~ubuntu-branches/debian/sid/link-monitor-applet/sid

« back to all changes in this revision

Viewing changes to src/lm-applet.gob

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-03-30 22:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080330222613-5aubcuo9mgg2n7st
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004-2006 Jean-Yves Lefort <jylefort@brutele.be>
 
2
 * Link Monitor Applet
 
3
 * Copyright (C) 2004-2008 Jean-Yves Lefort <jylefort@brutele.be>
3
4
 *
4
5
 * This program is free software; you can redistribute it and/or modify
5
6
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * the Free Software Foundation; either version 3 of the License, or
7
8
 * (at your option) any later version.
8
9
 *
9
10
 * This program is distributed in the hope that it will be useful,
11
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
13
 * GNU General Public License for more details.
13
14
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
 */
18
19
 
19
 
requires 2.0.14
20
 
 
21
20
%headertop{
22
 
#include "config.h"
23
21
#include <gnome.h>
24
22
#include <panel-applet.h>
25
23
#include "lm-host.h"
30
28
%}
31
29
 
32
30
%{
33
 
#include "config.h"
34
31
#include <string.h>
 
32
#include <glib/gi18n.h>
35
33
#include <panel-applet-gconf.h>
36
 
#include <eel/eel.h>
37
34
#include "lm-util.h"
38
35
#include "lm-preferences-dialog.h"
39
36
#include "lm-about-dialog.h"
40
37
#include "lm-icmp.h"
41
38
#include "lm-host-frontend.h"
 
39
#include "lm-bar-graph.h"
 
40
#include "lm-line-graph.h"
 
41
#include "lm-line-graph-icon.h"
 
42
#include "lm-color-generator.h"
42
43
 
43
44
#define ICON_PADDING                    1
44
45
 
45
46
#define BAR_SPACING                     3
46
47
 
 
48
#define NUM_HOST_COLORS                 500
 
49
 
47
50
#define CONF_HOSTS                      "hosts"
48
51
#define CONF_DELAY                      "delay"
49
 
#define CONF_TIMEOUT                    "timeout"
50
52
#define CONF_SCALE                      "scale"
 
53
#define CONF_TOOLTIP_GRAPH_SPAN         "tooltip_graph_span"
51
54
#define CONF_PREFERENCES_WIDTH          "preferences_width"
52
55
#define CONF_PREFERENCES_HEIGHT         "preferences_height"
53
56
 
54
57
/* keep in sync with link-monitor-applet.schemas */
 
58
 
 
59
#define DEFAULT_DELAY                   1000
 
60
#define DEFAULT_SCALE                   500
 
61
#define DEFAULT_TOOLTIP_GRAPH_SPAN      60
55
62
#define DEFAULT_PREFERENCES_WIDTH       -1
56
 
#define DEFAULT_PREFERENCES_HEIGHT      387
57
 
 
58
 
/* keep in sync with preferences.glade */
59
 
#define MIN_DELAY                       1000
60
 
#define MIN_TIMEOUT                     100
 
63
#define DEFAULT_PREFERENCES_HEIGHT      400
 
64
 
 
65
/* keep in sync with preferences.glade and LMPreferencesDialog */
 
66
 
 
67
#define MIN_DELAY                       200
61
68
#define MIN_SCALE                       1
 
69
#define MIN_TOOLTIP_GRAPH_SPAN          10
62
70
%}
63
71
 
64
72
class LM:Applet from Panel:Applet
65
73
{
66
 
  public GSList *hosts;
67
 
 
68
 
  public unsigned int delay;
69
 
  property UINT delay (minimum = MIN_DELAY, default_value = MIN_DELAY, export)
70
 
    set
71
 
    {
72
 
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_DELAY, self->delay = g_value_get_uint(VAL), NULL);
73
 
    }
74
 
    get
75
 
    {
76
 
      g_value_set_uint(VAL, self->delay);
77
 
    };
78
 
 
79
 
  public unsigned int timeout;
80
 
  property UINT timeout (minimum = MIN_TIMEOUT, default_value = MIN_TIMEOUT, export)
81
 
    set
