containmentActions logic is in ContainmentInterface

a copy is still in Containment, will be cleaned in next commit
This commit is contained in:
Marco Martin 2013-02-19 11:52:51 +01:00
parent 6941264229
commit ca799b08bf
8 changed files with 125 additions and 32 deletions

View File

@ -219,21 +219,21 @@ void Containment::restore(KConfigGroup &group)
//don't let global desktop actions conflict with panels
//this also prevents panels from sharing config with each other
//but the panels aren't configurable anyways, and I doubt that'll change.
d->containmentActionsSource = ContainmentPrivate::Local;
d->containmentActionsSource = ContainmentActions::Local;
cfg = KConfigGroup(&group, "ActionPlugins");
} else {
const QString source = group.readEntry("ActionPluginsSource", QString());
if (source == "Global") {
cfg = KConfigGroup(corona()->config(), "ActionPlugins");
d->containmentActionsSource = ContainmentPrivate::Global;
d->containmentActionsSource = ContainmentActions::Global;
} else if (source == "Activity") {
cfg = KConfigGroup(corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, d->activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins");
d->containmentActionsSource = ContainmentPrivate::Activity;
d->containmentActionsSource = ContainmentActions::Activity;
} else if (source == "Local") {
cfg = group;
d->containmentActionsSource = ContainmentPrivate::Local;
d->containmentActionsSource = ContainmentActions::Local;
} else {
//default to global
//but, if there is no global config, try copying it from local.
@ -241,7 +241,7 @@ void Containment::restore(KConfigGroup &group)
if (!cfg.exists()) {
cfg = KConfigGroup(&group, "ActionPlugins");
}
d->containmentActionsSource = ContainmentPrivate::Global;
d->containmentActionsSource = ContainmentActions::Global;
group.writeEntry("ActionPluginsSource", "Global");
}
}
@ -643,9 +643,9 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
plugin->setContainment(0);
} else {
switch (d->containmentActionsSource) {
case ContainmentPrivate::Activity:
case ContainmentActions::Activity:
//FIXME
case ContainmentPrivate::Local:
case ContainmentActions::Local:
plugin = PluginLoader::self()->loadContainmentActions(this, pluginName);
break;
default:
@ -654,6 +654,7 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
if (plugin) {
cfg.writeEntry(trigger, pluginName);
plugin->setSource(d->containmentActionsSource);
d->actionPlugins()->insert(trigger, plugin);
} else {
//bad plugin... gets removed. is this a feature or a bug?
@ -667,9 +668,9 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
QHash<QString, ContainmentActions*> Containment::containmentActions()
{
switch (d->containmentActionsSource) {
case ContainmentPrivate::Activity:
case ContainmentActions::Activity:
//FIXME
case ContainmentPrivate::Local:
case ContainmentActions::Local:
return d->localActionPlugins;
default:
return d->globalActionPlugins;

View File

@ -34,13 +34,9 @@
namespace Plasma
{
class AccessAppletJob;
class AppletHandle;
class DataEngine;
class Package;
class Corona;
class View;
class Wallpaper;
class ContainmentActions;
class ContainmentPrivate;

View File

@ -102,6 +102,39 @@ QString ContainmentActions::pluginName() const
return d->containmentActionsDescription.pluginName();
}
void ContainmentActions::setSource(ContainmentActionsSource source)
{
d->containmentActionsSource = source;
}
ContainmentActions::ContainmentActionsSource ContainmentActions::source() const
{
return d->containmentActionsSource;
}
KConfigGroup ContainmentActions::config() const
{
KConfigGroup cfg;
if (!d->containment) {
return cfg;
}
switch (d->containmentActionsSource) {
case Local:
cfg = d->containment->config();
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
case Activity:
cfg = KConfigGroup(d->containment->corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, d->containment->activity());
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
default:
cfg = KConfigGroup(d->containment->corona()->config(), "ActionPlugins");
}
return cfg;
}
void ContainmentActions::restore(const KConfigGroup &config)
{
init(config);
@ -211,7 +244,8 @@ QString ContainmentActions::eventToString(QEvent *event)
return trigger;
}
void ContainmentActions::setContainment(Containment *newContainment) {
void ContainmentActions::setContainment(Containment *newContainment)
{
d->containment = newContainment;
}

View File

@ -60,6 +60,18 @@ class PLASMA_EXPORT ContainmentActions : public QObject
Q_PROPERTY(bool configurationRequired READ configurationRequired NOTIFY configurationRequiredChanged)
public:
/**
* Where the actions come from.
* Containments can use a global set of actions or a personalized set,
* with granularity to Activity or Containment
*/
enum ContainmentActionsSource {
Global = 0,
Activity,
Local
};
Q_ENUMS(ContainmentActionsSource)
/**
* Default constructor for an empty or null containmentactions
*/
@ -85,6 +97,25 @@ class PLASMA_EXPORT ContainmentActions : public QObject
**/
QString icon() const;
/**
* Returns the configurations of this containmentactions
* @since 5.0
*/
KConfigGroup config() const;
/**
* Sets the source, for this containmentactions Global, Activity or Local
* @param source @see ContainmentActionsSource
* @since 5.0
*/
void setSource(ContainmentActionsSource source);
/**
* @return the source of this containmentactions
* @since 5.0
*/
ContainmentActionsSource source() const;
/**
* This method should be called once the plugin is loaded or settings are changed.
* @param config Config group to load settings

View File

@ -394,11 +394,11 @@ KConfigGroup ContainmentPrivate::containmentActionsConfig() const
{
KConfigGroup cfg;
switch (containmentActionsSource) {
case ContainmentPrivate::Local:
case ContainmentActions::Local:
cfg = q->config();
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
case ContainmentPrivate::Activity:
case ContainmentActions::Activity:
cfg = KConfigGroup(q->corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins");
@ -456,9 +456,9 @@ bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const
QHash<QString, ContainmentActions*> * ContainmentPrivate::actionPlugins()
{
switch (containmentActionsSource) {
case Activity:
case ContainmentActions::Activity:
//FIXME
case Local:
case ContainmentActions::Local:
return &localActionPlugins;
default:
return &globalActionPlugins;

View File

@ -27,6 +27,7 @@
#include "plasma.h"
#include "applet.h"
#include "corona.h"
#include "containmentactions.h"
static const int INTER_CONTAINMENT_MARGIN = 6;
static const int CONTAINMENT_COLUMNS = 2;
@ -55,7 +56,7 @@ public:
screen(-1), // no screen
type(Containment::NoContainmentType),
drawWallpaper(false),
containmentActionsSource(Global)
containmentActionsSource(ContainmentActions::Global)
{
}
@ -134,12 +135,7 @@ public:
Containment::Type type;
bool drawWallpaper : 1;
enum ContainmentActionsSource {
Global = 0,
Activity,
Local
};
ContainmentActionsSource containmentActionsSource;
ContainmentActions::ContainmentActionsSource containmentActionsSource;
static QHash<QString, ContainmentActions*> globalActionPlugins;
static const char defaultWallpaper[];
static const char defaultWallpaperMode[];

View File

@ -33,11 +33,15 @@ public:
containmentActionsDescription(service),
package(0),
containment(0),
needsConfig(false)
needsConfig(false),
containmentActionsSource(ContainmentActions::Global)
{
};
ContainmentActions *q;
ContainmentActions::ContainmentActionsSource containmentActionsSource;
QString currentTrigger;
KPluginInfo containmentActionsDescription;
Package *package;
KServiceAction mode;

View File

@ -28,6 +28,7 @@
#include <KDebug>
#include <KLocalizedString>
#include <Plasma/ContainmentActions>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <Plasma/PluginLoader>
@ -315,12 +316,42 @@ void ContainmentInterface::addContainmentActions(KMenu &desktopMenu, QEvent *eve
return;
}
//STUB
desktopMenu.addAction("Containment Menu Item 1");
desktopMenu.addAction("Containment Menu Item 2");
//TODO: reenable ContainmentActions plugins
/*const QString trigger = ContainmentActions::eventToString(event);
prepareContainmentActions(trigger, QPoint(), &desktopMenu);*/
//this is what ContainmentPrivate::prepareContainmentActions was
const QString trigger = Plasma::ContainmentActions::eventToString(event);
Plasma::ContainmentActions *plugin = containment()->containmentActions().value(trigger);
if (!plugin) {
return;
}
if (plugin->containment() != containment()) {
plugin->setContainment(containment());
// now configure it
KConfigGroup cfg = plugin->config();
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
}
if (plugin->configurationRequired()) {
desktopMenu.addTitle(i18n("This plugin needs to be configured"));
desktopMenu.addAction(containment()->action("configure"));
return;
} else {
QList<QAction*> actions = plugin->contextualActions();
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...
if ((containment()->containmentType() != Plasma::Containment::PanelContainment && containment()->containmentType() != Plasma::Containment::CustomPanelContainment) && containment()->action("configure")) {
desktopMenu.addAction(containment()->action("configure"));
}
} else {
desktopMenu.addActions(actions);
}
}
return;
}
#include "moc_containmentinterface.cpp"