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

libkdegames

kgamethemeselector.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2007 Mauricio Piacentini  <mauricio@tabuleiro.com>
00003 
00004     This library is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program 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
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 */
00018 
00019 #include "kgamethemeselector.h"
00020 
00021 #include <KLocale>
00022 #include <KStandardDirs>
00023 #include <KConfigSkeleton>
00024 #include <knewstuff2/engine.h>
00025 #include <KComponentData>
00026 
00027 #include "ui_kgamethemeselector.h"
00028 #include "kgametheme.h"
00029 
00030 class KGameThemeSelector::KGameThemeSelectorPrivate
00031 {
00032     public:
00033         KGameThemeSelectorPrivate(KGameThemeSelector* parent) : q(parent) {}
00034         ~KGameThemeSelectorPrivate() { qDeleteAll(themeMap); }
00035 
00036         KGameThemeSelector* q;
00037 
00038         QMap<QString, KGameTheme*> themeMap;
00039         Ui::KGameThemeSelectorBase ui;
00040         QString lookupDirectory;
00041         QString groupName;
00042 
00043         void setupData(KConfigSkeleton* config, KGameThemeSelector::NewStuffState knsflags);
00044 
00045         // private slots
00046         void _k_updatePreview();
00047         void _k_openKNewStuffDialog();
00048 };
00049 
00050 KGameThemeSelector::KGameThemeSelector(QWidget* parent, KConfigSkeleton * aconfig, KGameThemeSelector::NewStuffState knsflags, const QString &groupName, const QString &directory)
00051     : QWidget(parent), d(new KGameThemeSelectorPrivate(this))
00052 {
00053     d->lookupDirectory = directory;
00054     d->groupName = groupName;
00055     d->setupData(aconfig, knsflags);
00056 }
00057 
00058 KGameThemeSelector::~KGameThemeSelector()
00059 {
00060     delete d;
00061 }
00062 
00063 void KGameThemeSelector::KGameThemeSelectorPrivate::setupData(KConfigSkeleton * aconfig, KGameThemeSelector::NewStuffState knsflags)
00064 {
00065     ui.setupUi(q);
00066 
00067     //Get our currently configured Tileset entry
00068     KConfig * config = aconfig->config();
00069     KConfigGroup group = config->group("General");
00070     QString initialGroup = group.readEntry("Theme"); //Should be someting like "themes/default.desktop"
00071 
00072     //The lineEdit widget holds our bg path, but the user does not manipulate it directly
00073     ui.kcfg_Theme->hide();
00074     
00075     //Disable KNS button?
00076     if (knsflags==KGameThemeSelector::NewStuffDisableDownload) {
00077       ui.getNewButton->hide();
00078     }
00079 
00080     //Now get our tilesets into a list
00081     KGlobal::dirs()->addResourceType("gamethemeselector", "data", KGlobal::mainComponent().componentName() + '/' + lookupDirectory + '/');
00082     QStringList themesAvailable;
00083     KGlobal::dirs()->findAllResources("gamethemeselector", QString("*.desktop"), KStandardDirs::Recursive, themesAvailable);
00084     QString namestr("Name");
00085     int numvalidentries = 0;
00086     for (int i = 0; i < themesAvailable.size(); ++i)
00087     {
00088         KGameTheme* atheme = new KGameTheme(groupName);
00089         QString themepath = lookupDirectory + '/' + themesAvailable.at(i);
00090         if (atheme->load(themepath)) {
00091           themeMap.insert(atheme->themeProperty(namestr), atheme);
00092           ui.themeList->addItem(atheme->themeProperty(namestr));
00093             //Find if this is our currently configured Theme
00094             if (themepath==initialGroup) {
00095                 //Select current entry
00096                 ui.themeList->setCurrentRow(numvalidentries);
00097                 _k_updatePreview();
00098             }
00099             ++numvalidentries;
00100         } else {
00101             delete atheme;
00102         }
00103     }
00104 
00105     connect(ui.themeList, SIGNAL(currentItemChanged ( QListWidgetItem * , QListWidgetItem * )), q, SLOT(_k_updatePreview()));
00106     connect(ui.getNewButton, SIGNAL(clicked()), q, SLOT(_k_openKNewStuffDialog()));
00107 }
00108 
00109 void KGameThemeSelector::KGameThemeSelectorPrivate::_k_updatePreview()
00110 {
00111     KGameTheme * seltheme = themeMap.value(ui.themeList->currentItem()->text());
00112         //Sanity checkings. Should not happen.
00113     if (!seltheme) return;
00114     if (seltheme->path() == ui.kcfg_Theme->text()) {
00115         return;
00116     }
00117     QString authstr("Author");
00118     QString contactstr("AuthorEmail");
00119     QString descstr("Description");
00120     ui.kcfg_Theme->setText(seltheme->fileName());
00121     ui.themeAuthor->setText(seltheme->themeProperty(authstr));
00122     ui.themeContact->setText(seltheme->themeProperty(contactstr));
00123     ui.themeDescription->setText(seltheme->themeProperty(descstr));
00124 
00125     //Draw the preview
00126     //TODO here: add code to maintain aspect ration?
00127     ui.themePreview->setPixmap(seltheme->preview());
00128 
00129 }
00130 
00131 void KGameThemeSelector::KGameThemeSelectorPrivate::_k_openKNewStuffDialog()
00132 {
00133     KNS::Entry::List entries = KNS::Engine::download();
00134 }
00135 
00136 #include "kgamethemeselector.moc"

libkdegames

Skip menu "libkdegames"
  • 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