1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
|
/* MATE cpuload/memload panel applet
* (C) 2002 The Free Software Foundation
*
* Authors:
* Todd Kulesza
*
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <mate-panel-applet.h>
#include <mate-panel-applet-gsettings.h>
#include "global.h"
#define PROP_CPU 0
#define PROP_MEM 1
#define PROP_NET 2
#define PROP_SWAP 3
#define PROP_AVG 4
#define PROP_DISK 5
#define PROP_SPEED 6
#define PROP_SIZE 7
#define PROP_NET_THRESHOLD1 8
#define PROP_NET_THRESHOLD2 9
#define PROP_NET_THRESHOLD3 10
#define HIG_IDENTATION " "
#define NEVER_SENSITIVE "never_sensitive"
/* set sensitive and setup NEVER_SENSITIVE appropriately */
static void
hard_set_sensitive (GtkWidget *w, gboolean sensitivity)
{
gtk_widget_set_sensitive (w, sensitivity);
g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE,
GINT_TO_POINTER ( ! sensitivity));
}
/* set sensitive, but always insensitive if NEVER_SENSITIVE is set */
static void
soft_set_sensitive (GtkWidget *w, gboolean sensitivity)
{
if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE))
gtk_widget_set_sensitive (w, FALSE);
else
gtk_widget_set_sensitive (w, sensitivity);
}
static void
properties_set_insensitive(MultiloadApplet *ma)
{
gint i, total_graphs, last_graph;
total_graphs = 0;
last_graph = 0;
for (i = 0; i < graph_n; i++)
if (ma->graphs[i]->visible)
{
last_graph = i;
total_graphs++;
}
if (total_graphs < 2)
soft_set_sensitive(ma->check_boxes[last_graph], FALSE);
return;
}
static void
properties_close_cb (GtkWidget *widget, gint arg, MultiloadApplet *ma)
{
GError *error = NULL;
switch (arg)
{
case GTK_RESPONSE_HELP:
gtk_show_uri_on_window (NULL,
"help:mate-multiload/multiload-prefs",
gtk_get_current_event_time (),
&error);
if (error) { /* FIXME: the user needs to see this */
g_warning ("help error: %s\n", error->message);
g_error_free (error);
error = NULL;
}
break;
case GTK_RESPONSE_CLOSE:
default:
gtk_widget_destroy (widget);
ma->prop_dialog = NULL;
}
}
static void
property_toggled_cb(GtkWidget *widget, gpointer name)
{
MultiloadApplet *ma;
gint prop_type, i;
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet");
prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type"));
/* FIXME: the first toggle button to be checked/dechecked does not work, but after that everything is cool. what gives? */
/* FIXME: check if this is still valid for gsettings */
g_settings_set_boolean (ma->settings, (gchar *)name, active);
g_settings_set_boolean (ma->settings, (gchar *)name, active);
if (active)
{
for (i = 0; i < graph_n; i++)
soft_set_sensitive(ma->check_boxes[i], TRUE);
gtk_widget_show_all (ma->graphs[prop_type]->main_widget);
ma->graphs[prop_type]->visible = TRUE;
load_graph_start(ma->graphs[prop_type]);
}
else
{
load_graph_stop(ma->graphs[prop_type]);
gtk_widget_hide (ma->graphs[prop_type]->main_widget);
ma->graphs[prop_type]->visible = FALSE;
properties_set_insensitive(ma);
}
return;
}
static void
spin_button_changed_cb(GtkWidget *widget, gpointer name)
{
MultiloadApplet *ma;
gint value;
gint prop_type, i;
ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet");
prop_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "prop_type"));
value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
switch(prop_type)
{
case PROP_SPEED:
g_settings_set_int (ma->settings, (gchar *)name, value);
for (i = 0; i < graph_n; i++)
{
load_graph_stop(ma->graphs[i]);
ma->graphs[i]->speed = value;
if (ma->graphs[i]->visible)
load_graph_start(ma->graphs[i]);
}
break;
case PROP_SIZE:
for (i = 0; i < graph_n; i++)
{
g_settings_set_int (ma->settings, (gchar *)name, value);
ma->graphs[i]->size = value ;
if (ma->graphs[i]->orient)
gtk_widget_set_size_request (
ma->graphs[i]->main_widget,
ma->graphs[i]->pixel_size,
ma->graphs[i]->size);
else
gtk_widget_set_size_request (
ma->graphs[i]->main_widget,
ma->graphs[i]->size,
ma->graphs[i]->pixel_size);
}
break;
case PROP_NET_THRESHOLD1:
g_settings_set_uint (ma->settings, (gchar *)name, value);
if (value >= ma->net_threshold2)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold2") - 1);
ma->net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold2") - 1;
}
else
ma->net_threshold1 = value;
break;
case PROP_NET_THRESHOLD2:
g_settings_set_uint (ma->settings, (gchar *)name, value);
if (value >= ma->net_threshold3)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold3") - 1);
ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold3") - 1;
}
else if (value <= ma->net_threshold1)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold1") + 1);
ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold1") + 1;
}
else
ma->net_threshold2 = value;
break;
case PROP_NET_THRESHOLD3:
g_settings_set_uint (ma->settings, (gchar *)name, value);
if (value <= ma->net_threshold2)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold2") + 1);
ma->net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold2") + 1;
}
else
ma->net_threshold3 = value;
break;
default:
g_assert_not_reached();
}
return;
}
/* create a new page in the notebook widget, add it, and return a pointer to it */
static GtkWidget *
add_page(GtkWidget *notebook, gchar *label)
{
GtkWidget *page;
GtkWidget *page_label;
page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (page), TRUE);
page_label = gtk_label_new(label);
gtk_container_set_border_width(GTK_CONTAINER(page), 6);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, page_label);
return page;
}
/* save the selected color to gsettings and apply it on the applet */
static void
color_picker_set_cb(GtkColorChooser *color_picker, gchar *key)
{
gchar *color_string;
guint8 prop_type;
GdkRGBA color;
MultiloadApplet *ma;
ma = g_object_get_data (G_OBJECT (color_picker), "MultiloadApplet");
if (strstr(key, "cpuload"))
prop_type = PROP_CPU;
else if (strstr(key, "memload"))
prop_type = PROP_MEM;
else if (strstr(key, "netload2"))
prop_type = PROP_NET;
else if (strstr(key, "swapload"))
prop_type = PROP_SWAP;
else if (strstr(key, "loadavg"))
prop_type = PROP_AVG;
else if (strstr(key, "diskload"))
prop_type = PROP_DISK;
else
g_assert_not_reached();
gtk_color_chooser_get_rgba(color_picker, &color);
color_string = gdk_rgba_to_string (&color);
g_settings_set_string(ma->settings, key, color_string);
gdk_rgba_parse(&(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]),
color_string);
return;
}
/* create a color selector */
static void
add_color_selector(GtkWidget *page, gchar *name, gchar *key, MultiloadApplet *ma)
{
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *color_picker;
GdkRGBA color;
gchar *color_string;
color_string = g_settings_get_string (ma->settings, key);
if (!color_string)
color_string = g_strdup ("#000000");
gdk_rgba_parse (&color, color_string);
g_free (color_string);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
label = gtk_label_new_with_mnemonic(name);
color_picker = gtk_color_button_new();
gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker);
gtk_box_pack_start(GTK_BOX(vbox), color_picker, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0);
g_object_set_data (G_OBJECT (color_picker), "MultiloadApplet", ma);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_picker), &color);
g_signal_connect(G_OBJECT(color_picker), "color_set", G_CALLBACK(color_picker_set_cb), key);
if ( ! g_settings_is_writable (ma->settings, key))
hard_set_sensitive (vbox, FALSE);
return;
}
/* save the checkbox option to gsettings and apply it on the applet */
static void
nvme_checkbox_toggled_cb (GtkCheckButton *checkbox,
MultiloadApplet *ma)
{
gboolean option;
option = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
ma->nvme_diskstats = option;
g_settings_set_boolean (ma->settings, "diskload-nvme-diskstats", option);
return;
}
/* creates the properties dialog using up-to-the-minute info from gsettings */
static void
fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
{
GtkWidget *page;
GtkWidget *hbox, *vbox;
GtkWidget *categories_vbox;
GtkWidget *category_vbox;
GtkWidget *control_vbox;
GtkWidget *control_hbox;
GtkWidget *check_box;
GtkWidget *indent;
GtkWidget *spin_button;
GtkWidget *label;
MatePanelAppletOrient orient;
GtkSizeGroup *label_size;
GtkSizeGroup *spin_size;
gchar *label_text;
gchar *title;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox,
TRUE, TRUE, 0);
categories_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
gtk_box_pack_start (GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0);
gtk_widget_show (categories_vbox);
category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
gtk_widget_show (category_vbox);
title = g_strconcat ("<span weight=\"bold\">", _("Monitored Resources"), "</span>", NULL);
label = gtk_label_new_with_mnemonic (_(title));
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0);
g_free (title);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
indent = gtk_label_new (HIG_IDENTATION);
gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT);
gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0);
gtk_widget_show (indent);
control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0);
gtk_widget_show (control_vbox);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
check_box = gtk_check_button_new_with_mnemonic(_("_Processor"));
ma->check_boxes[0] = check_box;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
g_settings_get_boolean (ma->settings, VIEW_CPULOAD_KEY));
g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_CPU));
g_signal_connect(G_OBJECT(check_box), "toggled",
G_CALLBACK(property_toggled_cb), VIEW_CPULOAD_KEY);
gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_CPULOAD_KEY))
hard_set_sensitive (check_box, FALSE);
check_box = gtk_check_button_new_with_mnemonic(_("_Memory"));
ma->check_boxes[1] = check_box;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
g_settings_get_boolean (ma->settings, VIEW_MEMLOAD_KEY));
g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_MEM));
g_signal_connect(G_OBJECT(check_box), "toggled",
G_CALLBACK(property_toggled_cb), VIEW_MEMLOAD_KEY);
gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_MEMLOAD_KEY))
hard_set_sensitive (check_box, FALSE);
check_box = gtk_check_button_new_with_mnemonic(_("_Network"));
ma->check_boxes[2] = check_box;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
g_settings_get_boolean (ma->settings, VIEW_NETLOAD_KEY));
g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_NET));
g_signal_connect(G_OBJECT(check_box), "toggled",
G_CALLBACK(property_toggled_cb), VIEW_NETLOAD_KEY);
gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_NETLOAD_KEY))
hard_set_sensitive (check_box, FALSE);
check_box = gtk_check_button_new_with_mnemonic (_("S_wap Space"));
ma->check_boxes[3] = check_box;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
g_settings_get_boolean (ma->settings, VIEW_SWAPLOAD_KEY));
g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_SWAP));
g_signal_connect(G_OBJECT(check_box), "toggled",
G_CALLBACK(property_toggled_cb), VIEW_SWAPLOAD_KEY);
gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_SWAPLOAD_KEY))
hard_set_sensitive (check_box, FALSE);
check_box = gtk_check_button_new_with_mnemonic(_("_Load"));
ma->check_boxes[4] = check_box;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
g_settings_get_boolean (ma->settings, VIEW_LOADAVG_KEY));
g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(check_box), "prop_type", GINT_TO_POINTER(PROP_AVG));
g_signal_connect(G_OBJECT(check_box), "toggled",
G_CALLBACK(property_toggled_cb), VIEW_LOADAVG_KEY);
gtk_box_pack_start(GTK_BOX(control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_LOADAVG_KEY))
hard_set_sensitive (check_box, FALSE);
check_box = gtk_check_button_new_with_mnemonic(_("_Harddisk"));
ma->check_boxes[5] = check_box;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_box),
g_settings_get_boolean (ma->settings, VIEW_DISKLOAD_KEY));
g_object_set_data (G_OBJECT (check_box), "MultiloadApplet", ma);
g_object_set_data (G_OBJECT (check_box), "prop_type",
GINT_TO_POINTER (PROP_DISK));
g_signal_connect (G_OBJECT (check_box), "toggled",
G_CALLBACK (property_toggled_cb), VIEW_DISKLOAD_KEY);
gtk_box_pack_start (GTK_BOX (control_hbox), check_box, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, VIEW_DISKLOAD_KEY))
hard_set_sensitive (check_box, FALSE);
category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
gtk_widget_show (category_vbox);
title = g_strconcat ("<span weight=\"bold\">", _("Options"), "</span>", NULL);
label = gtk_label_new (title);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
g_free (title);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
indent = gtk_label_new (HIG_IDENTATION);
gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT);
gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0);
gtk_widget_show (indent);
control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0);
gtk_widget_show (control_vbox);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
orient = mate_panel_applet_get_orient(ma->applet);
if ( (orient == MATE_PANEL_APPLET_ORIENT_UP) || (orient == MATE_PANEL_APPLET_ORIENT_DOWN) )
label_text = g_strdup(_("System m_onitor width: "));
else
label_text = g_strdup(_("System m_onitor height: "));
label = gtk_label_new_with_mnemonic(label_text);
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_size_group_add_widget (label_size, label);
gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
spin_button = gtk_spin_button_new_with_range(10, 1000, 5);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(spin_button), "prop_type",
GINT_TO_POINTER(PROP_SIZE));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
(gdouble)g_settings_get_int(ma->settings, "size"));
g_signal_connect(G_OBJECT(spin_button), "value_changed",
G_CALLBACK(spin_button_changed_cb), "size");
if ( ! g_settings_is_writable (ma->settings, "size")) {
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
label = gtk_label_new (_("pixels"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
label = gtk_label_new_with_mnemonic(_("Sys_tem monitor update interval: "));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_size_group_add_widget (label_size, label);
gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
spin_button = gtk_spin_button_new_with_range(50, 10000, 50);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(spin_button), "prop_type",
GINT_TO_POINTER(PROP_SPEED));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
(gdouble)g_settings_get_int (ma->settings, "speed"));
g_signal_connect(G_OBJECT(spin_button), "value_changed",
G_CALLBACK(spin_button_changed_cb), "speed");
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, "speed")) {
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
label = gtk_label_new(_("milliseconds"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
g_free(label_text);
category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
gtk_widget_show (category_vbox);
title = g_strconcat ("<span weight=\"bold\">", _("Colors"), "</span>", NULL);
label = gtk_label_new (title);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
g_free (title);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
indent = gtk_label_new (HIG_IDENTATION);
gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT);
gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0);
gtk_widget_show (indent);
control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0);
gtk_widget_show (control_vbox);
ma->notebook = gtk_notebook_new();
gtk_container_add (GTK_CONTAINER (control_vbox), ma->notebook);
page = add_page(ma->notebook, _("Processor"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector(page, _("_User"), "cpuload-color0", ma);
add_color_selector(page, _("S_ystem"), "cpuload-color1", ma);
add_color_selector(page, _("N_ice"), "cpuload-color2", ma);
add_color_selector(page, _("I_OWait"), "cpuload-color3", ma);
add_color_selector(page, _("I_dle"), "cpuload-color4", ma);
page = add_page(ma->notebook, _("Memory"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector(page, _("_User"), "memload-color0", ma);
add_color_selector(page, _("Sh_ared"), "memload-color1", ma);
add_color_selector(page, _("_Buffers"), "memload-color2", ma);
add_color_selector (page, _("Cach_ed"), "memload-color3", ma);
add_color_selector(page, _("F_ree"), "memload-color4", ma);
page = add_page(ma->notebook, _("Network"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector (page, _("_In"), "netload2-color0", ma);
add_color_selector(page, _("_Out"), "netload2-color1", ma);
add_color_selector (page, _("_Local"), "netload2-color2", ma);
add_color_selector(page, _("_Background"), "netload2-color3", ma);
add_color_selector(page, _("_Gridline"), "netload2-color4", ma);
add_color_selector(page, _("_Indicator"), "netload2-color5", ma);
page = add_page(ma->notebook, _("Swap Space"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector(page, _("_Used"), "swapload-color0", ma);
add_color_selector(page, _("_Free"), "swapload-color1", ma);
page = add_page(ma->notebook, _("Load"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector(page, _("_Average"), "loadavg-color0", ma);
add_color_selector(page, _("_Background"), "loadavg-color1", ma);
add_color_selector(page, _("_Gridline"), "loadavg-color2", ma);
page = add_page (ma->notebook, _("Harddisk"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
add_color_selector (page, _("_Read"), "diskload-color0", ma);
add_color_selector (page, _("_Write"), "diskload-color1", ma);
add_color_selector (page, _("_Background"), "diskload-color2", ma);
GtkWidget *nvme_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
GtkWidget *nvme_checkbox = gtk_check_button_new_with_mnemonic (_("Use diskstats for NVMe"));
ma->nvme_diskstats = g_settings_get_boolean (ma->settings, "diskload-nvme-diskstats");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nvme_checkbox),
ma->nvme_diskstats);
g_signal_connect (G_OBJECT (nvme_checkbox), "toggled",
G_CALLBACK (nvme_checkbox_toggled_cb), ma);
gtk_box_pack_start (GTK_BOX(nvme_box), nvme_checkbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX(page), nvme_box, FALSE, FALSE, 0);
gtk_widget_show (nvme_box);
title = g_strconcat ("<span weight=\"bold\">", _("Network speed thresholds"), "</span>", NULL);
label = gtk_label_new (title);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (category_vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
g_free (title);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
indent = gtk_label_new (HIG_IDENTATION);
gtk_label_set_justify (GTK_LABEL (indent), GTK_JUSTIFY_LEFT);
gtk_box_pack_start (GTK_BOX (hbox), indent, FALSE, FALSE, 0);
gtk_widget_show (indent);
control_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (hbox), control_vbox, TRUE, TRUE, 0);
gtk_widget_show (control_vbox);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
label_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
label_text = g_strdup(_("Threshold 1: "));
label = gtk_label_new_with_mnemonic(label_text);
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_size_group_add_widget (label_size, label);
gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1, 5);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(spin_button), "prop_type",
GUINT_TO_POINTER(PROP_NET_THRESHOLD1));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
(gdouble)g_settings_get_uint(ma->settings, "netthreshold1"));
g_signal_connect(G_OBJECT(spin_button), "value_changed",
G_CALLBACK(spin_button_changed_cb), "netthreshold1");
if ( ! g_settings_is_writable (ma->settings, "netthreshold1"))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
label = gtk_label_new (_("bytes"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
label = gtk_label_new_with_mnemonic(_("Threshold 2: "));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_size_group_add_widget (label_size, label);
gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2, 5);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(spin_button), "prop_type",
GINT_TO_POINTER(PROP_NET_THRESHOLD2));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold2"));
g_signal_connect(G_OBJECT(spin_button), "value_changed",
G_CALLBACK(spin_button_changed_cb), "netthreshold2");
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, "netthreshold2"))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
label = gtk_label_new(_("bytes"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
label = gtk_label_new_with_mnemonic(_("Threshold 3: "));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_size_group_add_widget (label_size, label);
gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3, 5);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
g_object_set_data(G_OBJECT(spin_button), "prop_type",
GINT_TO_POINTER(PROP_NET_THRESHOLD3));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold3"));
g_signal_connect(G_OBJECT(spin_button), "value_changed",
G_CALLBACK(spin_button_changed_cb), "netthreshold3");
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (ma->settings, "netthreshold3"))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
label = gtk_label_new(_("bytes"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
g_free(label_text);
category_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
control_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
gtk_widget_show (control_hbox);
gtk_widget_show (category_vbox);
return;
}
/* show properties dialog */
void
multiload_properties_cb (GtkAction *action,
MultiloadApplet *ma)
{
GtkWidget *dialog = NULL;
if (ma->prop_dialog) {
dialog = ma->prop_dialog;
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (ma->applet)));
gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook),
ma->last_clicked);
gtk_window_present (GTK_WINDOW (dialog));
return;
}
dialog = gtk_dialog_new_with_buttons (_("System Monitor Preferences"),
NULL, 0,
"gtk-help", GTK_RESPONSE_HELP,
"gtk-close", GTK_RESPONSE_CLOSE,
NULL);
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (ma->applet)));
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);
fill_properties(dialog, ma);
properties_set_insensitive(ma);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(properties_close_cb), ma);
ma->prop_dialog = dialog;
gtk_widget_show_all(dialog);
gtk_notebook_set_current_page (GTK_NOTEBOOK (ma->notebook),
ma->last_clicked);
}
|