diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-06 16:43:27 -0300 |
---|---|---|
committer | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-06 16:43:27 -0300 |
commit | 31f8103187d2e27b1bb76eaed10dc9c9be226c90 (patch) | |
tree | 5b0d6a0a6bf07aaf213c482c61860a2784cd678f /src/QMenuModel/qdbusmenumodel.cpp | |
parent | 0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425 (diff) | |
download | qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.tar.gz qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.tar.bz2 qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.zip |
Implemented QDBusActionGroup.
Diffstat (limited to 'src/QMenuModel/qdbusmenumodel.cpp')
-rw-r--r-- | src/QMenuModel/qdbusmenumodel.cpp | 105 |
1 files changed, 22 insertions, 83 deletions
diff --git a/src/QMenuModel/qdbusmenumodel.cpp b/src/QMenuModel/qdbusmenumodel.cpp index 96f936c..c551464 100644 --- a/src/QMenuModel/qdbusmenumodel.cpp +++ b/src/QMenuModel/qdbusmenumodel.cpp @@ -2,95 +2,58 @@ #include <QDebug> QDBusMenuModel::QDBusMenuModel(QObject *parent) - :QMenuModel(parent), - m_watchId(0), - m_busType(None) + :QMenuModel(0, parent) { } QDBusMenuModel::~QDBusMenuModel() { - disconnect(); } -QDBusMenuModel::BusType QDBusMenuModel::busType() const +void QDBusMenuModel::start() { - return m_busType; + QDbusObject::connect(); } -void QDBusMenuModel::setBusType(QDBusMenuModel::BusType type) +void QDBusMenuModel::stop() { - if (m_busType != type) { - if (isConnected()) - disconnect(); - m_busType = type; - Q_EMIT busTypeChanged(m_busType); - } + QDbusObject::disconnect(); } -QString QDBusMenuModel::busName() const +void QDBusMenuModel::serviceVanish(GDBusConnection *) { - return m_busName; + setMenuModel(NULL); } -void QDBusMenuModel::setBusName(const QString &busName) +void QDBusMenuModel::serviceAppear(GDBusConnection *connection) { - if (m_busName != busName) { - if (isConnected()) - disconnect(); - m_busName = busName; - Q_EMIT busNameChanged(m_busName); + GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection, + busName().toLatin1(), + objectPath().toLatin1())); + setMenuModel(model); + if (model == NULL) { + stop(); } } -QString QDBusMenuModel::objectPath() const +void QDBusMenuModel::busTypeChanged(BusType) { - return m_objectPath; + busTypeChanged(); } -void QDBusMenuModel::setObjectPath(const QString &objectPath) +void QDBusMenuModel::busNameChanged(const QString &) { - if (m_objectPath != objectPath) { - if (isConnected()) - disconnect(); - m_objectPath = objectPath; - Q_EMIT objectPathChanged(m_objectPath); - } + busNameChanged(); } -void QDBusMenuModel::connect() +void QDBusMenuModel::objectPathChanged(const QString &objectPath) { - if (isConnected() || (m_watchId > 0)) { - return; - } else if ((m_busType > None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { - qDebug() << "Wait for service"; - GBusType type = m_busType == SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; - m_watchId = g_bus_watch_name (type, - m_busName.toLatin1(), - G_BUS_NAME_WATCHER_FLAGS_NONE, - QDBusMenuModel::onServiceAppeared, - QDBusMenuModel::onServiceFanished, - this, - NULL); - } else { - Q_EMIT connectionError("Invalid menu model connection args"); - } -} - -void QDBusMenuModel::disconnect() -{ - if (isConnected()) { - g_bus_unwatch_name (m_watchId); - m_watchId = 0; - - setMenuModel(NULL); - Q_EMIT disconnected(); - } + objectPathChanged(); } -bool QDBusMenuModel::isConnected() const +void QDBusMenuModel::statusChanged(ConnectionStatus status) { - return (m_watchId != 0); + statusChanged(); } void QDBusMenuModel::setIntBusType(int busType) @@ -99,27 +62,3 @@ void QDBusMenuModel::setIntBusType(int busType) setBusType(static_cast<BusType>(busType)); } } - -void QDBusMenuModel::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data) -{ - qDebug() << "Service appears"; - QDBusMenuModel *self = reinterpret_cast<QDBusMenuModel*>(data); - GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection, - self->m_busName.toLatin1(), - self->m_objectPath.toLatin1())); - self->setMenuModel(model); - if (model) { - Q_EMIT self->connected(); - } else { - Q_EMIT self->connectionError("Fail to retrieve menu model"); - self->disconnect(); - } -} - -void QDBusMenuModel::onServiceFanished(GDBusConnection *, const gchar *, gpointer data) -{ - qDebug() << "Service fanished"; - QDBusMenuModel *self = reinterpret_cast<QDBusMenuModel*>(data); - Q_EMIT self->connectionError("Menu model disapear"); - self->disconnect(); -} |