expose the KActionCollection instead of wrapping its API

This commit is contained in:
Aaron Seigo 2013-02-25 16:31:26 +01:00
parent 0db4b9b870
commit c9ff91fb0f
8 changed files with 29 additions and 42 deletions

View File

@ -563,14 +563,9 @@ QList<QAction*> Applet::contextualActions()
return d->script ? d->script->contextualActions() : QList<QAction*>();
}
QAction *Applet::action(QString name) const
KActionCollection *Applet::actions() const
{
return d->actions->action(name);
}
void Applet::addAction(QString name, QAction *action)
{
d->actions->addAction(name, action);
return d->actions;
}
FormFactor Applet::formFactor() const

View File

@ -305,14 +305,9 @@ class PLASMA_EXPORT Applet : public QObject
virtual QList<QAction*> contextualActions();
/**
* Returns the QAction with the given name from our collection
* Returns the collection of actions for this Applet
*/
QAction *action(QString name) const;
/**
* Adds the action to our collection under the given name
*/
void addAction(QString name, QAction *action);
KActionCollection *actions() const;
/**
* Sets the global shortcut to associate with this widget.

View File

@ -107,22 +107,22 @@ void Containment::init()
}
//connect actions
ContainmentPrivate::addDefaultActions(d->actions(), this);
ContainmentPrivate::addDefaultActions(actions(), this);
bool unlocked = immutability() == Mutable;
//fix the text of the actions that need title()
//btw, do we really want to use title() when it's a desktopcontainment?
QAction *closeApplet = action("remove");
QAction *closeApplet = actions()->action("remove");
if (closeApplet) {
closeApplet->setText(i18nc("%1 is the name of the applet", "Remove this %1", title()));
}
QAction *configAction = action("configure");
QAction *configAction = actions()->action("configure");
if (configAction) {
configAction->setText(i18nc("%1 is the name of the applet", "%1 Settings", title()));
}
QAction *appletBrowserAction = action("add widgets");
QAction *appletBrowserAction = actions()->action("add widgets");
if (appletBrowserAction) {
appletBrowserAction->setVisible(unlocked);
appletBrowserAction->setEnabled(unlocked);
@ -133,7 +133,7 @@ void Containment::init()
QAction *lockDesktopAction = corona()->action("lock widgets");
//keep a pointer so nobody notices it moved to corona
if (lockDesktopAction) {
d->actions()->addAction("lock widgets", lockDesktopAction);
actions()->addAction("lock widgets", lockDesktopAction);
}
}
}
@ -452,7 +452,7 @@ int Containment::screen() const
void Containment::enableAction(const QString &name, bool enable)
{
QAction *action = this->action(name);
QAction *action = actions()->action(name);
if (action) {
action->setEnabled(enable);
action->setVisible(enable);

View File

@ -169,11 +169,6 @@ KConfigGroup ContainmentPrivate::containmentActionsConfig() const
return cfg;
}
KActionCollection* ContainmentPrivate::actions()
{
return static_cast<Applet*>(q)->d->actions;
}
void ContainmentPrivate::configChanged()
{
KConfigGroup group = q->config();

View File

@ -85,8 +85,6 @@ public:
Applet *addApplet(const QString &name, const QVariantList &args = QVariantList(), uint id = 0);
KActionCollection *actions();
/**
* FIXME: this should completely go from here
* @return the config group that containmentactions plugins go in

View File

@ -40,8 +40,8 @@ class QmlObjectIncubationController : public QObject, public QQmlIncubationContr
public:
QmlObjectIncubationController(QObject *parent)
: QQmlIncubationController(),
QObject(parent)
: QObject(parent),
QQmlIncubationController()
{
// Allow incubation for 1/3 of a frame.
m_incubation_time = qMax(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3);

View File

@ -32,6 +32,7 @@
#include <QSignalMapper>
#include <QTimer>
#include <KActionCollection>
#include <KDebug>
#include <KGlobalSettings>
#include <KService>
@ -75,7 +76,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
connect(m_appletScriptEngine, SIGNAL(contextChanged()),
this, SIGNAL(contextChanged()));
connect(applet()->action("configure"), &QAction::triggered,
connect(applet()->actions()->action("configure"), &QAction::triggered,
this, &AppletInterface::configureTriggered);
m_qmlObject = new QmlObject(this);
@ -349,7 +350,7 @@ QList<QAction*> AppletInterface::contextualActions() const
}
foreach (const QString &name, m_actions) {
QAction *action = a->action(name);
QAction *action = a->actions()->action(name);
if (action) {
actions << action;
@ -362,14 +363,14 @@ QList<QAction*> AppletInterface::contextualActions() const
void AppletInterface::setActionSeparator(const QString &name)
{
Plasma::Applet *a = applet();
QAction *action = a->action(name);
QAction *action = a->actions()->action(name);
if (action) {
action->setSeparator(true);
} else {
action = new QAction(this);
action->setSeparator(true);
a->addAction(name, action);
a->actions()->addAction(name, action);
m_actions.append(name);
}
}
@ -377,13 +378,13 @@ void AppletInterface::setActionSeparator(const QString &name)
void AppletInterface::setAction(const QString &name, const QString &text, const QString &icon, const QString &shortcut)
{
Plasma::Applet *a = applet();
QAction *action = a->action(name);
QAction *action = a->actions()->action(name);
if (action) {
action->setText(text);
} else {
action = new QAction(text, this);
a->addAction(name, action);
a->actions()->addAction(name, action);
Q_ASSERT(!m_actions.contains(name));
m_actions.append(name);
@ -412,7 +413,7 @@ void AppletInterface::setAction(const QString &name, const QString &text, const
void AppletInterface::removeAction(const QString &name)
{
Plasma::Applet *a = applet();
QAction *action = a->action(name);
QAction *action = a->actions()->action(name);
if (action) {
if (m_actionSignals) {
@ -427,7 +428,7 @@ void AppletInterface::removeAction(const QString &name)
QAction *AppletInterface::action(QString name) const
{
return applet()->action(name);
return applet()->actions()->action(name);
}
bool AppletInterface::immutable() const

View File

@ -24,6 +24,7 @@
#include <QQmlExpression>
#include <QQmlProperty>
#include <KActionCollection>
#include <KAuthorized>
#include <KDebug>
#include <KLocalizedString>
@ -253,12 +254,12 @@ void ContainmentInterface::addAppletActions(KMenu &desktopMenu, Plasma::Applet *
}
if (!applet->failedToLaunch()) {
QAction *configureApplet = applet->action("configure");
QAction *configureApplet = applet->actions()->action("configure");
if (configureApplet && configureApplet->isEnabled()) {
desktopMenu.addAction(configureApplet);
}
QAction *runAssociatedApplication = applet->action("run associated application");
QAction *runAssociatedApplication = applet->actions()->action("run associated application");
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu.addAction(runAssociatedApplication);
}
@ -293,7 +294,7 @@ void ContainmentInterface::addAppletActions(KMenu &desktopMenu, Plasma::Applet *
}
if (containment()->immutability() == Plasma::Mutable) {
QAction *closeApplet = applet->action("remove");
QAction *closeApplet = applet->actions()->action("remove");
//kDebug() << "checking for removal" << closeApplet;
if (closeApplet) {
if (!desktopMenu.isEmpty()) {
@ -336,8 +337,10 @@ void ContainmentInterface::addContainmentActions(KMenu &desktopMenu, QEvent *eve
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::PanelContainment && containment()->containmentType() != Plasma::CustomPanelContainment) && containment()->action("configure")) {
desktopMenu.addAction(containment()->action("configure"));
if ((containment()->containmentType() != Plasma::PanelContainment &&
containment()->containmentType() != Plasma::CustomPanelContainment) &&
containment()->actions()->action("configure")) {
desktopMenu.addAction(containment()->actions()->action("configure"));
}
} else {
desktopMenu.addActions(actions);