~ubuntu-branches/ubuntu/gutsy/gnome-system-monitor/gutsy

« back to all changes in this revision

Viewing changes to src/procman.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-12-18 00:11:37 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20061218001137-xqbegj3g7g92y982
Tags: 2.17.4-0ubuntu1
* New upstream version:
  - 100% C++.
  - Disabled libsexy because it is buggy and unmaintained.
  - Fixed build on solaris.
* debian/control.in:
  - doesn't Build-Depends on libpcre3-dev
  - doesn't Recommends libsexy2
* debian/patches/01_load_library_instead_of_so.patch:
  - updated
* debian/patches/02_lpi.patch:
  - updated
* debian/patches/03_autoconf.patch:
  - updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Procman
2
 
 * Copyright (C) 2001 Kevin Vandersloot
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License
6
 
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Library General Public
15
 
 * License along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
 
 *
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
 
22
 
#include <stdlib.h>
23
 
 
24
 
#include <glib.h>
25
 
#include <glib/gi18n.h>
26
 
#include <gtk/gtk.h>
27
 
#include <gdk/gdkx.h>
28
 
#include <gnome.h>
29
 
#include <bacon-message-connection.h>
30
 
#include <libgnomevfs/gnome-vfs.h>
31
 
#include <gconf/gconf-client.h>
32
 
#include <glibtop.h>
33
 
#include <glibtop/close.h>
34
 
#include <glibtop/loadavg.h>
35
 
#include "load-graph.h"
36
 
#include "procman.h"
37
 
#include "interface.h"
38
 
#include "proctable.h"
39
 
#include "prettytable.h"
40
 
#include "favorites.h"
41
 
#include "callbacks.h"
42
 
#include "smooth_refresh.h"
43
 
 
44
 
 
45
 
static void
46
 
tree_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
47
 
{
48
 
        ProcData *procdata = data;
49
 
        GConfValue *value = gconf_entry_get_value (entry);
50
 
        
51
 
        procdata->config.show_tree = gconf_value_get_bool (value);
52
 
        proctable_clear_tree (procdata);
53
 
        proctable_update_all (procdata);
54
 
        
55
 
}
56
 
 
57
 
static void
58
 
view_as_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
59
 
{
60
 
        ProcData *procdata = data;
61
 
        GConfValue *value = gconf_entry_get_value (entry);
62
 
        
63
 
        procdata->config.whose_process = gconf_value_get_int (value);
64
 
        procdata->config.whose_process = CLAMP (procdata->config.whose_process, 0, 2);
65
 
        proctable_clear_tree (procdata);
66
 
        proctable_update_all (procdata);
67
 
        
68
 
}
69
 
 
70
 
static void
71
 
warning_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
72
 
{
73
 
        ProcData *procdata = data;
74
 
        const gchar *key = gconf_entry_get_key (entry);
75
 
        GConfValue *value = gconf_entry_get_value (entry);
76
 
        
77
 
        if (g_str_equal (key, "/apps/procman/kill_dialog")) {
78
 
                procdata->config.show_kill_warning = gconf_value_get_bool (value);
79
 
        }
80
 
        else {
81
 
                procdata->config.show_hide_message = gconf_value_get_bool (value);
82
 
        }
83
 
}
84
 
 
85
 
static void
86
 
timeouts_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
87
 