82
 
    {
83
 
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_TIMEOUT, self->timeout = g_value_get_uint(VAL), NULL);
84
 
    }
85
 
    get
86
 
    {
87
 
      g_value_set_uint(VAL, self->timeout);
88
 
    };
89
 
 
90
 
  public unsigned int scale;
91
 
  property UINT scale (minimum = MIN_SCALE, default_value = MIN_SCALE, export)
92
 
    set
93
 
    {
94
 
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_SCALE, self->scale = g_value_get_uint(VAL), NULL);
95
 
    }
96
 
    get
97
 
    {
98
 
      g_value_set_uint(VAL, self->scale);
 
74
  /* allow O(1) reverse iteration (used by LMLineGraph) */
 
75
  public GPtrArray *hosts = { g_ptr_array_new() };
 
76
 
 
77
  public int delay;             /* milliseconds */
 
78
  property INT delay (minimum = MIN_DELAY, default_value = DEFAULT_DELAY, export)
 
79
    set
 
80
    {
 
81
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_DELAY, self->delay = g_value_get_int(VAL), NULL);
 
82
    }
 
83
    get
 
84
    {
 
85
      g_value_set_int(VAL, self->delay);
 
86
    };
 
87
 
 
88
  public int scale;             /* milliseconds */
 
89
  property INT scale (minimum = MIN_SCALE, default_value = DEFAULT_SCALE, export)
 
90
    set
 
91
    {
 
92
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_SCALE, self->scale = g_value_get_int(VAL), NULL);
 
93
    }
 
94
    get
 
95
    {
 
96
      g_value_set_int(VAL, self->scale);
 
97
    };
 
98
 
 
99
  public int tooltip_graph_span; /* seconds */
 
100
  property INT tooltip_graph_span (minimum = MIN_TOOLTIP_GRAPH_SPAN, default_value = DEFAULT_TOOLTIP_GRAPH_SPAN, export)
 
101
    set
 
102
    {
 
103
      panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_TOOLTIP_GRAPH_SPAN, self->tooltip_graph_span = g_value_get_int(VAL), NULL);
 
104
    }
 
105
    get
 
106
    {
 
107
      g_value_set_int(VAL, self->tooltip_graph_span);
99
108
    };
100
109
 
101
110
  public int preferences_width;
120
129
      g_value_set_int(VAL, self->preferences_height);
121
130
    };
122
131
 
123
 
  private GtkSizeGroup *tooltip_status_size_group;
 
132
  private GArray *host_colors
 
133
    destroy
 
134
    {
 
135
      if (VAR)
 
136
        g_array_free(VAR, TRUE);
 
137
    };
 
138
 
124
139
  private GtkSizeGroup *tooltip_flag_size_group;
125
140
 
126
141
  private GtkWidget *preferences_dialog;
131
146
  signal (ACTION) private NONE (NONE)
132
147
    void activate (self)
133
148
  {
134
 
    self_display_preferences_dialog(self);
 
149
    self_show_preferences_dialog(self, gtk_get_current_event_time());
135
150
  }
136
151
 
137
152
  signal (ACTION) private NONE (NONE)
138
153
    void activate_preferences (self)
139
154
  {
140
 
    self_display_preferences_dialog(self);
 
155
    self_show_preferences_dialog(self, gtk_get_current_event_time());
141
156
  }
142
157
 
143
158
  class_init (class)
167
182
    };
168
183
    GSList *gconf_hosts;
169
184
    GSList *l;
 
185
    int num_hosts = 0;
170
186
 
171
187
    if (strcmp(iid, "OAFIID:GNOME_LinkMonitorApplet"))
172
188
      return FALSE;
181
197
 
182
198
    self->delay = panel_applet_gconf_get_int(applet, CONF_DELAY, NULL);
183
199
    if (self->delay < MIN_DELAY)
184
 
      self->delay = MIN_DELAY;
185
 
 
186
 
    self->timeout = panel_applet_gconf_get_int(applet, CONF_TIMEOUT, NULL);
187
 
    if (self->timeout < MIN_TIMEOUT)
188
 
      self->timeout = MIN_TIMEOUT;
 
