make the PackageStructures into Package subclasses

This commit is contained in:
Aaron Seigo 2011-07-15 13:03:46 +02:00
parent 889c9e7bd3
commit abf1b8510f
2 changed files with 78 additions and 85 deletions

View File

@ -29,17 +29,24 @@
#include <klocale.h> #include <klocale.h>
#include <kmessagebox.h> #include <kmessagebox.h>
#ifndef PLASMA_NO_KNEWSTUFF
#include <knewstuff3/downloaddialog.h>
#endif
#include "plasma/private/wallpaper_p.h" #include "plasma/private/wallpaper_p.h"
namespace Plasma namespace Plasma
{ {
PlasmoidPackage::PlasmoidPackage(QObject *parent) void ChangeableMainScriptPackage::pathChanged()
: Plasma::PackageStructure(parent, QString("Plasmoid")) {
KDesktopFile config(path() + "/metadata.desktop");
KConfigGroup cg = config.desktopGroup();
QString mainScript = cg.readEntry("X-Plasma-MainScript", QString());
if (!mainScript.isEmpty()) {
addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
setRequired("mainscript", true);
}
}
PlasmoidPackage::PlasmoidPackage()
: ChangeableMainScriptPackage()
{ {
QString pathsString(getenv("PLASMA_CUSTOM_PREFIX_PATHS")); QString pathsString(getenv("PLASMA_CUSTOM_PREFIX_PATHS"));
if (!pathsString.isEmpty()) { if (!pathsString.isEmpty()) {
@ -49,6 +56,9 @@ PlasmoidPackage::PlasmoidPackage(QObject *parent)
} }
} }
setServicePrefix("plasma-applet-");
setDefaultPackageRoot("plasma/plasmoids");
addDirectoryDefinition("images", "images", i18n("Images")); 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";
@ -79,26 +89,11 @@ PlasmoidPackage::PlasmoidPackage(QObject *parent)
setRequired("mainscript", true); setRequired("mainscript", true);
} }
PlasmoidPackage::~PlasmoidPackage() DataEnginePackage::DataEnginePackage()
{ : ChangeableMainScriptPackage()
}
void PlasmoidPackage::pathChanged()
{
KDesktopFile config(path() + "/metadata.desktop");
KConfigGroup cg = config.desktopGroup();
QString mainScript = cg.readEntry("X-Plasma-MainScript", QString());
if (!mainScript.isEmpty()) {
addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
setRequired("mainscript", true);
}
}
DataEnginePackage::DataEnginePackage(QObject *parent)
: Plasma::PackageStructure(parent, QString("DataEngine"))
{ {
setServicePrefix("plasma-dataengine-"); setServicePrefix("plasma-dataengine-");
setDefaultPackageRoot("plasma/dataengine/"); setDefaultPackageRoot("plasma/dataengines/");
addDirectoryDefinition("data", "data", i18n("Data Files")); addDirectoryDefinition("data", "data", i18n("Data Files"));
@ -116,23 +111,27 @@ DataEnginePackage::DataEnginePackage(QObject *parent)
setRequired("mainscript", true); setRequired("mainscript", true);
} }
DataEnginePackage::~DataEnginePackage() RunnerPackage::RunnerPackage()
: ChangeableMainScriptPackage()
{ {
setServicePrefix("plasma-runner-");
setDefaultPackageRoot("plasma/runners/");
addDirectoryDefinition("data", "data", i18n("Data Files"));
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
QStringList mimetypes;
mimetypes << "text/plain";
setMimeTypes("scripts", mimetypes);
addDirectoryDefinition("translations", "locale", i18n("Translations"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
setRequired("mainscript", true);
} }
void DataEnginePackage::pathChanged() ThemePackage::ThemePackage()
{ : Package()
KDesktopFile config(path() + "/metadata.desktop");
KConfigGroup cg = config.desktopGroup();
QString mainScript = cg.readEntry("X-Plasma-MainScript", QString());
if (!mainScript.isEmpty()) {
addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
setRequired("mainscript", true);
}
}
ThemePackage::ThemePackage(QObject *parent)
: Plasma::PackageStructure(parent, QString("Plasma Theme"))
{ {
addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs")); addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs"));
addFileDefinition("dialogs/background", "dialogs/background.svg", addFileDefinition("dialogs/background", "dialogs/background.svg",
@ -193,8 +192,8 @@ ThemePackage::ThemePackage(QObject *parent)
setDefaultMimeTypes(mimetypes); setDefaultMimeTypes(mimetypes);
} }
WallpaperPackage::WallpaperPackage(Wallpaper *paper, QObject *parent) WallpaperPackage::WallpaperPackage(Wallpaper *paper)
: PackageStructure(parent, "Background"), : Package(),
m_paper(paper), m_paper(paper),
m_fullPackage(true), m_fullPackage(true),
m_targetSize(100000, 100000), m_targetSize(100000, 100000),
@ -302,7 +301,7 @@ void WallpaperPackage::findBestPaper()
} }
//kDebug() << "best image" << bestImage; //kDebug() << "best image" << bestImage;
addFileDefinition("preferred", path("images") + bestImage, i18n("Recommended wallpaper file")); 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,
@ -340,12 +339,16 @@ void WallpaperPackage::paperDestroyed()
m_paper = 0; m_paper = 0;
} }
ContainmentActionsPackage::ContainmentActionsPackage(QObject *parent) ContainmentActionsPackage::ContainmentActionsPackage()
: Plasma::PackageStructure(parent, QString("ContainmentActions"))
{ {
//FIXME how do I do the mimetypes stuff? //FIXME how do I do the mimetypes stuff?
} }
GenericPackage::GenericPackage()
{
setDefaultPackageRoot("plasma/packages");
}
} // namespace Plasma } // namespace Plasma
#include "packages_p.moc" #include "packages_p.moc"

View File

@ -20,63 +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/packagestructure.h" #include "plasma/package.h"
#include "plasma/wallpaper.h"
#include "plasma/plasma.h" #include "plasma/plasma.h"
#include "plasma/wallpaper.h"
#include "config-plasma.h" #include "config-plasma.h"
#ifndef PLASMA_NO_KNEWSTUFF
namespace KNS3
{
class DownloadDialog;
} // namespace KNS
#endif
namespace Plasma namespace Plasma
{ {
class PlasmoidPackage : public PackageStructure class ChangeableMainScriptPackage : public Package
{ {
Q_OBJECT
public:
explicit PlasmoidPackage(QObject *parent = 0);
~PlasmoidPackage();
void createNewWidgetBrowser(QWidget *parent = 0);
protected:
void pathChanged();
private:
#ifndef PLASMA_NO_KNEWSTUFF
QWeakPointer<KNS3::DownloadDialog> m_knsDialog;
#endif
};
class DataEnginePackage : public PackageStructure
{
Q_OBJECT
public:
explicit DataEnginePackage(QObject *parent = 0);
~DataEnginePackage();
protected: protected:
void pathChanged(); void pathChanged();
}; };
class ThemePackage : public PackageStructure class PlasmoidPackage : public ChangeableMainScriptPackage
{ {
Q_OBJECT
public: public:
explicit ThemePackage(QObject *parent = 0); explicit PlasmoidPackage();
}; };
class WallpaperPackage : public PackageStructure class DataEnginePackage : public ChangeableMainScriptPackage
{
public:
explicit DataEnginePackage();
} ;
class RunnerPackage : public ChangeableMainScriptPackage
{
public:
explicit RunnerPackage();
};
class ThemePackage : public Package
{
public:
explicit ThemePackage();
};
class WallpaperPackage : public QObject, public Package
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WallpaperPackage(Wallpaper *paper = 0, QObject *parent = 0); explicit WallpaperPackage(Wallpaper *paper = 0);
protected: protected:
void pathChanged(); void pathChanged();
@ -98,15 +86,17 @@ private:
Wallpaper::ResizeMethod m_resizeMethod; Wallpaper::ResizeMethod m_resizeMethod;
}; };
class ContainmentActionsPackage : public PackageStructure class ContainmentActionsPackage : public Package
{ {
Q_OBJECT
public: public:
explicit ContainmentActionsPackage(QObject *parent = 0); explicit ContainmentActionsPackage();
}; };
PackageStructure::Ptr defaultPackageStructure(ComponentType type); class GenericPackage : public Package
{
public:
explicit GenericPackage();
};
} // namespace Plasma } // namespace Plasma