~mefrio-g/+junk/indicator-session-pantheon-shutdown

« back to all changes in this revision

Viewing changes to src/user-widget.c

  • Committer: cody at elementaryos
  • Date: 2012-12-10 00:13:38 UTC
  • Revision ID: cody@elementaryos.org-20121210001338-379sxx4jo6r003d6
Initial import, version 0.3.96-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2011 Canonical Ltd.
 
3
 
 
4
Authors:
 
5
    Conor Curran <conor.curran@canonical.com>
 
6
    Mirco Müller <mirco.mueller@canonical.com>
 
7
 
 
8
This program is free software: you can redistribute it and/or modify it 
 
9
under the terms of the GNU General Public License version 3, as published 
 
10
by the Free Software Foundation.
 
11
 
 
12
This program is distributed in the hope that it will be useful, but 
 
13
WITHOUT ANY WARRANTY; without even the implied warranties of 
 
14
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
15
PURPOSE.  See the GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License along 
 
18
with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "config.h"
 
23
#endif
 
24
 
 
25
#include <glib/gi18n.h>
 
26
#include <gtk/gtk.h>
 
27
#include <glib.h>
 
28
#include <math.h>
 
29
#include <libindicator/indicator-image-helper.h>
 
30
#include "user-widget.h"
 
31
#include "dbus-shared-names.h"
 
32
 
 
33
 
 
34
typedef struct _UserWidgetPrivate UserWidgetPrivate;
 
35
 
 
36
struct _UserWidgetPrivate
 
37
{
 
38
  DbusmenuMenuitem* twin_item;
 
39
  GtkWidget* user_image;
 
40
  gboolean using_personal_icon;
 
41
  GtkWidget* user_name;
 
42
  GtkWidget* container;
 
43
  GtkWidget* tick_icon;
 
44
  gboolean logged_in;
 
45
  gboolean sessions_active;
 
46
};
 
47
 
 
48
#define USER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USER_WIDGET_TYPE, UserWidgetPrivate))
 
49
 
 
50
typedef struct
 
51
{
 
52
  double r;
 
53
  double g;
 
54
  double b;
 
55
} CairoColorRGB;
 
56
 
 
57
/* Prototypes */
 
58
static void user_widget_class_init    (UserWidgetClass *klass);
 
59
static void user_widget_init          (UserWidget *self);
 
60
static void user_widget_dispose       (GObject *object);
 
61
static void user_widget_finalize      (GObject *object);
 
62
 
 
63
static void user_widget_set_twin_item (UserWidget* self,
 
64
                                       DbusmenuMenuitem* twin_item);
 
65
// keyevent consumers
 
66
static gboolean user_widget_button_release_event (GtkWidget *menuitem, 
 
67
                                                  GdkEventButton *event);
 
68
// Dbusmenuitem properties update callback
 
69
static void user_widget_property_update (DbusmenuMenuitem* item,
 
70
                                         gchar* property, 
 
71
                                         GVariant* value,
 
72
                                         gpointer userdata);
 
73
                                         
 
74
 
 
75
static void _color_shade (const CairoColorRGB *a,
 
76
                          float k,
 
77
                          CairoColorRGB *b);                                         
 
78
 
 
79
static void draw_album_border (GtkWidget *widget, gboolean selected);
 
80
                                         
 
81
#if GTK_CHECK_VERSION(3, 0, 0)
 
82
static gboolean user_widget_primitive_draw_cb_gtk_3 (GtkWidget *image,
 
83
                                                         cairo_t* cr,
 
84
                                                         gpointer user_data);
 
85
static gboolean user_widget_draw_usericon_gtk_3 (GtkWidget *widget,
 
86
                                                 cairo_t* cr,
 
87
                                                 gpointer user_data);
 
88
                                                         
 
89
#else
 
90
static gboolean user_widget_primitive_draw_cb (GtkWidget *image,
 
91
                                                   GdkEventExpose *event,
 
92
                                                   gpointer user_data);
 
93
static gboolean user_widget_draw_usericon_gtk_2 (GtkWidget *widget,
 
94
                                                 GdkEventExpose *event,
 
95
                                                 gpointer user_data);
 
96
                                                   
 
97
#endif
 
98
 
 
99
G_DEFINE_TYPE (UserWidget, user_widget, GTK_TYPE_MENU_ITEM);
 
100
 
 
101
static void
 
102
user_widget_class_init (UserWidgetClass *klass)
 
103
{
 
104
  GObjectClass      *gobject_class = G_OBJECT_CLASS (klass);
 
105
  GtkWidgetClass    *widget_class = GTK_WIDGET_CLASS (klass);
 
106
 
 
107
  widget_class->button_release_event = user_widget_button_release_event;
 
108
  
 
109
  g_type_class_add_private (klass, sizeof (UserWidgetPrivate));
 
110
 
 
111
  gobject_class->dispose = user_widget_dispose;
 
112
  gobject_class->finalize = user_widget_finalize;
 
113
}
 
114
 
 
115
static void
 
116
user_widget_init (UserWidget *self)
 
117
{
 
118
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(self);
 
119
  
 
120
        gint padding = 0;
 
121
        gtk_widget_style_get (GTK_WIDGET(self),
 
122
                        "horizontal-padding",
 
123
                        &padding,
 
124
                        NULL);
 
125
  
 
126
  priv->user_image = NULL;
 
127
  priv->user_name  = NULL;
 
128
  priv->logged_in = FALSE;
 
129
  priv->sessions_active = FALSE;
 
130
  priv->container = NULL;
 
131
  priv->tick_icon = NULL;
 
132
  
 
133
  // Create the UI elements.  
 
134
  priv->user_image = gtk_image_new ();
 
135
        gtk_misc_set_alignment(GTK_MISC(priv->user_image), 0.0, 0.0);
 
136
  gtk_misc_set_padding (GTK_MISC(priv->user_image),0, 4.0);
 
137
  
 
138
  priv->user_name = gtk_label_new ("");
 
139
 
 
140
#if HAVE_GTK3
 
141
  priv->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
142
#else
 
143
  priv->container = gtk_hbox_new (FALSE, 0);
 
144
#endif
 
145
 
 
146
        priv->tick_icon = gtk_image_new_from_icon_name ("account-logged-in",
 
147
                                                   GTK_ICON_SIZE_MENU);
 
148
        gtk_misc_set_alignment(GTK_MISC(priv->tick_icon), 1.0, 0.5);
 
149
  
 
150
  // Pack it together
 
151
  gtk_box_pack_start (GTK_BOX (priv->container),
 
152
                      priv->user_image,
 
153
                      FALSE,
 
154
                      FALSE,
 
155
                      0);   
 
156
  gtk_box_pack_start (GTK_BOX (priv->container),
 
157
                      priv->user_name,
 
158
                      FALSE,
 
159
                      FALSE,
 
160
                      3);                       
 
161
        gtk_box_pack_start (GTK_BOX(priv->container),
 
162
                      priv->tick_icon,
 
163
                      FALSE,
 
164
                      FALSE, 5);
 
165
  
 
166
  gtk_widget_show_all (priv->container);  
 
167
  gtk_container_add (GTK_CONTAINER (self), priv->container);    
 
168
  gtk_widget_show_all (priv->tick_icon);
 
169
  gtk_widget_set_no_show_all (priv->tick_icon, TRUE);
 
170
  gtk_widget_hide (priv->tick_icon);
 
171
  
 
172
  
 
173
  // Fetch the drawing context.
 
174
  #if GTK_CHECK_VERSION(3, 0, 0) 
 
175
  g_signal_connect_after (GTK_WIDGET(self), "draw", 
 
176
                          G_CALLBACK(user_widget_primitive_draw_cb_gtk_3),
 
177
                          GTK_WIDGET(self));
 
178
 
 
179
  g_signal_connect_after (GTK_WIDGET(priv->user_image), "draw", 
 
180
                          G_CALLBACK(user_widget_draw_usericon_gtk_3),
 
181
                          GTK_WIDGET(self));
 
182
                          
 
183
  #else
 
184
  g_signal_connect_after (GTK_WIDGET(self), "expose-event", 
 
185
                          G_CALLBACK(user_widget_primitive_draw_cb),
 
186
                          GTK_WIDGET(self));  
 
187
  g_signal_connect_after (GTK_WIDGET(priv->user_image), "expose-event", 
 
188
                          G_CALLBACK(user_widget_draw_usericon_gtk_2),
 
189
                          GTK_WIDGET(self));
 
190
  #endif  
 
191
}
 
