aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/QMenuModel/CMakeLists.txt13
-rw-r--r--src/common/CMakeLists.txt42
-rw-r--r--src/common/qdbusactiongroup.cpp (renamed from src/QMenuModel/qdbusactiongroup.cpp)4
-rw-r--r--src/common/qdbusactiongroup.h (renamed from src/QMenuModel/qdbusactiongroup.h)2
-rw-r--r--src/common/qdbusmenumodel.cpp (renamed from src/QMenuModel/qdbusmenumodel.cpp)6
-rw-r--r--src/common/qdbusmenumodel.h (renamed from src/QMenuModel/qdbusmenumodel.h)12
-rw-r--r--src/common/qdbusobject.cpp (renamed from src/QMenuModel/qdbusobject.cpp)62
-rw-r--r--src/common/qdbusobject.h (renamed from src/QMenuModel/qdbusobject.h)6
-rw-r--r--src/common/qmenumodel.cpp (renamed from src/QMenuModel/qmenumodel.cpp)97
-rw-r--r--src/common/qmenumodel.h (renamed from src/QMenuModel/qmenumodel.h)7
11 files changed, 194 insertions, 58 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e2c06cb..7215efc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,4 @@
project(src)
+add_subdirectory(common)
add_subdirectory(QMenuModel)
diff --git a/src/QMenuModel/CMakeLists.txt b/src/QMenuModel/CMakeLists.txt
index ee3f28c..bf3bb5a 100644
--- a/src/QMenuModel/CMakeLists.txt
+++ b/src/QMenuModel/CMakeLists.txt
@@ -1,16 +1,11 @@
+
+project(qmenumodelqmlplugin)
+
set(QMENUMODEL_SRC
- qmenumodel.cpp
- qdbusobject.cpp
- qdbusmenumodel.cpp
- qdbusactiongroup.cpp
plugin.cpp
)
set(QMENUMODEL_HEADERS
- qmenumodel.h
- qdbusobject.h
- qdbusmenumodel.h
- qdbusactiongroup.h
plugin.h
)
@@ -25,6 +20,7 @@ add_library(qmenumodel MODULE
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
+ ${qmenumodelcommon_SOURCE_DIR}
${QT_INCLUDE_DIR}
${QT_QTCORE_INCLUDE_DIR}
${QT_QTGUI_INCLUDE_DIR}
@@ -34,6 +30,7 @@ include_directories(
)
target_link_libraries(qmenumodel
+ qmenumodelcommon
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTDCLARATIVE_LIBRARY}
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
new file mode 100644
index 0000000..1428000
--- /dev/null
+++ b/src/common/CMakeLists.txt
@@ -0,0 +1,42 @@
+project(qmenumodelcommon)
+
+set(QMENUMODELCOMMON_SRC
+ qmenumodel.cpp
+ qdbusobject.cpp
+ qdbusmenumodel.cpp
+ qdbusactiongroup.cpp
+)
+
+set(QMENUMODELCOMMON_HEADERS
+ qmenumodel.h
+ qdbusobject.h
+ qdbusmenumodel.h
+ qdbusactiongroup.h
+)
+
+qt4_wrap_cpp(QMENUMODELCOMMON_MOC
+ ${QMENUMODELCOMMON_HEADERS}
+)
+
+add_library(qmenumodelcommon STATIC
+ ${QMENUMODELCOMMON_SRC}
+ ${QMENUMODELCOMMON_MOC}
+)
+
+set_target_properties(qmenumodelcommon PROPERTIES COMPILE_FLAGS -fPIC)
+
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${QT_INCLUDE_DIR}
+ ${QT_QTCORE_INCLUDE_DIR}
+ ${QT_QTGUI_INCLUDE_DIR}
+ ${GLIB_INCLUDE_DIRS}
+ ${GIO_INCLUDE_DIRS}
+)
+
+target_link_libraries(qmenumodelcommon
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ ${GLIB_LDFLAGS}
+ ${GIO_LDFLAGS}
+)
diff --git a/src/QMenuModel/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp
index ca430fb..8475c29 100644
--- a/src/QMenuModel/qdbusactiongroup.cpp
+++ b/src/common/qdbusactiongroup.cpp
@@ -44,12 +44,12 @@ void QDBusActionGroup::serviceAppear(GDBusConnection *connection)
void QDBusActionGroup::start()
{
- QDbusObject::connect();
+ QDBusObject::connect();
}
void QDBusActionGroup::stop()
{
- QDbusObject::disconnect();
+ QDBusObject::disconnect();
}
void QDBusActionGroup::busTypeChanged(BusType)
diff --git a/src/QMenuModel/qdbusactiongroup.h b/src/common/qdbusactiongroup.h
index a32b03e..fe743b6 100644
--- a/src/QMenuModel/qdbusactiongroup.h
+++ b/src/common/qdbusactiongroup.h
@@ -7,7 +7,7 @@
#include <QAction>
#include <QSet>
-class QDBusActionGroup : public QObject, public QDbusObject
+class QDBusActionGroup : public QObject, public QDBusObject
{
Q_OBJECT
Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged)
diff --git a/src/QMenuModel/qdbusmenumodel.cpp b/src/common/qdbusmenumodel.cpp
index c551464..6e35c85 100644
--- a/src/QMenuModel/qdbusmenumodel.cpp
+++ b/src/common/qdbusmenumodel.cpp
@@ -12,12 +12,12 @@ QDBusMenuModel::~QDBusMenuModel()
void QDBusMenuModel::start()
{
- QDbusObject::connect();
+ QDBusObject::connect();
}
void QDBusMenuModel::stop()
{
- QDbusObject::disconnect();
+ QDBusObject::disconnect();
}
void QDBusMenuModel::serviceVanish(GDBusConnection *)
@@ -36,6 +36,7 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection)
}
}
+/*
void QDBusMenuModel::busTypeChanged(BusType)
{
busTypeChanged();
@@ -55,6 +56,7 @@ void QDBusMenuModel::statusChanged(ConnectionStatus status)
{
statusChanged();
}
+*/
void QDBusMenuModel::setIntBusType(int busType)
{
diff --git a/src/QMenuModel/qdbusmenumodel.h b/src/common/qdbusmenumodel.h
index 975e72d..4fc439d 100644
--- a/src/QMenuModel/qdbusmenumodel.h
+++ b/src/common/qdbusmenumodel.h
@@ -6,7 +6,7 @@
#include <gio/gio.h>
-class QDBusMenuModel : public QMenuModel, public QDbusObject
+class QDBusMenuModel : public QMenuModel, public QDBusObject
{
Q_OBJECT
Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged)
@@ -19,10 +19,10 @@ public:
~QDBusMenuModel();
Q_SIGNALS:
- void busTypeChanged();
- void busNameChanged();
- void objectPathChanged();
- void statusChanged();
+ void busTypeChanged(BusType type);
+ void busNameChanged(const QString &busNameChanged);
+ void objectPathChanged(const QString &objectPath);
+ void statusChanged(QDBusObject::ConnectionStatus status);
public Q_SLOTS:
void start();
@@ -32,10 +32,12 @@ protected:
virtual void serviceAppear(GDBusConnection *connection);
virtual void serviceVanish(GDBusConnection *connection);
+ /*
virtual void busTypeChanged(BusType type);
virtual void busNameChanged(const QString &busNameChanged);
virtual void objectPathChanged(const QString &objectPath);
virtual void statusChanged(ConnectionStatus status);
+ */
private:
// workaround to support int as bustType
diff --git a/src/QMenuModel/qdbusobject.cpp b/src/common/qdbusobject.cpp
index 9f11813..6dec6d9 100644
--- a/src/QMenuModel/qdbusobject.cpp
+++ b/src/common/qdbusobject.cpp
@@ -2,14 +2,18 @@
#include <QDebug>
-QDbusObject::QDbusObject()
+
+
+QDBusObject::QDBusObject()
:m_watchId(0),
m_busType(None),
- m_status(QDbusObject::Disconnected)
+ m_status(QDBusObject::Disconnected)
{
+ qDebug() << "DBUS CREATED";
+ qRegisterMetaType<QDBusObject::ConnectionStatus>("QDBusObject::ConnectionStatus");
}
-QDbusObject::~QDbusObject()
+QDBusObject::~QDBusObject()
{
if (m_watchId != 0) {
g_bus_unwatch_name (m_watchId);
@@ -17,52 +21,52 @@ QDbusObject::~QDbusObject()
}
}
-QDbusObject::BusType QDbusObject::busType() const
+QDBusObject::BusType QDBusObject::busType() const
{
return m_busType;
}
-void QDbusObject::setBusType(QDbusObject::BusType type)
+void QDBusObject::setBusType(QDBusObject::BusType type)
{
if (m_busType != type) {
- if (m_status != QDbusObject::Disconnected)
+ if (m_status != QDBusObject::Disconnected)
disconnect();
m_busType = type;
busTypeChanged(m_busType);
}
}
-QString QDbusObject::busName() const
+QString QDBusObject::busName() const
{
return m_busName;
}
-void QDbusObject::setBusName(const QString &busName)
+void QDBusObject::setBusName(const QString &busName)
{
if (m_busName != busName) {
- if (m_status != QDbusObject::Disconnected)
+ if (m_status != QDBusObject::Disconnected)
disconnect();
m_busName = busName;
busNameChanged(m_busName);
}
}
-QString QDbusObject::objectPath() const
+QString QDBusObject::objectPath() const
{
return m_objectPath;
}
-void QDbusObject::setObjectPath(const QString &objectPath)
+void QDBusObject::setObjectPath(const QString &objectPath)
{
if (m_objectPath != objectPath) {
- if (m_status != QDbusObject::Disconnected)
+ if (m_status != QDBusObject::Disconnected)
disconnect();
m_objectPath = objectPath;
objectPathChanged(m_objectPath);
}
}
-void QDbusObject::setStatus(QDbusObject::ConnectionStatus status)
+void QDBusObject::setStatus(QDBusObject::ConnectionStatus status)
{
if (m_status != status) {
m_status = status;
@@ -70,52 +74,54 @@ void QDbusObject::setStatus(QDbusObject::ConnectionStatus status)
}
}
-QDbusObject::ConnectionStatus QDbusObject::status() const
+QDBusObject::ConnectionStatus QDBusObject::status() const
{
return m_status;
}
-void QDbusObject::connect()
+void QDBusObject::connect()
{
- if (m_status != QDbusObject::Disconnected) {
+ if (m_status != QDBusObject::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;
m_watchId = g_bus_watch_name (type,
m_busName.toLatin1(),
G_BUS_NAME_WATCHER_FLAGS_NONE,
- QDbusObject::onServiceAppeared,
- QDbusObject::onServiceFanished,
+ QDBusObject::onServiceAppeared,
+ QDBusObject::onServiceFanished,
this,
NULL);
- setStatus(QDbusObject::Connecting);
+ setStatus(QDBusObject::Connecting);
} else {
qWarning() << "Invalid dbus connection args";
}
}
-void QDbusObject::disconnect()
+void QDBusObject::disconnect()
{
- if (m_status != QDbusObject::Disconnected) {
+ if (m_status != QDBusObject::Disconnected) {
g_bus_unwatch_name (m_watchId);
m_watchId = 0;
- setStatus(QDbusObject::Disconnected);
+ setStatus(QDBusObject::Disconnected);
}
}
-void QDbusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data)
+void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data)
{
- QDbusObject *self = reinterpret_cast<QDbusObject*>(data);
+ QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
+ qDebug() << "service appear";
- self->setStatus(QDbusObject::Connected);
+ self->setStatus(QDBusObject::Connected);
self->serviceAppear(connection);
}
-void QDbusObject::onServiceFanished(GDBusConnection *connection, const gchar *, gpointer data)
+void QDBusObject::onServiceFanished(GDBusConnection *connection, const gchar *, gpointer data)
{
- QDbusObject *self = reinterpret_cast<QDbusObject*>(data);
+ QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
+ qDebug() << "service disappear";
- self->setStatus(QDbusObject::Connecting);
+ self->setStatus(QDBusObject::Connecting);
self->serviceVanish(connection);
}
diff --git a/src/QMenuModel/qdbusobject.h b/src/common/qdbusobject.h
index 0b17ae1..a2dc91c 100644
--- a/src/QMenuModel/qdbusobject.h
+++ b/src/common/qdbusobject.h
@@ -5,7 +5,7 @@
#include <gio/gio.h>
-class QDbusObject
+class QDBusObject
{
public:
enum BusType {
@@ -21,8 +21,8 @@ public:
Connected
};
- QDbusObject();
- ~QDbusObject();
+ QDBusObject();
+ ~QDBusObject();
BusType busType() const;
void setBusType(BusType type);
diff --git a/src/QMenuModel/qmenumodel.cpp b/src/common/qmenumodel.cpp
index c7ccf56..6e7483c 100644
--- a/src/QMenuModel/qmenumodel.cpp
+++ b/src/common/qmenumodel.cpp
@@ -1,4 +1,5 @@
#include "qmenumodel.h"
+
#include <QDebug>
QMenuModel::QMenuModel(GMenuModel *other, QObject *parent)
@@ -12,6 +13,7 @@ QMenuModel::QMenuModel(GMenuModel *other, QObject *parent)
rolesNames[Label] = "label";
rolesNames[LinkSection] = "linkSection";
rolesNames[LinkSubMenu] = "linkSubMenu";
+ rolesNames[Extra] = "extra";
}
setRoleNames(rolesNames);
setMenuModel(other);
@@ -36,17 +38,19 @@ void QMenuModel::setMenuModel(GMenuModel *other)
g_object_unref(m_menuModel);
}
- m_menuModel = other;
-
- endResetModel();
+ m_menuModel = other;
if (m_menuModel) {
- qDebug() << "Menu size:" << g_menu_model_get_n_items(m_menuModel);
+ // this will trigger the menu load
+ (void) g_menu_model_get_n_items(m_menuModel);
+ //qDebug() << "Menu size:" << g_menu_model_get_n_items(m_menuModel);
m_signalChangedId = g_signal_connect(m_menuModel,
"items-changed",
G_CALLBACK(QMenuModel::onItemsChanged),
this);
}
+
+ endResetModel();
}
GMenuModel *QMenuModel::menuModel() const
@@ -67,8 +71,7 @@ QVariant QMenuModel::data(const QModelIndex &index, int role) const
if ((rowCountValue > 0) && (index.row() >= 0) && (index.row() < rowCountValue)) {
if (m_menuModel) {
- switch (role)
- {
+ switch (role) {
case Action:
attribute = getStringAttribute(index, G_MENU_ATTRIBUTE_ACTION);
break;
@@ -81,6 +84,9 @@ QVariant QMenuModel::data(const QModelIndex &index, int role) const
case LinkSubMenu:
attribute = getLink(index, G_MENU_LINK_SUBMENU);
break;
+ case Extra:
+ attribute = getExtraProperties(index);
+ break;
default:
break;
}
@@ -135,6 +141,27 @@ QVariant QMenuModel::getLink(const QModelIndex &index,
return QVariant();
}
+QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const
+{
+ GMenuAttributeIter *iter = g_menu_model_iterate_item_attributes(m_menuModel, index.row());
+ if (iter == NULL) {
+ return QVariant();
+ }
+
+ QObject *extra = new QObject(const_cast<QMenuModel*>(this));
+ const gchar *attrName = NULL;
+ GVariant *value = NULL;
+ while (g_menu_attribute_iter_get_next (iter, &attrName, &value)) {
+ qDebug() << "Set property:" << attrName;
+ if (strncmp("x-", attrName, 2) == 0) {
+ extra->setProperty(attrName, parseGVariant(value));
+ }
+ }
+
+ return QVariant::fromValue<QObject*>(extra);
+}
+
+
void QMenuModel::onItemsChanged(GMenuModel *,
gint position,
gint removed,
@@ -142,6 +169,7 @@ void QMenuModel::onItemsChanged(GMenuModel *,
gpointer data)
{
QMenuModel *self = reinterpret_cast<QMenuModel*>(data);
+ //qDebug() << "Item Changed" << position << removed << added;
if (removed > 0) {
self->beginRemoveRows(QModelIndex(), position, position + removed - 1);
@@ -154,3 +182,60 @@ void QMenuModel::onItemsChanged(GMenuModel *,
}
}
+QVariant QMenuModel::parseGVariant(GVariant *value)
+{
+ QVariant result;
+ if (value == NULL) {
+ return result;
+ }
+
+ const GVariantType *type = g_variant_get_type(value);
+ if (g_variant_type_equal(type, G_VARIANT_TYPE_BOOLEAN)) {
+ result.setValue((bool)g_variant_get_boolean(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) {
+ result.setValue(g_variant_get_byte(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) {
+ result.setValue(g_variant_get_int16(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) {
+ result.setValue(g_variant_get_uint16(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) {
+ result.setValue(g_variant_get_int32(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) {
+ result.setValue(g_variant_get_uint32(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) {
+ result.setValue(g_variant_get_int64(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) {
+ result.setValue(g_variant_get_uint64(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_DOUBLE)) {
+ result.setValue(g_variant_get_double(value));
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING)) {
+ gsize size = 0;
+ const gchar *v = g_variant_get_string(value, &size);
+ result.setValue(QString::fromLatin1(v, size));
+ } else {
+ qWarning() << "Unsupported GVariant value";
+ }
+
+ /* TODO: implement convertions to others types
+ * G_VARIANT_TYPE_HANDLE
+ * G_VARIANT_TYPE_OBJECT_PATH
+ * G_VARIANT_TYPE_SIGNATURE
+ * G_VARIANT_TYPE_VARIANT
+ * G_VARIANT_TYPE_ANY
+ * G_VARIANT_TYPE_BASIC
+ * G_VARIANT_TYPE_MAYBE
+ * G_VARIANT_TYPE_ARRAY
+ * G_VARIANT_TYPE_TUPLE
+ * G_VARIANT_TYPE_UNIT
+ * G_VARIANT_TYPE_DICT_ENTRY
+ * G_VARIANT_TYPE_DICTIONARY
+ * G_VARIANT_TYPE_STRING_ARRAY
+ * G_VARIANT_TYPE_BYTESTRING
+ * G_VARIANT_TYPE_OBJECT_PATH_ARRAY
+ * G_VARIANT_TYPE_BYTESTRING_ARRAY
+ * G_VARIANT_TYPE_VARDICT
+ */
+
+ return result;
+}
+
diff --git a/src/QMenuModel/qmenumodel.h b/src/common/qmenumodel.h
index 18ad21c..f1e0b61 100644
--- a/src/QMenuModel/qmenumodel.h
+++ b/src/common/qmenumodel.h
@@ -4,7 +4,6 @@
#include <QAbstractListModel>
#include <gio/gio.h>
-
class QMenuModel : public QAbstractListModel
{
Q_OBJECT
@@ -14,7 +13,8 @@ public:
Action = 0,
Label,
LinkSection,
- LinkSubMenu
+ LinkSubMenu,
+ Extra
};
~QMenuModel();
@@ -36,9 +36,10 @@ private:
QVariant getStringAttribute(const QModelIndex &index, const QString &attribute) const;
QVariant getLink(const QModelIndex &index, const QString &linkName) const;
+ QVariant getExtraProperties(const QModelIndex &index) const;
static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data);
-
+ static QVariant parseGVariant(GVariant *value);
};
#endif