From db47d077dcd9ee6761de828c9194d3fa2331f9ea Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 9 Aug 2013 09:01:43 +0100 Subject: moved events to separate file. --- libqmenumodel/src/CMakeLists.txt | 1 + libqmenumodel/src/menunode.cpp | 11 +--- libqmenumodel/src/menunode.h | 14 ----- libqmenumodel/src/qdbusactiongroup.cpp | 22 +------- libqmenumodel/src/qdbusactiongroup.h | 30 ----------- libqmenumodel/src/qdbusmenumodel.cpp | 1 + libqmenumodel/src/qdbusobject.cpp | 20 +------ libqmenumodel/src/qdbusobject.h | 12 ----- libqmenumodel/src/qmenumodel.cpp | 20 +------ libqmenumodel/src/qmenumodel.h | 13 +---- libqmenumodel/src/qmenumodelevents.cpp | 96 +++++++++++++++++++++++++++++++++ libqmenumodel/src/qmenumodelevents.h | 99 ++++++++++++++++++++++++++++++++++ 12 files changed, 203 insertions(+), 136 deletions(-) create mode 100644 libqmenumodel/src/qmenumodelevents.cpp create mode 100644 libqmenumodel/src/qmenumodelevents.h (limited to 'libqmenumodel') diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt index 1fb89df..2f7aac8 100644 --- a/libqmenumodel/src/CMakeLists.txt +++ b/libqmenumodel/src/CMakeLists.txt @@ -8,6 +8,7 @@ set(QMENUMODEL_SRC qdbusobject.cpp qdbusmenumodel.cpp qdbusactiongroup.cpp + qmenumodelevents.cpp qstateaction.cpp ) diff --git a/libqmenumodel/src/menunode.cpp b/libqmenumodel/src/menunode.cpp index 10313d5..f244f40 100644 --- a/libqmenumodel/src/menunode.cpp +++ b/libqmenumodel/src/menunode.cpp @@ -18,13 +18,12 @@ */ #include "menunode.h" +#include "qmenumodelevents.h" #include #include #include -const QEvent::Type MenuNodeItemChangeEvent::eventType = static_cast(QEvent::registerEventType()); - MenuNode::MenuNode(const QString &linkType, GMenuModel *model, MenuNode *parent, int pos, QObject *listener) : m_model(model), m_parent(parent), @@ -250,11 +249,3 @@ void MenuNode::onItemsChanged(GMenuModel *model, gint position, gint removed, gi self->commitOperation(); } - -MenuNodeItemChangeEvent::MenuNodeItemChangeEvent(MenuNode* _node, int _position, int _removed, int _added) - : QEvent(MenuNodeItemChangeEvent::eventType), - node(_node), - position(_position), - removed(_removed), - added(_added) -{} diff --git a/libqmenumodel/src/menunode.h b/libqmenumodel/src/menunode.h index 9e22e82..21fc5bc 100644 --- a/libqmenumodel/src/menunode.h +++ b/libqmenumodel/src/menunode.h @@ -24,7 +24,6 @@ #include #include #include -#include extern "C" { #include @@ -74,17 +73,4 @@ private: static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); }; -class MenuNodeItemChangeEvent : public QEvent -{ -public: - static const QEvent::Type eventType; - - MenuNodeItemChangeEvent(MenuNode* node, int position, int removed, int added); - - MenuNode* node; - int position; - int removed; - int added; -}; - #endif diff --git a/libqmenumodel/src/qdbusactiongroup.cpp b/libqmenumodel/src/qdbusactiongroup.cpp index 72e3302..5000470 100644 --- a/libqmenumodel/src/qdbusactiongroup.cpp +++ b/libqmenumodel/src/qdbusactiongroup.cpp @@ -20,6 +20,7 @@ #include "qdbusactiongroup.h" #include "qstateaction.h" #include "converter.h" +#include "qmenumodelevents.h" // Qt #include @@ -29,9 +30,6 @@ extern "C" { #include } -const QEvent::Type DBusActionStateEvent::eventType = static_cast(QEvent::registerEventType()); -const QEvent::Type DBusActionVisiblityEvent::eventType = static_cast(QEvent::registerEventType()); - /*! \qmltype QDBusActionGroup \inherits QDBusObject @@ -272,21 +270,3 @@ void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *name, GVa 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) -{ -} diff --git a/libqmenumodel/src/qdbusactiongroup.h b/libqmenumodel/src/qdbusactiongroup.h index dde33a4..f369a4e 100644 --- a/libqmenumodel/src/qdbusactiongroup.h +++ b/libqmenumodel/src/qdbusactiongroup.h @@ -24,7 +24,6 @@ #include #include -#include class QStateAction; @@ -92,33 +91,4 @@ private: static void onActionStateChanged(GDBusActionGroup *ag, gchar *name, GVariant *value, gpointer data); }; -class DBusActionEvent : public QEvent -{ -public: - QString name; - -protected: - DBusActionEvent(const QString& name, QEvent::Type type); -}; - -class DBusActionVisiblityEvent : public DBusActionEvent -{ -public: - static const QEvent::Type eventType; - DBusActionVisiblityEvent(const QString& name, bool visible); - - bool visible; -}; - - -class DBusActionStateEvent : public DBusActionEvent -{ -public: - static const QEvent::Type eventType; - - DBusActionStateEvent(const QString& name, const QVariant& state); - - QVariant state; -}; - #endif // QDBUSACTIONGROUP_H diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp index 29ee364..f8b4a51 100644 --- a/libqmenumodel/src/qdbusmenumodel.cpp +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -22,6 +22,7 @@ extern "C" { } #include "qdbusmenumodel.h" +#include "qmenumodelevents.h" #include diff --git a/libqmenumodel/src/qdbusobject.cpp b/libqmenumodel/src/qdbusobject.cpp index f289bf9..be9fb93 100644 --- a/libqmenumodel/src/qdbusobject.cpp +++ b/libqmenumodel/src/qdbusobject.cpp @@ -23,12 +23,11 @@ extern "C" { } #include "qdbusobject.h" +#include "qmenumodelevents.h" #include #include -const QEvent::Type DbusObjectServiceEvent::eventType = static_cast(QEvent::registerEventType()); - /*! \qmltype QDBusObject \brief The QDBusObject is a base class @@ -216,20 +215,3 @@ bool QDBusObject::event(QEvent* e) } return false; } - -DbusObjectServiceEvent::DbusObjectServiceEvent(GDBusConnection* _connection, bool _visible) - : QEvent(DbusObjectServiceEvent::eventType), - connection(_connection), - visible(_visible) -{ - if (connection) { - g_object_ref(connection); - } -} - -DbusObjectServiceEvent::~DbusObjectServiceEvent() -{ - if (connection) { - g_object_unref(connection); - } -} diff --git a/libqmenumodel/src/qdbusobject.h b/libqmenumodel/src/qdbusobject.h index 3a00301..1a87844 100644 --- a/libqmenumodel/src/qdbusobject.h +++ b/libqmenumodel/src/qdbusobject.h @@ -21,7 +21,6 @@ #define QDBUSOBJECT_H #include -#include #include "dbus-enums.h" @@ -78,15 +77,4 @@ private: static void onServiceVanished(GDBusConnection *connection, const gchar *name, gpointer data); }; -class DbusObjectServiceEvent : public QEvent -{ -public: - static const QEvent::Type eventType; - DbusObjectServiceEvent(GDBusConnection* connection, bool visible); - ~DbusObjectServiceEvent(); - - GDBusConnection* connection; - bool visible; -}; - #endif diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 2b1397a..e77419f 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -25,11 +25,11 @@ extern "C" { #include "qmenumodel.h" #include "menunode.h" #include "converter.h" +#include "qmenumodelevents.h" + #include #include -const QEvent::Type MenuModelEvent::eventType = static_cast(QEvent::registerEventType()); - /*! \qmltype QMenuModel \brief The QMenuModel class implements the base list model for menus @@ -303,19 +303,3 @@ bool QMenuModel::hasLink(MenuNode *node, int row, const QString &linkType) const MenuNode *child = node->child(row); return (child && (child->linkType() == linkType)); } - -MenuModelEvent::MenuModelEvent(GMenuModel* _model) - : QEvent(MenuModelEvent::eventType), - model(_model) -{ - if (model) { - g_object_ref(model); - } -} - -MenuModelEvent::~MenuModelEvent() -{ - if (model) { - g_object_unref(model); - } -} diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index 54c09f5..bbb35a0 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -21,7 +21,6 @@ #define QMENUTREEMODEL_H #include -#include class MenuNode; typedef struct _GMenuModel GMenuModel; @@ -29,6 +28,7 @@ typedef struct _GMenuModel GMenuModel; class QMenuModel : public QAbstractItemModel { Q_OBJECT + public: enum MenuRoles { Action = Qt::DisplayRole + 1, @@ -73,15 +73,4 @@ private: void clearModel(); }; -class MenuModelEvent : public QEvent -{ -public: - static const QEvent::Type eventType; - - MenuModelEvent(GMenuModel *model); - ~MenuModelEvent(); - - GMenuModel *model; -}; - #endif diff --git a/libqmenumodel/src/qmenumodelevents.cpp b/libqmenumodel/src/qmenumodelevents.cpp new file mode 100644 index 0000000..c705d5c --- /dev/null +++ b/libqmenumodel/src/qmenumodelevents.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2013 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 . + * + * Authors: + * Nicholas Dedekind +#include +} + +#include "qmenumodelevents.h" + +const QEvent::Type MenuNodeItemChangeEvent::eventType = static_cast(QEvent::registerEventType()); +const QEvent::Type DBusActionStateEvent::eventType = static_cast(QEvent::registerEventType()); +const QEvent::Type DBusActionVisiblityEvent::eventType = static_cast(QEvent::registerEventType()); +const QEvent::Type MenuModelEvent::eventType = static_cast(QEvent::registerEventType()); +const QEvent::Type DbusObjectServiceEvent::eventType = static_cast(QEvent::registerEventType()); + +MenuNodeItemChangeEvent::MenuNodeItemChangeEvent(MenuNode* _node, int _position, int _removed, int _added) + : QEvent(MenuNodeItemChangeEvent::eventType), + node(_node), + position(_position), + removed(_removed), + added(_added) +{} + + +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) +{ +} + + +DbusObjectServiceEvent::DbusObjectServiceEvent(GDBusConnection* _connection, bool _visible) + : QEvent(DbusObjectServiceEvent::eventType), + connection(_connection), + visible(_visible) +{ + if (connection) { + g_object_ref(connection); + } +} + + +DbusObjectServiceEvent::~DbusObjectServiceEvent() +{ + if (connection) { + g_object_unref(connection); + } +} + + +MenuModelEvent::MenuModelEvent(GMenuModel* _model) + : QEvent(MenuModelEvent::eventType), + model(_model) +{ + if (model) { + g_object_ref(model); + } +} + +MenuModelEvent::~MenuModelEvent() +{ + if (model) { + g_object_unref(model); + } +} diff --git a/libqmenumodel/src/qmenumodelevents.h b/libqmenumodel/src/qmenumodelevents.h new file mode 100644 index 0000000..be8f80d --- /dev/null +++ b/libqmenumodel/src/qmenumodelevents.h @@ -0,0 +1,99 @@ +/* + * Copyright 2013 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 . + * + * Authors: + * Nicholas Dedekind +#include + +class MenuNode; +typedef struct _GDBusConnection GDBusConnection; +typedef struct _GMenuModel GMenuModel; + +/* Event for a connection update for a dbus object */ +class DbusObjectServiceEvent : public QEvent +{ +public: + static const QEvent::Type eventType; + DbusObjectServiceEvent(GDBusConnection* connection, bool visible); + ~DbusObjectServiceEvent(); + + GDBusConnection* connection; + bool visible; +}; + +/* Event for an update to the gmenumodel */ +class MenuModelEvent : public QEvent +{ +public: + static const QEvent::Type eventType; + + MenuModelEvent(GMenuModel *model); + ~MenuModelEvent(); + + GMenuModel *model; +}; + +/* Event for a GAction (base) */ +class DBusActionEvent : public QEvent +{ +public: + QString name; + +protected: + DBusActionEvent(const QString& name, QEvent::Type type); +}; + +/* Event for a GAction add/remove */ +class DBusActionVisiblityEvent : public DBusActionEvent +{ +public: + static const QEvent::Type eventType; + DBusActionVisiblityEvent(const QString& name, bool visible); + + bool visible; +}; + +/* Event for a GAction state value update */ +class DBusActionStateEvent : public DBusActionEvent +{ +public: + static const QEvent::Type eventType; + + DBusActionStateEvent(const QString& name, const QVariant& state); + + QVariant state; +}; + +/* Event for changing gmenumodel entries */ +class MenuNodeItemChangeEvent : public QEvent +{ +public: + static const QEvent::Type eventType; + + MenuNodeItemChangeEvent(MenuNode* node, int position, int removed, int added); + + MenuNode* node; + int position; + int removed; + int added; +}; + +#endif //QMENUMODELEVENTS_H -- cgit v1.2.3