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

« back to all changes in this revision

Viewing changes to src/callbacks.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 - callbacks
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 <libgnome/gnome-help.h>
23
 
#include <libgnomevfs/gnome-vfs.h>
24
 
#include <gtk/gtk.h>
25
 
#include <glib/gi18n.h>
26
 
#include <signal.h>
27
 
#include "callbacks.h"
28
 
#include "interface.h"
29
 
#include "proctable.h"
30
 
#include "util.h"
31
 
#include "procactions.h"
32
 
#include "procdialogs.h"
33
 
#include "memmaps.h"
34
 
#include "openfiles.h"
35
 
#include "favorites.h"
36
 
#include "load-graph.h"
37
 
#include "disks.h"
38
 
#include "lsof.h"
39
 
 
40
 
 
41
 
 
42
 
void
43
 
cb_kill_sigstop(GtkAction *action, gpointer data)
44
 
{
45
 
        ProcData * const procdata = data;
46
 
 
47
 
        /* no confirmation */
48
 
        kill_process (procdata, SIGSTOP);
49
 
}
50
 
 
51
 
 
52
 
 
53
 
 
54
 
void
55
 
cb_kill_sigcont(GtkAction *action, gpointer data)
56
 
{
57
 
        ProcData * const procdata = data;
58
 
 
59
 
        /* no confirmation */
60
 
        kill_process (procdata, SIGCONT);
61
 
}
62
 
 
63
 
 
64
 
 
65
 
 
66
 
static void
67
 
kill_process_helper(ProcData *procdata, int sig)
68
 
{
69
 
        if (procdata->config.show_kill_warning)
70
 
                procdialog_create_kill_dialog (procdata, sig);
71
 
        else
72
 
                kill_process (procdata, sig);
73
 
}
74
 
 
75
 
 
76
 
void
77
 
cb_edit_preferences (GtkAction *action, gpointer data)
78
 
{
79
 
        ProcData * const procdata = data;
80
 
 
81
 
        procdialog_create_preferences_dialog (procdata);
82
 
}
83
 
 
84
 
 
85
 
void
86
 
cb_renice (GtkAction *action, gpointer data)
87
 
{
88
 
        ProcData * const procdata = data;
89
 
 
90
 
        procdialog_create_renice_dialog (procdata);
91
 
}
92
 
 
93
 
 
94
 
void
95
 
cb_end_process (GtkAction *action, gpointer data)
96
 
{
97
 
        kill_process_helper(data, SIGTERM);
98
 
}
99
 
 
100
 
 
101
 
void
102
 
cb_kill_process (GtkAction *action, gpointer data)
103
 
{
104
 
        kill_process_helper(data, SIGKILL);
105
 
}
106
 
 
107
 
 
108
 
void
109
 
cb_show_memory_maps (GtkAction *action, gpointer data)
110
 
{
111
 
        ProcData * const procdata = data;
112
 
 
113
 
        create_memmaps_dialog (procdata);
114
 
}
115
 
 
116
 
void
117
 
cb_show_open_files (GtkAction *action, gpointer data)
118
 
{
119
 
        ProcData *procdata = data;
120
 
        
121
 
        create_openfiles_dialog (procdata);
122
 
}
123
 
 
124
 
void
125
 
cb_show_lsof(GtkAction *action, gpointer data)
126
 
{
127
 
        ProcData *procdata = data;
128
 
        procman_lsof(procdata);
129
 
}
130
 
 
131
 
void            
132
 
cb_show_hidden_processes (GtkAction *action, gpointer data)
133
 
{
134
 
        ProcData * const procdata = data;
135
 
 
136
 
        create_blacklist_dialog (procdata);
137
 
}
138
 
 
139
 
 
140
 
void
141
 
cb_hide_process (GtkAction *action, gpointer data)
142
 
