~ubuntu-branches/ubuntu/oneiric/xpad/oneiric

« back to all changes in this revision

Viewing changes to src/eggstatusicon.c

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2007-12-10 22:52:37 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071210225237-llvwje5iwbbi5adw
Tags: 2.13-1
* New upstream release.
* debian/patches/01_workspaces.diff: Removed.
* debian/menu: Updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* eggstatusicon.c:
2
 
 *
3
 
 * Copyright (C) 2003 Sun Microsystems, Inc.
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public
16
 
 * License along with this library; if not, write to the
17
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
 
 * Boston, MA 02111-1307, USA.
19
 
 *
20
 
 * Authors:
21
 
 *      Mark McLoughlin <mark@skynet.ie>
22
 
 */
23
 
 
24
 
#include <config.h>
25
 
#include <string.h>
26
 
#include <libintl.h>
27
 
 
28
 
#include "eggstatusicon.h"
29
 
 
30
 
#include <gtk/gtk.h>
31
 
#include "eggmarshalers.h"
32
 
 
33
 
#ifndef EGG_COMPILATION
34
 
#ifndef _
35
 
#define _(x) dgettext (GETTEXT_PACKAGE, x)
36
 
#define N_(x) x
37
 
#endif
38
 
#else
39
 
#define _(x) x
40
 
#define N_(x) x
41
 
#endif
42
 
 
43
 
enum{
44
 
  PROP_0,
45
 
  PROP_PIXBUF,
46
 
  PROP_FILE,
47
 
  PROP_STOCK,
48
 
  PROP_PIXBUF_ANIMATION,
49
 
  PROP_STORAGE_TYPE,
50
 
  PROP_SIZE,
51
 
  PROP_BLINKING
52
 
};
53
 
 
54
 
enum {
55
 
  ACTIVATE_SIGNAL,
56
 
  POPUP_MENU_SIGNAL,
57
 
  SIZE_CHANGED_SIGNAL,
58
 
  LAST_SIGNAL
59
 
};
60
 
 
61
 
struct _EggStatusIconPrivate
62
 
{
63
 
  GtkWidget    *tray_icon;
64
 
  GtkWidget    *image;
65
 
  gint          size;
66
 
 
67
 
  GtkTooltips  *tooltips;
68
 
 
69
 
  GtkImageType  image_type;
70
 
 
71
 
  union
72
 
    {
73
 
      GdkPixbuf          *pixbuf;
74
 
      const gchar        *stock_id;
75
 
      GdkPixbufAnimation *animimation;
76
 
    } image_data;
77
 
 
78
 
  GdkPixbuf    *blank_icon;
79
 
  guint         blinking_timeout;
80
 
 
81
 
  guint         blinking : 1;
82
 
  guint         blink_off : 1;
83
 
};
84
 
 
85
 
static void egg_status_icon_class_init (EggStatusIconClass *klass);
86
 
static void egg_status_icon_init       (EggStatusIcon      *status_icon);
87
 
 
88
 
static void egg_status_icon_finalize     (GObject      *object);
89
 
static void egg_status_icon_set_property (GObject      *object,
90
 
                                          guint         prop_id,
91
 
                                          const GValue *value,
92
 
                                          GParamSpec   *pspec);
93
 
static void egg_status_icon_get_property (GObject      *object,
94
 
                                          guint         prop_id,
95
 
                                          GValue       *value,
96
 
                                          GParamSpec   *pspec);
97
 
 
98
 
static void     egg_status_icon_size_allocate    (EggStatusIcon  *status_icon,
99
 
                                                  GtkAllocation  *allocation);
100
 
static gboolean egg_status_icon_button_press     (EggStatusIcon  *status_icon,
101
 
                                                  GdkEventButton *event);
102
 
static void     egg_status_icon_disable_blinking (EggStatusIcon  *status_icon);
103
 
static void     egg_status_icon_reset_image_data (EggStatusIcon  *status_icon);
104
 
                                           
105
 
 
106
 