192
 
 
193
static void
 
194
user_widget_dispose (GObject *object)
 
195
{
 
196
  G_OBJECT_CLASS (user_widget_parent_class)->dispose (object);
 
197
}
 
198
 
 
199
// TODO tidy up image and name
 
200
static void
 
201
user_widget_finalize (GObject *object)
 
202
{
 
203
  G_OBJECT_CLASS (user_widget_parent_class)->finalize (object);
 
204
}
 
205
 
 
206
 
 
207
/*****************************************************************/
 
208
 
 
209
#if GTK_CHECK_VERSION(3, 0, 0)  
 
210
 
 
211
// TODO handle drawing of green check mark
 
212
static gboolean
 
213
user_widget_primitive_draw_cb_gtk_3 (GtkWidget *widget,
 
214
                                     cairo_t* cr,
 
215
                                     gpointer user_data)
 
216
{
 
217
        
 
218
  g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE);
 
219
  UserWidget* meta = USER_WIDGET(user_data);
 
220
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta);  
 
221
 
 
222
  // Draw dot only when user is the current user.
 
223
  if (!dbusmenu_menuitem_property_get_bool (priv->twin_item,
 
224
                                            USER_ITEM_PROP_IS_CURRENT_USER)){
 
225
    return FALSE;                                           
 
226
  }
 
227
  
 
228
  GtkStyle *style;
 
229
  gdouble x, y;  
 
230
  style = gtk_widget_get_style (widget);
 
231
  
 
232
  GtkAllocation allocation;
 
233
  gtk_widget_get_allocation (widget, &allocation);
 
234
  x = allocation.x + 13;        
 
235
  y = allocation.height / 2;
 
236
  
 
237
  cairo_arc (cr, x, y, 3.0, 0.0, 2 * G_PI);;
 
238
  
 
239
  cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
 
240
                            style->fg[gtk_widget_get_state(widget)].green/65535.0,
 
241
                            style->fg[gtk_widget_get_state(widget)].blue/65535.0);
 
242
  cairo_fill (cr);                                             
 
243
 
 
244
  return FALSE;  
 
245
}
 
246
 
 
247
static gboolean
 
248
user_widget_draw_usericon_gtk_3 (GtkWidget *widget,
 
249
                                 cairo_t* cr,
 
250
                                 gpointer user_data)
 
251
{
 
252
  g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE);
 
253
  UserWidget* meta = USER_WIDGET(user_data);
 
254
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta);  
 
255
 
 
256
  if (priv->using_personal_icon == FALSE)
 
257
    return FALSE;
 
258
  
 
259
  draw_album_border (widget, FALSE);  
 
260
  return FALSE;
 
261
}
 
262
/**
 
263
 * TODO:
 
264
 * Sort out gtk2
 
265
 */
 
266
// GTK 2 Expose handler
 
267
#else
 
268
 
 
269
static gboolean
 
270
user_widget_draw_usericon_gtk_2 (GtkWidget *widget,
 
271
                                 GdkEventExpose *event,
 
272
                                 gpointer user_data)
 
273
{
 
274
  g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE);
 
275
  UserWidget* meta = USER_WIDGET(user_data);
 
276
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta);  
 
277
 
 
278
  if (priv->using_personal_icon == FALSE)
 
279
    return FALSE;
 
280
  
 
281
  draw_album_border (widget, FALSE);  
 
282
  return FALSE;
 
283
}
 
284
 
 
285
static gboolean
 
