From b632849aefb2292231765c0218db36b4a6842e9a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 14:15:38 -0500 Subject: Pushing in Pidgin code, doesn't compile. --- src/status-provider-pidgin.c | 118 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index aaa8732..ab71755 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -100,6 +100,25 @@ status_provider_pidgin_class_init (StatusProviderPidginClass *klass) return; } +static void +changed_status (DBusGProxy * proxy, gint savedstatus, GError ** error, StatusProviderPidgin * spp) +{ + + return; +} + +static void +proxy_destroy (DBusGProxy * proxy, StatusProviderPidgin * spp) +{ + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(spp); + + priv->proxy = NULL; + priv->pg_status = PG_STATUS_OFFLINE; + + g_signal_emit(G_OBJECT(spp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); + return; +} + static void status_provider_pidgin_init (StatusProviderPidgin *self) { @@ -121,6 +140,30 @@ status_provider_pidgin_init (StatusProviderPidgin *self) if (error != NULL) { g_debug("Unable to get Pidgin proxy: %s", error->message); g_error_free(error); + return; + } + + if (priv->proxy != NULL) { + g_object_add_weak_pointer (G_OBJECT(priv->proxy), (gpointer *)&priv->proxy); + g_signal_connect(G_OBJECT(priv->proxy), "destroy", + G_CALLBACK(proxy_destroy), self); + + g_debug("Adding Pidgin Signals"); + dbus_g_object_register_marshaller(_status_provider_pidgin_marshal_VOID__INT_INT, + G_TYPE_NONE, + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->proxy, + "SavedstatusChanged", + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(priv->proxy, + "SavedstatusChanged", + G_CALLBACK(changed_status), + (void *)self, + NULL); } return; @@ -167,12 +210,79 @@ status_provider_pidgin_new (void) static void set_status (StatusProvider * sp, StatusProviderStatus status) { - g_debug("\tSetting Pidgin Status: %d", status); + gchar * message = ""; + g_return_if_fail(IS_STATUS_PROVIDER_PIDGIN(sp)); StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(sp); - pg_status_t pg_status = sp_to_pg_map[status]; - priv->pg_status = pg_status; - g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); + + g_debug("\tPidgin set status to %d", status); + if (priv->proxy == NULL) { + return; + } + + priv->pg_status = sp_to_pg_map[status]; + gint status_val = 0; + gboolean ret = FALSE; + GError * error = NULL; + + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusFindTransientByTypeAndMessage", &error, + G_TYPE_INT, priv->pg_status, + G_TYPE_STRING, message, + G_TYPE_INVALID, + G_TYPE_INT, &status_val, + G_TYPE_INVALID); + + if (!ret) { + if (error != NULL) { + g_error_free(error); + } + error = NULL; + status_val = 0; + g_debug("No Pidgin saved status to apply"); + } + + if (status_val == 0) { + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusNew", &error, + G_TYPE_STRING, message, + G_TYPE_INT, priv->pg_status, + G_TYPE_INVALID, + G_TYPE_INT, &status_val, + G_TYPE_INVALID); + + if (!ret) { + status_val = 0; + if (error != NULL) { + g_warning("Unable to create Pidgin status for %d: %s", status, error->message); + g_error_free(error); + } else { + g_warning("Unable to create Pidgin status for %d", status); + } + error = NULL; + } + } + + if (status_val == 0) { + return; + } + + ret = dbus_g_proxy_call(priv->proxy, + "PurpleSavedstatusActivate", &error, + G_TYPE_INT, status_val, + G_TYPE_INVALID, + G_TYPE_INVALID); + + if (!ret) { + if (error != NULL) { + g_warning("Pidgin unable to change to status: %s", error->message); + g_error_free(error); + } else { + g_warning("Pidgin unable to change to status"); + } + error = NULL; + } + return; } -- cgit v1.2.3 From a2f9b2b061063f4878573705ddf356b7b5cbd4cb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 14:22:11 -0500 Subject: Setting up a list of marshallers for the pidgin functionality --- src/Makefile.am | 21 ++++++++++++++++++--- src/status-provider-pidgin.c | 1 + src/status-provider-pidgin.list | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/status-provider-pidgin.list (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index bc3c9d9..736fd61 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,9 @@ indicator_status_service_SOURCES = \ status-provider.h \ status-provider.c \ status-provider-pidgin.h \ - status-provider-pidgin.c + status-provider-pidgin.c \ + status-provider-pidgin-marshal.h \ + status-provider-pidgin-marshal.c indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror indicator_status_service_LDADD = $(STATUSSERVICE_LIBS) @@ -46,6 +48,16 @@ status-service-server.h: $(srcdir)/status-service.xml --output=status-service-server.h \ $(srcdir)/status-service.xml +status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list + glib-genmarshal --header \ + --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ + > status-provider-pidgin-marshal.h + +status-provider-pidgin-marshal.c: $(srcdir)/status-provider-pidgin.list + glib-genmarshal --body \ + --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ + > status-provider-pidgin-marshal.c + ############### # Users Stuff ############### @@ -68,10 +80,13 @@ indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) BUILT_SOURCES = \ status-service-client.h \ - status-service-server.h + status-service-server.h \ + status-provider-pidgin-marshal.h \ + status-provider-pidgin-marshal.c EXTRA_DIST = \ - status-service.xml + status-service.xml \ + status-provider-pidgin.list CLEANFILES = \ $(BUILT_SOURCES) diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index ab71755..1d09ec8 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -26,6 +26,7 @@ with this program. If not, see . #include "status-provider.h" #include "status-provider-pidgin.h" +#include "status-provider-pidgin-marshal.h" #include diff --git a/src/status-provider-pidgin.list b/src/status-provider-pidgin.list new file mode 100644 index 0000000..1f953dd --- /dev/null +++ b/src/status-provider-pidgin.list @@ -0,0 +1 @@ +VOID:INT,INT -- cgit v1.2.3 From 2c69e50476ce831a8b878c76f3534263926be575 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 16:29:54 -0500 Subject: Now we can set the value in Pidgin and have it come back over the wire --- src/status-provider-pidgin.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index 1d09ec8..342cddc 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -102,12 +102,46 @@ status_provider_pidgin_class_init (StatusProviderPidginClass *klass) } static void -changed_status (DBusGProxy * proxy, gint savedstatus, GError ** error, StatusProviderPidgin * spp) +type_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + GError * error = NULL; + gint status = 0; + if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INT, &status, G_TYPE_INVALID)) { + g_warning("Unable to get type from Pidgin: %s", error->message); + g_error_free(error); + return; + } + + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(userdata); + if (status != priv->pg_status) { + priv->pg_status = status; + + g_signal_emit(G_OBJECT(userdata), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); + } + + return; +} + +static void +saved_status_to_type (StatusProviderPidgin * spp, gint savedstatus) { + StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(spp); + + g_debug("Pidgin figuring out type for %d", savedstatus); + dbus_g_proxy_begin_call(priv->proxy, + "PurpleSavedstatusGetType", type_cb, spp, NULL, + G_TYPE_INT, savedstatus, G_TYPE_INVALID); return; } +static void +changed_status (DBusGProxy * proxy, gint savedstatus, GError ** error, StatusProviderPidgin * spp) +{ + saved_status_to_type(spp, savedstatus); + return; +} + static void proxy_destroy (DBusGProxy * proxy, StatusProviderPidgin * spp) { -- cgit v1.2.3 From 7917b6f262b675546cd878925c5601ba6b9da116 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 16:31:38 -0500 Subject: Should update for local changes as well. --- src/status-provider-pidgin.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index 342cddc..53b8e6d 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -318,6 +318,7 @@ set_status (StatusProvider * sp, StatusProviderStatus status) error = NULL; } + g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE); return; } -- cgit v1.2.3 From d539c58cdce66db1be5cd49181d47cbf64731c49 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 16:52:43 -0500 Subject: Initially querying the status so that when we start, we get the right value. --- src/status-provider-pidgin.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c index 53b8e6d..052ce12 100644 --- a/src/status-provider-pidgin.c +++ b/src/status-provider-pidgin.c @@ -135,6 +135,22 @@ saved_status_to_type (StatusProviderPidgin * spp, gint savedstatus) return; } +static void +savedstatus_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + GError * error = NULL; + gint status = 0; + if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INT, &status, G_TYPE_INVALID)) { + g_warning("Unable to get saved status from Pidgin: %s", error->message); + g_error_free(error); + return; + } + + saved_status_to_type(STATUS_PROVIDER_PIDGIN(userdata), status); + return; +} + + static void changed_status (DBusGProxy * proxy, gint savedstatus, GError ** error, StatusProviderPidgin * spp) { @@ -199,6 +215,13 @@ status_provider_pidgin_init (StatusProviderPidgin *self) G_CALLBACK(changed_status), (void *)self, NULL); + + dbus_g_proxy_begin_call(priv->proxy, + "PurpleSavedstatusGetCurrent", + savedstatus_cb, + self, + NULL, + G_TYPE_INVALID); } return; -- cgit v1.2.3 From a52eb4af8fd90ae883ad511fbce0bc9297dbaca5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 17:07:07 -0500 Subject: Some marshallers for the Telepathy status stuff. --- src/Makefile.am | 21 ++++++++++++++++++--- src/status-provider-telepathy.list | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/status-provider-telepathy.list (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 736fd61..a014128 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,7 +30,9 @@ indicator_status_service_SOURCES = \ status-provider-pidgin.h \ status-provider-pidgin.c \ status-provider-pidgin-marshal.h \ - status-provider-pidgin-marshal.c + status-provider-pidgin-marshal.c \ + status-provider-telepathy-marshal.h \ + status-provider-telepathy-marshal.c indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror indicator_status_service_LDADD = $(STATUSSERVICE_LIBS) @@ -58,6 +60,16 @@ status-provider-pidgin-marshal.c: $(srcdir)/status-provider-pidgin.list --prefix=_status_provider_pidgin_marshal $(srcdir)/status-provider-pidgin.list \ > status-provider-pidgin-marshal.c +status-provider-telepathy-marshal.h: $(srcdir)/status-provider-telepathy.list + glib-genmarshal --header \ + --prefix=_status_provider_telepathy_marshal $(srcdir)/status-provider-telepathy.list \ + > status-provider-telepathy-marshal.h + +status-provider-telepathy-marshal.c: $(srcdir)/status-provider-telepathy.list + glib-genmarshal --body \ + --prefix=_status_provider_telepathy_marshal $(srcdir)/status-provider-telepathy.list \ + > status-provider-telepathy-marshal.c + ############### # Users Stuff ############### @@ -82,11 +94,14 @@ BUILT_SOURCES = \ status-service-client.h \ status-service-server.h \ status-provider-pidgin-marshal.h \ - status-provider-pidgin-marshal.c + status-provider-pidgin-marshal.c \ + status-provider-telepathy-marshal.h \ + status-provider-telepathy-marshal.c EXTRA_DIST = \ status-service.xml \ - status-provider-pidgin.list + status-provider-pidgin.list \ + status-provider-telepathy.list CLEANFILES = \ $(BUILT_SOURCES) diff --git a/src/status-provider-telepathy.list b/src/status-provider-telepathy.list new file mode 100644 index 0000000..5ab45bf --- /dev/null +++ b/src/status-provider-telepathy.list @@ -0,0 +1 @@ +VOID:UINT,STRING -- cgit v1.2.3 From f022d796081febf634787868ddd93d5e19431786 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Aug 2009 17:20:45 -0500 Subject: Getting more of a basis for Telepathy stuff --- src/Makefile.am | 2 + src/status-provider-telepathy.c | 113 ++++++++++++++++++++++++++++++++++++++++ src/status-provider-telepathy.h | 56 ++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 src/status-provider-telepathy.c create mode 100644 src/status-provider-telepathy.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index a014128..dbe6d0f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,8 @@ indicator_status_service_SOURCES = \ status-provider-pidgin.c \ status-provider-pidgin-marshal.h \ status-provider-pidgin-marshal.c \ + status-provider-telepathy.h \ + status-provider-telepathy.c \ status-provider-telepathy-marshal.h \ status-provider-telepathy-marshal.c indicator_status_service_CFLAGS = $(STATUSSERVICE_CFLAGS) -Wall -Werror diff --git a/src/status-provider-telepathy.c b/src/status-provider-telepathy.c new file mode 100644 index 0000000..339ede3 --- /dev/null +++ b/src/status-provider-telepathy.c @@ -0,0 +1,113 @@ +/* +A small wrapper utility to load indicators and put them as menu items +into the gnome-panel using it's applet interface. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "status-provider.h" +#include "status-provider-telepathy.h" +#include "status-provider-telepathy-marshal.h" + +#include + + +typedef struct _StatusProviderTelepathyPrivate StatusProviderTelepathyPrivate; +struct _StatusProviderTelepathyPrivate { + DBusGProxy * proxy; +}; + +#define STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyPrivate)) + +/* Prototypes */ +/* GObject stuff */ +static void status_provider_telepathy_class_init (StatusProviderTelepathyClass *klass); +static void status_provider_telepathy_init (StatusProviderTelepathy *self); +static void status_provider_telepathy_dispose (GObject *object); +static void status_provider_telepathy_finalize (GObject *object); + +G_DEFINE_TYPE (StatusProviderTelepathy, status_provider_telepathy, STATUS_PROVIDER_TYPE); + +static void +status_provider_telepathy_class_init (StatusProviderTelepathyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (StatusProviderTelepathyPrivate)); + + object_class->dispose = status_provider_telepathy_dispose; + object_class->finalize = status_provider_telepathy_finalize; + + //StatusProviderClass * spclass = STATUS_PROVIDER_CLASS(klass); + + //spclass->set_status = set_status; + //spclass->get_status = get_status; + + return; +} + + +static void +status_provider_telepathy_init (StatusProviderTelepathy *self) +{ + //StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(self); + + return; +} + +static void +status_provider_telepathy_dispose (GObject *object) +{ + StatusProviderTelepathyPrivate * priv = STATUS_PROVIDER_TELEPATHY_GET_PRIVATE(object); + + if (priv->proxy != NULL) { + g_object_unref(priv->proxy); + priv->proxy = NULL; + } + + G_OBJECT_CLASS (status_provider_telepathy_parent_class)->dispose (object); + return; +} + +static void +status_provider_telepathy_finalize (GObject *object) +{ + + G_OBJECT_CLASS (status_provider_telepathy_parent_class)->finalize (object); + return; +} + +/** + status_provider_telepathy_new: + + Creates a new #StatusProviderTelepathy object. No parameters or anything + like that. Just a convience function. + + Return value: A new instance of #StatusProviderTelepathy +*/ +StatusProvider * +status_provider_telepathy_new (void) +{ + return STATUS_PROVIDER(g_object_new(STATUS_PROVIDER_TELEPATHY_TYPE, NULL)); +} + diff --git a/src/status-provider-telepathy.h b/src/status-provider-telepathy.h new file mode 100644 index 0000000..a67ee40 --- /dev/null +++ b/src/status-provider-telepathy.h @@ -0,0 +1,56 @@ +/* +A small wrapper utility to load indicators and put them as menu items +into the gnome-panel using it's applet interface. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifndef __STATUS_PROVIDER_TELEPATHY_H__ +#define __STATUS_PROVIDER_TELEPATHY_H__ + +#include +#include + +#include "status-provider.h" + +G_BEGIN_DECLS + +#define STATUS_PROVIDER_TELEPATHY_TYPE (status_provider_telepathy_get_type ()) +#define STATUS_PROVIDER_TELEPATHY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathy)) +#define STATUS_PROVIDER_TELEPATHY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyClass)) +#define IS_STATUS_PROVIDER_TELEPATHY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STATUS_PROVIDER_TELEPATHY_TYPE)) +#define IS_STATUS_PROVIDER_TELEPATHY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STATUS_PROVIDER_TELEPATHY_TYPE)) +#define STATUS_PROVIDER_TELEPATHY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STATUS_PROVIDER_TELEPATHY_TYPE, StatusProviderTelepathyClass)) + + +typedef struct _StatusProviderTelepathyClass StatusProviderTelepathyClass; +struct _StatusProviderTelepathyClass { + StatusProviderClass parent_class; +}; + +typedef struct _StatusProviderTelepathy StatusProviderTelepathy; +struct _StatusProviderTelepathy { + StatusProvider parent; +}; + +GType status_provider_telepathy_get_type (void); +StatusProvider * status_provider_telepathy_new (void); + +G_END_DECLS + +#endif -- cgit v1.2.3