Merge remote-tracking branch 'origin/KDE/4.10' into frameworks
Conflicts: CMakeLists.txt [version] README [version] cmake/modules/CMakeLists.txt cmake/modules/FindKDE4Internal.cmake cmake/modules/FindNepomuk.cmake [git replaying an old conflict!] cmake/modules/KDE4Macros.cmake [automoc4 stuff, reverted] interfaces/ktexteditor/* [moved out] kdecore/services/kmimetype.cpp [hand-merged into kio/global.cpp] kdeui/util/kkeyserver.h kdeui/widgets/ktextedit.cpp kdewebkit/kwebwallet.cpp khtml/misc/enum.h [git got confused, me thinks] kio/kio/accessmanager.cpp kio/kio/hostinfo.cpp kio/kio/kprotocolmanager.cpp kio/kio/kprotocolmanager.h kioslave/http/http.cpp kioslave/http/http.h kioslave/http/tests/CMakeLists.txt kioslave/http/tests/httpheaderdispositiontest.cpp nepomuk/core/* [moved out] plasma/CMakeLists.txt plasma/applet.cpp plasma/applet.h plasma/dialog.cpp plasma/packagestructure.cpp plasma/popupapplet.cpp plasma/private/applethandle.cpp plasma/private/packages.cpp plasma/private/tooltip.cpp plasma/tooltipmanager.cpp plasma/widgets/videowidget.h staging/ki18n/src/klocalizedstring.cpp staging/kservice/autotests/kservicetest.cpp staging/kwidgets/src/utils/kglobalsettings.cpp tier1/solid/src/solid/backends/udisks2/udisksstorageaccess.cpp tier1/solid/src/solid/backends/upower/upoweracadapter.cpp tier1/solid/src/solid/backends/upower/upowerbattery.cpp
This commit is contained in:
commit
bdb7251250
@ -124,6 +124,7 @@ set(plasma_LIB_SRCS
|
||||
private/dataenginemanager.cpp
|
||||
private/dataengineservice.cpp
|
||||
private/effects/halopainter.cpp
|
||||
private/dialogshadows.cpp
|
||||
private/getsource.cpp
|
||||
private/packages.cpp
|
||||
private/plasmoidservice.cpp
|
||||
|
344
applet.h
344
applet.h
@ -22,22 +22,26 @@
|
||||
#ifndef PLASMA_APPLET_H
|
||||
#define PLASMA_APPLET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QIcon>
|
||||
#include <QtGui/QGraphicsItem>
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
#include <QtGui/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
|
||||
@ -45,7 +49,10 @@ namespace Plasma
|
||||
|
||||
class AppletPrivate;
|
||||
class Containment;
|
||||
class Context;
|
||||
class DataEngine;
|
||||
class Extender;
|
||||
class ExtenderItem;
|
||||
class Package;
|
||||
|
||||
|
||||
@ -67,28 +74,50 @@ class Package;
|
||||
*
|
||||
* See techbase.kde.org for tutorials on writing Applets using this class.
|
||||
*/
|
||||
class PLASMA_EXPORT Applet : public QObject
|
||||
class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString pluginName READ pluginName)
|
||||
Q_PROPERTY(QString category READ category)
|
||||
Q_PROPERTY(QString name READ name CONSTANT)
|
||||
Q_PROPERTY(QString pluginName READ pluginName CONSTANT)
|
||||
Q_PROPERTY(QString category READ category CONSTANT)
|
||||
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)
|
||||
Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints)
|
||||
Q_PROPERTY(uint id READ id CONSTANT)
|
||||
Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
|
||||
Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints)
|
||||
Q_ENUMS(BackgroundHints)
|
||||
|
||||
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
|
||||
*/
|
||||
@ -103,6 +132,15 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
**/
|
||||
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.
|
||||
@ -167,7 +205,29 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*
|
||||
* @return the Package object, or 0 if none
|
||||
**/
|
||||
Package package() const;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Reccomended position for a popup window like a menu or a tooltip
|
||||
@ -210,6 +270,11 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -245,7 +310,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*
|
||||
* @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.
|
||||
@ -300,6 +365,38 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
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
|
||||
*
|
||||
@ -314,20 +411,26 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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. Can be changed with @see setName
|
||||
* .desktop file.
|
||||
*
|
||||
* @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
|
||||
**/
|
||||
@ -362,6 +465,9 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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,
|
||||
@ -411,19 +517,38 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*
|
||||
* @param hints the BackgroundHint combination for this applet
|
||||
*/
|
||||
void setBackgroundHints(const Plasma::BackgroundHints hint);
|
||||
void setBackgroundHints(const BackgroundHints hints);
|
||||
|
||||
/**
|
||||
* @return BackgroundHints flags combination telling if the standard background is shown
|
||||
* and if it has a drop shadow
|
||||
*/
|
||||
Plasma::BackgroundHints backgroundHints() const;
|
||||
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
|
||||
**/
|
||||
@ -460,25 +585,46 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
virtual void removeAssociatedWidget(QWidget *widget);
|
||||
|
||||
/**
|
||||
* @param parent the QObject this applet is parented to
|
||||
* 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 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(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
|
||||
explicit Applet(QGraphicsItem *parent = 0,
|
||||
const QString &serviceId = QString(),
|
||||
uint appletId = 0);
|
||||
|
||||
/**
|
||||
* @param parent the QObject this applet is parented to
|
||||
* @param parent the QGraphicsItem 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, QObject *parent = 0, uint appletId = 0);
|
||||
explicit Applet(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0);
|
||||
|
||||
/**
|
||||
* @param parent the QObject this applet is parented to
|
||||
* @param parent the QGraphicsItem 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
|
||||
@ -487,7 +633,10 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
* and the applet id
|
||||
* @since 4.3
|
||||
*/
|
||||
explicit Applet(QObject *parent, const QString &serviceId, uint appletId, const QVariantList &args);
|
||||
explicit Applet(QGraphicsItem *parent,
|
||||
const QString &serviceId,
|
||||
uint appletId,
|
||||
const QVariantList &args);
|
||||
|
||||
|
||||
/**
|
||||
@ -548,7 +697,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*
|
||||
* @param urls
|
||||
*/
|
||||
void setAssociatedApplicationUrls(const QList<QUrl> &urls);
|
||||
void setAssociatedApplicationUrls(const KUrl::List &urls);
|
||||
|
||||
/**
|
||||
* @return the application associated to this applet
|
||||
@ -560,7 +709,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
* @return the urls associated to this applet
|
||||
* @since 4.4
|
||||
*/
|
||||
QList<QUrl> associatedApplicationUrls() const;
|
||||
KUrl::List associatedApplicationUrls() const;
|
||||
|
||||
/**
|
||||
* @return true if the applet has a valid associated application or urls
|
||||
@ -577,6 +726,18 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -587,6 +748,11 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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
|
||||
@ -615,7 +781,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
/**
|
||||
* Emitted when the applet is deleted
|
||||
*/
|
||||
void appletDeleted(Plasma::Applet *applet);
|
||||
void appletDestroyed(Plasma::Applet *applet);
|
||||
|
||||
/**
|
||||
* Emitted when the applet status changes
|
||||
@ -623,12 +789,17 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void immutabilityChanged(Plasma::ImmutabilityType immutable);
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Sets the immutability type for this applet (not immutable,
|
||||
@ -674,6 +845,16 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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.
|
||||
@ -682,7 +863,7 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
|
||||
/**
|
||||
* This method is called once the applet is loaded and added to a Corona.
|
||||
* If the applet requires a Scene or has an particularly intensive
|
||||
* If the applet requires a QGraphicsScene or has an particularly intensive
|
||||
* set of initialization routines to go through, consider implementing it
|
||||
* in this method instead of the constructor.
|
||||
*
|
||||
@ -743,9 +924,6 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
void runAssociatedApplication();
|
||||
|
||||
bool hasFocus() const;
|
||||
void setFocus(Qt::FocusReason);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor is to be used with the plugin loading systems
|
||||
@ -844,6 +1022,84 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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
|
||||
@ -862,12 +1118,23 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -880,15 +1147,22 @@ class PLASMA_EXPORT Applet : public QObject
|
||||
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
|
||||
*/
|
||||
|
@ -173,20 +173,32 @@ void DeclarativeWidgetPrivate::finishExecute()
|
||||
object->setProperty("width", q->size().width());
|
||||
object->setProperty("height", q->size().height());
|
||||
|
||||
minimumWidth = object->property("minimumWidth").toReal();
|
||||
minimumHeight = object->property("minimumHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(minimumWidthChanged()), q, SLOT(minimumWidthChanged()));
|
||||
QObject::connect(object, SIGNAL(minimumHeightChanged()), q, SLOT(minimumHeightChanged()));
|
||||
if (object->metaObject()->indexOfProperty("minimumWidth")>=0) {
|
||||
minimumWidth = object->property("minimumWidth").toReal();
|
||||
QObject::connect(object, SIGNAL(minimumWidthChanged()), q, SLOT(minimumWidthChanged()));
|
||||
}
|
||||
if (object->metaObject()->indexOfProperty("minimumHeight")>=0) {
|
||||
minimumHeight = object->property("minimumHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(minimumHeightChanged()), q, SLOT(minimumHeightChanged()));
|
||||
}
|
||||
|
||||
maximumWidth = object->property("maximumWidth").toReal();
|
||||
maximumHeight = object->property("maximumHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(maximumWidthChanged()), q, SLOT(maximumWidthChanged()));
|
||||
QObject::connect(object, SIGNAL(maximumHeightChanged()), q, SLOT(maximumHeightChanged()));
|
||||
if (object->metaObject()->indexOfProperty("maximumWidth")>=0) {
|
||||
maximumWidth = object->property("maximumWidth").toReal();
|
||||
QObject::connect(object, SIGNAL(maximumWidthChanged()), q, SLOT(maximumWidthChanged()));
|
||||
}
|
||||
if (object->metaObject()->indexOfProperty("maximumHeight")>=0) {
|
||||
maximumHeight = object->property("maximumHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(maximumHeightChanged()), q, SLOT(maximumHeightChanged()));
|
||||
}
|
||||
|
||||
preferredWidth = object->property("preferredWidth").toReal();
|
||||
preferredHeight = object->property("preferredHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(preferredWidthChanged()), q, SLOT(preferredWidthChanged()));
|
||||
QObject::connect(object, SIGNAL(preferredHeightChanged()), q, SLOT(preferredHeightChanged()));
|
||||
if (object->metaObject()->indexOfProperty("preferredWidth")>=0) {
|
||||
preferredWidth = object->property("preferredWidth").toReal();
|
||||
QObject::connect(object, SIGNAL(preferredWidthChanged()), q, SLOT(preferredWidthChanged()));
|
||||
}
|
||||
if (object->metaObject()->indexOfProperty("preferredHeight")>=0) {
|
||||
preferredHeight = object->property("preferredHeight").toReal();
|
||||
QObject::connect(object, SIGNAL(preferredHeightChanged()), q, SLOT(preferredHeightChanged()));
|
||||
}
|
||||
}
|
||||
|
||||
if (minimumWidth > 0 && minimumHeight > 0) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org> *
|
||||
* Copyright 2007 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,44 +18,652 @@
|
||||
*******************************************************************************/
|
||||
|
||||
#include "packagestructure.h"
|
||||
#include "private/package_p.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"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
PackageStructure::PackageStructure(QObject *parent, const QVariantList &args)
|
||||
: QObject(parent),
|
||||
d(0)
|
||||
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)
|
||||
: QObject(parent),
|
||||
d(new PackageStructurePrivate(type))
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
}
|
||||
|
||||
PackageStructure::~PackageStructure()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void PackageStructure::initPackage(Package *package)
|
||||
PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
|
||||
{
|
||||
Q_UNUSED(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;
|
||||
}
|
||||
|
||||
void PackageStructure::pathChanged(Package *package)
|
||||
PackageStructure &PackageStructure::operator=(const PackageStructure &rhs)
|
||||
{
|
||||
Q_UNUSED(package)
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
*d = *rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool PackageStructure::installPackage(Package *package, const QString &archivePath, const QString &packageRoot)
|
||||
QString PackageStructure::type() const
|
||||
{
|
||||
return PackagePrivate::installPackage(archivePath, packageRoot, package->servicePrefix());
|
||||
return d->type;
|
||||
}
|
||||
|
||||
bool PackageStructure::uninstallPackage(Package *package, const QString &packageName, const QString &packageRoot)
|
||||
QList<const char*> PackageStructure::directories() const
|
||||
{
|
||||
return PackagePrivate::uninstallPackage(packageName, packageRoot, package->servicePrefix());
|
||||
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;
|
||||
}
|
||||
|
||||
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"
|
||||
|
4
plasma.h
4
plasma.h
@ -72,8 +72,10 @@ enum FormFactor {
|
||||
referred to as a "ten foot interface".*/
|
||||
Horizontal, /**< The applet is constrained vertically, but
|
||||
can expand horizontally. */
|
||||
Vertical /**< The applet is constrained horizontally, but
|
||||
Vertical, /**< The applet is constrained horizontally, but
|
||||
can expand vertically. */
|
||||
Application /**< The Applet lives in a plane and should be optimized to look as a full application,
|
||||
for the desktop or the particular device. */
|
||||
};
|
||||
|
||||
/**
|
||||
|
381
private/dialogshadows.cpp
Normal file
381
private/dialogshadows.cpp
Normal file
@ -0,0 +1,381 @@
|
||||
/*
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "dialogshadows_p.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <QX11Info>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <fixx11h.h>
|
||||
#endif
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kglobal.h>
|
||||
|
||||
class DialogShadows::Private
|
||||
{
|
||||
public:
|
||||
Private(DialogShadows *shadows)
|
||||
: q(shadows),
|
||||
m_managePixmaps(false)
|
||||
{
|
||||
}
|
||||
|
||||
~Private()
|
||||
{
|
||||
clearPixmaps();
|
||||
}
|
||||
|
||||
void clearPixmaps();
|
||||
void setupPixmaps();
|
||||
void initPixmap(const QString &element);
|
||||
QPixmap initEmptyPixmap(const QSize &size);
|
||||
void updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders);
|
||||
void clearShadow(const QWidget *window);
|
||||
void updateShadows();
|
||||
void windowDestroyed(QObject *deletedObject);
|
||||
void setupData(Plasma::FrameSvg::EnabledBorders enabledBorders);
|
||||
|
||||
DialogShadows *q;
|
||||
QList<QPixmap> m_shadowPixmaps;
|
||||
|
||||
QPixmap m_emptyCornerPix;
|
||||
QPixmap m_emptyCornerLeftPix;
|
||||
QPixmap m_emptyCornerTopPix;
|
||||
QPixmap m_emptyCornerRightPix;
|
||||
QPixmap m_emptyCornerBottomPix;
|
||||
QPixmap m_emptyVerticalPix;
|
||||
QPixmap m_emptyHorizontalPix;
|
||||
|
||||
QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long> > data;
|
||||
QHash<const QWidget *, Plasma::FrameSvg::EnabledBorders> m_windows;
|
||||
bool m_managePixmaps;
|
||||
};
|
||||
|
||||
class DialogShadowsSingleton
|
||||
{
|
||||
public:
|
||||
DialogShadowsSingleton()
|
||||
{
|
||||
}
|
||||
|
||||
DialogShadows self;
|
||||
};
|
||||
|
||||
K_GLOBAL_STATIC(DialogShadowsSingleton, privateDialogShadowsSelf)
|
||||
|
||||
DialogShadows::DialogShadows(QObject *parent, const QString &prefix)
|
||||
: Plasma::Svg(parent),
|
||||
d(new Private(this))
|
||||
{
|
||||
setImagePath(prefix);
|
||||
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateShadows()));
|
||||
}
|
||||
|
||||
DialogShadows *DialogShadows::self()
|
||||
{
|
||||
return &privateDialogShadowsSelf->self;
|
||||
}
|
||||
|
||||
void DialogShadows::addWindow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
|
||||
{
|
||||
if (!window || !window->isWindow()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_windows[window] = enabledBorders;
|
||||
d->updateShadow(window, enabledBorders);
|
||||
connect(window, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(windowDestroyed(QObject*)), Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void DialogShadows::removeWindow(const QWidget *window)
|
||||
{
|
||||
if (!d->m_windows.contains(window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_windows.remove(window);
|
||||
disconnect(window, 0, this, 0);
|
||||
d->clearShadow(window);
|
||||
|
||||
if (d->m_windows.isEmpty()) {
|
||||
d->clearPixmaps();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogShadows::Private::windowDestroyed(QObject *deletedObject)
|
||||
{
|
||||
m_windows.remove(static_cast<QWidget *>(deletedObject));
|
||||
|
||||
if (m_windows.isEmpty()) {
|
||||
clearPixmaps();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogShadows::Private::updateShadows()
|
||||
{
|
||||
setupPixmaps();
|
||||
QHash<const QWidget *, Plasma::FrameSvg::EnabledBorders>::const_iterator i;
|
||||
for (i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) {
|
||||
updateShadow(i.key(), i.value());
|
||||
}
|
||||
}
|
||||
|
||||
void DialogShadows::Private::initPixmap(const QString &element)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
QPixmap pix = q->pixmap(element);
|
||||
if (!pix.isNull() && pix.handle() == 0) {
|
||||
Pixmap xPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), pix.width(), pix.height(), 32);
|
||||
QPixmap tempPix = QPixmap::fromX11Pixmap(xPix, QPixmap::ExplicitlyShared);
|
||||
tempPix.fill(Qt::transparent);
|
||||
QPainter p(&tempPix);
|
||||
p.drawPixmap(QPoint(0, 0), pix);
|
||||
m_shadowPixmaps << tempPix;
|
||||
m_managePixmaps = true;
|
||||
} else {
|
||||
m_shadowPixmaps << pix;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QPixmap DialogShadows::Private::initEmptyPixmap(const QSize &size)
|
||||
{
|
||||
Pixmap emptyXPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), size.width(), size.height(), 32);
|
||||
QPixmap tempEmptyPix = QPixmap::fromX11Pixmap(emptyXPix, QPixmap::ExplicitlyShared);
|
||||
tempEmptyPix.fill(Qt::transparent);
|
||||
return tempEmptyPix;
|
||||
}
|
||||
|
||||
void DialogShadows::Private::setupPixmaps()
|
||||
{
|
||||
clearPixmaps();
|
||||
initPixmap("shadow-top");
|
||||
initPixmap("shadow-topright");
|
||||
initPixmap("shadow-right");
|
||||
initPixmap("shadow-bottomright");
|
||||
initPixmap("shadow-bottom");
|
||||
initPixmap("shadow-bottomleft");
|
||||
initPixmap("shadow-left");
|
||||
initPixmap("shadow-topleft");
|
||||
|
||||
m_emptyCornerPix = initEmptyPixmap(QSize(1,1));
|
||||
m_emptyCornerLeftPix = initEmptyPixmap(QSize(q->elementSize("shadow-topleft").width(), 1));
|
||||
m_emptyCornerTopPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-topleft").height()));
|
||||
m_emptyCornerRightPix = initEmptyPixmap(QSize(q->elementSize("shadow-bottomright").width(), 1));
|
||||
m_emptyCornerBottomPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-bottomright").height()));
|
||||
m_emptyVerticalPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-left").height()));
|
||||
m_emptyHorizontalPix = initEmptyPixmap(QSize(q->elementSize("shadow-top").width(), 1));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
//shadow-top
|
||||
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[0].handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyHorizontalPix.handle();
|
||||
}
|
||||
|
||||
//shadow-topright
|
||||
if (enabledBorders & Plasma::FrameSvg::TopBorder &&
|
||||
enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[1].handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::TopBorder) {
|
||||
data[enabledBorders] << m_emptyCornerTopPix.handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
data[enabledBorders] << m_emptyCornerRightPix.handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyCornerPix.handle();
|
||||
}
|
||||
|
||||
//shadow-right
|
||||
if (enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[2].handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyVerticalPix.handle();
|
||||
}
|
||||
|
||||
//shadow-bottomright
|
||||
if (enabledBorders & Plasma::FrameSvg::BottomBorder &&
|
||||
enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[3].handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
|
||||
data[enabledBorders] << m_emptyCornerBottomPix.handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
data[enabledBorders] << m_emptyCornerRightPix.handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyCornerPix.handle();
|
||||
}
|
||||
|
||||
//shadow-bottom
|
||||
if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[4].handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyHorizontalPix.handle();
|
||||
}
|
||||
|
||||
//shadow-bottomleft
|
||||
if (enabledBorders & Plasma::FrameSvg::BottomBorder &&
|
||||
enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[5].handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
|
||||
data[enabledBorders] << m_emptyCornerBottomPix.handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
data[enabledBorders] << m_emptyCornerLeftPix.handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyCornerPix.handle();
|
||||
}
|
||||
|
||||
//shadow-left
|
||||
if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[6].handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyVerticalPix.handle();
|
||||
}
|
||||
|
||||
//shadow-topleft
|
||||
if (enabledBorders & Plasma::FrameSvg::TopBorder &&
|
||||
enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
data[enabledBorders] << m_shadowPixmaps[7].handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::TopBorder) {
|
||||
data[enabledBorders] << m_emptyCornerTopPix.handle();
|
||||
} else if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
data[enabledBorders] << m_emptyCornerLeftPix.handle();
|
||||
} else {
|
||||
data[enabledBorders] << m_emptyCornerPix.handle();
|
||||
}
|
||||
#endif
|
||||
|
||||
int left, top, right, bottom = 0;
|
||||
|
||||
QSize marginHint;
|
||||
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
|
||||
marginHint = q->elementSize("shadow-hint-top-margin");
|
||||
if (marginHint.isValid()) {
|
||||
top = marginHint.height();
|
||||
} else {
|
||||
top = m_shadowPixmaps[0].height(); // top
|
||||
}
|
||||
} else {
|
||||
top = 1;
|
||||
}
|
||||
|
||||
if (enabledBorders & Plasma::FrameSvg::RightBorder) {
|
||||
marginHint = q->elementSize("shadow-hint-right-margin");
|
||||
if (marginHint.isValid()) {
|
||||
right = marginHint.width();
|
||||
} else {
|
||||
right = m_shadowPixmaps[2].width(); // right
|
||||
}
|
||||
} else {
|
||||
right = 1;
|
||||
}
|
||||
|
||||
if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
|
||||
marginHint = q->elementSize("shadow-hint-bottom-margin");
|
||||
if (marginHint.isValid()) {
|
||||
bottom = marginHint.height();
|
||||
} else {
|
||||
bottom = m_shadowPixmaps[4].height(); // bottom
|
||||
}
|
||||
} else {
|
||||
bottom = 1;
|
||||
}
|
||||
|
||||
if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
|
||||
marginHint = q->elementSize("shadow-hint-left-margin");
|
||||
if (marginHint.isValid()) {
|
||||
left = marginHint.width();
|
||||
} else {
|
||||
left = m_shadowPixmaps[6].width(); // left
|
||||
}
|
||||
} else {
|
||||
left = 1;
|
||||
}
|
||||
|
||||
data[enabledBorders] << top << right << bottom << left;
|
||||
}
|
||||
|
||||
void DialogShadows::Private::clearPixmaps()
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
if (m_managePixmaps) {
|
||||
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
|
||||
XFreePixmap(QX11Info::display(), pixmap.handle());
|
||||
}
|
||||
|
||||
XFreePixmap(QX11Info::display(), m_emptyCornerPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyCornerBottomPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyCornerLeftPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyCornerRightPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyCornerTopPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyVerticalPix.handle());
|
||||
XFreePixmap(QX11Info::display(), m_emptyHorizontalPix.handle());
|
||||
|
||||
m_managePixmaps = false;
|
||||
}
|
||||
#endif
|
||||
m_shadowPixmaps.clear();
|
||||
data.clear();
|
||||
}
|
||||
|
||||
void DialogShadows::Private::updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
if (m_shadowPixmaps.isEmpty()) {
|
||||
setupPixmaps();
|
||||
}
|
||||
|
||||
if (!data.contains(enabledBorders)) {
|
||||
setupData(enabledBorders);
|
||||
}
|
||||
|
||||
Display *dpy = QX11Info::display();
|
||||
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
|
||||
|
||||
//kDebug() << "going to set the shadow of" << winId() << "to" << data;
|
||||
XChangeProperty(dpy, window->winId(), atom, XA_CARDINAL, 32, PropModeReplace,
|
||||
reinterpret_cast<const unsigned char *>(data[enabledBorders].constData()), data[enabledBorders].size());
|
||||
#endif
|
||||
}
|
||||
|
||||
void DialogShadows::Private::clearShadow(const QWidget *window)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
Display *dpy = QX11Info::display();
|
||||
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
|
||||
XDeleteProperty(dpy, window->winId(), atom);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DialogShadows::enabled() const
|
||||
{
|
||||
return hasElement("shadow-left");
|
||||
}
|
||||
|
||||
#include "dialogshadows_p.moc"
|
||||
|
51
private/dialogshadows_p.h
Normal file
51
private/dialogshadows_p.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_DIALOGSHADOWS_H
|
||||
#define PLASMA_DIALOGSHADOWS_H
|
||||
|
||||
#include <QSet>
|
||||
|
||||
#include "plasma/framesvg.h"
|
||||
#include "plasma/svg.h"
|
||||
|
||||
|
||||
class DialogShadows : public Plasma::Svg
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogShadows(QObject *parent = 0, const QString &prefix = "dialogs/background");
|
||||
|
||||
static DialogShadows *self();
|
||||
|
||||
void addWindow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders = Plasma::FrameSvg::AllBorders);
|
||||
void removeWindow(const QWidget *window);
|
||||
|
||||
bool enabled() const;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void updateShadows())
|
||||
Q_PRIVATE_SLOT(d, void windowDestroyed(QObject *deletedObject))
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,68 +27,23 @@
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
#include <kdesktopfile.h>
|
||||
#include <klocalizedstring.h>
|
||||
#include <klocale.h>
|
||||
#include <kmessagebox.h>
|
||||
|
||||
#ifndef PLASMA_NO_KNEWSTUFF
|
||||
#include <knewstuff3/downloaddialog.h>
|
||||
#endif
|
||||
|
||||
#include "kdeclarative.h"
|
||||
#include "package.h"
|
||||
#include "config-plasma.h"
|
||||
|
||||
#include "private/wallpaper_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
void ChangeableMainScriptPackage::initPackage(Package *package)
|
||||
PlasmoidPackage::PlasmoidPackage(QObject *parent)
|
||||
: Plasma::PackageStructure(parent, QString("Plasmoid"))
|
||||
{
|
||||
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);
|
||||
@ -96,190 +51,384 @@ void PlasmoidPackage::initPackage(Package *package)
|
||||
it.next();
|
||||
it.setValue("platformcontents/" + it.value());
|
||||
}
|
||||
|
||||
platform.append("contents");
|
||||
package->setContentsPrefixPaths(platform);
|
||||
setContentsPrefixPaths(platform);
|
||||
}
|
||||
|
||||
package->setServicePrefix("plasma-applet-");
|
||||
package->setDefaultPackageRoot("plasma/plasmoids");
|
||||
|
||||
package->addDirectoryDefinition("images", "images", i18n("Images"));
|
||||
addDirectoryDefinition("images", "images", i18n("Images"));
|
||||
QStringList mimetypes;
|
||||
mimetypes << "image/svg+xml" << "image/png" << "image/jpeg";
|
||||
package->setMimeTypes("images", mimetypes);
|
||||
setMimetypes("images", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("config", "config", i18n("Configuration Definitions"));
|
||||
addDirectoryDefinition("config", "config", i18n("Configuration Definitions"));
|
||||
mimetypes.clear();
|
||||
mimetypes << "text/xml";
|
||||
package->setMimeTypes("config", mimetypes);
|
||||
setMimetypes("config", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("ui", "ui", i18n("User Interface"));
|
||||
package->setMimeTypes("ui", mimetypes);
|
||||
addDirectoryDefinition("ui", "ui", i18n("User Interface"));
|
||||
setMimetypes("ui", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("data", "data", i18n("Data Files"));
|
||||
addDirectoryDefinition("data", "data", i18n("Data Files"));
|
||||
|
||||
package->addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
|
||||
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
|
||||
mimetypes.clear();
|
||||
mimetypes << "text/plain";
|
||||
package->setMimeTypes("scripts", mimetypes);
|
||||
setMimetypes("scripts", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
|
||||
addDirectoryDefinition("translations", "locale", i18n("Translations"));
|
||||
|
||||
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"));
|
||||
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);
|
||||
}
|
||||
|
||||
QString ContainmentPackage::mainScriptConfigKey() const
|
||||
PlasmoidPackage::~PlasmoidPackage()
|
||||
{
|
||||
return QLatin1String("X-Plasma-Containment-MainScript");
|
||||
#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
|
||||
}
|
||||
|
||||
void DataEnginePackage::initPackage(Package *package)
|
||||
void PlasmoidPackage::pathChanged()
|
||||
{
|
||||
ChangeableMainScriptPackage::initPackage(package);
|
||||
package->setServicePrefix("plasma-dataengine-");
|
||||
package->setDefaultPackageRoot("plasma/dataengines/");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
package->addDirectoryDefinition("data", "data", i18n("Data Files"));
|
||||
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("scripts", "code", i18n("Executable Scripts"));
|
||||
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"));
|
||||
QStringList mimetypes;
|
||||
mimetypes << "text/plain";
|
||||
package->setMimeTypes("scripts", mimetypes);
|
||||
setMimetypes("scripts", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("services", "services/", i18n("Service Descriptions"));
|
||||
package->setMimeTypes("services", mimetypes);
|
||||
addDirectoryDefinition("services", "services/", i18n("Service Descriptions"));
|
||||
setMimetypes("services", mimetypes);
|
||||
|
||||
package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
|
||||
addDirectoryDefinition("translations", "locale", i18n("Translations"));
|
||||
|
||||
addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
|
||||
setRequired("mainscript", true);
|
||||
}
|
||||
|
||||
void RunnerPackage::initPackage(Package *package)
|
||||
DataEnginePackage::~DataEnginePackage()
|
||||
{
|
||||
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 ThemePackage::initPackage(Package *package)
|
||||
void DataEnginePackage::pathChanged()
|
||||
{
|
||||
package->addDirectoryDefinition("dialogs", "dialogs/", i18n("Images for dialogs"));
|
||||
package->addFileDefinition("dialogs/background", "dialogs/background.svg",
|
||||
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",
|
||||
i18n("Generic dialog background"));
|
||||
package->addFileDefinition("dialogs/background", "dialogs/background.svgz",
|
||||
addFileDefinition("dialogs/background", "dialogs/background.svgz",
|
||||
i18n("Generic dialog background"));
|
||||
package->addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
|
||||
|
||||
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
|
||||
i18n("Theme for the logout dialog"));
|
||||
package->addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svgz",
|
||||
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svgz",
|
||||
i18n("Theme for the logout dialog"));
|
||||
|
||||
package->addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages"));
|
||||
package->addDirectoryDefinition("animations", "animations/", i18n("Animation scripts"));
|
||||
addDirectoryDefinition("wallpapers", "wallpapers/", i18n("Wallpaper packages"));
|
||||
addDirectoryDefinition("animations", "animations/", i18n("Animation scripts"));
|
||||
|
||||
package->addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
|
||||
package->addFileDefinition("widgets/background", "widgets/background.svg",
|
||||
addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
|
||||
|
||||
addFileDefinition("widgets/background", "widgets/background.svg",
|
||||
i18n("Background image for widgets"));
|
||||
package->addFileDefinition("widgets/background", "widgets/background.svgz",
|
||||
addFileDefinition("widgets/background", "widgets/background.svgz",
|
||||
i18n("Background image for widgets"));
|
||||
package->addFileDefinition("widgets/clock", "widgets/clock.svg",
|
||||
|
||||
addFileDefinition("widgets/clock", "widgets/clock.svg",
|
||||
i18n("Analog clock face"));
|
||||
package->addFileDefinition("widgets/clock", "widgets/clock.svgz",
|
||||
addFileDefinition("widgets/clock", "widgets/clock.svgz",
|
||||
i18n("Analog clock face"));
|
||||
package->addFileDefinition("widgets/panel-background", "widgets/panel-background.svg",
|
||||
|
||||
addFileDefinition("widgets/panel-background", "widgets/panel-background.svg",
|
||||
i18n("Background image for panels"));
|
||||
package->addFileDefinition("widgets/panel-background", "widgets/panel-background.svgz",
|
||||
addFileDefinition("widgets/panel-background", "widgets/panel-background.svgz",
|
||||
i18n("Background image for panels"));
|
||||
package->addFileDefinition("widgets/plot-background", "widgets/plot-background.svg",
|
||||
|
||||
addFileDefinition("widgets/plot-background", "widgets/plot-background.svg",
|
||||
i18n("Background for graphing widgets"));
|
||||
package->addFileDefinition("widgets/plot-background", "widgets/plot-background.svgz",
|
||||
addFileDefinition("widgets/plot-background", "widgets/plot-background.svg",
|
||||
i18n("Background for graphing widgets"));
|
||||
package->addFileDefinition("widgets/tooltip", "widgets/tooltip.svg",
|
||||
|
||||
addFileDefinition("widgets/tooltip", "widgets/tooltip.svg",
|
||||
i18n("Background image for tooltips"));
|
||||
package->addFileDefinition("widgets/tooltip", "widgets/tooltip.svgz",
|
||||
addFileDefinition("widgets/tooltip", "widgets/tooltip.svgz",
|
||||
i18n("Background image for tooltips"));
|
||||
|
||||
package->addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs"));
|
||||
package->addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg",
|
||||
addDirectoryDefinition("opaque/dialogs", "opaque/dialogs/", i18n("Opaque images for dialogs"));
|
||||
|
||||
addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svg",
|
||||
i18n("Opaque generic dialog background"));
|
||||
package->addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svgz",
|
||||
addFileDefinition("opaque/dialogs/background", "opaque/dialogs/background.svgz",
|
||||
i18n("Opaque generic dialog background"));
|
||||
package->addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svg",
|
||||
|
||||
addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svg",
|
||||
i18n("Opaque theme for the logout dialog"));
|
||||
package->addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svgz",
|
||||
addFileDefinition("opaque/dialogs/shutdowndialog", "opaque/dialogs/shutdowndialog.svgz",
|
||||
i18n("Opaque theme for the logout dialog"));
|
||||
|
||||
package->addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets"));
|
||||
package->addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg",
|
||||
addDirectoryDefinition("opaque/widgets", "opaque/widgets/", i18n("Opaque images for widgets"));
|
||||
|
||||
addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svg",
|
||||
i18n("Opaque background image for panels"));
|
||||
package->addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svgz",
|
||||
addFileDefinition("opaque/widgets/panel-background", "opaque/widgets/panel-background.svgz",
|
||||
i18n("Opaque background image for panels"));
|
||||
package->addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svg",
|
||||
|
||||
addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svg",
|
||||
i18n("Opaque background image for tooltips"));
|
||||
package->addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svgz",
|
||||
addFileDefinition("opaque/widgets/tooltip", "opaque/widgets/tooltip.svgz",
|
||||
i18n("Opaque background image for tooltips"));
|
||||
|
||||
package->addDirectoryDefinition("locolor/dialogs", "locolor/dialogs/",
|
||||
addDirectoryDefinition("locolor/dialogs", "locolor/dialogs/",
|
||||
i18n("Low color images for dialogs"));
|
||||
package->addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svg",
|
||||
|
||||
addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svg",
|
||||
i18n("Low color generic dialog background"));
|
||||
package->addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svgz",
|
||||
addFileDefinition("locolor/dialogs/background", "locolor/dialogs/background.svgz",
|
||||
i18n("Low color generic dialog background"));
|
||||
package->addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svg",
|
||||
|
||||
addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svg",
|
||||
i18n("Low color theme for the logout dialog"));
|
||||
package->addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svgz",
|
||||
addFileDefinition("locolor/dialogs/shutdowndialog", "locolor/dialogs/shutdowndialog.svgz",
|
||||
i18n("Low color theme for the logout dialog"));
|
||||
|
||||
package->addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets"));
|
||||
package->addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg",
|
||||
addDirectoryDefinition("locolor/widgets", "locolor/widgets/", i18n("Images for widgets"));
|
||||
|
||||
addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svg",
|
||||
i18n("Low color background image for widgets"));
|
||||
package->addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svgz",
|
||||
addFileDefinition("locolor/widgets/background", "locolor/widgets/background.svgz",
|
||||
i18n("Low color background image for widgets"));
|
||||
package->addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svg",
|
||||
|
||||
addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svg",
|
||||
i18n("Low color analog clock face"));
|
||||
package->addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svgz",
|
||||
addFileDefinition("locolor/widgets/clock", "locolor/widgets/clock.svgz",
|
||||
i18n("Low color analog clock face"));
|
||||
package->addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svg",
|
||||
|
||||
addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svg",
|
||||
i18n("Low color background image for panels"));
|
||||
package->addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svgz",
|
||||
addFileDefinition("locolor/widgets/panel-background", "locolor/widgets/panel-background.svgz",
|
||||
i18n("Low color background image for panels"));
|
||||
package->addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svg",
|
||||
|
||||
addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svg",
|
||||
i18n("Low color background for graphing widgets"));
|
||||
package->addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svgz",
|
||||
addFileDefinition("locolor/widgets/plot-background", "locolor/widgets/plot-background.svgz",
|
||||
i18n("Low color background for graphing widgets"));
|
||||
package->addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svg",
|
||||
|
||||
addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svg",
|
||||
i18n("Low color background image for tooltips"));
|
||||
package->addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svgz",
|
||||
addFileDefinition("locolor/widgets/tooltip", "locolor/widgets/tooltip.svgz",
|
||||
i18n("Low color background image for tooltips"));
|
||||
|
||||
package->addFileDefinition("colors", "colors", i18n("KColorScheme configuration file"));
|
||||
addFileDefinition("colors", "colors", i18n("KColorScheme configuration file"));
|
||||
|
||||
QStringList mimetypes;
|
||||
mimetypes << "image/svg+xml";
|
||||
package->setDefaultMimeTypes(mimetypes);
|
||||
setDefaultMimetypes(mimetypes);
|
||||
}
|
||||
|
||||
void ContainmentActionsPackage::initPackage(Package *package)
|
||||
WallpaperPackage::WallpaperPackage(Wallpaper *paper, QObject *parent)
|
||||
: PackageStructure(parent, "Background"),
|
||||
m_paper(paper),
|
||||
m_fullPackage(true),
|
||||
m_targetSize(100000, 100000),
|
||||
m_resizeMethod(Wallpaper::ScaledResize)
|
||||
{
|
||||
ChangeableMainScriptPackage::initPackage(package);
|
||||
package->setDefaultPackageRoot("plasma/containmentactions/");
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
void GenericPackage::initPackage(Package *package)
|
||||
void WallpaperPackage::renderHintsChanged()
|
||||
{
|
||||
package->setDefaultPackageRoot("plasma/packages/");
|
||||
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?
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_packages_p.cpp"
|
||||
#include "packages_p.moc"
|
||||
|
||||
|
@ -482,6 +482,37 @@ bool RunnerContext::removeMatch(const QString matchId)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RunnerContext::removeMatches(Plasma::AbstractRunner *runner)
|
||||
{
|
||||
if (!isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<QueryMatch> presentMatchList;
|
||||
|
||||
LOCK_FOR_READ(d)
|
||||
foreach(const QueryMatch &match, d->matches) {
|
||||
if (match.runner() == runner) {
|
||||
presentMatchList << match;
|
||||
}
|
||||
}
|
||||
UNLOCK(d)
|
||||
|
||||
if (presentMatchList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LOCK_FOR_WRITE(d)
|
||||
foreach (const QueryMatch &match, presentMatchList) {
|
||||
d->matchesById.remove(match.id());
|
||||
d->matches.removeAll(match);
|
||||
}
|
||||
UNLOCK(d)
|
||||
|
||||
emit d->q->matchesChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<QueryMatch> RunnerContext::matches() const
|
||||
{
|
||||
LOCK_FOR_READ(d)
|
||||
|
@ -156,9 +156,9 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
||||
* @param matchId the id of match to remove
|
||||
*
|
||||
* @return true if the match was removed, false otherwise.
|
||||
* @since 4.4
|
||||
* @since 4.4
|
||||
*/
|
||||
bool removeMatch(const QString matchId);
|
||||
bool removeMatch(const QString matchId);
|
||||
|
||||
/**
|
||||
* Removes lists of matches from the existing list of matches.
|
||||
@ -172,6 +172,18 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
||||
*/
|
||||
bool removeMatches(const QStringList matchIdList);
|
||||
|
||||
/**
|
||||
* Removes lists of matches from a given AbstractRunner
|
||||
*
|
||||
* This method is thread safe and causes the matchesChanged() signal to be emitted.
|
||||
*
|
||||
* @param runner the AbstractRunner from which to remove matches
|
||||
*
|
||||
* @return true if at least one match was removed, false otherwise.
|
||||
* @since 4.10
|
||||
*/
|
||||
bool removeMatches(AbstractRunner *runner);
|
||||
|
||||
/**
|
||||
* Retrieves all available matches for the current search term.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user