package structure appropriateness for dynamic packages

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=780124
This commit is contained in:
Aaron J. Seigo 2008-02-28 03:53:26 +00:00
parent 2e9488e2af
commit 1a84d94eeb
6 changed files with 87 additions and 19 deletions

View File

@ -297,19 +297,26 @@ void AppletBrowserWidget::openWidgetFile()
{ {
KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure"); KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure");
QStringList filters; QStringList filters;
filters << ("*.plasmoid|Plasma Widget"); filters << i18nc("File dialog filter", "%1|PlasmaWidget", "*.plasma");
/* QStringList mimetypes;
foreach (const KService::Ptr &offer, offers) { foreach (const KService::Ptr &offer, offers) {
QString glob = offer //filters << offer->property("X-Plasma-PackageMimeFilter").toStringList();
QString filter( 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); KFileDialog fd(KUrl(), QString(), this);
fd.setOperationMode(KFileDialog::Opening); fd.setOperationMode(KFileDialog::Opening);
fd.setMode(KFile::Files | KFile::ExistingOnly); fd.setMode(KFile::Files | KFile::ExistingOnly);
fd.setFilter(filters.join("\n")); fd.setFilter(filters.join("\n"));// + mimetypes.join("\n"));
fd.exec(); fd.exec();
kDebug() << "selected file" << fd.selectedUrl(); kDebug() << "selected file" << fd.selectedUrl() << "of type" << fd.currentFilter();
} }
class AppletBrowser::Private 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->setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
q->setButtonText(KDialog::Apply, i18n("Add Widget")); 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); KMenu *widgetsMenu = new KMenu(i18n("Get New Widgets"), q);
QAction *action = new QAction(KIcon("applications-internet"), QAction *action = new QAction(KIcon("applications-internet"),
@ -344,7 +351,7 @@ void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *contain
widgetsMenu->addAction(action); widgetsMenu->addAction(action);
action = new QAction(KIcon("applications-internet"), action = new QAction(KIcon("applications-internet"),
i18n("Load from file"), q); i18n("Install from file"), q);
connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile())); connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile()));
widgetsMenu->addAction(action); widgetsMenu->addAction(action);
q->button(KDialog::User1)->setMenu(widgetsMenu); q->button(KDialog::User1)->setMenu(widgetsMenu);
@ -357,10 +364,16 @@ void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *contain
q->setButtonWhatsThis(KDialog::User1, i18n("<qt>When clicking <b>Get New Widgets</b>, a dialog will open to allow you to download new widgets. You need to be connected to the Internet.</qt>")); q->setButtonWhatsThis(KDialog::User1, i18n("<qt>When clicking <b>Get New Widgets</b>, a dialog will open to allow you to download new widgets. You need to be connected to the Internet.</qt>"));
connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet())); connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet()));
q->setInitialSize(QSize(400, 600));
KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog");
q->restoreDialogSize(cg);
} }
AppletBrowser::~AppletBrowser() AppletBrowser::~AppletBrowser()
{ {
KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog");
saveDialogSize(cg);
} }
void AppletBrowser::setApplication(const QString& app) void AppletBrowser::setApplication(const QString& app)

View File

@ -59,21 +59,22 @@ public:
delete metadata; delete metadata;
} }
const PackageStructure::Ptr structure; PackageStructure::Ptr structure;
QString basePath; QString basePath;
bool valid; bool valid;
PackageMetadata *metadata; PackageMetadata *metadata;
}; };
Package::Package(const QString& packageRoot, const QString& package, Package::Package(const QString& packageRoot, const QString& package, PackageStructure::Ptr structure)
const PackageStructure::Ptr structure)
: d(new Private(structure, packageRoot + '/' + package)) : 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)) : d(new Private(structure, packagePath))
{ {
structure->setPath(d->basePath);
} }
Package::~Package() Package::~Package()
@ -159,12 +160,23 @@ QStringList Package::entryList(const char* fileType) const
const PackageMetadata* Package::metadata() const const PackageMetadata* Package::metadata() const
{ {
//FIXME: this only works for native plasma packges; should fall back to... PackageStructure?
if (!d->metadata) { if (!d->metadata) {
d->metadata = new PackageMetadata(d->basePath + "metadata.desktop"); d->metadata = new PackageMetadata(d->basePath + "metadata.desktop");
} }
return d->metadata; 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? //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? // should we be using KService here instead/as well?
QStringList Package::knownPackages(const QString& packageRoot) // static QStringList Package::knownPackages(const QString& packageRoot) // static

View File

@ -100,6 +100,16 @@ class PLASMA_EXPORT Package
*/ */
const PackageMetadata *metadata() const; 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 * Returns a list of all installed packages
* *

View File

@ -60,10 +60,11 @@ class PackageStructure::Private
{ {
public: public:
QString type; QString type;
QString path;
QMap<QByteArray, ContentStructure> contents; QMap<QByteArray, ContentStructure> contents;
QStringList mimetypes; QStringList mimetypes;
static QHash<QString, PackageStructure::Ptr> structures; static QHash<QString, PackageStructure::Ptr> structures;
}; };
QHash<QString, PackageStructure::Ptr> PackageStructure::Private::structures; QHash<QString, PackageStructure::Ptr> PackageStructure::Private::structures;
@ -101,7 +102,6 @@ PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
PackageStructure::Ptr structure(offer->createInstance<Plasma::PackageStructure>(0, args, &error)); PackageStructure::Ptr structure(offer->createInstance<Plasma::PackageStructure>(0, args, &error));
if (structure) { if (structure) {
Private::structures[packageFormat] = structure;
return structure; return structure;
} }
@ -116,9 +116,9 @@ PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
if (!configPath.isEmpty()) { if (!configPath.isEmpty()) {
KConfig config(configPath); KConfig config(configPath);
structure->read(&config); structure->read(&config);
Private::structures[packageFormat] = structure;
} }
Private::structures[packageFormat] = structure;
return structure; return structure;
} }
@ -279,6 +279,22 @@ QStringList PackageStructure::mimetypes(const char* key) const
return it.value().mimetypes; 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) void PackageStructure::read(const KConfigBase *config)
{ {
d->contents.clear(); d->contents.clear();

View File

@ -96,7 +96,7 @@ public:
* @return a package that matches the format, if available. The caller * @return a package that matches the format, if available. The caller
* is responsible for deleting the object. * 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 * Type of package this structure describes
@ -192,6 +192,17 @@ public:
**/ **/
QStringList mimetypes(const char* key) const; 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. * Read a package structure from a config file.
*/ */
@ -206,12 +217,15 @@ public:
* Installs a package matching this package structure. By default simply calls * Installs a package matching this package structure. By default simply calls
* Plasma::Package::install. * 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 * @param packageRoot path to the directory where the package should be
* installed to * installed to
* @return true on successful installation, false otherwise * @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: private:
class Private; class Private;

View File

@ -5,3 +5,6 @@ Comment=Plasma package structure definition
Comment[km]= Comment[km]=
Comment[zh_TW]=Plasma Comment[zh_TW]=Plasma
[PropertyDef::X-Plasma-PackageFileFilter]
Type=QString