~indicator-applet-developers/indicator-session/trunk.0.1

« back to all changes in this revision

Viewing changes to src/status-provider-pidgin.c

  • Committer: Ted Gould
  • Date: 2009-07-27 04:47:27 UTC
  • mfrom: (9.1.94 fusa.libindicator)
  • Revision ID: ted@canonical.com-20090727044727-m04ul5d8sxqt2pd4
Merging in the branch to port everything to libindicator and fleshing thigns out.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#include "status-provider.h"
 
6
#include "status-provider-pidgin.h"
 
7
 
 
8
#include <dbus/dbus-glib.h>
 
9
 
 
10
typedef enum {
 
11
        PG_STATUS_UNKNOWN,
 
12
        PG_STATUS_OFFLINE,
 
13
        PG_STATUS_AVAILABLE,
 
14
        PG_STATUS_UNAVAILABLE,
 
15
        PG_STATUS_INVISIBLE,
 
16
        PG_STATUS_AWAY,
 
17
        PG_STATUS_EXTENDEND_AWAY,
 
18
        PG_STATUS_MOBILE,
 
19
        PG_STATUS_TUNE
 
20
} pg_status_t;
 
21
 
 
22
static const StatusProviderStatus pg_to_sp_map[] = {
 
23
        /* PG_STATUS_UNKNOWN,        */   STATUS_PROVIDER_STATUS_OFFLINE,
 
24
        /* PG_STATUS_OFFLINE,        */   STATUS_PROVIDER_STATUS_OFFLINE,
 
25
        /* PG_STATUS_AVAILABLE,      */   STATUS_PROVIDER_STATUS_ONLINE,
 
26
        /* PG_STATUS_UNAVAILABLE,    */   STATUS_PROVIDER_STATUS_DND,
 
27
        /* PG_STATUS_INVISIBLE,      */   STATUS_PROVIDER_STATUS_INVISIBLE,
 
28
        /* PG_STATUS_AWAY,           */   STATUS_PROVIDER_STATUS_AWAY,
 
29
        /* PG_STATUS_EXTENDEND_AWAY, */   STATUS_PROVIDER_STATUS_AWAY,
 
30
        /* PG_STATUS_MOBILE,         */   STATUS_PROVIDER_STATUS_OFFLINE,
 
31
        /* PG_STATUS_TUNE            */   STATUS_PROVIDER_STATUS_OFFLINE
 
32
};
 
33
 
 
34
static const pg_status_t sp_to_pg_map[STATUS_PROVIDER_STATUS_LAST] = {
 
35
        /* STATUS_PROVIDER_STATUS_ONLINE,  */  PG_STATUS_AVAILABLE,
 
36
        /* STATUS_PROVIDER_STATUS_AWAY,    */  PG_STATUS_AWAY,
 
37
        /* STATUS_PROVIDER_STATUS_DND      */  PG_STATUS_UNAVAILABLE,
 
38
        /* STATUS_PROVIDER_STATUS_INVISIBLE*/  PG_STATUS_INVISIBLE,
 
39
        /* STATUS_PROVIDER_STATUS_OFFLINE  */  PG_STATUS_OFFLINE
 
40
};
 
41
 
 
42
typedef struct _StatusProviderPidginPrivate StatusProviderPidginPrivate;
 
43
struct _StatusProviderPidginPrivate {
 
44
        DBusGProxy * proxy;
 
45
        pg_status_t  pg_status;
 
46
};
 
47
 
 
48
#define STATUS_PROVIDER_PIDGIN_GET_PRIVATE(o) \
 
49
(G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_PROVIDER_PIDGIN_TYPE, StatusProviderPidginPrivate))
 
50
 
 
51
/* Prototypes */
 
52
/* GObject stuff */
 
53
static void status_provider_pidgin_class_init (StatusProviderPidginClass *klass);
 
54
static void status_provider_pidgin_init       (StatusProviderPidgin *self);
 
55
static void status_provider_pidgin_dispose    (GObject *object);
 
56
static void status_provider_pidgin_finalize   (GObject *object);
 
57
/* Internal Funcs */
 
58
static void set_status (StatusProvider * sp, StatusProviderStatus status);
 
59
static StatusProviderStatus get_status (StatusProvider * sp);
 