{
88
 
        ProcData *procdata = data;
89
 
        const gchar *key = gconf_entry_get_key (entry);
90
 
        GConfValue *value = gconf_entry_get_value (entry);
91
 
 
92
 
        if (g_str_equal (key, "/apps/procman/update_interval")) {
93
 
                procdata->config.update_interval = gconf_value_get_int (value);
94
 
                procdata->config.update_interval = 
95
 
                        MAX (procdata->config.update_interval, 1000);
96
 
 
97
 
                smooth_refresh_reset(procdata->smooth_refresh);
98
 
 
99
 
                if(procdata->timeout) {
100
 
                        g_source_remove (procdata->timeout);
101
 
                        procdata->timeout = g_timeout_add (procdata->config.update_interval,
102
 
                                                           cb_timeout,
103
 
                                                           procdata);
104
 
                }
105
 
        }
106
 
        else if (g_str_equal (key, "/apps/procman/graph_update_interval")){
107
 
                procdata->config.graph_update_interval = gconf_value_get_int (value);
108
 
                procdata->config.graph_update_interval = 
109
 
                        MAX (procdata->config.graph_update_interval, 
110
 
                             250);
111
 
                load_graph_change_speed(procdata->cpu_graph,
112
 
                                        procdata->config.graph_update_interval);
113
 
                load_graph_change_speed(procdata->mem_graph,
114
 
                                        procdata->config.graph_update_interval);
115
 
                load_graph_change_speed(procdata->net_graph,
116
 
                                        procdata->config.graph_update_interval);
117
 
        }
118
 
        else if (g_str_equal(key, "/apps/procman/disks_interval")) {
119
 
                
120
 
                procdata->config.disks_update_interval = gconf_value_get_int (value);
121
 
                procdata->config.disks_update_interval = 
122
 
                        MAX (procdata->config.disks_update_interval, 1000);     
123
 
 
124
 
                if(procdata->disk_timeout) {
125
 
                        g_source_remove (procdata->disk_timeout);
126
 
                        procdata->disk_timeout = \
127
 
                                g_timeout_add (procdata->config.disks_update_interval,
128
 
                                               cb_update_disks,
129
 
                                               procdata);
130
 
                }
131
 
        }
132
 
        else {
133
 
                g_assert_not_reached();
134
 
        }
135
 
}
136
 
 
137
 
static void
138
 
color_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
139
 
{
140
 
        ProcData * const procdata = data;
141
 
        const gchar *key = gconf_entry_get_key (entry);
142
 
        GConfValue *value = gconf_entry_get_value (entry);
143
 
        const gchar *color = gconf_value_get_string (value);
144
 
 
145
 
        if (g_str_equal (key, "/apps/procman/bg_color")) {
146
 
                gdk_color_parse (color, &procdata->config.bg_color);
147
 
                load_graph_get_colors(procdata->cpu_graph)[0] = procdata->config.bg_color;
148
 
                load_graph_get_colors(procdata->mem_graph)[0] = procdata->config.bg_color;
149
 
                load_graph_get_colors(procdata->net_graph)[0] = procdata->config.bg_color;
150
 
        }
151
 
        else if (g_str_equal (key, "/apps/procman/frame_color")) {
152
 
                gdk_color_parse (color, &procdata->config.frame_color);
153
 
                load_graph_get_colors(procdata->cpu_graph)[1] = procdata->config.frame_color;
154
 
                load_graph_get_colors(procdata->mem_graph)[1] = procdata->config.frame_color;
155
 
                load_graph_get_colors(procdata->net_graph)[1] = procdata->config.frame_color;
156
 
        }
157
 
        else if (g_str_equal (key, "/apps/procman/cpu_color")) {
158
 
                gdk_color_parse (color, &procdata->config.cpu_color[0]);
159
 
                load_graph_get_colors(procdata->cpu_graph)[2] = procdata->config.cpu_color[0];
160
 
        }
161
 
        else if (g_str_has_prefix (key, "/apps/procman/cpu_color")) {
162
 
                gint i;
163
 
 
164
 
                for (i=1;i<GLIBTOP_NCPU;i++) {
165
 
                        gchar *cpu_key;
166
 
                        cpu_key = g_strdup_printf ("/apps/procman/cpu_color%d",i);
167
 
                        if (g_str_equal (key, cpu_key)) {
168
 
                                gdk_color_parse (color, &procdata->config.cpu_color[i]);
169
 
                                load_graph_get_colors(procdata->cpu_graph)[i+2] = procdata->config.cpu_color[i];
170
 
                        }
171
 
                        g_free (cpu_key);
172
 
                }
173
 
        }
174
 
        else if (g_str_equal (key, "/apps/procman/mem_color")) {
175
 
                gdk_color_parse (color, &procdata->config.mem_color);
176
 
                load_graph_get_colors(procdata->mem_graph)[2] = procdata->config.mem_color;
177
 
        }
178
 
        else if (g_str_equal (key, "/apps/procman/swap_color")) {
179
 
                gdk_color_parse (color, &procdata->config.swap_color);
180
 
                load_graph_get_colors(procdata->mem_graph)[3] = procdata->config.swap_color;
181
 
        }
182
 
        else if (g_str_equal (key, "/apps/procman/net_in_color")) {
183
 
                gdk_color_parse (color, &procdata->config.net_in_color);
184
 
                load_graph_get_colors(procdata->net_graph)[2] = procdata->config.net_in_color;
185
 
        }
186
 
        else if (g_str_equal (key, "/apps/procman/net_out_color")) {
187
 
                gdk_color_parse (color, &procdata->config.net_out_color);
188
 
                load_graph_get_colors(procdata->net_graph)[3] = procdata->config.net_out_color;
189
 
        }
190
 
        else {
191
 
                g_assert_not_reached();
192
 
        }
193
 
}
194
 
 
195
 
 
196
 
 
197
 
static void
198
 
show_all_fs_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
199
 
{
200
 
        ProcData * const procdata = data;
201
 
        GConfValue *value = gconf_entry_get_value (entry);
202
 
 
203
 
        procdata->config.show_all_fs = gconf_value_get_bool (value);
204
 
 
205
 
        cb_update_disks (data);
206
 
}
207
 
 
208
 
 
209
 
static ProcData *
210
 
procman_data_new (GConfClient *client)
211
 
{
212
 
 
213
 
        ProcData *pd;
214
 
        gchar *color;
215
 
        gint swidth, sheight;
216
 
        gint i;
217
 
        glibtop_cpu cpu;
218
 
 
219
 
        pd = g_new0 (ProcData, 1);
220
 
        
221
 
        pd->tree = NULL;
222
 
        pd->info = NULL;
223
 
        pd->pids = g_hash_table_new(NULL, NULL);
224
 
        pd->selected_process = NULL;
225
 
        pd->timeout = 0;
226
 
        pd->blacklist = NULL;
227
 
        pd->cpu_graph = NULL;
228
 
        pd->mem_graph = NULL;
229
 
        pd->net_graph = NULL;
230
 
        pd->disk_timeout = 0;
231
 
 
232
 
        /* username is usually 8 chars long
233
 
           for caching, we create chunks of 128 chars */
234
 
        pd->users = g_string_chunk_new(128);
235
 
        /* push empty string */
236
 
        g_string_chunk_insert_const(pd->users, "");
237
 
 
238
 
        pd->config.width = gconf_client_get_int (client, "/apps/procman/width", NULL);
239
 
        pd->config.height = gconf_client_get_int (client, "/apps/procman/height", NULL);
240
 
        pd->config.show_tree = gconf_client_get_bool (client, "/apps/procman/show_tree", NULL);
241
 
        gconf_client_notify_add (client, "/apps/procman/show_tree", tree_changed_cb,
242
 
                                 pd, NULL, NULL);
243
 
        pd->config.show_kill_warning = gconf_client_get_bool (client, "/apps/procman/kill_dialog", 
244
 
                                                              NULL);
245
 
        gconf_client_notify_add (client, "/apps/procman/kill_dialog", warning_changed_cb,
246
 
                                 pd, NULL, NULL);
247
 
        pd->config.show_hide_message = gconf_client_get_bool (client, "/apps/procman/hide_message",
248
 
                                                              NULL);
249
 
        gconf_client_notify_add (client, "/apps/procman/hide_message", warning_changed_cb,
250
 
                                 pd, NULL, NULL);
251
 
        pd->config.update_interval = gconf_client_get_int (client, "/apps/procman/update_interval", 
252
 
                                                           NULL);
253
 
        gconf_client_notify_add (client, "/apps/procman/update_interval", timeouts_changed_cb,
254
 
                                 pd, NULL, NULL);
255
 
        pd->config.graph_update_interval = gconf_client_get_int (client,
256
 
                                                "/apps/procman/graph_update_interval",
257
 
                                                NULL);
258
 
        gconf_client_notify_add (client, "/apps/procman/graph_update_interval", timeouts_changed_cb,
259
 
                                 pd, NULL, NULL);
260
 
        pd->config.disks_update_interval = gconf_client_get_int (client,
261
 
                                                                 "/apps/procman/disks_interval",
262
 
                                                                 NULL);
263
 
        gconf_client_notify_add (client, "/apps/procman/disks_interval", timeouts_changed_cb,
264
 
                                 pd, NULL, NULL);
265
 
 
266
 
 
267
 
        /* /apps/procman/show_all_fs */
268
 
        pd->config.show_all_fs = gconf_client_get_bool (
269
 
                client, "/apps/procman/show_all_fs",
270
 
                NULL);
271
 
        gconf_client_notify_add
272
 
                (client, "/apps/procman/show_all_fs",
273
 
                 show_all_fs_changed_cb, pd, NULL, NULL);
274
 
 
275
 
 
276
 
        pd->config.whose_process = gconf_client_get_int (client, "/apps/procman/view_as", NULL);
277
 
        gconf_client_notify_add (client, "/apps/procman/view_as", view_as_changed_cb,
278
 
                                 pd, NULL, NULL);
279
 
        pd->config.current_tab = gconf_client_get_int (client, "/apps/procman/current_tab", NULL);
280
 
 
281
 
        color = gconf_client_get_string (client, "/apps/procman/bg_color", NULL);
282
 
        if (!color)
283
 
                color = g_strdup ("#000000");
284
 
        gconf_client_notify_add (client, "/apps/procman/bg_color", 
285
 
                                 color_changed_cb, pd, NULL, NULL);
286
 
        gdk_color_parse(color, &pd->config.bg_color);
287
 
        g_free (color);
288
 
        
289
 
        color = gconf_client_get_string (client, "/apps/procman/frame_color", NULL);
290
 
        if (!color)
291
 
                color = g_strdup ("#231e89aa2805");
292
 
        gconf_client_notify_add (client, "/apps/procman/frame_color", 
293
 
                                 color_changed_cb, pd, NULL, NULL);
294
 
        gdk_color_parse(color, &pd->config.frame_color);
295
 
        g_free (color);
296
 
        
297
 
        color = gconf_client_get_string (client, "/apps/procman/cpu_color", NULL);
298
 
        if (!color)
299
 
                color = g_strdup ("#000000a200ff");
300
 
        gconf_client_notify_add (client, "/apps/procman/cpu_color", 
301
 
                                 color_changed_cb, pd, NULL, NULL);
302
 
        gdk_color_parse(color, &pd->config.cpu_color[0]);
303
 
        g_free (color);
304
 
        
305
 
        for (i=1;i<GLIBTOP_NCPU;i++) {
306
 
                gchar *key;
307
 
                key = g_strdup_printf ("/apps/procman/cpu_color%d", i);
308
 
                
309
 
                color = gconf_client_get_string (client, key, NULL);
310
 
                if (!color)
311
 
                        color = g_strdup ("#f25915e815e8");
312
 
                gconf_client_notify_add (client, key, 
313
 
                                 color_changed_cb, pd, NULL, NULL);
314
 
                gdk_color_parse(color, &pd->config.cpu_color[i]);
315
 
                g_free (color);
316
 
                g_free (key);
317
 
        }
318
 
        color = gconf_client_get_string (client, "/apps/procman/mem_color", NULL);
319
 
        if (!color)
320
 
                color = g_strdup ("#000000ff0082");
321
 
        gconf_client_notify_add (client, "/apps/procman/mem_color", 
322
 
                                 color_changed_cb, pd, NULL, NULL);
323
 
        gdk_color_parse(color, &pd->config.mem_color);
324
 
        
325
 
        g_free (color);
326
 
        
327
 
        color = gconf_client_get_string (client, "/apps/procman/swap_color", NULL);
328
 
        if (!color)
329
 
                color = g_strdup ("#00b6000000ff");
330
 
        gconf_client_notify_add (client, "/apps/procman/swap_color", 
331
 
                                 color_changed_cb, pd, NULL, NULL);
332
 
        gdk_color_parse(color, &pd->config.swap_color);
333
 
        g_free (color);
334
 
 
335
 
        color = gconf_client_get_string (client, "/apps/procman/net_in_color", NULL);
336
 
        if (!color)
337
 
                color = g_strdup ("#000000f200f2");
338
 
        gconf_client_notify_add (client, "/apps/procman/net_in_color",
339
 
                                 color_changed_cb, pd, NULL, NULL);
340
 
        gdk_color_parse(color, &pd->config.net_in_color);
341
 
        g_free (color);
342
 
 
343
 
        color = gconf_client_get_string (client, "/apps/procman/net_out_color", NULL);
344
 
        if (!color)
345
 
                color = g_strdup ("#00f2000000c1");
346
 
        gconf_client_notify_add (client, "/apps/procman/net_out_color",
347
 
                                 color_changed_cb, pd, NULL, NULL);
348
 
        gdk_color_parse(color, &pd->config.net_out_color);
349
 
        g_free (color);
350
 
        
351
 
        get_blacklist (pd, client);
352
 
        
353
 
        /* Sanity checks */
354
 
        swidth = gdk_screen_width ();
355
 
        sheight = gdk_screen_height ();
356
 
        pd->config.width = CLAMP (pd->config.width, 50, swidth);
357
 
        pd->config.height = CLAMP (pd->config.height, 50, sheight);
358
 
        pd->config.update_interval = MAX (pd->config.update_interval, 1000);
359
 
        pd->config.graph_update_interval = MAX (pd->config.graph_update_interval, 250);
360
 
        pd->config.disks_update_interval = MAX (pd->config.disks_update_interval, 1000);
361
 
        pd->config.whose_process = CLAMP (pd->config.whose_process, 0, 2);
362
 
        pd->config.current_tab = CLAMP(pd->config.current_tab,
363
 
                                       PROCMAN_TAB_SYSINFO,
364
 
                                       PROCMAN_TAB_DISKS);
365
 
        
366
 
        /* Determinie number of cpus since libgtop doesn't really tell you*/
367
 
        pd->config.num_cpus = 0;
368
 
        glibtop_get_cpu (&cpu);
369
 
        pd->frequency = cpu.frequency;
370
 
        i=0;
371
 
        while (i < GLIBTOP_NCPU && cpu.xcpu_total[i] != 0) {
372
 
            pd->config.num_cpus ++;
373
 
            i++;
374
 
        }
375
 
        if (pd->config.num_cpus == 0)
376
 
                pd->config.num_cpus = 1;
377
 
 
378
 
        pd->smooth_refresh = smooth_refresh_new(&pd->config.update_interval);
379
 
 
380
 
        return pd;
381
 
 
382
 
}
383
 
 
384
 
static void
385
 
procman_free_data (ProcData *procdata)
386
 
{
387
 
 
388
 
        proctable_free_table (procdata);
389
 
        g_string_chunk_free(procdata->users);
390
 
        g_hash_table_destroy(procdata->pids);
391
 
        pretty_table_free (procdata->pretty_table);
392
 
        smooth_refresh_destroy(procdata->smooth_refresh);
393
 
        g_free (procdata);
394
 
        
395
 
}
396
 
 
397
 
 
398
 
gboolean
399
 
procman_get_tree_state (GConfClient *client, GtkWidget *tree, const gchar *prefix)
400
 
{
401
 
        GtkTreeModel *model;
402
 
        GList *columns, *it;
403
 
        gint sort_col;
404
 
        GtkSortType order;
405
 
        gchar *key;
406
 
        
407
 
 
408
 
        g_assert(tree);
409
 
        g_assert(prefix);
410
 
        
411
 
        if (!gconf_client_dir_exists (client, prefix, NULL)) 
412
 
                return FALSE;
413
 
        
414
 
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
415
 
        
416
 
        key = g_strdup_printf ("%s/sort_col", prefix);
417
 
        sort_col = gconf_client_get_int (client, key, NULL);
418
 
        g_free (key);
419
 
        
420
 
        key = g_strdup_printf ("%s/sort_order", prefix);
421
 
        order = gconf_client_get_int (client, key, NULL);
422
 
        g_free (key);
423
 
        
424
 
        if (sort_col != -1)
425
 
                gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
426
 
                                                      sort_col,
427
 
                                                      order);
428
 
 
429
 
        columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
430
 
 
431
 
        for(it = columns; it; it = it->next)
432
 
        {
433
 
                GtkTreeViewColumn *column;
434
 
                GConfValue *value = NULL;
435
 
                gint width;
436
 
                gboolean visible;
437
 
                int id;
438
 
 
439
 
                column = it->data;
440
 
                id = gtk_tree_view_column_get_sort_column_id (column);
441
 
 
442
 
                key = g_strdup_printf ("%s/col_%d_width", prefix, id);
443
 
                value = gconf_client_get (client, key, NULL);
444
 
                g_free (key);
445
 
 
446
 
                if (value != NULL) {
447
 
                        width = gconf_value_get_int(value);
448
 
                        gconf_value_free (value);
449
 
 
450
 
                        key = g_strdup_printf ("%s/col_%d_visible", prefix, id);
451
 
                        visible = gconf_client_get_bool (client, key, NULL);
452
 
                        g_free (key);
453
 
 
454
 
                        column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), id);
455
 
                        if(!column) continue;
456
 
                        gtk_tree_view_column_set_visible (column, visible);
457
 
                        if (visible) {
458
 
                                /* ensure column is really visible */
459
 
                                width = MAX(width, 10);
460
 
                                gtk_tree_view_column_set_fixed_width(column, width);
461
 
                        }
462
 
                }
463
 
        }
464
 
 
465
 
        if(g_str_has_suffix(prefix, "proctree") || g_str_has_suffix(prefix, "disktreenew"))
466
 
        {
467
 
                GSList *order;
468
 
                char *key;
469
 
 
470
 
                key = g_strdup_printf("%s/columns_order", prefix);
471
 
                order = gconf_client_get_list(client, key, GCONF_VALUE_INT, NULL);
472
 
                proctable_set_columns_order(GTK_TREE_VIEW(tree), order);
473
 
 
474
 
                g_slist_free(order);
475
 
                g_free(key);
476
 
        }
477
 
 
478
 
        g_list_free(columns);
479
 
        
480
 
        return TRUE;
481
 
}
482
 
 
483
 
void
484
 
procman_save_tree_state (GConfClient *client, GtkWidget *tree, const gchar *prefix)
485
 
{
486
 
        GtkTreeModel *model;
487
 
        GList *it, *columns;
488
 
        gint sort_col;
489
 
        GtkSortType order;
490
 
        
491
 
        g_assert(tree);
492
 
        g_assert(prefix);
493
 
        
494
 
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
495
 
        if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model), &sort_col,
496
 
                                                  &order)) {
497
 
                gchar *key;
498
 
                
499
 
                key = g_strdup_printf ("%s/sort_col", prefix);
500
 
                gconf_client_set_int (client, key, sort_col, NULL);
501
 
                g_free (key);
502
 
                
503
 
                key = g_strdup_printf ("%s/sort_order", prefix);
504
 
                gconf_client_set_int (client, key, order, NULL);
505
 
                g_free (key);
506
 
        }                              
507
 
        
508
 
        columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
509
 
 
510
 
        for(it = columns; it; it = it->next)
