Source Code (Use browser search to find items of interest.)
Class Index
ksokoban'Bookmark (./kdegames/ksokoban/Bookmark.H:28)
class Bookmark {
public:
Bookmark(int _num);
int collection() { return collection_; }
int level() { return level_; }
int moves() { return moves_; }
//int pushes() { return pushes_; }
void set(int _collection, int _level, int _moves, History *_h);
bool goTo(LevelMap *_map, History *_h);
private:
void fileName(QString &p);
int number_;
int collection_;
int level_;
int moves_;
//int pushes_;
QString data_;
};
ksokoban'Bookmark::fileName() (./kdegames/ksokoban/Bookmark.C:40)
Bookmark::fileName(QString &p) {
#if (KDE_VERSION_MAJOR > 1) || (KDE_VERSION_MINOR >= 9)
p = KGlobal::dirs()->saveLocation("appdata");
#else
p = (KApplication::kApplication())->localkdedir().data();
p += "/share/apps";
if (access(p, F_OK)) mkdir(p.data(), 0740);
p += "/ksokoban";
if (access(p, F_OK)) mkdir(p.data(), 0740);
#endif
QString n;
n.setNum(number_);
p += "/bookmark" + n;
}
ksokoban'Bookmark::Bookmark() (./kdegames/ksokoban/Bookmark.C:56)
Bookmark::Bookmark(int _num) :
number_(_num), collection_(-1), level_(-1), moves_(0), data_("") {
QString p;
fileName(p);
FILE *file = fopen(p.data(), "r");
if (file == NULL) return;
char buf[4096];
buf[0] = '\0';
fgets (buf, 4096, file);
if (sscanf(buf, "%d %d %d", &collection_, &level_, &moves_) != 3) {
collection_ = level_ = -1;
data_ = "";
fclose(file);
return;
}
data_ = "";
int len;
while (!feof(file)) {
len = fread(buf, 1, 4095, file);
if (ferror(file)) break;
buf[len] = '\0';
data_ += buf;
}
fclose(file);
data_ = data_.stripWhiteSpace();
}
void
ksokoban'Bookmark::set() (./kdegames/ksokoban/Bookmark.C:91)
Bookmark::set(int _collection, int _level, int _moves, History *_h) {
assert(_collection >= 0);
if (_collection < 0) return;
collection_ = _collection;
level_ = _level;
moves_ = _moves;
data_ = "";
_h->save(data_);
QString p;
fileName(p);
FILE *file = fopen(p.data(), "w");
if (file == NULL) return;
fprintf(file, "%d %d %d\n", collection_, level_, moves_);
fprintf(file, "%s\n", data_.data());
fclose(file);
}
bool
ksokoban'Bookmark::goTo() (./kdegames/ksokoban/Bookmark.C:112)
Bookmark::goTo(LevelMap *_map, History *_h) {
return _h->load(_map, data_.data()) != 0;
}