200
      self->delay = DEFAULT_DELAY;
189
201
 
190
202
    self->scale = panel_applet_gconf_get_int(applet, CONF_SCALE, NULL);
191
203
    if (self->scale < MIN_SCALE)
192
 
      self->scale = MIN_SCALE;
 
204
      self->scale = DEFAULT_SCALE;
 
205
 
 
206
    self->tooltip_graph_span = panel_applet_gconf_get_int(applet, CONF_TOOLTIP_GRAPH_SPAN, NULL);
 
207
    if (self->tooltip_graph_span < MIN_TOOLTIP_GRAPH_SPAN)
 
208
      self->tooltip_graph_span = DEFAULT_TOOLTIP_GRAPH_SPAN;
193
209
 
194
210
    self->preferences_width = panel_applet_gconf_get_int(applet, CONF_PREFERENCES_WIDTH, NULL);
195
211
    if (! self->preferences_width)
199
215
    if (! self->preferences_height)
200
216
      self->preferences_height = DEFAULT_PREFERENCES_HEIGHT;
201
217
 
202
 
    selfp->tooltip_status_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
203
218
    selfp->tooltip_flag_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
204
219
 
205
220
    gconf_hosts = panel_applet_gconf_get_list(applet, CONF_HOSTS, GCONF_VALUE_STRING, NULL);
206
221
    LM_LIST_FOREACH(l, gconf_hosts)
207
 
      self_add_host_internal(self, l->data);
208
 
    eel_g_slist_free_deep(gconf_hosts);
 
222
      {
 
223
        const char *entry = l->data;
 
224
        LMHostFrontend *host;
 
225
 
 
226
        if (++num_hosts > LM_MAX_HOSTS)
 
227
          {
 
228
            /* unlikely, not worth a translation */
 
229
            g_warning("too many hosts configured, excess hosts ignored");
 
230
            break;
 
231
          }
 
232
 
 
233
        host = lm_host_frontend_parse_gconf_entry(self, entry);
 
234
        if (host)
 
235
          {
 
236
            self_add_host_internal(self, host);
 
237
            g_object_unref(host);
 
238
          }
 
239
        else
 
240
          g_warning("cannot parse GConf host entry \"%s\"", entry);
 
241
      }
 
242
    lm_g_slist_free_deep(gconf_hosts);
209
243
 
210
244
    self_update(self);
211
245
 
215
249
                     "signal::change-orient", self_reconfigure, NULL,
216
250
                     "signal::change-size", self_reconfigure, NULL,
217
251
                     "signal::change-background", self_change_background_h, NULL,
 
252
                     "signal::style-set", self_style_set_h, NULL,
218
253
                     NULL);
219
254
 
220
255
    gtk_widget_show(GTK_WIDGET(self));
239
274
    if (selfp->reconfigure_timeout_id)
240
275
      g_source_remove(selfp->reconfigure_timeout_id);
241
276
 
242
 
    lm_g_object_slist_free(self->hosts);
 
277
    lm_g_object_array_free(self->hosts);
243
278
 
244
 
    g_object_unref(selfp->tooltip_status_size_group);
245
279
    g_object_unref(selfp->tooltip_flag_size_group);
246
280
 
247
281
    if (selfp->preferences_dialog)
260
294
      g_source_remove(selfp->reconfigure_timeout_id);
261
295
 
262
296
    /* do not flood the panel with reconfigures, queue it */
263
 
    selfp->reconfigure_timeout_id = g_timeout_add(10, self_reconfigure_timeout_cb, self);
 
297
    selfp->reconfigure_timeout_id = gdk_threads_add_timeout(10, self_reconfigure_timeout_cb, self);
264
298
  }
265
299
 
266
300
  private gboolean
267
301
    reconfigure_timeout_cb (gpointer data)
268
302
  {
269
303
    Self *self = data;
270
 
    GSList *l;
271
 
 
272
 
    GDK_THREADS_ENTER();
273
304
 
274
305
    self_update_applet(self);
275
 
    LM_LIST_FOREACH(l, self->hosts)
276
 
      {
277
 
        LMHostFrontend *host = l->data;
278
 
        lm_host_frontend_configure_applet_progress_bar(host);
279
 
      }
280
 
 
281
 
    GDK_THREADS_LEAVE();
282
306
 
283
307
    return FALSE;               /* remove source */
284
308
  }
