29 #include <KFileDialog>
30 #include <KStandardDirs>
31 #include <KIconLoader>
32 #include <KIO/CopyJob>
35 #include <KIO/NetAccess>
40 m_newStuffInitialized(false)
43 setObjectName( QLatin1String( name ) );
47 connect(buttonAddToDesktop, SIGNAL(clicked()),
this, SLOT(
addToDesktop()));
48 connect(tableThemes, SIGNAL(selected(
int)),
this, SLOT(
selectionChanged(
int)));
50 connect(editSearch, SIGNAL(textChanged(QString)),
this, SLOT(
search(QString)));
51 connect(comboShow, SIGNAL(activated(QString)),
this, SLOT(
search(QString)));
64 QStringList dirs = ksd.findDirs(
"data", QString(kapp->objectName()) +
"/themes");
65 QStringList::Iterator it = t.begin();
68 while (it != t.end()) {
70 QStringList::Iterator jtend(dirs.end());
71 for (QStringList::Iterator jt = dirs.begin(); jt != jtend; ++jt) {
72 if (QString(QFileInfo(*it).dir().path() +
'/') == *jt) {
91 for (uint i = 2; i < tableThemes->count(); ++i) {
107 tableThemes->clear();
111 item->iconLabel->setPixmap(KIconLoader::global()->loadIcon(
"get-hot-new-stuff",
112 KIconLoader::NoGroup, KIconLoader::SizeHuge));
116 item->buttonGo->setText(i18n(
"New Stuff..."));
117 item->buttonGo->setEnabled(
true);
118 QObject::connect(item->buttonGo, SIGNAL(clicked()),
121 tableThemes->insertItem((
QWidget*)(item));
124 item->iconLabel->setPixmap(KIconLoader::global()->loadIcon(
"document-open",
125 KIconLoader::NoGroup, KIconLoader::SizeHuge));
128 item->buttonGo->setProperty(
"stdItem", 18);
129 item->buttonGo->setText(i18nc(
"Open theme button",
"Open..."));
130 QObject::connect((
QObject*)(item->buttonGo), SIGNAL(clicked()),
132 tableThemes->insertItem((
QWidget*)item);
134 dirs = ksd.findDirs(
"data", QString(kapp->objectName()) +
"/themes");
136 QStringList::Iterator itend(dirs.end());
137 for (QStringList::Iterator it = dirs.begin(); it != itend; ++it) {
139 types <<
"*.skz" <<
"*.theme";
143 t = dir.entryList(types);
144 for (QStringList::Iterator it = t.begin(); it != t.end(); ++it) {
146 tableThemes->insertItem((
QWidget*)item);
147 item->buttonGo->setText(i18n(
"Uninstall"));
148 QObject::connect((
QObject*)item->buttonGo, SIGNAL(clicked()),
153 for (QStringList::Iterator it = t.begin(); it != t.end(); ++it) {
158 tableThemes->insertItem((
QWidget*)item);
159 item->buttonGo->setText(i18n(
"Uninstall"));
160 QObject::connect((
QObject*)item->buttonGo, SIGNAL(clicked()),
165 tableThemes->setSelected(0);
191 QStringList fileNames;
192 fileNames = KFileDialog::getOpenFileNames(KUrl(),
193 i18n(
"*.theme *.skz|Themes"),
194 (
QWidget*)
this, i18n(
"Open Themes"));
196 for (QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
206 if (!m_newStuffInitialized) {
207 KDirWatch *dirWatch = KDirWatch::self();
208 connect(dirWatch, SIGNAL(created(QString)),
211 QString destDir = KStandardDirs::locateLocal(
"appdata",
"themes/");
212 dirWatch->addDir(destDir, KDirWatch::WatchFiles);
214 m_newStuffInitialized =
true;
217 KNS::Engine::download();
224 KMimeType::Ptr result;
226 result = KMimeType::findByUrl(newTheme);
227 }
while (result->name() ==
"application/x-zerosize");
229 if (result->name() ==
"application/x-gzip" ||
230 result->name() ==
"application/x-compressed-tar" ||
231 result->name() ==
"application/x-bzip" ||
232 result->name() ==
"application/x-bzip" ||
233 result->name() ==
"application/x-bzip-compressed-tar" ||
234 result->name() ==
"application/x-bzip-compressed-tar2" ||
235 result->name() ==
"application/x-tar" ||
236 result->name() ==
"application/x-tarz") {
238 kDebug() <<
"SKNewStuff::install() gzip/bzip2 mimetype encountered" << endl;
240 KTar archive(newTheme);
241 if (!archive.open(QIODevice::ReadOnly)) {
245 QString destDir = KStandardDirs::locateLocal(
"appdata",
"themes/");
247 const KArchiveDirectory *archiveDir = archive.directory();
248 archiveDir->copyTo(destDir);
252 }
else if (result->name() ==
"application/zip" ||
253 result->name() ==
"application/x-superkaramba") {
255 kDebug() <<
"SKNewStuff::install() zip mimetype encountered" << endl;
262 }
else if (result->name() ==
"plain/text") {
263 kDebug() <<
"SKNewStuff::install() plain text" << endl;
264 }
else if (result->name() ==
"text/html" ||
265 result->name() ==
"application/x-php") {
267 kDebug() <<
"SKNewStuff::install() text/html" << endl;
268 KRun::runUrl(newTheme,
"text/html", 0);
270 kDebug() <<
"SKNewStuff::install() Error no compatible mimetype encountered to install" << endl;
277 buttonAddToDesktop->setEnabled(index > 1);
279 for (uint i = 2; i < tableThemes->count(); ++i) {
294 for (uint i = 2; i < tableThemes->count(); ++i) {
310 const QString& destDir)
312 kDebug() <<
"addThemeToDialog(): destDir = " << destDir ;
313 QStringList entries = archiveDir->entries();
315 QStringList::Iterator end(entries.end());
316 for (QStringList::Iterator it = entries.begin(); it != end; ++it) {
317 if (archiveDir->entry(*it)->isDirectory()) {
318 addThemeToDialog(static_cast<const KArchiveDirectory*>(archiveDir->entry(*it)),
319 destDir + *it +
'/');
322 if (fi.suffix() ==
"theme") {
331 kDebug() <<
"addThemeToList() file: " << file ;
336 i = tableThemes->insertItem((
QWidget*)item);
337 item->buttonGo->setText(i18n(
"Uninstall"));
338 QObject::connect((
QObject*)item->buttonGo, SIGNAL(clicked()),
341 tableThemes->setSelected(i);
370 tableThemes->showItems(&
filter,
this);
381 if (dlg->comboShow->currentIndex() == 1)
385 QString searchText = dlg->editSearch->text().toLower();
386 if (searchText.isEmpty()) {
389 if (w->themeName->text().toLower().contains(searchText))
391 if (w->description->text().toLower().contains(searchText))
399 kDebug() <<
"isDownloaded path: " << path ;
400 KSharedConfigPtr config = KGlobal::config();
401 return !config->group(
"KNewStuffNames").readEntry(path, QString()).isEmpty();
408 KUrl theme(tf->
file());
409 QString tempPath(tf->
path());
414 kDebug() <<
"encountered unpacked theme" ;
417 QFileInfo remPath(tf->
path());
418 QDir remDir(remPath.dir());
420 kDebug() <<
"moving " << remDir.path() <<
" to the trash" ;
421 KIO::trash(remDir.path());
423 tableThemes->removeItem((
QWidget*)w);
427 QList<ThemeWidget*> list;
428 for (uint i = 2; i < tableThemes->count(); ++i) {
431 if (tempTf->
path().compare(tempPath) == 0) {
437 tableThemes->removeItem((
QWidget*)twPtr);
440 KSharedConfigPtr config = KGlobal::config();
441 QString name = config->group(
"KNewStuffNames").readEntry(tempPath, QString());
442 if (!name.isEmpty()) {
444 kDebug() <<
"removing " << tempPath <<
" under KNewStuffNames from superkarambarc"
446 KGlobal::config()->group(
"KNewStuffNames").deleteEntry(tempPath);
447 kDebug() <<
"removing " << name <<
" under KNewStuffStatus from superkarambarc"
449 KGlobal::config()->group(
"KNewStuffStatus").deleteEntry(name);
450 KGlobal::config()->sync();
453 kDebug() <<
"encountered skz theme" ;
455 QFileInfo remPath(theme.path());
456 QDir remDir(remPath.dir());
457 kDebug() <<
"moving " << remDir.path() <<
" to the trash" ;
458 KIO::trash(remDir.path());
460 tableThemes->removeItem((
QWidget*)w);
462 KSharedConfigPtr config = KGlobal::config();
463 QString name = config->group(
"KNewStuffNames").readEntry(theme.path(), QString());
464 if (!name.isEmpty()) {
465 kDebug() <<
"removing " << theme.path() <<
" from superkarambarc" ;
466 KGlobal::config()->group(
"KNewStuffNames").deleteEntry(theme.path());
467 kDebug() <<
"removing " << name <<
" from superkarambarc" ;
468 KGlobal::config()->group(
"KNewStuffStatus").deleteEntry(name);
469 KGlobal::config()->sync();
480 for (uint i = 2; i < tableThemes->count(); ++i) {
489 #include "themesdlg.moc"
virtual void addToDesktop()
const QString & file() const
void saveUserAddedThemes()
static QString canonicalFile(const QString &file)
static QStringList userAddedThemes()
Get Themes that user added to theme list.
virtual void openLocalTheme()
bool isDownloaded(const QString &path)
ThemesDlg(QWidget *parent=0, const char *name=0)
virtual void selectionChanged(int)
void addThemeToDialog(const KArchiveDirectory *archiveDir, const QString &destDir)
const QString & name() const
virtual void installNewTheme(const QString &newTheme)
static void setUserAddedThemes(const QStringList &v)
Set Themes that user added to theme list.
int themeIndex(const QString &file)
int addTheme(const QString &appId, const QString &file)
void removeTheme(const QString &appId, const QString &file, int instance)
static SuperKarambaSettings * self()
virtual void getNewStuff()
static bool filter(int index, QWidget *widget, void *data)
const QString & path() const
bool canUninstall() const
void addSkzThemeToDialog(const QString &file)
virtual void search(const QString &text)
QStringList runningThemes()
int addThemeToList(const QString &file)