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");
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("<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()));
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)

View File

@ -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

View File

@ -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
*

View File

@ -60,10 +60,11 @@ class PackageStructure::Private
{
public:
QString type;
QString path;
QMap<QByteArray, ContentStructure> contents;
QStringList mimetypes;
static QHash<QString, PackageStructure::Ptr> 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));
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();

View File

@ -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;

View File

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