static GObjectClass *parent_class = NULL;
107
 
static guint status_icon_signals [LAST_SIGNAL] = { 0 };
108
 
 
109
 
GType
110
 
egg_status_icon_get_type (void)
111
 
{
112
 
  static GType status_icon_type = 0;
113
 
  
114
 
  if (!status_icon_type)
115
 
    {
116
 
      static const GTypeInfo status_icon_info =
117
 
      {
118
 
        sizeof (EggStatusIconClass),
119
 
        NULL,           /* base_init */
120
 
        NULL,           /* base_finalize */
121
 
        (GClassInitFunc) egg_status_icon_class_init,
122
 
        NULL,           /* class_finalize */
123
 
        NULL,           /* class_data */
124
 
        sizeof (EggStatusIcon),
125
 
        0,              /* n_preallocs */
126
 
        (GInstanceInitFunc) egg_status_icon_init,
127
 
      };
128
 
      
129
 
      status_icon_type = g_type_register_static (G_TYPE_OBJECT,
130
 
                                                 "EggStatusIcon",
131
 
                                                 &status_icon_info, 0);
132
 
    }
133
 
  
134
 
  return status_icon_type;
135
 
}
136
 
 
137
 
static void
138
 
egg_status_icon_class_init (EggStatusIconClass *klass)
139
 
{
140
 
  GObjectClass *gobject_class = (GObjectClass *) klass;
141
 
 
142
 
  parent_class = g_type_class_peek_parent (klass);
143
 
 
144
 
  gobject_class->finalize     = egg_status_icon_finalize;
145
 
  gobject_class->set_property = egg_status_icon_set_property;
146
 
  gobject_class->get_property = egg_status_icon_get_property;
147
 
 
148
 
  g_object_class_install_property (gobject_class,
149
 
                                   PROP_PIXBUF,
150
 
                                   g_param_spec_object ("pixbuf",
151
 
                                                        _("Pixbuf"),
152
 
                                                        _("A GdkPixbuf to display"),
153
 
                                                        GDK_TYPE_PIXBUF,
154
 
                                                        G_PARAM_READWRITE));
155
 
 
156
 
  g_object_class_install_property (gobject_class,
157
 
                                   PROP_FILE,
158
 
                                   g_param_spec_string ("file",
159
 
                                                        _("Filename"),
160
 
                                                        _("Filename to load and display"),
161
 
                                                        NULL,
162
 
                                                        G_PARAM_WRITABLE));
163
 
 
164
 
  g_object_class_install_property (gobject_class,
165
 
                                   PROP_STOCK,
166
 
                                   g_param_spec_string ("stock",
167
 
                                                        _("Stock ID"),
168
 
                                                        _("Stock ID for a stock image to display"),
169
 
                                                        NULL,
170
 
                                                        G_PARAM_READWRITE));
171
 
  
172
 
  g_object_class_install_property (gobject_class,
173
 
                                   PROP_PIXBUF_ANIMATION,
174
 
                                   g_param_spec_object ("pixbuf-animation",
175
 
                                                        _("Animation"),
176
 
                                                        _("GdkPixbufAnimation to display"),
177
 
                                                        GDK_TYPE_PIXBUF_ANIMATION,
178
 
                                                        G_PARAM_READWRITE));
179
 
  
180
 
  g_object_class_install_property (gobject_class,
181
 
                                   PROP_STORAGE_TYPE,
182
 
                                   g_param_spec_enum ("image-type",
183
 
                                                      _("Image type"),
184
 
                                                      _("The representation being used for image data"),
185
 
                                                      GTK_TYPE_IMAGE_TYPE,
186
 
                                                      GTK_IMAGE_EMPTY,
187
 
                                                      G_PARAM_READABLE));
188
 
 
189
 
  g_object_class_install_property (gobject_class,
190
 
                                   PROP_SIZE,
191
 
                                   g_param_spec_int ("size",
192
 
                                                     _("Size"),
193
 
                                                     _("The size of the icon"),
194
 
                                                     G_MININT,
195
 
                                                     G_MAXINT,
196
 
                                                     0,
197
 
                                                     G_PARAM_READABLE));
198
 
 
199
 
  g_object_class_install_property (gobject_class,
200
 
                                   PROP_BLINKING,
201
 
                                   g_param_spec_boolean ("blinking",
202
 
                                                         _("Blinking"),
203
 
                                                         _("Whether or not the status icon is blinking"),
204
 
                                                         FALSE,
205
 
                                                         G_PARAM_READWRITE));
206
 
 
207
 
  status_icon_signals [ACTIVATE_SIGNAL] =
208
 
    g_signal_new ("activate",
209
 
                  G_TYPE_FROM_CLASS (gobject_class),
210
 
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
211
 
                  G_STRUCT_OFFSET (EggStatusIconClass, activate),
212
 
                  NULL,
213
 
                  NULL,
214
 
                  g_cclosure_marshal_VOID__VOID,
215
 
                  G_TYPE_NONE,
216
 
                  0);
217
 
 
218
 
  status_icon_signals [POPUP_MENU_SIGNAL] =
219
 
    g_signal_new ("popup-menu",
220
 
                  G_TYPE_FROM_CLASS (gobject_class),
221
 
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
222
 
                  G_STRUCT_OFFSET (EggStatusIconClass, popup_menu),
223
 
                  NULL,
224
 
                  NULL,
225
 
                  eggmarshalers_VOID__UINT_UINT,
226
 
                  G_TYPE_NONE,
227
 
                  2,
228
 
                  G_TYPE_UINT,
229
 
                  G_TYPE_UINT);
230
 
 
231
 
  status_icon_signals [SIZE_CHANGED_SIGNAL] =
232
 
    g_signal_new ("size-changed",
233
 
                  G_TYPE_FROM_CLASS (gobject_class),
234
 
                  G_SIGNAL_RUN_FIRST,
235
 
                  G_STRUCT_OFFSET (EggStatusIconClass, size_changed),
236
 
                  NULL,
237
 
                  NULL,
238
 
                  g_cclosure_marshal_VOID__INT,
239
 
                  G_TYPE_NONE,
240
 
                  1,
241
 
                  G_TYPE_INT);
242
 
}
243
 
 
244
 
gboolean
245
 
egg_status_icon_is_visible (EggStatusIcon *icon)
246
 
{
247
 
        return(icon->priv->tray_icon && EGG_TRAY_ICON (icon->priv->tray_icon)->manager_window != None);
248
 
}
249
 
 
250
 
static void egg_status_icon_destroyed (EggStatusIcon *icon);
251
 
static void
252
 
egg_status_icon_allocate (EggStatusIcon *status_icon)
253
 
{
254
 
  status_icon->priv->image_type = GTK_IMAGE_EMPTY;
255
 
  status_icon->priv->size       = G_MAXINT;
256
 
 
257
 
  status_icon->priv->tray_icon = GTK_WIDGET (egg_tray_icon_new (NULL));
258
 
 
259
 
  gtk_widget_add_events (GTK_WIDGET (status_icon->priv->tray_icon),
260
 
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
261
 
 
262
 
  g_signal_connect_swapped (status_icon->priv->tray_icon, "button-press-event",
263
 
                            G_CALLBACK (egg_status_icon_button_press), status_icon);
264
 
 
265
 
  status_icon->priv->image = gtk_image_new ();
266
 
  gtk_container_add (GTK_CONTAINER (status_icon->priv->tray_icon),
267
 
                     status_icon->priv->image);
268
 
 
269
 
  g_signal_connect_swapped (status_icon->priv->image, "size-allocate",
270
 
                            G_CALLBACK (egg_status_icon_size_allocate), status_icon);
271
 
 
272
 
  g_signal_connect_swapped (status_icon->priv->image, "destroy",
273
 
                            G_CALLBACK (egg_status_icon_destroyed), status_icon);
274
 
 
275
 
  gtk_widget_show (status_icon->priv->image);
276
 
  gtk_widget_show (status_icon->priv->tray_icon);
277
 
 
278
 
  status_icon->priv->tooltips = gtk_tooltips_new ();
279
 
  g_object_ref (status_icon->priv->tooltips);
280
 
  gtk_object_sink (GTK_OBJECT (status_icon->priv->tooltips));
281
 
}
282
 
 
283
 
static gboolean
284
 
egg_status_icon_create_idle (EggStatusIcon *icon)
285
 
{
286
 
        egg_status_icon_allocate (icon);
287
 
        return FALSE;
288
 
}
289
 
 
290
 
static void
291
 
egg_status_icon_destroyed (EggStatusIcon *icon)
292
 
{
293
 
        g_idle_add ((GSourceFunc) egg_status_icon_create_idle, icon);
294
 
}
295
 
 
296
 
static void
297
 
egg_status_icon_init (EggStatusIcon *status_icon)
298
 
{
299
 
  status_icon->priv = g_new0 (EggStatusIconPrivate, 1);
300
 
  egg_status_icon_allocate (status_icon);
301
 
}
302
 
 
303
 
static void
304
 
egg_status_icon_finalize (GObject *object)
305
 
{
306
 
  EggStatusIcon *status_icon = EGG_STATUS_ICON (object);
307
 
 
308
 
  egg_status_icon_disable_blinking (status_icon);
309
 
 
310
 
  egg_status_icon_reset_image_data (status_icon);
311
 
 
312
 
  if (status_icon->priv->blank_icon)
313
 
    g_object_unref (status_icon->priv->blank_icon);
314
 
  status_icon->priv->blank_icon = NULL;
315
 
 
316
 
  if (status_icon->priv->tooltips)
317
 
    g_object_unref (status_icon->priv->tooltips);
318
 
  status_icon->priv->tooltips = NULL;
319
 
 
320
 
  gtk_widget_destroy (status_icon->priv->tray_icon);
321
 
 
322
 
  g_free (status_icon->priv);
323
 
 
324
 
  G_OBJECT_CLASS (parent_class)->finalize (object);
325
 
}
326
 
 
327
 
static void
328
 
egg_status_icon_set_property (GObject      *object,
329
 
                              guint         prop_id,
330
 
                              const GValue *value,
331
 
                              GParamSpec   *pspec)
332
 
{
333
 
  EggStatusIcon *status_icon = EGG_STATUS_ICON (object);
334
 
 
335
 
  switch (prop_id)
336
 
    {
337
 
    case PROP_PIXBUF:
338
 
      egg_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
339
 
      break;
340
 
    case PROP_FILE:
341
 
      egg_status_icon_set_from_file (status_icon, g_value_get_string (value));
342
 
      break;
343
 
    case PROP_STOCK:
344
 
      egg_status_icon_set_from_stock (status_icon, g_value_get_string (value));
345
 
      break;
346
 
    case PROP_PIXBUF_ANIMATION:
347
 
      egg_status_icon_set_from_animation (status_icon, g_value_get_object (value));
348
 
      break;
349
 
    case PROP_BLINKING:
350
 
      egg_status_icon_set_is_blinking (status_icon, g_value_get_boolean (value));
351
 
      break;
352
 
    default:
353
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
354
 
      break;
355
 
    }
356
 
}
357
 
 
358
 
static void
359
 
egg_status_icon_get_property (GObject    *object,
360
 
                              guint       prop_id,
361
 
                              GValue     *value,
362
 
                              GParamSpec *pspec)
363
 
{
364
 
  EggStatusIcon *status_icon = EGG_STATUS_ICON (object);
365
 
 
366
 
  switch (prop_id)
367
 
    {
368
 
    case PROP_PIXBUF:
369
 
      g_value_set_object (value, egg_status_icon_get_pixbuf (status_icon));
370
 
      break;
371
 
    case PROP_STOCK:
372
 
      g_value_set_string (value, egg_status_icon_get_stock (status_icon));
373
 
      break;
374
 
    case PROP_PIXBUF_ANIMATION:
375
 
      g_value_set_object (value, egg_status_icon_get_animation (status_icon));
376
 
      break;
377
 
    case PROP_STORAGE_TYPE:
378
 
      g_value_set_enum (value, egg_status_icon_get_image_type (status_icon));
379
 
      break;
380
 
    case PROP_SIZE:
381
 
      g_value_set_int (value, status_icon->priv->size);
382
 
      break;
383
 
    case PROP_BLINKING:
384
 
      g_value_set_boolean (value, status_icon->priv->blinking);
385
 
      break;
386
 
    default:
387
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
388
 
      break;
389
 
    }
390
 
}
391
 
 
392
 
EggStatusIcon *
393
 
egg_status_icon_new (void)
394
 
{
395
 
  return g_object_new (EGG_TYPE_STATUS_ICON, NULL);
396
 
}
397
 
 
398
 
EggStatusIcon *
399
 
egg_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
400
 
{
401
 
  return g_object_new (EGG_TYPE_STATUS_ICON,
402
 
                       "pixbuf", pixbuf,
403
 
                       NULL);
404
 
}
405
 
 
406
 
EggStatusIcon *
407
 
egg_status_icon_new_from_file (const gchar *filename)
408
 
{
409
 
  return g_object_new (EGG_TYPE_STATUS_ICON,
410
 
                       "file", filename,
411
 
                       NULL);
412
 
}
413
 
 
414
 
EggStatusIcon *
415
 
egg_status_icon_new_from_stock (const gchar *stock_id)
416
 
{
417
 
  return g_object_new (EGG_TYPE_STATUS_ICON,
418
 
                       "stock", stock_id,
419
 
                       NULL);
420
 
}
421
 
 
422
 
EggStatusIcon *
423
 
egg_status_icon_new_from_animation (GdkPixbufAnimation *animation)
424
 
{
425
 
  return g_object_new (EGG_TYPE_STATUS_ICON,
426
 
                       "pixbuf_animation", animation,
427
 
                       NULL);
428
 
}
429
 
 
430
 
static void
431
 
emit_activate_signal (EggStatusIcon *status_icon)
432
 
{
433
 
  g_signal_emit (status_icon,
434
 
                 status_icon_signals [ACTIVATE_SIGNAL], 0);
435
 
}
436
 
 
437
 
static void
438
 
emit_popup_menu_signal (EggStatusIcon *status_icon,
439
 
                        guint          button,
440
 
                        guint32        activate_time)
441
 
{
442
 
  g_signal_emit (status_icon,
443
 
                 status_icon_signals [POPUP_MENU_SIGNAL], 0,
444
 
                 button,
445
 
                 activate_time);
446
 
}
447
 
 
448
 
static gboolean
449
 
emit_size_changed_signal (EggStatusIcon *status_icon,
450
 
                          gint           size)
451
 
{
452
 
  gboolean handled = FALSE;
453
 
  
454
 
  g_signal_emit (status_icon,
455
 
                 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
456
 
                 size,
457
 
                 &handled);
458
 
 
459
 
  return handled;
460
 
}
461
 
 
462
 
static GdkPixbuf *
463
 
egg_status_icon_blank_icon (EggStatusIcon *status_icon)
464
 
{
465
 
  if (status_icon->priv->blank_icon)
466
 
    {
467
 
      gint width, height;
468
 
 
469
 
      width  = gdk_pixbuf_get_width (status_icon->priv->blank_icon);
470
 
      height = gdk_pixbuf_get_width (status_icon->priv->blank_icon);
471
 
 
472
 
      if (width  == status_icon->priv->size &&
473
 
          height == status_icon->priv->size)
474
 
        {
475
 
          return status_icon->priv->blank_icon;
476
 
        }
477
 
      else
478
 
        {
479
 
          g_object_unref (status_icon->priv->blank_icon);
480
 
          status_icon->priv->blank_icon = NULL;
481
 
        }
482
 
    }
483
 
 
484
 
  status_icon->priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
485
 
                                                  status_icon->priv->size,
486
 
                                                  status_icon->priv->size);
487
 
  if (status_icon->priv->blank_icon)
488
 
    gdk_pixbuf_fill (status_icon->priv->blank_icon, 0);
489
 
 
490
 
  return status_icon->priv->blank_icon;
491
 
}
492
 
 
493
 
