[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/plasma
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2009-07-25 9:34:21
Message-ID: 1248514461.233636.10598.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1002165 by aseigo:

* make it possibl 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.


 M  +51 -33    package.cpp  
 M  +3 -1      package.h  


--- trunk/KDE/kdelibs/plasma/package.cpp #1002164:1002165
@@ -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 @@
             path.append('/');
         }
     } else {
-        KZip archive(package);
-        if (!archive.open(QIODevice::ReadOnly)) {
-            kWarning() << "Could not open package file:" << package;
+        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;
         }
 
-        archivedPackage = true;
-        const KArchiveDirectory *source = archive.directory();
-        const KArchiveEntry *metadata = source->entry("metadata.desktop");
-
-        if (!metadata) {
-            kWarning() << "No metadata file in package" << package;
+        if (!archive->open(QIODevice::ReadOnly)) {
+            kWarning() << "Could not open package file:" << package;
             return false;
         }
 
+        archivedPackage = true;
         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 @@
         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;
--- trunk/KDE/kdelibs/plasma/package.h #1002164:1002165
@@ -143,7 +143,9 @@
          * @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,


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic