• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames/highscore

kexthighscore_internal.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001-2004 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., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXTHIGHSCORE_INTERNAL_H
00021 #define KEXTHIGHSCORE_INTERNAL_H
00022 
00023 #include <kglobal.h>
00024 #include <kconfig.h>
00025 #include <klocale.h>
00026 #include <kurl.h>
00027 
00028 #include "khighscore.h"
00029 #include "kexthighscore.h"
00030 
00031 #include <QtCore/QTextStream>
00032 #include <QtCore/QVector>
00033 #include <QtCore/QDateTime>
00034 #include <kconfiggroup.h>
00035 
00036 class QTextStream;
00037 class QDomNamedNodeMap;
00038 
00039 
00040 namespace KExtHighscore
00041 {
00042 
00043 class PlayerInfos;
00044 class Score;
00045 class Manager;
00046 
00047 
00048 //-----------------------------------------------------------------------------
00049 class RankItem : public Item
00050 {
00051  public:
00052     RankItem()
00053         : Item((uint)0, i18n("Rank"), Qt::AlignRight) {}
00054 
00055     QVariant read(uint i, const QVariant &value) const  { Q_UNUSED(value); return i; }
00056     QString pretty(uint i, const QVariant &value) const
00057         { Q_UNUSED(value); return QString::number(i+1); }
00058 };
00059 
00060 class NameItem : public Item
00061 {
00062  public:
00063     NameItem()
00064         : Item(QString(), i18n("Name"), Qt::AlignLeft) {
00065             setPrettySpecial(Anonymous);
00066     }
00067 };
00068 
00069 class DateItem : public Item
00070 {
00071  public:
00072     DateItem()
00073         : Item(QDateTime(), i18n("Date"), Qt::AlignRight) {
00074             setPrettyFormat(DateTime);
00075     }
00076 };
00077 
00078 class SuccessPercentageItem : public Item
00079 {
00080  public:
00081     SuccessPercentageItem()
00082         : Item((double)-1, i18n("Success"), Qt::AlignRight) {
00083             setPrettyFormat(Percentage);
00084             setPrettySpecial(NegativeNotDefined);
00085     }
00086 };
00087 
00088 //-----------------------------------------------------------------------------
00089 class ItemContainer
00090 {
00091  public:
00092     ItemContainer();
00093     ~ItemContainer();
00094 
00095     void setItem(Item *item);
00096     const Item *item() const { return _item; }
00097     Item *item() { return _item; }
00098 
00099     void setName(const QString &name) { _name = name; }
00100     QString name() const { return _name; }
00101 
00102     void setGroup(const QString &group) { _group = group; }
00103     bool isStored() const { return !_group.isNull(); }
00104 
00105     void setSubGroup(const QString &subGroup) { _subGroup = subGroup; }
00106     bool canHaveSubGroup() const { return !_subGroup.isNull(); }
00107 
00108     static const char ANONYMOUS[]; // name assigned to anonymous players
00109     static const char ANONYMOUS_LABEL[];
00110 
00111     QVariant read(uint i) const;
00112     QString pretty(uint i) const;
00113     void write(uint i, const QVariant &value) const;
00114     // for UInt QVariant (return new value)
00115     uint increment(uint i) const;
00116 
00117  private:
00118     Item    *_item;
00119     QString  _name, _group, _subGroup;
00120 
00121     QString entryName() const;
00122 
00123     ItemContainer(const ItemContainer &);
00124     ItemContainer &operator =(const ItemContainer &);
00125 };
00126 
00127 //-----------------------------------------------------------------------------
00132 class ItemArray : public QVector<ItemContainer *>
00133 {
00134  public:
00135     ItemArray();
00136     virtual ~ItemArray();
00137 
00138     virtual uint nbEntries() const = 0;
00139 
00140     const ItemContainer *item(const QString &name) const;
00141     ItemContainer *item(const QString &name);
00142 
00143     void addItem(const QString &name, Item *, bool stored = true,
00144                  bool canHaveSubGroup = false);
00145     void setItem(const QString &name, Item *);
00146     int findIndex(const QString &name) const;
00147 
00148     void setGroup(const QString &group);
00149     void setSubGroup(const QString &subGroup);
00150 
00151     void read(uint k, Score &data) const;
00152     void write(uint k, const Score &data, uint maxNbLines) const;
00153 
00154     void exportToText(QTextStream &) const;
00155 
00156  private:
00157     QString _group, _subGroup;
00158 
00159     void _setItem(uint i, const QString &name, Item *, bool stored,
00160                   bool canHaveSubGroup);
00161 
00162     ItemArray(const ItemArray &);
00163     ItemArray &operator =(const ItemArray &);
00164 };
00165 
00166 //-----------------------------------------------------------------------------
00167 class ScoreInfos : public ItemArray
00168 {
00169  public:
00170     ScoreInfos(uint maxNbEntries, const PlayerInfos &infos);
00171 
00172     uint nbEntries() const;
00173     uint maxNbEntries() const { return _maxNbEntries; }
00174 
00175  private:
00176     uint _maxNbEntries;
00177 };
00178 
00179 //-----------------------------------------------------------------------------
00180 class ConfigGroup : public KConfigGroup
00181 {
00182  public:
00183     ConfigGroup(const QString &group = "")
00184         : KConfigGroup(KGlobal::config(), group) {}
00185 };
00186 
00187 //-----------------------------------------------------------------------------
00188 class PlayerInfos : public ItemArray
00189 {
00190  public:
00191     PlayerInfos();
00192 
00193     bool isNewPlayer() const { return _newPlayer; }
00194     bool isOldLocalPlayer() const { return _oldLocalPlayer; }
00195     uint nbEntries() const;
00196     QString name() const { return item("name")->read(_id).toString(); }
00197     bool isAnonymous() const;
00198     QString prettyName() const { return prettyName(_id); }
00199     QString prettyName(uint id) const { return item("name")->pretty(id); }
00200     QString registeredName() const;
00201     QString comment() const { return item("comment")->pretty(_id); }
00202     bool isWWEnabled() const;
00203     QString key() const;
00204     uint id() const { return _id; }
00205     uint oldLocalId() const { return _oldLocalId; }
00206 
00207     void createHistoItems(const QVector<uint> &scores, bool bound);
00208     QString histoName(int i) const;
00209     int histoSize() const;
00210     const QVector<uint> &histogram() const { return _histogram; }
00211 
00212     void submitScore(const Score &) const;
00213     // return true if the nickname is already used locally
00214     bool isNameUsed(const QString &name) const;
00215     void modifyName(const QString &newName) const;
00216     void modifySettings(const QString &newName, const QString &comment,
00217                         bool WWEnabled, const QString &newKey) const;
00218     void removeKey();
00219 
00220  private:
00221     bool _newPlayer, _bound, _oldLocalPlayer;
00222     uint _id, _oldLocalId;
00223     QVector<uint> _histogram;
00224 };
00225 
00226 //-----------------------------------------------------------------------------
00227 class ManagerPrivate
00228 {
00229  public:
00230     ManagerPrivate(uint nbGameTypes, Manager &manager);
00231     void init(uint maxNbentries);
00232     ~ManagerPrivate();
00233 
00234     bool modifySettings(const QString &newName, const QString &comment,
00235                         bool WWEnabled, QWidget *widget);
00236 
00237     void setGameType(uint type);
00238     void checkFirst();
00239     int submitLocal(const Score &score);
00240     int submitScore(const Score &score, QWidget *widget, bool askIfAnonymous);
00241     Score readScore(uint i) const;
00242 
00243     uint gameType() const        { return _gameType; }
00244     uint nbGameTypes() const     { return _nbGameTypes; }
00245     bool isWWHSAvailable() const { return !serverURL.isEmpty(); }
00246     ScoreInfos &scoreInfos()     { return *_scoreInfos; }
00247     PlayerInfos &playerInfos()   { return *_playerInfos; }
00248     KHighscore &hsConfig()       { return *_hsConfig; }
00249     enum QueryType { Submit, Register, Change, Players, Scores };
00250     KUrl queryUrl(QueryType type, const QString &newName = "") const;
00251 
00252     void exportHighscores(QTextStream &);
00253 
00254     Manager &manager;
00255     KUrl     serverURL;
00256     QString  version;
00257     bool     showStatistics, showDrawGames, trackLostGames, trackDrawGames;
00258     Manager::ShowMode showMode;
00259 
00260  private:
00261     KHighscore   *_hsConfig;
00262     PlayerInfos  *_playerInfos;
00263     ScoreInfos   *_scoreInfos;
00264     bool          _first;
00265     const uint    _nbGameTypes;
00266     uint          _gameType;
00267 
00268     // return -1 if not a local best score
00269     int rank(const Score &score) const;
00270 
00271     bool submitWorldWide(const Score &score, QWidget *parent) const;
00272     static bool doQuery(const KUrl &url, QWidget *parent,
00273                         QDomNamedNodeMap *map = 0);
00274     static bool getFromQuery(const QDomNamedNodeMap &map, const QString &name,
00275                              QString &value, QWidget *parent);
00276     void convertToGlobal();
00277 };
00278 
00279 } // namespace
00280 
00281 #endif

libkdegames/highscore

Skip menu "libkdegames/highscore"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal