separe containmentactions and containment

most of containmentactions related stuff is now out of containment. some entanglement still exists
This commit is contained in:
Marco Martin 2013-02-19 12:03:53 +01:00
parent ca799b08bf
commit 32cbdac6e2
4 changed files with 28 additions and 175 deletions

View File

@ -627,10 +627,10 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
KConfigGroup cfg = d->containmentActionsConfig(); KConfigGroup cfg = d->containmentActionsConfig();
ContainmentActions *plugin = 0; ContainmentActions *plugin = 0;
if (d->actionPlugins()->contains(trigger)) { if (containmentActions().contains(trigger)) {
plugin = d->actionPlugins()->value(trigger); plugin = containmentActions().value(trigger);
if (plugin->pluginName() != pluginName) { if (plugin->pluginName() != pluginName) {
d->actionPlugins()->remove(trigger); containmentActions().remove(trigger);
delete plugin; delete plugin;
plugin = 0; plugin = 0;
} }
@ -655,7 +655,7 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
if (plugin) { if (plugin) {
cfg.writeEntry(trigger, pluginName); cfg.writeEntry(trigger, pluginName);
plugin->setSource(d->containmentActionsSource); plugin->setSource(d->containmentActionsSource);
d->actionPlugins()->insert(trigger, plugin); containmentActions().insert(trigger, plugin);
} else { } else {
//bad plugin... gets removed. is this a feature or a bug? //bad plugin... gets removed. is this a feature or a bug?
cfg.deleteEntry(trigger); cfg.deleteEntry(trigger);
@ -665,7 +665,7 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
emit configNeedsSaving(); emit configNeedsSaving();
} }
QHash<QString, ContainmentActions*> Containment::containmentActions() QHash<QString, ContainmentActions*> &Containment::containmentActions()
{ {
switch (d->containmentActionsSource) { switch (d->containmentActionsSource) {
case ContainmentActions::Activity: case ContainmentActions::Activity:

View File

@ -296,7 +296,7 @@ class PLASMA_EXPORT Containment : public Applet
* @return All the loaded containment action plugins, indexed by trigger name * @return All the loaded containment action plugins, indexed by trigger name
* @since 5.0 * @since 5.0
*/ */
QHash<QString, ContainmentActions*> containmentActions(); QHash<QString, ContainmentActions*> &containmentActions();
Q_SIGNALS: Q_SIGNALS:

View File

@ -112,79 +112,6 @@ void ContainmentPrivate::checkContainmentFurniture()
} }
} }
void ContainmentPrivate::addContainmentActions(KMenu &desktopMenu, QEvent *event)
{
if (q->corona()->immutability() != Mutable &&
!KAuthorized::authorizeKAction("plasma/containment_actions")) {
//kDebug() << "immutability";
return;
}
const QString trigger = ContainmentActions::eventToString(event);
prepareContainmentActions(trigger, QPoint(), &desktopMenu);
}
void ContainmentPrivate::addAppletActions(KMenu &desktopMenu, Applet *applet, QEvent *event)
{
foreach (QAction *action, applet->contextualActions()) {
if (action) {
desktopMenu.addAction(action);
}
}
if (!applet->d->failed) {
QAction *configureApplet = applet->d->actions->action("configure");
if (configureApplet && configureApplet->isEnabled()) {
desktopMenu.addAction(configureApplet);
}
QAction *runAssociatedApplication = applet->d->actions->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu.addAction(runAssociatedApplication);
}
}
KMenu *containmentMenu = new KMenu(i18nc("%1 is the name of the containment", "%1 Options", q->title()), &desktopMenu);
addContainmentActions(*containmentMenu, event);
if (!containmentMenu->isEmpty()) {
int enabled = 0;
//count number of real actions
QListIterator<QAction *> actionsIt(containmentMenu->actions());
while (enabled < 3 && actionsIt.hasNext()) {
QAction *action = actionsIt.next();
if (action->isVisible() && !action->isSeparator()) {
++enabled;
}
}
if (enabled) {
//if there is only one, don't create a submenu
if (enabled < 2) {
foreach (QAction *action, containmentMenu->actions()) {
if (action->isVisible() && !action->isSeparator()) {
desktopMenu.addAction(action);
}
}
} else {
desktopMenu.addMenu(containmentMenu);
}
}
}
if (q->immutability() == Mutable) {
QAction *closeApplet = applet->d->actions->action("remove");
//kDebug() << "checking for removal" << closeApplet;
if (closeApplet) {
if (!desktopMenu.isEmpty()) {
desktopMenu.addSeparator();
}
//kDebug() << "adding close action" << closeApplet->isEnabled() << closeApplet->isVisible();
desktopMenu.addAction(closeApplet);
}
}
}
void ContainmentPrivate::setScreen(int newScreen) void ContainmentPrivate::setScreen(int newScreen)
{ {
// What we want to do in here is: // What we want to do in here is:
@ -264,6 +191,24 @@ void ContainmentPrivate::setScreen(int newScreen)
} }
} }
KConfigGroup ContainmentPrivate::containmentActionsConfig() const
{
KConfigGroup cfg;
switch (containmentActionsSource) {
case ContainmentActions::Local:
cfg = q->config();
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
case ContainmentActions::Activity:
cfg = KConfigGroup(q->corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
default:
cfg = KConfigGroup(q->corona()->config(), "ActionPlugins");
}
return cfg;
}
KActionCollection* ContainmentPrivate::actions() KActionCollection* ContainmentPrivate::actions()
{ {
@ -390,79 +335,4 @@ bool ContainmentPrivate::isPanelContainment() const
return type == Containment::PanelContainment || type == Containment::CustomPanelContainment; return type == Containment::PanelContainment || type == Containment::CustomPanelContainment;
} }
KConfigGroup ContainmentPrivate::containmentActionsConfig() const
{
KConfigGroup cfg;
switch (containmentActionsSource) {
case ContainmentActions::Local:
cfg = q->config();
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
case ContainmentActions::Activity:
cfg = KConfigGroup(q->corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins");
break;
default:
cfg = KConfigGroup(q->corona()->config(), "ActionPlugins");
}
return cfg;
}
bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu)
{
ContainmentActions *plugin = actionPlugins()->value(trigger);
if (!plugin) {
return false;
}
if (plugin->containment() != q) {
plugin->setContainment(q);
// now configure it
KConfigGroup cfg = containmentActionsConfig();
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
}
if (plugin->configurationRequired()) {
KMenu *localMenu = menu ? menu : new KMenu();
localMenu->addTitle(i18n("This plugin needs to be configured"));
localMenu->addAction(q->action("configure"));
if (!menu) {
localMenu->exec(screenPos);
delete localMenu;
}
return false;
} else if (menu) {
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 (!isPanelContainment() && q->action("configure")) {
menu->addAction(q->action("configure"));
}
} else {
menu->addActions(actions);
}
}
return true;
}
QHash<QString, ContainmentActions*> * ContainmentPrivate::actionPlugins()
{
switch (containmentActionsSource) {
case ContainmentActions::Activity:
//FIXME
case ContainmentActions::Local:
return &localActionPlugins;
default:
return &globalActionPlugins;
}
}
} }

