• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • highscore
kexthighscore_internal.h
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2001-2004 Nicolas Hadacek (hadacek@kde.org)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KEXTHIGHSCORE_INTERNAL_H
21 #define KEXTHIGHSCORE_INTERNAL_H
22 
23 #include <tdeapplication.h>
24 #include <tdeconfig.h>
25 #include <tdelocale.h>
26 #include <kurl.h>
27 
28 #include "khighscore.h"
29 #include "kexthighscore.h"
30 
31 class TQTextStream;
32 class TQTabWidget;
33 class TQDomNamedNodeMap;
34 
35 
36 namespace KExtHighscore
37 {
38 
39 class PlayerInfos;
40 class Score;
41 class Manager;
42 
43 
44 //-----------------------------------------------------------------------------
45 class RankItem : public Item
46 {
47  public:
48  RankItem()
49  : Item((uint)0, i18n("Rank"), TQt::AlignRight) {}
50 
51  TQVariant read(uint rank, const TQVariant &) const { return rank; }
52  TQString pretty(uint rank, const TQVariant &) const
53  { return TQString::number(rank+1); }
54 };
55 
56 class NameItem : public Item
57 {
58  public:
59  NameItem()
60  : Item(TQString(), i18n("Name"), TQt::AlignLeft) {
61  setPrettySpecial(Anonymous);
62  }
63 };
64 
65 class DateItem : public Item
66 {
67  public:
68  DateItem()
69  : Item(TQDateTime(), i18n("Date"), TQt::AlignRight) {
70  setPrettyFormat(DateTime);
71  }
72 };
73 
74 class SuccessPercentageItem : public Item
75 {
76  public:
77  SuccessPercentageItem()
78  : Item((double)-1, i18n("Success"), TQt::AlignRight) {
79  setPrettyFormat(Percentage);
80  setPrettySpecial(NegativeNotDefined);
81  }
82 };
83 
84 //-----------------------------------------------------------------------------
85 class ItemContainer
86 {
87  public:
88  ItemContainer();
89  ~ItemContainer();
90 
91  void setItem(Item *item);
92  const Item *item() const { return _item; }
93  Item *item() { return _item; }
94 
95  void setName(const TQString &name) { _name = name; }
96  TQString name() const { return _name; }
97 
98  void setGroup(const TQString &group) { _group = group; }
99  bool isStored() const { return !_group.isNull(); }
100 
101  void setSubGroup(const TQString &subGroup) { _subGroup = subGroup; }
102  bool canHaveSubGroup() const { return !_subGroup.isNull(); }
103 
104  static const char ANONYMOUS[]; // name assigned to anonymous players
105  static const char ANONYMOUS_LABEL[];
106 
107  TQVariant read(uint i) const;
108  TQString pretty(uint i) const;
109  void write(uint i, const TQVariant &value) const;
110  // for UInt TQVariant (return new value)
111  uint increment(uint i) const;
112 
113  private:
114  Item *_item;
115  TQString _name, _group, _subGroup;
116 
117  TQString entryName() const;
118 
119  ItemContainer(const ItemContainer &);
120  ItemContainer &operator =(const ItemContainer &);
121 };
122 
123 //-----------------------------------------------------------------------------
128 class ItemArray : public TQMemArray<ItemContainer *>
129 {
130  public:
131  ItemArray();
132  virtual ~ItemArray();
133 
134  virtual uint nbEntries() const = 0;
135 
136  const ItemContainer *item(const TQString &name) const;
137  ItemContainer *item(const TQString &name);
138 
139  void addItem(const TQString &name, Item *, bool stored = true,
140  bool canHaveSubGroup = false);
141  void setItem(const TQString &name, Item *);
142  int findIndex(const TQString &name) const;
143 
144  void setGroup(const TQString &group);
145  void setSubGroup(const TQString &subGroup);
146 
147  void read(uint k, Score &data) const;
148  void write(uint k, const Score &data, uint maxNbLines) const;
149 
150  void exportToText(TQTextStream &) const;
151 
152  private:
153  TQString _group, _subGroup;
154 
155  void _setItem(uint i, const TQString &name, Item *, bool stored,
156  bool canHaveSubGroup);
157 
158  ItemArray(const ItemArray &);
159  ItemArray &operator =(const ItemArray &);
160 };
161 
162 //-----------------------------------------------------------------------------
163 class ScoreInfos : public ItemArray
164 {
165  public:
166  ScoreInfos(uint maxNbEntries, const PlayerInfos &infos);
167 
168  uint nbEntries() const;
169  uint maxNbEntries() const { return _maxNbEntries; }
170 
171  private:
172  uint _maxNbEntries;
173 };
174 
175 //-----------------------------------------------------------------------------
176 class ConfigGroup : public TDEConfigGroupSaver
177 {
178  public:
179  ConfigGroup(const TQString &group = TQString())
180  : TDEConfigGroupSaver(kapp->config(), group) {}
181 };
182 
183 //-----------------------------------------------------------------------------
184 class PlayerInfos : public ItemArray
185 {
186  public:
187  PlayerInfos();
188 
189  bool isNewPlayer() const { return _newPlayer; }
190  bool isOldLocalPlayer() const { return _oldLocalPlayer; }
191  uint nbEntries() const;
192  TQString name() const { return item("name")->read(_id).toString(); }
193  bool isAnonymous() const;
194  TQString prettyName() const { return prettyName(_id); }
195  TQString prettyName(uint id) const { return item("name")->pretty(id); }
196  TQString registeredName() const;
197  TQString comment() const { return item("comment")->pretty(_id); }
198  bool isWWEnabled() const;
199  TQString key() const;
200  uint id() const { return _id; }
201  uint oldLocalId() const { return _oldLocalId; }
202 
203  void createHistoItems(const TQMemArray<uint> &scores, bool bound);
204  TQString histoName(uint i) const;
205  uint histoSize() const;
206  const TQMemArray<uint> &histogram() const { return _histogram; }
207 
208  void submitScore(const Score &) const;
209  // return true if the nickname is already used locally
210  bool isNameUsed(const TQString &name) const;
211  void modifyName(const TQString &newName) const;
212  void modifySettings(const TQString &newName, const TQString &comment,
213  bool WWEnabled, const TQString &newKey) const;
214  void removeKey();
215 
216  private:
217  bool _newPlayer, _bound, _oldLocalPlayer;
218  uint _id, _oldLocalId;
219  TQMemArray<uint> _histogram;
220 };
221 
222 //-----------------------------------------------------------------------------
223 class ManagerPrivate
224 {
225  public:
226  ManagerPrivate(uint nbGameTypes, Manager &manager);
227  void init(uint maxNbentries);
228  ~ManagerPrivate();
229 
230  bool modifySettings(const TQString &newName, const TQString &comment,
231  bool WWEnabled, TQWidget *widget);
232 
233  void setGameType(uint type);
234  void checkFirst();
235  int submitLocal(const Score &score);
236  int submitScore(const Score &score, TQWidget *widget, bool askIfAnonymous);
237  Score readScore(uint i) const;
238 
239  uint gameType() const { return _gameType; }
240  uint nbGameTypes() const { return _nbGameTypes; }
241  bool isWWHSAvailable() const { return !serverURL.isEmpty(); }
242  ScoreInfos &scoreInfos() { return *_scoreInfos; }
243  PlayerInfos &playerInfos() { return *_playerInfos; }
244  KHighscore &hsConfig() { return *_hsConfig; }
245  enum QueryType { Submit, Register, Change, Players, Scores };
246  KURL queryURL(QueryType type, const TQString &newName=TQString()) const;
247 
248  void exportHighscores(TQTextStream &);
249 
250  Manager &manager;
251  KURL serverURL;
252  TQString version;
253  bool showStatistics, showDrawGames, trackLostGames, trackDrawGames;
254  Manager::ShowMode showMode;
255 
256  private:
257  KHighscore *_hsConfig;
258  PlayerInfos *_playerInfos;
259  ScoreInfos *_scoreInfos;
260  bool _first;
261  const uint _nbGameTypes;
262  uint _gameType;
263 
264  // return -1 if not a local best score
265  int rank(const Score &score) const;
266 
267  bool submitWorldWide(const Score &score, TQWidget *parent) const;
268  static bool doQuery(const KURL &url, TQWidget *parent,
269  TQDomNamedNodeMap *map = 0);
270  static bool getFromQuery(const TQDomNamedNodeMap &map, const TQString &name,
271  TQString &value, TQWidget *parent);
272  void convertToGlobal();
273 };
274 
275 } // namespace
276 
277 #endif
KHighscore
Class for managing highscore tables.
Definition: khighscore.h:84
KExtHighscore::Manager
This class manages highscores and players entries (several players can share the same highscores list...
Definition: kexthighscore.h:139
KExtHighscore
Definition: kexthighscore.cpp:30
KExtHighscore::Item
This class defines how to convert and how to display a highscore element (such as the score...
Definition: kexthighscore_item.h:40
KExtHighscore::Manager::ShowMode
ShowMode
Enumerate different conditions under which to show the high score dialog.
Definition: kexthighscore.h:220
KExtHighscore::Item::Item
Item(const TQVariant &def=TQVariant::Invalid, const TQString &label=TQString(), int alignment=TQt::AlignRight)
Constructor.
Definition: kexthighscore_item.cpp:36
KExtHighscore::Score
This class contains data for a score.
Definition: kexthighscore_item.h:175
KExtHighscore::ItemArray
Manage a bunch of Item which are saved under the same group in KHighscores config file...
Definition: kexthighscore_internal.h:128

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.