aboutsummaryrefslogtreecommitdiff
path: root/src/common/qstateaction.cpp
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:11:28 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:11:28 -0300
commitebe349e1d96b28e31c29b3e563da1a65fb176e39 (patch)
treebe1271f3d09159fa9f1a44b96fc62cff9cb3b72e /src/common/qstateaction.cpp
parent2b9cf1654e8eb602f70e14246c3c583962ce7254 (diff)
downloadqmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.gz
qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.bz2
qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.zip
Created function to convert from QVariant to GVariant.
Moved QStateAction controler from QACtionGroup.
Diffstat (limited to 'src/common/qstateaction.cpp')
-rw-r--r--src/common/qstateaction.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/common/qstateaction.cpp b/src/common/qstateaction.cpp
index 8e3c7c3..1369bfc 100644
--- a/src/common/qstateaction.cpp
+++ b/src/common/qstateaction.cpp
@@ -19,6 +19,8 @@
#include "qstateaction.h"
+#include "qdbusactiongroup.h"
+
/*!
\qmlclass QStateAction
\inherits QAction
@@ -44,9 +46,20 @@
*/
/*! \internal */
-QStateAction::QStateAction(const QString &text, QObject *parent)
- :QAction(text, parent)
+QStateAction::QStateAction(QDBusActionGroup *group, const QString &name)
+ : QAction(name, group),
+ m_group(group)
{
+ QObject::connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));
+
+ // This keep the code clean
+ // But maybe we need move the action state control to QActionGroup to optimizations
+ QObject::connect(m_group, SIGNAL(actionAppear(QString)),
+ this, SLOT(onActionAppear(QString)));
+ QObject::connect(m_group, SIGNAL(actionVanish(QString)),
+ this, SLOT(onActionVanish(QString)));
+ QObject::connect(m_group, SIGNAL(actionStateUpdated(QString,QVariant)),
+ this, SLOT(onActionStateUpdate(QString,QVariant)));
}
/*!
@@ -68,6 +81,11 @@ bool QStateAction::isValid() const
return m_valid;
}
+void QStateAction::updateState(const QVariant &state)
+{
+ m_group->updateActionState(text(), state);
+}
+
/*! \internal */
void QStateAction::setValid(bool valid)
{
@@ -85,3 +103,33 @@ void QStateAction::setState(const QVariant &state)
Q_EMIT stateChanged(m_state);
}
}
+
+/*! \internal */
+void QStateAction::onTriggered()
+{
+ updateState(QVariant());
+}
+
+/*! \internal */
+void QStateAction::onActionAppear(const QString &actionName)
+{
+ if (text() == actionName) {
+ setValid(true);
+ }
+}
+
+/*! \internal */
+void QStateAction::onActionVanish(const QString &actionName)
+{
+ if (text() == actionName) {
+ setValid(false);
+ }
+}
+
+/*! \internal */
+void QStateAction::onActionStateUpdate(const QString &actionName, const QVariant &state)
+{
+ if (text() == actionName) {
+ setState(state);
+ }
+}