34
31
#include <string.h>
32
#include <glib/gi18n.h>
35
33
#include <panel-applet-gconf.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"
43
44
#define ICON_PADDING 1
45
46
#define BAR_SPACING 3
48
#define NUM_HOST_COLORS 500
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"
54
57
/* keep in sync with link-monitor-applet.schemas */
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
58
/* keep in sync with preferences.glade */
59
#define MIN_DELAY 1000
60
#define MIN_TIMEOUT 100
63
#define DEFAULT_PREFERENCES_HEIGHT 400
65
/* keep in sync with preferences.glade and LMPreferencesDialog */
61
68
#define MIN_SCALE 1
69
#define MIN_TOOLTIP_GRAPH_SPAN 10
64
72
class LM:Applet from Panel:Applet
68
public unsigned int delay;
69
property UINT delay (minimum = MIN_DELAY, default_value = MIN_DELAY, export)
72
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_DELAY, self->delay = g_value_get_uint(VAL), NULL);
76
g_value_set_uint(VAL, self->delay);
79
public unsigned int timeout;
80
property UINT timeout (minimum = MIN_TIMEOUT, default_value = MIN_TIMEOUT, export)
83
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_TIMEOUT, self->timeout = g_value_get_uint(VAL), NULL);
87
g_value_set_uint(VAL, self->timeout);
90
public unsigned int scale;
91
property UINT scale (minimum = MIN_SCALE, default_value = MIN_SCALE, export)
94
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_SCALE, self->scale = g_value_get_uint(VAL), NULL);
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() };
77
public int delay; /* milliseconds */
78
property INT delay (minimum = MIN_DELAY, default_value = DEFAULT_DELAY, export)
81
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_DELAY, self->delay = g_value_get_int(VAL), NULL);
85
g_value_set_int(VAL, self->delay);
88
public int scale; /* milliseconds */
89
property INT scale (minimum = MIN_SCALE, default_value = DEFAULT_SCALE, export)
92
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_SCALE, self->scale = g_value_get_int(VAL), NULL);
96
g_value_set_int(VAL, self->scale);
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)
103
panel_applet_gconf_set_int(PANEL_APPLET(self), CONF_TOOLTIP_GRAPH_SPAN, self->tooltip_graph_span = g_value_get_int(VAL), NULL);
107
g_value_set_int(VAL, self->tooltip_graph_span);
101
110
public int preferences_width;
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;
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;
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;
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;
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;
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);
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);
223
const char *entry = l->data;
224
LMHostFrontend *host;
226
if (++num_hosts > LM_MAX_HOSTS)
228
/* unlikely, not worth a translation */
229
g_warning("too many hosts configured, excess hosts ignored");
233
host = lm_host_frontend_parse_gconf_entry(self, entry);
236
self_add_host_internal(self, host);
237
g_object_unref(host);
240
g_warning("cannot parse GConf host entry \"%s\"", entry);
242
lm_g_slist_free_deep(gconf_hosts);
210
244
self_update(self);
402
445
self_update_tooltip(self);
456
pixbuf = lm_pixbuf_new(GNOMEPIXMAPSDIR G_DIR_SEPARATOR_S "link-monitor-applet.png");
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);
462
icon = gtk_image_new_from_pixbuf(scaled);
463
g_object_unref(scaled);
406
469
update_applet (self)
410
GtkWidget *old_child;
414
switch (panel_applet_get_orient(PANEL_APPLET(self)))
416
case PANEL_APPLET_ORIENT_UP:
417
case PANEL_APPLET_ORIENT_DOWN:
418
child = gtk_hbox_new(FALSE, BAR_SPACING);
421
case PANEL_APPLET_ORIENT_LEFT:
422
case PANEL_APPLET_ORIENT_RIGHT:
423
child = gtk_vbox_new(FALSE, BAR_SPACING);
427
g_assert_not_reached();
431
LM_LIST_FOREACH(l, self->hosts)
433
LMHostFrontend *host = l->data;
436
parent = gtk_widget_get_parent(host->applet_progress_bar);
438
gtk_container_remove(GTK_CONTAINER(parent), host->applet_progress_bar);
440
gtk_box_pack_start(GTK_BOX(child), host->applet_progress_bar, FALSE, FALSE, 0);
441
gtk_widget_show(host->applet_progress_bar);
448
pixbuf = lm_pixbuf_new(GNOMEPIXMAPSDIR G_DIR_SEPARATOR_S "link-monitor-applet.png");
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);
458
child = gtk_image_new_from_pixbuf(scaled);
459
g_object_unref(scaled);
461
else /* use label as fallback */
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);
469
old_child = gtk_bin_get_child(GTK_BIN(self));
471
gtk_container_remove(GTK_CONTAINER(self), old_child);
473
gtk_container_add(GTK_CONTAINER(self), child);
474
gtk_widget_show(child);
471
GtkWidget *bar_graph = NULL;
476
if (self->hosts->len != 0)
477
bar_graph = lm_bar_graph_new(self);
479
switch (panel_applet_get_orient(PANEL_APPLET(self)))
481
case PANEL_APPLET_ORIENT_UP:
482
case PANEL_APPLET_ORIENT_DOWN:
483
box = gtk_hbox_new(FALSE, BAR_SPACING);
485
lm_bar_graph_set_orientation(LM_BAR_GRAPH(bar_graph), LM_BAR_GRAPH_ORIENTATION_VERTICAL);
488
case PANEL_APPLET_ORIENT_LEFT:
489
case PANEL_APPLET_ORIENT_RIGHT:
490
box = gtk_vbox_new(FALSE, BAR_SPACING);
492
lm_bar_graph_set_orientation(LM_BAR_GRAPH(bar_graph), LM_BAR_GRAPH_ORIENTATION_HORIZONTAL);
496
g_assert_not_reached();
500
icon = self_create_icon(self);
501
gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0);
502
gtk_widget_show(icon);
506
gtk_box_pack_start(GTK_BOX(box), bar_graph, FALSE, FALSE, 0);
507
gtk_widget_show(bar_graph);
510
old_box = gtk_bin_get_child(GTK_BIN(self));
512
gtk_container_remove(GTK_CONTAINER(self), old_box);
514
gtk_container_add(GTK_CONTAINER(self), box);
515
gtk_widget_show(box);
478
519
update_tooltip (self)
521
if (self->hosts->len != 0)
486
vbox = gtk_vbox_new(TRUE, 6);
488
LM_LIST_FOREACH(l, self->hosts)
524
GtkWidget *hosts_vbox;
525
GtkWidget *line_graph;
528
vbox = gtk_vbox_new(FALSE, 12);
529
hosts_vbox = gtk_vbox_new(TRUE, 6);
530
line_graph = lm_line_graph_new(self);
532
LM_ARRAY_FOREACH(i, self->hosts)
490
LMHostFrontend *host = l->data;
493
parent = gtk_widget_get_parent(host->tooltip);
495
gtk_container_remove(GTK_CONTAINER(parent), host->tooltip);
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);
536
GtkWidget *graph_icon;
538
hbox = gtk_hbox_new(FALSE, 6);
540
if (self->hosts->len != 1)
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);
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);
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);
555
gtk_box_pack_start(GTK_BOX(hosts_vbox), hbox, FALSE, FALSE, 0);
556
gtk_widget_show(hbox);
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);
562
gtk_widget_show(line_graph);
563
gtk_widget_show(hosts_vbox);
501
565
lm_tooltips_set_tip_widget(lm_shell->tooltips, GTK_WIDGET(self), vbox);
502
566
gtk_widget_show(vbox);
532
g_slist_free(gconf_hosts);
599
lm_g_slist_free_deep(gconf_hosts);
536
host_new (self, const char *name (check null))
603
add_host_internal (self, LM:Host:Frontend *host (check null type))
538
LMHostFrontend *host;
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));
607
lm_g_object_connect(self, host,
608
"swapped-signal::notify::color", self_save_hosts, self,
542
611
gtk_size_group_add_widget(selfp->tooltip_flag_size_group, host->tooltip_flag);
544
return LM_HOST(host);
548
add_host_internal (self, const char *name (check null))
552
host = self_host_new(self, name);
553
self->hosts = g_slist_append(self->hosts, host);
555
613
self_update(self);
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))
568
elem = g_slist_find(self->hosts, old);
569
g_assert(elem != NULL);
571
new_host = self_host_new(self, new);
623
idx = lm_g_ptr_array_find(self->hosts, old);
573
626
g_object_unref(old);
574
elem->data = new_host;
627
g_ptr_array_index(self->hosts, idx) = g_object_ref(new);
576
629
self_update(self);
582
633
reorder_hosts_internal (self, GSList *new_hosts)
584
lm_g_object_slist_free(self->hosts);
585
self->hosts = lm_g_object_slist_copy(new_hosts);
637
lm_g_object_array_free(self->hosts);
638
self->hosts = g_ptr_array_new();
640
LM_LIST_FOREACH(l, new_hosts)
642
LMHostFrontend *host = l->data;
643
g_ptr_array_add(self->hosts, g_object_ref(host));
587
646
self_update(self);
591
remove_host_internal (self, LM:Host *host (check null type))
650
remove_host_internal (self, LM:Host:Frontend *host (check null type))
595
elem = g_slist_find(self->hosts, host);
596
g_assert(elem != NULL);
598
self->hosts = g_slist_delete_link(self->hosts, elem);
654
status = g_ptr_array_remove(self->hosts, host);
655
g_assert(status == TRUE);
599
657
g_object_unref(host);
601
659
self_update(self);
605
add_host (self, const char *name (check null))
663
add_host (self, LM:Host:Frontend *host (check null type))
609
host = self_add_host_internal(self, name);
610
self_sync_gconf_hosts(self);
665
self_add_host_internal(self, host);
666
self_save_hosts(self);
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))
622
new_host = self_replace_host_internal(self, old, new);
623
self_sync_gconf_hosts(self);
674
self_replace_host_internal(self, old, new);
675
self_save_hosts(self);
629
679
reorder_hosts (self, GSList *new_hosts)
631
681
self_reorder_hosts_internal(self, new_hosts);
632
self_sync_gconf_hosts(self);
682
self_save_hosts(self);
636
remove_host (self, LM:Host *host (check null type))
686
remove_host (self, LM:Host:Frontend *host (check null type))
638
688
self_remove_host_internal(self, host);
639
self_sync_gconf_hosts(self);
689
self_save_hosts(self);
693
get_host_color (self,
694
const char *name (check null),
695
GdkColor *color (check null))
697
GtkWidget *widget = GTK_WIDGET(self);
699
if (! selfp->host_colors)
701
gtk_widget_ensure_style(widget);
702
selfp->host_colors = lm_color_generator_generate(NUM_HOST_COLORS, &widget->style->base[GTK_STATE_NORMAL]);
705
*color = g_array_index(selfp->host_colors, GdkColor, g_str_hash(name) % selfp->host_colors->len);