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*>(); return d->script ? d->script->contextualActions() : QList<QAction*>();
} }
QAction *Applet::action(QString name) const KActionCollection *Applet::actions() const
{ {
return d->actions->action(name); return d->actions;
}
void Applet::addAction(QString name, QAction *action)
{
d->actions->addAction(name, action);
} }
FormFactor Applet::formFactor() const FormFactor Applet::formFactor() const

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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