297
321
    gtk_widget_set_style(GTK_WIDGET(applet), NULL);
298
322
    rc_style = gtk_rc_style_new();
299
323
    gtk_widget_modify_style(GTK_WIDGET(applet), rc_style);
300
 
    gtk_rc_style_unref(rc_style);
 
324
    g_object_unref(rc_style);
301
325
 
302
326
    switch (type)
303
327
      {
323
347
      }
324
348
  }
325
349
 
 
350
  private void
 
351
    style_set_h (GtkWidget *widget,
 
352
                 GtkStyle *previous_style,
 
353
                 gpointer user_data)
 
354
  {
 
355
    Self *self = SELF(widget);
 
356
 
 
357
    /* invalidate the colors since they refer to style->base */
 
358
    if (selfp->host_colors)
 
359
      {
 
360
        g_array_free(selfp->host_colors, TRUE);
 
361
        selfp->host_colors = NULL;
 
362
      }
 
363
  }
 
364
 
326
365
  private gboolean
327
366
    button_press_event_h (GtkWidget *widget,
328
367
                          GdkEventButton *event,
352
391
             gpointer user_data,
353
392
             const char *cname)
354
393
  {
355
 
    lm_display_help(NULL);
 
394
    lm_show_help(NULL);
356
395
  }
357
396
 
358
397
  private void
362
401
  {
363
402
    Self *self = user_data;
364
403
 
365
 
    self_display_window(self, LM_TYPE_ABOUT_DIALOG, &selfp->about_dialog);
 
404
    self_show_window(self, LM_TYPE_ABOUT_DIALOG, &selfp->about_dialog, gtk_get_current_event_time());
366
405
  }
367
406
 
368
407
  private void
369
 
    display_preferences_dialog (self)
 
408
    show_preferences_dialog (self, guint32 timestamp)
370
409
  {
371
 
    self_display_window(self, LM_TYPE_PREFERENCES_DIALOG, &selfp->preferences_dialog);
 
410
    self_show_window(self, LM_TYPE_PREFERENCES_DIALOG, &selfp->preferences_dialog, timestamp);
372
411
  }
373
412
 
374
413
  private void
375
 
    display_window (self,
376
 
                    GType type (check != 0),
377
 
                    GtkWidget **ptr (check null))
 
414
    show_window (self,
 
415
                 GType type (check != 0),
 
416
                 GtkWidget **ptr (check null),
 
417
                 guint32 timestamp)
378
418
  {
379
419
    GObjectClass *class;
380
420
 
381
421
    if (*ptr)
382
422
      {
383
 
        gtk_window_present(GTK_WINDOW(*ptr));
 
423
        if (timestamp)
 
424
          gtk_window_present_with_time(GTK_WINDOW(*ptr), timestamp);
 
425
        else
 
426
          gtk_window_present(GTK_WINDOW(*ptr));
384
427
        return;
385
428
      }
386
429
 
391
434
      *ptr = g_object_new(type, NULL);
392
435
    g_type_class_unref(class);
393
436
 
394
 
    eel_add_weak_pointer(ptr);
 
437
    lm_add_weak_pointer(ptr);
395
438
    gtk_widget_show(*ptr);
396
439
  }
397
440
 
402
445
    self_update_tooltip(self);
403
446
  }
404
447
 
 
448
  private GtkWidget *
 
449
    create_icon (self)
 
450
  {
 
451
    GdkPixbuf *pixbuf;
 
452
    int size;
 
453
    GdkPixbuf *scaled;
 
454
    GtkWidget *icon;
 
455
 
 
456
    pixbuf = lm_pixbuf_new(GNOMEPIXMAPSDIR G_DIR_SEPARATOR_S "link-monitor-applet.png");
 
457
 
 
458
    size = panel_applet_get_size(PANEL_APPLET(self)) - (ICON_PADDING * 2);
 
459
    scaled = gdk_pixbuf_scale_simple(pixbuf, size, size, GDK_INTERP_BILINEAR);
 
460
    g_object_unref(pixbuf);
 
461
 
 
462
    icon = gtk_image_new_from_pixbuf(scaled);
 
463
    g_object_unref(scaled);
 
464
 
 
465
    return icon;
 
466
  }
 
