Fix build after bad merge, by restoring these files to their frameworks version.

Aseigo told me to use "git checkout --theirs applet.h" in order to
"take the 4.10 version of the changes where there were conflicts",
but it turns out that this was very bad advice: it loses ALL the changes
ever made to the file in the frameworks branch.
CCMAIL: aseigo@kde.org
This commit is contained in:
David Faure 2012-12-01 10:11:55 +01:00
parent bdb7251250
commit d9b054b3bc
3 changed files with 199 additions and 1230 deletions

342
applet.h
View File

@ -22,26 +22,22 @@
#ifndef PLASMA_APPLET_H
#define PLASMA_APPLET_H
#include <QtGui/QGraphicsItem>
#include <QtGui/QGraphicsWidget>
#include <QtGui/QIcon>
#include <QObject>
#include <QIcon>
#include <kconfiggroup.h>
#include <kgenericfactory.h>
#include <kplugininfo.h>
#include <kshortcut.h>
#include <kurl.h>
#include <plasma/configloader.h>
#include <plasma/packagestructure.h>
#include <plasma/plasma.h>
#include <plasma/animator.h>
#include <plasma/version.h>
#include <plasma/framesvg.h>
class QWidget;
class KConfigDialog;
class QGraphicsView;
class KActionCollection;
namespace Plasma
@ -49,10 +45,7 @@ namespace Plasma
class AppletPrivate;
class Containment;
class Context;
class DataEngine;
class Extender;
class ExtenderItem;
class Package;
@ -74,50 +67,28 @@ class Package;
*
* See techbase.kde.org for tutorials on writing Applets using this class.
*/
class PLASMA_EXPORT Applet : public QGraphicsWidget
class PLASMA_EXPORT Applet : public QObject
{
Q_OBJECT
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString pluginName READ pluginName CONSTANT)
Q_PROPERTY(QString category READ category CONSTANT)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString pluginName READ pluginName)
Q_PROPERTY(QString category READ category)
Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
Q_PROPERTY(bool isBusy READ isBusy WRITE setBusy) //KDE5: remove
Q_PROPERTY(bool busy READ isBusy WRITE setBusy)
Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
Q_PROPERTY(uint id READ id CONSTANT)
Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
Q_PROPERTY(uint id READ id)
Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints)
Q_ENUMS(BackgroundHints)
Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
public:
typedef QList<Applet*> List;
typedef QHash<QString, Applet*> Dict;
/**
* Description on how draw a background for the applet
*/
enum BackgroundHint {
NoBackground = 0, /**< Not drawing a background under the
applet, the applet has its own implementation */
StandardBackground = 1, /**< The standard background from the theme is drawn */
TranslucentBackground = 2, /**< An alternate version of the background is drawn,
usually more translucent */
DefaultBackground = StandardBackground /**< Default settings:
both standard background */
};
Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
~Applet();
/**
* @return a package structure representing an Applet
*/
static PackageStructure::Ptr packageStructure();
/**
* @return the id of this applet
*/
@ -132,15 +103,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
**/
KConfigGroup config() const;
/**
* Returns a config group with the name provided. This ensures
* that the group name is properly namespaced to avoid collision
* with other applets that may be sharing this config file
*
* @param group the name of the group to access
**/
KConfigGroup config(const QString &group) const;
/**
* Saves state information about this applet that will
* be accessed when next instantiated in the restore(KConfigGroup&) method.
@ -205,29 +167,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*
* @return the Package object, or 0 if none
**/
const Package *package() const;
/**
* Returns the view this widget is visible on, or 0 if none can be found.
* @warning do NOT assume this will always return a view!
* a null view probably means that either plasma isn't finished loading, or your applet is
* on an activity that's not being shown anywhere.
*/
QGraphicsView *view() const;
/**
* Maps a QRect from a view's coordinates to local coordinates.
* @param view the view from which rect should be mapped
* @param rect the rect to be mapped
*/
QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
/**
* Maps a QRectF from local coordinates to a view's coordinates.
* @param view the view to which rect should be mapped
* @param rect the rect to be mapped
*/
QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
Package package() const;
/**
* Reccomended position for a popup window like a menu or a tooltip
@ -270,11 +210,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
virtual Location location() const;
/**
* Returns the workspace context which the applet is operating in
*/
Context *context() const;
/**
* @return the preferred aspect ratio mode for placement and resizing
*/
@ -310,7 +245,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*
* @return list of applets
**/
static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
static KPluginInfo::List listAppletInfoForMimeType(const QString &mimetype);
/**
* Returns a list of all known applets associated with a certain URL.
@ -365,38 +300,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
const QVariantList &args = QVariantList());
/**
* Attempts to load an applet
*
* Returns a pointer to the applet if successful.
* The caller takes responsibility for the applet, including
* deleting it when no longer needed.
*
* @param name the plugin name, as returned by KPluginInfo::pluginName()
* @param appletId unique ID to assign the applet, or zero to have one
* assigned automatically.
* @param args to send the applet extra arguments
* @return a pointer to the loaded applet, or 0 on load failure
**/
static Applet *load(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList());
/**
* Attempts to load an applet
*
* Returns a pointer to the applet if successful.
* The caller takes responsibility for the applet, including
* deleting it when no longer needed.
*
* @param info KPluginInfo object for the desired applet
* @param appletId unique ID to assign the applet, or zero to have one
* assigned automatically.
* @param args to send the applet extra arguments
* @return a pointer to the loaded applet, or 0 on load failure
**/
static Applet *load(const KPluginInfo &info, uint appletId = 0,
const QVariantList &args = QVariantList());
/**
* Get the category of the given applet
*
@ -411,26 +314,20 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
static QString category(const QString &appletName);
/**
* This method is called when the interface should be painted.
*
* @param painter the QPainter to use to do the paintiner
* @param option the style options object
* @param contentsRect the rect to paint within; automatically adjusted for
* the background, if any
**/
virtual void paintInterface(QPainter *painter,
const QStyleOptionGraphicsItem *option,
const QRect &contentsRect);
/**
* Returns the user-visible name for the applet, as specified in the
* .desktop file.
* .desktop file. Can be changed with @see setName
*
* @return the user-visible name for the applet.
**/
QString name() const;
/**
* Sets a custom name for this instance of the applet. E.g. a clock might
* use the timezone as its name rather than the .desktop file
*/
void setName(const QString &name) const;
/**
* @return the font currently set for this widget
**/
@ -465,9 +362,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
ImmutabilityType immutability() const;
void paintWindowFrame(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget);
/**
* If for some reason, the applet fails to get up on its feet (the
* library couldn't be loaded, necessary hardware support wasn't found,
@ -517,38 +411,19 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*
* @param hints the BackgroundHint combination for this applet
*/
void setBackgroundHints(const BackgroundHints hints);
void setBackgroundHints(const Plasma::BackgroundHints hint);
/**
* @return BackgroundHints flags combination telling if the standard background is shown
* and if it has a drop shadow
*/
BackgroundHints backgroundHints() const;
Plasma::BackgroundHints backgroundHints() const;
/**
* @return true if this Applet is currently being used as a Containment, false otherwise
*/
bool isContainment() const;
/**
* This method returns screen coordinates for the widget; this method can be somewhat
* expensive and should ONLY be called when screen coordinates are required. For
* example when positioning top level widgets on top of the view to create the
* appearance of unit. This should NOT be used for popups (@see popupPosition) or
* for normal widget use (use Plasma:: widgets or QGraphicsProxyWidget instead).
*
* @return a rect of the applet in screen coordinates.
*/
QRect screenRect() const;
/**
* Reimplemented from QGraphicsItem
**/
int type() const;
enum {
Type = Plasma::AppletType
};
/**
* @return the Containment, if any, this applet belongs to
**/
@ -585,46 +460,25 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
virtual void removeAssociatedWidget(QWidget *widget);
/**
* Gets called when an extender item has to be initialized after a plasma restart. If you
* create ExtenderItems in your applet, you should implement this function to again create
* the widget that should be shown in this extender item. This function might look something
* like this:
*
* @code
* SuperCoolWidget *widget = new SuperCoolWidget();
* dataEngine("engine")->connectSource(item->config("dataSourceName"), widget);
* item->setWidget(widget);
* @endcode
*
* You can also add one or more custom qactions to this extender item in this function.
*
* Note that by default, not all ExtenderItems are persistent. Only items that are detached,
* will have their configuration stored when plasma exits.
*/
virtual void initExtenderItem(ExtenderItem *item);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param parent the QObject this applet is parented to
* @param serviceId the name of the .desktop file containing the
* information about the widget
* @param appletId a unique id used to differentiate between multiple
* instances of the same Applet type
*/
explicit Applet(QGraphicsItem *parent = 0,
const QString &serviceId = QString(),
uint appletId = 0);
explicit Applet(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param parent the QObject this applet is parented to
* @param info the plugin information object for this Applet
* @param appletId a unique id used to differentiate between multiple
* instances of the same Applet type
* @since 4.6
*/
explicit Applet(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0);
explicit Applet(const KPluginInfo &info, QObject *parent = 0, uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param parent the QObject this applet is parented to
* @param serviceId the name of the .desktop file containing the
* information about the widget
* @param appletId a unique id used to differentiate between multiple
@ -633,10 +487,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
* and the applet id
* @since 4.3
*/
explicit Applet(QGraphicsItem *parent,
const QString &serviceId,
uint appletId,
const QVariantList &args);
explicit Applet(QObject *parent, const QString &serviceId, uint appletId, const QVariantList &args);
/**
@ -697,7 +548,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*
* @param urls
*/
void setAssociatedApplicationUrls(const KUrl::List &urls);
void setAssociatedApplicationUrls(const QList<QUrl> &urls);
/**
* @return the application associated to this applet
@ -709,7 +560,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
* @return the urls associated to this applet
* @since 4.4
*/
KUrl::List associatedApplicationUrls() const;
QList<QUrl> associatedApplicationUrls() const;
/**
* @return true if the applet has a valid associated application or urls
@ -726,18 +577,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void releaseVisualFocus();
#if QT_VERSION >= 0x040700
protected:
void geometryChanged(); // in QGraphicsWidget now; preserve BC
#else
/**
* Emitted whenever the applet makes a geometry change, so that views
* can coordinate themselves with these changes if they desire.
*/
void geometryChanged();
#endif
Q_SIGNALS:
/**
* Emitted when the user completes a transformation of the applet.
*/
@ -748,11 +587,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void appletTransformedItself();
/**
* Emitted by Applet subclasses when they change a sizeHint and wants to announce the change
*/
void sizeHintChanged(Qt::SizeHint which);
/**
* Emitted when an applet has changed values in its configuration
* and wishes for them to be saved at the next save point. As this implies
@ -781,7 +615,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/**
* Emitted when the applet is deleted
*/
void appletDestroyed(Plasma::Applet *applet);
void appletDeleted(Plasma::Applet *applet);
/**
* Emitted when the applet status changes
@ -789,11 +623,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void newStatus(Plasma::ItemStatus status);
/**
* Emitted when an ExtenderItem in a scripting applet needs to be initialized
*/
void extenderItemRestored(Plasma::ExtenderItem *item);
/**
* Emitted when the immutability changes
* @since 4.4
@ -845,16 +674,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
bool isUserConfiguring() const;
/**
* Causes this applet to raise above all other applets.
*/
void raise();
/**
* Causes this applet to lower below all the other applets.
*/
void lower();
/**
* Sends all pending contraints updates to the applet. Will usually
* be called automatically, but can also be called manually if needed.
@ -863,7 +682,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/**
* This method is called once the applet is loaded and added to a Corona.
* If the applet requires a QGraphicsScene or has an particularly intensive
* If the applet requires a Scene or has an particularly intensive
* set of initialization routines to go through, consider implementing it
* in this method instead of the constructor.
*
@ -924,6 +743,9 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void runAssociatedApplication();
bool hasFocus() const;
void setFocus(Qt::FocusReason);
protected:
/**
* This constructor is to be used with the plugin loading systems
@ -1022,84 +844,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
virtual void constraintsEvent(Plasma::Constraints constraints);
/**
* Register the widgets that manage mouse clicks but you still want
* to be able to drag the applet around when holding the mouse pointer
* on that widget.
*
* Calling this results in an eventFilter being places on the widget.
*
* @param item the item to watch for mouse move
*/
void registerAsDragHandle(QGraphicsItem *item);
/**
* Unregister a widget registered with registerAsDragHandle.
*
* @param item the item to unregister
*/
void unregisterAsDragHandle(QGraphicsItem *item);
/**
* @param item the item to look for if it is registered or not
* @return true if it is registered, false otherwise
*/
bool isRegisteredAsDragHandle(QGraphicsItem *item);
/**
* @return the extender of this applet.
*/
Extender *extender() const;
/**
* @internal event filter; used for focus watching
**/
bool eventFilter(QObject *o, QEvent *e);
/**
* @internal scene event filter; used to manage applet dragging
*/
bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
/**
* @internal manage the mouse movement to drag the applet around
*/
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
void focusInEvent(QFocusEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
void resizeEvent(QGraphicsSceneResizeEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* Reimplemented from QGraphicsItem
*/
QPainterPath shape() const;
/**
* Reimplemented from QGraphicsLayoutItem
*/
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
/**
* Reimplemented from QGraphicsLayoutItem
*/
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
/**
* Reimplemented from QObject
@ -1118,23 +862,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
Applet(const QString &packagePath, uint appletId, const QVariantList &args);
Q_PRIVATE_SLOT(d, void setFocus())
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
Q_PRIVATE_SLOT(d, void selectItemToDestroy())
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
Q_PRIVATE_SLOT(d, void configDialogFinished())
Q_PRIVATE_SLOT(d, void updateShortcuts())
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
Q_PRIVATE_SLOT(d, void globalShortcutChanged())
Q_PRIVATE_SLOT(d, void propagateConfigChanged())
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
/**
* Reimplemented from QGraphicsItem
**/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
AppletPrivate *const d;
@ -1147,22 +880,15 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
friend class AppletHandle;
friend class AppletPrivate;
friend class AccessAppletJobPrivate;
friend class GraphicsViewAppletPrivate;
friend class PluginLoader;
friend class PopupApplet;
friend class PopupAppletPrivate;
friend class AssociatedApplicationManager;
friend class Extender;
friend class ExtenderGroup;
friend class ExtenderGroupPrivate;
friend class ExtenderPrivate;
friend class ExtenderItem;
};
} // Plasma namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
/**
* Register an applet when it is contained in a loadable module
*/

View File

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* Copyright 2011 by Aaron Seigo <aseigo@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
@ -18,652 +18,44 @@
*******************************************************************************/
#include "packagestructure.h"
#include "config-plasma.h"
#include <QDir>
#include <QMap>
#include <QMutableListIterator>
#include <QFileInfo>
#include <kconfiggroup.h>
#include <kdebug.h>
#ifndef PLASMA_NO_KIO
#include <kio/job.h>
#endif
#include <kmimetype.h>
#include <kstandarddirs.h>
#include <kservicetypetrader.h>
#include <ktar.h>
#include <ktemporaryfile.h>
#include <ktempdir.h>
#include <kurl.h>
#include <kzip.h>
#include "package.h"
#include "private/packages_p.h"
#include "theme.h"
#include "private/package_p.h"
namespace Plasma
{
class ContentStructure
{
public:
ContentStructure()
: directory(false),
required(false)
{
}
ContentStructure(const ContentStructure &other)
{
paths = other.paths;
name = other.name;
mimetypes = other.mimetypes;
directory = other.directory;
required = other.required;
}
QStringList paths;
QString name;
QStringList mimetypes;
bool directory : 1;
bool required : 1;
};
class PackageStructurePrivate
{
public:
PackageStructurePrivate(const QString &t)
: type(t),
packageRoot("plasma/plasmoids"),
servicePrefix("plasma-applet-"),
metadata(0),
externalPaths(false)
{
contentsPrefixPaths << "contents/";
}
~PackageStructurePrivate()
{
delete metadata;
}
void createPackageMetadata(const QString &path);
QStringList entryList(const QString &prefix, const QString &requestedPath);
QString type;
QString path;
QStringList contentsPrefixPaths;
QString packageRoot;
QString servicePrefix;
QMap<QByteArray, ContentStructure> contents;
QStringList mimetypes;
PackageMetadata *metadata;
bool externalPaths;
};
PackageStructure::PackageStructure(QObject *parent, const QString &type)
PackageStructure::PackageStructure(QObject *parent, const QVariantList &args)
: QObject(parent),
d(new PackageStructurePrivate(type))
d(0)
{
Q_UNUSED(args)
}
PackageStructure::~PackageStructure()
{
delete d;
}
PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
void PackageStructure::initPackage(Package *package)
{
if (packageFormat.isEmpty()) {
return Ptr(new PackageStructure());
}
PackageStructure::Ptr structure;
if (packageFormat == "Plasma/Applet") {
structure = defaultPackageStructure(AppletComponent);
structure->d->type = "Plasma/Applet";
} else if (packageFormat == "Plasma/DataEngine") {
structure = defaultPackageStructure(DataEngineComponent);
structure->d->type = "Plasma/DataEngine";
} else if (packageFormat == "Plasma/Runner") {
structure = defaultPackageStructure(RunnerComponent);
structure->d->type = "Plasma/Runner";
} else if (packageFormat == "Plasma/Wallpaper") {
structure = defaultPackageStructure(WallpaperComponent);
structure->d->type = "Plasma/Wallpaper";
} else if (packageFormat == "Plasma/Theme") {
structure = Theme::packageStructure();
structure->d->type = "Plasma/Theme";
} else if (packageFormat == "Plasma/Generic") {
structure = defaultPackageStructure(GenericComponent);
structure->d->type = "Plasma/Generic";
structure->setDefaultPackageRoot(KStandardDirs::locate("data", "plasma/packages/"));
}
if (structure) {
return structure;
}
// first we check for plugins in sycoca
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
KService::List offers =
KServiceTypeTrader::self()->query("Plasma/PackageStructure", constraint);
QVariantList args;
QString error;
foreach (const KService::Ptr &offer, offers) {
PackageStructure::Ptr structure(
offer->createInstance<Plasma::PackageStructure>(0, args, &error));
if (structure) {
return structure;
}
kDebug() << "Couldn't load PackageStructure for" << packageFormat
<< "! reason given: " << error;
}
// if that didn't give us any love, then we try to load from a config file
structure = new PackageStructure();
QString configPath("plasma/packageformats/%1rc");
configPath = KStandardDirs::locate("data", configPath.arg(packageFormat));
if (!configPath.isEmpty()) {
KConfig config(configPath);
structure->read(&config);
return structure;
}
// try to load from absolute file path
KUrl url(packageFormat);
if (url.isLocalFile()) {
KConfig config(url.toLocalFile(), KConfig::SimpleConfig);
structure->read(&config);
}
#ifndef PLASMA_NO_KIO
else {
KTemporaryFile tmp;
if (tmp.open()) {
KIO::Job *job = KIO::file_copy(url, KUrl(tmp.fileName()),
-1, KIO::Overwrite | KIO::HideProgressInfo);
if (job->exec()) {
KConfig config(tmp.fileName(), KConfig::SimpleConfig);
structure->read(&config);
}
}
}
#endif
return structure;
Q_UNUSED(package)
}
PackageStructure &PackageStructure::operator=(const PackageStructure &rhs)
void PackageStructure::pathChanged(Package *package)
{
if (this == &rhs) {
return *this;
}
*d = *rhs.d;
return *this;
Q_UNUSED(package)
}
QString PackageStructure::type() const
bool PackageStructure::installPackage(Package *package, const QString &archivePath, const QString &packageRoot)
{
return d->type;
return PackagePrivate::installPackage(archivePath, packageRoot, package->servicePrefix());
}
QList<const char*> PackageStructure::directories() const
bool PackageStructure::uninstallPackage(Package *package, const QString &packageName, const QString &packageRoot)
{
QList<const char*> dirs;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (it.value().directory) {
dirs << it.key();
}
++it;
}
return dirs;
return PackagePrivate::uninstallPackage(packageName, packageRoot, package->servicePrefix());
}
QList<const char*> PackageStructure::requiredDirectories() const
{
QList<const char*> dirs;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (it.value().directory &&
it.value().required) {
dirs << it.key();
}
++it;
}
return dirs;
}
QList<const char*> PackageStructure::files() const
{
QList<const char*> files;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (!it.value().directory) {
files << it.key();
}
++it;
}
return files;
}
QList<const char*> PackageStructure::requiredFiles() const
{
QList<const char*> files;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (!it.value().directory && it.value().required) {
files << it.key();
}
++it;
}
return files;
}
QStringList PackageStructure::entryList(const char *key)
{
QString p = path(key);
if (p.isEmpty()) {
return QStringList();
}
QStringList list;
if (d->contentsPrefixPaths.isEmpty()) {
// no prefixes is the same as d->contentsPrefixPths with QStringList() << QString()
list << d->entryList(QString(), p);
} else {
foreach (QString prefix, d->contentsPrefixPaths) {
list << d->entryList(prefix, p);
}
}
return list;
}
QStringList PackageStructurePrivate::entryList(const QString &prefix, const QString &requestedPath)
{
QDir dir(path + prefix + requestedPath);
if (externalPaths) {
return dir.entryList(QDir::Files | QDir::Readable);
}
// ensure that we don't return files outside of our base path
// due to symlink or ../ games
QString canonicalized = dir.canonicalPath();
if (canonicalized.startsWith(path)) {
return dir.entryList(QDir::Files | QDir::Readable);
}
return QStringList();
}
void PackageStructure::addDirectoryDefinition(const char *key,
const QString &path, const QString &name)
{
ContentStructure s;
if (d->contents.contains(key)) {
s = d->contents[key];
}
if (!name.isEmpty()) {
s.name = name;
}
s.paths.append(path);
s.directory = true;
d->contents[key] = s;
}
void PackageStructure::addFileDefinition(const char *key, const QString &path, const QString &name)
{
ContentStructure s;
if (d->contents.contains(key)) {
s = d->contents[key];
}
if (!name.isEmpty()) {
s.name = name;
}
s.paths.append(path);
s.directory = false;
d->contents[key] = s;
}
void PackageStructure::removeDefinition(const char *key)
{
d->contents.remove(key);
}
QString PackageStructure::path(const char *key) const
{
//kDebug() << "looking for" << key;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QString();
}
//kDebug() << "found" << key << "and the value is" << it.value().paths.first();
return it.value().paths.first();
}
QStringList PackageStructure::searchPath(const char *key) const
{
//kDebug() << "looking for" << key;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QStringList();
}
//kDebug() << "found" << key << "and the value is" << it.value().paths;
return it.value().paths;
}
QString PackageStructure::name(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QString();
}
return it.value().name;
}
void PackageStructure::setRequired(const char *key, bool required)
{
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
if (it == d->contents.end()) {
return;
}
it.value().required = required;
}
bool PackageStructure::isRequired(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return false;
}
return it.value().required;
}
void PackageStructure::setDefaultMimetypes(QStringList mimetypes)
{
d->mimetypes = mimetypes;
}
void PackageStructure::setMimetypes(const char *key, QStringList mimetypes)
{
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
if (it == d->contents.end()) {
return;
}
it.value().mimetypes = mimetypes;
}
QStringList PackageStructure::mimetypes(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QStringList();
}
if (it.value().mimetypes.isEmpty()) {
return d->mimetypes;
}
return it.value().mimetypes;
}
void PackageStructure::setPath(const QString &path)
{
KUrl url(path);
QDir dir(url.toLocalFile());
QString basePath = dir.canonicalPath();
bool valid = QFile::exists(basePath);
if (valid) {
QFileInfo info(basePath);
if (info.isDir() && !basePath.endsWith('/')) {
basePath.append('/');
}
//kDebug() << "basePath is" << basePath;
} else {
kDebug() << path << "invalid, basePath is" << basePath;
return;
}
if (d->path == basePath) {
return;
}
d->path = basePath;
delete d->metadata;
d->metadata = 0;
pathChanged();
}
QString PackageStructure::path() const
{
return d->path;
}
void PackageStructure::pathChanged()
{
// default impl does nothing, this is a hook for subclasses.
}
void PackageStructure::read(const KConfigBase *config)
{
d->contents.clear();
d->mimetypes.clear();
KConfigGroup general(config, QString());
d->type = general.readEntry("Type", QString());
d->contentsPrefixPaths = general.readEntry("ContentsPrefixPaths", d->contentsPrefixPaths);
d->packageRoot = general.readEntry("DefaultPackageRoot", d->packageRoot);
d->externalPaths = general.readEntry("AllowExternalPaths", d->externalPaths);
QStringList groups = config->groupList();
foreach (const QString &group, groups) {
KConfigGroup entry(config, group);
QByteArray key = group.toAscii();
QString path = entry.readEntry("Path", QString());
QString name = entry.readEntry("Name", QString());
QStringList mimetypes = entry.readEntry("Mimetypes", QStringList());
bool directory = entry.readEntry("Directory", false);
bool required = entry.readEntry("Required", false);
if (directory) {
addDirectoryDefinition(key, path, name);
} else {
addFileDefinition(key, path, name);
}
setMimetypes(key, mimetypes);
setRequired(key, required);
}
}
void PackageStructure::write(KConfigBase *config) const
{
KConfigGroup general = KConfigGroup(config, "");
general.writeEntry("Type", type());
general.writeEntry("ContentsPrefixPaths", d->contentsPrefixPaths);
general.writeEntry("DefaultPackageRoot", d->packageRoot);
general.writeEntry("AllowExternalPaths", d->externalPaths);
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
KConfigGroup group = config->group(it.key());
group.writeEntry("Path", it.value().paths);
group.writeEntry("Name", it.value().name);
if (!it.value().mimetypes.isEmpty()) {
group.writeEntry("Mimetypes", it.value().mimetypes);
}
if (it.value().directory) {
group.writeEntry("Directory", true);
}
if (it.value().required) {
group.writeEntry("Required", true);
}
++it;
}
}
QString PackageStructure::contentsPrefix() const
{
return d->contentsPrefixPaths.isEmpty() ? QString() : d->contentsPrefixPaths.first();
}
void PackageStructure::setContentsPrefix(const QString &prefix)
{
d->contentsPrefixPaths.clear();
d->contentsPrefixPaths << prefix;
}
QStringList PackageStructure::contentsPrefixPaths() const
{
return d->contentsPrefixPaths;
}
void PackageStructure::setContentsPrefixPaths(const QStringList &prefixPaths)
{
d->contentsPrefixPaths = prefixPaths;
// the code assumes that the prefixes have a trailing slash
// so let's make that true here
QMutableStringListIterator it(d->contentsPrefixPaths);
while (it.hasNext()) {
it.next();
if (!it.value().endsWith('/')) {
it.setValue(it.value() % '/');
}
}
}
bool PackageStructure::installPackage(const QString &package, const QString &packageRoot)
{
return Package::installPackage(package, packageRoot, d->servicePrefix);
}
bool PackageStructure::uninstallPackage(const QString &packageName, const QString &packageRoot)
{
return Package::uninstallPackage(packageName, packageRoot, d->servicePrefix);
}
void PackageStructure::createNewWidgetBrowser(QWidget *parent)
{
Q_UNUSED(parent)
emit newWidgetBrowserFinished();
}
QString PackageStructure::defaultPackageRoot() const
{
return d->packageRoot;
}
QString PackageStructure::servicePrefix() const
{
return d->servicePrefix;
}
void PackageStructure::setDefaultPackageRoot(const QString &packageRoot)
{
d->packageRoot = packageRoot;
}
void PackageStructure::setServicePrefix(const QString &servicePrefix)
{
d->servicePrefix = servicePrefix;
}
void PackageStructurePrivate::createPackageMetadata(const QString &path)
{
delete metadata;
metadata = 0;
QString metadataPath(path + "/metadata.desktop");
if (!QFile::exists(metadataPath)) {
kWarning() << "No metadata file in the package, expected it at:" << metadataPath;
metadataPath.clear();
}
metadata = new PackageMetadata(metadataPath);
}
//FIXME KDE5: should be const
PackageMetadata PackageStructure::metadata()
{
if (!d->metadata && !d->path.isEmpty()) {
QFileInfo fileInfo(d->path);
if (fileInfo.isDir()) {
d->createPackageMetadata(d->path);
} else if (fileInfo.exists()) {
KArchive *archive = 0;
KMimeType::Ptr mimetype = KMimeType::findByPath(d->path);
if (mimetype->is("application/zip")) {
archive = new KZip(d->path);
} else if (mimetype->is("application/x-compressed-tar") || mimetype->is("application/x-gzip") ||
mimetype->is("application/x-tar")|| mimetype->is("application/x-bzip-compressed-tar")) {
archive = new KTar(d->path);
} else {
kWarning() << "Could not open package file, unsupported archive format:" << d->path << mimetype->name();
}
if (archive && archive->open(QIODevice::ReadOnly)) {
const KArchiveDirectory *source = archive->directory();
KTempDir tempdir;
source->copyTo(tempdir.name());
d->createPackageMetadata(tempdir.name());
} else {
kWarning() << "Could not open package file:" << d->path;
}
delete archive;
}
}
if (!d->metadata) {
d->metadata = new PackageMetadata();
}
return *d->metadata;
}
bool PackageStructure::allowExternalPaths() const
{
return d->externalPaths;
}
void PackageStructure::setAllowExternalPaths(bool allow)
{
d->externalPaths = allow;
}
} // Plasma namespace
#include "packagestructure.moc"
#include "moc_packagestructure.cpp"

