libkdegames
kgamethemeselector.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00068 KConfig * config = aconfig->config();
00069 KConfigGroup group = config->group("General");
00070 QString initialGroup = group.readEntry("Theme");
00071
00072
00073 ui.kcfg_Theme->hide();
00074
00075
00076 if (knsflags==KGameThemeSelector::NewStuffDisableDownload) {
00077 ui.getNewButton->hide();
00078 }
00079
00080
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
00094 if (themepath==initialGroup) {
00095
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
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
00126
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"