diff --git a/scriptengines/qml/plasmoid/appletinterface.cpp b/scriptengines/qml/plasmoid/appletinterface.cpp index 237f70e55..f5974afb5 100644 --- a/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/scriptengines/qml/plasmoid/appletinterface.cpp @@ -373,19 +373,21 @@ AppletInterface::ItemStatus AppletInterface::status() const return (AppletInterface::ItemStatus)((int)(applet()->status())); } -/* QString AppletInterface::downloadPath(const QString &file) { - KDesktopFile config(v.toVariant().value().path() + "/metadata.desktop"); - KConfigGroup cg = config.desktopGroup(); - const QString pluginName = cg.readEntry("X-KDE-PluginInfo-Name", QString()); - destination = KGlobalSettings::downloadPath() + "/Plasma/" + pluginName + '/'; + const QString downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/Plasma/" + applet()->pluginInfo().pluginName() + '/'; + + if (!QFile::exists(downloadDir)) { + QDir dir(QChar('/')); + dir.mkpath(downloadDir); + } + + return downloadDir; } -*/ QStringList AppletInterface::downloadedFiles() const { - const QString downloadDir = KGlobalSettings::downloadPath() + "/Plasma/" + applet()->pluginInfo().pluginName(); + const QString downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/Plasma/" + applet()->pluginInfo().pluginName() + '/'; QDir dir(downloadDir); return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable); } diff --git a/scriptengines/qml/plasmoid/appletinterface.h b/scriptengines/qml/plasmoid/appletinterface.h index 59e7620e4..a017d65cd 100644 --- a/scriptengines/qml/plasmoid/appletinterface.h +++ b/scriptengines/qml/plasmoid/appletinterface.h @@ -172,7 +172,7 @@ enum IntervalAlignment { inline Plasma::Applet *applet() const { return m_appletScriptEngine->applet(); } -// Q_INVOKABLE QString downloadPath(const QString &file); + Q_INVOKABLE QString downloadPath(const QString &file); Q_INVOKABLE QStringList downloadedFiles() const; diff --git a/scriptengines/qml/plasmoid/containmentinterface.cpp b/scriptengines/qml/plasmoid/containmentinterface.cpp new file mode 100644 index 000000000..50ec3df56 --- /dev/null +++ b/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -0,0 +1,154 @@ +/* + * Copyright 2008 Chani Armitage + * Copyright 2008, 2009 Aaron Seigo + * Copyright 2010 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either 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 "containmentinterface.h" + +#include + +#include + +#include +#include +#include +#include + +ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) + : AppletInterface(parent) +{ + qmlRegisterType(); + + connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *))); + connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &))); + connect(containment(), SIGNAL(screenChanged(int, int, Plasma::Containment*)), this, SIGNAL(screenChanged())); + connect(containment(), SIGNAL(activityChanged()), this, SIGNAL(activityChanged())); + connect(containment(), SIGNAL(wallpaperChanged()), this, SLOT(loadWallpaper())); + + if (containment()->corona()) { + connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()), + this, SIGNAL(availableScreenRegionChanged())); + } +} + +QVariantList ContainmentInterface::applets() +{ + QVariantList list; + int i = 0; + foreach (Plasma::Applet *applet, containment()->applets()) { + list << QVariant::fromValue(applet); + ++i; + } + return list; +} + +void ContainmentInterface::setDrawWallpaper(bool drawWallpaper) +{ + m_appletScriptEngine->setDrawWallpaper(drawWallpaper); +} + +bool ContainmentInterface::drawWallpaper() +{ + return m_appletScriptEngine->drawWallpaper(); +} + +ContainmentInterface::Type ContainmentInterface::containmentType() const +{ + return (ContainmentInterface::Type)m_appletScriptEngine->containmentType(); +} + +void ContainmentInterface::setContainmentType(ContainmentInterface::Type type) +{ + m_appletScriptEngine->setContainmentType((Plasma::Containment::Type)type); +} + +int ContainmentInterface::screen() const +{ + return containment()->screen(); +} + +QRectF ContainmentInterface::screenGeometry(int id) const +{ + QRectF rect; + if (containment()->corona()) { + rect = QRectF(containment()->corona()->screenGeometry(id)); + } + + return rect; +} + +QVariantList ContainmentInterface::availableScreenRegion(int id) const +{ + QRegion reg; + if (containment()->corona()) { + reg = containment()->corona()->availableScreenRegion(id); + } + + QVariantList regVal; + foreach (QRect rect, reg.rects()) { + regVal << QVariant::fromValue(QRectF(rect)); + } + return regVal; +} + +void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos) +{ + QObject *appletGraphicObject = applet->property("graphicObject").value(); + QObject *contGraphicObject = containment()->property("graphicObject").value(); + + qDebug() << "Applet added:" << applet << applet->title() << appletGraphicObject; + + if (applet && contGraphicObject && appletGraphicObject) { + appletGraphicObject->setProperty("visible", false); + appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject)); + + //if an appletGraphicObject is not set, we have to display some error message + } else if (applet && contGraphicObject) { + QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), applet); + component->loadUrl(QUrl::fromLocalFile(containment()->corona()->package().filePath("ui", "AppletError.qml"))); + QObject *errorUi = component->create(); + + if (errorUi) { + errorUi->setProperty("visible", false); + errorUi->setProperty("parent", QVariant::fromValue(contGraphicObject)); + errorUi->setProperty("reason", applet->launchErrorMessage()); + appletGraphicObject = errorUi; + } + } + + emit appletAdded(appletGraphicObject, pos); +} + +void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) +{ + QObject *appletGraphicObject = applet->property("graphicObject").value(); + emit appletRemoved(appletGraphicObject); +} + +void ContainmentInterface::loadWallpaper() +{ + +} + +QString ContainmentInterface::activityId() const +{ + return containment()->activity(); +} + +#include "moc_containmentinterface.cpp" diff --git a/scriptengines/qml/plasmoid/containmentinterface.h b/scriptengines/qml/plasmoid/containmentinterface.h new file mode 100644 index 000000000..580095484 --- /dev/null +++ b/scriptengines/qml/plasmoid/containmentinterface.h @@ -0,0 +1,93 @@ +/* + * Copyright 2008-2013 Aaron Seigo + * Copyright 2010-2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either 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 CONTAINMENTINTERFACE_H +#define CONTAINMENTINTERFACE_H + +#include +#include + +#include +#include +#include + +#include "appletinterface.h" + +class QAction; +class QmlAppletScript; +class QSignalMapper; +class QSizeF; + + +namespace Plasma +{ + class ConfigLoader; +} // namespace Plasma + +class ContainmentInterface : public AppletInterface +{ + Q_OBJECT + Q_PROPERTY(QVariantList applets READ applets) + Q_PROPERTY(bool drawWallpaper READ drawWallpaper WRITE setDrawWallpaper) + Q_PROPERTY(Type containmentType READ containmentType WRITE setContainmentType) + Q_PROPERTY(int screen READ screen NOTIFY screenChanged) + Q_PROPERTY(QString activityId READ activityId NOTIFY activityIdChanged) + Q_ENUMS(Type) + +public: + enum Type { + NoContainmentType = -1, /**< @internal */ + DesktopContainment = 0, /**< A desktop containment */ + PanelContainment, /**< A desktop panel */ + CustomContainment = 127, /**< A containment that is neither a desktop nor a panel + but something application specific */ + CustomPanelContainment = 128 /**< A customized desktop panel */ + }; + ContainmentInterface(DeclarativeAppletScript *parent); + + inline Plasma::Containment *containment() const { return static_cast(m_appletScriptEngine->applet()); } + + QVariantList applets(); + + void setDrawWallpaper(bool drawWallpaper); + bool drawWallpaper(); + Type containmentType() const; + void setContainmentType(Type type); + int screen() const; + + QString activityId() const; + + Q_INVOKABLE QRectF screenGeometry(int id) const; + Q_INVOKABLE QVariantList availableScreenRegion(int id) const; + +Q_SIGNALS: + void appletAdded(QObject *applet, const QPointF &pos); + void appletRemoved(QObject *applet); + void screenChanged(); + void activityIdChanged(); + void availableScreenRegionChanged(); + +protected Q_SLOTS: + void appletAddedForward(Plasma::Applet *applet, const QPointF &pos); + void appletRemovedForward(Plasma::Applet *applet); + void loadWallpaper(); +}; + +#endif