467
 
405
468
  private void
406
469
    update_applet (self)
407
470
  {
408
 
    GSList *l;
409
 
    GtkWidget *child;
410
 
    GtkWidget *old_child;
411
 
 
412
 
    if (self->hosts)
413
 
      {
414
 
        switch (panel_applet_get_orient(PANEL_APPLET(self)))
415
 
          {
416
 
          case PANEL_APPLET_ORIENT_UP:
417
 
          case PANEL_APPLET_ORIENT_DOWN:
418
 
            child = gtk_hbox_new(FALSE, BAR_SPACING);
419
 
            break;
420
 
 
421
 
          case PANEL_APPLET_ORIENT_LEFT:
422
 
          case PANEL_APPLET_ORIENT_RIGHT:
423
 
            child = gtk_vbox_new(FALSE, BAR_SPACING);
424
 
            break;
425
 
 
426
 
          default:
427
 
            g_assert_not_reached();
428
 
            break;
429
 
          }
430
 
 
431
 
        LM_LIST_FOREACH(l, self->hosts)
432
 
          {
433
 
            LMHostFrontend *host = l->data;
434
 
            GtkWidget *parent;
435
 
 
436
 
            parent = gtk_widget_get_parent(host->applet_progress_bar);
437
 
            if (parent)
438
 
              gtk_container_remove(GTK_CONTAINER(parent), host->applet_progress_bar);
439
 
 
440
 
            gtk_box_pack_start(GTK_BOX(child), host->applet_progress_bar, FALSE, FALSE, 0);
441
 
            gtk_widget_show(host->applet_progress_bar);
442
 
          }
443
 
      }
444
 
    else
445
 
      {
446
 
        GdkPixbuf *pixbuf;
447
 
 
448
 
        pixbuf = lm_pixbuf_new(GNOMEPIXMAPSDIR G_DIR_SEPARATOR_S "link-monitor-applet.png");
449
 
        if (pixbuf)
450
 
          {
451
 
            int size;
452
 
            GdkPixbuf *scaled;
453
 
 
454
 
            size = panel_applet_get_size(PANEL_APPLET(self)) - (ICON_PADDING * 2);
455
 
            scaled = gdk_pixbuf_scale_simple(pixbuf, size, size, GDK_INTERP_BILINEAR);
456
 
            g_object_unref(pixbuf);
457
 
 
458
 
            child = gtk_image_new_from_pixbuf(scaled);
459
 
            g_object_unref(scaled);
460
 
          }
461
 
        else                    /* use label as fallback */
462
 
          {
463
 
            /* translators: header capitalization */
464
 
            child = gtk_label_new(_("<span size=\"small\">Link Monitor</span>"));
465
 
            gtk_label_set_use_markup(GTK_LABEL(child), TRUE);
466
 
          }
467
 
      }
468
 
 
469
 
    old_child = gtk_bin_get_child(GTK_BIN(self));
470
 
    if (old_child)
471
 
      gtk_container_remove(GTK_CONTAINER(self), old_child);
472
 
 
473
 
    gtk_container_add(GTK_CONTAINER(self), child);
474
 
    gtk_widget_show(child);
 
471
    GtkWidget *bar_graph = NULL;
 
472
    GtkWidget *box;
 
473
    GtkWidget *icon;
 
474
    GtkWidget *old_box;
 
475
 
 
476
    if (self->hosts->len != 0)
 
477
      bar_graph = lm_bar_graph_new(self);
 
478
 
 
479
    switch (panel_applet_get_orient(PANEL_APPLET(self)))
 
480
      {
 
481
      case PANEL_APPLET_ORIENT_UP:
 
482
      case PANEL_APPLET_ORIENT_DOWN:
 
483
        box = gtk_hbox_new(FALSE, BAR_SPACING);
 
484
        if (bar_graph)
 
485
          lm_bar_graph_set_orientation(LM_BAR_GRAPH(bar_graph), LM_BAR_GRAPH_ORIENTATION_VERTICAL);
 
486
        break;
 
487
 
 
488
      case PANEL_APPLET_ORIENT_LEFT:
 
489
      case PANEL_APPLET_ORIENT_RIGHT:
 
490
        box = gtk_vbox_new(FALSE, BAR_SPACING);
 
491
        if (bar_graph)
 
492
          lm_bar_graph_set_orientation(LM_BAR_GRAPH(bar_graph), LM_BAR_GRAPH_ORIENTATION_HORIZONTAL);
 
493
        break;
 
494
 
 
495
      default:
 
496
        g_assert_not_reached();
 
497
        break;
 
498
      }
 
499
 
 
500
    icon = self_create_icon(self);
 
501
    gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0);
 