static void
494
 
egg_status_icon_update_image (EggStatusIcon *status_icon)
495
 
{
496
 
  if (status_icon->priv->blink_off)
497
 
    {
498
 
      gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image),
499
 
                                 egg_status_icon_blank_icon (status_icon));
500
 
      return;
501
 
    }
502
 
 
503
 
  switch (status_icon->priv->image_type)
504
 
    {
505
 
    case GTK_IMAGE_PIXBUF:
506
 
      {
507
 
        GdkPixbuf *pixbuf;
508
 
 
509
 
        pixbuf = status_icon->priv->image_data.pixbuf;
510
 
 
511
 
        if (pixbuf)
512
 
          {
513
 
            GdkPixbuf *scaled;
514
 
            gint size;
515
 
            gint width;
516
 
            gint height;
517
 
 
518
 
            size = status_icon->priv->size;
519
 
 
520
 
            width  = gdk_pixbuf_get_width  (pixbuf);
521
 
            height = gdk_pixbuf_get_height (pixbuf);
522
 
 
523
 
            if (width > size || height > size)
524
 
              {
525
 
                scaled = gdk_pixbuf_scale_simple (pixbuf,
526
 
                                                  MIN (size, width),
527
 
                                                  MIN (size, height),
528
 
                                                  GDK_INTERP_BILINEAR);
529
 
              }
530
 
            else
531
 
              {
532
 
                scaled = g_object_ref (pixbuf);
533
 
              }
534
 
 
535
 
            gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), scaled);
536
 
 
537
 
            g_object_unref (scaled);
538
 
          }
539
 
        else
540
 
          {
541
 
            gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL);
542
 
          }
543
 
      }
544
 
      break;
545
 
    case GTK_IMAGE_STOCK:
546
 
    case GTK_IMAGE_ANIMATION:
547
 
    case GTK_IMAGE_EMPTY:
548
 
      gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL);
549
 
      break;
550
 
    default:
551
 
      g_assert_not_reached ();
552
 
      break;
553
 
    }
554
 
}
555
 
 
556
 
static void
557
 
egg_status_icon_size_allocate (EggStatusIcon *status_icon,
558
 
                               GtkAllocation *allocation)
559
 
{
560
 
  GtkOrientation orientation;
561
 
  gint size;
562
 
 
563
 
  orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->priv->tray_icon));
564
 
 
565
 
  if (orientation == GTK_ORIENTATION_HORIZONTAL)
566
 
    size = allocation->height;
567
 
  else
568
 
    size = allocation->width;
569
 
 
570
 
  if (status_icon->priv->size != size)
571
 
    {
572
 
      status_icon->priv->size = size;
573
 
 
574
 
      g_object_notify (G_OBJECT (status_icon), "size");
575
 
 
576
 
      if (!emit_size_changed_signal (status_icon, size))
577
 
        {
578
 
          egg_status_icon_update_image (status_icon);
579
 
        }
580
 
    }
