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 ui.themeList->sortItems();
00106
00107 connect(ui.themeList, SIGNAL(currentItemChanged ( QListWidgetItem * , QListWidgetItem * )), q, SLOT(_k_updatePreview()));
00108 connect(ui.getNewButton, SIGNAL(clicked()), q, SLOT(_k_openKNewStuffDialog()));
00109 }
00110
00111 void KGameThemeSelector::KGameThemeSelectorPrivate::_k_updatePreview()
00112 {
00113 KGameTheme * seltheme = themeMap.value(ui.themeList->currentItem()->text());
00114
00115 if (!seltheme) return;
00116 if (seltheme->path() == ui.kcfg_Theme->text()) {
00117 return;
00118 }
00119 ui.kcfg_Theme->setText(seltheme->fileName());
00120
00121 QString authstr("Author");
00122 QString contactstr("AuthorEmail");
00123 QString descstr("Description");
00124 QString emailstr;
00125 if (!seltheme->themeProperty(contactstr).isEmpty() ) {
00126 emailstr = QString("<a href=\"mailto:%1\">%1</a>").arg(seltheme->themeProperty(contactstr));
00127 }
00128
00129 ui.themeAuthor->setText(seltheme->themeProperty(authstr));
00130 ui.themeContact->setText(emailstr);
00131 ui.themeDescription->setText(seltheme->themeProperty(descstr));
00132
00133
00134
00135 ui.themePreview->setPixmap(seltheme->preview());
00136
00137 }
00138
00139 void KGameThemeSelector::KGameThemeSelectorPrivate::_k_openKNewStuffDialog()
00140 {
00141 KNS::Entry::List entries = KNS::Engine::download();
00142 }
00143
00144 #include "kgamethemeselector.moc"