{
143
 
        ProcData * const procdata = data;
144
 
 
145
 
        if (procdata->config.show_hide_message)
146
 
                procdialog_create_hide_dialog (procdata);
147
 
        else
148
 
                add_selected_to_blacklist (procdata);
149
 
}
150
 
 
151
 
 
152
 
void
153
 
cb_about (GtkAction *action, gpointer data)
154
 
{
155
 
        const gchar * const authors[] = {
156
 
                "Kevin Vandersloot",
157
 
                "Erik Johnsson",
158
 
                "Jorgen Scheibengruber",
159
 
                "Benoît Dejean",
160
 
                "Paollo Borelli",
161
 
                NULL
162
 
        };
163
 
 
164
 
        const gchar * const documenters[] = {
165
 
                "Bill Day",
166
 
                "Sun Microsystems",
167
 
                NULL
168
 
        };
169
 
 
170
 
        const gchar * const artists[] = {
171
 
                "Baptiste Mille-Mathias",
172
 
                NULL
173
 
        };
174
 
 
175
 
        gtk_show_about_dialog (
176
 
                NULL,
177
 
                "name",                 _("System Monitor"),
178
 
                "comments",             _("View current processes and monitor "
179
 
                                          "system state"),
180
 
                "version",              VERSION,
181
 
                "copyright",            "Copyright \xc2\xa9 2001-2004 Kevin Vandersloot\n"
182
 
                                        "Copyright \xc2\xa9 2005-2006 Benoît Dejean",
183
 
                "logo-icon-name",       "utilities-system-monitor",
184
 
                "authors",              authors,
185
 
                "artists",              artists,
186
 
                "documenters",          documenters,
187
 
                "translator-credits",   _("translator-credits"),
188
 
                "license",              "GPL 2+",
189
 
                "wrap-license",         TRUE,
190
 
                NULL
191
 
                );
192
 
}
193
 
 
194
 
 
195
 
void
196
 
cb_help_contents (GtkAction *action, gpointer data)
197
 
{
198
 
        GError *error = NULL;
199
 
 
200
 
        gnome_help_display ("gnome-system-monitor.xml", NULL, &error);
201
 
 
202
 
        if (error != NULL)
203
 
        {
204
 
                g_warning (error->message);
205
 
                g_error_free (error);
206
 
        }
207
 
}
208
 
 
209
 
 
210
 
void
211
 
cb_app_exit (GtkAction *action, gpointer data)
212
 
{
213
 
        ProcData * const procdata = data;
214
 
 
215
 
        cb_app_delete (NULL, NULL, procdata);
216
 
}
217
 
 
218
 
 
219
 
gboolean
220
 
cb_app_delete (GtkWidget *window, GdkEventAny *event, gpointer data)
221
 
{
222
 
        ProcData * const procdata = data;
223
 
 
224
 
        procman_save_config (procdata);
225
 
        if (procdata->timeout)
226
 
                g_source_remove (procdata->timeout);
227
 
        if (procdata->disk_timeout)
228
 
                g_source_remove (procdata->disk_timeout);
229
 
 
230
 
        gtk_main_quit ();
231
 
 
232
 
        return TRUE;
233
 
}
234
 
 
235
 
 
236
 
 
237
 
void
238
 
cb_end_process_button_pressed (GtkButton *button, gpointer data)
239
 
{
240
 
        kill_process_helper(data, SIGTERM);
241
 
}
242
 
 
243
 
 
244
 
static void change_gconf_color(GConfClient *client, const char *key,
245
 
                               GtkColorButton *cp)
246
 
{
247
 
        GdkColor c;
248
 
        char color[24]; /* color should be 1 + 3*4 + 1 = 15 chars -> 24 */
249
 
 
250
 
        gtk_color_button_get_color(cp, &c);
251
 
        g_snprintf(color, sizeof color, "#%04x%04x%04x", c.red, c.green, c.blue);
252
 
        gconf_client_set_string (client, key, color, NULL);
253
 
}
254
 
 
255
 
 
256
 
void
257
 
