From 1a84d94eeb0513efaf1f7ae0827bf8246e366de1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Thu, 28 Feb 2008 03:53:26 +0000 Subject: [PATCH] package structure appropriateness for dynamic packages svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=780124 --- appletbrowser.cpp | 31 ++++++++++++++------ package.cpp | 20 ++++++++++--- package.h | 10 +++++++ packagestructure.cpp | 22 ++++++++++++-- packagestructure.h | 20 +++++++++++-- servicetypes/plasma-packagestructure.desktop | 3 ++ 6 files changed, 87 insertions(+), 19 deletions(-) diff --git a/appletbrowser.cpp b/appletbrowser.cpp index 27e4b141d..b07adbe83 100644 --- a/appletbrowser.cpp +++ b/appletbrowser.cpp @@ -297,19 +297,26 @@ void AppletBrowserWidget::openWidgetFile() { KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure"); QStringList filters; - filters << ("*.plasmoid|Plasma Widget"); -/* + filters << i18nc("File dialog filter", "%1|PlasmaWidget", "*.plasma"); + QStringList mimetypes; + foreach (const KService::Ptr &offer, offers) { - QString glob = offer - QString filter( + //filters << offer->property("X-Plasma-PackageMimeFilter").toStringList(); + QString glob = offer->property("X-Plasma-PackageFileFilter").toString(); + + if (!glob.isEmpty()) { + glob = QString("%1|%2").arg(glob).arg(offer->name()); + filters << glob; + } } -*/ + + kDebug() << "filters are" << filters; KFileDialog fd(KUrl(), QString(), this); fd.setOperationMode(KFileDialog::Opening); fd.setMode(KFile::Files | KFile::ExistingOnly); - fd.setFilter(filters.join("\n")); + fd.setFilter(filters.join("\n"));// + mimetypes.join("\n")); fd.exec(); - kDebug() << "selected file" << fd.selectedUrl(); + kDebug() << "selected file" << fd.selectedUrl() << "of type" << fd.currentFilter(); } class AppletBrowser::Private @@ -335,7 +342,7 @@ void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *contain q->setButtons(KDialog::Apply | KDialog::Close | KDialog::User1); q->setButtonText(KDialog::Apply, i18n("Add Widget")); - q->setButtonText(KDialog::User1, i18n("Get New Widgets")); + q->setButtonText(KDialog::User1, i18n("Install New Widgets")); KMenu *widgetsMenu = new KMenu(i18n("Get New Widgets"), q); QAction *action = new QAction(KIcon("applications-internet"), @@ -344,7 +351,7 @@ void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *contain widgetsMenu->addAction(action); action = new QAction(KIcon("applications-internet"), - i18n("Load from file"), q); + i18n("Install from file"), q); connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile())); widgetsMenu->addAction(action); q->button(KDialog::User1)->setMenu(widgetsMenu); @@ -357,10 +364,16 @@ void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *contain q->setButtonWhatsThis(KDialog::User1, i18n("When clicking Get New Widgets, a dialog will open to allow you to download new widgets. You need to be connected to the Internet.")); connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet())); + + q->setInitialSize(QSize(400, 600)); + KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog"); + q->restoreDialogSize(cg); } AppletBrowser::~AppletBrowser() { + KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog"); + saveDialogSize(cg); } void AppletBrowser::setApplication(const QString& app) diff --git a/package.cpp b/package.cpp index d558ab390..d0a0f0ae3 100644 --- a/package.cpp +++ b/package.cpp @@ -59,21 +59,22 @@ public: delete metadata; } - const PackageStructure::Ptr structure; + PackageStructure::Ptr structure; QString basePath; bool valid; PackageMetadata *metadata; }; -Package::Package(const QString& packageRoot, const QString& package, - const PackageStructure::Ptr structure) +Package::Package(const QString& packageRoot, const QString& package, PackageStructure::Ptr structure) : d(new Private(structure, packageRoot + '/' + package)) { + structure->setPath(d->basePath); } -Package::Package(const QString &packagePath, const PackageStructure::Ptr structure) +Package::Package(const QString &packagePath, PackageStructure::Ptr structure) : d(new Private(structure, packagePath)) { + structure->setPath(d->basePath); } Package::~Package() @@ -159,12 +160,23 @@ QStringList Package::entryList(const char* fileType) const const PackageMetadata* Package::metadata() const { + //FIXME: this only works for native plasma packges; should fall back to... PackageStructure? if (!d->metadata) { d->metadata = new PackageMetadata(d->basePath + "metadata.desktop"); } return d->metadata; } +const QString Package::path() const +{ + return d->basePath; +} + +const PackageStructure::Ptr Package::structure() const +{ + return d->structure; +} + //TODO: provide a version of this that allows one to ask for certain types of packages, etc? // should we be using KService here instead/as well? QStringList Package::knownPackages(const QString& packageRoot) // static diff --git a/package.h b/package.h index 44fefe6a1..cea579a76 100644 --- a/package.h +++ b/package.h @@ -100,6 +100,16 @@ class PLASMA_EXPORT Package */ const PackageMetadata *metadata() const; + /** + * @return the path to the root of this particular package + */ + const QString path() const; + + /** + * @return the PackageStructure use in this Package + */ + const PackageStructure::Ptr structure() const; + /** * Returns a list of all installed packages * diff --git a/packagestructure.cpp b/packagestructure.cpp index 8ebcc2bc0..49148dbfe 100644 --- a/packagestructure.cpp +++ b/packagestructure.cpp @@ -60,10 +60,11 @@ class PackageStructure::Private { public: QString type; + QString path; QMap contents; QStringList mimetypes; static QHash structures; -}; + }; QHash PackageStructure::Private::structures; @@ -101,7 +102,6 @@ PackageStructure::Ptr PackageStructure::load(const QString &packageFormat) PackageStructure::Ptr structure(offer->createInstance(0, args, &error)); if (structure) { - Private::structures[packageFormat] = structure; return structure; } @@ -116,9 +116,9 @@ PackageStructure::Ptr PackageStructure::load(const QString &packageFormat) if (!configPath.isEmpty()) { KConfig config(configPath); structure->read(&config); + Private::structures[packageFormat] = structure; } - Private::structures[packageFormat] = structure; return structure; } @@ -279,6 +279,22 @@ QStringList PackageStructure::mimetypes(const char* key) const return it.value().mimetypes; } +void PackageStructure::setPath(const QString &path) +{ + d->path = path; + pathChanged(); +} + +QString PackageStructure::path() const +{ + return d->path; +} + +void PackageStructure::pathChanged() +{ + // Do nothing ... subclasses might, however. +} + void PackageStructure::read(const KConfigBase *config) { d->contents.clear(); diff --git a/packagestructure.h b/packagestructure.h index e17cd4164..b1899b81e 100644 --- a/packagestructure.h +++ b/packagestructure.h @@ -96,7 +96,7 @@ public: * @return a package that matches the format, if available. The caller * is responsible for deleting the object. */ - static PackageStructure::Ptr load(const QString &package); + static PackageStructure::Ptr load(const QString &packageFormat); /** * Type of package this structure describes @@ -192,6 +192,17 @@ public: **/ QStringList mimetypes(const char* key) const; + /** + * Sets the path to the package. Useful for package formats + * which do not have well defined contents prior to installation. + */ + void setPath(const QString &path); + + /** + * @return the path to the package, or QString() if none + */ + QString path() const; + /** * Read a package structure from a config file. */ @@ -206,12 +217,15 @@ public: * Installs a package matching this package structure. By default simply calls * Plasma::Package::install. * - * @param package path to the Plasmagik package + * @param archivePath path to the package archive file * @param packageRoot path to the directory where the package should be * installed to * @return true on successful installation, false otherwise **/ - virtual bool installPackage(const QString &package, const QString &packageRoot); + virtual bool installPackage(const QString &archivePath, const QString &packageRoot); + +protected: + virtual void pathChanged(); private: class Private; diff --git a/servicetypes/plasma-packagestructure.desktop b/servicetypes/plasma-packagestructure.desktop index 3de242023..e4b9bdd92 100644 --- a/servicetypes/plasma-packagestructure.desktop +++ b/servicetypes/plasma-packagestructure.desktop @@ -5,3 +5,6 @@ Comment=Plasma package structure definition Comment[km]=កា​រកំណត់​រចនាសម្ព័ន្ធ​កញ្ចប់​ប្លាស្មា Comment[zh_TW]=Plasma 套件結構定義 +[PropertyDef::X-Plasma-PackageFileFilter] +Type=QString +