502
    gtk_widget_show(icon);
 
503
 
 
504
    if (bar_graph)
 
505
      {
 
506
        gtk_box_pack_start(GTK_BOX(box), bar_graph, FALSE, FALSE, 0);
 
507
        gtk_widget_show(bar_graph);
 
508
      }
 
509
 
 
510
    old_box = gtk_bin_get_child(GTK_BIN(self));
 
511
    if (old_box)
 
512
      gtk_container_remove(GTK_CONTAINER(self), old_box);
 
513
 
 
514
    gtk_container_add(GTK_CONTAINER(self), box);
 
515
    gtk_widget_show(box);
475
516
  }
476
517
 
477
518
  private void
478
519
    update_tooltip (self)
479
520
  {
480
 
    GSList *l;
481
 
 
482
 
    if (self->hosts)
 
521
    if (self->hosts->len != 0)
483
522
      {
484
523
        GtkWidget *vbox;
485
 
 
486
 
        vbox = gtk_vbox_new(TRUE, 6);
487
 
 
488
 
        LM_LIST_FOREACH(l, self->hosts)
 
524
        GtkWidget *hosts_vbox;
 
525
        GtkWidget *line_graph;
 
526
        int i;
 
527
 
 
528
        vbox = gtk_vbox_new(FALSE, 12);
 
529
        hosts_vbox = gtk_vbox_new(TRUE, 6);
 
530
        line_graph = lm_line_graph_new(self);
 
531
 
 
532
        LM_ARRAY_FOREACH(i, self->hosts)
489
533
          {
490
 
            LMHostFrontend *host = l->data;
491
 
            GtkWidget *parent;
492
 
 
493
 
            parent = gtk_widget_get_parent(host->tooltip);
494
 
            if (parent)
495
 
              gtk_container_remove(GTK_CONTAINER(parent), host->tooltip);
496
 
 
497
 
            gtk_box_pack_start(GTK_BOX(vbox), host->tooltip, TRUE, TRUE, 0);
498
 
            gtk_widget_show(host->tooltip);
 
534
            LMHostFrontend *host = g_ptr_array_index(self->hosts, i);
 
535
            GtkWidget *hbox;
 
536
            GtkWidget *graph_icon;
 
537
 
 
538
            hbox = gtk_hbox_new(FALSE, 6);
 
539
 
 
540
            if (self->hosts->len != 1)
 
541
              {
 
542
                graph_icon = lm_line_graph_icon_new(host);
 
543
                gtk_box_pack_start(GTK_BOX(hbox), graph_icon, FALSE, FALSE, 0);
 
544
                gtk_widget_show(graph_icon);
 
545
              }
 
546
 
 
547
            lm_widget_remove_from_container(host->tooltip_flag);
 
548
            gtk_box_pack_start(GTK_BOX(hbox), host->tooltip_flag, FALSE, FALSE, 0);
 
549
            gtk_widget_show(host->tooltip_flag);
 
550
 
 
551
            lm_widget_remove_from_container(host->tooltip_status);
 
552
            gtk_box_pack_start(GTK_BOX(hbox), host->tooltip_status, FALSE, FALSE, 0);
 
553
            gtk_widget_show(host->tooltip_status);
 
554
 
 
555
            gtk_box_pack_start(GTK_BOX(hosts_vbox), hbox, FALSE, FALSE, 0);
 
556
            gtk_widget_show(hbox);
499
557
          }
500
558
 
 
559
        gtk_box_pack_start(GTK_BOX(vbox), line_graph, TRUE, TRUE, 0);
 
560
        gtk_box_pack_start(GTK_BOX(vbox), hosts_vbox, FALSE, FALSE, 0);
 
561
 
 
562
        gtk_widget_show(line_graph);
 
563
        gtk_widget_show(hosts_vbox);
 
564
 
501
565
        lm_tooltips_set_tip_widget(lm_shell->tooltips, GTK_WIDGET(self), vbox);
502
566
        gtk_widget_show(vbox);
503
567
      }
515
579
  }