286
user_widget_primitive_draw_cb (GtkWidget *widget,
 
287
                               GdkEventExpose *event,
 
288
                               gpointer user_data)
 
289
{
 
290
  g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE);
 
291
  UserWidget* meta = USER_WIDGET(user_data);
 
292
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta);  
 
293
 
 
294
  // Draw dot only when user is the current user.
 
295
  if (!dbusmenu_menuitem_property_get_bool (priv->twin_item,
 
296
                                            USER_ITEM_PROP_IS_CURRENT_USER)){
 
297
    return FALSE;                                           
 
298
  }
 
299
  
 
300
  GtkStyle *style;
 
301
  cairo_t *cr;
 
302
  cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));  
 
303
  
 
304
  gdouble x, y;  
 
305
  style = gtk_widget_get_style (widget);
 
306
 
 
307
  GtkAllocation allocation;
 
308
  
 
309
  gtk_widget_get_allocation (widget, &allocation);
 
310
  x = allocation.x + 13;        
 
311
  y = allocation.y + allocation.height/2;
 
312
  
 
313
  cairo_arc (cr, x, y, 3.0, 0.0, 2 * G_PI);;
 
314
  
 
315
  cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
 
316
                            style->fg[gtk_widget_get_state(widget)].green/65535.0,
 
317
                            style->fg[gtk_widget_get_state(widget)].blue/65535.0);
 
318
  cairo_fill (cr);      
 
319
  cairo_destroy (cr);
 
320
 
 
321
  return FALSE;  
 
322
}
 
323
#endif
 
324
 
 
325
 
 
326
static void
 
327
draw_album_border(GtkWidget *widg, gboolean selected)
 
328
{
 
329
  cairo_t *cr;  
 
330
  cr = gdk_cairo_create (gtk_widget_get_window (widg));
 
331
  #if GTK_CHECK_VERSION(3, 0, 0)
 
332
  gtk_style_context_add_class (gtk_widget_get_style_context (widg),
 
333
                               "menu");
 
334
  #endif
 
335
  
 
336
  GtkStyle *style;
 
337
  style = gtk_widget_get_style (widg);
 
338
  
 
339
  GtkAllocation alloc;
 
340
  gtk_widget_get_allocation (widg, &alloc);
 
341
  gint offset = 0;
 
342
  gint v_offset = 4;
 
343
  
 
344
  alloc.width = alloc.width + (offset * 2);
 
345
  alloc.height = alloc.height - v_offset - 2;
 
346
  alloc.x = alloc.x - offset;
 
347
  alloc.y = alloc.y + v_offset/2 +1;
 
348
 
 
349
  CairoColorRGB bg_normal, fg_normal;
 
350
 
 
351
  bg_normal.r = style->bg[0].red/65535.0;
 
352
  bg_normal.g = style->bg[0].green/65535.0;
 
353
  bg_normal.b = style->bg[0].blue/65535.0;
 
354
 
 
355
  gint state = selected ? 5 : 0;
 
356
  
 
357
  fg_normal.r = style->fg[state].red/65535.0;
 
358
  fg_normal.g = style->fg[state].green/65535.0;
 
359
  fg_normal.b = style->fg[state].blue/65535.0;
 
360
 
 
361
  CairoColorRGB dark_top_color;
 
362
  CairoColorRGB light_bottom_color;
 
363
  CairoColorRGB background_color;
 
364
  
 
365
  _color_shade ( &bg_normal, 0.93, &background_color );
 
366
  _color_shade ( &bg_normal, 0.23, &dark_top_color );
 
367
  _color_shade ( &fg_normal, 0.55, &light_bottom_color );
 
368
  
 
369
  cairo_rectangle (cr,
 
370
                   alloc.x, alloc.y,
 
371
                   alloc.width, alloc.height);
 
372
 
 
373
  cairo_set_line_width (cr, 1.0);
 
374
  
 
375
  cairo_clip ( cr );
 
376
 
 
377
  cairo_move_to (cr, alloc.x, alloc.y );
 
378
  cairo_line_to (cr, alloc.x + alloc.width,
 
379
                alloc.y );
 
380
  cairo_line_to ( cr, alloc.x + alloc.width,
 
381
                  alloc.y + alloc.height );
 
382
  cairo_line_to ( cr, alloc.x, alloc.y + alloc.height );
 
383
  cairo_line_to ( cr, alloc.x, alloc.y);
 
384
  cairo_close_path (cr);
 
385
 
 
386
  cairo_set_source_rgba ( cr,
 
387
                          background_color.r,
 
388
                          background_color.g,
 
389
                          background_color.b,
 
390
                          1.0 );
 
391
  
 
392
  cairo_stroke ( cr );
 
393
  
 
394
  cairo_move_to (cr, alloc.x, alloc.y );
 
395
  cairo_line_to (cr, alloc.x + alloc.width,
 
396
                alloc.y );
 
397
 
 
398
  cairo_close_path (cr);
 
399
  cairo_set_source_rgba ( cr,
 
400
                          dark_top_color.r,
 
401
                          dark_top_color.g,
 
402
                          dark_top_color.b,
 
403
                          1.0 );
 
404
  
 
405
  cairo_stroke ( cr );
 
406
  
 
407
  cairo_move_to ( cr, alloc.x + alloc.width,
 
408
                  alloc.y + alloc.height );
 
409
  cairo_line_to ( cr, alloc.x, alloc.y + alloc.height );
 
410
 
 
411
  cairo_close_path (cr);
 
412
  cairo_set_source_rgba ( cr,
 
413
                         light_bottom_color.r,
 
414
                         light_bottom_color.g,
 
415
                         light_bottom_color.b,
 
416
                         1.0);
 
417
  
 
418
  cairo_stroke ( cr );
 
419
  cairo_destroy (cr);   
 
420
}
 