View File

@ -27,23 +27,68 @@
#include <kconfiggroup.h>
#include <kdesktopfile.h>
#include <klocale.h>
#include <klocalizedstring.h>
#include <kmessagebox.h>
#ifndef PLASMA_NO_KNEWSTUFF
#include <knewstuff3/downloaddialog.h>
#endif
#include "kdeclarative.h"
#include "private/wallpaper_p.h"
#include "package.h"
#include "config-plasma.h"
namespace Plasma
{
PlasmoidPackage::PlasmoidPackage(QObject *parent)
: Plasma::PackageStructure(parent, QString("Plasmoid"))
void ChangeableMainScriptPackage::initPackage(Package *package)
{
package->addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
package->setRequired("mainscript", true);
}
QString ChangeableMainScriptPackage::findMainScript(Package *package) const
{
Q_UNUSED(package)
return QString();
}
QString ChangeableMainScriptPackage::mainScriptConfigKey() const
{
return QLatin1String("X-Plasma-MainScript");
}
void ChangeableMainScriptPackage::pathChanged(Package *package)
{
KDesktopFile config(package->path() + "/metadata.desktop");
KConfigGroup cg = config.desktopGroup();
QString mainScript = cg.readEntry(mainScriptConfigKey(), QString());
if (mainScript.isEmpty()) {
mainScript = findMainScript(package);
if (mainScript.isEmpty()) {
mainScript = package->path() + "/code/main.js";
if (!QFile::exists(mainScript)) {
mainScript.clear();
}
}
}
if (!mainScript.isEmpty()) {
package->addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
}
}
QString PlasmoidPackage::findMainScript(Package *package) const
{
const QString mainScript = package->path() + "/ui/main.qml";
if (QFile::exists(mainScript)) {
return mainScript;
}
return QString();
}
void PlasmoidPackage::initPackage(Package *package)
{
ChangeableMainScriptPackage::initPackage(package);
QStringList platform = KDeclarative::runtimePlatform();
if (!platform.isEmpty()) {
QMutableStringListIterator it(platform);
@ -51,384 +96,190 @@ PlasmoidPackage::PlasmoidPackage(QObject *parent)
it.next();
it.setValue("platformcontents/" + it.value());
}
platform.append("contents");
setContentsPrefixPaths(platform);
package->setContentsPrefixPaths(platform);
}
addDirectoryDefinition("images", "images", i18n("Images"));
package->setServicePrefix("plasma-applet-");
package->setDefaultPackageRoot("plasma/plasmoids");
package->addDirectoryDefinition("images", "images", i18n("Images"));
QStringList mimetypes;
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 << "text/xml";
setMimetypes("config", mimetypes);
package->setMimeTypes("config", mimetypes);
addDirectoryDefinition("ui", "ui", i18n("User Interface"));
setMimetypes("ui", mimetypes);
package->addDirectoryDefinition("ui", "ui", i18n("User Interface"));
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 << "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"));
addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
addFileDefinition("defaultconfig", "config/default-configrc", i18n("Default configuration"));
addDirectoryDefinition("animations", "animations", i18n("Animation scripts"));
setRequired("mainscript", true);
package->addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File"));
package->addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file"));
package->addDirectoryDefinition("animations", "animations", i18n("Animation scripts"));
}
PlasmoidPackage::~PlasmoidPackage()
QString ContainmentPackage::mainScriptConfigKey() const
{
#ifndef PLASMA_NO_KNEWSTUFF
if (!QCoreApplication::closingDown()) {
// let it "leak" on application close as this causes crashes otherwise, BUG 288153
delete m_knsDialog.data();
}
#endif
return QLatin1String("X-Plasma-Containment-MainScript");
}
void PlasmoidPackage::pathChanged()
void DataEnginePackage::initPackage(Package *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);
}
}
ChangeableMainScriptPackage::initPackage(package);
package->setServicePrefix("plasma-dataengine-");
package->setDefaultPackageRoot("plasma/dataengines/");
void PlasmoidPackage::createNewWidgetBrowser(QWidget *parent)
{
#ifndef PLASMA_NO_KNEWSTUFF
KNS3::DownloadDialog *knsDialog = m_knsDialog.data();
if (!knsDialog) {
m_knsDialog = knsDialog = new KNS3::DownloadDialog("plasmoids.knsrc", parent);
knsDialog->setProperty("DoNotCloseController", true);
connect(knsDialog, SIGNAL(accepted()), this, SIGNAL(newWidgetBrowserFinished()));
connect(knsDialog, SIGNAL(accepted()), knsDialog, SLOT(deleteLater()));
}
package->addDirectoryDefinition("data", "data", i18n("Data Files"));
knsDialog->show();
knsDialog->raise();
#endif
}
DataEnginePackage::DataEnginePackage(QObject *parent)
: Plasma::PackageStructure(parent, QString("DataEngine"))
{
setServicePrefix("plasma-dataengine-");
setDefaultPackageRoot("plasma/dataengine/");
addDirectoryDefinition("data", "data", i18n("Data Files"));
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
QStringList mimetypes;
mimetypes << "text/plain";
setMimetypes("scripts", mimetypes);
package->setMimeTypes("scripts", mimetypes);
addDirectoryDefinition("services", "services/", i18n("Service Descriptions"));
setMimetypes("services", mimetypes);
package->addDirectoryDefinition("services", "services/", i18n("Service Descriptions"));
package->setMimeTypes("services", mimetypes);
addDirectoryDefinition("translations", "locale", i18n("Translations"));
addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
setRequired("mainscript", true);
package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
}
DataEnginePackage::~DataEnginePackage()
void RunnerPackage::initPackage(Package *package)
{
ChangeableMainScriptPackage::initPackage(package);
package->setServicePrefix("plasma-runner-");
package->setDefaultPackageRoot("plasma/runners/");
package->addDirectoryDefinition("data", "data", i18n("Data Files"));
package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
QStringList mimetypes;
mimetypes << "text/plain";
package->setMimeTypes("scripts", mimetypes);
package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
}
void DataEnginePackage::pathChanged()
void ThemePackage::initPackage(Package *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"));
addFileDefinition("dialogs/background", "dialogs/background.svg",
package->addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs"));
package->addFileDefinition("dialogs/background", "dialogs/background.svg",
i18n("Generic dialog background"));
addFileDefinition("dialogs/background", "dialogs/background.svgz",
package->addFileDefinition("dialogs/background", "dialogs/background.svgz",
i18n("Generic dialog background"));
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
package->addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
i18n("Theme for the logout dialog"));
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svgz",
package->addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svgz",
i18n("Theme for the logout dialog"));
addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages"));
addDirectoryDefinition("animations", "animations/", i18n("Animation scripts"));
package->addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages"));
package->addDirectoryDefinition("animations", "animations/", i18n("Animation scripts"));
addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
addFileDefinition("widgets/background", "widgets/background.svg",
package->addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
package->addFileDefinition("widgets/background", "widgets/background.svg",
i18n("Background image for widgets"));
addFileDefinition("widgets/background", "widgets/background.svgz",
package->addFileDefinition("widgets/background", "widgets/background.svgz",
i18n("Background image for widgets"));
addFileDefinition("widgets/clock", "widgets/clock.svg",
package->addFileDefinition("widgets/clock", "widgets/clock.svg",
i18n("Analog clock face"));
addFileDefinition("widgets/clock", "widgets/clock.svgz",
package->addFileDefinition("widgets/clock", "widgets/clock.svgz",
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"));
addFileDefinition("widgets/panel-background", "widgets/panel-background.svgz",
package->addFileDefinition("widgets/panel-background", "widgets/panel-background.svgz",
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"));
addFileDefinition("widgets/plot-background", "widgets/plot-background.svg",
package->addFileDefinition("widgets/plot-background", "widgets/plot-background.svgz",
i18n("Background for graphing widgets"));
addFileDefinition("widgets/tooltip", "widgets/tooltip.svg",
package->addFileDefinition("widgets/tooltip", "widgets/tooltip.svg",
i18n("Background image for tooltips"));
addFileDefinition("widgets/tooltip", "widgets/tooltip.svgz",
package->addFileDefinition("widgets/tooltip", "widgets/tooltip.svgz",
i18n("Background image for tooltips"));
addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs"));
addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg",
package->addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs"));
package->addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg",
i18n("Opaque generic dialog background"));
addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svgz",
package->addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svgz",
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"));
addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svgz",
package->addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svgz",
i18n("Opaque theme for the logout dialog"));
addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets"));
addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg",
package->addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets"));
package->addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg",
i18n("Opaque background image for panels"));
addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svgz",
package->addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svgz",
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"));
addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svgz",
package->addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svgz",
i18n("Opaque background image for tooltips"));
addDirectoryDefinition("locolor/dialogs", "locolor/dialogs/",
package->addDirectoryDefinition("locolor/dialogs", "locolor/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"));
addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svgz",
package->addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svgz",
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"));
addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svgz",
package->addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svgz",
i18n("Low color theme for the logout dialog"));
addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets"));
addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg",
package->addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets"));
package->addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg",
i18n("Low color background image for widgets"));
addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svgz",
package->addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svgz",
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"));
addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svgz",
package->addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svgz",
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"));
addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svgz",
package->addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svgz",
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"));
addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svgz",
package->addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svgz",
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"));
addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svgz",
package->addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svgz",
i18n("Low color background image for tooltips"));
addFileDefinition("colors", "colors", i18n("KColorScheme configuration file"));
package->addFileDefinition("colors", "colors", i18n("KColorScheme configuration file"));
QStringList mimetypes;
mimetypes << "image/svg+xml";
setDefaultMimetypes(mimetypes);
package->setDefaultMimeTypes(mimetypes);
}
WallpaperPackage::WallpaperPackage(Wallpaper *paper, QObject *parent)
: PackageStructure(parent, "Background"),
m_paper(paper),
m_fullPackage(true),
m_targetSize(100000, 100000),
m_resizeMethod(Wallpaper::ScaledResize)
void ContainmentActionsPackage::initPackage(Package *package)
{
QStringList mimetypes;
mimetypes << "image/svg" << "image/png" << "image/jpeg" << "image/jpg";
setDefaultMimetypes(mimetypes);
addDirectoryDefinition("images", "images/", i18n("Images"));
setRequired("images", true);
addFileDefinition("screenshot", "screenshot.png", i18n("Screenshot"));
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()));
}
ChangeableMainScriptPackage::initPackage(package);
package->setDefaultPackageRoot("plasma/containmentactions/");
}
void WallpaperPackage::renderHintsChanged()
void GenericPackage::initPackage(Package *package)
{
if (m_paper) {
m_targetSize = m_paper->d->targetSize.toSize();
m_resizeMethod = m_paper->d->lastResizeMethod;
}
if (m_fullPackage) {
findBestPaper();
}
}
void WallpaperPackage::pathChanged()
{
static bool guard = false;
if (guard) {
return;
}
guard = true;
QFileInfo info(path());
m_fullPackage = info.isDir();
removeDefinition("preferred");
setRequired("images", m_fullPackage);
if (m_fullPackage) {
setContentsPrefixPaths(QStringList() << "contents/");
findBestPaper();
} else {
// dirty trick to support having a file passed in instead of a directory
addFileDefinition("preferred", info.fileName(), i18n("Recommended wallpaper file"));
setContentsPrefixPaths(QStringList());
//kDebug() << "changing" << path() << "to" << info.path();
setPath(info.path());
}
guard = false;
}
QSize WallpaperPackage::resSize(const QString &str) const
{
int index = str.indexOf('x');
if (index != -1) {
return QSize(str.left(index).toInt(),
str.mid(index + 1).toInt());
} else {
return QSize();
}
}
void WallpaperPackage::findBestPaper()
{
QStringList images = entryList("images");
if (images.empty()) {
return;
}
//kDebug() << "wanted" << size;
// choose the nearest resolution
float best = FLT_MAX;
QString bestImage;
foreach (const QString &entry, images) {
QSize candidate = resSize(QFileInfo(entry).baseName());
if (candidate == QSize()) {
continue;
}
double dist = distance(candidate, m_targetSize, m_resizeMethod);
//kDebug() << "candidate" << candidate << "distance" << dist;
if (bestImage.isEmpty() || dist < best) {
bestImage = entry;
best = dist;
//kDebug() << "best" << bestImage;
if (dist == 0) {
break;
}
}
}
//kDebug() << "best image" << bestImage;
addFileDefinition("preferred", path("images") + bestImage, i18n("Recommended wallpaper file"));
}
float WallpaperPackage::distance(const QSize& size, const QSize& desired,
Plasma::Wallpaper::ResizeMethod method) const
{
// compute difference of areas
float delta = size.width() * size.height() -
desired.width() * desired.height();
// scale down to about 1.0
delta /= ((desired.width() * desired.height())+(size.width() * size.height()))/2;
switch (method) {
case Plasma::Wallpaper::ScaledResize: {
// Consider first the difference in aspect ratio,
// then in areas. Prefer scaling down.
float deltaRatio = 1.0;
if (size.height() > 0 && desired.height() > 0) {
deltaRatio = float(size.width()) / float(size.height()) -
float(desired.width()) / float(desired.height());
}
return fabs(deltaRatio) * 3.0 + (delta >= 0.0 ? delta : -delta + 5.0);
}
case Plasma::Wallpaper::ScaledAndCroppedResize:
// Difference of areas, slight preference to scale down
return delta >= 0.0 ? delta : -delta + 2.0;
default:
// Difference in areas
return fabs(delta);
}
}
void WallpaperPackage::paperDestroyed()
{
m_paper = 0;
}
ContainmentActionsPackage::ContainmentActionsPackage(QObject *parent)
: Plasma::PackageStructure(parent, QString("ContainmentActions"))
{
//FIXME how do I do the mimetypes stuff?
package->setDefaultPackageRoot("plasma/packages/");
}
} // namespace Plasma
#include "packages_p.moc"
#include "moc_packages_p.cpp"