re-port back to PackageStructure

This commit is contained in:
Aaron Seigo 2011-07-19 21:36:57 +02:00
parent 8c354ba4c6
commit 32f75b826c
2 changed files with 130 additions and 141 deletions

View File

@ -29,207 +29,204 @@
#include <klocale.h> #include <klocale.h>
#include <kmessagebox.h> #include <kmessagebox.h>
#include "plasma/private/wallpaper_p.h" #include "private/wallpaper_p.h"
#include "package.h"
#include "config-plasma.h"
namespace Plasma namespace Plasma
{ {
void ChangeableMainScriptPackage::pathChanged() void ChangeableMainScriptPackage::pathChanged(Package *package)
{ {
KDesktopFile config(path() + "/metadata.desktop"); KDesktopFile config(package->path() + "/metadata.desktop");
KConfigGroup cg = config.desktopGroup(); KConfigGroup cg = config.desktopGroup();
QString mainScript = cg.readEntry("X-Plasma-MainScript", QString()); QString mainScript = cg.readEntry("X-Plasma-MainScript", QString());
if (!mainScript.isEmpty()) { if (!mainScript.isEmpty()) {
addFileDefinition("mainscript", mainScript, i18n("Main Script File")); package->addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
setRequired("mainscript", true); package->setRequired("mainscript", true);
} }
} }
PlasmoidPackage::PlasmoidPackage() void PlasmoidPackage::initPackage(Package *package)
: ChangeableMainScriptPackage()
{ {
QString pathsString(getenv("PLASMA_CUSTOM_PREFIX_PATHS")); QString pathsString(getenv("PLASMA_CUSTOM_PREFIX_PATHS"));
if (!pathsString.isEmpty()) { if (!pathsString.isEmpty()) {
QStringList prefixPaths(pathsString.split(":")); QStringList prefixPaths(pathsString.split(":"));
if (!prefixPaths.isEmpty()) { if (!prefixPaths.isEmpty()) {
setContentsPrefixPaths(prefixPaths); package->setContentsPrefixPaths(prefixPaths);
} }
} }
setServicePrefix("plasma-applet-"); package->setServicePrefix("plasma-applet-");
setDefaultPackageRoot("plasma/plasmoids"); package->setDefaultPackageRoot("plasma/plasmoids");
addDirectoryDefinition("images", "images", i18n("Images")); package->addDirectoryDefinition("images", "images", i18n("Images"));
QStringList mimetypes; QStringList mimetypes;
mimetypes << "image/svg+xml" << "image/png" << "image/jpeg"; mimetypes << "image/svg+xml" << "image/png" << "image/jpeg";
setMimeTypes("images", mimetypes); package->setMimeTypes("images", mimetypes);
addDirectoryDefinition("config", "config", i18n("Configuration Definitions")); package->addDirectoryDefinition("config", "config", i18n("Configuration Definitions"));
mimetypes.clear(); mimetypes.clear();
mimetypes << "text/xml"; mimetypes << "text/xml";
setMimeTypes("config", mimetypes); package->setMimeTypes("config", mimetypes);
addDirectoryDefinition("ui", "ui", i18n("User Interface")); package->addDirectoryDefinition("ui", "ui", i18n("User Interface"));
setMimeTypes("ui", mimetypes); package->setMimeTypes("ui", mimetypes);
addDirectoryDefinition("data", "data", i18n("Data Files")); package->addDirectoryDefinition("data", "data", i18n("Data Files"));
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts")); package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
mimetypes.clear(); mimetypes.clear();
mimetypes << "text/plain"; mimetypes << "text/plain";
setMimeTypes("scripts", mimetypes); package->setMimeTypes("scripts", mimetypes);
addDirectoryDefinition("translations", "locale", i18n("Translations")); package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File")); package->addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File"));
addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file")); package->addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File")); package->addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
addFileDefinition("defaultconfig", "config/default-configrc", i18n("Default configuration")); package->addFileDefinition("defaultconfig", "config/default-configrc", i18n("Default configuration"));
addDirectoryDefinition("animations", "animations", i18n("Animation scripts")); package->addDirectoryDefinition("animations", "animations", i18n("Animation scripts"));
setRequired("mainscript", true); package->setRequired("mainscript", true);
} }
DataEnginePackage::DataEnginePackage() void DataEnginePackage::initPackage(Package *package)
: ChangeableMainScriptPackage()
{ {
setServicePrefix("plasma-dataengine-"); package->setServicePrefix("plasma-dataengine-");
setDefaultPackageRoot("plasma/dataengines/"); package->setDefaultPackageRoot("plasma/dataengines/");
addDirectoryDefinition("data", "data", i18n("Data Files")); package->addDirectoryDefinition("data", "data", i18n("Data Files"));
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts")); package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
QStringList mimetypes; QStringList mimetypes;
mimetypes << "text/plain"; mimetypes << "text/plain";
setMimeTypes("scripts", mimetypes); package->setMimeTypes("scripts", mimetypes);
addDirectoryDefinition("services", "services/", i18n("Service Descriptions")); package->addDirectoryDefinition("services", "services/", i18n("Service Descriptions"));
setMimeTypes("services", mimetypes); package->setMimeTypes("services", mimetypes);
addDirectoryDefinition("translations", "locale", i18n("Translations")); package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File")); package->addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
setRequired("mainscript", true); package->setRequired("mainscript", true);
} }
RunnerPackage::RunnerPackage() void RunnerPackage::initPackage(Package *package)
: ChangeableMainScriptPackage()
{ {
setServicePrefix("plasma-runner-"); package->setServicePrefix("plasma-runner-");
setDefaultPackageRoot("plasma/runners/"); package->setDefaultPackageRoot("plasma/runners/");
addDirectoryDefinition("data", "data", i18n("Data Files")); package->addDirectoryDefinition("data", "data", i18n("Data Files"));
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts")); package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
QStringList mimetypes; QStringList mimetypes;
mimetypes << "text/plain"; mimetypes << "text/plain";
setMimeTypes("scripts", mimetypes); package->setMimeTypes("scripts", mimetypes);
addDirectoryDefinition("translations", "locale", i18n("Translations")); package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File")); package->addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
setRequired("mainscript", true); package->setRequired("mainscript", true);
} }
ThemePackage::ThemePackage() void ThemePackage::initPackage(Package *package)
: Package()
{ {
addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs")); package->addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs"));
addFileDefinition("dialogs/background", "dialogs/background.svg", package->addFileDefinition("dialogs/background", "dialogs/background.svg",
i18n("Generic dialog background")); i18n("Generic dialog background"));
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg", package->addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
i18n("Theme for the logout dialog")); i18n("Theme for the logout dialog"));
addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages")); package->addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages"));
addDirectoryDefinition("animations", "animations/", i18n("Animation scripts")); package->addDirectoryDefinition("animations", "animations/", i18n("Animation scripts"));
addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets")); package->addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
addFileDefinition("widgets/background", "widgets/background.svg", package->addFileDefinition("widgets/background", "widgets/background.svg",
i18n("Background image for widgets")); i18n("Background image for widgets"));
addFileDefinition("widgets/clock", "widgets/clock.svg", package->addFileDefinition("widgets/clock", "widgets/clock.svg",
i18n("Analog clock face")); i18n("Analog clock face"));
addFileDefinition("widgets/panel-background", "widgets/panel-background.svg", package->addFileDefinition("widgets/panel-background", "widgets/panel-background.svg",
i18n("Background image for panels")); i18n("Background image for panels"));
addFileDefinition("widgets/plot-background", "widgets/plot-background.svg", package->addFileDefinition("widgets/plot-background", "widgets/plot-background.svg",
i18n("Background for graphing widgets")); i18n("Background for graphing widgets"));
addFileDefinition("widgets/tooltip", "widgets/tooltip.svg", package->addFileDefinition("widgets/tooltip", "widgets/tooltip.svg",
i18n("Background image for tooltips")); i18n("Background image for tooltips"));
addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs")); package->addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs"));
addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg", package->addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg",
i18n("Opaque generic dialog background")); i18n("Opaque generic dialog background"));
addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svg", package->addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svg",
i18n("Opaque theme for the logout dialog")); i18n("Opaque theme for the logout dialog"));
addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets")); package->addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets"));
addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg", package->addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg",
i18n("Opaque background image for panels")); i18n("Opaque background image for panels"));
addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svg", package->addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svg",
i18n("Opaque background image for tooltips")); i18n("Opaque background image for tooltips"));
addDirectoryDefinition("locolor/dialogs", "locolor/dialogs/", package->addDirectoryDefinition("locolor/dialogs", "locolor/dialogs/",
i18n("Low color images for dialogs")); i18n("Low color images for dialogs"));
addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svg", package->addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svg",
i18n("Low color generic dialog background")); i18n("Low color generic dialog background"));
addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svg", package->addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svg",
i18n("Low color theme for the logout dialog")); i18n("Low color theme for the logout dialog"));
addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets")); package->addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets"));
addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg", package->addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg",
i18n("Low color background image for widgets")); i18n("Low color background image for widgets"));
addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svg", package->addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svg",
i18n("Low color analog clock face")); i18n("Low color analog clock face"));
addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svg", package->addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svg",
i18n("Low color background image for panels")); i18n("Low color background image for panels"));
addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svg", package->addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svg",
i18n("Low color background for graphing widgets")); i18n("Low color background for graphing widgets"));
addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svg", package->addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svg",
i18n("Low color background image for tooltips")); i18n("Low color background image for tooltips"));
addFileDefinition("colors", "colors", i18n("KColorScheme configuration file")); package->addFileDefinition("colors", "colors", i18n("KColorScheme configuration file"));
QStringList mimetypes; QStringList mimetypes;
mimetypes << "image/svg+xml"; mimetypes << "image/svg+xml";
setDefaultMimeTypes(mimetypes); package->setDefaultMimeTypes(mimetypes);
} }
WallpaperPackage::WallpaperPackage(Wallpaper *paper) WallpaperPackage::WallpaperPackage(Wallpaper *paper)
: Package(), : PackageStructure(),
m_paper(paper),
m_fullPackage(true), m_fullPackage(true),
m_targetSize(100000, 100000), m_targetSize(100000, 100000),
m_resizeMethod(Wallpaper::ScaledResize) m_resizeMethod(Wallpaper::ScaledResize)
{
if (paper) {
connect(paper, SIGNAL(renderHintsChanged()), this, SLOT(renderHintsChanged()));
connect(paper, SIGNAL(destroyed(QObject*)), this, SLOT(paperDestroyed()));
}
}
void WallpaperPackage::initPackage(Package *package)
{ {
QStringList mimetypes; QStringList mimetypes;
mimetypes << "image/svg" << "image/png" << "image/jpeg" << "image/jpg"; mimetypes << "image/svg" << "image/png" << "image/jpeg" << "image/jpg";
setDefaultMimeTypes(mimetypes); package->setDefaultMimeTypes(mimetypes);
addDirectoryDefinition("images", "images/", i18n("Images")); package->addDirectoryDefinition("images", "images/", i18n("Images"));
setRequired("images", true); package->setRequired("images", true);
addFileDefinition("screenshot", "screenshot.png", i18n("Screenshot")); package->addFileDefinition("screenshot", "screenshot.png", i18n("Screenshot"));
setAllowExternalPaths(true); package->setAllowExternalPaths(true);
if (m_paper) {
m_targetSize = m_paper->d->targetSize.toSize();
m_resizeMethod = m_paper->d->lastResizeMethod;
connect(m_paper, SIGNAL(renderHintsChanged()), this, SLOT(renderHintsChanged()));
connect(m_paper, SIGNAL(destroyed(QObject*)), this, SLOT(paperDestroyed()));
}
} }
void WallpaperPackage::renderHintsChanged() void WallpaperPackage::renderHintsChanged()
{ {
if (m_paper) { Wallpaper *paper = qobject_cast<Wallpaper *>(sender());
m_targetSize = m_paper->d->targetSize.toSize(); if (!paper) {
m_resizeMethod = m_paper->d->lastResizeMethod; return;
} }
if (m_fullPackage) { if (m_fullPackage) {
findBestPaper(); findBestPaper(paper, packages.value(paper));
} }
} }
void WallpaperPackage::pathChanged() void WallpaperPackage::pathChanged(Package *package)
{ {
static bool guard = false; static bool guard = false;
@ -239,20 +236,20 @@ void WallpaperPackage::pathChanged()
guard = true; guard = true;
QFileInfo info(path()); QFileInfo info(package->path());
m_fullPackage = info.isDir(); m_fullPackage = info.isDir();
removeDefinition("preferred"); package->removeDefinition("preferred");
setRequired("images", m_fullPackage); package->setRequired("images", m_fullPackage);
if (m_fullPackage) { if (m_fullPackage) {
setContentsPrefixPaths(QStringList() << "contents/"); package->setContentsPrefixPaths(QStringList() << "contents/");
findBestPaper(); findBestPaper(package, papers.value(package));
} else { } else {
// dirty trick to support having a file passed in instead of a directory // dirty trick to support having a file passed in instead of a directory
addFileDefinition("preferred", info.fileName(), i18n("Recommended wallpaper file")); package->addFileDefinition("preferred", info.fileName(), i18n("Recommended wallpaper file"));
setContentsPrefixPaths(QStringList()); package->setContentsPrefixPaths(QStringList());
//kDebug() << "changing" << path() << "to" << info.path(); //kDebug() << "changing" << path() << "to" << info.path();
setPath(info.path()); package->setPath(info.path());
} }
guard = false; guard = false;
@ -262,16 +259,15 @@ QSize WallpaperPackage::resSize(const QString &str) const
{ {
int index = str.indexOf('x'); int index = str.indexOf('x');
if (index != -1) { if (index != -1) {
return QSize(str.left(index).toInt(), return QSize(str.left(index).toInt(), str.mid(index + 1).toInt());
str.mid(index + 1).toInt());
} else { } else {
return QSize(); return QSize();
} }
} }
void WallpaperPackage::findBestPaper() void WallpaperPackage::findBestPaper(Package *package)
{ {
QStringList images = entryList("images"); QStringList images = package->entryList("images");
if (images.empty()) { if (images.empty()) {
return; return;
} }
@ -301,7 +297,7 @@ void WallpaperPackage::findBestPaper()
} }
//kDebug() << "best image" << bestImage; //kDebug() << "best image" << bestImage;
addFileDefinition("preferred", filePath("images") + bestImage, i18n("Recommended wallpaper file")); package->addFileDefinition("preferred", filePath("images") + bestImage, i18n("Recommended wallpaper file"));
} }
float WallpaperPackage::distance(const QSize& size, const QSize& desired, float WallpaperPackage::distance(const QSize& size, const QSize& desired,
@ -334,19 +330,15 @@ float WallpaperPackage::distance(const QSize& size, const QSize& desired,
} }
} }
void WallpaperPackage::paperDestroyed() void ContainmentActionsPackage::initPackage(Package *package)
{ {
m_paper = 0; package->setDefaultPackageRoot("plasma/containmentactions/");
package->addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
} }
ContainmentActionsPackage::ContainmentActionsPackage() void GenericPackage::initPackage(Package *package)
{ {
//FIXME how do I do the mimetypes stuff? package->setDefaultPackageRoot("plasma/packages/");
}
GenericPackage::GenericPackage()
{
setDefaultPackageRoot("plasma/packages");
} }
} // namespace Plasma } // namespace Plasma

