aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:54:28 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:54:28 -0300
commit759356c47bdd7fd62775d604e910b358d43f059f (patch)
tree1dc86957b5f5f76be3ee99e0fc67e7242ee15e79
parentebe349e1d96b28e31c29b3e563da1a65fb176e39 (diff)
downloadqmenumodel-759356c47bdd7fd62775d604e910b358d43f059f.tar.gz
qmenumodel-759356c47bdd7fd62775d604e910b358d43f059f.tar.bz2
qmenumodel-759356c47bdd7fd62775d604e910b358d43f059f.zip
Fixed action state initialization.
-rw-r--r--src/common/qdbusactiongroup.cpp40
-rw-r--r--src/common/qdbusactiongroup.h21
-rw-r--r--src/common/qstateaction.cpp26
-rw-r--r--src/common/qstateaction.h6
4 files changed, 58 insertions, 35 deletions
diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp
index 305e12e..629915b 100644
--- a/src/common/qdbusactiongroup.cpp
+++ b/src/common/qdbusactiongroup.cpp
@@ -73,16 +73,28 @@ QStateAction *QDBusActionGroup::action(const QString &name)
{
QStateAction *act = actionImpl(name);
if (act == 0) {
- return new QStateAction(this, name);
- } else {
- return act;
+ act = new QStateAction(this, name);
}
+
+ return act;
}
-bool QDBusActionGroup::hasAction(const QString &actionName)
+QVariant QDBusActionGroup::actionState(const QString &name)
+{
+ QVariant result;
+ GVariant *state = g_action_group_get_action_state(m_actionGroup, name.toLatin1());
+ result = Converter::toQVariant(state);
+ if (state) {
+ g_variant_unref(state);
+ }
+ return result;
+}
+
+
+bool QDBusActionGroup::hasAction(const QString &name)
{
if (m_actionGroup) {
- return g_action_group_has_action(m_actionGroup, actionName.toLatin1());
+ return g_action_group_has_action(m_actionGroup, name.toLatin1());
} else {
return false;
}
@@ -170,7 +182,7 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
this);
gchar **actions = g_action_group_list_actions(m_actionGroup);
- for(int i=0; i < g_strv_length(actions); i++) {
+ for(guint i=0; i < g_strv_length(actions); i++) {
Q_EMIT actionAppear(actions[i]);
}
g_strfreev(actions);
@@ -191,30 +203,30 @@ void QDBusActionGroup::clear()
}
/*! \internal */
-void QDBusActionGroup::updateActionState(const QString &actionName, const QVariant &state)
+void QDBusActionGroup::updateActionState(const QString &name, const QVariant &state)
{
if (m_actionGroup != NULL) {
- g_action_group_activate_action(m_actionGroup, actionName.toLatin1(), Converter::toGVariant(state));
+ g_action_group_activate_action(m_actionGroup, name.toLatin1(), Converter::toGVariant(state));
}
}
/*! \internal */
-void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *actionName, gpointer data)
+void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *name, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);
- Q_EMIT self->actionAppear(actionName);
+ Q_EMIT self->actionAppear(name);
}
/*! \internal */
-void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *actionName, gpointer data)
+void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *name, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);
- Q_EMIT self->actionVanish(actionName);
+ Q_EMIT self->actionVanish(name);
}
/*! \internal */
-void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *actionName, GVariant *value, gpointer data)
+void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *name, GVariant *value, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);
- Q_EMIT self->actionStateChanged(actionName, Converter::toQVariant(value));
+ Q_EMIT self->actionStateChanged(name, Converter::toQVariant(value));
}
diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h
index 723094c..2f46f8f 100644
--- a/src/common/qdbusactiongroup.h
+++ b/src/common/qdbusactiongroup.h
@@ -40,19 +40,20 @@ public:
QDBusActionGroup(QObject *parent=0);
~QDBusActionGroup();
- void updateActionState(const QString &actionName, const QVariant &state);
- bool hasAction(const QString &actionName);
+ void updateActionState(const QString &name, const QVariant &state);
+ bool hasAction(const QString &name);
- Q_INVOKABLE QStateAction *action(const QString &actionName);
+ Q_INVOKABLE QStateAction *action(const QString &name);
+ Q_INVOKABLE QVariant actionState(const QString &name);
Q_SIGNALS:
void busTypeChanged(BusType type);
void busNameChanged(const QString &busNameChanged);
void objectPathChanged(const QString &objectPath);
void statusChanged(ConnectionStatus status);
- void actionAppear(const QString &actionName);
- void actionVanish(const QString &actionName);
- void actionStateChanged(const QString &actionName, QVariant state);
+ void actionAppear(const QString &name);
+ void actionVanish(const QString &name);
+ void actionStateChanged(const QString &name, QVariant state);
public Q_SLOTS:
void start();
@@ -72,14 +73,14 @@ private:
void setIntBusType(int busType);
void setActionGroup(GDBusActionGroup *ag);
- QStateAction *actionImpl(const QString &actionName);
+ QStateAction *actionImpl(const QString &name);
void clear();
// glib slots
- static void onActionAdded(GDBusActionGroup *ag, gchar *actionName, gpointer data);
- static void onActionRemoved(GDBusActionGroup *ag, gchar *actionName, gpointer data);
- static void onActionStateChanged(GDBusActionGroup *ag, gchar *actionName, GVariant *value, gpointer data);
+ static void onActionAdded(GDBusActionGroup *ag, gchar *name, gpointer data);
+ static void onActionRemoved(GDBusActionGroup *ag, gchar *name, gpointer data);
+ static void onActionStateChanged(GDBusActionGroup *ag, gchar *name, GVariant *value, gpointer data);
};
#endif
diff --git a/src/common/qstateaction.cpp b/src/common/qstateaction.cpp
index 1369bfc..3629fce 100644
--- a/src/common/qstateaction.cpp
+++ b/src/common/qstateaction.cpp
@@ -58,8 +58,16 @@ QStateAction::QStateAction(QDBusActionGroup *group, const QString &name)
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)));
+ QObject::connect(m_group, SIGNAL(actionStateChanged(QString,QVariant)),
+ this, SLOT(onActionStateChanged(QString,QVariant)));
+
+
+
+ bool isValid = m_group->hasAction(name);
+ setValid(isValid);
+ if (isValid) {
+ setState(m_group->actionState(name));
+ }
}
/*!
@@ -111,25 +119,27 @@ void QStateAction::onTriggered()
}
/*! \internal */
-void QStateAction::onActionAppear(const QString &actionName)
+void QStateAction::onActionAppear(const QString &name)
{
- if (text() == actionName) {
+ if (text() == name) {
+ setState(m_group->actionState(name));
setValid(true);
}
}
/*! \internal */
-void QStateAction::onActionVanish(const QString &actionName)
+void QStateAction::onActionVanish(const QString &name)
{
- if (text() == actionName) {
+ if (text() == name) {
+ setState(QVariant());
setValid(false);
}
}
/*! \internal */
-void QStateAction::onActionStateUpdate(const QString &actionName, const QVariant &state)
+void QStateAction::onActionStateChanged(const QString &name, const QVariant &state)
{
- if (text() == actionName) {
+ if (text() == name) {
setState(state);
}
}
diff --git a/src/common/qstateaction.h b/src/common/qstateaction.h
index c6bdcea..1a5a0fa 100644
--- a/src/common/qstateaction.h
+++ b/src/common/qstateaction.h
@@ -41,9 +41,9 @@ Q_SIGNALS:
void validChanged(bool valid);
private Q_SLOTS:
- void onActionAppear(const QString &actionName);
- void onActionVanish(const QString &actionName);
- void onActionStateUpdate(const QString &actionNane, const QVariant &state);
+ void onActionAppear(const QString &name);
+ void onActionVanish(const QString &name);
+ void onActionStateChanged(const QString &name, const QVariant &state);
void onTriggered();
private: