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
|
/* GNOME multiload panel applet
* (C) 1997 The Free Software Foundation
*
* Authors: Tim P. Gerla
* Martin Baulig
* Todd Kulesza
*
* With code from wmload.c, v0.9.2, apparently by Ryan Land, rland@bc1.com.
*
*/
#include <config.h>
#include <stdio.h>
#include <config.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
#include <gnome.h>
#include <panel-applet.h>
#include <panel-applet-gconf.h>
#include <gtk/gtk.h>
#include <libgnomeui/libgnomeui.h>
#include <libgnome/libgnome.h>
#include <libgnomeui/gnome-window-icon.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libart_lgpl/libart.h>
#include "global.h"
void
about_cb (BonoboUIComponent *uic, gpointer data, const gchar *name)
{
static GtkWidget *about = NULL;
GdkPixbuf *pixbuf;
GError *error = NULL;
gchar *file;
static const gchar *authors[] =
{
"Martin Baulig <martin@home-of-linux.org>",
"Todd Kulesza <fflewddur@dropline.net>\n",
NULL
};
const gchar *documenters[] =
{
NULL
};
const gchar *translator_credits = _("translator_credits");
if (about != NULL)
{
gdk_window_show(about->window);
gdk_window_raise(about->window);
return;
}
file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP, "gnome-monitor.png", FALSE, NULL);
pixbuf = gdk_pixbuf_new_from_file (file, &error);
g_free (file);
if (error)
{
g_warning (G_STRLOC ": cannot open %s: %s", file, error->message);
g_error_free (error);
}
about = gnome_about_new
(_("System Monitor"), VERSION,
"(C) 1999 - 2002 The Free Software Foundation",
_("Released under the GNU General Public License.\n\n"
"A system load monitor capable of displaying graphs for CPU, ram, and swap file use, plus network traffic."),
authors,
documenters,
strcmp (translator_credits, "translator_credits") != 0 ? translator_credits : NULL,
pixbuf);
if (pixbuf)
gdk_pixbuf_unref (pixbuf);
gtk_window_set_wmclass (GTK_WINDOW (about), "system monitor", "System Monitor");
g_signal_connect (G_OBJECT (about), "destroy",
G_CALLBACK (gtk_widget_destroyed), &about);
gtk_widget_show (about);
}
/* run the full-scale system process monitor */
void
start_procman_cb (BonoboUIComponent *uic, gpointer data, const gchar *name)
{
gnome_execute_shell(NULL, "gnome-system-monitor");
return;
}
void
multiload_change_size_cb(PanelApplet *applet, gint size, gpointer data)
{
gint i;
MultiloadApplet *ma = (MultiloadApplet *)data;
for (i = 0; i < 5; i++) {
ma->graphs[i]->pixel_size = size;
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);
}
return;
}
void
multiload_change_orient_cb(PanelApplet *applet, gint arg1, gpointer data)
{
MultiloadApplet *ma = data;
multiload_applet_refresh((MultiloadApplet *)data);
gtk_widget_show (GTK_WIDGET (ma->applet));
return;
}
void
multiload_destroy_cb(GtkWidget *widget, gpointer data)
{
gint i;
MultiloadApplet *ma = data;
for (i = 0; i < 5; i++)
{
if (ma->graphs[i]->visible)
{
load_graph_stop(ma->graphs[i]);
gtk_widget_destroy(ma->graphs[i]->main_widget);
}
load_graph_unalloc(ma->graphs[i]);
g_free(ma->graphs[i]);
}
gtk_widget_destroy(GTK_WIDGET(ma->applet));
return;
}
gboolean
multiload_enter_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
{
MultiloadApplet *ma;
gint i;
ma = (MultiloadApplet *)data;
for (i = 0; i < 5; i++)
if (ma->graphs[i]->visible)
{
ma->graphs[i]->tooltip_update = TRUE;
multiload_applet_tooltip_update(ma->graphs[i]);
}
return TRUE;
}
gboolean
multiload_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
{
MultiloadApplet *ma;
gint i;
ma = (MultiloadApplet *)data;
for (i = 0; i < 5; i++)
if (ma->graphs[i]->visible)
ma->graphs[i]->tooltip_update = FALSE;
return TRUE;
}
/* update the tooltip to the graph's current "used" percentage */
void
multiload_applet_tooltip_update(LoadGraph *g)
{
gint i, total_used, percent;
gchar *tooltip_text, *name;
g_return_if_fail(g);
g_return_if_fail(g->name);
total_used = 0;
/* label the tooltip intuitively */
if (!strncmp(g->name, "cpuload", strlen("cpuload")))
name = g_strdup(_("Processor"));
else if (!strncmp(g->name, "memload", strlen("memload")))
name = g_strdup(_("Memory"));
else if (!strncmp(g->name, "netload", strlen("netload")))
name = g_strdup(_("Network"));
else if (!strncmp(g->name, "swapload", strlen("swapload")))
name = g_strdup(_("Swap File"));
else
name = g_strdup(_("Resource"));
/* fill data[0] with the current load */
g->get_data (g->draw_height, g->data[0], g);
for (i = 0; i < (g->n - 1); i++)
total_used += g->data[0][i];
/* netload has a fifth data structute */
if (!strncmp(g->name, "netload", strlen("netload")))
total_used += g->data[0][g->n - 1];
percent = 100 * (gdouble)total_used / (gdouble)g->draw_height;
tooltip_text = g_strdup_printf(_("%s:\n%d%% in use"), name, percent);
gtk_tooltips_set_tip(g->tooltips, g->disp, tooltip_text, tooltip_text);
g_free(tooltip_text);
g_free(name);
return;
}
/* remove the old graphs and rebuild them */
void
multiload_applet_refresh(MultiloadApplet *ma)
{
gint i;
PanelAppletOrient orientation;
/* stop and free the old graphs */
for (i = 0; i < 5; i++)
{
if (ma->graphs[i]->visible)
{
load_graph_stop(ma->graphs[i]);
gtk_widget_destroy(ma->graphs[i]->main_widget);
}
load_graph_unalloc(ma->graphs[i]);
g_free(ma->graphs[i]);
}
gtk_widget_destroy(ma->box);
orientation = panel_applet_get_orient(ma->applet);
if ( (orientation == PANEL_APPLET_ORIENT_UP) ||
(orientation == PANEL_APPLET_ORIENT_DOWN) ) {
ma->box = gtk_hbox_new(FALSE, 0);
}
else
ma->box = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(ma->applet), ma->box);
/* create the 5 graphs, passing in their user-configurable properties with gconf. */
ma->graphs[0] = cpuload_applet_new(ma->applet, NULL);
ma->graphs[1] = memload_applet_new(ma->applet, NULL);
ma->graphs[2] = netload_applet_new(ma->applet, NULL);
ma->graphs[3] = swapload_applet_new(ma->applet, NULL);
ma->graphs[4] = loadavg_applet_new(ma->applet, NULL);
/* only start and display the graphs the user has turned on */
for (i = 0; i < 5; i++) {
gtk_box_pack_start(GTK_BOX(ma->box),
ma->graphs[i]->main_widget,
FALSE, FALSE, 1);
if (ma->graphs[i]->visible) {
gtk_widget_show_all (ma->graphs[i]->main_widget);
load_graph_start(ma->graphs[i]);
}
}
gtk_widget_show (ma->box);
return;
}
/* create a box and stuff the load graphs inside of it */
gboolean
multiload_applet_new(PanelApplet *applet, const gchar *iid, gpointer data)
{
gint i;
GtkWidget *box;
PanelAppletOrient orientation;
MultiloadApplet *ma;
ma = g_new0(MultiloadApplet, 1);
ma->applet = applet;
gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-monitor.png");
panel_applet_add_preferences (applet, "/schemas/apps/multiload/prefs", NULL);
orientation = panel_applet_get_orient(applet);
if ( (orientation == PANEL_APPLET_ORIENT_UP) || (orientation == PANEL_APPLET_ORIENT_DOWN) )
box = gtk_hbox_new(FALSE, 0);
else
box = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(applet), box);
/* create the 5 graphs, passing in their user-configurable properties with gconf. */
ma->graphs[0] = cpuload_applet_new(applet, NULL);
ma->graphs[1] = memload_applet_new(applet, NULL);
ma->graphs[2] = netload_applet_new(applet, NULL);
ma->graphs[3] = swapload_applet_new(applet, NULL);
ma->graphs[4] = loadavg_applet_new(applet, NULL);
/* only start and display the graphs the user has turned on */
for (i = 0; i < 5; i++) {
gtk_box_pack_start(GTK_BOX(box),
ma->graphs[i]->main_widget,
FALSE, FALSE, 1);
if (ma->graphs[i]->visible) {
gtk_widget_show_all (ma->graphs[i]->main_widget);
load_graph_start(ma->graphs[i]);
}
}
{
/* we need to pass 'ma' into the properties_cb or else every instance of multiload will use the same properties dialog*/
const BonoboUIVerb multiload_menu_verbs [] = {
BONOBO_UI_VERB_DATA ("MultiLoadProperties", multiload_properties_cb, ma),
BONOBO_UI_VERB ("MultiLoadRunProcman", start_procman_cb),
BONOBO_UI_VERB ("MultiLoadAbout", about_cb),
BONOBO_UI_VERB_END
};
panel_applet_setup_menu_from_file (applet,
NULL,
"GNOME_MultiloadApplet.xml",
NULL,
multiload_menu_verbs,
ma);
}
ma->box = box;
g_signal_connect(G_OBJECT(applet), "change_size",
G_CALLBACK(multiload_change_size_cb), ma);
g_signal_connect(G_OBJECT(applet), "change_orient",
G_CALLBACK(multiload_change_orient_cb), ma);
g_signal_connect(G_OBJECT(applet), "destroy",
G_CALLBACK(multiload_destroy_cb), ma);
g_signal_connect(G_OBJECT(applet), "enter_notify_event",
G_CALLBACK(multiload_enter_cb), ma);
multiload_change_size_cb (ma->applet,
panel_applet_get_size (ma->applet),
ma);
gtk_widget_show (box);
gtk_widget_show(GTK_WIDGET(applet));
return TRUE;
}
static gboolean
multiload_factory (PanelApplet *applet,
const gchar *iid,
gpointer data)
{
gboolean retval = FALSE;
retval = multiload_applet_new(applet, iid, data);
return retval;
}
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_MultiLoadApplet_Factory",
PANEL_TYPE_APPLET,
"MultiLoad Applet factory",
"0",
multiload_factory,
NULL);
|