421
 
 
422
static void
 
423
_color_rgb_to_hls (gdouble *r,
 
424
                   gdouble *g,
 
425
                   gdouble *b)
 
426
{
 
427
  gdouble min;
 
428
  gdouble max;
 
429
  gdouble red;
 
430
  gdouble green;
 
431
  gdouble blue;
 
432
  gdouble h = 0;
 
433
  gdouble l;
 
434
  gdouble s;
 
435
  gdouble delta;
 
436
 
 
437
  red = *r;
 
438
  green = *g;
 
439
  blue = *b;
 
440
 
 
441
  if (red > green)
 
442
  {
 
443
    if (red > blue)
 
444
      max = red;
 
445
    else
 
446
      max = blue;
 
447
 
 
448
    if (green < blue)
 
449
      min = green;
 
450
    else
 
451
    min = blue;
 
452
  }
 
453
  else
 
454
  {
 
455
    if (green > blue)
 
456
      max = green;
 
457
    else
 
458
    max = blue;
 
459
 
 
460
    if (red < blue)
 
461
      min = red;
 
462
    else
 
463
      min = blue;
 
464
  }
 
465
  l = (max+min)/2;
 
466
  if (fabs (max-min) < 0.0001)
 
467
  {
 
468
    h = 0;
 
469
    s = 0;
 
470
  }
 
471
  else
 
472
  {
 
473
    if (l <= 0.5)
 
474
    s = (max-min)/(max+min);
 
475
    else
 
476
    s = (max-min)/(2-max-min);
 
477
 
 
478
    delta = (max -min) != 0 ? (max -min) : 1;
 
479
    
 
480
    if(delta == 0)
 
481
      delta = 1;
 
482
    if (red == max)
 
483
      h = (green-blue)/delta;
 
484
    else if (green == max)
 
485
      h = 2+(blue-red)/delta;
 
486
    else if (blue == max)
 
487
      h = 4+(red-green)/delta;
 
488
 
 
489
    h *= 60;
 
490
    if (h < 0.0)
 
491
      h += 360;
 
492
  }
 
493
 
 
494
  *r = h;
 
495
  *g = l;
 
496
  *b = s;
 
497
}
 
498
 
 
499
static void
 