581
 
}
582
 
 
583
 
static gboolean
584
 
egg_status_icon_button_press (EggStatusIcon  *status_icon,
585
 
                              GdkEventButton *event)
586
 
{
587
 
  if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
588
 
    {
589
 
      emit_activate_signal (status_icon);
590
 
      return TRUE;
591
 
    }
592
 
  else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
593
 
    {
594
 
      emit_popup_menu_signal (status_icon, event->button, event->time);
595
 
      return TRUE;
596
 
    }
597
 
 
598
 
  return FALSE;
599
 
}
600
 
 
601
 
static void
602
 
egg_status_icon_reset_image_data (EggStatusIcon *status_icon)
603
 
{
604
 
  switch (status_icon->priv->image_type)
605
 
  {
606
 
    case GTK_IMAGE_PIXBUF:
607
 
      status_icon->priv->image_type = GTK_IMAGE_EMPTY;
608
 
 
609
 
      if (status_icon->priv->image_data.pixbuf)
610
 
        g_object_unref (status_icon->priv->image_data.pixbuf);
611
 
      status_icon->priv->image_data.pixbuf = NULL;
612
 
 
613
 
      g_object_notify (G_OBJECT (status_icon), "image-type");
614
 
      g_object_notify (G_OBJECT (status_icon), "pixbuf");
615
 
      break;
616
 
    case GTK_IMAGE_STOCK:
617
 
    case GTK_IMAGE_ANIMATION:
618
 
    case GTK_IMAGE_EMPTY:
619
 
      break;
620
 
    default:
621
 
      g_assert_not_reached ();
622
 
      break;
623
 
  }
624
 
}
625
 
 
626
 
