diff options
| author | Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | 2011-01-31 14:36:49 +0100 |
|---|---|---|
| committer | Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | 2011-01-31 14:36:49 +0100 |
| commit | 10f88c5d7c1afdaa3e7875a49a453c3f34845fc5 (patch) | |
| tree | c86c8b3ce15305289a5d9b29f7cd3044a9818f75 /src | |
| parent | 6a996226d3120c5ac6b00feefc1e7ccd61f5767e (diff) | |
More stubbing out of the Launcher DBus API, still not functional, but compiles without warnings
(bzr r798.5.2)
Diffstat (limited to 'src')
| -rw-r--r-- | src/LauncherEntryRemote.cpp | 87 | ||||
| -rw-r--r-- | src/LauncherEntryRemote.h | 50 | ||||
| -rw-r--r-- | src/LauncherEntryRemoteModel.cpp (renamed from src/LauncherEntryRemoteController.cpp) | 89 | ||||
| -rw-r--r-- | src/LauncherEntryRemoteModel.h (renamed from src/LauncherEntryRemoteController.h) | 30 |
4 files changed, 215 insertions, 41 deletions
diff --git a/src/LauncherEntryRemote.cpp b/src/LauncherEntryRemote.cpp index db92ea840..e1b85b4c7 100644 --- a/src/LauncherEntryRemote.cpp +++ b/src/LauncherEntryRemote.cpp @@ -21,10 +21,97 @@ LauncherEntryRemote::LauncherEntryRemote() { + _emblem = NULL; + _count = G_GINT64_CONSTANT (0); + _progress = 0.0; + _emblem_visible = FALSE; + _count_visible = FALSE; + _progress_visible = FALSE; } LauncherEntryRemote::~LauncherEntryRemote() { } + +const gchar* +LauncherEntryRemote::Emblem() +{ + return _emblem; +} + +gint64 +LauncherEntryRemote::Count() +{ + return _count; +} + +gdouble +LauncherEntryRemote::Progress() +{ + return _progress; +} + +gboolean +LauncherEntryRemote::EmblemVisible() +{ + return _emblem_visible; +} + +gboolean +LauncherEntryRemote::CountVisible() +{ + return _count_visible; +} + +gboolean +LauncherEntryRemote::ProgressVisible() +{ + return _progress_visible; +} + +void +LauncherEntryRemote::SetEmblem(const gchar* emblem) +{ + if (_emblem) + g_free (_emblem); + + _emblem = g_strdup (emblem); + emblem_changed.emit (); +} + +void +LauncherEntryRemote::SetCount(gint64 count) +{ + _count = count; + count_changed.emit (); +} + +void +LauncherEntryRemote::SetProgress(gdouble progress) +{ + _progress = progress; + progress_changed.emit (); +} + +void +LauncherEntryRemote::SetEmblemVisible(gboolean visible) +{ + _emblem_visible = visible; + emblem_visible_changed.emit (); +} + +void +LauncherEntryRemote::SetCountVisible(gboolean visible) +{ + _count_visible = visible; + count_visible_changed.emit (); +} + +void +LauncherEntryRemote::SetProgressVisible(gboolean visible) +{ + _progress_visible = visible; + progress_visible_changed.emit (); +} diff --git a/src/LauncherEntryRemote.h b/src/LauncherEntryRemote.h index 5f8663fa5..2f9b6a371 100644 --- a/src/LauncherEntryRemote.h +++ b/src/LauncherEntryRemote.h @@ -20,21 +20,61 @@ #ifndef LAUNCHER_ENTRY_REMOTE_H #define LAUNCHER_ENTRY_REMOTE_H +#include <Nux/Nux.h> #include <glib.h> #include <sigc++/sigc++.h> -class LauncherEntryRemote : public sigc::trackable +/** + * Instances of this class mirrors the remote metadata for a laucnher entry + * exposed by an application via the com.canonical.Unity.LauncherEntry DBus API. + * + * You do not create instances of LauncherEntryRemote yourself. Instead they + * are created and managed dynamically by a LauncherEntryRemoteModel. + */ +class LauncherEntryRemote : public nux::InitiallyUnownedObject, public sigc::trackable { + NUX_DECLARE_OBJECT_TYPE (LauncherEntryRemote, nux::InitiallyUnownedObject); + public: + const gchar* Emblem(); + gint64 Count(); + gdouble Progress(); + + gboolean EmblemVisible(); + gboolean CountVisible(); + gboolean ProgressVisible(); + + sigc::signal<void> emblem_changed; + sigc::signal<void> count_changed; + sigc::signal<void> progress_changed; + + sigc::signal<void> emblem_visible_changed; + sigc::signal<void> count_visible_changed; + sigc::signal<void> progress_visible_changed; + +private: + LauncherEntryRemote(); ~LauncherEntryRemote(); -private: - GDBusConnection *conn; - guint launcher_entry_dbus_signal_id; + gchar *_emblem; + gint64 _count; + gdouble _progress; + + gboolean _emblem_visible; + gboolean _count_visible; + gboolean _progress_visible; + + void SetEmblem (const gchar *emblem); + void SetCount (gint64 count); + void SetProgress (gdouble progress); + + void SetEmblemVisible (gboolean visible); + void SetCountVisible (gboolean visible); + void SetProgressVisible (gboolean visible); - void OnUpdateReceived (GVariant *params); + friend class LauncherEntryRemoteModel; }; #endif // LAUNCHER_ENTRY_REMOTE_H diff --git a/src/LauncherEntryRemoteController.cpp b/src/LauncherEntryRemoteModel.cpp index 6460f73b8..449008818 100644 --- a/src/LauncherEntryRemoteController.cpp +++ b/src/LauncherEntryRemoteModel.cpp @@ -17,7 +17,7 @@ * Authored by: Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> */ -#include "LauncherEntryRemoteController.h" +#include "LauncherEntryRemoteModel.h" static void on_launcher_entry_signal_received (GDBusConnection *connection, const gchar *sender_name, @@ -38,15 +38,10 @@ static void on_launcher_entry_signal_received (GDBusConnection *connection, * in order to help third party developers as much as possible when integrating * with Unity. */ -LauncherEntryRemoteController::LauncherEntryRemoteController() +LauncherEntryRemoteModel::LauncherEntryRemoteModel() { GError *error; - if (controller == NULL) - { - controller = new auncherEntryRemoteController(); - } - launcher_entry_dbus_signal_id = 0; error = NULL; @@ -73,7 +68,7 @@ LauncherEntryRemoteController::LauncherEntryRemoteController() NULL); } -LauncherEntryRemoteController::~LauncherEntryRemoteController() +LauncherEntryRemoteModel::~LauncherEntryRemoteModel() { if (launcher_entry_dbus_signal_id && conn) g_dbus_connection_signal_unsubscribe (conn, launcher_entry_dbus_signal_id); @@ -82,20 +77,46 @@ LauncherEntryRemoteController::~LauncherEntryRemoteController() g_object_unref (conn); } -/* Called with raw DBus params when the signal - * "com.canonical.Unity.LauncherEntry.Update" is received. - * The GVariant params should not be unreffed */ -LauncherEntryRemoteController::OnUpdateReceived (GVariant *params) +int +LauncherEntryRemoteModel::Size () { - g_return_if_fail (params != NULL); + return _entries.size (); +} - if (!g_variant_is_of_type (params, G_VARIANT_TYPE ("(sa{sv})"))) - { - g_warning ("Received 'com.canonical.Unity.LauncherEntry.Update' with" - " illegal payload signature '%s'. Expected '(sa{sv})'.", - g_variant_get_type_string (params)); - return; - } +std::list<LauncherEntryRemote*>::iterator +LauncherEntryRemoteModel::begin () +{ + return _entries.begin (); +} + +std::list<LauncherEntryRemote*>::iterator +LauncherEntryRemoteModel::end () +{ + return _entries.end (); +} + +std::list<LauncherEntryRemote*>::reverse_iterator +LauncherEntryRemoteModel::rbegin () +{ + return _entries.rbegin (); +} + +std::list<LauncherEntryRemote*>::reverse_iterator +LauncherEntryRemoteModel::rend () +{ + return _entries.rend (); +} + +/* Called when the signal com.canonical.Unity.LauncherEntry.Update is received. + * The app_uri looks like "application://firefox.desktop". The properties + * hashtable is a map from strings to GVariants with the property value. + */ +void +LauncherEntryRemoteModel::OnUpdateReceived (const gchar *app_uri, + GHashTable *props) +{ + g_return_if_fail (app_uri != NULL); + g_return_if_fail (props != NULL); } @@ -109,24 +130,34 @@ on_launcher_entry_signal_received (GDBusConnection *connection, GVariant *parameters, gpointer user_data) { - LauncherEntryRemote *self; + LauncherEntryRemoteModel *self; - self = static_cast<LauncherEntryRemoteController *> (user_data); + self = static_cast<LauncherEntryRemoteModel *> (user_data); - if (params == NULL) + if (parameters == NULL) { - g_warning ("Received DBus signal '%.%s' with empty payload from %s", + g_warning ("Received DBus signal '%s.%s' with empty payload from %s", interface_name, signal_name, sender_name); return; } if (g_strcmp0 (signal_name, "Update") == 0) { - self->OnUpdateReceived (paramters); + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv})"))) + { + g_warning ("Received 'com.canonical.Unity.LauncherEntry.Update' with" + " illegal payload signature '%s'. Expected '(sa{sv})'.", + g_variant_get_type_string (parameters)); + return; + } + // FIXME parse props + self->OnUpdateReceived (NULL, NULL); + } + else + { + g_warning ("Unknown signal '%s.%s' from %s", + interface_name, signal_name, sender_name); } - /* It's an undocumented fact that GDBus passes a full ref on the - * paramters back to the signal handler. So free the params */ - if (parameters != NULL) - g_variant_unref (parameters); + } diff --git a/src/LauncherEntryRemoteController.h b/src/LauncherEntryRemoteModel.h index a5194a4ef..c12f5ddbb 100644 --- a/src/LauncherEntryRemoteController.h +++ b/src/LauncherEntryRemoteModel.h @@ -17,24 +17,40 @@ * Authored by: Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> */ -#ifndef LAUNCHER_ENTRY_REMOTE_CONTROLLER_H -#define LAUNCHER_ENTRY_REMOTE_CONTROLLER_H +#ifndef LAUNCHER_ENTRY_REMOTE_MODEL_H +#define LAUNCHER_ENTRY_REMOTE_MODEL_H #include <glib.h> #include <sigc++/sigc++.h> -class LauncherEntryRemote : public sigc::trackable +#include "LauncherEntryRemote.h" + +class LauncherEntryRemoteModel : public sigc::trackable { public: - LauncherEntryRemoteController(); - ~LauncherEntryRemoteController(); + LauncherEntryRemoteModel(); + ~LauncherEntryRemoteModel(); + + void OnUpdateReceived (const gchar *app_uri, GHashTable *props); + + int Size (); + std::list<LauncherEntryRemote*>::iterator begin (); + std::list<LauncherEntryRemote*>::iterator end (); + std::list<LauncherEntryRemote*>::reverse_iterator rbegin (); + std::list<LauncherEntryRemote*>::reverse_iterator rend (); + + sigc::signal<void, LauncherEntryRemote *> entry_added; + sigc::signal<void, LauncherEntryRemote *> entry_removed; private: GDBusConnection *conn; guint launcher_entry_dbus_signal_id; - void OnUpdateReceived (GVariant *params); + std::list<LauncherEntryRemote*> _entries; + + void AddEntry (LauncherEntryRemote *entry); + void RemoveEntry (LauncherEntryRemote *entry); }; -#endif // LAUNCHER_ENTRY_REMOTE_CONTROLLER_H +#endif // LAUNCHER_ENTRY_REMOTE_MODEL_H |