500
_color_hls_to_rgb (gdouble *h,
 
501
                   gdouble *l, 
 
502
                   gdouble *s)
 
503
{
 
504
  gdouble hue;
 
505
  gdouble lightness;
 
506
  gdouble saturation;
 
507
  gdouble m1, m2;
 
508
  gdouble r, g, b;
 
509
 
 
510
  lightness = *l;
 
511
  saturation = *s;
 
512
 
 
513
  if (lightness <= 0.5)
 
514
    m2 = lightness*(1+saturation);
 
515
  else
 
516
    m2 = lightness+saturation-lightness*saturation;
 
517
 
 
518
  m1 = 2*lightness-m2;
 
519
 
 
520
  if (saturation == 0)
 
521
  {
 
522
    *h = lightness;
 
523
    *l = lightness;
 
524
    *s = lightness;
 
525
  }
 
526
  else
 
527
  {
 
528
    hue = *h+120;
 
529
    while (hue > 360)
 
530
      hue -= 360;
 
531
    while (hue < 0)
 
532
      hue += 360;
 
533
 
 
534
    if (hue < 60)
 
535
      r = m1+(m2-m1)*hue/60;
 
536
    else if (hue < 180)
 
537
      r = m2;
 
538
    else if (hue < 240)
 
539
      r = m1+(m2-m1)*(240-hue)/60;
 
540
    else
 
541
      r = m1;
 
542
 
 
543
    hue = *h;
 
544
    while (hue > 360)
 
545
      hue -= 360;
 
546
    while (hue < 0)
 
547
      hue += 360;
 
548
 
 
549
    if (hue < 60)
 
550
      g = m1+(m2-m1)*hue/60;
 
551
    else if (hue < 180)
 
552
      g = m2;
 
553
    else if (hue < 240)
 
554
      g = m1+(m2-m1)*(240-hue)/60;
 
555
    else
 
556
      g = m1;
 
557
 
 
558
    hue = *h-120;
 
559
    while (hue > 360)
 
560
      hue -= 360;
 
561
    while (hue < 0)
 
562
      hue += 360;
 
563
 
 
564
    if (hue < 60)
 
565
      b = m1+(m2-m1)*hue/60;
 
566
    else if (hue < 180)
 
567
      b = m2;
 
568
    else if (hue < 240)
 
569
      b = m1+(m2-m1)*(240-hue)/60;
 
570
    else
 
571
      b = m1;
 
572
 
 
573
    *h = r;
 
574
    *l = g;
 
575
    *s = b;
 
576
  }
 
577
}
 
578
 
 
579
void
 
580
_color_shade (const CairoColorRGB *a, float k, CairoColorRGB *b)
 
581
{
 
582
  double red;
 
583
  double green;
 
584
  double blue;
 
585
 
 
586
  red   = a->r;
 
587
  green = a->g;
 
588
  blue  = a->b;
 
589
 
 
590
  if (k == 1.0)
 
591
  {
 
592
    b->r = red;
 
593
    b->g = green;
 
594
    b->b = blue;
 
595
    return;
 
596
  }
 
597
 
 
598
  _color_rgb_to_hls (&red, &green, &blue);
 
599
 
 
600
  green *= k;
 
601
  if (green > 1.0)
 
602
    green = 1.0;
 
603
  else if (green < 0.0)
 
604
    green = 0.0;
 
605
 
 
606
  blue *= k;
 
607
  if (blue > 1.0)
 
608
    blue = 1.0;
 
609
  else if (blue < 0.0)
 
610
    blue = 0.0;
 
611
 
 
612
  _color_hls_to_rgb (&red, &green, &blue);
 
613
 
 
614
  b->r = red;
 
615
  b->g = green;
 
616
  b->b = blue;
 
617
}
 
618
 
 
619
 
 
620
/*****************************************************************/
 
621
 
 
622
/* Suppress/consume keyevents */
 
623
static gboolean
 
624
user_widget_button_release_event (GtkWidget *menuitem, 
 
625
                                      GdkEventButton *event)
 
626
{
 
627
  return FALSE;
 
628
}
 