516
580
 
517
581
  private void
518
 
    sync_gconf_hosts (self)
 
582
    save_hosts (self)
519
583
  {
 
584
    int i;
520
585
    GSList *gconf_hosts = NULL;
521
 
    GSList *l;
522
586
 
523
 
    LM_LIST_FOREACH(l, self->hosts)
524
 
      gconf_hosts = g_slist_append(gconf_hosts, LM_HOST(l->data)->name);
 
587
    LM_ARRAY_FOREACH(i, self->hosts)
 
588
      {
 
589
        LMHostFrontend *host = g_ptr_array_index(self->hosts, i);
 
590
        gconf_hosts = g_slist_append(gconf_hosts, lm_host_frontend_build_gconf_entry(host));
 
591
      }
525
592
 
526
593
    panel_applet_gconf_set_list(PANEL_APPLET(self),
527
594
                                CONF_HOSTS,
529
596
                                gconf_hosts,
530
597
                                NULL);
531
598
 
532
 
    g_slist_free(gconf_hosts);
 
599
    lm_g_slist_free_deep(gconf_hosts);
533
600
  }
534
601
 
535
 
  private LMHost *
536
 
    host_new (self, const char *name (check null))
 
602
  private void
 
603
    add_host_internal (self, LM:Host:Frontend *host (check null type))
537
604
  {
538
 
    LMHostFrontend *host;
539
 
 
540
 
    host = lm_host_frontend_new(self, name, lm_shell_get_unique_host_id(lm_shell));
541
 
    gtk_size_group_add_widget(selfp->tooltip_status_size_group, host->tooltip_status_box);
 
605
    g_ptr_array_add(self->hosts, g_object_ref(host));
 
606
 
 
607
    lm_g_object_connect(self, host,
 
608
                        "swapped-signal::notify::color", self_save_hosts, self,
 
609
                        NULL);
 
610
 
542
611
    gtk_size_group_add_widget(selfp->tooltip_flag_size_group, host->tooltip_flag);
543
612
 
544
 
    return LM_HOST(host);
545
 
  }
546
 
 
547
 
  private LMHost *
548
 
    add_host_internal (self, const char *name (check null))
549
 
  {
550
 
    LMHost *host;
551
 
 
552
 
    host = self_host_new(self, name);
553
 
    self->hosts = g_slist_append(self->hosts, host);
554
 
 
555
613
    self_update(self);
556
 
 
557
 
    return host;
558
614
  }
559
615
 
560
 
  private LMHost *
 
616
  private void
561
617
    replace_host_internal (self,
562
 
                           LM:Host *old (check null type),
563
 
                           const char *new (check null))
 
618
                           LM:Host:Frontend *old (check null type),
 
619
                           LM:Host:Frontend *new (check null type))
564
620
  {
565
 
    GSList *elem;
566
 
    LMHost *new_host;
567
 
 
568
 
    elem = g_slist_find(self->hosts, old);
569
 
    g_assert(elem != NULL);
570
 
 
571
 
    new_host = self_host_new(self, new);
 
621
    int idx;
 
622
 
 
623
    idx = lm_g_ptr_array_find(self->hosts, old);
 
624
    g_assert(idx != -1);
572
625
 
573
626
    g_object_unref(old);
574
 
    elem->data = new_host;
 
627
    g_ptr_array_index(self->hosts, idx) = g_object_ref(new);
575
628
 
576
629
    self_update(self);
577
 
 
578
 
    return new_host;
579
630
  }