511
 
        {
512
 
                GtkTreeViewColumn *column;
513
 
                gboolean visible;
514
 
                gint width;
515
 
                gchar *key;
516
 
                int id;
517
 
 
518
 
                column = it->data;
519
 
                id = gtk_tree_view_column_get_sort_column_id (column);
520
 
                visible = gtk_tree_view_column_get_visible (column);
521
 
                width = gtk_tree_view_column_get_width (column);
522
 
 
523
 
                key = g_strdup_printf ("%s/col_%d_width", prefix, id);
524
 
                gconf_client_set_int (client, key, width, NULL);
525
 
                g_free (key);
526
 
 
527
 
                key = g_strdup_printf ("%s/col_%d_visible", prefix, id);
528
 
                gconf_client_set_bool (client, key, visible, NULL);
529
 
                g_free (key);
530
 
        }
531
 
 
532
 
        if(g_str_has_suffix(prefix, "proctree") || g_str_has_suffix(prefix, "disktreenew"))
533
 
        {
534
 
                GSList *order;
535
 
                char *key;
536
 
                GError *error = NULL;
537
 
 
538
 
                key = g_strdup_printf("%s/columns_order", prefix);
539
 
                order = proctable_get_columns_order(GTK_TREE_VIEW(tree));
540
 
 
541
 
                if(!gconf_client_set_list(client, key, GCONF_VALUE_INT, order, &error))
542
 
                {
543
 
                        g_critical("Could not save GConf key '%s' : %s",
544
 
                                   key,
545
 
                                   error->message);
546
 
                        g_error_free(error);
547
 
                }
548
 
 
549
 
                g_slist_free(order);
550
 
                g_free(key);
551
 
        }
552
 
 
553
 
        g_list_free(columns);
554
 
}
555
 
 
556
 
void
557
 
procman_save_config (ProcData *data)
558
 
{
559
 
        GConfClient *client = data->client;
560
 
        gint width, height;
561
 
 
562
 
        g_assert(data);
563
 
                
564
 
        procman_save_tree_state (data->client, data->tree, "/apps/procman/proctree");
565
 
        procman_save_tree_state (data->client, data->disk_list, "/apps/procman/disktreenew");
566
 
                
567
 
        gdk_window_get_size (data->app->window, &width, &height);
568
 
        data->config.width = width;
569
 
        data->config.height = height;
570
 
        
571
 
        gconf_client_set_int (client, "/apps/procman/width", data->config.width, NULL);
572
 
        gconf_client_set_int (client, "/apps/procman/height", data->config.height, NULL);       
573
 
        gconf_client_set_int (client, "/apps/procman/current_tab", data->config.current_tab, NULL);
574
 
        
575
 
        save_blacklist (data, client);
576
 
 
577
 
        gconf_client_suggest_sync (client, NULL);
578
 
        
579
 
 
580
 
        
581
 
}
582
 
 
583
 
static guint32
584
 
get_startup_timestamp ()
585
 
{
586
 
        const gchar *startup_id_env;
587
 
        gchar *startup_id = NULL;
588
 
        gchar *time_str;
589
 
        gulong retval = 0;
590
 
 
591
 
        /* we don't unset the env, since startup-notification
592
 
         * may still need it */
593
 
        startup_id_env = g_getenv ("DESKTOP_STARTUP_ID");
594
 
        if (startup_id_env == NULL)
595
 
                goto out;
596
 
 
597
 
        startup_id = g_strdup (startup_id_env);
598
 
 
599
 
        time_str = g_strrstr (startup_id, "_TIME");
600
 
        if (time_str == NULL)
601
 
                goto out;
602
 
 
603
 
        /* Skip past the "_TIME" part */
604
 
        time_str += 5;
605
 
 
606
 
        retval = strtoul (time_str, NULL, 0);
607
 
 
608
 
 out:
609
 
        g_free (startup_id);
610
 
 
611
 
        return retval;
612
 
}
613
 
 
614
 
 
615
 
static void
616
 
cb_server (const gchar *msg, gpointer user_data)
617
 
