diff --git a/package.cpp b/package.cpp index a1885c413..56f5405c3 100644 --- a/package.cpp +++ b/package.cpp @@ -31,8 +31,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -253,28 +255,42 @@ bool Package::installPackage(const QString &package, path.append('/'); } } else { - KZip archive(package); - if (!archive.open(QIODevice::ReadOnly)) { + KArchive *archive = 0; + KMimeType::Ptr mimetype = KMimeType::findByPath(package); + + if (mimetype->is("application/zip")) { + archive = new KZip(package); + } else if (mimetype->is("application/x-compressed-tar") || + mimetype->is("application/x-tar")) { + archive = new KTar(package); + } else { + kWarning() << "Could not open package file, unsupported archive format:" << package << mimetype->name(); + return false; + } + + if (!archive->open(QIODevice::ReadOnly)) { kWarning() << "Could not open package file:" << package; return false; } archivedPackage = true; - const KArchiveDirectory *source = archive.directory(); - const KArchiveEntry *metadata = source->entry("metadata.desktop"); - - if (!metadata) { - kWarning() << "No metadata file in package" << package; - return false; - } - path = tempdir.name(); + + const KArchiveDirectory *source = archive->directory(); source->copyTo(path); + + QStringList entries = source->entries(); + if (entries.count() == 1) { + const KArchiveEntry *entry = source->entry(entries[0]); + if (entry->isDirectory()) { + path.append(entry->name()).append("/"); + } + } } QString metadataPath = path + "metadata.desktop"; if (!QFile::exists(metadataPath)) { - kWarning() << "No metadata file in package" << package; + kWarning() << "No metadata file in package" << package << metadataPath; return false; } @@ -322,34 +338,36 @@ bool Package::installPackage(const QString &package, tempdir.setAutoRemove(false); } - // and now we register it as a service =) - QString metaPath = targetName + "/metadata.desktop"; - KDesktopFile df(metaPath); - KConfigGroup cg = df.desktopGroup(); + if (!servicePrefix.isEmpty()) { + // and now we register it as a service =) + QString metaPath = targetName + "/metadata.desktop"; + KDesktopFile df(metaPath); + KConfigGroup cg = df.desktopGroup(); - // Q: should not installing it as a service disqualify it? - // Q: i don't think so since KServiceTypeTrader may not be - // used by the installing app in any case, and the - // package is properly installed - aseigo + // Q: should not installing it as a service disqualify it? + // Q: i don't think so since KServiceTypeTrader may not be + // used by the installing app in any case, and the + // package is properly installed - aseigo - //TODO: reduce code duplication with registerPackage below + //TODO: reduce code duplication with registerPackage below - QString serviceName = servicePrefix + meta.pluginName(); + QString serviceName = servicePrefix + meta.pluginName(); - QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop"); - KIO::FileCopyJob *job = KIO::file_copy(metaPath, service, -1, KIO::HideProgressInfo); - if (job->exec()) { - // the icon in the installed file needs to point to the icon in the - // installation dir! - QString iconPath = targetName + '/' + cg.readEntry("Icon"); - QFile icon(iconPath); - if (icon.exists()) { - KDesktopFile df(service); - KConfigGroup cg = df.desktopGroup(); - cg.writeEntry("Icon", iconPath); + QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop"); + KIO::FileCopyJob *job = KIO::file_copy(metaPath, service, -1, KIO::HideProgressInfo); + if (job->exec()) { + // the icon in the installed file needs to point to the icon in the + // installation dir! + QString iconPath = targetName + '/' + cg.readEntry("Icon"); + QFile icon(iconPath); + if (icon.exists()) { + KDesktopFile df(service); + KConfigGroup cg = df.desktopGroup(); + cg.writeEntry("Icon", iconPath); + } + } else { + kWarning() << "Could not register package as service (this is not necessarily fatal):" << serviceName << " : " << job->errorString(); } - } else { - kWarning() << "Could not register package as service (this is not necessarily fatal):" << serviceName << " : " << job->errorString(); } return true; diff --git a/package.h b/package.h index 78d2c65e8..7eb12632a 100644 --- a/package.h +++ b/package.h @@ -143,7 +143,9 @@ class PLASMA_EXPORT Package * @param packageRoot path to the directory where the package should be * installed to * @param servicePrefix the prefix for the desktop file, so as not to interfere - * with unrelated services (eg: "plasma-applet-") + * with unrelated services (eg: "plasma-applet-"). If no prefix + * is set (e.g. a QString() is passed in), then the package will NOT + * be registered as a service * @return true on successful installation, false otherwise **/ static bool installPackage(const QString &package,