themesdlg.cpp

00001 /*
00002  * Copyright (C) 2005 Petri Damstén <petri.damsten@iki.fi>
00003  *
00004  * This file is part of SuperKaramba.
00005  *
00006  *  SuperKaramba is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  SuperKaramba is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with SuperKaramba; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  ****************************************************************************/
00020 #include "karambaapp.h"
00021 #include "dcopinterface_stub.h"
00022 #include "karambainterface.h"
00023 #include "themesdlg.h"
00024 #include "themewidget.h"
00025 #include "kwidgetlistbox.h"
00026 #include "karamba.h"
00027 
00028 #ifdef HAVE_CONFIG_H
00029   #include <config.h>
00030 #endif
00031 
00032 #ifdef HAVE_KNEWSTUFF
00033   #include "sknewstuff.h"
00034 #endif
00035 
00036 #include "superkarambasettings.h"
00037 #include <karchive.h>
00038 #include <kdebug.h>
00039 #include <kfiledialog.h>
00040 #include <kpushbutton.h>
00041 #include <kstandarddirs.h>
00042 #include <kapplication.h>
00043 #include <kiconloader.h>
00044 #include <klocale.h>
00045 #include <qlineedit.h>
00046 #include <qtable.h>
00047 #include <qdir.h>
00048 #include <qlabel.h>
00049 #include <qcombobox.h>
00050 #include <qptrlist.h>
00051 #include <kio/job.h>
00052 #include <kprotocolinfo.h>
00053 
00054 ThemesDlg::ThemesDlg(QWidget *parent, const char *name)
00055  : ThemesLayout(parent, name)
00056 {
00057   populateListbox();
00058 #ifdef HAVE_KNEWSTUFF
00059   mNewStuff = 0;
00060 #endif
00061 }
00062 
00063 ThemesDlg::~ThemesDlg()
00064 {
00065   //kdDebug() << k_funcinfo << endl;
00066   saveUserAddedThemes();
00067 #ifdef HAVE_KNEWSTUFF
00068   if(mNewStuff)
00069   {
00070     delete mNewStuff;
00071   }
00072 #endif
00073 }
00074 
00075 void ThemesDlg::saveUserAddedThemes()
00076 {
00077   KStandardDirs ksd;
00078   QStringList t = themes();
00079   QStringList dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00080   QStringList::Iterator it = t.begin();
00081   bool remove;
00082 
00083   while(it != t.end())
00084   {
00085     remove = false;
00086     QStringList::Iterator jtend( dirs.end() );
00087     for(QStringList::Iterator jt = dirs.begin(); jt != jtend; ++jt)
00088     {
00089       if(QFileInfo(*it).dir().path() + "/" == *jt)
00090       {
00091         remove = true;
00092         break;
00093       }
00094     }
00095     if(remove)
00096       it = t.remove(it);
00097     else
00098       ++it;
00099   }
00100   SuperKarambaSettings::setUserAddedThemes(t);
00101   SuperKarambaSettings::writeConfig();
00102 }
00103 
00104 QStringList ThemesDlg::themes()
00105 {
00106   QStringList result;
00107   ThemeWidget* w;
00108 
00109   for(uint i = 2; i < tableThemes->count(); ++i)
00110   {
00111     w = static_cast<ThemeWidget*>(tableThemes->item(i));
00112 
00113     result.append(w->themeFile()->file());
00114   }
00115   return result;
00116 }
00117 
00118 void ThemesDlg::populateListbox()
00119 {
00120   ThemeWidget* item;
00121   QDir dir;
00122   QStringList dirs;
00123   QStringList t;
00124   KStandardDirs ksd;
00125 
00126   tableThemes->clear();
00127 
00128   item = new ThemeWidget;
00129   item->icon->setPixmap(KGlobal::iconLoader()->loadIcon("knewstuff",
00130                         KIcon::NoGroup, KIcon::SizeHuge));
00131   item->setHeaderText(i18n("Get New Stuff"));
00132   item->setDescriptionText(i18n("Download new themes."));
00133 
00134   item->buttonGo->setText(i18n("New Stuff..."));
00135 #ifdef HAVE_KNEWSTUFF
00136   item->buttonGo->setEnabled(true);
00137   connect(item->buttonGo, SIGNAL(clicked()),
00138           this, SLOT(getNewStuff()));
00139 #else
00140   item->buttonGo->setEnabled(false);
00141 #endif
00142   tableThemes->insertItem(item);
00143 
00144   item = new ThemeWidget;
00145   item->icon->setPixmap(KGlobal::iconLoader()->loadIcon("ksysguard",
00146                         KIcon::NoGroup, KIcon::SizeHuge));
00147   item->setHeaderText(i18n("Open Local Theme"));
00148   item->setDescriptionText(i18n("Add local theme to the list."));
00149   item->buttonGo->setProperty("stdItem", 18);
00150   item->buttonGo->setText(i18n("Open..."));
00151   connect(item->buttonGo, SIGNAL(clicked()),
00152           this, SLOT(openLocalTheme()));
00153   tableThemes->insertItem(item);
00154 
00155   dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00156   // Get custom dirs from config here?
00157   QStringList::Iterator itend( dirs.end() );
00158   for(QStringList::Iterator it = dirs.begin(); it != itend; ++it )
00159   {
00160     dir.setPath(*it);
00161     t = dir.entryList("*.skz; *.theme");
00162     for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00163     {
00164       item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
00165       tableThemes->insertItem(item);
00166       item->buttonGo->setText(i18n("Uninstall"));
00167       connect(item->buttonGo, SIGNAL(clicked()),
00168               this, SLOT(uninstall()));
00169     }
00170   }
00171   t = SuperKarambaSettings::userAddedThemes();
00172   for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00173   {
00174     ThemeFile* file = new ThemeFile(*it);
00175 
00176     if(file->isValid())
00177     {
00178       item = new ThemeWidget(file);
00179       tableThemes->insertItem(item);
00180       item->buttonGo->setText(i18n("Uninstall"));
00181       connect(item->buttonGo, SIGNAL(clicked()),
00182               this, SLOT(uninstall()));
00183     }
00184     else
00185       delete file;
00186   }
00187   tableThemes->setSelected(0);
00188 }
00189 
00190 void ThemesDlg::addToDesktop()
00191 {
00192   ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
00193   if(w)
00194   {
00195     ThemeFile* tf = w->themeFile();
00196     if(tf)
00197     {
00198       (new karamba(tf->file(), QString()))->show();
00199     }
00200   }
00201 }
00202 
00203 void ThemesDlg::openLocalTheme()
00204 {
00205   QStringList fileNames;
00206   fileNames = KFileDialog::getOpenFileNames(":<themes>",
00207                   i18n("*.theme *.skz|Themes"),
00208                   this, i18n("Open Themes"));
00209   for(QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
00210   {
00211     ThemeFile file(*it);
00212     if(file.isValid())
00213       (new karamba(*it, QString()))->show();
00214   }
00215 }
00216 
00217 void ThemesDlg::getNewStuff()
00218 {
00219 #ifdef HAVE_KNEWSTUFF
00220   KConfig* config = KGlobal::config();
00221   config->setGroup("KNewStuff");
00222   config->writePathEntry("ProvidersUrl",
00223       QString::fromLatin1("http://download.kde.org/khotnewstuff/karamba-providers.xml"));
00224   config->sync();
00225   m_newStuffStatus = config->entryMap("KNewStuffStatus").keys();
00226   //This check is b/c KNewStuff will download, throw an error, 
00227   //and still have the entry in the config that it was successful
00228   configSanityCheck();
00229 
00230   if ( !mNewStuff )
00231   {
00232     mNewStuff = new SKNewStuff(this);
00233   }
00234   mNewStuff->download/span> ( !mNewStu class="code" href="classThemeWidget.html#56f56f1e89c47186e8cabb2c69476dcf">setHeaderText(i18n("Open Local Theme"));
00148   item->setDescriptionText(i18n("Add local theme to the list."));
00149   item->buttonGo->setProperty("stdItem", 18);
00150   item->buttonGo->setText(i18n("Open..."));
00151   connect(item->buttonGo, SIGNAL(clicked()),
00152           this, SLOT(openLocalTheme()));
00153   tableThemes->insertItem(item);
00154 
00155   dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00156   // Get custom dirs from config here?
00157   QStringList::Iterator itend( dirs.end() );
00158   for(QStringList::Iterator it = dirs.begin(); it != itend; ++it )
00159   {
00160     dir.setPath(*it);
00161     t = dir.entryList("*.skz; *.theme");
00162     for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00163     {
00164       item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
00165       tableThemes->insertItem(item);
00166       item->buttonGo->setText(i18n("Uninstall"));
00167       connect(item->buttonGo, SIGNAL(clicked()),
00168               this, SLOT(uninstall()));
00169     }
00170   }
00171   t = SuperKarambaSettings::userAddedThemes();
00172   for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00173   {
00174     ThemeFile* file = new ThemeFile(*it);
00175 
00176     if(file->isValid())
00177     {
00178       item = new ThemeWidget(file);
00179       tableThemes->insertItem(item);
00180       item->buttonGo->setText(i18n("Uninstall"));
00181       connect(item->buttonGo, SIGNAL(clicked()),
00182               this, SLOT(uninstall()));
00183     }
00184     else
00185       delete file;
00186   }
00187   tableThemes->setSelected(0);
00188 }
00189 
00190 void ThemesDlg::addToDesktop()
00191 {
00192   ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
00193   if(w)
00194   {
00195     ThemeFile* tf = w->themeFile();
00196     if(tf)
00197     {
00198       (new karamba(tf->file(), QString()))->show();
00199     }
00200   }
00201 }
00202 
00203 void ThemesDlg::openLocalTheme()
00204 {
00205   QStringList fileNames;
00206   fileNames = KFileDialog::getOpenFileNames(":<themes>",
00207                   i18n("*.theme *.skz|Themes"),
00208                   this, i18n("Open Themes"));
00209   for(QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
00210   {
00211     ThemeFile file(*it);
00212     if(file.isValid())
00213       (new karamba(*it, QString()))->show();
00214   }
00215 }
00216 
00217 void ThemesDlg::getNewStuff()
00218 {
00219 #ifdef HAVE_KNEWSTUFF
00220   KConfig* config = KGlobal::config();
00221   config->setGroup("KNewStuff");
00222   config->writePathEntry("ProvidersUrl",
00223       QString::fromLatin1("http://download.kde.org/khotnewstuff/karamba-providers.xml"));
00224   config->sync();
00225   m_newStuffStatus = config->entryMap("KNewStuffStatus").keys();
00226   //This check is b/c KNewStuff will download, throw an error, 
00227   //and still have the entry in the config that it was successful
00228   configSanityCheck();
00229 
00230   if ( !mNewStuff )
00231   {
00232     mNewStuff = new SKNewStuff(this);
00233   }
00234   mNewStuff->download/span> ( !mNewStu class="code" href="classThemeWidget.html#56f56f1e89c47186e8cabb2c69476dcf">setHeaderText(i18n("Open Local Theme"));
00148   item->setDescriptionText(i18n("Add local theme to the list."));
00149   item->buttonGo->setProperty("stdItem", 18);
00150   item->buttonGo->setText(i18n("Open..."));
00151   connect(item->buttonGo, SIGNAL(clicked()),
00152           this, SLOT(openLocalTheme()));
00153   tableThemes->insertItem(item);
00154 
00155   dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00156   // Get custom dirs from config here?
00157   QStringList::Iterator itend( dirs.end() );
00158   for(QStringList::Iterator it = dirs.begin(); it != itend; ++it )
00159   {
00160     dir.setPath(*it);
00161     t = dir.entryList("*.skz; *.theme");
00162     for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00163     {
00164       item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
00165       tableThemes->insertItem(item);
00166       item->buttonGo->setText(i18n("Uninstall"));
00167       connect(item->buttonGo, SIGNAL(clicked()),
00168               this, SLOT(uninstall()));
00169     }
00170   }
00171   t = SuperKarambaSettings::userAddedThemes();
00172   for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00173   {
00174     ThemeFile* file = new ThemeFile(*it);
00175 
00176     if(file->isValid())
00177     {
00178       item = new ThemeWidget(file);
00179       tableThemes->insertItem(item);
00180       item->buttonGo->setText(i18n("Uninstall"));
00181       connect(item->buttonGo, SIGNAL(clicked()),
00182               this, SLOT(uninstall()));
00183     }
00184     else
00185       delete file;
00186   }
00187   tableThemes->setSelected(0);
00188 }
00189 
00190 void ThemesDlg::addToDesktop()
00191 {
00192   ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
00193   if(w)
00194   {
00195     ThemeFile* tf = w->themeFile();
00196     if(tf)
00197     {
00198       (new karamba(tf->file(), QString()))->show();
00199     }
00200   }
00201 }
00202 
00203 void ThemesDlg::openLocalTheme()
00204 {
00205   QStringList fileNames;
00206   fileNames = KFileDialog::getOpenFileNames(":<themes>",
00207                   i18n("*.theme *.skz|Themes"),
00208                   this, i18n("Open Themes"));
00209   for(QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
00210   {
00211     ThemeFile file(*it);
00212     if(file.isValid())
00213       (new karamba(*it, QString()))->show();
00214   }
00215 }
00216 
00217 void ThemesDlg::getNewStuff()
00218 {
00219 #ifdef HAVE_KNEWSTUFF
00220   KConfig* config = KGlobal::config();
00221   config->setGroup("KNewStuff");
00222   config->writePathEntry("ProvidersUrl",
00223       QString::fromLatin1("http://download.kde.org/khotnewstuff/karamba-providers.xml"));
00224   config->sync();
00225   m_newStuffStatus = config->entryMap("KNewStuffStatus").keys();
00226   //This check is b/c KNewStuff will download, throw an error, 
00227   //and still have the entry in the config that it was successful
00228   configSanityCheck();
00229 
00230   if ( !mNewStuff )
00231   {
00232     mNewStuff = new SKNewStuff(this);
00233   }
00234   mNewStuff->download/span> ( !mNewStu class="code" href="classThemeWidget.html#56f56f1e89c47186e8cabb2c69476dcf">setHeaderText(i18n("Open Local Theme"));
00148   item->setDescriptionText(i18n("Add local theme to the list."));
00149   item->buttonGo->setProperty("stdItem", 18);
00150   item->buttonGo->setText(i18n("Open..."));
00151   connect(item->buttonGo, SIGNAL(clicked()),
00152           this, SLOT(openLocalTheme()));
00153   tableThemes->insertItem(item);
00154 
00155   dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00156   // Get custom dirs from config here?
00157   QStringList::Iterator itend( dirs.end() );
00158   for(QStringList::Iterator it = dirs.begin(); it != itend; ++it )
00159   {
00160     dir.setPath(*it);
00161     t = dir.entryList("*.skz; *.theme");
00162     for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00163     {
00164       item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
00165       tableThemes->insertItem(item);
00166       item->buttonGo->setText(i18n("Uninstall"));
00167       connect(item->buttonGo, SIGNAL(clicked()),
00168               this, SLOT(uninstall()));
00169     }
00170   }
00171   t = SuperKarambaSettings::userAddedThemes();
00172   for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00173   {
00174     ThemeFile* file = new ThemeFile(*it);
00175 
00176     if(file->isValid())
00177     {
00178       item = new ThemeWidget(file);
00179       tableThemes->insertItem(item);
00180       item->buttonGo->setText(i18n("Uninstall"));
00181       connect(item->buttonGo, SIGNAL(clicked()),
00182               this, SLOT(uninstall()));
00183     }
00184     else
00185       delete file;
00186   }
00187   tableThemes->setSelected(0);
00188 }
00189 
00190 void ThemesDlg::addToDesktop()
00191 {
00192   ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
00193   if(w)
00194   {
00195     ThemeFile* tf = w->themeFile();
00196     if(tf)
00197     {
00198       (new karamba(tf->file(), QString()))->show();
00199     }
00200   }
00201 }
00202 
00203 void ThemesDlg::openLocalTheme()
00204 {
00205   QStringList fileNames;
00206   fileNames = KFileDialog::getOpenFileNames(":<themes>",
00207                   i18n("*.theme *.skz|Themes"),
00208                   this, i18n("Open Themes"));
00209   for(QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
00210   {
00211     ThemeFile file(*it);
00212     if(file.isValid())
00213       (new karamba(*it, QString()))->show();
00214   }
00215 }
00216 
00217 void ThemesDlg::getNewStuff()
00218 {
00219 #ifdef HAVE_KNEWSTUFF
00220   KConfig* config = KGlobal::config();
00221   config->setGroup("KNewStuff");
00222   config->writePathEntry("ProvidersUrl",
00223       QString::fromLatin1("http://download.kde.org/khotnewstuff/karamba-providers.xml"));
00224   config->sync();
00225   m_newStuffStatus = config->entryMap("KNewStuffStatus").keys();
00226   //This check is b/c KNewStuff will download, throw an error, 
00227   //and still have the entry in the config that it was successful
00228   configSanityCheck();
00229 
00230   if ( !mNewStuff )
00231   {
00232     mNewStuff = new SKNewStuff(this);
00233   }
00234   mNewStuff->download/span> ( !mNewStu class="code" href="classThemeWidget.html#56f56f1e89c47186e8cabb2c69476dcf">setHeaderText(i18n("Open Local Theme"));
00148   item->setDescriptionText(i18n("Add local theme to the list."));
00149   item->buttonGo->setProperty("stdItem", 18);
00150   item->buttonGo->setText(i18n("Open..."));
00151   connect(item->buttonGo, SIGNAL(clicked()),
00152           this, SLOT(openLocalTheme()));
00153   tableThemes->insertItem(item);
00154 
00155   dirs = ksd.findDirs("data", QString(kapp->name()) + "/themes");
00156   // Get custom dirs from config here?
00157   QStringList::Iterator itend( dirs.end() );
00158   for(QStringList::Iterator it = dirs.begin(); it != itend; ++it )
00159   {
00160     dir.setPath(*it);
00161     t = dir.entryList("*.skz; *.theme");
00162     for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00163     {
00164       item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
00165       tableThemes->insertItem(item);
00166       item->buttonGo->setText(i18n("Uninstall"));
00167       connect(item->buttonGo, SIGNAL(clicked()),
00168               this, SLOT(uninstall()));
00169     }
00170   }
00171   t = SuperKarambaSettings::userAddedThemes();
00172   for(QStringList::Iterator it = t.begin(); it != t.end(); ++it )
00173   {
00174     ThemeFile* file = new ThemeFile(*it);
00175 
00176     if(file->isValid())
00177     {
00178       item = new ThemeWidget(file);
00179       tableThemes->insertItem(item);
00180       item->buttonGo->setText(i18n("Uninstall"));
00181       connect(item->buttonGo, SIGNAL(clicked()),
00182               this, SLOT(uninstall()));
00183     }
00184     else
00185       delete file;
00186   }
00187   tableThemes->setSelected(0);
00188 }
00189 
00190 void ThemesDlg::addToDesktop()
00191 {
00192   ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
00193   if(w)
00194   {
00195     ThemeFile* tf = w->themeFile();
00196     if(tf)
00197     {
00198       (new karamba(tf->file(), QString()))->show();
00199     }
00200   }
00201 }
00202 
00203 void ThemesDlg::openLocalTheme()
00204 {
00205   QStringList fileNames;
00206   fileNames = KFileDialog::getOpenFileNames(":<themes>",
00207                   i18n("*.theme *.skz|Themes"),
00208                   this, i18n("Open Themes"));
00209   for(QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
00210   {
00211     ThemeFile file(*it);
00212     if(file.isValid())
00213       (new karamba(*it, QString()))->show();
00214   }
00215 }
00216 
00217 void ThemesDlg::getNewStuff()
00218 {
00219 #ifdef HAVE_KNEWSTUFF
00220   KConfig* config = KGlobal::config();
00221   config->setGroup("KNewStuff");
00222   config->writePathEntry("ProvidersUrl",
00223       QString::fromLatin1("http://download.kde.org/khotnewstuff/karamba-providers.xml"));
00224   config->sync();
00225   m_newStuffStatus = config->entryMap("KNewStuffStatus").keys();
00226   //This check is b/c KNewStuff will download, throw an error, 
00227   //and still have the entry in the config that it was successful
00228   configSanityCheck();
00229 
00230   if ( !mNewStuff )
00231   {
00232     mNewStuff = new SKNewS