aboutsummaryrefslogtreecommitdiff
path: root/src/common/qdbusactiongroup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/qdbusactiongroup.cpp')
-rw-r--r--src/common/qdbusactiongroup.cpp106
1 files changed, 80 insertions, 26 deletions
diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp
index 51bc4ac..e453215 100644
--- a/src/common/qdbusactiongroup.cpp
+++ b/src/common/qdbusactiongroup.cpp
@@ -18,26 +18,60 @@
*/
#include "qdbusactiongroup.h"
+#include "converter.h"
#include <QDebug>
#include <gio/gio.h>
+/*!
+ \qmlclass QDBusActionGroup
+ \inherits QDBusObject
+
+ \brief A DBusActionGroup implementation to be used with \l QDBusMenuModel
+
+ \bold {This component is under heavy development.}
+
+ This class can be used as a proxy for an action group that is exported over D-Bus
+
+ \code
+ QDBusActionGroup {
+ id: actionGroup
+ busType: 1
+ busName: "com.ubuntu.menu"
+ objectPath: "com/ubuntu/menu/actions"
+ }
+
+ Button {
+ onClicked: actionGroup.getAction("app.quit").trigger()
+ }
+ \endcode
+*/
+
+/*! \internal */
QDBusActionGroup::QDBusActionGroup(QObject *parent)
:QObject(parent),
m_actionGroup(NULL)
{
}
+/*! \internal */
QDBusActionGroup::~QDBusActionGroup()
{
clear();
}
-QAction *QDBusActionGroup::getAction(const QString &actionName)
+/*!
+ \qmlmethod QDBusActionGroup::action(QString name)
+
+ Look for a action with the same name and return a \l QAction object.
+
+ \bold Note: methods should only be called after the Component has completed.
+*/
+QAction *QDBusActionGroup::action(const QString &name)
{
Q_FOREACH(QAction *act, m_actions) {
- if (act->text() == actionName) {
+ if (act->text() == name) {
return act;
}
}
@@ -45,11 +79,22 @@ QAction *QDBusActionGroup::getAction(const QString &actionName)
return NULL;
}
+/*!
+ \qmlproperty int QDBusActionGroup::count
+ This property holds the number of actions inside of \l QDBusActionGroup
+*/
+int QDBusActionGroup::count() const
+{
+ return m_actions.count();
+}
+
+/*! \internal */
void QDBusActionGroup::serviceVanish(GDBusConnection *)
{
clear();
}
+/*! \internal */
void QDBusActionGroup::serviceAppear(GDBusConnection *connection)
{
GDBusActionGroup *ag = g_dbus_action_group_get(connection,
@@ -61,36 +106,19 @@ void QDBusActionGroup::serviceAppear(GDBusConnection *connection)
}
}
+/*! \internal */
void QDBusActionGroup::start()
{
QDBusObject::connect();
}
+/*! \internal */
void QDBusActionGroup::stop()
{
QDBusObject::disconnect();
}
-void QDBusActionGroup::busTypeChanged(BusType)
-{
- busTypeChanged();
-}
-
-void QDBusActionGroup::busNameChanged(const QString &)
-{
- busNameChanged();
-}
-
-void QDBusActionGroup::objectPathChanged(const QString &objectPath)
-{
- objectPathChanged();
-}
-
-void QDBusActionGroup::statusChanged(ConnectionStatus status)
-{
- statusChanged();
-}
-
+/*! \internal */
void QDBusActionGroup::setIntBusType(int busType)
{
if ((busType > None) && (busType < LastBusType)) {
@@ -98,6 +126,7 @@ void QDBusActionGroup::setIntBusType(int busType)
}
}
+/*! \internal */
void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
{
if (m_actionGroup == reinterpret_cast<GActionGroup*>(ag)) {
@@ -107,16 +136,16 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
if (m_actionGroup) {
g_signal_handler_disconnect(m_actionGroup, m_signalActionAddId);
g_signal_handler_disconnect(m_actionGroup, m_signalActionRemovedId);
- m_signalActionAddId = m_signalActionRemovedId = 0;
+ g_signal_handler_disconnect(m_actionGroup, m_signalStateChangedId);
+ m_signalActionAddId = m_signalActionRemovedId = m_signalStateChangedId = 0;
g_object_unref(m_actionGroup);
}
m_actionGroup = reinterpret_cast<GActionGroup*>(ag);
if (m_actionGroup) {
-
m_signalActionAddId = g_signal_connect(m_actionGroup,
- "action-add",
+ "action-added",
G_CALLBACK(QDBusActionGroup::onActionAdded),
this);
@@ -125,6 +154,11 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
G_CALLBACK(QDBusActionGroup::onActionRemoved),
this);
+ m_signalStateChangedId = g_signal_connect(m_actionGroup,
+ "action-state-changed",
+ G_CALLBACK(QDBusActionGroup::onActionStateChanged),
+ this);
+
gchar **actionNames = g_action_group_list_actions(m_actionGroup);
for(int i=0; actionNames[i] != NULL; i++) {
addAction(actionNames[i]);
@@ -133,6 +167,7 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
}
}
+/*! \internal */
void QDBusActionGroup::addAction(const char *actionName)
{
QAction *act = new QAction(actionName, this);
@@ -150,35 +185,51 @@ void QDBusActionGroup::addAction(const char *actionName)
}
}
+ QObject::connect(act, SIGNAL(triggered()), this, SLOT(onActionTriggered()));
+
// remove any older action with the same name
removeAction(actionName);
m_actions.insert(act);
+ Q_EMIT countChanged(m_actions.count());
}
+/*! \internal */
+void QDBusActionGroup::onActionTriggered()
+{
+ QAction *act = qobject_cast<QAction*>(QObject::sender());
+ g_action_group_activate_action(m_actionGroup, act->text().toLatin1(), NULL);
+}
+
+/*! \internal */
void QDBusActionGroup::removeAction(const char *actionName)
{
Q_FOREACH(QAction *act, m_actions) {
if (act->text() == actionName) {
m_actions.remove(act);
delete act;
+ Q_EMIT countChanged(m_actions.count());
break;
}
}
}
+/*! \internal */
void QDBusActionGroup::updateAction(const char *actionName, GVariant *state)
{
- QAction *action = getAction(actionName);
+ QAction *action = this->action(actionName);
if ((action != NULL) && (state != NULL)) {
const GVariantType *stateType = g_variant_get_type(state);
if (stateType == G_VARIANT_TYPE_BOOLEAN) {
action->setChecked(g_variant_get_boolean(state));
}
+
+ Q_EMIT actionStateChanged(actionName, Converter::parseGVariant(state));
}
}
+/*! \internal */
void QDBusActionGroup::clear()
{
Q_FOREACH(QAction *act, m_actions) {
@@ -192,12 +243,14 @@ void QDBusActionGroup::clear()
}
}
+/*! \internal */
void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *actionName, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);
self->addAction(actionName);
}
+/*! \internal */
void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *actionName, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);
@@ -205,6 +258,7 @@ void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *actionName, gp
}
+/*! \internal */
void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *ag, gchar *actionName, GVariant *value, gpointer data)
{
QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data);