cb_cpu_color_changed (GtkColorButton *cp, gpointer data)
258
 
{
259
 
        char key[80];
260
 
        gint i = GPOINTER_TO_INT (data);
261
 
        GConfClient *client = gconf_client_get_default ();
262
 
 
263
 
        if (i == 0) {
264
 
                strcpy(key, "/apps/procman/cpu_color");
265
 
        }
266
 
        else {
267
 
                g_snprintf(key, sizeof key, "/apps/procman/cpu_color%d", i);
268
 
        }
269
 
 
270
 
        change_gconf_color(client, key, cp);
271
 
}
272
 
 
273
 
void
274
 
cb_mem_color_changed (GtkColorButton *cp, gpointer data)
275
 
{
276
 
        ProcData * const procdata = data;
277
 
        change_gconf_color(procdata->client, "/apps/procman/mem_color", cp);
278
 
}
279
 
 
280
 
 
281
 
void
282
 
cb_swap_color_changed (GtkColorButton *cp, gpointer data)
283
 
{
284
 
        ProcData * const procdata = data;
285
 
        change_gconf_color(procdata->client, "/apps/procman/swap_color", cp);
286
 
}
287
 
 
288
 
void
289
 
cb_net_in_color_changed (GtkColorButton *cp, gpointer data)
290
 
{
291
 
        ProcData * const procdata = data;
292
 
        change_gconf_color(procdata->client, "/apps/procman/net_in_color", cp);
293
 
}
294
 
 
295
 
void
296
 
cb_net_out_color_changed (GtkColorButton *cp, gpointer data)
297
 
{
298
 
        ProcData * const procdata = data;
299
 
        change_gconf_color(procdata->client, "/apps/procman/net_out_color", cp);
300
 
}
301
 
 
302
 
void
303
 
cb_bg_color_changed (GtkColorButton *cp, gpointer data)
304
 
{
305
 
        ProcData * const procdata = data;
306
 
        change_gconf_color(procdata->client, "/apps/procman/bg_color", cp);
307
 
}
308
 
 
309
 
void
310
 
cb_frame_color_changed (GtkColorButton *cp, gpointer data)
311
 
{
312
 
        ProcData * const procdata = data;
313
 
        change_gconf_color(procdata->client, "/apps/procman/frame_color", cp);
314
 
}
315
 
 
316
 
 
317
 
static void
318
 
get_last_selected (GtkTreeModel *model, GtkTreePath *path,
319
 
                   GtkTreeIter *iter, gpointer data)
320
 
{
321
 
        ProcInfo **info = data;
322
 
 
323
 
        gtk_tree_model_get (model, iter, COL_POINTER, info, -1);
324
 
}
325
 
 
326
 
 
327
 
void
328
 
cb_row_selected (GtkTreeSelection *selection, gpointer data)
329
 
{
330
 
        ProcData * const procdata = data;
331
 
 
332
 
        procdata->selection = selection;
333
 
 
334
 
        /* get the most recent selected process and determine if there are
335
 
        ** no selected processes
336
 
        */
337
 
        gtk_tree_selection_selected_foreach (procdata->selection, get_last_selected,
338
 
                                             &procdata->selected_process);
339
 
 
340
 
                update_sensitivity(procdata);
341
 
}
342
 
 
343
 
 
344
 
gboolean
345
 
cb_tree_button_pressed (GtkWidget *widget,
346
 
                        GdkEventButton *event,
347
 
                        gpointer data)
348
 
{
349
 
        ProcData * const procdata = data;
350
 
 
351
 
        if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
352
 
                do_popup_menu (procdata, event);
353
 
 
354
 
        return FALSE;
355
 
}
356
 
 
357
 
 
358
 
gboolean
359
 
cb_tree_popup_menu (GtkWidget *widget, gpointer data)
360
 
{
361
 
        ProcData * const procdata = data;
362
 
 
363
 
        do_popup_menu (procdata, NULL);
364
 
 
365
 
        return TRUE;
366
 
}
367
 
 
368
 
 
369
 
