separe containmentactions and containment
most of containmentactions related stuff is now out of containment. some entanglement still exists
This commit is contained in:
parent
ca799b08bf
commit
32cbdac6e2
@ -627,10 +627,10 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
|
||||
KConfigGroup cfg = d->containmentActionsConfig();
|
||||
ContainmentActions *plugin = 0;
|
||||
|
||||
if (d->actionPlugins()->contains(trigger)) {
|
||||
plugin = d->actionPlugins()->value(trigger);
|
||||
if (containmentActions().contains(trigger)) {
|
||||
plugin = containmentActions().value(trigger);
|
||||
if (plugin->pluginName() != pluginName) {
|
||||
d->actionPlugins()->remove(trigger);
|
||||
containmentActions().remove(trigger);
|
||||
delete plugin;
|
||||
plugin = 0;
|
||||
}
|
||||
@ -655,7 +655,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);
|
||||
containmentActions().insert(trigger, plugin);
|
||||
} else {
|
||||
//bad plugin... gets removed. is this a feature or a bug?
|
||||
cfg.deleteEntry(trigger);
|
||||
@ -665,7 +665,7 @@ void Containment::addContainmentActions(const QString &trigger, const QString &p
|
||||
emit configNeedsSaving();
|
||||
}
|
||||
|
||||
QHash<QString, ContainmentActions*> Containment::containmentActions()
|
||||
QHash<QString, ContainmentActions*> &Containment::containmentActions()
|
||||
{
|
||||
switch (d->containmentActionsSource) {
|
||||
case ContainmentActions::Activity:
|
||||
|
@ -296,7 +296,7 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
* @return All the loaded containment action plugins, indexed by trigger name
|
||||
* @since 5.0
|
||||
*/
|
||||
QHash<QString, ContainmentActions*> containmentActions();
|
||||
QHash<QString, ContainmentActions*> &containmentActions();
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -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)
|
||||
{
|
||||
// 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()
|
||||
{
|
||||
@ -390,79 +335,4 @@ bool ContainmentPrivate::isPanelContainment() const
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,8 +85,6 @@ public:
|
||||
bool isPanelContainment() const;
|
||||
void setLockToolText();
|
||||
void appletDeleted(Applet*);
|
||||
void addContainmentActions(KMenu &desktopMenu, QEvent *event);
|
||||
void addAppletActions(KMenu &desktopMenu, Applet *applet, QEvent *event);
|
||||
void checkRemoveAction();
|
||||
void configChanged();
|
||||
|
||||
@ -95,31 +93,16 @@ public:
|
||||
KActionCollection *actions();
|
||||
|
||||
/**
|
||||
* add the regular actions & keyboard shortcuts onto Applet's collection
|
||||
*/
|
||||
static void addDefaultActions(KActionCollection *actions, Containment *c = 0);
|
||||
|
||||
/**
|
||||
* FIXME: this should completely go from here
|
||||
* @return the config group that containmentactions plugins go in
|
||||
* @since 4.6
|
||||
*/
|
||||
KConfigGroup containmentActionsConfig() const;
|
||||
|
||||
/**
|
||||
* inits the containmentactions if necessary
|
||||
* 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
|
||||
* add the regular actions & keyboard shortcuts onto Applet's collection
|
||||
*/
|
||||
bool prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu = 0);
|
||||
|
||||
|
||||
|
||||
QHash<QString, ContainmentActions*> *actionPlugins();
|
||||
static void addDefaultActions(KActionCollection *actions, Containment *c = 0);
|
||||
|
||||
static bool s_positioningPanels;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user