580
631
 
581
632
  private void
582
633
    reorder_hosts_internal (self, GSList *new_hosts)
583
634
  {
584
 
    lm_g_object_slist_free(self->hosts);
585
 
    self->hosts = lm_g_object_slist_copy(new_hosts);
 
635
    GSList *l;
 
636
 
 
637
    lm_g_object_array_free(self->hosts);
 
638
    self->hosts = g_ptr_array_new();
 
639
 
 
640
    LM_LIST_FOREACH(l, new_hosts)
 
641
      {
 
642
        LMHostFrontend *host = l->data;
 
643
        g_ptr_array_add(self->hosts, g_object_ref(host));
 
644
      }
586
645
 
587
646
    self_update(self);
588
647
  }
589
648
 
590
649
  private void
591
 
    remove_host_internal (self, LM:Host *host (check null type))
 
650
    remove_host_internal (self, LM:Host:Frontend *host (check null type))
592
651
  {
593
 
    GSList *elem;
594
 
 
595
 
    elem = g_slist_find(self->hosts, host);
596
 
    g_assert(elem != NULL);
597
 
 
598
 
    self->hosts = g_slist_delete_link(self->hosts, elem);
 
652
    gboolean status;
 
653
 
 
654
    status = g_ptr_array_remove(self->hosts, host);
 
655
    g_assert(status == TRUE);
 
656
 
599
657
    g_object_unref(host);
600
658
 
601
659
    self_update(self);
602
660
  }
603
661
 
604
 
  public LMHost *
605
 
    add_host (self, const char *name (check null))
 
662
  public void
 
663
    add_host (self, LM:Host:Frontend *host (check null type))
606
664
  {
607
 
    LMHost *host;
608
 
 
609
 
    host = self_add_host_internal(self, name);
610
 
    self_sync_gconf_hosts(self);
611
 
 
612
 
    return host;
 
665
    self_add_host_internal(self, host);
 
666
    self_save_hosts(self);
613
667
  }
614
668
 
615
 
  public LMHost *
 
669
  public void
616
670
    replace_host (self,
617
 
                  LM:Host *old (check null type),
618
 
                  const char *new (check null))
 
671
                  LM:Host:Frontend *old (check null type),
 
672
                  LM:Host:Frontend *new (check null type))
619
673
  {
620
 
    LMHost *new_host;
621
 
 
622
 
    new_host = self_replace_host_internal(self, old, new);
623
 
    self_sync_gconf_hosts(self);
624
 
 
625
 
    return new_host;
 
674
    self_replace_host_internal(self, old, new);
 
675
    self_save_hosts(self);
626
676
  }
627
677
 
628
678
  public void
629
679
    reorder_hosts (self, GSList *new_hosts)
630
680
  {
631
681
    self_reorder_hosts_internal(self, new_hosts);
632
 
    self_sync_gconf_hosts(self);
 
682
    self_save_hosts(self);
633
683
  }
634
684
 
635
685
  public void
636
 
    remove_host (self, LM:Host *host (check null type))
 
686
    remove_host (self, LM:Host:Frontend *host (check null type))
637
687
  {
638
688
    self_remove_host_internal(self, host);
639
 
    self_sync_gconf_hosts(self);
 
689
    self_save_hosts(self);
 
690
  }
 
691
 
 
692
  public void
 
693
    get_host_color (self,
 
694
                    const char *name (check null),
 
695
                    GdkColor *color (check null))
 
696
  {
 
697
    GtkWidget *widget = GTK_WIDGET(self);
 
698
 
 
699
    if (! selfp->host_colors)
 
700
      {
 
701
        gtk_widget_ensure_style(widget);
 
702
        selfp->host_colors = lm_color_generator_generate(NUM_HOST_COLORS, &widget->style->base[GTK_STATE_NORMAL]);
 
703
      }
 
704
 
 
705
    *color = g_array_index(selfp->host_colors, GdkColor, g_str_hash(name) % selfp->host_colors->len);
640
706
  }
641
707
}