make a class to hold a map of default containmentactions plugins
svn path=/trunk/KDE/kdelibs/; revision=1031735
This commit is contained in:
parent
6ccaa814b3
commit
cfd8409432
@ -48,6 +48,7 @@ set(plasma_LIB_SRCS
|
||||
configloader.cpp
|
||||
containment.cpp
|
||||
containmentactions.cpp
|
||||
containmentactionspluginsconfig.cpp
|
||||
context.cpp
|
||||
corona.cpp
|
||||
datacontainer.cpp
|
||||
@ -238,6 +239,7 @@ set(plasma_LIB_INCLUDES
|
||||
configloader.h
|
||||
containment.h
|
||||
containmentactions.h
|
||||
containmentactionspluginsconfig.h
|
||||
context.h
|
||||
corona.h
|
||||
datacontainer.h
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "animator.h"
|
||||
#include "context.h"
|
||||
#include "containmentactions.h"
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "corona.h"
|
||||
#include "extenderitem.h"
|
||||
#include "svg.h"
|
||||
@ -61,6 +62,7 @@
|
||||
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
#include "private/containmentactionspluginsconfig_p.h"
|
||||
#include "private/desktoptoolbox_p.h"
|
||||
#include "private/extenderitemmimedata_p.h"
|
||||
#include "private/paneltoolbox_p.h"
|
||||
@ -237,25 +239,14 @@ void Containment::init()
|
||||
foreach (const QString &key, cfg.keyList()) {
|
||||
setContainmentActions(key, cfg.readEntry(key, QString()));
|
||||
}
|
||||
} else {
|
||||
} else if (corona()){
|
||||
//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:
|
||||
defaults.insert("wheel:Vertical;NoModifier", "switchdesktop");
|
||||
defaults.insert("MidButton;NoModifier", "paste");
|
||||
defaults.insert("RightButton;NoModifier", "contextmenu");
|
||||
break;
|
||||
case PanelContainment:
|
||||
case CustomPanelContainment:
|
||||
defaults.insert("RightButton;NoModifier", "contextmenu");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig conf = corona()->containmentActionsDefaults(d->type);
|
||||
//steal the data directly, for efficiency
|
||||
QHash<QString,QString> defaults = conf.d->plugins;
|
||||
|
||||
for (QHash<QString,QString>::const_iterator it = defaults.constBegin(),
|
||||
end = defaults.constEnd(); it != end; ++it) {
|
||||
|
96
containmentactionspluginsconfig.cpp
Normal file
96
containmentactionspluginsconfig.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "private/containmentactionspluginsconfig_p.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QString>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#include "containmentactions.h"
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ContainmentActionsPluginsConfig::ContainmentActionsPluginsConfig()
|
||||
: d(new ContainmentActionsPluginsConfigPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig::ContainmentActionsPluginsConfig(const ContainmentActionsPluginsConfig &other)
|
||||
: d(new ContainmentActionsPluginsConfigPrivate(this))
|
||||
{
|
||||
d->plugins = other.d->plugins;
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig& ContainmentActionsPluginsConfig::operator=(const ContainmentActionsPluginsConfig &other)
|
||||
{
|
||||
d->plugins = other.d->plugins;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig::~ContainmentActionsPluginsConfig()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void ContainmentActionsPluginsConfig::clear()
|
||||
{
|
||||
d->plugins.clear();
|
||||
}
|
||||
|
||||
void ContainmentActionsPluginsConfig::remove(QEvent *trigger)
|
||||
{
|
||||
QString s = ContainmentActions::eventToString(trigger);
|
||||
d->plugins.remove(s);
|
||||
}
|
||||
|
||||
void ContainmentActionsPluginsConfig::addPlugin(QEvent *trigger, const QString &name)
|
||||
{
|
||||
QString s = ContainmentActions::eventToString(trigger);
|
||||
d->plugins.insert(s, name);
|
||||
}
|
||||
|
||||
void ContainmentActionsPluginsConfig::addPlugin(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, const QString &name)
|
||||
{
|
||||
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
|
||||
event.setButton(button);
|
||||
event.setModifiers(modifiers);
|
||||
QString s = ContainmentActions::eventToString(&event);
|
||||
d->plugins.insert(s, name);
|
||||
}
|
||||
|
||||
void ContainmentActionsPluginsConfig::addPlugin(Qt::KeyboardModifiers modifiers, Qt::Orientation wheelDirection, const QString &name)
|
||||
{
|
||||
QGraphicsSceneWheelEvent event(QEvent::GraphicsSceneWheel);
|
||||
event.setOrientation(wheelDirection);
|
||||
event.setModifiers(modifiers);
|
||||
QString s = ContainmentActions::eventToString(&event);
|
||||
d->plugins.insert(s, name);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
90
containmentactionspluginsconfig.h
Normal file
90
containmentactionspluginsconfig.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CONTAINMENTACTIONSPLUGINSCONFIG_H
|
||||
#define PLASMA_CONTAINMENTACTIONSPLUGINSCONFIG_H
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
#include <Qt>
|
||||
|
||||
class QString;
|
||||
class QEvent;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ContainmentActionsPluginsConfigPrivate;
|
||||
|
||||
/**
|
||||
* @class ContainmentActionsPluginsConfig plasma/containmentactionspluginsconfig.h <Plasma/ContainmentActionsPluginsConfig>
|
||||
*
|
||||
* @short A class that holds a map of triggers to plugin names
|
||||
* @since 4.4
|
||||
*/
|
||||
class PLASMA_EXPORT ContainmentActionsPluginsConfig
|
||||
{
|
||||
|
||||
public:
|
||||
ContainmentActionsPluginsConfig();
|
||||
ContainmentActionsPluginsConfig(const ContainmentActionsPluginsConfig &other);
|
||||
~ContainmentActionsPluginsConfig();
|
||||
ContainmentActionsPluginsConfig& operator=(const ContainmentActionsPluginsConfig &other);
|
||||
|
||||
/**
|
||||
* clears everything
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* removes @p trigger
|
||||
* @see addPlugin for an explanation of the @p trigger
|
||||
*/
|
||||
void remove(QEvent *trigger);
|
||||
|
||||
/**
|
||||
* Sets @p trigger to plugin @p name
|
||||
* if you're passing the trigger as an event, the following events are currently understood:
|
||||
* -mouse press and release events: button and modifiers
|
||||
* -mouse wheel events: direction and modifiers
|
||||
* both traditional and graphicsscene events are supported.
|
||||
*/
|
||||
void addPlugin(QEvent *trigger, const QString &name);
|
||||
|
||||
/**
|
||||
* Sets trigger described by @p modifiers and @p button to plugin @p name
|
||||
*/
|
||||
void addPlugin(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, const QString &name);
|
||||
|
||||
/**
|
||||
* Sets trigger described by @p modifiers and @p wheelDirection to plugin @p name
|
||||
*/
|
||||
void addPlugin(Qt::KeyboardModifiers modifiers, Qt::Orientation wheelDirection, const QString &name);
|
||||
|
||||
private:
|
||||
ContainmentActionsPluginsConfigPrivate *const d;
|
||||
|
||||
friend class ContainmentActionsPluginsConfigPrivate;
|
||||
friend class Containment;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
12
corona.cpp
12
corona.cpp
@ -41,6 +41,7 @@
|
||||
#include <kshortcutsdialog.h>
|
||||
|
||||
#include "containment.h"
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "view.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/containment_p.h"
|
||||
@ -254,6 +255,7 @@ public:
|
||||
QHash<uint, QGraphicsWidget*> offscreenWidgets;
|
||||
KActionCollection actions;
|
||||
KShortcutsDialog shortcutsDlg;
|
||||
QMap<Containment::Type, ContainmentActionsPluginsConfig> containmentActionsDefaults;
|
||||
};
|
||||
|
||||
Corona::Corona(QObject *parent)
|
||||
@ -762,6 +764,16 @@ void Corona::addShortcuts(KActionCollection *newShortcuts)
|
||||
d->shortcutsDlg.addCollection(newShortcuts);
|
||||
}
|
||||
|
||||
void Corona::setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config)
|
||||
{
|
||||
d->containmentActionsDefaults.insert(containmentType, config);
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig Corona::containmentActionsDefaults(Containment::Type containmentType)
|
||||
{
|
||||
return d->containmentActionsDefaults.value(containmentType);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "corona.moc"
|
||||
|
15
corona.h
15
corona.h
@ -24,6 +24,7 @@
|
||||
#include <QtGui/QGraphicsScene>
|
||||
|
||||
#include <plasma/applet.h>
|
||||
#include <plasma/containment.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
@ -35,8 +36,8 @@ class KAction;
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Containment;
|
||||
class CoronaPrivate;
|
||||
class ContainmentActionsPluginsConfig;
|
||||
|
||||
/**
|
||||
* @class Corona plasma/corona.h <Plasma/Corona>
|
||||
@ -223,6 +224,18 @@ public:
|
||||
*/
|
||||
KAction* addAction(QString name);
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
* Sets the default containmentactions plugins for the given containment type
|
||||
*/
|
||||
void setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config);
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
* Returns the default containmentactions plugins for the given containment type
|
||||
*/
|
||||
ContainmentActionsPluginsConfig containmentActionsDefaults(Containment::Type containmentType);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Initializes the layout from a config file. This will first clear any existing
|
||||
|
47
private/containmentactionspluginsconfig_p.h
Normal file
47
private/containmentactionspluginsconfig_p.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CONTAINMENTACTIONSPLUGINSCONFIGPRIVATE_H
|
||||
#define PLASMA_CONTAINMENTACTIONSPLUGINSCONFIGPRIVATE_H
|
||||
|
||||
#include <QHash>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ContainmentActionsPluginsConfigPrivate
|
||||
{
|
||||
public:
|
||||
ContainmentActionsPluginsConfigPrivate(ContainmentActionsPluginsConfig *config)
|
||||
: q(config)
|
||||
{
|
||||
}
|
||||
|
||||
~ContainmentActionsPluginsConfigPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
ContainmentActionsPluginsConfig *q;
|
||||
//map trigger -> pluginname
|
||||
QHash<QString, QString> plugins;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user