void
627
 
egg_status_icon_set_from_pixbuf (EggStatusIcon *status_icon,
628
 
                                 GdkPixbuf     *pixbuf)
629
 
{
630
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
631
 
  g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
632
 
 
633
 
  if (pixbuf)
634
 
    g_object_ref (pixbuf);
635
 
 
636
 
  g_object_freeze_notify (G_OBJECT (status_icon));
637
 
 
638
 
  egg_status_icon_reset_image_data (status_icon);
639
 
 
640
 
  status_icon->priv->image_type = GTK_IMAGE_PIXBUF;
641
 
  status_icon->priv->image_data.pixbuf = pixbuf;
642
 
 
643
 
  g_object_notify (G_OBJECT (status_icon), "image-type");
644
 
  g_object_notify (G_OBJECT (status_icon), "pixbuf");
645
 
 
646
 
  g_object_thaw_notify (G_OBJECT (status_icon));
647
 
 
648
 
  egg_status_icon_update_image (status_icon);
649
 
}
650
 
 
651
 
void
652
 
egg_status_icon_set_from_file (EggStatusIcon *status_icon,
653
 
                               const gchar   *filename)
654
 
{
655
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
656
 
}
657
 
 
658
 
void
659
 
egg_status_icon_set_from_stock (EggStatusIcon *status_icon,
660
 
                                const gchar   *stock_id)
661
 
{
662
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
663
 
}
664
 
 
665
 
void
666
 
egg_status_icon_set_from_animation (EggStatusIcon      *status_icon,
667
 
                                    GdkPixbufAnimation *animation)
668
 
{
669
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
670
 
  g_return_if_fail (animation == NULL || GDK_IS_PIXBUF_ANIMATION (animation));
671
 
}
672
 
                                                                                                             
673
 
GtkImageType
674
 
egg_status_icon_get_image_type (EggStatusIcon *status_icon)
675
 
{
676
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
677
 
 
678
 
  return status_icon->priv->image_type;
679
 
}
680
 
                                                                                                             
681
 
GdkPixbuf *
682
 
egg_status_icon_get_pixbuf (EggStatusIcon *status_icon)
683
 
{
684
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), NULL);
685
 
  g_return_val_if_fail (status_icon->priv->image_type == GTK_IMAGE_PIXBUF ||
686
 
                        status_icon->priv->image_type == GTK_IMAGE_EMPTY, NULL);
687
 
                                                                                                             
688
 
  if (status_icon->priv->image_type == GTK_IMAGE_EMPTY)
689
 
    status_icon->priv->image_data.pixbuf = NULL;
690
 
                                                                                                             
691
 
  return status_icon->priv->image_data.pixbuf;
692
 
}
693
 
 
694
 
G_CONST_RETURN gchar *
695
 
egg_status_icon_get_stock (EggStatusIcon *status_icon)
696
 
