aboutsummaryrefslogtreecommitdiff
path: root/src/status-provider-pidgin.c
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-08-25 16:21:44 -0500
committerTed Gould <ted@canonical.com>2009-08-25 16:21:44 -0500
commita4b4a9271212b8a9370fb7aa461302c6f9a97111 (patch)
tree67027342bfdc8363433a16c613fa0119a5bb48a9 /src/status-provider-pidgin.c
parentfaef72466956d377bfd5d679ea173db7617a5253 (diff)
parent2ca0db49f3d75fe732885cbad2ba89c4c71beb93 (diff)
downloadayatana-indicator-session-a4b4a9271212b8a9370fb7aa461302c6f9a97111.tar.gz
ayatana-indicator-session-a4b4a9271212b8a9370fb7aa461302c6f9a97111.tar.bz2
ayatana-indicator-session-a4b4a9271212b8a9370fb7aa461302c6f9a97111.zip
Merging in the more status branch that implements basic status for Pidgin and Telepathy.
Diffstat (limited to 'src/status-provider-pidgin.c')
-rw-r--r--src/status-provider-pidgin.c175
1 files changed, 172 insertions, 3 deletions
diff --git a/src/status-provider-pidgin.c b/src/status-provider-pidgin.c
index aaa8732..052ce12 100644
--- a/src/status-provider-pidgin.c
+++ b/src/status-provider-pidgin.c
@@ -26,6 +26,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "status-provider.h"
#include "status-provider-pidgin.h"
+#include "status-provider-pidgin-marshal.h"
#include <dbus/dbus-glib.h>
@@ -101,6 +102,75 @@ status_provider_pidgin_class_init (StatusProviderPidginClass *klass)
}
static void
+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
+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)
+{
+ saved_status_to_type(spp, savedstatus);
+ 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)
{
StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(self);
@@ -121,6 +191,37 @@ 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);
+
+ dbus_g_proxy_begin_call(priv->proxy,
+ "PurpleSavedstatusGetCurrent",
+ savedstatus_cb,
+ self,
+ NULL,
+ G_TYPE_INVALID);
}
return;
@@ -167,11 +268,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_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;
+ }
+
g_signal_emit(G_OBJECT(sp), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED_ID, 0, pg_to_sp_map[priv->pg_status], TRUE);
return;
}