2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2009-08-18 00:31:18 +02:00
|
|
|
* Copyright 2009 Chani Armitage <chani@kde.org>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* 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 "containment.h"
|
|
|
|
#include "private/containment_p.h"
|
|
|
|
|
2009-05-05 20:11:50 +02:00
|
|
|
#include <QApplication>
|
2009-05-05 07:19:35 +02:00
|
|
|
#include <QClipboard>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
|
|
|
#include <QGraphicsLayout>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kauthorized.h>
|
|
|
|
#include <kicon.h>
|
|
|
|
#include <kmenu.h>
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <kmimetype.h>
|
|
|
|
#include <krun.h>
|
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <ktemporaryfile.h>
|
|
|
|
#include <kwindowsystem.h>
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
#include "kio/jobclasses.h" // for KIO::JobFlags
|
|
|
|
#include "kio/job.h"
|
|
|
|
#include "kio/scheduler.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include "animator.h"
|
|
|
|
#include "context.h"
|
2009-08-18 00:31:32 +02:00
|
|
|
#include "containmentactions.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "corona.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "extenderitem.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "svg.h"
|
|
|
|
#include "wallpaper.h"
|
|
|
|
|
2009-09-22 17:29:08 +02:00
|
|
|
#include "remote/accessappletjob.h"
|
|
|
|
#include "remote/accessmanager.h"
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/applet_p.h"
|
|
|
|
#include "private/applethandle_p.h"
|
|
|
|
#include "private/desktoptoolbox_p.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "private/extenderitemmimedata_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/paneltoolbox_p.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ContainmentPrivate::s_positioning = false;
|
|
|
|
static const char defaultWallpaper[] = "image";
|
|
|
|
static const char defaultWallpaperMode[] = "SingleImage";
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption()
|
|
|
|
: QStyleOptionGraphicsItem(),
|
|
|
|
view(0)
|
|
|
|
{
|
|
|
|
version = Version;
|
|
|
|
type = Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const Containment::StyleOption & other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
|
|
|
view(other.view)
|
|
|
|
{
|
|
|
|
version = Version;
|
|
|
|
type = Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const QStyleOptionGraphicsItem &other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
|
|
|
view(0)
|
|
|
|
{
|
|
|
|
version = Version;
|
|
|
|
type = Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::Containment(QGraphicsItem *parent,
|
|
|
|
const QString &serviceId,
|
|
|
|
uint containmentId)
|
|
|
|
: Applet(parent, serviceId, containmentId),
|
|
|
|
d(new ContainmentPrivate(this))
|
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
setPos(0, 0);
|
|
|
|
setBackgroundHints(NoBackground);
|
|
|
|
setContainmentType(CustomContainment);
|
2009-01-22 01:00:16 +01:00
|
|
|
setHasConfigurationInterface(false);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::Containment(QObject *parent, const QVariantList &args)
|
|
|
|
: Applet(parent, args),
|
|
|
|
d(new ContainmentPrivate(this))
|
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
setPos(0, 0);
|
|
|
|
setBackgroundHints(NoBackground);
|
2009-01-22 01:00:16 +01:00
|
|
|
setHasConfigurationInterface(false);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::~Containment()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::init()
|
|
|
|
{
|
|
|
|
if (!isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCacheMode(NoCache);
|
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
|
|
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
|
|
|
|
//TODO: would be nice to not do this on init, as it causes Animator to init
|
|
|
|
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
|
|
|
this, SLOT(containmentAppletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
|
|
|
|
|
|
|
if (d->type == NoContainmentType) {
|
|
|
|
setContainmentType(DesktopContainment);
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
//connect actions
|
|
|
|
ContainmentPrivate::addDefaultActions(d->actions());
|
2008-11-04 00:08:39 +01:00
|
|
|
bool unlocked = immutability() == Mutable;
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
//fix the text of the actions that need name()
|
|
|
|
//btw, do we really want to use name() when it's a desktopcontainment?
|
2009-06-10 06:51:24 +02:00
|
|
|
QAction *closeApplet = action("remove");
|
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setText(i18nc("%1 is the name of the applet", "Remove this %1", name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *configAction = action("configure");
|
|
|
|
if (configAction) {
|
|
|
|
configAction->setText(i18nc("%1 is the name of the applet", "%1 Settings", name()));
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
|
|
|
|
QAction *appletBrowserAction = action("add widgets");
|
2009-06-10 06:51:24 +02:00
|
|
|
if (appletBrowserAction) {
|
|
|
|
appletBrowserAction->setVisible(unlocked);
|
|
|
|
appletBrowserAction->setEnabled(unlocked);
|
|
|
|
connect(appletBrowserAction, SIGNAL(triggered()), this, SLOT(triggerShowAddWidgets()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *act = action("next applet");
|
2009-06-10 06:51:24 +02:00
|
|
|
if (act) {
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(focusNextApplet()));
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
act = action("previous applet");
|
2009-06-10 06:51:24 +02:00
|
|
|
if (act) {
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(focusPreviousApplet()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-10 20:52:50 +01:00
|
|
|
if (immutability() != SystemImmutable && corona()) {
|
|
|
|
QAction *lockDesktopAction = corona()->action("lock widgets");
|
|
|
|
//keep a pointer so nobody notices it moved to corona
|
|
|
|
if (lockDesktopAction) {
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions()->addAction("lock widgets", lockDesktopAction);
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
if (d->type == PanelContainment ||
|
|
|
|
d->type == CustomPanelContainment) {
|
2009-06-10 06:51:24 +02:00
|
|
|
d->actions()->removeAction(action("zoom in"));
|
2009-05-03 22:22:14 +02:00
|
|
|
} else {
|
|
|
|
QAction *zoomAction = action("zoom in");
|
|
|
|
connect(zoomAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-11 19:37:12 +01:00
|
|
|
if (corona()) {
|
2009-03-20 01:36:04 +01:00
|
|
|
QAction *action = corona()->action("zoom out");
|
|
|
|
if (action) {
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions()->addAction("zoom out", action);
|
2009-03-20 01:36:04 +01:00
|
|
|
}
|
|
|
|
action = corona()->action("add sibling containment");
|
2009-03-11 19:37:12 +01:00
|
|
|
if (action) {
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions()->addAction("add sibling containment", action);
|
|
|
|
}
|
|
|
|
//a stupid hack to make this one's keyboard shortcut work
|
|
|
|
action = corona()->action("configure shortcuts");
|
|
|
|
if (action) {
|
|
|
|
d->actions()->addAction("configure shortcuts", action);
|
2009-03-11 19:37:12 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (d->type == DesktopContainment && d->toolBox) {
|
|
|
|
d->toolBox->addTool(this->action("add widgets"));
|
|
|
|
d->toolBox->addTool(this->action("zoom in"));
|
2008-12-01 13:40:08 +01:00
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
//TODO: do we need some way to allow this be overridden?
|
|
|
|
// it's always available because shells rely on this
|
|
|
|
// to offer their own custom configuration as well
|
|
|
|
QAction *configureContainment = this->action("configure");
|
|
|
|
if (configureContainment) {
|
|
|
|
d->toolBox->addTool(configureContainment);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set a default wallpaper the first time the containment is created,
|
|
|
|
//for instance from the toolbox by the user
|
|
|
|
if (d->drawWallpaper) {
|
|
|
|
setDrawWallpaper(true);
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
//containmentactionss, from config or defaults
|
|
|
|
KConfigGroup cfg = config();
|
|
|
|
cfg = KConfigGroup(&cfg, "ActionPlugins");
|
2009-08-18 00:30:34 +02:00
|
|
|
if (cfg.exists()) {
|
|
|
|
foreach (const QString &key, cfg.keyList()) {
|
2009-08-18 00:31:32 +02:00
|
|
|
setContainmentActions(key, cfg.readEntry(key, QString()));
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-08-18 00:30:46 +02:00
|
|
|
//we need to be very careful here to not write anything
|
|
|
|
//because we have a group, and so the defaults will get merged instead of overwritten
|
|
|
|
//when copyTo is used (which happens right before restore() is called)
|
|
|
|
//FIXME maybe PlasmaApp should handle the defaults?
|
|
|
|
QHash<QString,QString> defaults;
|
|
|
|
switch (d->type) {
|
|
|
|
case DesktopContainment:
|
2009-08-18 00:30:42 +02:00
|
|
|
defaults.insert("wheel:Vertical;NoModifier", "switchdesktop");
|
2009-08-18 00:31:37 +02:00
|
|
|
defaults.insert("MidButton;NoModifier", "paste");
|
2009-08-18 00:30:46 +02:00
|
|
|
defaults.insert("RightButton;NoModifier", "contextmenu");
|
|
|
|
break;
|
|
|
|
case PanelContainment:
|
|
|
|
case CustomPanelContainment:
|
|
|
|
defaults.insert("RightButton;NoModifier", "contextmenu");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
for (QHash<QString,QString>::const_iterator it = defaults.constBegin(),
|
|
|
|
end = defaults.constEnd(); it != end; ++it) {
|
|
|
|
ContainmentActions *plugin = ContainmentActions::load(this, it.value());
|
|
|
|
if (plugin) {
|
|
|
|
d->actionPlugins.insert(it.key(), plugin);
|
2009-08-18 00:30:42 +02:00
|
|
|
}
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::addDefaultActions(KActionCollection *actions)
|
|
|
|
{
|
|
|
|
actions->setConfigGroup("Shortcuts-Containment");
|
|
|
|
|
|
|
|
//adjust applet actions
|
|
|
|
KAction *appAction = qobject_cast<KAction*>(actions->action("remove"));
|
|
|
|
appAction->setShortcut(KShortcut("alt+d, alt+r"));
|
|
|
|
appAction->setText(i18n("Remove this Activity"));
|
|
|
|
appAction = qobject_cast<KAction*>(actions->action("configure"));
|
|
|
|
if (appAction) {
|
|
|
|
appAction->setShortcut(KShortcut("alt+d, alt+s"));
|
|
|
|
appAction->setText(i18n("Activity Settings"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//add our own actions
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction *appletBrowserAction = actions->addAction("add widgets");
|
2009-06-29 03:22:58 +02:00
|
|
|
appletBrowserAction->setAutoRepeat(false);
|
2009-05-04 00:13:05 +02:00
|
|
|
appletBrowserAction->setText(i18n("Add Widgets..."));
|
2009-05-03 22:22:14 +02:00
|
|
|
appletBrowserAction->setIcon(KIcon("list-add"));
|
|
|
|
appletBrowserAction->setShortcut(KShortcut("alt+d, a"));
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction *action = actions->addAction("next applet");
|
|
|
|
action->setText(i18n("Next Widget"));
|
2009-05-03 22:22:14 +02:00
|
|
|
//no icon
|
|
|
|
action->setShortcut(KShortcut("alt+d, n"));
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
action = actions->addAction("previous applet");
|
|
|
|
action->setText(i18n("Previous Widget"));
|
2009-05-03 22:22:14 +02:00
|
|
|
//no icon
|
|
|
|
action->setShortcut(KShortcut("alt+d, p"));
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction *zoomAction = actions->addAction("zoom in");
|
2009-06-29 03:22:58 +02:00
|
|
|
zoomAction->setAutoRepeat(false);
|
2009-05-04 00:13:05 +02:00
|
|
|
zoomAction->setText(i18n("Zoom In"));
|
2009-05-03 22:22:14 +02:00
|
|
|
zoomAction->setIcon(KIcon("zoom-in"));
|
|
|
|
//two shortcuts because I hate ctrl-+ but others expect it
|
|
|
|
zoomAction->setShortcuts(KShortcut("alt+d, +; alt+d, ="));
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// helper function for sorting the list of applets
|
|
|
|
bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2)
|
|
|
|
{
|
|
|
|
QPointF p1 = c1.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
QPointF p2 = c2.readEntry("geometry", QRectF()).topLeft();
|
2008-11-14 05:01:01 +01:00
|
|
|
|
|
|
|
if (!qFuzzyCompare(p1.x(), p2.x())) {
|
2009-07-08 02:37:40 +02:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
return p1.x() > p2.x();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return p1.x() < p2.x();
|
|
|
|
}
|
2008-11-14 05:01:01 +01:00
|
|
|
|
|
|
|
return qFuzzyCompare(p1.y(), p2.y()) || p1.y() < p2.y();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::restore(KConfigGroup &group)
|
|
|
|
{
|
2009-01-23 08:32:11 +01:00
|
|
|
/*kDebug() << "!!!!!!!!!!!!initConstraints" << group.name() << d->type;
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << " location:" << group.readEntry("location", (int)d->location);
|
|
|
|
kDebug() << " geom:" << group.readEntry("geometry", geometry());
|
|
|
|
kDebug() << " formfactor:" << group.readEntry("formfactor", (int)d->formFactor);
|
|
|
|
kDebug() << " screen:" << group.readEntry("screen", d->screen);*/
|
|
|
|
if (!isContainment()) {
|
|
|
|
Applet::restore(group);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF geo = group.readEntry("geometry", geometry());
|
|
|
|
//override max/min
|
|
|
|
//this ensures panels are set to their saved size even when they have max & min set to prevent
|
|
|
|
//resizing
|
|
|
|
if (geo.size() != geo.size().boundedTo(maximumSize())) {
|
|
|
|
setMaximumSize(maximumSize().expandedTo(geo.size()));
|
|
|
|
}
|
|
|
|
if (geo.size() != geo.size().expandedTo(minimumSize())) {
|
|
|
|
setMinimumSize(minimumSize().boundedTo(geo.size()));
|
|
|
|
}
|
2009-04-08 22:37:45 +02:00
|
|
|
|
2009-05-20 22:27:01 +02:00
|
|
|
|
|
|
|
setGeometry(geo);
|
2009-04-08 22:37:45 +02:00
|
|
|
//are we an offscreen containment?
|
|
|
|
if (containmentType() != PanelContainment && containmentType() != CustomPanelContainment && geo.right() < 0) {
|
|
|
|
corona()->addOffscreenWidget(this);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
setLocation((Plasma::Location)group.readEntry("location", (int)d->location));
|
|
|
|
setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
|
2009-06-01 19:30:52 +02:00
|
|
|
//kDebug() << "setScreen from restore";
|
2008-11-17 06:16:33 +01:00
|
|
|
setScreen(group.readEntry("screen", d->screen), group.readEntry("desktop", d->desktop));
|
2008-11-04 00:08:39 +01:00
|
|
|
setActivity(group.readEntry("activity", QString()));
|
|
|
|
|
|
|
|
flushPendingConstraintsEvents();
|
|
|
|
restoreContents(group);
|
|
|
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
|
|
|
|
|
|
|
setWallpaper(group.readEntry("wallpaperplugin", defaultWallpaper),
|
|
|
|
group.readEntry("wallpaperpluginmode", defaultWallpaperMode));
|
2009-06-15 15:57:46 +02:00
|
|
|
|
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->load(group);
|
|
|
|
}
|
2009-08-18 00:30:42 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
KConfigGroup cfg(&group, "ActionPlugins");
|
2009-08-18 00:30:42 +02:00
|
|
|
kDebug() << cfg.keyList();
|
|
|
|
if (cfg.exists()) {
|
2009-08-18 00:31:32 +02:00
|
|
|
//clear default containmentactionss
|
|
|
|
qDeleteAll(d->actionPlugins);
|
|
|
|
d->actionPlugins.clear();
|
2009-08-18 00:30:42 +02:00
|
|
|
//load the right configactions
|
|
|
|
foreach (const QString &key, cfg.keyList()) {
|
|
|
|
kDebug() << "loading" << key;
|
2009-08-18 00:31:32 +02:00
|
|
|
setContainmentActions(key, cfg.readEntry(key, QString()));
|
2009-08-18 00:30:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
kDebug() << "Containment" << id() <<
|
|
|
|
"screen" << screen() <<
|
|
|
|
"geometry is" << geometry() <<
|
|
|
|
"wallpaper" << ((d->wallpaper) ? d->wallpaper->pluginName() : QString()) <<
|
|
|
|
"wallpaper mode" << wallpaperMode() <<
|
|
|
|
"config entries" << group.entryMap();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::save(KConfigGroup &g) const
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (Applet::d->transient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup group = g;
|
|
|
|
if (!group.isValid()) {
|
|
|
|
group = config();
|
|
|
|
}
|
|
|
|
|
|
|
|
// locking is saved in Applet::save
|
|
|
|
Applet::save(group);
|
|
|
|
group.writeEntry("screen", d->screen);
|
2008-11-17 06:16:33 +01:00
|
|
|
group.writeEntry("desktop", d->desktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
group.writeEntry("formfactor", (int)d->formFactor);
|
|
|
|
group.writeEntry("location", (int)d->location);
|
|
|
|
group.writeEntry("activity", d->context()->currentActivity());
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->save(group);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->wallpaper) {
|
|
|
|
group.writeEntry("wallpaperplugin", d->wallpaper->pluginName());
|
|
|
|
group.writeEntry("wallpaperpluginmode", d->wallpaper->renderingMode().name());
|
|
|
|
|
|
|
|
if (d->wallpaper->isInitialized()) {
|
|
|
|
KConfigGroup wallpaperConfig(&group, "Wallpaper");
|
|
|
|
wallpaperConfig = KConfigGroup(&wallpaperConfig, d->wallpaper->pluginName());
|
|
|
|
d->wallpaper->save(wallpaperConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveContents(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::saveContents(KConfigGroup &group) const
|
|
|
|
{
|
|
|
|
KConfigGroup applets(&group, "Applets");
|
|
|
|
foreach (const Applet *applet, d->applets) {
|
|
|
|
KConfigGroup appletConfig(&applets, QString::number(applet->id()));
|
|
|
|
applet->save(appletConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::restoreContents(KConfigGroup &group)
|
|
|
|
{
|
|
|
|
KConfigGroup applets(&group, "Applets");
|
|
|
|
|
|
|
|
// Sort the applet configs in order of geometry to ensure that applets
|
|
|
|
// are added from left to right or top to bottom for a panel containment
|
|
|
|
QList<KConfigGroup> appletConfigs;
|
|
|
|
foreach (const QString &appletGroup, applets.groupList()) {
|
|
|
|
//kDebug() << "reading from applet group" << appletGroup;
|
|
|
|
KConfigGroup appletConfig(&applets, appletGroup);
|
|
|
|
appletConfigs.append(appletConfig);
|
|
|
|
}
|
2008-11-14 05:01:01 +01:00
|
|
|
qStableSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-06 00:14:47 +01:00
|
|
|
QMutableListIterator<KConfigGroup> it(appletConfigs);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
KConfigGroup &appletConfig = it.next();
|
2008-11-04 00:08:39 +01:00
|
|
|
int appId = appletConfig.name().toUInt();
|
|
|
|
QString plugin = appletConfig.readEntry("plugin", QString());
|
|
|
|
|
|
|
|
if (plugin.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-06 00:14:47 +01:00
|
|
|
Applet *applet = d->addApplet(plugin, QVariantList(),
|
|
|
|
appletConfig.readEntry("geometry", QRectF()),
|
|
|
|
appId, true);
|
2008-11-04 00:08:39 +01:00
|
|
|
applet->restore(appletConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::Type Containment::containmentType() const
|
|
|
|
{
|
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setContainmentType(Containment::Type type)
|
|
|
|
{
|
|
|
|
if (d->type == type) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete d->toolBox;
|
|
|
|
d->toolBox = 0;
|
|
|
|
d->type = type;
|
|
|
|
|
|
|
|
if (!isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-24 19:51:29 +01:00
|
|
|
if (type == DesktopContainment || type == PanelContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->createToolBox();
|
|
|
|
}
|
2008-12-04 21:34:04 +01:00
|
|
|
|
2008-12-15 17:54:09 +01:00
|
|
|
d->checkRemoveAction();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Corona *Containment::corona() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<Corona*>(scene());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
if (d->wallpaper && d->wallpaper->isInitialized()) {
|
|
|
|
QGraphicsItem *item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
|
|
|
d->wallpaper->mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event->isAccepted()) {
|
|
|
|
event->accept();
|
|
|
|
Applet::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
2009-08-30 20:52:05 +02:00
|
|
|
if (d->appletAt(event->scenePos())) {
|
2009-08-18 00:31:18 +02:00
|
|
|
return; //no unexpected click-throughs
|
|
|
|
}
|
2009-08-18 00:30:34 +02:00
|
|
|
|
|
|
|
if (d->wallpaper && d->wallpaper->isInitialized() && !event->isAccepted()) {
|
2009-08-18 00:31:18 +02:00
|
|
|
d->wallpaper->mousePressEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event->isAccepted()) {
|
|
|
|
setFocus(Qt::MouseFocusReason);
|
|
|
|
} else {
|
2009-08-25 18:14:05 +02:00
|
|
|
QString trigger = ContainmentActions::eventToString(event);
|
|
|
|
if (d->actionPlugins.contains(trigger)) {
|
|
|
|
if (d->prepareContainmentActions(trigger, event->screenPos())) {
|
|
|
|
d->actionPlugins.value(trigger)->contextEvent(event);
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
2009-08-30 20:52:05 +02:00
|
|
|
if (d->appletAt(event->scenePos())) {
|
2009-08-18 00:31:18 +02:00
|
|
|
return; //no unexpected click-throughs
|
|
|
|
}
|
2009-08-18 00:30:34 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString trigger = ContainmentActions::eventToString(event);
|
2009-08-18 00:30:34 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->wallpaper && d->wallpaper->isInitialized()) {
|
2009-08-18 00:31:18 +02:00
|
|
|
d->wallpaper->mouseReleaseEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-08-25 18:14:05 +02:00
|
|
|
if (!event->isAccepted() && isContainment()) {
|
|
|
|
if (d->actionPlugins.contains(trigger)) {
|
|
|
|
if (d->prepareContainmentActions(trigger, event->screenPos())) {
|
|
|
|
d->actionPlugins.value(trigger)->contextEvent(event);
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
event->accept();
|
|
|
|
Applet::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::showDropZone(const QPoint pos)
|
|
|
|
{
|
2008-11-17 05:34:55 +01:00
|
|
|
Q_UNUSED(pos)
|
2008-11-04 00:08:39 +01:00
|
|
|
//Base implementation does nothing, don't put code here
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::showContextMenu(const QPointF &containmentPos, const QPoint &screenPos)
|
|
|
|
{
|
2009-08-30 20:52:10 +02:00
|
|
|
d->showContextMenu(mapToScene(containmentPos), screenPos, false, false);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2009-09-01 20:46:28 +02:00
|
|
|
//kDebug() << "let's see if we manage to get a context menu here, huh";
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!isContainment() || !scene() || !KAuthorized::authorizeKAction("desktop_contextmenu")) {
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-30 20:52:10 +02:00
|
|
|
if (d->showContextMenu(event->scenePos(), event->screenPos(), true,
|
|
|
|
event->reason() == QGraphicsSceneContextMenuEvent::Mouse)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
event->accept();
|
2009-08-30 20:51:32 +02:00
|
|
|
} else {
|
|
|
|
Applet::contextMenuEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-14 00:08:58 +01:00
|
|
|
void ContainmentPrivate::containmentActions(KMenu &desktopMenu)
|
|
|
|
{
|
|
|
|
if (static_cast<Corona*>(q->scene())->immutability() != Mutable &&
|
|
|
|
!KAuthorized::authorizeKAction("unlock_desktop")) {
|
|
|
|
//kDebug() << "immutability";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:46 +02:00
|
|
|
QString trigger = "RightButton;NoModifier";
|
2008-11-14 00:08:58 +01:00
|
|
|
//get base context actions
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *plugin = actionPlugins.value(trigger);
|
|
|
|
if (plugin) {
|
|
|
|
if (!plugin->isInitialized()) {
|
|
|
|
KConfigGroup cfg = q->config();
|
|
|
|
cfg = KConfigGroup(&cfg, "ActionPlugins");
|
2009-08-18 00:31:37 +02:00
|
|
|
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
|
2009-08-18 00:31:32 +02:00
|
|
|
plugin->restore(pluginConfig);
|
2009-08-18 00:31:18 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (plugin->configurationRequired()) {
|
|
|
|
desktopMenu.addTitle(i18n("This menu needs to be configured"));
|
2009-08-18 00:30:58 +02:00
|
|
|
desktopMenu.addAction(q->action("configure"));
|
2009-08-18 00:30:46 +02:00
|
|
|
} else {
|
2009-08-18 00:31:32 +02:00
|
|
|
QList<QAction*> actions = plugin->contextualActions();
|
2009-08-18 00:30:46 +02:00
|
|
|
if (actions.isEmpty()) {
|
|
|
|
//it probably didn't bother implementing the function. give the user a chance to set
|
|
|
|
//a better plugin.
|
|
|
|
//note that if the user sets no-plugin this won't happen...
|
|
|
|
//FIXME maybe the behaviour could be better
|
|
|
|
if (type == Containment::DesktopContainment) {
|
|
|
|
desktopMenu.addAction(q->action("configure"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//yay!
|
|
|
|
desktopMenu.addActions(actions);
|
2008-12-09 20:10:30 +01:00
|
|
|
}
|
2008-11-14 00:08:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::appletActions(KMenu &desktopMenu, Applet *applet, bool includeApplet)
|
|
|
|
{
|
|
|
|
QList<QAction*> actions;
|
|
|
|
|
|
|
|
if (includeApplet) {
|
|
|
|
actions = applet->contextualActions();
|
2009-08-18 00:31:32 +02:00
|
|
|
foreach (QAction *action, actions) {
|
|
|
|
if (action) {
|
|
|
|
desktopMenu.addAction(action);
|
2008-11-14 00:08:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-28 03:09:17 +02:00
|
|
|
QAction *configureApplet = applet->d->actions->action("configure");
|
|
|
|
if (configureApplet && configureApplet->isEnabled()) {
|
|
|
|
desktopMenu.addAction(configureApplet);
|
2008-11-14 00:08:58 +01:00
|
|
|
}
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
QAction *runAssociatedApplication = applet->d->actions->action("run associated application");
|
|
|
|
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
|
|
|
|
desktopMenu.addAction(runAssociatedApplication);
|
|
|
|
}
|
|
|
|
|
2008-11-14 00:08:58 +01:00
|
|
|
KMenu *containmentMenu = new KMenu(i18nc("%1 is the name of the containment", "%1 Options", q->name()), &desktopMenu);
|
|
|
|
containmentActions(*containmentMenu);
|
|
|
|
if (!containmentMenu->isEmpty()) {
|
2009-01-13 12:03:48 +01:00
|
|
|
int enabled = 0;
|
|
|
|
//count number of real actions
|
2009-08-18 00:31:32 +02:00
|
|
|
foreach (const QAction *action, containmentMenu->actions()) {
|
|
|
|
if (action->isVisible() && !action->isSeparator()) {
|
|
|
|
++enabled;
|
2009-01-13 12:03:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (enabled) {
|
|
|
|
//if there is only one, don't create a submenu
|
|
|
|
if (enabled < 2) {
|
|
|
|
foreach (QAction *action, containmentMenu->actions()) {
|
|
|
|
desktopMenu.addAction(action);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
desktopMenu.addMenu(containmentMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<Corona*>(q->scene())->immutability() == Mutable) {
|
|
|
|
if (!desktopMenu.isEmpty()) {
|
2008-11-14 00:08:58 +01:00
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QAction *closeApplet = applet->d->actions->action("remove");
|
|
|
|
if (closeApplet) {
|
|
|
|
desktopMenu.addAction(closeApplet);
|
2009-01-13 12:03:48 +01:00
|
|
|
}
|
2008-11-14 00:08:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 20:52:05 +02:00
|
|
|
Applet* ContainmentPrivate::appletAt(const QPointF &point)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Applet *applet = 0;
|
|
|
|
|
|
|
|
QGraphicsItem *item = q->scene()->itemAt(point);
|
|
|
|
if (item == q) {
|
|
|
|
item = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (item) {
|
2009-08-30 20:51:58 +02:00
|
|
|
if (item->isWidget()) {
|
2009-08-30 20:52:05 +02:00
|
|
|
applet = qobject_cast<Applet*>(static_cast<QGraphicsWidget*>(item));
|
2009-08-30 20:51:58 +02:00
|
|
|
if (applet) {
|
|
|
|
if (applet->isContainment()) {
|
|
|
|
applet = 0;
|
|
|
|
}
|
|
|
|
break;
|
2009-08-30 20:51:51 +02:00
|
|
|
}
|
2009-08-30 20:51:58 +02:00
|
|
|
}
|
2009-08-31 01:41:23 +02:00
|
|
|
AppletHandle *handle = dynamic_cast<AppletHandle*>(item);
|
|
|
|
if (handle) {
|
|
|
|
//pretend it was on the applet
|
|
|
|
applet = handle->applet();
|
|
|
|
break;
|
|
|
|
}
|
2009-08-30 20:52:05 +02:00
|
|
|
item = item->parentItem();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-08-30 20:52:05 +02:00
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
2009-08-30 20:52:10 +02:00
|
|
|
bool ContainmentPrivate::showContextMenu(const QPointF &point, const QPoint &screenPos, bool includeApplet, bool isMouseEvent)
|
2009-08-30 20:52:05 +02:00
|
|
|
{
|
|
|
|
Applet *applet = appletAt(point);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
KMenu desktopMenu;
|
|
|
|
//kDebug() << "context menu event " << (QObject*)applet;
|
|
|
|
if (applet) {
|
2008-11-14 00:08:58 +01:00
|
|
|
appletActions(desktopMenu, applet, includeApplet);
|
2009-08-30 20:52:10 +02:00
|
|
|
} else if (isMouseEvent) {
|
|
|
|
return false; //fall through to plugin/wallpaper stuff
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-08-30 20:51:51 +02:00
|
|
|
containmentActions(desktopMenu);
|
2008-11-14 00:08:58 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-14 00:08:58 +01:00
|
|
|
if (!desktopMenu.isEmpty()) {
|
|
|
|
//kDebug() << "executing at" << screenPos;
|
|
|
|
desktopMenu.exec(screenPos);
|
|
|
|
return true;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-14 00:08:58 +01:00
|
|
|
return false;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setFormFactor(FormFactor formFactor)
|
|
|
|
{
|
|
|
|
if (d->formFactor == formFactor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "switching FF to " << formFactor;
|
|
|
|
d->formFactor = formFactor;
|
|
|
|
|
|
|
|
if (isContainment() &&
|
2009-02-24 05:54:57 +01:00
|
|
|
(d->type == PanelContainment || d->type == CustomPanelContainment)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// we are a panel and we have chaged our orientation
|
|
|
|
d->positionPanel(true);
|
|
|
|
}
|
|
|
|
|
2009-02-24 05:54:57 +01:00
|
|
|
if (d->toolBox) {
|
|
|
|
if (d->formFactor == Vertical) {
|
|
|
|
d->toolBox->setCorner(ToolBox::Bottom);
|
|
|
|
//defaults to horizontal
|
|
|
|
} else if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
d->toolBox->setCorner(ToolBox::Left);
|
|
|
|
} else {
|
|
|
|
d->toolBox->setCorner(ToolBox::Right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
|
|
|
|
KConfigGroup c = config();
|
|
|
|
c.writeEntry("formfactor", (int)formFactor);
|
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setLocation(Location location)
|
|
|
|
{
|
|
|
|
if (d->location == location) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool emitGeomChange = false;
|
|
|
|
|
|
|
|
if ((location == TopEdge || location == BottomEdge) &&
|
|
|
|
(d->location == TopEdge || d->location == BottomEdge)) {
|
|
|
|
emitGeomChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((location == RightEdge || location == LeftEdge) &&
|
|
|
|
(d->location == RightEdge || d->location == LeftEdge)) {
|
|
|
|
emitGeomChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->location = location;
|
|
|
|
|
|
|
|
foreach (Applet *applet, d->applets) {
|
|
|
|
applet->updateConstraints(Plasma::LocationConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emitGeomChange) {
|
|
|
|
// our geometry on the scene will not actually change,
|
|
|
|
// but for the purposes of views it has
|
|
|
|
emit geometryChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConstraints(Plasma::LocationConstraint);
|
|
|
|
|
|
|
|
KConfigGroup c = config();
|
|
|
|
c.writeEntry("location", (int)location);
|
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::addSiblingContainment()
|
|
|
|
{
|
|
|
|
emit addSiblingContainment(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::clearApplets()
|
|
|
|
{
|
|
|
|
foreach (Applet *applet, d->applets) {
|
|
|
|
applet->d->cleanUpAndDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->applets.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *Containment::addApplet(const QString &name, const QVariantList &args,
|
|
|
|
const QRectF &appletGeometry)
|
|
|
|
{
|
|
|
|
return d->addApplet(name, args, appletGeometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
|
|
|
{
|
|
|
|
if (!isContainment() || (!delayInit && immutability() != Mutable)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "adding null applet!?!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->applets.contains(applet)) {
|
|
|
|
kDebug() << "already have this applet!";
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment *currentContainment = applet->containment();
|
|
|
|
|
2009-01-23 08:32:11 +01:00
|
|
|
if (d->type == PanelContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//panels don't want backgrounds, which is important when setting geometry
|
|
|
|
setBackgroundHints(NoBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentContainment && currentContainment != this) {
|
|
|
|
emit currentContainment->appletRemoved(applet);
|
2009-05-13 20:11:08 +02:00
|
|
|
if (currentContainment->d->focusedApplet == applet) {
|
|
|
|
currentContainment->d->focusedApplet = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-25 04:07:18 +01:00
|
|
|
disconnect(applet, 0, currentContainment, 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
applet->removeSceneEventFilter(currentContainment);
|
|
|
|
KConfigGroup oldConfig = applet->config();
|
|
|
|
currentContainment->d->applets.removeAll(applet);
|
|
|
|
if (currentContainment->d->handles.contains(applet)) {
|
|
|
|
currentContainment->d->handles.remove(applet);
|
|
|
|
}
|
|
|
|
applet->setParentItem(this);
|
|
|
|
|
|
|
|
// now move the old config to the new location
|
2009-01-23 08:32:11 +01:00
|
|
|
//FIXME: this doesn't seem to get the actual main config group containing plugin=, etc
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup c = config().group("Applets").group(QString::number(applet->id()));
|
|
|
|
oldConfig.reparent(&c);
|
|
|
|
applet->d->resetConfigurationObject();
|
2009-01-24 11:47:35 +01:00
|
|
|
|
|
|
|
disconnect(applet, SIGNAL(activate()), currentContainment, SIGNAL(activate()));
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
applet->setParentItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->applets << applet;
|
|
|
|
|
|
|
|
connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving()));
|
|
|
|
connect(applet, SIGNAL(releaseVisualFocus()), this, SIGNAL(releaseVisualFocus()));
|
2009-01-28 08:58:17 +01:00
|
|
|
connect(applet, SIGNAL(appletDestroyed(Plasma::Applet*)), this, SLOT(appletDestroyed(Plasma::Applet*)));
|
2009-01-24 11:47:35 +01:00
|
|
|
connect(applet, SIGNAL(activate()), this, SIGNAL(activate()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (pos != QPointF(-1, -1)) {
|
|
|
|
applet->setPos(pos);
|
|
|
|
}
|
|
|
|
|
2009-01-09 21:44:53 +01:00
|
|
|
if (delayInit || currentContainment) {
|
2009-01-23 08:32:11 +01:00
|
|
|
if (d->type == DesktopContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
applet->installSceneEventFilter(this);
|
|
|
|
//applet->setWindowFlags(Qt::Window);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
applet->init();
|
|
|
|
Animator::self()->animateItem(applet, Animator::AppearAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
applet->updateConstraints(Plasma::AllConstraints);
|
|
|
|
|
|
|
|
if (!delayInit) {
|
|
|
|
applet->flushPendingConstraintsEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit appletAdded(applet, pos);
|
2008-12-12 02:05:00 +01:00
|
|
|
|
|
|
|
if (!currentContainment) {
|
|
|
|
applet->updateConstraints(Plasma::StartupCompletedConstraint);
|
|
|
|
if (!delayInit) {
|
|
|
|
applet->flushPendingConstraintsEvents();
|
|
|
|
}
|
|
|
|
}
|
2008-12-15 18:48:28 +01:00
|
|
|
|
|
|
|
if (!delayInit) {
|
|
|
|
applet->d->scheduleModificationNotification();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Applet::List Containment::applets() const
|
|
|
|
{
|
|
|
|
return d->applets;
|
|
|
|
}
|
|
|
|
|
2009-01-18 20:52:09 +01:00
|
|
|
void Containment::setScreen(int newScreen, int newDesktop)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
// What we want to do in here is:
|
|
|
|
// * claim the screen as our own
|
|
|
|
// * signal whatever may be watching this containment about the switch
|
|
|
|
// * if we are a full screen containment, then:
|
|
|
|
// * resize to match the screen if we're that kind of containment
|
|
|
|
// * kick other full-screen containments off this screen
|
|
|
|
// * if we had a screen, then give our screen to the containment
|
|
|
|
// we kick out
|
|
|
|
//
|
|
|
|
// a screen of -1 means no associated screen.
|
2009-01-18 20:52:09 +01:00
|
|
|
Q_ASSERT(corona());
|
|
|
|
int numScreens = corona()->numScreens();
|
|
|
|
if (newScreen < -1) {
|
|
|
|
newScreen = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -1 == All desktops
|
|
|
|
if (newDesktop < -1 || newDesktop > KWindowSystem::numberOfDesktops() - 1) {
|
|
|
|
newDesktop = -1;
|
|
|
|
}
|
|
|
|
|
2009-06-01 19:30:52 +02:00
|
|
|
//kDebug() << activity() << "setting screen to " << newScreen << newDesktop << "and type is" << d->type;
|
2009-01-18 20:52:09 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Containment *swapScreensWith(0);
|
2008-12-15 19:28:28 +01:00
|
|
|
if (d->type == DesktopContainment || d->type >= CustomContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// we want to listen to changes in work area if our screen changes
|
2009-01-18 20:52:09 +01:00
|
|
|
if (d->screen < 0 && newScreen > -1) {
|
2009-02-24 05:54:57 +01:00
|
|
|
connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2009-01-18 20:52:09 +01:00
|
|
|
} else if (newScreen < 0) {
|
2009-02-24 05:54:57 +01:00
|
|
|
disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-11-05 23:57:45 +01:00
|
|
|
|
2009-01-18 20:52:09 +01:00
|
|
|
if (newScreen > -1 && corona()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// sanity check to make sure someone else doesn't have this screen already!
|
2009-01-18 20:52:09 +01:00
|
|
|
Containment *currently = corona()->containmentForScreen(newScreen, newDesktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (currently && currently != this) {
|
2008-12-15 19:28:28 +01:00
|
|
|
kDebug() << "currently is on screen" << currently->screen()
|
2009-04-11 18:23:38 +02:00
|
|
|
<< "desktop" << currently->desktop()
|
|
|
|
<< "and is" << currently->activity()
|
|
|
|
<< (QObject*)currently << "i'm" << (QObject*)this;
|
2009-06-01 19:30:52 +02:00
|
|
|
//kDebug() << "setScreen due to swap";
|
2009-01-18 20:52:09 +01:00
|
|
|
currently->setScreen(-1, newDesktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
swapScreensWith = currently;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 20:52:09 +01:00
|
|
|
if (newScreen < numScreens && newScreen > -1) {
|
2009-01-23 08:32:11 +01:00
|
|
|
if (d->type == DesktopContainment ||
|
|
|
|
d->type >= CustomContainment) {
|
2009-01-18 20:52:09 +01:00
|
|
|
resize(corona()->screenGeometry(newScreen).size());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 18:56:06 +01:00
|
|
|
int oldDesktop = d->desktop;
|
2009-01-18 20:52:09 +01:00
|
|
|
d->desktop = newDesktop;
|
2008-11-17 05:34:55 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
int oldScreen = d->screen;
|
2009-01-18 20:52:09 +01:00
|
|
|
d->screen = newScreen;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
updateConstraints(Plasma::ScreenConstraint);
|
2009-01-18 20:52:09 +01:00
|
|
|
|
2009-06-01 19:30:52 +02:00
|
|
|
if (oldScreen != newScreen || oldDesktop != newDesktop) {
|
|
|
|
if (oldScreen != newScreen) {
|
|
|
|
emit screenChanged(oldScreen, newScreen, this);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
KConfigGroup c = config();
|
|
|
|
c.writeEntry("screen", d->screen);
|
2009-06-01 19:30:52 +02:00
|
|
|
c.writeEntry("desktop", d->desktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapScreensWith) {
|
2009-06-01 19:30:52 +02:00
|
|
|
//kDebug() << "setScreen due to swap, part 2";
|
2009-01-18 18:56:06 +01:00
|
|
|
swapScreensWith->setScreen(oldScreen, oldDesktop);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2008-12-01 13:40:08 +01:00
|
|
|
|
2008-12-15 17:54:09 +01:00
|
|
|
d->checkRemoveAction();
|
2009-06-15 15:58:23 +02:00
|
|
|
|
|
|
|
if (newScreen >= 0) {
|
|
|
|
emit activate();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Containment::screen() const
|
|
|
|
{
|
|
|
|
return d->screen;
|
|
|
|
}
|
|
|
|
|
2008-11-17 05:34:55 +01:00
|
|
|
int Containment::desktop() const
|
|
|
|
{
|
|
|
|
return d->desktop;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KPluginInfo::List Containment::listContainments(const QString &category,
|
|
|
|
const QString &parentApp)
|
2009-04-03 02:29:54 +02:00
|
|
|
{
|
|
|
|
return listContainmentsOfType(QString(), category, parentApp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KPluginInfo::List Containment::listContainmentsOfType(const QString &type,
|
|
|
|
const QString &category,
|
|
|
|
const QString &parentApp)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
2009-04-03 02:29:54 +02:00
|
|
|
if (!type.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
|
|
|
}
|
|
|
|
|
2009-04-03 02:34:53 +02:00
|
|
|
constraint.append("'").append(type).append("' ~in [X-Plasma-ContainmentCategories]");
|
2009-04-03 02:29:54 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
|
|
|
}
|
|
|
|
|
2009-05-01 20:01:26 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
2008-11-04 00:08:39 +01:00
|
|
|
if (category == "Miscellaneous") {
|
2009-05-01 20:01:26 +02:00
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
//kDebug() << "constraint was" << constraint << "which got us" << offers.count() << "matches";
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List Containment::listContainmentsForMimetype(const QString &mimetype)
|
|
|
|
{
|
2009-07-06 13:49:01 +02:00
|
|
|
const QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimetype);
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << mimetype << constraint;
|
2009-07-06 13:49:01 +02:00
|
|
|
const KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
2008-11-04 00:08:39 +01:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2009-04-03 02:29:54 +02:00
|
|
|
QStringList Containment::listContainmentTypes()
|
|
|
|
{
|
|
|
|
KPluginInfo::List containmentInfos = listContainments();
|
|
|
|
QSet<QString> types;
|
|
|
|
|
|
|
|
foreach (const KPluginInfo &containmentInfo, containmentInfos) {
|
|
|
|
QStringList theseTypes = containmentInfo.service()->property("X-Plasma-ContainmentCategories").toStringList();
|
|
|
|
foreach (const QString &type, theseTypes) {
|
|
|
|
types.insert(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.toList();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
//kDebug() << immutability() << Mutable << (immutability() == Mutable);
|
|
|
|
event->setAccepted(immutability() == Mutable &&
|
|
|
|
(event->mimeData()->hasFormat(static_cast<Corona*>(scene())->appletMimeType()) ||
|
2009-02-09 19:10:45 +01:00
|
|
|
KUrl::List::canDecode(event->mimeData()) ||
|
|
|
|
event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (!event->isAccepted()) {
|
|
|
|
// check to see if we have an applet that accepts the format.
|
|
|
|
QStringList formats = event->mimeData()->formats();
|
|
|
|
|
|
|
|
foreach (const QString &format, formats) {
|
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(format);
|
|
|
|
if (!appletList.isEmpty()) {
|
|
|
|
event->setAccepted(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 22:40:22 +02:00
|
|
|
|
|
|
|
if (!event->isAccepted()) {
|
|
|
|
foreach (const QString &format, formats) {
|
|
|
|
KPluginInfo::List wallpaperList = Wallpaper::listWallpaperInfoForMimetype(format);
|
|
|
|
if (!wallpaperList.isEmpty()) {
|
|
|
|
event->setAccepted(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-03-11 15:41:37 +01:00
|
|
|
|
|
|
|
if (event->isAccepted() && view()) {
|
|
|
|
showDropZone(view()->mapFromScene(event->scenePos()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsItem *item = scene()->itemAt(event->scenePos());
|
|
|
|
event->setAccepted(item == this || !item);
|
2009-03-11 15:41:37 +01:00
|
|
|
Plasma::Containment *c = containment();
|
|
|
|
if (c && c->immutability() == Plasma::Mutable &&
|
|
|
|
(event->mimeData()->hasFormat(static_cast<Plasma::Corona*>(scene())->appletMimeType()) ||
|
|
|
|
KUrl::List::canDecode(event->mimeData())) && view()) {
|
|
|
|
showDropZone(view()->mapFromScene(event->scenePos()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2009-05-05 07:19:35 +02:00
|
|
|
if (isContainment()) {
|
2009-08-18 00:31:03 +02:00
|
|
|
d->dropData(event->scenePos(), event->screenPos(), event);
|
2009-05-05 07:19:35 +02:00
|
|
|
} else {
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet::dropEvent(event);
|
2009-05-05 07:19:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:03 +02:00
|
|
|
void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsSceneDragDropEvent *dropEvent)
|
2009-05-05 07:19:35 +02:00
|
|
|
{
|
|
|
|
if (q->immutability() != Mutable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:03 +02:00
|
|
|
QPointF pos = q->mapFromScene(scenePos);
|
2009-06-16 19:46:32 +02:00
|
|
|
const QMimeData *mimeData = 0;
|
2009-05-05 07:19:35 +02:00
|
|
|
|
|
|
|
if (dropEvent) {
|
|
|
|
mimeData = dropEvent->mimeData();
|
2009-08-18 00:31:03 +02:00
|
|
|
} else {
|
2009-05-05 07:19:35 +02:00
|
|
|
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?
|
2009-06-16 19:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mimeData) {
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
//Selection is either empty or not supported on this OS
|
2009-06-16 19:46:32 +02:00
|
|
|
kDebug() << "no mime data";
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
//kDebug() << event->mimeData()->text();
|
|
|
|
|
|
|
|
QString appletMimetype(q->corona() ? q->corona()->appletMimeType() : QString());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
if (!appletMimetype.isEmpty() && mimeData->hasFormat(appletMimetype)) {
|
|
|
|
QString data = mimeData->data(appletMimetype);
|
2009-07-06 13:49:01 +02:00
|
|
|
const QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (const QString &appletName, appletNames) {
|
|
|
|
//kDebug() << "doing" << appletName;
|
2009-08-18 00:31:03 +02:00
|
|
|
QRectF geom(pos, QSize(0, 0));
|
2009-05-05 07:19:35 +02:00
|
|
|
q->addApplet(appletName, QVariantList(), geom);
|
|
|
|
}
|
|
|
|
if (dropEvent) {
|
|
|
|
dropEvent->acceptProposedAction();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-05-05 07:19:35 +02:00
|
|
|
} else if (mimeData->hasFormat(ExtenderItemMimeData::mimeType())) {
|
2009-02-09 19:10:45 +01:00
|
|
|
kDebug() << "mimetype plasma/extenderitem is dropped, creating internal:extender";
|
|
|
|
//Handle dropping extenderitems.
|
2009-05-05 07:19:35 +02:00
|
|
|
const ExtenderItemMimeData *extenderData = qobject_cast<const ExtenderItemMimeData*>(mimeData);
|
|
|
|
if (extenderData) {
|
|
|
|
ExtenderItem *item = extenderData->extenderItem();
|
|
|
|
QRectF geometry(pos, item->size());
|
2009-02-09 19:10:45 +01:00
|
|
|
kDebug() << "desired geometry: " << geometry;
|
2009-05-05 07:19:35 +02:00
|
|
|
Applet *applet = q->addApplet("internal:extender", QVariantList(), geometry);
|
2009-02-09 19:10:45 +01:00
|
|
|
item->setExtender(applet->extender());
|
|
|
|
}
|
2009-09-12 03:44:01 +02:00
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
} else if (KUrl::List::canDecode(mimeData)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//TODO: collect the mimetypes of available script engines and offer
|
|
|
|
// to create widgets out of the matching URLs, if any
|
2009-07-06 13:49:01 +02:00
|
|
|
const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (const KUrl &url, urls) {
|
2009-09-22 17:29:08 +02:00
|
|
|
if (AccessManager::supportedProtocols().contains(url.protocol())) {
|
|
|
|
AccessAppletJob *job = AccessManager::self()->accessRemoteApplet(url);
|
|
|
|
dropPoints[job] = dropEvent->scenePos();
|
|
|
|
QObject::connect(AccessManager::self(), SIGNAL(finished(Plasma::AccessAppletJob*)),
|
|
|
|
q, SLOT(remoteAppletReady(Plasma::AccessAppletJob*)));
|
|
|
|
} else {
|
|
|
|
KMimeType::Ptr mime = KMimeType::findByUrl(url);
|
|
|
|
QString mimeName = mime->name();
|
|
|
|
QRectF geom(pos, QSize());
|
|
|
|
QVariantList args;
|
|
|
|
args << url.url();
|
|
|
|
kDebug() << "can decode" << mimeName << args;
|
|
|
|
kDebug() << "protocol:" << url.protocol();
|
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(mimeName);
|
|
|
|
KPluginInfo::List wallpaperList;
|
|
|
|
if (q->drawWallpaper()) {
|
|
|
|
wallpaperList = Wallpaper::listWallpaperInfoForMimetype(mimeName);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-22 17:29:08 +02:00
|
|
|
// It may be a directory or a file, let's stat
|
|
|
|
KIO::JobFlags flags = KIO::HideProgressInfo;
|
|
|
|
KIO::TransferJob *job = KIO::get(url, KIO::NoReload, flags);
|
|
|
|
dropPoints[job] = dropEvent->scenePos();
|
|
|
|
QObject::connect(job, SIGNAL(mimetype(KIO::Job *, const QString&)),
|
|
|
|
q, SLOT(mimeTypeRetrieved(KIO::Job *, const QString&)));
|
|
|
|
|
|
|
|
KMenu *choices = new KMenu("Content dropped");
|
|
|
|
choices->addAction(KIcon("process-working"), i18n("Fetching file type..."));
|
|
|
|
choices->popup(dropEvent->screenPos());
|
|
|
|
dropMenus[job] = choices;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-06-16 19:46:32 +02:00
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
if (dropEvent) {
|
|
|
|
dropEvent->acceptProposedAction();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-05-05 07:19:35 +02:00
|
|
|
QStringList formats = mimeData->formats();
|
2008-11-04 00:08:39 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 01:22:48 +02:00
|
|
|
//kDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QString selectedPlugin;
|
|
|
|
|
|
|
|
if (seenPlugins.isEmpty()) {
|
2009-06-16 19:46:32 +02:00
|
|
|
// do nothing
|
|
|
|
} else if (seenPlugins.count() == 1) {
|
2008-11-04 00:08:39 +01:00
|
|
|
selectedPlugin = seenPlugins.constBegin().key();
|
|
|
|
} else {
|
2009-09-12 03:44:01 +02:00
|
|
|
KMenu choices;
|
2008-11-04 00:08:39 +01:00
|
|
|
QHash<QAction *, QString> actionsToPlugins;
|
|
|
|
foreach (const KPluginInfo &info, seenPlugins) {
|
|
|
|
QAction *action;
|
|
|
|
if (!info.icon().isEmpty()) {
|
|
|
|
action = choices.addAction(KIcon(info.icon()), info.name());
|
|
|
|
} else {
|
|
|
|
action = choices.addAction(info.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
actionsToPlugins.insert(action, info.pluginName());
|
|
|
|
}
|
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
QAction *choice = choices.exec(screenPos);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (choice) {
|
|
|
|
selectedPlugin = actionsToPlugins[choice];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedPlugin.isEmpty()) {
|
|
|
|
KTemporaryFile tempFile;
|
|
|
|
if (tempFile.open()) {
|
|
|
|
//TODO: what should we do with files after the applet is done with them??
|
|
|
|
tempFile.setAutoRemove(false);
|
|
|
|
|
|
|
|
{
|
|
|
|
QDataStream stream(&tempFile);
|
2009-05-05 07:19:35 +02:00
|
|
|
QByteArray data = mimeData->data(pluginFormats[selectedPlugin]);
|
2008-11-04 00:08:39 +01:00
|
|
|
stream.writeRawData(data, data.size());
|
|
|
|
}
|
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
QRectF geom(pos, QSize());
|
2008-11-04 00:08:39 +01:00
|
|
|
QVariantList args;
|
|
|
|
args << tempFile.fileName();
|
|
|
|
kDebug() << args;
|
|
|
|
tempFile.close();
|
|
|
|
|
2009-05-05 07:19:35 +02:00
|
|
|
q->addApplet(selectedPlugin, args, geom);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-12 04:38:10 +02:00
|
|
|
void ContainmentPrivate::clearDataForMimeJob(KIO::Job *job)
|
|
|
|
{
|
|
|
|
dropPoints.remove(job);
|
|
|
|
KMenu *choices = dropMenus.take(job);
|
|
|
|
if (choices) {
|
|
|
|
delete choices;
|
|
|
|
}
|
|
|
|
job->kill();
|
|
|
|
}
|
|
|
|
|
2009-09-22 17:29:08 +02:00
|
|
|
void ContainmentPrivate::remoteAppletReady(Plasma::AccessAppletJob *job)
|
|
|
|
{
|
|
|
|
QPointF pos = dropPoints.take(job);
|
|
|
|
if (job->error()) {
|
|
|
|
//TODO: nice user visible error handling (knotification probably?)
|
|
|
|
kDebug() << "remote applet access failed: " << job->errorText();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!job->applet()) {
|
|
|
|
kDebug() << "how did we end up here? if applet is null, the job->error should be nonzero";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
q->addApplet(job->applet(), pos);
|
|
|
|
}
|
|
|
|
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
void ContainmentPrivate::mimeTypeRetrieved(KIO::Job * job, const QString &mimetype)
|
|
|
|
{
|
|
|
|
kDebug() << "Mimetype Job returns." << mimetype;
|
|
|
|
if (job->error()) {
|
|
|
|
// TODO: error feedback
|
2009-09-12 04:38:10 +02:00
|
|
|
clearDataForMimeJob(job);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
kDebug() << "ERROR" << job->error() << ' ' << job->errorString();
|
2009-09-12 04:38:10 +02:00
|
|
|
return;
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
} else {
|
|
|
|
KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
|
|
|
|
if (!tjob) {
|
|
|
|
kDebug() << "job should be a TransferJob, but isn't";
|
2009-09-12 04:38:10 +02:00
|
|
|
clearDataForMimeJob(job);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-09-12 04:38:10 +02:00
|
|
|
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
QPointF posi; // will be overwritten with the event's position
|
2009-09-12 04:38:10 +02:00
|
|
|
if (dropPoints.keys().contains(tjob)) {
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
posi = dropPoints[tjob];
|
|
|
|
kDebug() << "Received a suitable dropEvent at" << posi;
|
2009-09-12 04:38:10 +02:00
|
|
|
} else {
|
|
|
|
kDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob";
|
|
|
|
clearDataForMimeJob(job);
|
|
|
|
return;
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
}
|
2009-09-12 04:38:10 +02:00
|
|
|
|
|
|
|
KMenu *choices = dropMenus.value(tjob);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
if (!choices) {
|
|
|
|
kDebug() << "Bailing out. No QMenu found for this job.";
|
2009-09-12 04:38:10 +02:00
|
|
|
clearDataForMimeJob(job);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariantList args;
|
|
|
|
args << tjob->url().url() << mimetype;
|
|
|
|
|
|
|
|
kDebug() << "Creating menu for:" << mimetype << posi << args;
|
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(mimetype);
|
2009-09-12 03:44:01 +02:00
|
|
|
|
|
|
|
KPluginInfo::List wallpaperList;
|
|
|
|
if (q->drawWallpaper()) {
|
|
|
|
wallpaperList = Wallpaper::listWallpaperInfoForMimetype(mimetype);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!appletList.isEmpty() || !wallpaperList.isEmpty()) {
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
choices->clear();
|
2009-09-12 03:44:01 +02:00
|
|
|
QHash<QAction *, QString> actionsToApplets;
|
2009-09-12 05:48:56 +02:00
|
|
|
choices->addTitle(i18n("Widgets"));
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
foreach (const KPluginInfo &info, appletList) {
|
|
|
|
kDebug() << info.name();
|
|
|
|
QAction *action;
|
|
|
|
if (!info.icon().isEmpty()) {
|
|
|
|
action = choices->addAction(KIcon(info.icon()), info.name());
|
|
|
|
} else {
|
|
|
|
action = choices->addAction(info.name());
|
|
|
|
}
|
|
|
|
|
2009-09-12 03:44:01 +02:00
|
|
|
actionsToApplets.insert(action, info.pluginName());
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
kDebug() << info.pluginName();
|
|
|
|
}
|
2009-09-12 03:44:01 +02:00
|
|
|
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(KIcon(info.icon()), info.name());
|
|
|
|
} else {
|
|
|
|
action = choices->addAction(info.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
actionsToWallpapers.insert(action, info.pluginName());
|
|
|
|
}
|
|
|
|
}
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
tjob->putOnHold();
|
|
|
|
KIO::Scheduler::publishSlaveOnHold();
|
|
|
|
|
2009-09-12 03:44:01 +02:00
|
|
|
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();
|
|
|
|
emit wallpaper->urlDropped(tjob->url());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addApplet(actionsToApplets[choice], args, QRectF(posi, QSize()));
|
|
|
|
}
|
2009-09-12 04:38:10 +02:00
|
|
|
|
|
|
|
clearDataForMimeJob(job);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we can at least create an icon as a link to the URL
|
|
|
|
addApplet("icon", args, QRectF(posi, QSize()));
|
|
|
|
}
|
|
|
|
}
|
2009-09-12 04:38:10 +02:00
|
|
|
|
|
|
|
clearDataForMimeJob(job);
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 21:49:42 +01:00
|
|
|
const QGraphicsItem *Containment::toolBoxItem() const
|
|
|
|
{
|
|
|
|
return d->toolBox;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
|
|
|
Applet::resizeEvent(event);
|
2009-02-19 20:50:19 +01:00
|
|
|
|
|
|
|
if (!ContainmentPrivate::s_positioning) {
|
|
|
|
switch (d->type) {
|
|
|
|
case Containment::PanelContainment:
|
|
|
|
case Containment::CustomPanelContainment:
|
|
|
|
d->positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d->positionContainments();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->wallpaper) {
|
2009-03-26 20:14:58 +01:00
|
|
|
d->wallpaper->setBoundingRect(QRectF(QPointF(0, 0), size()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
//kDebug() << "keyPressEvent with" << event->key()
|
|
|
|
// << "and hoping and wishing for a" << Qt::Key_Tab;
|
|
|
|
if (event->key() == Qt::Key_Tab) { // && event->modifiers() == 0) {
|
|
|
|
if (!d->applets.isEmpty()) {
|
|
|
|
kDebug() << "let's give focus to...." << (QObject*)d->applets.first();
|
|
|
|
d->applets.first()->setFocus(Qt::TabFocusReason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|
|
|
{
|
2009-08-18 00:31:18 +02:00
|
|
|
event->ignore();
|
2009-08-30 20:52:05 +02:00
|
|
|
if (d->appletAt(event->scenePos())) {
|
2009-08-18 00:31:18 +02:00
|
|
|
return; //no unexpected click-throughs
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString trigger = ContainmentActions::eventToString(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (d->actionPlugins.contains(trigger)) {
|
|
|
|
if (d->prepareContainmentActions(trigger, event->screenPos())) {
|
|
|
|
d->actionPlugins.value(trigger)->contextEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-08-18 00:30:34 +02:00
|
|
|
event->accept();
|
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:34 +02:00
|
|
|
if (d->wallpaper && d->wallpaper->isInitialized()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QGraphicsItem *item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
2009-08-18 00:30:34 +02:00
|
|
|
event->ignore();
|
|
|
|
d->wallpaper->wheelEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-08-18 00:30:34 +02:00
|
|
|
if (event->isAccepted()) {
|
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event->ignore();
|
|
|
|
Applet::wheelEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
|
|
|
|
|
|
|
|
// Otherwise we're watching something we shouldn't be...
|
|
|
|
Q_ASSERT(applet != 0);
|
|
|
|
if (!d->applets.contains(applet)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "got sceneEvent";
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::GraphicsSceneHoverEnter:
|
|
|
|
//kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
|
|
|
|
if (immutability() == Mutable && applet->immutability() == Mutable) {
|
|
|
|
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
2008-11-11 01:57:08 +01:00
|
|
|
if (d->handles.contains(applet)) {
|
|
|
|
AppletHandle *handle = d->handles.value(applet);
|
|
|
|
if (handle) {
|
|
|
|
handle->setHoverPos(he->pos());
|
|
|
|
}
|
|
|
|
} else {
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << "generated applet handle";
|
|
|
|
AppletHandle *handle = new AppletHandle(this, applet, he->pos());
|
|
|
|
d->handles[applet] = handle;
|
|
|
|
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
|
|
|
this, SLOT(handleDisappeared(AppletHandle*)));
|
|
|
|
connect(applet, SIGNAL(geometryChanged()),
|
|
|
|
handle, SLOT(appletResized()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-02-19 20:43:52 +01:00
|
|
|
case QEvent::GraphicsSceneHoverMove:
|
|
|
|
if (immutability() == Mutable && applet->immutability() == Mutable) {
|
|
|
|
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
|
|
|
if (d->handles.contains(applet)) {
|
|
|
|
AppletHandle *handle = d->handles.value(applet);
|
|
|
|
if (handle) {
|
|
|
|
handle->setHoverPos(he->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
//FIXME if the applet is moved to another containment we need to unfocus it
|
|
|
|
|
2008-11-25 01:23:43 +01:00
|
|
|
if (isContainment() && !ContainmentPrivate::s_positioning &&
|
2009-02-16 23:11:24 +01:00
|
|
|
(change == QGraphicsItem::ItemSceneHasChanged || change == QGraphicsItem::ItemPositionHasChanged)) {
|
|
|
|
switch (d->type) {
|
|
|
|
case PanelContainment:
|
|
|
|
case CustomPanelContainment:
|
|
|
|
d->positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d->positionContainments();
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-16 23:11:24 +01:00
|
|
|
return Applet::itemChange(change, value);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::enableAction(const QString &name, bool enable)
|
|
|
|
{
|
|
|
|
QAction *action = this->action(name);
|
|
|
|
if (action) {
|
|
|
|
action->setEnabled(enable);
|
|
|
|
action->setVisible(enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::addToolBoxAction(QAction *action)
|
|
|
|
{
|
2009-03-06 02:41:01 +01:00
|
|
|
if (!d->toolBox && (d->type == CustomPanelContainment || d->type >= CustomContainment)) {
|
|
|
|
d->createToolBox();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->addTool(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::removeToolBoxAction(QAction *action)
|
|
|
|
{
|
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->removeTool(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setToolBoxOpen(bool open)
|
|
|
|
{
|
|
|
|
if (open) {
|
|
|
|
openToolBox();
|
|
|
|
} else {
|
|
|
|
closeToolBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::openToolBox()
|
|
|
|
{
|
2009-04-24 21:27:58 +02:00
|
|
|
if (d->toolBox && !d->toolBox->showing()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->toolBox->showToolBox();
|
2009-04-24 21:27:58 +02:00
|
|
|
emit toolBoxVisibilityChanged(true);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::closeToolBox()
|
|
|
|
{
|
2009-04-24 21:27:58 +02:00
|
|
|
if (d->toolBox && d->toolBox->showing()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->toolBox->hideToolBox();
|
2009-04-24 21:27:58 +02:00
|
|
|
emit toolBoxVisibilityChanged(false);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::addAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
Applet::addAssociatedWidget(widget);
|
|
|
|
if (d->focusedApplet) {
|
|
|
|
d->focusedApplet->addAssociatedWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const Applet *applet, d->applets) {
|
|
|
|
if (applet->d->activationAction) {
|
|
|
|
widget->addAction(applet->d->activationAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::removeAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
Applet::removeAssociatedWidget(widget);
|
|
|
|
if (d->focusedApplet) {
|
|
|
|
d->focusedApplet->removeAssociatedWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const Applet *applet, d->applets) {
|
|
|
|
if (applet->d->activationAction) {
|
|
|
|
widget->removeAction(applet->d->activationAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setDrawWallpaper(bool drawWallpaper)
|
|
|
|
{
|
|
|
|
d->drawWallpaper = drawWallpaper;
|
|
|
|
if (drawWallpaper) {
|
|
|
|
KConfigGroup cfg = config();
|
2009-07-06 13:49:01 +02:00
|
|
|
const QString wallpaper = cfg.readEntry("wallpaperplugin", defaultWallpaper);
|
|
|
|
const QString mode = cfg.readEntry("wallpaperpluginmode", defaultWallpaperMode);
|
2008-11-04 00:08:39 +01:00
|
|
|
setWallpaper(wallpaper, mode);
|
|
|
|
} else {
|
|
|
|
delete d->wallpaper;
|
|
|
|
d->wallpaper = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::drawWallpaper()
|
|
|
|
{
|
|
|
|
return d->drawWallpaper;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setWallpaper(const QString &pluginName, const QString &mode)
|
|
|
|
{
|
|
|
|
KConfigGroup cfg = config();
|
|
|
|
bool newPlugin = true;
|
|
|
|
bool newMode = true;
|
|
|
|
|
|
|
|
if (d->drawWallpaper) {
|
|
|
|
if (d->wallpaper) {
|
|
|
|
// we have a wallpaper, so let's decide whether we need to swap it out
|
|
|
|
if (d->wallpaper->pluginName() != pluginName) {
|
|
|
|
delete d->wallpaper;
|
|
|
|
d->wallpaper = 0;
|
|
|
|
} else {
|
|
|
|
// it's the same plugin, so let's save its state now so when
|
|
|
|
// we call restore later on we're safe
|
|
|
|
newMode = d->wallpaper->renderingMode().name() != mode;
|
|
|
|
newPlugin = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pluginName.isEmpty() && !d->wallpaper) {
|
|
|
|
d->wallpaper = Plasma::Wallpaper::load(pluginName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->wallpaper) {
|
2009-05-17 20:23:31 +02:00
|
|
|
d->wallpaper->setParent(this);
|
2009-03-26 20:14:58 +01:00
|
|
|
d->wallpaper->setBoundingRect(QRectF(QPointF(0, 0), size()));
|
2008-11-04 00:08:39 +01:00
|
|
|
d->wallpaper->setRenderingMode(mode);
|
|
|
|
|
|
|
|
if (newPlugin) {
|
|
|
|
connect(d->wallpaper, SIGNAL(update(const QRectF&)),
|
|
|
|
this, SLOT(updateRect(const QRectF&)));
|
|
|
|
cfg.writeEntry("wallpaperplugin", pluginName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->wallpaper->isInitialized()) {
|
|
|
|
KConfigGroup wallpaperConfig = KConfigGroup(&cfg, "Wallpaper");
|
|
|
|
wallpaperConfig = KConfigGroup(&wallpaperConfig, pluginName);
|
|
|
|
d->wallpaper->restore(wallpaperConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newMode) {
|
|
|
|
cfg.writeEntry("wallpaperpluginmode", mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->wallpaper) {
|
|
|
|
cfg.deleteEntry("wallpaperplugin");
|
|
|
|
cfg.deleteEntry("wallpaperpluginmode");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPlugin || newMode) {
|
2009-04-02 06:15:50 +02:00
|
|
|
if (newPlugin && d->wallpaper) {
|
2009-04-23 18:38:16 +02:00
|
|
|
connect(d->wallpaper, SIGNAL(configureRequested()), this, SLOT(requestConfiguration()));
|
|
|
|
connect(d->wallpaper, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving()));
|
2009-04-02 06:15:50 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Wallpaper *Containment::wallpaper() const
|
|
|
|
{
|
|
|
|
return d->wallpaper;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void Containment::setContainmentActions(const QString &trigger, const QString &pluginName)
|
2009-08-18 00:30:34 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
KConfigGroup cfg = config();
|
|
|
|
cfg = KConfigGroup(&cfg, "ActionPlugins");
|
2009-08-18 00:30:42 +02:00
|
|
|
bool everSaved = cfg.exists();
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *plugin = 0;
|
2009-08-18 00:30:34 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (d->actionPlugins.contains(trigger)) {
|
|
|
|
plugin = d->actionPlugins.value(trigger);
|
|
|
|
if (plugin->pluginName() != pluginName) {
|
|
|
|
d->actionPlugins.remove(trigger);
|
|
|
|
delete plugin;
|
|
|
|
plugin=0;
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pluginName.isEmpty()) {
|
|
|
|
cfg.deleteEntry(trigger);
|
2009-08-18 00:31:32 +02:00
|
|
|
} else if (plugin) {
|
2009-08-18 00:31:08 +02:00
|
|
|
//it already existed, just reload config
|
2009-08-18 00:31:32 +02:00
|
|
|
if (plugin->isInitialized()) {
|
2009-08-18 00:31:08 +02:00
|
|
|
//FIXME make a truly unique config group
|
2009-08-18 00:31:37 +02:00
|
|
|
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
|
2009-08-18 00:31:32 +02:00
|
|
|
plugin->restore(pluginConfig);
|
2009-08-18 00:30:42 +02:00
|
|
|
}
|
2009-08-18 00:31:08 +02:00
|
|
|
} else {
|
2009-08-18 00:31:32 +02:00
|
|
|
plugin = ContainmentActions::load(this, pluginName);
|
|
|
|
if (plugin) {
|
2009-08-18 00:31:08 +02:00
|
|
|
cfg.writeEntry(trigger, pluginName);
|
2009-08-18 00:31:32 +02:00
|
|
|
d->actionPlugins.insert(trigger, plugin);
|
2009-08-18 00:31:08 +02:00
|
|
|
} else {
|
|
|
|
//bad plugin... gets removed. is this a feature or a bug?
|
|
|
|
cfg.deleteEntry(trigger);
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:42 +02:00
|
|
|
if (!everSaved) {
|
|
|
|
//ensure all our defaults are written out
|
|
|
|
//the disadvantage of using a group...
|
2009-08-18 00:31:32 +02:00
|
|
|
for (QHash<QString,ContainmentActions*>::const_iterator it = d->actionPlugins.constBegin(),
|
|
|
|
end = d->actionPlugins.constEnd(); it != end; ++it) {
|
|
|
|
cfg.writeEntry(it.key(), it.value()->pluginName());
|
2009-08-18 00:30:42 +02:00
|
|
|
}
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:42 +02:00
|
|
|
emit configNeedsSaving();
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QStringList Containment::containmentActionsTriggers()
|
2009-08-18 00:30:38 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
return d->actionPlugins.keys();
|
2009-08-18 00:30:38 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString Containment::containmentActions(const QString &trigger)
|
2009-08-18 00:30:38 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *c = d->actionPlugins.value(trigger);
|
2009-08-18 00:31:18 +02:00
|
|
|
return c ? c->pluginName() : QString();
|
2009-08-18 00:30:38 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Containment::setActivity(const QString &activity)
|
|
|
|
{
|
|
|
|
Context *context = d->context();
|
|
|
|
if (context->currentActivity() != activity) {
|
|
|
|
context->setCurrentActivity(activity);
|
|
|
|
|
|
|
|
foreach (Applet *a, d->applets) {
|
|
|
|
a->updateConstraints(ContextConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup c = config();
|
|
|
|
c.writeEntry("activity", activity);
|
2009-08-28 21:07:56 +02:00
|
|
|
|
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->update();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Containment::activity() const
|
|
|
|
{
|
|
|
|
return d->context()->currentActivity();
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *ContainmentPrivate::context()
|
|
|
|
{
|
|
|
|
if (!con) {
|
|
|
|
con = new Context(q);
|
|
|
|
q->connect(con, SIGNAL(changed(Plasma::Context*)),
|
|
|
|
q, SIGNAL(contextChanged(Plasma::Context*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return con;
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
KActionCollection* ContainmentPrivate::actions()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
return static_cast<Applet*>(q)->d->actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::focusApplet(Plasma::Applet *applet)
|
|
|
|
{
|
|
|
|
if (focusedApplet == applet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
QList<QWidget *> widgets = actions()->associatedWidgets();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (focusedApplet) {
|
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
focusedApplet->removeAssociatedWidget(w);
|
|
|
|
}
|
|
|
|
}
|
2009-01-04 08:59:10 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (applet && applets.contains(applet)) {
|
|
|
|
//kDebug() << "switching to" << applet->name();
|
|
|
|
focusedApplet = applet;
|
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
focusedApplet->addAssociatedWidget(w);
|
|
|
|
}
|
2009-01-04 08:59:10 +01:00
|
|
|
|
|
|
|
if (!focusedApplet->hasFocus()) {
|
|
|
|
focusedApplet->setFocus(Qt::ShortcutFocusReason);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
focusedApplet = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
kDebug() << "index" << index;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
kDebug() << "index" << index;
|
|
|
|
d->focusApplet(d->applets.at(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::destroy()
|
|
|
|
{
|
|
|
|
destroy(true);
|
|
|
|
}
|
|
|
|
|
2008-11-10 02:26:27 +01:00
|
|
|
void Containment::showConfigurationInterface()
|
|
|
|
{
|
|
|
|
Applet::showConfigurationInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::requestConfiguration()
|
|
|
|
{
|
|
|
|
emit q->configureRequested(q);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Containment::destroy(bool confirm)
|
|
|
|
{
|
2009-05-06 21:08:29 +02:00
|
|
|
if (immutability() != Mutable || Applet::d->transient) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isContainment()) {
|
|
|
|
//FIXME maybe that %1 should be the containment type not the name
|
|
|
|
if (!confirm ||
|
|
|
|
KMessageBox::warningContinueCancel(
|
|
|
|
view(),
|
|
|
|
i18nc("%1 is the name of the containment", "Do you really want to remove this %1?", name()),
|
|
|
|
i18nc("@title:window %1 is the name of the containment", "Remove %1", name()), KStandardGuiItem::remove()) == KMessageBox::Continue) {
|
|
|
|
//clearApplets();
|
|
|
|
Applet::destroy();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Applet::destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::zoomIn()
|
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomIn);
|
|
|
|
positionToolBox();
|
|
|
|
}
|
|
|
|
|
Make dropping remote content onto Plasma work
The idea is that you drop a file from a webpage, or basically a URL onto Plasma and Plasma creates a suitable applet to display this URL. For example an image frame for picture, or a previewer for pdf files. Downloading the data itself (and possibly saving it) is left to the applets. The mimetype needs to be retrieved as it cannot be determined from the URL.
The code pathes I've changed or added are, roughly:
- "something" is dropped onto Plasma
- if it's a remote URL, we don't know the mimetype of the object behind the URL yet
- a KIO::TransferJob is used to retrieve the mimetype asynchronously, and will call back
- we open a QMenu that says "Fetching file type..."
- If the user closes the menu while the mimetype is being retrieved, we will open a new one
- When the TransferJob calls back, and we have our mimetype, we offer a list of applets suitable for this kind of content
- If the user chooses to create an applet, we put the transfer job on hold to make it available for recycling by the applet
- If the user dismisses the offering, we kill the job
Thanks to marco for reviewing and everybody else for the input :)
Next steps are making some more applets work with this.
CCMAIL:plasma-devel@kde.org
svn path=/trunk/KDE/kdelibs/; revision=1009004
2009-08-09 00:01:16 +02:00
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ContainmentPrivate::zoomOut()
|
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomOut);
|
|
|
|
positionToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolBox *ContainmentPrivate::createToolBox()
|
|
|
|
{
|
|
|
|
if (!toolBox) {
|
|
|
|
switch (type) {
|
|
|
|
case Containment::PanelContainment:
|
2009-03-06 02:41:01 +01:00
|
|
|
case Containment::CustomPanelContainment:
|
2008-11-04 00:08:39 +01:00
|
|
|
toolBox = new PanelToolBox(q);
|
2009-02-15 17:35:52 +01:00
|
|
|
toolBox->setSize(KIconLoader::SizeSmallMedium);
|
|
|
|
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
|
2008-11-04 00:08:39 +01:00
|
|
|
if (q->immutability() != Mutable) {
|
|
|
|
toolBox->hide();
|
|
|
|
}
|
|
|
|
break;
|
2009-03-06 02:41:01 +01:00
|
|
|
default:
|
2008-11-04 00:08:39 +01:00
|
|
|
toolBox = new DesktopToolBox(q);
|
2009-03-05 23:15:06 +01:00
|
|
|
toolBox->setSize(KIconLoader::SizeSmallMedium);
|
|
|
|
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toolBox) {
|
|
|
|
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
|
2009-04-24 21:27:58 +02:00
|
|
|
QObject::connect(toolBox, SIGNAL(toggled()), q, SLOT(updateToolBoxVisibility()));
|
2008-11-14 08:28:02 +01:00
|
|
|
toolBox->load();
|
2008-11-04 00:08:39 +01:00
|
|
|
positionToolBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return toolBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::positionToolBox()
|
|
|
|
{
|
2008-11-14 08:28:02 +01:00
|
|
|
if (toolBox) {
|
|
|
|
toolBox->reposition();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 21:27:58 +02:00
|
|
|
void ContainmentPrivate::updateToolBoxVisibility()
|
2009-04-13 22:26:17 +02:00
|
|
|
{
|
2009-04-24 21:27:58 +02:00
|
|
|
emit q->toolBoxVisibilityChanged(toolBox->showing());
|
2009-04-13 22:26:17 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ContainmentPrivate::triggerShowAddWidgets()
|
|
|
|
{
|
|
|
|
emit q->showAddWidgetsInterface(QPointF());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::handleDisappeared(AppletHandle *handle)
|
|
|
|
{
|
|
|
|
if (handles.contains(handle->applet())) {
|
|
|
|
handles.remove(handle->applet());
|
|
|
|
handle->detachApplet();
|
2009-08-18 01:40:07 +02:00
|
|
|
if (q->scene()) {
|
|
|
|
q->scene()->removeItem(handle);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 17:54:09 +01:00
|
|
|
void ContainmentPrivate::checkRemoveAction()
|
|
|
|
{
|
2009-09-23 22:37:17 +02:00
|
|
|
q->enableAction("remove", q->immutability() == Mutable);
|
2008-12-15 17:54:09 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
if (!q->isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-11 20:53:35 +01:00
|
|
|
//kDebug() << "got containmentConstraintsEvent" << constraints << (QObject*)toolBox;
|
2008-11-04 00:08:39 +01:00
|
|
|
if (constraints & Plasma::ImmutableConstraint) {
|
|
|
|
//update actions
|
2008-12-15 17:54:09 +01:00
|
|
|
checkRemoveAction();
|
2008-11-04 00:08:39 +01:00
|
|
|
bool unlocked = q->immutability() == Mutable;
|
|
|
|
q->setAcceptDrops(unlocked);
|
2008-12-15 17:54:09 +01:00
|
|
|
q->enableAction("add widgets", unlocked);
|
2009-01-16 01:39:07 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// tell the applets too
|
|
|
|
foreach (Applet *a, applets) {
|
|
|
|
a->updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
|
2009-01-07 17:42:12 +01:00
|
|
|
if (toolBox) {
|
|
|
|
if (type == Containment::PanelContainment || type == Containment::CustomPanelContainment) {
|
|
|
|
toolBox->setVisible(unlocked);
|
|
|
|
} else {
|
|
|
|
toolBox->setIsMovable(unlocked);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-03-10 20:52:50 +01:00
|
|
|
|
|
|
|
//clear handles on lock
|
|
|
|
if (!unlocked) {
|
|
|
|
QMap<Applet*, AppletHandle*> h = handles;
|
|
|
|
handles.clear();
|
|
|
|
|
|
|
|
foreach (AppletHandle *handle, h) {
|
|
|
|
handle->disconnect(q);
|
2009-08-18 01:40:07 +02:00
|
|
|
|
|
|
|
if (q->scene()) {
|
|
|
|
q->scene()->removeItem(handle);
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:52:50 +01:00
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints & Plasma::FormFactorConstraint) {
|
|
|
|
foreach (Applet *applet, applets) {
|
|
|
|
applet->updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:16:45 +01:00
|
|
|
if (toolBox && (constraints & Plasma::SizeConstraint ||
|
|
|
|
constraints & Plasma::FormFactorConstraint ||
|
|
|
|
constraints & Plasma::ScreenConstraint ||
|
|
|
|
constraints & Plasma::StartupCompletedConstraint)) {
|
2008-12-01 13:40:08 +01:00
|
|
|
//kDebug() << "Positioning toolbox";
|
2008-11-04 00:08:39 +01:00
|
|
|
positionToolBox();
|
|
|
|
}
|
2008-12-01 13:40:08 +01:00
|
|
|
|
2009-03-13 18:07:58 +01:00
|
|
|
if (toolBox &&
|
|
|
|
constraints & Plasma::StartupCompletedConstraint &&
|
|
|
|
type < Containment::CustomContainment) {
|
2008-12-01 13:40:08 +01:00
|
|
|
toolBox->addTool(q->action("remove"));
|
2008-12-15 17:54:09 +01:00
|
|
|
checkRemoveAction();
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Applet *ContainmentPrivate::addApplet(const QString &name, const QVariantList &args,
|
|
|
|
const QRectF &appletGeometry, uint id, bool delayInit)
|
|
|
|
{
|
|
|
|
if (!q->isContainment()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!delayInit && q->immutability() != Mutable) {
|
|
|
|
kDebug() << "addApplet for" << name << "requested, but we're currently immutable!";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *v = q->view();
|
|
|
|
if (v) {
|
|
|
|
v->setCursor(Qt::BusyCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = Applet::load(name, id, args);
|
|
|
|
if (v) {
|
|
|
|
v->unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "Applet" << name << "could not be loaded.";
|
|
|
|
applet = new Applet(0, QString(), id);
|
|
|
|
applet->setFailedToLaunch(true, i18n("Could not find requested component: %1", name));
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
|
|
|
|
|
|
|
q->addApplet(applet, appletGeometry.topLeft(), delayInit);
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContainmentPrivate::regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet) const
|
|
|
|
{
|
|
|
|
foreach (Applet *applet, applets) {
|
|
|
|
if (applet != ignoredApplet && applet->geometry().intersects(region)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-28 08:58:17 +01:00
|
|
|
void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
applets.removeAll(applet);
|
|
|
|
if (focusedApplet == applet) {
|
|
|
|
focusedApplet = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handles.contains(applet)) {
|
|
|
|
AppletHandle *handle = handles.value(applet);
|
|
|
|
handles.remove(applet);
|
2009-08-18 01:40:07 +02:00
|
|
|
if (q->scene()) {
|
|
|
|
q->scene()->removeItem(handle);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit q->appletRemoved(applet);
|
|
|
|
emit q->configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
|
|
|
{
|
|
|
|
if (anim == Animator::AppearAnimation &&
|
|
|
|
item->parentItem() == q) {
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
|
|
|
|
|
|
|
if (applet) {
|
2009-01-23 08:32:11 +01:00
|
|
|
if (type == Containment::DesktopContainment) {
|
|
|
|
applet->installSceneEventFilter(q);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup *cg = applet->d->mainConfigGroup();
|
|
|
|
applet->save(*cg);
|
|
|
|
emit q->configNeedsSaving();
|
|
|
|
//applet->setWindowFlags(Qt::Window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool containmentSortByPosition(const Containment *c1, const Containment *c2)
|
|
|
|
{
|
|
|
|
return c1->id() < c2->id();
|
|
|
|
}
|
|
|
|
|
2008-11-25 01:23:43 +01:00
|
|
|
void ContainmentPrivate::positionContainments()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Corona *c = q->corona();
|
2008-11-25 01:23:43 +01:00
|
|
|
if (!c || ContainmentPrivate::s_positioning) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-25 01:23:43 +01:00
|
|
|
ContainmentPrivate::s_positioning = true;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//TODO: we should avoid running this too often; consider compressing requests
|
|
|
|
// with a timer.
|
|
|
|
QList<Containment*> containments = c->containments();
|
|
|
|
QMutableListIterator<Containment*> it(containments);
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
2009-01-23 08:32:11 +01:00
|
|
|
if (containment->d->type == Containment::PanelContainment ||
|
2009-04-07 23:22:18 +02:00
|
|
|
containment->d->type == Containment::CustomPanelContainment ||
|
|
|
|
q->corona()->offscreenWidgets().contains(containment)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// weed out all containments we don't care about at all
|
|
|
|
// e.g. Panels and ourself
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (containments.isEmpty()) {
|
2008-11-25 01:23:43 +01:00
|
|
|
ContainmentPrivate::s_positioning = false;
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qSort(containments.begin(), containments.end(), containmentSortByPosition);
|
|
|
|
it.toFront();
|
|
|
|
|
|
|
|
int column = 0;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
int rowHeight = 0;
|
|
|
|
//int count = 0;
|
|
|
|
|
|
|
|
//kDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++" << containments.count();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
containment->setPos(x, y);
|
|
|
|
//kDebug() << ++count << "setting to" << x << y;
|
|
|
|
|
|
|
|
int height = containment->size().height();
|
|
|
|
if (height > rowHeight) {
|
|
|
|
rowHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
++column;
|
|
|
|
|
|
|
|
if (column == CONTAINMENT_COLUMNS) {
|
|
|
|
column = 0;
|
|
|
|
x = 0;
|
2008-12-02 19:42:06 +01:00
|
|
|
y += rowHeight + INTER_CONTAINMENT_MARGIN + TOOLBOX_MARGIN;
|
2008-11-04 00:08:39 +01:00
|
|
|
rowHeight = 0;
|
|
|
|
} else {
|
|
|
|
x += containment->size().width() + INTER_CONTAINMENT_MARGIN;
|
|
|
|
}
|
|
|
|
//kDebug() << "column: " << column << "; x " << x << "; y" << y << "; width was"
|
|
|
|
// << containment->size().width();
|
|
|
|
}
|
|
|
|
//kDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++";
|
|
|
|
|
|
|
|
ContainmentPrivate::s_positioning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentPrivate::positionPanel(bool force)
|
|
|
|
{
|
|
|
|
if (!q->scene()) {
|
|
|
|
kDebug() << "no scene yet";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we position panels in negative coordinates, and stack all horizontal
|
|
|
|
// and all vertical panels with each other.
|
|
|
|
|
2009-02-19 20:50:19 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
const QPointF p = q->pos();
|
|
|
|
|
|
|
|
if (!force &&
|
|
|
|
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
|
|
|
|
q->scene()->collidingItems(q).isEmpty()) {
|
|
|
|
// already positioned and not running into any other panels
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
|
2009-02-24 05:54:57 +01:00
|
|
|
bool horiz = formFactor == Plasma::Horizontal;
|
2009-02-19 20:47:24 +01:00
|
|
|
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
2008-11-04 00:08:39 +01:00
|
|
|
qreal lastHeight = 0;
|
|
|
|
|
|
|
|
// this should be ok for small numbers of panels, but if we ever end
|
|
|
|
// up managing hundreds of them, this simplistic alogrithm will
|
|
|
|
// likely be too slow.
|
|
|
|
foreach (const Containment *other, q->corona()->containments()) {
|
|
|
|
if (other == q ||
|
2009-01-23 08:32:11 +01:00
|
|
|
(other->d->type != Containment::PanelContainment &&
|
|
|
|
other->d->type != Containment::CustomPanelContainment) ||
|
2008-11-04 00:08:39 +01:00
|
|
|
horiz != (other->formFactor() == Plasma::Horizontal)) {
|
|
|
|
// only line up with panels of the same orientation
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (horiz) {
|
2009-02-19 20:47:24 +01:00
|
|
|
qreal y = other->pos().y();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (y < bottom) {
|
|
|
|
lastHeight = other->size().height();
|
|
|
|
bottom = y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qreal width = other->size().width();
|
|
|
|
qreal x = other->pos().x() + width;
|
|
|
|
if (x > bottom) {
|
|
|
|
lastHeight = width;
|
|
|
|
bottom = x + lastHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kDebug() << "positioning" << (horiz ? "" : "non-") << "horizontal panel; forced?" << force;
|
|
|
|
// give a space equal to the height again of the last item so there is
|
|
|
|
// room to grow.
|
|
|
|
QPointF newPos;
|
|
|
|
if (horiz) {
|
|
|
|
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix x position for non-flush-left panels
|
|
|
|
kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
|
|
|
|
newPos = QPointF(0, bottom - q->size().height());
|
|
|
|
} else {
|
|
|
|
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix y position for non-flush-top panels
|
|
|
|
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p != newPos) {
|
2009-02-24 05:54:57 +01:00
|
|
|
ContainmentPrivate::s_positioning = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
q->setPos(newPos);
|
2009-02-24 05:54:57 +01:00
|
|
|
ContainmentPrivate::s_positioning = false;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:34 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos)
|
2009-08-18 00:30:34 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *plugin = actionPlugins.value(trigger);
|
2009-08-18 00:30:34 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!plugin->isInitialized()) {
|
|
|
|
KConfigGroup cfg = q->config();
|
|
|
|
cfg = KConfigGroup(&cfg, "ActionPlugins");
|
2009-08-18 00:31:37 +02:00
|
|
|
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
|
2009-08-18 00:31:32 +02:00
|
|
|
plugin->restore(pluginConfig);
|
2009-08-18 00:30:34 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (plugin->configurationRequired()) {
|
2009-08-18 00:30:34 +02:00
|
|
|
KMenu menu;
|
2009-08-18 00:30:58 +02:00
|
|
|
menu.addTitle(i18n("This plugin needs to be configured"));
|
|
|
|
menu.addAction(q->action("configure"));
|
2009-08-18 00:30:34 +02:00
|
|
|
menu.exec(screenPos);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "containment.moc"
|
|
|
|
|