{
697
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), NULL);
698
 
 
699
 
  return NULL;
700
 
}
701
 
 
702
 
GdkPixbufAnimation *
703
 
egg_status_icon_get_animation (EggStatusIcon *status_icon)
704
 
{
705
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), NULL);
706
 
 
707
 
  return NULL;
708
 
}
709
 
                                                                                                             
710
 
gint
711
 
egg_status_icon_get_size (EggStatusIcon *status_icon)
712
 
{
713
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), -1);
714
 
 
715
 
  return status_icon->priv->size;
716
 
}
717
 
                                                                                                             
718
 
void
719
 
egg_status_icon_set_tooltip (EggStatusIcon *status_icon,
720
 
                             const gchar   *tooltip_text,
721
 
                             const gchar   *tooltip_private)
722
 
{
723
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
724
 
 
725
 
  gtk_tooltips_set_tip (status_icon->priv->tooltips,
726
 
                        status_icon->priv->tray_icon,
727
 
                        tooltip_text,
728
 
                        tooltip_private);
729
 
}
730
 
 
731
 
void
732
 
egg_status_icon_set_balloon_text (EggStatusIcon *status_icon,
733
 
                                  const gchar   *text)
734
 
{
735
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
736
 
}
737
 
 
738
 
G_CONST_RETURN gchar *
739
 
egg_status_icon_get_balloon_text (EggStatusIcon *status_icon)
740
 
{
741
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), NULL);
742
 
 
743
 
  return NULL;
744
 
}
745
 
 
746
 
static gboolean
747
 
egg_status_icon_blinker (EggStatusIcon *status_icon)
748
 
{
749
 
  status_icon->priv->blink_off = !status_icon->priv->blink_off;
750
 
 
751
 
  egg_status_icon_update_image (status_icon);
752
 
 
753
 
  return TRUE;
754
 
}
755
 
 
756
 
static void
757
 
egg_status_icon_enable_blinking (EggStatusIcon *status_icon)
758
 
{
759
 
  if (!status_icon->priv->blinking_timeout)
760
 
    {
761
 
      egg_status_icon_blinker (status_icon);
762
 
 
763
 
      status_icon->priv->blinking_timeout =
764
 
        g_timeout_add (500, (GSourceFunc) egg_status_icon_blinker, status_icon);
765
 
    }
766
 
}
767
 
 
768
 
static void
769
 
egg_status_icon_disable_blinking (EggStatusIcon *status_icon)
770
 
{
771
 
  if (status_icon->priv->blinking_timeout)
772
 
    {
773
 
      g_source_remove (status_icon->priv->blinking_timeout);
774
 
      status_icon->priv->blinking_timeout = 0;
775
 
      status_icon->priv->blink_off = FALSE;
776
 
 
777
 
      egg_status_icon_update_image (status_icon);
778
 
    }
779
 
}
780
 
 
781
 
void
782
 
egg_status_icon_set_is_blinking (EggStatusIcon *status_icon,
783
 
                                 gboolean       is_blinking)
784
 
{
785
 
  g_return_if_fail (EGG_IS_STATUS_ICON (status_icon));
786
 
 
787
 
  is_blinking = is_blinking != FALSE;
788
 
 
789
 
  if (status_icon->priv->blinking != is_blinking)
790
 
    {
791
 
      status_icon->priv->blinking = is_blinking;
792
 
 
793
 
      if (is_blinking)
794
 
        egg_status_icon_enable_blinking (status_icon);
795
 
      else
796
 
        egg_status_icon_disable_blinking (status_icon);
797
 
 
798
 
      g_object_notify (G_OBJECT (status_icon), "blinking");
799
 
    }
800
 
}
801
 
 
802
 
gboolean
803
 
egg_status_icon_get_is_blinking (EggStatusIcon *status_icon)
804
 
{
805
 
  g_return_val_if_fail (EGG_IS_STATUS_ICON (status_icon), FALSE);
806
 
 
807
 
  return status_icon->priv->blinking;
808
 
}