~skypce/indicator-session/indicator-session

« back to all changes in this revision

Viewing changes to src/indicator-session.c

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2009-12-10 10:42:21 UTC
  • mfrom: (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20091210104221-vf7zqsien3deqc1p
Tags: 0.1.7+r58-0ubuntu1
* New snapshot for libindicator 0.3.0
* debian/control
  - build depend on libtelepathy-glib-dev instead of libempathy-dev
  - build depend on libindicator-dev >= 0.3.0
* removed 03_tp_glib.patch and 99_autoreconf.patch, applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
*/
22
22
 
23
 
 
 
23
#include <glib.h>
 
24
#include <glib-object.h>
24
25
#include <gtk/gtk.h>
25
26
#include <libdbusmenu-gtk/client.h>
26
27
 
28
29
#include <dbus/dbus-glib-bindings.h>
29
30
 
30
31
#include <libindicator/indicator.h>
31
 
INDICATOR_SET_VERSION
32
 
INDICATOR_SET_NAME("users-status-session")
 
32
#include <libindicator/indicator-object.h>
33
33
 
34
34
#include "dbus-shared-names.h"
35
35
#include "status-service-client.h"
36
36
 
 
37
#define INDICATOR_SESSION_TYPE            (indicator_session_get_type ())
 
38
#define INDICATOR_SESSION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SESSION_TYPE, IndicatorSession))
 
39
#define INDICATOR_SESSION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SESSION_TYPE, IndicatorSessionClass))
 
40
#define IS_INDICATOR_SESSION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SESSION_TYPE))
 
41
#define IS_INDICATOR_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SESSION_TYPE))
 
42
#define INDICATOR_SESSION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SESSION_TYPE, IndicatorSessionClass))
 
43
 
 
44
typedef struct _IndicatorSession      IndicatorSession;
 
45
typedef struct _IndicatorSessionClass IndicatorSessionClass;
 
46
 
 
47
struct _IndicatorSessionClass {
 
48
        IndicatorObjectClass parent_class;
 
49
};
 
50
 
 
51
struct _IndicatorSession {
 
52
        IndicatorObject parent;
 
53
};
 
54
 
 
55
GType indicator_session_get_type (void);
 
56
 
 
57
/* Indicator stuff */
 
58
INDICATOR_SET_VERSION
 
59
INDICATOR_SET_TYPE(INDICATOR_SESSION_TYPE)
 
60
 
 
61
/* Globals */
37
62
static DbusmenuGtkClient * status_client = NULL;
38
63
static DbusmenuGtkClient * users_client = NULL;
39
64
static DbusmenuGtkClient * session_client = NULL;
57
82
        END_OF_SECTIONS
58
83
} section_t;
59
84
 
 
85
/* Prototypes */
60
86
static void child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer section);
61
87
static guint status_menu_pos_offset (void);
62
88
static guint users_menu_pos_offset (void);
64
90
static void child_realized (DbusmenuMenuitem * child, gpointer userdata);
65
91
static gboolean start_service (gpointer userdata);
66
92
static void start_service_phase2 (DBusGProxy * proxy, guint status, GError * error, gpointer data);
67
 
 
68
 
GtkLabel *
69
 
get_label (void)
 
93
static GtkLabel * get_label (IndicatorObject * io);
 
94
static GtkImage * get_icon (IndicatorObject * io);
 
95
static GtkMenu * get_menu (IndicatorObject * io);
 
96
 
 
97
static void indicator_session_class_init (IndicatorSessionClass *klass);
 
98
static void indicator_session_init       (IndicatorSession *self);
 
99
static void indicator_session_dispose    (GObject *object);
 
100
static void indicator_session_finalize   (GObject *object);
 
101
 
 
102
G_DEFINE_TYPE (IndicatorSession, indicator_session, INDICATOR_OBJECT_TYPE);
 
103
 
 
104
static void
 
105
indicator_session_class_init (IndicatorSessionClass *klass)
 
106
{
 
107
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
108
 
 
109
        object_class->dispose = indicator_session_dispose;
 
110
        object_class->finalize = indicator_session_finalize;
 
111
 
 
112
        IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);
 
113
        io_class->get_label = get_label;
 
114
        io_class->get_image = get_icon;
 
115
        io_class->get_menu = get_menu;
 
116
 
 
117
        return;
 
118
}
 
119
 
 
120
static void
 
121
indicator_session_init (IndicatorSession *self)
 
122
{
 
123
 
 
124
        return;
 
125
}
 
126
 
 
127
static void
 
128
indicator_session_dispose (GObject *object)
 
129
{
 
130
 
 
131
        G_OBJECT_CLASS (indicator_session_parent_class)->dispose (object);
 
132
        return;
 
133
}
 
134
 
 
135
static void
 
136
indicator_session_finalize (GObject *object)
 
137
{
 
138
 
 
139
        G_OBJECT_CLASS (indicator_session_parent_class)->finalize (object);
 
140
        return;
 
141
}
 
142
 
 
143
static GtkLabel *
 
144
get_label (IndicatorObject * io)
70
145
{
71
146
        GtkLabel * returnval = GTK_LABEL(gtk_label_new(g_get_user_name()));
72
147
        gtk_widget_show(GTK_WIDGET(returnval));
73
148
        return returnval;
74
149
}
75
150
 
76
 
GtkImage *
77
 
get_icon (void)
 
151
static GtkImage *
 
152
get_icon (IndicatorObject * io)
78
153
{
79
154
        g_debug("Changing status icon: '%s'", "system-shutdown-panel");
80
155
        status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU));
260
335
        return;
261
336
}
262
337
 
263
 
void
 
338
static void
264
339
status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata)
265
340
{
266
341
        g_return_if_fail(status_image != NULL);
273
348
        return;
274
349
}
275
350
 
276
 
void
 
351
static void
277
352
status_icon_changed (DBusGProxy * proxy, gchar * icon, gpointer userdata)
278
353
{
279
354
        return status_icon_cb(proxy, icon, NULL, NULL);
540
615
/* Indicator based function to get the menu for the whole
541
616
   applet.  This starts up asking for the parts of the menu
542
617
   from the various services. */
543
 
GtkMenu *
544
 
get_menu (void)
 
618
static GtkMenu *
 
619
get_menu (IndicatorObject * io)
545
620
{
546
621
        connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
547
622
        proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);