diff options
author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-08-08 16:12:57 +0100 |
---|---|---|
committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-08-08 16:12:57 +0100 |
commit | c6cb726c5694f8a35711a48a7bf5e2a6723aeba8 (patch) | |
tree | 509f5b5c2cf1223274034721a611c55c5039b0ab /libqmenumodel/src/qdbusactiongroup.cpp | |
parent | 52b17007596bcd29ec0fe01468d28fddfcc18785 (diff) | |
download | qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.tar.gz qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.tar.bz2 qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.zip |
Glib callbacks send events through qt.
Diffstat (limited to 'libqmenumodel/src/qdbusactiongroup.cpp')
-rw-r--r-- | libqmenumodel/src/qdbusactiongroup.cpp | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/libqmenumodel/src/qdbusactiongroup.cpp b/libqmenumodel/src/qdbusactiongroup.cpp index 824b5f0..48aa882 100644 --- a/libqmenumodel/src/qdbusactiongroup.cpp +++ b/libqmenumodel/src/qdbusactiongroup.cpp @@ -21,11 +21,18 @@ #include "qstateaction.h" #include "converter.h" +// Qt +#include <QDebug> +#include <QCoreApplication> + extern "C" { #include <glib.h> #include <gio/gio.h> } +const QEvent::Type DBusActionStateEvent::eventType = static_cast<QEvent::Type>(QEvent::registerEventType()); +const QEvent::Type DBusActionVisiblityEvent::eventType = static_cast<QEvent::Type>(QEvent::registerEventType()); + /*! \qmltype QDBusActionGroup \inherits QDBusObject @@ -53,7 +60,8 @@ extern "C" { /*! \internal */ QDBusActionGroup::QDBusActionGroup(QObject *parent) :QObject(parent), - m_actionGroup(NULL) + QDBusObject(this), + m_actionGroup(NULL) { } @@ -184,7 +192,8 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag) gchar **actions = g_action_group_list_actions(m_actionGroup); for(guint i=0; i < g_strv_length(actions); i++) { - Q_EMIT actionAppear(actions[i]); + DBusActionVisiblityEvent dave(actions[i], true); + QCoreApplication::sendEvent(this, &dave); } g_strfreev(actions); } @@ -218,23 +227,68 @@ void QDBusActionGroup::activateAction(const QString &name, const QVariant ¶m } } +bool QDBusActionGroup::event(QEvent* e) +{ + if (QDBusObject::event(e)) { + return true; + + } else if (e->type() == DBusActionVisiblityEvent::eventType) { + DBusActionVisiblityEvent *dave = static_cast<DBusActionVisiblityEvent*>(e); + + if (dave->visible) { + Q_EMIT actionAppear(dave->name); + } else { + Q_EMIT actionVanish(dave->name); + } + } else if (e->type() == DBusActionStateEvent::eventType) { + DBusActionStateEvent *dase = static_cast<DBusActionStateEvent*>(e); + + Q_EMIT actionStateChanged(dase->name, dase->state); + } + return QObject::event(e); +} + /*! \internal */ void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *name, gpointer data) { QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); - Q_EMIT self->actionAppear(name); + + DBusActionVisiblityEvent dave(name, true); + QCoreApplication::sendEvent(self, &dave); } /*! \internal */ void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *name, gpointer data) { QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); - Q_EMIT self->actionVanish(name); + + DBusActionVisiblityEvent dave(name, false); + QCoreApplication::sendEvent(self, &dave); } /*! \internal */ void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *name, GVariant *value, gpointer data) { QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); - Q_EMIT self->actionStateChanged(name, Converter::toQVariant(value)); + + DBusActionStateEvent dase(name, Converter::toQVariant(value)); + QCoreApplication::sendEvent(self, &dase); +} + +DBusActionEvent::DBusActionEvent(const QString& _name, QEvent::Type type) + : QEvent(type), + name(_name) +{ +} + +DBusActionVisiblityEvent::DBusActionVisiblityEvent(const QString& _name, bool _visible) + : DBusActionEvent(_name, DBusActionVisiblityEvent::eventType), + visible(_visible) +{ +} + +DBusActionStateEvent::DBusActionStateEvent(const QString& _name, const QVariant& _state) + : DBusActionEvent(_name, DBusActionStateEvent::eventType), + state(_state) +{ } |