{
618
 
        GdkWindow *window;
619
 
        ProcData *procdata;
620
 
        guint32 timestamp;
621
 
 
622
 
        window = gdk_get_default_root_window ();
623
 
 
624
 
        procdata = *(ProcData**)user_data;
625
 
        g_assert (procdata != NULL);
626
 
 
627
 
        timestamp = strtoul(msg, NULL, 0);
628
 
 
629
 
        if (timestamp == 0)
630
 
        {
631
 
                /* fall back to rountripping to X */
632
 
                timestamp = gdk_x11_get_server_time (window);
633
 
        }
634
 
 
635
 
        gdk_x11_window_set_user_time (window, timestamp);
636
 
 
637
 
        gtk_window_present (GTK_WINDOW(procdata->app));
638
 
}
639
 
 
640
 
 
641
 
static void
642
 
init_volume_monitor(ProcData *procdata)
643
 
{
644
 
        GnomeVFSVolumeMonitor *mon;
645
 
        mon = gnome_vfs_get_volume_monitor();
646
 
 
647
 
        g_signal_connect(mon, "volume_mounted",
648
 
                         G_CALLBACK(cb_volume_mounted_or_unmounted), procdata);
649
 
 
650
 
        g_signal_connect(mon, "volume_unmounted",
651
 
                         G_CALLBACK(cb_volume_mounted_or_unmounted), procdata);
652
 
}
653
 
 
654
 
 
655
 
int
656
 
main (int argc, char *argv[])
657
 
{
658
 
        guint32 startup_timestamp;
659
 
        GnomeProgram *procman;
660
 
        GConfClient *client;
661
 
        ProcData *procdata;
662
 
        BaconMessageConnection *conn;
663
 
 
664
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
665
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
666
 
        textdomain (GETTEXT_PACKAGE);
667
 
 
668
 
        startup_timestamp = get_startup_timestamp();
669
 
 
670
 
        procman = gnome_program_init ("gnome-system-monitor", VERSION, 
671
 
                                       LIBGNOMEUI_MODULE, argc, argv,
672
 
                                      GNOME_PARAM_APP_DATADIR,DATADIR, NULL);
673
 
 
674
 
        conn = bacon_message_connection_new ("gnome-system-monitor");
675
 
        if (!conn) g_error("Couldn't connect to gnome-system-monitor");
676
 
 
677
 
        if (bacon_message_connection_get_is_server (conn))
678
 
        {
679
 
                bacon_message_connection_set_callback (conn, cb_server, &procdata);
680
 
        }
681
 
        else /* client */
682
 
        {
683
 
                char *timestamp;
684
 
 
685
 
                timestamp = g_strdup_printf ("%" G_GUINT32_FORMAT, startup_timestamp);
686
 
 
687
 
                bacon_message_connection_send (conn, timestamp);
688
 
 
689
 
                gdk_notify_startup_complete ();
690
 
 
691
 
                g_free (timestamp);
692
 
                bacon_message_connection_free (conn);
693
 
 
694
 
                exit (0);
695
 
        }
696
 
 
697
 
        gtk_window_set_default_icon_name ("utilities-system-monitor");
698
 
        g_set_application_name(_("System Monitor"));
699
 
                    
700
 
        gconf_init (argc, argv, NULL);
701
 
                            
702
 
        client = gconf_client_get_default ();
703
 
        gconf_client_add_dir(client, "/apps/procman", GCONF_CLIENT_PRELOAD_NONE, NULL);
704
 
 
705
 
        gnome_vfs_init ();
706
 
        glibtop_init ();
707
 
        
708
 
        procdata = procman_data_new (client);
709
 
        procdata->client = client;
710
 
        pretty_table_new (procdata);
711
 
 
712
 
        create_main_window (procdata);
713
 
        
714
 
        proctable_update_all (procdata);
715
 
 
716
 
        init_volume_monitor (procdata);
717
 
 
718
 
        g_assert(procdata->app);
719
 
                        
720
 
        gtk_widget_show(procdata->app);
721
 
        
722
 
        gtk_main ();
723
 
        
724
 
        procman_free_data (procdata);
725
 
 
726
 
        glibtop_close ();
727
 
        gnome_vfs_shutdown ();
728
 
 
729
 
        return 0;
730
 
}
731