libkdegames Library API Documentation

kexthighscore_internal.h

00001 /* 00002 This file is part of the KDE games library 00003 Copyright (C) 2001-02 Nicolas Hadacek (hadacek@kde.org) 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef KEXTHIGHSCORE_INTERNAL_H 00021 #define KEXTHIGHSCORE_INTERNAL_H 00022 00023 #include <kapplication.h> 00024 #include <kconfig.h> 00025 #include <klocale.h> 00026 #include <kurl.h> 00027 00028 #include "khighscore.h" 00029 #include "kexthighscore.h" 00030 00031 class QTextStream; 00032 class QTabWidget; 00033 class QDomNamedNodeMap; 00034 00035 00036 namespace KExtHighscore 00037 { 00038 00039 class PlayerInfos; 00040 class Score; 00041 class Manager; 00042 00043 00044 //----------------------------------------------------------------------------- 00045 class RankItem : public Item 00046 { 00047 public: 00048 RankItem() 00049 : Item((uint)0, i18n("Rank"), Qt::AlignRight) {} 00050 00051 QVariant read(uint rank, const QVariant &) const { return rank; } 00052 QString pretty(uint rank, const QVariant &) const 00053 { return QString::number(rank+1); } 00054 }; 00055 00056 class NameItem : public Item 00057 { 00058 public: 00059 NameItem() 00060 : Item(QString::null, i18n("Name"), Qt::AlignLeft) { 00061 setPrettySpecial(Anonymous); 00062 } 00063 }; 00064 00065 class DateItem : public Item 00066 { 00067 public: 00068 DateItem() 00069 : Item(QDateTime(), i18n("Date"), Qt::AlignRight) { 00070 setPrettyFormat(DateTime); 00071 } 00072 }; 00073 00074 class SuccessPercentageItem : public Item 00075 { 00076 public: 00077 SuccessPercentageItem() 00078 : Item((double)-1, i18n("Success"), Qt::AlignRight) { 00079 setPrettyFormat(Percentage); 00080 setPrettySpecial(NegativeNotDefined); 00081 } 00082 }; 00083 00084 //----------------------------------------------------------------------------- 00085 class ItemContainer 00086 { 00087 public: 00088 ItemContainer(); 00089 ~ItemContainer(); 00090 00091 void setItem(Item *item); 00092 const Item *item() const { return _item; } 00093 Item *item() { return _item; } 00094 00095 void setName(const QString &name) { _name = name; } 00096 QString name() const { return _name; } 00097 00098 void setGroup(const QString &group) { _group = group; } 00099 bool isStored() const { return !_group.isNull(); } 00100 00101 void setSubGroup(const QString &subGroup) { _subGroup = subGroup; } 00102 bool canHaveSubGroup() const { return !_subGroup.isNull(); } 00103 00104 static const char ANONYMOUS[]; // name assigned to anonymous players 00105 static const char ANONYMOUS_LABEL[]; 00106 00107 QVariant read(uint i) const; 00108 QString pretty(uint i) const; 00109 void write(uint i, const QVariant &value) const; 00110 // for UInt QVariant (return new value) 00111 uint increment(uint i) const; 00112 00113 private: 00114 Item *_item; 00115 QString _name, _group, _subGroup; 00116 00117 QString entryName() const; 00118 00119 ItemContainer(const ItemContainer &); 00120 ItemContainer &operator =(const ItemContainer &); 00121 }; 00122 00123 //----------------------------------------------------------------------------- 00128 class ItemArray : public QMemArray<ItemContainer *> 00129 { 00130 public: 00131 ItemArray(); 00132 virtual ~ItemArray(); 00133 00134 virtual uint nbEntries() const = 0; 00135 00136 const ItemContainer *item(const QString &name) const; 00137 ItemContainer *item(const QString &name); 00138 00139 void addItem(const QString &name, Item *, bool stored = true, 00140 bool canHaveSubGroup = false); 00141 void setItem(const QString &name, Item *); 00142 int findIndex(const QString &name) const; 00143 00144 void setGroup(const QString &group); 00145 void setSubGroup(const QString &subGroup); 00146 00147 void read(uint k, Score &data) const; 00148 void write(uint k, const Score &data, uint maxNbLines) const; 00149 00150 void exportToText(QTextStream &) const; 00151 00152 private: 00153 QString _group, _subGroup; 00154 00155 void _setItem(uint i, const QString &name, Item *, bool stored, 00156 bool canHaveSubGroup); 00157 00158 ItemArray(const ItemArray &); 00159 ItemArray &operator =(const ItemArray &); 00160 }; 00161 00162 //----------------------------------------------------------------------------- 00163 class ScoreInfos : public ItemArray 00164 { 00165 public: 00166 ScoreInfos(uint maxNbEntries, const PlayerInfos &infos); 00167 00168 uint nbEntries() const; 00169 uint maxNbEntries() const { return _maxNbEntries; } 00170 00171 private: 00172 uint _maxNbEntries; 00173 }; 00174 00175 //----------------------------------------------------------------------------- 00176 class ConfigGroup : public KConfigGroupSaver 00177 { 00178 public: 00179 ConfigGroup(const QString &group = QString::null) 00180 : KConfigGroupSaver(kapp->config(), group) {} 00181 }; 00182 00183 //----------------------------------------------------------------------------- 00184 class PlayerInfos : public ItemArray 00185 { 00186 public: 00187 PlayerInfos(); 00188 00189 bool isNewPlayer() const { return _newPlayer; } 00190 bool isOldLocalPlayer() const { return _oldLocalPlayer; } 00191 uint nbEntries() const; 00192 QString name() const { return item("name")->read(_id).toString(); } 00193 bool isAnonymous() const; 00194 QString prettyName() const { return prettyName(_id); } 00195 QString prettyName(uint id) const { return item("name")->pretty(id); } 00196 QString registeredName() const; 00197 QString comment() const { return item("comment")->pretty(_id); } 00198 bool isWWEnabled() const; 00199 QString key() const; 00200 uint id() const { return _id; } 00201 uint oldLocalId() const { return _oldLocalId; } 00202 00203 void createHistoItems(const QMemArray<uint> &scores, bool bound); 00204 QString histoName(uint i) const; 00205 uint histoSize() const; 00206 const QMemArray<uint> &histogram() const { return _histogram; } 00207 00208 void submitScore(const Score &) const; 00209 // return true if the nickname is already used locally 00210 bool isNameUsed(const QString &name) const; 00211 void modifyName(const QString &newName) const; 00212 void modifySettings(const QString &newName, const QString &comment, 00213 bool WWEnabled, const QString &newKey) const; 00214 void removeKey(); 00215 00216 private: 00217 bool _newPlayer, _bound, _oldLocalPlayer; 00218 uint _id, _oldLocalId; 00219 QMemArray<uint> _histogram; 00220 }; 00221 00222 //----------------------------------------------------------------------------- 00223 class ManagerPrivate 00224 { 00225 public: 00226 ManagerPrivate(uint nbGameTypes, Manager &manager); 00227 void init(uint maxNbentries); 00228 ~ManagerPrivate(); 00229 00230 bool modifySettings(const QString &newName, const QString &comment, 00231 bool WWEnabled, QWidget *widget); 00232 00233 void setGameType(uint type); 00234 void checkFirst(); 00235 int submitLocal(const Score &score); 00236 int submitScore(const Score &score, QWidget *widget, bool askIfAnonymous); 00237 Score readScore(uint i) const; 00238 00239 uint gameType() const { return _gameType; } 00240 uint nbGameTypes() const { return _nbGameTypes; } 00241 bool isWWHSAvailable() const { return !serverURL.isEmpty(); } 00242 ScoreInfos &scoreInfos() { return *_scoreInfos; } 00243 PlayerInfos &playerInfos() { return *_playerInfos; } 00244 KHighscore &hsConfig() { return *_hsConfig; } 00245 enum QueryType { Submit, Register, Change, Players, Scores }; 00246 KURL queryURL(QueryType type, const QString &newName=QString::null) const; 00247 00248 void exportHighscores(QTextStream &); 00249 00250 Manager &manager; 00251 KURL serverURL; 00252 QString version; 00253 bool showStatistics, trackLostGames; 00254 Manager::ShowMode showMode; 00255 00256 private: 00257 KHighscore *_hsConfig; 00258 PlayerInfos *_playerInfos; 00259 ScoreInfos *_scoreInfos; 00260 bool _first; 00261 const uint _nbGameTypes; 00262 uint _gameType; 00263 00264 // return -1 if not a local best score 00265 int rank(const Score &score) const; 00266 00267 bool submitWorldWide(const Score &score, QWidget *parent) const; 00268 static bool doQuery(const KURL &url, QWidget *parent, 00269 QDomNamedNodeMap *map = 0); 00270 static bool getFromQuery(const QDomNamedNodeMap &map, const QString &name, 00271 QString &value, QWidget *parent); 00272 void convertToGlobal(); 00273 }; 00274 00275 } // namespace 00276 00277 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 21 12:08:02 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003