KHighscore Class Reference
#include <khighscore.h>
Detailed Description
Class for managing highscore tables.This is the KDE class for saving and reading highscore tables. It offers the possibility for system-wide highscore tables (configure with e.g. --enable-highscore-dir=/var/games) and a theoretically unlimited number of entries.
You can specify different "keys" for an entry - just like the KConfig keys. But it will be prefixed with the number of the entry. For example you will probably use something like this to save the name of the player on the top of the list (ie the winner):
highscore->writeEntry(1, "name", myPlayer->name());
You can also specify different groups using setHighscoreGroup. Just like the keys mentioned above the groups behave like groups in KConfig but are prefixed with "KHighscore_". The default group is just "KHighscore". You might use this e.g. to create different highscore tables like
table->setHighscoreGroup("Easy"); // write the highscores for level "easy" to the table writeEasyHighscores(table); table->setHighscore("Player_1"); // write player specific highscores to the table writePlayerHighscores(table);
QString group = QString("%1_%2").arg(player).arg(level); table->setGroup(group); writeHighscore(table, player, level);
Also note that you MUST NOT mark the key or the group for translation! I.e. don't use i18n() for the keys or groups! Here is the code to read the above written entry:
QString firstName = highscore->readEntry(0, "name");
- Author:
- Andreas Beckermann <b_mann@gmx.de>
Definition at line 84 of file khighscore.h.
Public Member Functions | |
KHighscore (QObject *parent=0) | |
KHighscore (bool forceLocal, QObject *parent) | |
void | readCurrentConfig () |
bool | lockForWriting (QWidget *widget=0) |
void | writeAndUnlock () |
bool | isLocked () const |
~KHighscore () | |
void | writeEntry (int entry, const QString &key, const QString &value) |
void | writeEntry (int entry, const QString &key, int value) |
void | writeEntry (int entry, const QString &key, const QVariant &value) |
QString | readEntry (int entry, const QString &key, const QString &pDefault=QString::null) const |
int | readNumEntry (int entry, const QString &key, int pDefault=-1) const |
QVariant | readPropertyEntry (int entry, const QString &key, const QVariant &pDefault) const |
bool | hasEntry (int entry, const QString &key) const |
QStringList | readList (const QString &key, int lastEntry=20) const |
void | writeList (const QString &key, const QStringList &list) |
bool | hasTable () const |
void | sync () |
void | setHighscoreGroup (const QString &groupname=QString::null) |
const QString & | highscoreGroup () const |
Static Public Member Functions | |
static void | init (const char *appname) |
Protected Member Functions | |
QString | group () const |
KConfig * | config () const |
void | init (bool forceLocal) |
Constructor & Destructor Documentation
|
Definition at line 59 of file khighscore.cpp. |
|
Constructor.
Definition at line 65 of file khighscore.cpp. |
|
Destructor. If necessary, write and unlock the highscore file. Definition at line 157 of file khighscore.cpp. |
Member Function Documentation
|
Definition at line 163 of file khighscore.cpp. |
|
Definition at line 246 of file khighscore.cpp. |
|
Definition at line 213 of file khighscore.cpp. |
|
Definition at line 254 of file khighscore.cpp. |
|
Definition at line 241 of file khighscore.cpp. |
|
Definition at line 95 of file khighscore.cpp. |
|
Definition at line 85 of file khighscore.cpp. |
|
Definition at line 114 of file khighscore.cpp. |
|
Read the current state of the highscore file. Remember that when it's not locked for writing, this file can change at any time. (This method is only useful for a system-wide highscore file).
Definition at line 90 of file khighscore.cpp. |
|
Reads an entry from the highscore table.
Definition at line 199 of file khighscore.cpp. |
|
Reads a list of entries from the highscore table starting at 1 until lastEntry. If an entry between those numbers doesn't exist the function aborts reading even if after the missing entry is an existing one. The first entry of the list is the first placing, the last on is the last placing.
Definition at line 220 of file khighscore.cpp. |
|
Read a numeric value.
Definition at line 206 of file khighscore.cpp. |
|
Read a QVariant entry. See KConfigBase documentation for allowed QVariant::Type.
Definition at line 192 of file khighscore.cpp. |
|
Set the new highscore group. The group is being prefixed with "KHighscore_" in the table.
Definition at line 236 of file khighscore.cpp. |
|
Definition at line 257 of file khighscore.cpp. |
|
Effectively write and unlock the system-wide highscore file (.
Definition at line 143 of file khighscore.cpp. |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. See KConfigBase documentation for allowed QVariant::Type. Definition at line 168 of file khighscore.cpp. |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Definition at line 176 of file khighscore.cpp. |
|
Definition at line 184 of file khighscore.cpp. |
|
Writes a list of entries to the highscore table. The first entry is prefixed with "1". Using this method is a short way of calling writeEntry(i, key, list[i]) from i = 1 to list.count()
Definition at line 229 of file khighscore.cpp. |
The documentation for this class was generated from the following files: