diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/dbus-enums.h | 53 | ||||
-rw-r--r-- | src/common/qdbusactiongroup.cpp | 4 | ||||
-rw-r--r-- | src/common/qdbusactiongroup.h | 4 | ||||
-rw-r--r-- | src/common/qdbusmenumodel.cpp | 4 | ||||
-rw-r--r-- | src/common/qdbusmenumodel.h | 4 | ||||
-rw-r--r-- | src/common/qdbusobject.cpp | 36 | ||||
-rw-r--r-- | src/common/qdbusobject.h | 31 |
8 files changed, 90 insertions, 47 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ad3343a..2b831b7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -11,6 +11,7 @@ set(QMENUMODELCOMMON_SRC set(QMENUMODELCOMMON_HEADERS converter.h + dbus-enums.h qmenumodel.h qdbusobject.h qdbusmenumodel.h diff --git a/src/common/dbus-enums.h b/src/common/dbus-enums.h new file mode 100644 index 0000000..76149da --- /dev/null +++ b/src/common/dbus-enums.h @@ -0,0 +1,53 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Olivier Tilloy <olivier.tilloy@canonical.com> + */ + +#ifndef __DBUS_ENUMS__ +#define __DBUS_ENUMS__ + +#include <QObject> + +// This class acts as a namespace only, with the addition that its enums +// are registered to be exposed on the QML side. +class DBusEnums : public QObject +{ + Q_OBJECT + + Q_ENUMS(BusType) + Q_ENUMS(ConnectionStatus) + +public: + enum BusType { + None = 0, + SessionBus, + SystemBus, + LastBusType + }; + + enum ConnectionStatus { + Disconnected = 0, + Connecting, + Connected + }; + +private: + DBusEnums() {} +}; + +#endif // __DBUS_ENUMS__ + diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp index 629915b..d25f2de 100644 --- a/src/common/qdbusactiongroup.cpp +++ b/src/common/qdbusactiongroup.cpp @@ -143,8 +143,8 @@ void QDBusActionGroup::stop() /*! \internal */ void QDBusActionGroup::setIntBusType(int busType) { - if ((busType > None) && (busType < LastBusType)) { - setBusType(static_cast<BusType>(busType)); + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast<DBusEnums::BusType>(busType)); } } diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h index dd3726c..2bd0a15 100644 --- a/src/common/qdbusactiongroup.h +++ b/src/common/qdbusactiongroup.h @@ -47,10 +47,10 @@ public: Q_INVOKABLE QVariant actionState(const QString &name); Q_SIGNALS: - void busTypeChanged(BusType type); + void busTypeChanged(DBusEnums::BusType type); void busNameChanged(const QString &busNameChanged); void objectPathChanged(const QString &objectPath); - void statusChanged(QDBusObject::ConnectionStatus status); + void statusChanged(DBusEnums::ConnectionStatus status); void actionAppear(const QString &name); void actionVanish(const QString &name); void actionStateChanged(const QString &name, QVariant state); diff --git a/src/common/qdbusmenumodel.cpp b/src/common/qdbusmenumodel.cpp index 9b824b4..354b10b 100644 --- a/src/common/qdbusmenumodel.cpp +++ b/src/common/qdbusmenumodel.cpp @@ -104,7 +104,7 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection) /*! \internal */ void QDBusMenuModel::setIntBusType(int busType) { - if ((busType > None) && (busType < LastBusType)) { - setBusType(static_cast<BusType>(busType)); + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast<DBusEnums::BusType>(busType)); } } diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h index 9af516d..2660ffe 100644 --- a/src/common/qdbusmenumodel.h +++ b/src/common/qdbusmenumodel.h @@ -38,10 +38,10 @@ public: ~QDBusMenuModel(); Q_SIGNALS: - void busTypeChanged(BusType type); + void busTypeChanged(DBusEnums::BusType type); void busNameChanged(const QString &busNameChanged); void objectPathChanged(const QString &objectPath); - void statusChanged(QDBusObject::ConnectionStatus status); + void statusChanged(DBusEnums::ConnectionStatus status); public Q_SLOTS: void start(); diff --git a/src/common/qdbusobject.cpp b/src/common/qdbusobject.cpp index d5ac44b..ff2a4a6 100644 --- a/src/common/qdbusobject.cpp +++ b/src/common/qdbusobject.cpp @@ -70,10 +70,10 @@ QDBusObject::QDBusObject() :m_watchId(0), - m_busType(None), - m_status(QDBusObject::Disconnected) + m_busType(DBusEnums::None), + m_status(DBusEnums::Disconnected) { - qRegisterMetaType<QDBusObject::ConnectionStatus>("QDBusObject::ConnectionStatus"); + qRegisterMetaType<DBusEnums::ConnectionStatus>("DBusEnums::ConnectionStatus"); } QDBusObject::~QDBusObject() @@ -84,15 +84,15 @@ QDBusObject::~QDBusObject() } } -QDBusObject::BusType QDBusObject::busType() const +DBusEnums::BusType QDBusObject::busType() const { return m_busType; } -void QDBusObject::setBusType(QDBusObject::BusType type) +void QDBusObject::setBusType(DBusEnums::BusType type) { if (m_busType != type) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_busType = type; busTypeChanged(m_busType); @@ -107,7 +107,7 @@ QString QDBusObject::busName() const void QDBusObject::setBusName(const QString &busName) { if (m_busName != busName) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_busName = busName; busNameChanged(m_busName); @@ -122,14 +122,14 @@ QString QDBusObject::objectPath() const void QDBusObject::setObjectPath(const QString &objectPath) { if (m_objectPath != objectPath) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_objectPath = objectPath; objectPathChanged(m_objectPath); } } -void QDBusObject::setStatus(QDBusObject::ConnectionStatus status) +void QDBusObject::setStatus(DBusEnums::ConnectionStatus status) { if (m_status != status) { m_status = status; @@ -137,17 +137,17 @@ void QDBusObject::setStatus(QDBusObject::ConnectionStatus status) } } -QDBusObject::ConnectionStatus QDBusObject::status() const +DBusEnums::ConnectionStatus QDBusObject::status() const { return m_status; } void QDBusObject::connect() { - if (m_status != QDBusObject::Disconnected) { + if (m_status != DBusEnums::Disconnected) { return; - } else if ((m_busType > None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { - GBusType type = m_busType == SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; + } else if ((m_busType > DBusEnums::None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { + GBusType type = m_busType == DBusEnums::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, @@ -156,7 +156,7 @@ void QDBusObject::connect() this, NULL); - setStatus(QDBusObject::Connecting); + setStatus(DBusEnums::Connecting); } else { qWarning() << "Invalid dbus connection args"; } @@ -164,10 +164,10 @@ void QDBusObject::connect() void QDBusObject::disconnect() { - if (m_status != QDBusObject::Disconnected) { + if (m_status != DBusEnums::Disconnected) { g_bus_unwatch_name (m_watchId); m_watchId = 0; - setStatus(QDBusObject::Disconnected); + setStatus(DBusEnums::Disconnected); } } @@ -175,7 +175,7 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, { QDBusObject *self = reinterpret_cast<QDBusObject*>(data); - self->setStatus(QDBusObject::Connected); + self->setStatus(DBusEnums::Connected); self->serviceAppear(connection); } @@ -183,6 +183,6 @@ void QDBusObject::onServiceFanished(GDBusConnection *connection, const gchar *, { QDBusObject *self = reinterpret_cast<QDBusObject*>(data); - self->setStatus(QDBusObject::Connecting); + self->setStatus(DBusEnums::Connecting); self->serviceVanish(connection); } diff --git a/src/common/qdbusobject.h b/src/common/qdbusobject.h index c50d540..cad6658 100644 --- a/src/common/qdbusobject.h +++ b/src/common/qdbusobject.h @@ -24,27 +24,16 @@ #include <gio/gio.h> +#include "dbus-enums.h" + class QDBusObject { public: - enum BusType { - None = 0, - SessionBus, - SystemBus, - LastBusType - }; - - enum ConnectionStatus { - Disconnected = 0, - Connecting, - Connected - }; - QDBusObject(); ~QDBusObject(); - BusType busType() const; - void setBusType(BusType type); + DBusEnums::BusType busType() const; + void setBusType(DBusEnums::BusType type); QString busName() const; void setBusName(const QString &busName); @@ -52,7 +41,7 @@ public: QString objectPath() const; void setObjectPath(const QString &busName); - ConnectionStatus status() const; + DBusEnums::ConnectionStatus status() const; void connect(); void disconnect(); @@ -62,19 +51,19 @@ protected: virtual void serviceVanish(GDBusConnection *connection) = 0; // notify functions - virtual void busTypeChanged(BusType type) = 0; + virtual void busTypeChanged(DBusEnums::BusType type) = 0; virtual void busNameChanged(const QString &busNameChanged) = 0; virtual void objectPathChanged(const QString &objectPath) = 0; - virtual void statusChanged(ConnectionStatus status) = 0; + virtual void statusChanged(DBusEnums::ConnectionStatus status) = 0; private: guint m_watchId; - BusType m_busType; + DBusEnums::BusType m_busType; QString m_busName; QString m_objectPath; - ConnectionStatus m_status; + DBusEnums::ConnectionStatus m_status; - void setStatus(ConnectionStatus status); + void setStatus(DBusEnums::ConnectionStatus status); // glib slots static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); |