allow installing an uncompressed package as well

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=792006
This commit is contained in:
Aaron J. Seigo 2008-03-30 22:27:32 +00:00
parent bd671a7c8a
commit a17a25a3b3

View File

@ -218,17 +218,32 @@ bool Package::installPackage(const QString& package,
} }
} }
if (!QFile::exists(package)) { QFileInfo fileInfo(package);
if (!fileInfo.exists()) {
kWarning(505) << "No such file:" << package; kWarning(505) << "No such file:" << package;
return false; return false;
} }
QString path;
KTempDir tempdir;
bool archivedPackage = false;
if (fileInfo.isDir()) {
// we have a directory, so let's just install what is in there
path = package;
// make sure we end in a slash!
if (path[path.size() - 1] != '/') {
path.append('/');
}
} else {
KZip archive(package); KZip archive(package);
if (!archive.open(QIODevice::ReadOnly)) { if (!archive.open(QIODevice::ReadOnly)) {
kWarning(505) << "Could not open package file:" << package; kWarning(505) << "Could not open package file:" << package;
return false; return false;
} }
archivedPackage = true;
const KArchiveDirectory* source = archive.directory(); const KArchiveDirectory* source = archive.directory();
const KArchiveEntry* metadata = source->entry("metadata.desktop"); const KArchiveEntry* metadata = source->entry("metadata.desktop");
@ -237,15 +252,16 @@ bool Package::installPackage(const QString& package,
return false; return false;
} }
QFile f(package); path = tempdir.name();
KTempDir tempdir; source->copyTo(path);
source->copyTo(tempdir.name()); }
QString metadataPath = tempdir.name() + "metadata.desktop"; QString metadataPath = path + "metadata.desktop";
if (!QFile::exists(metadataPath)) { if (!QFile::exists(metadataPath)) {
kWarning(505) << "No metadata file in package" << package; kWarning(505) << "No metadata file in package" << package;
return false; return false;
} }
PackageMetadata meta(metadataPath); PackageMetadata meta(metadataPath);
QString targetName = meta.pluginName(); QString targetName = meta.pluginName();
@ -260,15 +276,26 @@ bool Package::installPackage(const QString& package,
return false; return false;
} }
KIO::FileCopyJob* job = KIO::file_move(tempdir.name(), targetName, -1, KIO::HideProgressInfo); KIO::FileCopyJob* job(0);
if (archivedPackage) {
// it's in a temp dir, so just move it over.
job = KIO::file_move(path, targetName, -1, KIO::HideProgressInfo);
} else {
// it's a directory containing the stuff, so copy the contents rather
// than move them
job = KIO::file_copy(path, targetName, -1, KIO::HideProgressInfo);
}
if (!job->exec()) { if (!job->exec()) {
kWarning(505) << "Could not move package to destination:" << targetName; kWarning(505) << "Could not move package to destination:" << targetName;
return false; return false;
} }
// no need to remove the temp dir (which has been moved) if (archivedPackage) {
// no need to remove the temp dir (which has been successfully moved if it's an archive)
tempdir.setAutoRemove(false); tempdir.setAutoRemove(false);
}
// and now we register it as a service =) // and now we register it as a service =)
targetName.append("/metadata.desktop"); targetName.append("/metadata.desktop");