629
 
 
630
 
 
631
/** 
 
632
 * TODO, be sensitive to UI updates
 
633
 * */
 
634
static void 
 
635
user_widget_property_update (DbusmenuMenuitem* item, gchar* property, 
 
636
                             GVariant* value, gpointer userdata)
 
637
{
 
638
  g_return_if_fail (IS_USER_WIDGET (userdata)); 
 
639
  //gtk_widget_queue_redraw (GTK_WIDGET(userdata));
 
640
}
 
641
 
 
642
 
 
643
 
 
644
 
 
645
static void
 
646
user_widget_set_twin_item (UserWidget* self,
 
647
                           DbusmenuMenuitem* twin_item)
 
648
{
 
649
  UserWidgetPrivate* priv = USER_WIDGET_GET_PRIVATE(self);
 
650
  priv->twin_item = twin_item;
 
651
  g_signal_connect( G_OBJECT(priv->twin_item), "property-changed", 
 
652
                    G_CALLBACK(user_widget_property_update), self);
 
653
 
 
654
  const gchar * icon_name = dbusmenu_menuitem_property_get (twin_item,
 
655
                                                            USER_ITEM_PROP_ICON);
 
656
  gtk_label_set_label (GTK_LABEL (priv->user_name),
 
657
                       dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME));
 
658
 
 
659
        if (dbusmenu_menuitem_property_get_bool (twin_item, USER_ITEM_PROP_LOGGED_IN)) {
 
660
    g_debug ("%s USER HAS ACTIVE SESSIONS", 
 
661
             dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME));
 
662
          gtk_widget_show(priv->tick_icon);
 
663
        }
 
664
  else {
 
665
    g_debug ("%s USER DOESN'T HAVE ACTIVE SESSIONS", 
 
666
             dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME));
 
667
    gtk_widget_hide(priv->tick_icon);
 
668
        }
 
669
 
 
670
  GdkPixbuf* pixbuf  = NULL; 
 
671
  GError* error = NULL;
 
672
  pixbuf = gdk_pixbuf_new_from_file_at_size(icon_name, 32, 32, NULL);
 
673
 
 
674
  if (pixbuf == NULL || error != NULL) {
 
675
    g_warning ("Could not load the user image (%s) for some reason",
 
676
                icon_name);
 
677
    if (pixbuf != NULL){
 
678
      g_object_unref (pixbuf);
 
679
      pixbuf = NULL;
 
680
    }
 
681
    if (error != NULL){
 
682
      g_error_free (error);
 
683
      error = NULL;
 
684
    }
 
685
    
 
686
    priv->using_personal_icon = FALSE;
 
687
    
 
688
    pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
 
689
                                       USER_ITEM_ICON_DEFAULT,
 
690
                                       32,
 
691
                                       GTK_ICON_LOOKUP_FORCE_SIZE,
 
692
                                       &error);                
 
693
  }
 
694
  else{
 
695
    priv->using_personal_icon = TRUE;
 
696
  }    
 
697
 
 
698
  if (pixbuf == NULL || error != NULL) {
 
699
    g_warning ("Could not load the user image");
 
700
    if (error != NULL){
 
701
      g_error_free (error);
 
702
      error = NULL;
 
703
    }                    
 
704
  }  
 
705
  else{
 
706
    gtk_image_set_from_pixbuf (GTK_IMAGE(priv->user_image), pixbuf);
 
707
  }
 
708
  if (pixbuf != NULL){
 
709
    g_object_unref (pixbuf);  
 
710
    pixbuf = NULL;
 
711
  }
 
712
}
 
713
 
 
714
 /**
 
715
 * transport_new:
 
716
 * @returns: a new #UserWidget.
 
717
 **/
 
718
GtkWidget* 
 
719
user_widget_new(DbusmenuMenuitem *item)
 
720
{
 
721
  GtkWidget* widget =  g_object_new(USER_WIDGET_TYPE, NULL);
 
722
  user_widget_set_twin_item ( USER_WIDGET(widget), item );
 
723
  return widget;                  
 
724
}