implement downloadPath, port to QStandardPaths
This commit is contained in:
parent
55d23cddb6
commit
3b6f014824
@ -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<Plasma::Package>().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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
154
scriptengines/qml/plasmoid/containmentinterface.cpp
Normal file
154
scriptengines/qml/plasmoid/containmentinterface.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2008 Chani Armitage <chani@kde.org>
|
||||
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Marco Martin <mart@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 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 <QQmlComponent>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <Plasma/Plasma>
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Package>
|
||||
|
||||
ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
|
||||
: AppletInterface(parent)
|
||||
{
|
||||
qmlRegisterType<ContainmentInterface>();
|
||||
|
||||
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 *>();
|
||||
QObject *contGraphicObject = containment()->property("graphicObject").value<QObject *>();
|
||||
|
||||
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<QObject *>();
|
||||
emit appletRemoved(appletGraphicObject);
|
||||
}
|
||||
|
||||
void ContainmentInterface::loadWallpaper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString ContainmentInterface::activityId() const
|
||||
{
|
||||
return containment()->activity();
|
||||
}
|
||||
|
||||
#include "moc_containmentinterface.cpp"
|
93
scriptengines/qml/plasmoid/containmentinterface.h
Normal file
93
scriptengines/qml/plasmoid/containmentinterface.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2008-2013 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010-2013 Marco Martin <mart@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 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 <QQuickItem>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Theme>
|
||||
|
||||
#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<Plasma::Containment *>(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
|
Loading…
Reference in New Issue
Block a user