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

kmahjongg

kmahjongglayout.cpp

Go to the documentation of this file.
00001 /*
00002     kmahjongg, the classic mahjongg game for KDE
00003     Copyright (C) 2007 Mauricio Piacentini   <mauricio@tabuleiro.com>
00004 
00005     Kmahjongg is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 */
00019 
00020 #include "kmahjongglayout.h"
00021 #include "BoardLayout.h"
00022 #include <kstandarddirs.h>
00023 #include <klocale.h>
00024 #include <kconfig.h>
00025 #include <kconfiggroup.h>
00026 #include <QFile>
00027 #include <QMap>
00028 #include <KDebug>
00029 
00030 class KMahjonggLayoutPrivate
00031 {
00032 public:
00033     KMahjonggLayoutPrivate()
00034     {
00035       board = new BoardLayout();
00036     }
00037     ~KMahjonggLayoutPrivate()
00038     {
00039       delete board;
00040     }
00041 
00042     BoardLayout * board;
00043     QMap<QString, QString> authorproperties;
00044     QString filename;
00045 };
00046 
00047 KMahjonggLayout::KMahjonggLayout()
00048     : d(new KMahjonggLayoutPrivate)
00049 {
00050     static bool _inited = false;
00051     if (_inited)
00052         return;
00053     KGlobal::dirs()->addResourceType("kmahjongglayout", "data", QString::fromLatin1("kmahjongg/layouts/"));
00054 
00055     _inited = true;
00056 }
00057 
00058 KMahjonggLayout::~KMahjonggLayout() {
00059     delete d;
00060 }
00061 
00062 bool KMahjonggLayout::loadDefault()
00063 {
00064     QString idx = "default.desktop";
00065 
00066     QString layoutPath = KStandardDirs::locate("kmahjongglayout", idx);
00067     kDebug() << "Inside LoadDefault(), located layout at" << layoutPath;
00068     if (layoutPath.isEmpty()) {
00069         return false;
00070     }
00071     return load(layoutPath);
00072 }
00073 
00074 #define kLayoutVersionFormat 1
00075 
00076 bool KMahjonggLayout::load(const QString &file) {
00077     kDebug() << "Layout loading";
00078 
00079     QString layoutPath;
00080     kDebug() << "Attempting to load .desktop at" << file;
00081 
00082     // verify if it is a valid file first and if we can open it
00083     QFile bgfile(file);
00084     if (!bgfile.open(QIODevice::ReadOnly)) {
00085       return (false);
00086     }
00087     bgfile.close();
00088 
00089     KConfig bgconfig(file, KConfig::SimpleConfig);
00090     KConfigGroup group = bgconfig.group("KMahjonggLayout");
00091 
00092     d->authorproperties.insert("Name", group.readEntry("Name"));// Returns translated data
00093     d->authorproperties.insert("Author", group.readEntry("Author"));
00094     d->authorproperties.insert("Description", group.readEntry("Description"));
00095     d->authorproperties.insert("AuthorEmail", group.readEntry("AuthorEmail"));
00096 
00097     //Version control
00098     int bgversion = group.readEntry("VersionFormat",0);
00099     //Format is increased when we have incompatible changes, meaning that older clients are not able to use the remaining information safely
00100     if (bgversion > kLayoutVersionFormat) {
00101         return false;
00102     }
00103 
00104     QString layoutName = group.readEntry("FileName");
00105 
00106     layoutPath = KStandardDirs::locate("kmahjongglayout", layoutName);
00107     kDebug() << "Using layout at" << layoutPath;
00108     d->filename = layoutPath;
00109 
00110     if (layoutPath.isEmpty()) return (false);
00111     
00112     if (!d->board->loadBoardLayout(d->filename)) return (false);
00113     
00114     filename = file;
00115 
00116    return true;
00117 }
00118 
00119 BoardLayout * KMahjonggLayout::board() { 
00120   return d->board; 
00121 }
00122 
00123 QString KMahjonggLayout::path() const {
00124     return filename;
00125 }
00126 
00127 QString KMahjonggLayout::authorProperty(const QString &key) const {
00128     return d->authorproperties[key];
00129 }

kmahjongg

Skip menu "kmahjongg"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

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