bool IconThemesConfig::installThemes(const QStringList &themes, const QString &archiveName) { bool everythingOk = true; QString localThemesDir(locateLocal("icon", "./")); KProgressDialog progressDiag(this, "themeinstallprogress", i18n("Installing icon themes"), QString::null, true); progressDiag.setAutoClose(true); progressDiag.progressBar()->setTotalSteps(themes.count()); progressDiag.show(); KTar archive(archiveName); archive.open(IO_ReadOnly); kapp->processEvents(); const KArchiveDirectory* rootDir = archive.directory(); KArchiveDirectory* currentTheme; for (QStringList::ConstIterator it = themes.begin(); it != themes.end(); ++it) { progressDiag.setLabel( i18n("<qt>Installing <strong>%1</strong> theme</qt>") .arg(*it)); kapp->processEvents(); if (progressDiag.wasCancelled()) break; currentTheme = dynamic_cast<KArchiveDirectory*>( const_cast<KArchiveEntry*>( rootDir->entry(*it))); if (currentTheme == NULL) { // we tell back that something went wrong, but try to install as much // as possible everythingOk = false; continue; } currentTheme->copyTo(localThemesDir + *it); progressDiag.progressBar()->advance(1); } archive.close(); return everythingOk; }
QStringList KEmoticons::installTheme(const QString &archiveName) { QStringList foundThemes; KArchiveEntry *currentEntry = 0L; KArchiveDirectory* currentDir = 0L; KArchive *archive = 0L; QString localThemesDir(KStandardDirs::locateLocal("emoticons", QString())); if (localThemesDir.isEmpty()) { kError() << "Could not find a suitable place in which to install the emoticon theme"; return QStringList(); } const QString currentBundleMimeType = KMimeType::findByPath(archiveName, 0, false)->name(); if (currentBundleMimeType == "application/zip" || currentBundleMimeType == "application/x-zip" || currentBundleMimeType == "application/x-zip-compressed") { archive = new KZip(archiveName); } else if (currentBundleMimeType == "application/x-compressed-tar" || currentBundleMimeType == "application/x-bzip-compressed-tar" || currentBundleMimeType == "application/x-lzma-compressed-tar" || currentBundleMimeType == "application/x-xz-compressed-tar" || currentBundleMimeType == "application/x-gzip" || currentBundleMimeType == "application/x-bzip" || currentBundleMimeType == "application/x-lzma" || currentBundleMimeType == "application/x-xz") { archive = new KTar(archiveName); } else if (archiveName.endsWith(QLatin1String("jisp")) || archiveName.endsWith(QLatin1String("zip"))) { archive = new KZip(archiveName); } else { archive = new KTar(archiveName); } if (!archive || !archive->open(QIODevice::ReadOnly)) { kError() << "Could not open" << archiveName << "for unpacking"; delete archive; return QStringList(); } const KArchiveDirectory* rootDir = archive->directory(); // iterate all the dirs looking for an emoticons.xml file const QStringList entries = rootDir->entries(); for (QStringList::ConstIterator it = entries.begin(); it != entries.end(); ++it) { currentEntry = const_cast<KArchiveEntry*>(rootDir->entry(*it)); if (currentEntry->isDirectory()) { currentDir = dynamic_cast<KArchiveDirectory*>(currentEntry); for (int i = 0; i < d->m_loaded.size(); ++i) { QString fName = d->m_loaded.at(i)->property("X-KDE-EmoticonsFileName").toString(); if (currentDir && currentDir->entry(fName) != NULL) { foundThemes.append(currentDir->name()); } } } } if (foundThemes.isEmpty()) { kError() << "The file" << archiveName << "is not a valid emoticon theme archive"; archive->close(); delete archive; return QStringList(); } for (int themeIndex = 0; themeIndex < foundThemes.size(); ++themeIndex) { const QString &theme = foundThemes[themeIndex]; currentEntry = const_cast<KArchiveEntry *>(rootDir->entry(theme)); if (currentEntry == 0) { kDebug() << "couldn't get next archive entry"; continue; } if (currentEntry->isDirectory()) { currentDir = dynamic_cast<KArchiveDirectory*>(currentEntry); if (currentDir == 0) { kDebug() << "couldn't cast archive entry to KArchiveDirectory"; continue; } currentDir->copyTo(localThemesDir + theme); } } archive->close(); delete archive; return foundThemes; }