60
 
 
61
G_DEFINE_TYPE (StatusProviderPidgin, status_provider_pidgin, STATUS_PROVIDER_TYPE);
 
62
 
 
63
static void
 
64
status_provider_pidgin_class_init (StatusProviderPidginClass *klass)
 
65
{
 
66
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
67
 
 
68
        g_type_class_add_private (klass, sizeof (StatusProviderPidginPrivate));
 
69
 
 
70
        object_class->dispose = status_provider_pidgin_dispose;
 
71
        object_class->finalize = status_provider_pidgin_finalize;
 
72
 
 
73
        StatusProviderClass * spclass = STATUS_PROVIDER_CLASS(klass);
 
74
 
 
75
        spclass->set_status = set_status;
 
76
        spclass->get_status = get_status;
 
77
 
 
78
        return;
 
79
}
 
80
 
 
81
static void
 
82
status_provider_pidgin_init (StatusProviderPidgin *self)
 
83
{
 
84
        StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(self);
 
85
 
 
86
        priv->proxy = NULL;
 
87
        priv->pg_status = PG_STATUS_OFFLINE;
 
88
 
 
89
        DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
 
90
        g_return_if_fail(bus != NULL); /* Can't do anymore DBus stuff without this,
 
91
                                          all non-DBus stuff should be done */
 
92
 
 
93
        GError * error = NULL;
 
94
        priv->proxy = dbus_g_proxy_new_for_name_owner (bus,
 
95
                                                       "im.pidgin.purple.PurpleService",
 
96
                                                       "/im/pidgin/purple/PurpleObject",
 
97
                                                       "im.pidgin.purple.PurpleInterface",
 
98
                                                       &error);
 
99
        if (error != NULL) {
 
100
                g_debug("Unable to get Pidgin proxy: %s", error->message);
 
101
                g_error_free(error);
 
102
        }
 
103
 
 
104
        return;
 
105
}
 
106
 
 
107
static void
 
108
status_provider_pidgin_dispose (GObject *object)
 
109
{
 
110
 
 
111
        G_OBJECT_CLASS (status_provider_pidgin_parent_class)->dispose (object);
 
112
        return;
 
113
}
 
114
 
 
115
static void
 
116
status_provider_pidgin_finalize (GObject *object)
 
117
{
 
118
 
 
119
        G_OBJECT_CLASS (status_provider_pidgin_parent_class)->finalize (object);
 
120
        return;
 
121
}
 
122
 
 
123
/**
 
124
        status_provider_pidgin_new:
 
125
 
 
126
        Creates a new #StatusProviderPidgin object.  No parameters or anything
 
127
        like that.  Just a convience function.
 
128
 
 
129
        Return value: A new instance of #StatusProviderPidgin
 
130
*/
 
131
StatusProvider *
 
132
status_provider_pidgin_new (void)
 
133
{
 
134
        return STATUS_PROVIDER(g_object_new(STATUS_PROVIDER_PIDGIN_TYPE, NULL));
 
135
}
 
136
 
 
137
/* Takes the status provided generically for Status providers
 
138
   and turns it into a Pidgin status and sends it to Pidgin. */
 
139
static void
 
140
set_status (StatusProvider * sp, StatusProviderStatus status)
 
141
{
 
142
        g_debug("\tSetting Pidgin Status: %d", status);
 
143
        g_return_if_fail(IS_STATUS_PROVIDER_PIDGIN(sp));
 
144
        StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(sp);
 
145
        pg_status_t pg_status = sp_to_pg_map[status];
 
146
        priv->pg_status = pg_status;
 
147
        return;
 
148
}
 
149
 
 
150
/* Takes the cached Pidgin status and makes it into the generic
 
151
   Status provider status */
 
152
static StatusProviderStatus
 
153
get_status (StatusProvider * sp)
 
154
{
 
155
        g_return_val_if_fail(IS_STATUS_PROVIDER_PIDGIN(sp), STATUS_PROVIDER_STATUS_OFFLINE);
 
156
        StatusProviderPidginPrivate * priv = STATUS_PROVIDER_PIDGIN_GET_PRIVATE(sp);
 
157
        return pg_to_sp_map[priv->pg_status];
 
158
}