* make it possible to install packages without registering them as a service
* support tar and compressed tar as well as zip * support archives that contain the actual package in a top level subdir themes and wallpapers now install nicely. svn path=/branches/KDE/4.3/kdelibs/; revision=1002169
This commit is contained in:
parent
2ac54f8f19
commit
55fd81456f
40
package.cpp
40
package.cpp
@ -31,8 +31,10 @@
|
||||
#include <kio/deletejob.h>
|
||||
#include <kio/jobclasses.h>
|
||||
#include <kio/job.h>
|
||||
#include <kmimetype.h>
|
||||
#include <kplugininfo.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <ktar.h>
|
||||
#include <ktempdir.h>
|
||||
#include <ktemporaryfile.h>
|
||||
#include <kzip.h>
|
||||
@ -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,6 +338,7 @@ bool Package::installPackage(const QString &package,
|
||||
tempdir.setAutoRemove(false);
|
||||
}
|
||||
|
||||
if (!servicePrefix.isEmpty()) {
|
||||
// and now we register it as a service =)
|
||||
QString metaPath = targetName + "/metadata.desktop";
|
||||
KDesktopFile df(metaPath);
|
||||
@ -351,6 +368,7 @@ bool Package::installPackage(const QString &package,
|
||||
} else {
|
||||
kWarning() << "Could not register package as service (this is not necessarily fatal):" << serviceName << " : " << job->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user