remove intoDeclarativeEngine folder
functionality of usefu; files in is already migrated
This commit is contained in:
parent
b37ec71e9f
commit
bfe5c1e942
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
||||
* Copyright 2009 Chani Armitage <chani@kde.org>
|
||||
* Copyright 2012 Marco Martin <notmart@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.
|
||||
*/
|
||||
|
||||
|
||||
void Containment::focusNextApplet()
|
||||
{
|
||||
if (d->applets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int index = d->focusedApplet ? d->applets.indexOf(d->focusedApplet) + 1 : 0;
|
||||
if (index >= d->applets.size()) {
|
||||
index = 0;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "index" << index;
|
||||
#endif
|
||||
d->focusApplet(d->applets.at(index));
|
||||
}
|
||||
|
||||
void Containment::focusPreviousApplet()
|
||||
{
|
||||
if (d->applets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int index = d->focusedApplet ? d->applets.indexOf(d->focusedApplet) - 1 : -1;
|
||||
if (index < 0) {
|
||||
index = d->applets.size() - 1;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "index" << index;
|
||||
#endif
|
||||
d->focusApplet(d->applets.at(index));
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
||||
* Copyright (c) 2009 Chani Armitage <chani@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 PLASMA_CONTAINMENT_H
|
||||
#define PLASMA_CONTAINMENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
#include <kplugininfo.h>
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
#include <plasma/applet.h>
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AccessAppletJob;
|
||||
class AppletHandle;
|
||||
class DataEngine;
|
||||
class Package;
|
||||
class Corona;
|
||||
class View;
|
||||
class Wallpaper;
|
||||
class DeclarativeContainmentActions;
|
||||
class DeclarativeContainmentPrivate;
|
||||
class AbstractToolBox;
|
||||
|
||||
|
||||
class PLASMA_EXPORT DeclarativeContainment : public Applet
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
void focusNextApplet();
|
||||
void focusPreviousApplet();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Q_PRIVATE_SLOT(d, void showDropZoneDelayed())
|
||||
Q_PRIVATE_SLOT(d, void remoteAppletReady(Plasma::AccessAppletJob *))
|
||||
/**
|
||||
* This slot is called when the 'stat' after a job event has finished.
|
||||
*/
|
||||
Q_PRIVATE_SLOT(d, void mimeTypeRetrieved(KIO::Job *, const QString &))
|
||||
Q_PRIVATE_SLOT(d, void dropJobResult(KJob *))
|
||||
|
||||
DeclarativeContainmentPrivate *const d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif // multiple inclusion guard
|
@ -1,476 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
||||
* Copyright 2009 Chani Armitage <chani@kde.org>
|
||||
* Copyright 2012 Marco Martin <notmart@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 "private/containment_p.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QMimeDatabase>
|
||||
#include <QDropEvent>
|
||||
#include <qtemporaryfile.h>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kactioncollection.h>
|
||||
#include <kcoreauthorized.h>
|
||||
#include <kurlmimedata.h>
|
||||
#include <kwindowsystem.h>
|
||||
|
||||
#include "config-plasma.h"
|
||||
|
||||
#if !PLASMA_NO_KIO
|
||||
#include "kio/jobclasses.h" // for KIO::JobFlags
|
||||
#include "kio/job.h"
|
||||
#include "kio/scheduler.h"
|
||||
#endif
|
||||
|
||||
#include "containmentactions.h"
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "corona.h"
|
||||
#include "pluginloader.h"
|
||||
#include "svg.h"
|
||||
|
||||
#include "remote/accessappletjob.h"
|
||||
#include "remote/accessmanager.h"
|
||||
|
||||
#include "private/applet_p.h"
|
||||
#include "private/containmentactionspluginsconfig_p.h"
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
|
||||
const char DeclarativeContainmentPrivate::defaultWallpaperMode[] = "SingleImage";
|
||||
|
||||
|
||||
void DeclarativeContainmentPrivate::showDropZoneDelayed()
|
||||
{
|
||||
dropZoneStarted = true;
|
||||
q->showDropZone(dropPoints.value(0).toPoint());
|
||||
dropPoints.remove(0);
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::dropData(QPoint screenPos, QDropEvent *dropEvent)
|
||||
{
|
||||
if (q->immutability() != Mutable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QMimeData *mimeData = 0;
|
||||
|
||||
if (dropEvent) {
|
||||
mimeData = dropEvent->mimeData();
|
||||
} else {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
mimeData = clipboard->mimeData(QClipboard::Selection);
|
||||
//TODO if that's not supported (ie non-linux) should we try clipboard instead of selection?
|
||||
}
|
||||
|
||||
if (!mimeData) {
|
||||
//Selection is either empty or not supported on this OS
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "no mime data";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
//kDebug() << event->mimeData()->text();
|
||||
|
||||
QString appletMimetype(q->corona() ? q->corona()->appletMimeType() : QString());
|
||||
|
||||
if (!appletMimetype.isEmpty() && mimeData->hasFormat(appletMimetype)) {
|
||||
QString data = mimeData->data(appletMimetype);
|
||||
const QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
||||
foreach (const QString &appletName, appletNames) {
|
||||
//kDebug() << "doing" << appletName;
|
||||
QRectF geom(screenPos, QSize(0, 0));
|
||||
q->addApplet(appletName, QVariantList(), geom);
|
||||
}
|
||||
if (dropEvent) {
|
||||
dropEvent->acceptProposedAction();
|
||||
}
|
||||
} else if (mimeData->hasUrls()) {
|
||||
//TODO: collect the mimeTypes of available script engines and offer
|
||||
// to create widgets out of the matching URLs, if any
|
||||
const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
|
||||
foreach (const QUrl &url, urls) {
|
||||
if (AccessManager::supportedProtocols().contains(url.scheme())) {
|
||||
AccessAppletJob *job = AccessManager::self()->accessRemoteApplet(url);
|
||||
if (dropEvent) {
|
||||
dropPoints[job] = dropEvent->pos();
|
||||
} else {
|
||||
dropPoints[job] = screenPos;
|
||||
}
|
||||
QObject::connect(AccessManager::self(), SIGNAL(finished(Plasma::AccessAppletJob*)),
|
||||
q, SLOT(remoteAppletReady(Plasma::AccessAppletJob*)));
|
||||
}
|
||||
#if !PLASMA_NO_KIO
|
||||
else {
|
||||
QMimeDatabase db;
|
||||
QMimeType mime = db.mimeTypeForUrl(url);
|
||||
QString mimeName = mime.name();
|
||||
QRectF geom(screenPos, QSize());
|
||||
QVariantList args;
|
||||
args << url.toString();
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "can decode" << mimeName << args;
|
||||
#endif
|
||||
|
||||
// It may be a directory or a file, let's stat
|
||||
KIO::JobFlags flags = KIO::HideProgressInfo;
|
||||
KIO::MimetypeJob *job = KIO::mimetype(url, flags);
|
||||
if (dropEvent) {
|
||||
dropPoints[job] = dropEvent->pos();
|
||||
} else {
|
||||
dropPoints[job] = screenPos;
|
||||
}
|
||||
|
||||
QObject::connect(job, SIGNAL(result(KJob*)), q, SLOT(dropJobResult(KJob*)));
|
||||
QObject::connect(job, SIGNAL(mimetype(KIO::Job*,QString)),
|
||||
q, SLOT(mimeTypeRetrieved(KIO::Job*,QString)));
|
||||
|
||||
KMenu *choices = new KMenu("Content dropped");
|
||||
choices->addAction(KDE::icon("process-working"), i18n("Fetching file type..."));
|
||||
if (dropEvent) {
|
||||
choices->popup(dropEvent->pos());
|
||||
} else {
|
||||
choices->popup(screenPos);
|
||||
}
|
||||
|
||||
dropMenus[job] = choices;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (dropEvent) {
|
||||
dropEvent->acceptProposedAction();
|
||||
}
|
||||
} else {
|
||||
QStringList formats = mimeData->formats();
|
||||
QHash<QString, KPluginInfo> seenPlugins;
|
||||
QHash<QString, QString> pluginFormats;
|
||||
|
||||
foreach (const QString &format, formats) {
|
||||
KPluginInfo::List plugins = Applet::listAppletInfoForMimeType(format);
|
||||
|
||||
foreach (const KPluginInfo &plugin, plugins) {
|
||||
if (seenPlugins.contains(plugin.pluginName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
seenPlugins.insert(plugin.pluginName(), plugin);
|
||||
pluginFormats.insert(plugin.pluginName(), format);
|
||||
}
|
||||
}
|
||||
//kDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values();
|
||||
|
||||
QString selectedPlugin;
|
||||
|
||||
if (seenPlugins.isEmpty()) {
|
||||
// do nothing
|
||||
} else if (seenPlugins.count() == 1) {
|
||||
selectedPlugin = seenPlugins.constBegin().key();
|
||||
} else {
|
||||
KMenu choices;
|
||||
QHash<QAction *, QString> actionsToPlugins;
|
||||
foreach (const KPluginInfo &info, seenPlugins) {
|
||||
QAction *action;
|
||||
if (!info.icon().isEmpty()) {
|
||||
action = choices.addAction(KDE::icon(info.icon()), info.name());
|
||||
} else {
|
||||
action = choices.addAction(info.name());
|
||||
}
|
||||
|
||||
actionsToPlugins.insert(action, info.pluginName());
|
||||
}
|
||||
|
||||
QAction *choice = choices.exec(screenPos);
|
||||
if (choice) {
|
||||
selectedPlugin = actionsToPlugins[choice];
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedPlugin.isEmpty()) {
|
||||
if (!dropEvent) {
|
||||
// since we may have entered an event loop up above with the menu,
|
||||
// the clipboard item may no longer be valid, as QClipboard resets
|
||||
// the object behind the back of the application with a zero timer
|
||||
// so we fetch it again here
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
mimeData = clipboard->mimeData(QClipboard::Selection);
|
||||
}
|
||||
|
||||
QTemporaryFile tempFile;
|
||||
if (mimeData && tempFile.open()) {
|
||||
//TODO: what should we do with files after the applet is done with them??
|
||||
tempFile.setAutoRemove(false);
|
||||
|
||||
{
|
||||
QDataStream stream(&tempFile);
|
||||
QByteArray data = mimeData->data(pluginFormats[selectedPlugin]);
|
||||
stream.writeRawData(data, data.size());
|
||||
}
|
||||
|
||||
QRectF geom(screenPos, QSize());
|
||||
QVariantList args;
|
||||
args << tempFile.fileName();
|
||||
#ifndef NDEBUG
|
||||
kDebug() << args;
|
||||
#endif
|
||||
tempFile.close();
|
||||
|
||||
q->addApplet(selectedPlugin, args, geom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::clearDataForMimeJob(KIO::Job *job)
|
||||
{
|
||||
#if !PLASMA_NO_KIO
|
||||
QObject::disconnect(job, 0, q, 0);
|
||||
dropPoints.remove(job);
|
||||
KMenu *choices = dropMenus.take(job);
|
||||
delete choices;
|
||||
job->kill();
|
||||
#endif // PLASMA_NO_KIO
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::dropJobResult(KJob *job)
|
||||
{
|
||||
#if !PLASMA_NO_KIO
|
||||
KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
|
||||
if (!tjob) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "job is not a KIO::TransferJob, won't handle the drop...";
|
||||
#endif
|
||||
clearDataForMimeJob(tjob);
|
||||
return;
|
||||
}
|
||||
if (job->error()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "ERROR" << tjob->error() << ' ' << tjob->errorString();
|
||||
#endif
|
||||
}
|
||||
// We call mimeTypeRetrieved since there might be other mechanisms
|
||||
// for finding suitable applets. Cleanup happens there as well.
|
||||
mimeTypeRetrieved(qobject_cast<KIO::Job *>(job), QString());
|
||||
#endif // PLASMA_NO_KIO
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::mimeTypeRetrieved(KIO::Job *job, const QString &mimeType)
|
||||
{
|
||||
#if !PLASMA_NO_KIO
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Mimetype Job returns." << mimeType;
|
||||
#endif
|
||||
KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
|
||||
if (!tjob) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "job should be a TransferJob, but isn't";
|
||||
#endif
|
||||
clearDataForMimeJob(job);
|
||||
return;
|
||||
}
|
||||
KPluginInfo::List appletList = Applet::listAppletInfoForUrl(tjob->url());
|
||||
if (mimeType.isEmpty() && !appletList.count()) {
|
||||
clearDataForMimeJob(job);
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "No applets found matching the url (" << tjob->url() << ") or the mimeType (" << mimeType << ")";
|
||||
#endif
|
||||
return;
|
||||
} else {
|
||||
|
||||
QPointF posi; // will be overwritten with the event's position
|
||||
if (dropPoints.keys().contains(tjob)) {
|
||||
posi = dropPoints[tjob];
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Received a suitable dropEvent at" << posi;
|
||||
#endif
|
||||
} else {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob";
|
||||
#endif
|
||||
clearDataForMimeJob(job);
|
||||
return;
|
||||
}
|
||||
|
||||
KMenu *choices = dropMenus.value(tjob);
|
||||
if (!choices) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Bailing out. No QMenu found for this job.";
|
||||
#endif
|
||||
clearDataForMimeJob(job);
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantList args;
|
||||
args << tjob->url().toString() << mimeType;
|
||||
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Creating menu for:" << mimeType << posi << args;
|
||||
#endif
|
||||
|
||||
appletList << Applet::listAppletInfoForMimeType(mimeType);
|
||||
KPluginInfo::List wallpaperList;
|
||||
if (drawWallpaper) {
|
||||
if (wallpaper && wallpaper->supportsMimetype(mimeType)) {
|
||||
wallpaperList << wallpaper->d->wallpaperDescription;
|
||||
} else {
|
||||
wallpaperList = Wallpaper::listWallpaperInfoForMimeType(mimeType);
|
||||
}
|
||||
}
|
||||
|
||||
if (!appletList.isEmpty() || !wallpaperList.isEmpty()) {
|
||||
choices->clear();
|
||||
QHash<QAction *, QString> actionsToApplets;
|
||||
choices->addTitle(i18n("Widgets"));
|
||||
foreach (const KPluginInfo &info, appletList) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << info.name();
|
||||
#endif
|
||||
QAction *action;
|
||||
if (!info.icon().isEmpty()) {
|
||||
action = choices->addAction(KDE::icon(info.icon()), info.name());
|
||||
} else {
|
||||
action = choices->addAction(info.name());
|
||||
}
|
||||
|
||||
actionsToApplets.insert(action, info.pluginName());
|
||||
#ifndef NDEBUG
|
||||
kDebug() << info.pluginName();
|
||||
#endif
|
||||
}
|
||||
actionsToApplets.insert(choices->addAction(i18n("Icon")), "icon");
|
||||
|
||||
QHash<QAction *, QString> actionsToWallpapers;
|
||||
if (!wallpaperList.isEmpty()) {
|
||||
choices->addTitle(i18n("Wallpaper"));
|
||||
|
||||
QMap<QString, KPluginInfo> sorted;
|
||||
foreach (const KPluginInfo &info, appletList) {
|
||||
sorted.insert(info.name(), info);
|
||||
}
|
||||
|
||||
foreach (const KPluginInfo &info, wallpaperList) {
|
||||
QAction *action;
|
||||
if (!info.icon().isEmpty()) {
|
||||
action = choices->addAction(KDE::icon(info.icon()), info.name());
|
||||
} else {
|
||||
action = choices->addAction(info.name());
|
||||
}
|
||||
|
||||
actionsToWallpapers.insert(action, info.pluginName());
|
||||
}
|
||||
}
|
||||
|
||||
QAction *choice = choices->exec();
|
||||
if (choice) {
|
||||
// Put the job on hold so it can be recycled to fetch the actual content,
|
||||
// which is to be expected when something's dropped onto the desktop and
|
||||
// an applet is to be created with this URL
|
||||
if (!mimeType.isEmpty() && !tjob->error()) {
|
||||
tjob->putOnHold();
|
||||
KIO::Scheduler::publishSlaveOnHold();
|
||||
}
|
||||
QString plugin = actionsToApplets.value(choice);
|
||||
if (plugin.isEmpty()) {
|
||||
//set wallpapery stuff
|
||||
plugin = actionsToWallpapers.value(choice);
|
||||
if (!wallpaper || plugin != wallpaper->pluginName()) {
|
||||
//kDebug() << "Wallpaper dropped:" << tjob->url();
|
||||
q->setWallpaper(plugin);
|
||||
}
|
||||
|
||||
if (wallpaper) {
|
||||
//kDebug() << "Wallpaper dropped:" << tjob->url();
|
||||
wallpaper->addUrls(QList<QUrl>() << tjob->url());
|
||||
}
|
||||
} else {
|
||||
addApplet(actionsToApplets[choice], args, QRectF(posi, QSize()));
|
||||
}
|
||||
|
||||
clearDataForMimeJob(job);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// we can at least create an icon as a link to the URL
|
||||
addApplet("icon", args, QRectF(posi, QSize()));
|
||||
}
|
||||
}
|
||||
|
||||
clearDataForMimeJob(job);
|
||||
#endif // PLASMA_NO_KIO
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::focusApplet(Plasma::Applet *applet)
|
||||
{
|
||||
if (focusedApplet == applet) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QWidget *> widgets = actions()->associatedWidgets();
|
||||
if (focusedApplet) {
|
||||
foreach (QWidget *w, widgets) {
|
||||
focusedApplet->removeAssociatedWidget(w);
|
||||
}
|
||||
}
|
||||
|
||||
if (applet && applets.contains(applet)) {
|
||||
//kDebug() << "switching to" << applet->name();
|
||||
focusedApplet = applet;
|
||||
foreach (QWidget *w, widgets) {
|
||||
focusedApplet->addAssociatedWidget(w);
|
||||
}
|
||||
|
||||
if (!focusedApplet->hasFocus()) {
|
||||
focusedApplet->setFocus(Qt::ShortcutFocusReason);
|
||||
}
|
||||
} else {
|
||||
focusedApplet = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeContainmentPrivate::remoteAppletReady(Plasma::AccessAppletJob *job)
|
||||
{
|
||||
QPointF pos = dropPoints.take(job);
|
||||
if (job->error()) {
|
||||
//TODO: nice user visible error handling (knotification probably?)
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "remote applet access failed: " << job->errorText();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if (!job->applet()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "how did we end up here? if applet is null, the job->error should be nonzero";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
q->addApplet(job->applet(), pos);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
||||
* Copyright 2012 by 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 DECLARATIVECONTAINMENT_P_H
|
||||
#define DECLARATIVECONTAINMENT_P_H
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <kmenu.h>
|
||||
|
||||
#include "plasma.h"
|
||||
#include "applet.h"
|
||||
#include "corona.h"
|
||||
|
||||
|
||||
class KJob;
|
||||
|
||||
namespace KIO
|
||||
{
|
||||
class Job;
|
||||
}
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AccessAppletJob;
|
||||
class Containment;
|
||||
|
||||
class DeclarativeContainmentPrivate
|
||||
{
|
||||
public:
|
||||
DeclarativeContainmentPrivate(Containment *c)
|
||||
: q(c),
|
||||
focusedApplet(0),
|
||||
wallpaper(0),
|
||||
showDropZoneDelayTimer(0),
|
||||
dropZoneStarted(false),
|
||||
{
|
||||
}
|
||||
|
||||
~DeclarativeContainmentPrivate()
|
||||
{
|
||||
qDeleteAll(dropMenus);
|
||||
dropMenus.clear();
|
||||
}
|
||||
|
||||
|
||||
void clearDataForMimeJob(KIO::Job *job);
|
||||
void mimeTypeRetrieved(KIO::Job *job, const QString &mimetype);
|
||||
void dropJobResult(KJob *);
|
||||
void remoteAppletReady(Plasma::AccessAppletJob *job);
|
||||
|
||||
|
||||
/**
|
||||
* give keyboard focus to applet within this containment
|
||||
*/
|
||||
void focusApplet(Plasma::Applet *applet);
|
||||
|
||||
/**
|
||||
* Handles dropped/pasted mimetype data
|
||||
* @param screenPos screen-relative position
|
||||
* @param dropEvent the drop event (if null, the clipboard is used instead)
|
||||
*/
|
||||
void dropData(QPoint screenPos, QDropEvent *dropEvent = 0);
|
||||
|
||||
/**
|
||||
* Delayed drop zone display
|
||||
*/
|
||||
void showDropZoneDelayed();
|
||||
|
||||
DeclarativeContainment *q;
|
||||
Applet *focusedApplet;
|
||||
Plasma::Wallpaper *wallpaper;
|
||||
QHash<KJob*, QPointF> dropPoints;
|
||||
QHash<KJob*, KMenu*> dropMenus;
|
||||
QTimer *showDropZoneDelayTimer;
|
||||
bool dropZoneStarted : 1;
|
||||
|
||||
static const char defaultWallpaper[];
|
||||
static const char defaultWallpaperMode[];
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif
|
@ -1,335 +0,0 @@
|
||||
/*
|
||||
* 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 "declarativewidget.h"
|
||||
|
||||
|
||||
#include <QDeclarativeComponent>
|
||||
#include <QDeclarativeItem>
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeContext>
|
||||
#include <QScriptEngine>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsScene>
|
||||
#include <QTimer>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kdeclarative.h>
|
||||
|
||||
|
||||
#include "private/declarative/declarativenetworkaccessmanagerfactory_p.h"
|
||||
#include "private/declarative/dataenginebindings_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class DeclarativeWidgetPrivate
|
||||
{
|
||||
public:
|
||||
DeclarativeWidgetPrivate(DeclarativeWidget *parent)
|
||||
: q(parent),
|
||||
engine(0),
|
||||
scriptEngine(0),
|
||||
component(0),
|
||||
root(0),
|
||||
delay(false)
|
||||
{
|
||||
}
|
||||
|
||||
~DeclarativeWidgetPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void errorPrint();
|
||||
void execute(const QString &fileName);
|
||||
void finishExecute();
|
||||
void scheduleExecutionEnd();
|
||||
void minimumWidthChanged();
|
||||
void minimumHeightChanged();
|
||||
void maximumWidthChanged();
|
||||
void maximumHeightChanged();
|
||||
void preferredWidthChanged();
|
||||
void preferredHeightChanged();
|
||||
|
||||
|
||||
DeclarativeWidget *q;
|
||||
|
||||
QString qmlPath;
|
||||
QDeclarativeEngine* engine;
|
||||
QScriptEngine *scriptEngine;
|
||||
QDeclarativeComponent* component;
|
||||
QObject *root;
|
||||
bool delay : 1;
|
||||
};
|
||||
|
||||
void DeclarativeWidgetPrivate::errorPrint()
|
||||
{
|
||||
QString errorStr = "Error loading QML file.\n";
|
||||
if(component->isError()){
|
||||
QList<QDeclarativeError> errors = component->errors();
|
||||
foreach (const QDeclarativeError &error, errors) {
|
||||
errorStr += (error.line()>0?QString(QString::number(error.line()) + QLatin1String(": ")):QLatin1String(""))
|
||||
+ error.description() + '\n';
|
||||
}
|
||||
}
|
||||
kWarning() << component->url().toString() + '\n' + errorStr;
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::execute(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "File name empty!";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(engine);
|
||||
kdeclarative.initialize();
|
||||
//binds things like kconfig and icons
|
||||
kdeclarative.setupBindings();
|
||||
|
||||
component->loadUrl(QUrl::fromLocalFile(fileName));
|
||||
|
||||
scriptEngine = kdeclarative.scriptEngine();
|
||||
registerDataEngineMetaTypes(scriptEngine);
|
||||
|
||||
if (delay) {
|
||||
QTimer::singleShot(0, q, SLOT(scheduleExecutionEnd()));
|
||||
} else {
|
||||
scheduleExecutionEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::scheduleExecutionEnd()
|
||||
{
|
||||
if (component->isReady() || component->isError()) {
|
||||
finishExecute();
|
||||
} else {
|
||||
QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), q, SLOT(finishExecute()));
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::finishExecute()
|
||||
{
|
||||
if (component->isError()) {
|
||||
errorPrint();
|
||||
}
|
||||
|
||||
root = component->create();
|
||||
|
||||
if (!root) {
|
||||
errorPrint();
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "Execution of QML done!";
|
||||
#endif
|
||||
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget*>(root);
|
||||
QGraphicsObject *object = dynamic_cast<QGraphicsObject *>(root);
|
||||
|
||||
|
||||
if (object) {
|
||||
static_cast<QGraphicsItem *>(object)->setParentItem(q);
|
||||
}
|
||||
|
||||
if (widget) {
|
||||
q->setPreferredSize(-1,-1);
|
||||
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(q->layout());
|
||||
if (!lay) {
|
||||
lay = new QGraphicsLinearLayout(q);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
lay->addItem(widget);
|
||||
} else {
|
||||
q->setLayout(0);
|
||||
qreal minimumWidth = 0;
|
||||
qreal minimumHeight = 0;
|
||||
qreal maximumWidth = 0;
|
||||
qreal maximumHeight = 0;
|
||||
qreal preferredWidth = 0;
|
||||
qreal preferredHeight = 0;
|
||||
if (object) {
|
||||
object->setProperty("width", q->size().width());
|
||||
object->setProperty("height", q->size().height());
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
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) {
|
||||
q->setMinimumSize(minimumWidth, minimumHeight);
|
||||
} else {
|
||||
q->setMinimumSize(-1, -1);
|
||||
}
|
||||
|
||||
if (maximumWidth > 0 && maximumHeight > 0) {
|
||||
q->setMaximumSize(maximumWidth, maximumHeight);
|
||||
} else {
|
||||
q->setMaximumSize(-1, -1);
|
||||
}
|
||||
|
||||
if (preferredWidth > 0 && preferredHeight > 0) {
|
||||
q->setPreferredSize(preferredWidth, preferredHeight);
|
||||
} else {
|
||||
q->setPreferredSize(-1, -1);
|
||||
}
|
||||
}
|
||||
emit q->finished();
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::minimumWidthChanged()
|
||||
{
|
||||
qreal minimumWidth = root->property("minimumWidth").toReal();
|
||||
q->setMinimumWidth(minimumWidth);
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::minimumHeightChanged()
|
||||
{
|
||||
qreal minimumHeight = root->property("minimumHeight").toReal();
|
||||
q->setMinimumHeight(minimumHeight);
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::maximumWidthChanged()
|
||||
{
|
||||
qreal maximumWidth = root->property("maximumWidth").toReal();
|
||||
q->setMaximumWidth(maximumWidth);
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::maximumHeightChanged()
|
||||
{
|
||||
qreal maximumHeight = root->property("maximumHeight").toReal();
|
||||
q->setMaximumHeight(maximumHeight);
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::preferredWidthChanged()
|
||||
{
|
||||
qreal preferredWidth = root->property("preferredWidth").toReal();
|
||||
q->setPreferredWidth(preferredWidth);
|
||||
}
|
||||
|
||||
void DeclarativeWidgetPrivate::preferredHeightChanged()
|
||||
{
|
||||
qreal preferredHeight = root->property("preferredHeight").toReal();
|
||||
q->setPreferredHeight(preferredHeight);
|
||||
}
|
||||
|
||||
DeclarativeWidget::DeclarativeWidget(QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
d(new DeclarativeWidgetPrivate(this))
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemHasNoContents);
|
||||
|
||||
d->engine = new QDeclarativeEngine(this);
|
||||
d->engine->setNetworkAccessManagerFactory(new DeclarativeNetworkAccessManagerFactory);
|
||||
|
||||
d->component = new QDeclarativeComponent(d->engine, this);
|
||||
}
|
||||
|
||||
DeclarativeWidget::~DeclarativeWidget()
|
||||
{
|
||||
QDeclarativeNetworkAccessManagerFactory *factory = d->engine->networkAccessManagerFactory();
|
||||
d->engine->setNetworkAccessManagerFactory(0);
|
||||
delete factory;
|
||||
delete d;
|
||||
}
|
||||
|
||||
void DeclarativeWidget::setQmlPath(const QString &path)
|
||||
{
|
||||
d->qmlPath = path;
|
||||
d->execute(path);
|
||||
}
|
||||
|
||||
QString DeclarativeWidget::qmlPath() const
|
||||
{
|
||||
return d->qmlPath;
|
||||
}
|
||||
|
||||
void DeclarativeWidget::setInitializationDelayed(const bool delay)
|
||||
{
|
||||
d->delay = delay;
|
||||
}
|
||||
|
||||
bool DeclarativeWidget::isInitializationDelayed() const
|
||||
{
|
||||
return d->delay;
|
||||
}
|
||||
|
||||
QDeclarativeEngine* DeclarativeWidget::engine()
|
||||
{
|
||||
return d->engine;
|
||||
}
|
||||
|
||||
QScriptEngine *DeclarativeWidget::scriptEngine() const
|
||||
{
|
||||
return d->scriptEngine;
|
||||
}
|
||||
|
||||
QObject *DeclarativeWidget::rootObject() const
|
||||
{
|
||||
return d->root;
|
||||
}
|
||||
|
||||
QDeclarativeComponent *DeclarativeWidget::mainComponent() const
|
||||
{
|
||||
return d->component;
|
||||
}
|
||||
|
||||
void DeclarativeWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
QGraphicsWidget::resizeEvent(event);
|
||||
|
||||
if (d->root) {
|
||||
d->root->setProperty("width", size().width());
|
||||
d->root->setProperty("height", size().height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_declarativewidget.cpp"
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_DECLARATIVEWIDGET_H
|
||||
#define PLASMA_DECLARATIVEWIDGET_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QDeclarativeEngine;
|
||||
class QDeclarativeComponent;
|
||||
class QScriptEngine;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class DeclarativeWidgetPrivate;
|
||||
|
||||
/**
|
||||
* @class DeclarativeWidget plasma/declarativewidget.h <Plasma/DeclarativeWidget>
|
||||
*
|
||||
* @author Marco Martin <mart@kde.org>
|
||||
*
|
||||
* @short A widget that contains an entire QML context, with its own declarative engine
|
||||
*
|
||||
* Plasma::DeclarativeWidget provides a class for conveniently use QML based
|
||||
* declarative user interfaces inside Plasma widgets.
|
||||
* To one DeclarativeWidget corresponds one QML file (that can eventually include others)
|
||||
* tere will be its own QDeclarativeEngine with a single root object,
|
||||
* described in the QML file.
|
||||
*/
|
||||
class PLASMA_EXPORT DeclarativeWidget : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString qmlPath READ qmlPath WRITE setQmlPath)
|
||||
Q_PROPERTY(bool initializationDelayed READ isInitializationDelayed WRITE setInitializationDelayed)
|
||||
Q_PROPERTY(QObject * rootObject READ rootObject)
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructs a new DeclarativeWidget
|
||||
*
|
||||
* @param parent the parent of this widget
|
||||
*/
|
||||
explicit DeclarativeWidget(QGraphicsWidget *parent = 0);
|
||||
~DeclarativeWidget();
|
||||
|
||||
/**
|
||||
* Sets the path of the QML file to parse and execute
|
||||
*
|
||||
* @param path the absolute path of a QML file
|
||||
*/
|
||||
void setQmlPath(const QString &path);
|
||||
|
||||
/**
|
||||
* @return the absolute path of the current QML file
|
||||
*/
|
||||
QString qmlPath() const;
|
||||
|
||||
/**
|
||||
* Sets whether the execution of the QML file has to be delayed later in the event loop. It has to be called before setQmlPath().
|
||||
* In this case will be possible to assign new objects in the main engine context
|
||||
* before the main component gets initialized.
|
||||
* So it will be possible to access it immediately from the QML code.
|
||||
*
|
||||
* @param delay if true the initialization of the QML file will be delayed
|
||||
* at the end of the event loop
|
||||
*/
|
||||
void setInitializationDelayed(const bool delay);
|
||||
|
||||
/**
|
||||
* @return true if the initialization of the QML file will be delayed
|
||||
* at the end of the event loop
|
||||
*/
|
||||
bool isInitializationDelayed() const;
|
||||
|
||||
/**
|
||||
* @return the declarative engine that runs the qml file assigned to this widget.
|
||||
*/
|
||||
QDeclarativeEngine* engine();
|
||||
|
||||
/**
|
||||
* @return the script engine used by the declarative engine
|
||||
* @since 4.7
|
||||
*/
|
||||
QScriptEngine *scriptEngine() const;
|
||||
|
||||
/**
|
||||
* @return the root object of the declarative object tree
|
||||
*/
|
||||
QObject *rootObject() const;
|
||||
|
||||
/**
|
||||
* @return the main QDeclarativeComponent of the engine
|
||||
*/
|
||||
QDeclarativeComponent *mainComponent() const;
|
||||
|
||||
protected:
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when the parsing and execution of the QML file is terminated
|
||||
*/
|
||||
void finished();
|
||||
|
||||
private:
|
||||
friend class DeclarativeWidgetPrivate;
|
||||
DeclarativeWidgetPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void finishExecute())
|
||||
Q_PRIVATE_SLOT(d, void scheduleExecutionEnd())
|
||||
Q_PRIVATE_SLOT(d, void minimumWidthChanged())
|
||||
Q_PRIVATE_SLOT(d, void minimumHeightChanged())
|
||||
Q_PRIVATE_SLOT(d, void maximumWidthChanged())
|
||||
Q_PRIVATE_SLOT(d, void maximumHeightChanged())
|
||||
Q_PRIVATE_SLOT(d, void preferredWidthChanged())
|
||||
Q_PRIVATE_SLOT(d, void preferredHeightChanged())
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
Loading…
Reference in New Issue
Block a user