View File

@ -85,8 +85,6 @@ public:
bool isPanelContainment() const; bool isPanelContainment() const;
void setLockToolText(); void setLockToolText();
void appletDeleted(Applet*); void appletDeleted(Applet*);
void addContainmentActions(KMenu &desktopMenu, QEvent *event);
void addAppletActions(KMenu &desktopMenu, Applet *applet, QEvent *event);
void checkRemoveAction(); void checkRemoveAction();
void configChanged(); void configChanged();
@ -95,31 +93,16 @@ public:
KActionCollection *actions(); KActionCollection *actions();
/** /**
* add the regular actions & keyboard shortcuts onto Applet's collection * FIXME: this should completely go from here
*/
static void addDefaultActions(KActionCollection *actions, Containment *c = 0);
/**
* @return the config group that containmentactions plugins go in * @return the config group that containmentactions plugins go in
* @since 4.6 * @since 4.6
*/ */
KConfigGroup containmentActionsConfig() const; KConfigGroup containmentActionsConfig() const;
/** /**
* inits the containmentactions if necessary * add the regular actions & keyboard shortcuts onto Applet's collection
* if it needs configuring, this warns the user and returns false
* if a menu is passed in, then it populates that menu with the actions from the plugin
* @param trigger the string to identify the correct plugin with
* @param screenPos used to show the configure menu, only used if no menu is passed in
* @param menu an optional menu to use to populate with actions, instead of triggering the
* action directly
* @return true if it's ok to run the action
*/ */
bool prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu = 0); static void addDefaultActions(KActionCollection *actions, Containment *c = 0);
QHash<QString, ContainmentActions*> *actionPlugins();
static bool s_positioningPanels; static bool s_positioningPanels;