View File

@ -20,54 +20,51 @@
#ifndef LIBS_PLASMA_PACKAGES_P_H #ifndef LIBS_PLASMA_PACKAGES_P_H
#define LIBS_PLASMA_PACKAGES_P_H #define LIBS_PLASMA_PACKAGES_P_H
#include "plasma/package.h" #include "packagestructure.h"
#include "plasma/plasma.h" #include "plasma.h"
#include "plasma/wallpaper.h" #include "wallpaper.h"
#include "config-plasma.h"
namespace Plasma namespace Plasma
{ {
class ChangeableMainScriptPackage : public Package class ChangeableMainScriptPackage : public PackageStructure
{ {
protected: protected:
void pathChanged(); void pathChanged(Package *package);
}; };
class PlasmoidPackage : public ChangeableMainScriptPackage class PlasmoidPackage : public ChangeableMainScriptPackage
{ {
public: public:
explicit PlasmoidPackage(); void initPackage(Package *package);
}; };
class DataEnginePackage : public ChangeableMainScriptPackage class DataEnginePackage : public ChangeableMainScriptPackage
{ {
public: public:
explicit DataEnginePackage(); void initPackage(Package *package);
} ; };
class RunnerPackage : public ChangeableMainScriptPackage class RunnerPackage : public ChangeableMainScriptPackage
{ {
public: public:
explicit RunnerPackage(); void initPackage(Package *package);
}; };
class ThemePackage : public Package class ThemePackage : public PackageStructure
{ {
public: public:
explicit ThemePackage(); void initPackage(Package *package);
}; };
class WallpaperPackage : public QObject, public Package class WallpaperPackage : public PackageStructure
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WallpaperPackage(Wallpaper *paper = 0); explicit WallpaperPackage(Wallpaper *paper = 0);
void initPackage(Package *package);
protected: void pathChanged(Package *package);
void pathChanged();
private: private:
QSize resSize(const QString &str) const; QSize resSize(const QString &str) const;
@ -86,16 +83,16 @@ private:
Wallpaper::ResizeMethod m_resizeMethod; Wallpaper::ResizeMethod m_resizeMethod;
}; };
class ContainmentActionsPackage : public Package class ContainmentActionsPackage : public PackageStructure
{ {
public: public:
explicit ContainmentActionsPackage(); void initPackage(Package *package);
}; };
class GenericPackage : public Package class GenericPackage : public PackageStructure
{ {
public: public:
explicit GenericPackage(); void initPackage(Package *package);
}; };
} // namespace Plasma } // namespace Plasma