void
370
 
cb_switch_page (GtkNotebook *nb, GtkNotebookPage *page,
371
 
                gint num, gpointer data)
372
 
{
373
 
        cb_change_current_page (nb, num, data);
374
 
}
375
 
 
376
 
void
377
 
cb_change_current_page (GtkNotebook *nb, gint num, gpointer data)
378
 
{
379
 
        ProcData * const procdata = data;
380
 
 
381
 
        procdata->config.current_tab = num;
382
 
 
383
 
 
384
 
        if (num == PROCMAN_TAB_PROCESSES) {
385
 
 
386
 
                cb_timeout (procdata);
387
 
 
388
 
                if (!procdata->timeout)
389
 
                        procdata->timeout = g_timeout_add (
390
 
                                procdata->config.update_interval,
391
 
                                cb_timeout, procdata);
392
 
 
393
 
                update_sensitivity(procdata);
394
 
        }
395
 
        else {
396
 
                if (procdata->timeout) {
397
 
                        g_source_remove (procdata->timeout);
398
 
                        procdata->timeout = 0;
399
 
                }
400
 
 
401
 
                update_sensitivity(procdata);
402
 
        }
403
 
 
404
 
 
405
 
        if (num == PROCMAN_TAB_RESOURCES) {
406
 
                load_graph_start (procdata->cpu_graph);
407
 
                load_graph_start (procdata->mem_graph);
408
 
                load_graph_start (procdata->net_graph);
409
 
        }
410
 
        else {
411
 
                load_graph_stop (procdata->cpu_graph);
412
 
                load_graph_stop (procdata->mem_graph);
413
 
                load_graph_stop (procdata->net_graph);
414
 
        }
415
 
 
416
 
 
417
 
        if (num == PROCMAN_TAB_DISKS) {
418
 
 
419
 
                cb_update_disks (procdata);
420
 
 
421
 
                if(!procdata->disk_timeout) {
422
 
                        procdata->disk_timeout =
423
 
                                g_timeout_add (procdata->config.disks_update_interval,
424
 
                                               cb_update_disks,
425
 
                                               procdata);
426
 
                }
427
 
        }
428
 
        else {
429
 
                if(procdata->disk_timeout) {
430
 
                        g_source_remove (procdata->disk_timeout);
431
 
                        procdata->disk_timeout = 0;
432
 
                }
433
 
        }
434
 
}
435
 
 
436
 
 
437
 
 
438
 
void
439
 
cb_volume_mounted_or_unmounted(GnomeVFSVolumeMonitor *vfsvolumemonitor,
440
 
                            GnomeVFSVolume *vol,
441
 
                            gpointer procdata)
442
 
{
443
 
        cb_update_disks(procdata);
444
 
}
445
 
 
446
 
 
447
 
gint
448
 
cb_timeout (gpointer data)
449
 
{
450
 
        ProcData * const procdata = data;
451
 
        guint new_interval;
452
 
 
453
 
        proctable_update_all (procdata);
454
 
 
455
 
        if(smooth_refresh_get(procdata->smooth_refresh, &new_interval))
456
 
        {
457
 
                procdata->timeout = g_timeout_add(new_interval,
458
 
                                                  cb_timeout,
459
 
                                                  procdata);
460
 
                return FALSE;
461
 
        }
462
 
 
463
 
        return TRUE;
464
 
}
465
 
 
466
 
 
467
 
void
468
 
cb_radio_processes(GtkAction *action, GtkRadioAction *current, gpointer data)
469
 
{
470
 
        ProcData * const procdata = data;
471
 
 
472
 
        procdata->config.whose_process = gtk_radio_action_get_current_value(current);
473
 
 
474
 
        gconf_client_set_int (procdata->client, "/apps/procman/view_as",
475
 
                              procdata->config.whose_process, NULL);
476
 
}