Update memory sizes to 64 bit and fix compilation warnings.
[lxde/lxtask.git] / src / interface.c
1 /* $Id: interface.c 3940 2008-02-10 22:48:45Z nebulon $
2 *
3 * Copyright (c) 2006 Johannes Zellner, <webmaster@nebulon.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /* 2008-04-26 modified by Hong Jen Yee to be used in LXDE. */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <glib/gi18n.h>
27 #include "interface.h"
28
29 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
30 g_object_set_data_full (G_OBJECT (component), name, \
31 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
32
33 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
34 g_object_set_data (G_OBJECT (component), name, widget)
35
36 void show_preferences(void);
37 extern gint refresh_interval;
38 extern guint rID;
39 GtkWidget *refresh_spin;
40
41 GtkWidget* create_main_window (void)
42 {
43 GtkWidget *window;
44 GtkWidget *menubar, *menu, *item;// *sub;
45 GtkWidget *vbox1;
46 GtkWidget *bbox1;
47 GtkWidget *scrolledwindow1;
48 GtkWidget *button1;
49 // GtkWidget *button2;
50 GtkWidget *button3;
51
52 GtkWidget *system_info_box;
53
54 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
55 gtk_window_set_title (GTK_WINDOW (window), _("Task Manager"));
56 gtk_window_set_default_size (GTK_WINDOW (window), win_width, win_height);
57 gtk_window_set_icon_name (GTK_WINDOW (window),"utilities-system-monitor");
58
59 bbox1 = gtk_vbox_new (FALSE, 10);
60 gtk_widget_show (bbox1);
61 gtk_container_add (GTK_CONTAINER (window), bbox1);
62
63 menubar = gtk_menu_bar_new();
64 gtk_widget_show( menubar );
65 gtk_box_pack_start(GTK_BOX (bbox1), menubar, FALSE, TRUE, 0 );
66
67 /* build menu */
68 menu = gtk_menu_new();
69
70 item = gtk_menu_item_new_with_mnemonic( _("_File") );
71 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
72 gtk_menu_shell_append( (GtkMenuShell*)menubar, item );
73
74 item = gtk_image_menu_item_new_from_stock( GTK_STOCK_QUIT, NULL );
75 GtkAccelGroup* accel_group = gtk_accel_group_new();
76 gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
77 #if GTK_CHECK_VERSION(3,0,0)
78 gtk_widget_add_accelerator(item, "activate", accel_group,
79 GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE);
80 gtk_widget_add_accelerator(item, "activate", accel_group,
81 GDK_KEY_W, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
82 #else
83 gtk_widget_add_accelerator(item, "activate", accel_group,
84 GDK_Escape, (GdkModifierType)NULL, GTK_ACCEL_VISIBLE);
85 gtk_widget_add_accelerator(item, "activate", accel_group,
86 GDK_W, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
87 #endif
88 gtk_menu_shell_append( (GtkMenuShell*)menu, item );
89 g_signal_connect( item, "activate", G_CALLBACK(gtk_main_quit), NULL );
90
91 item = gtk_menu_item_new_with_mnemonic( _("_View") );
92 gtk_menu_shell_append( (GtkMenuShell*)menubar, item );
93
94 menu = create_mainmenu();
95 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
96
97 item = gtk_menu_item_new_with_mnemonic( _("_Help") );
98 gtk_menu_shell_append( (GtkMenuShell*)menubar, item );
99 menu = gtk_menu_new();
100 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
101
102 item= gtk_image_menu_item_new_from_stock ("gtk-about", NULL);
103 gtk_widget_show (item);
104 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
105 g_signal_connect ((gpointer) item, "activate", G_CALLBACK (show_about_dialog), NULL);
106
107 gtk_widget_show_all( menubar );
108
109 /* window content */
110 vbox1 = gtk_vbox_new (FALSE, 10);
111 gtk_widget_show (vbox1);
112 gtk_box_pack_start( GTK_BOX(bbox1), vbox1, TRUE, TRUE, 0 );
113 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6);
114
115 system_info_box = gtk_hbox_new (TRUE, 10);
116 gtk_widget_show (system_info_box);
117 gtk_box_pack_start (GTK_BOX (vbox1), system_info_box, FALSE, TRUE, 0);
118
119 cpu_usage_progress_bar_box = gtk_event_box_new ();
120 cpu_usage_progress_bar = gtk_progress_bar_new ();
121 #if GTK_CHECK_VERSION(3,0,0)
122 gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (cpu_usage_progress_bar), TRUE);
123 #endif
124 gtk_progress_bar_set_text (GTK_PROGRESS_BAR (cpu_usage_progress_bar), _("cpu usage"));
125 gtk_widget_show (cpu_usage_progress_bar);
126 gtk_widget_show (cpu_usage_progress_bar_box);
127 gtk_container_add (GTK_CONTAINER (cpu_usage_progress_bar_box), cpu_usage_progress_bar);
128 gtk_box_pack_start (GTK_BOX (system_info_box), cpu_usage_progress_bar_box, TRUE, TRUE, 0);
129
130 mem_usage_progress_bar_box = gtk_event_box_new ();
131 mem_usage_progress_bar = gtk_progress_bar_new ();
132 #if GTK_CHECK_VERSION(3,0,0)
133 gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (mem_usage_progress_bar), TRUE);
134 #endif
135 gtk_progress_bar_set_text (GTK_PROGRESS_BAR (mem_usage_progress_bar), _("memory usage"));
136 gtk_widget_show (mem_usage_progress_bar);
137 gtk_widget_show (mem_usage_progress_bar_box);
138 gtk_container_add (GTK_CONTAINER (mem_usage_progress_bar_box), mem_usage_progress_bar);
139 gtk_box_pack_start (GTK_BOX (system_info_box), mem_usage_progress_bar_box, TRUE, TRUE, 0);
140
141 scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
142 gtk_widget_show (scrolledwindow1);
143 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
144 gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
145 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN);
146
147 treeview = gtk_tree_view_new ();
148 gtk_widget_show (treeview);
149 gtk_container_add (GTK_CONTAINER (scrolledwindow1), treeview);
150
151 create_list_store();
152
153 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
154
155 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(list_store));
156
157 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list_store), COLUMN_TIME, GTK_SORT_ASCENDING);
158
159 bbox1 = gtk_hbutton_box_new();
160 gtk_box_pack_start(GTK_BOX(vbox1), bbox1, FALSE, TRUE, 0);
161 gtk_widget_show (bbox1);
162
163 button3 = gtk_toggle_button_new_with_label (_("more details"));
164 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button3), full_view);
165 gtk_widget_show (button3);
166 gtk_box_pack_start (GTK_BOX (bbox1), button3, FALSE, FALSE, 0);
167
168 button1 = gtk_button_new_from_stock ("gtk-quit");
169 gtk_widget_show (button1);
170 gtk_box_pack_start (GTK_BOX (bbox1), button1, FALSE, FALSE, 0);
171
172 g_signal_connect ((gpointer) window, "destroy", G_CALLBACK (on_quit), NULL);
173 g_signal_connect_swapped ((gpointer) treeview, "button-press-event", G_CALLBACK(on_treeview1_button_press_event), NULL);
174 g_signal_connect ((gpointer) button1, "clicked", G_CALLBACK (on_quit), NULL);
175 g_signal_connect ((gpointer) button3, "toggled", G_CALLBACK (on_button3_toggled_event), NULL);
176
177 return window;
178 }
179
180 void create_list_store(void)
181 {
182 GtkCellRenderer *cell_renderer;
183
184 /* my change 8->9 */
185 list_store = gtk_tree_store_new(9, G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
186
187 cell_renderer = gtk_cell_renderer_text_new();
188
189 column = gtk_tree_view_column_new_with_attributes(_("Command"), cell_renderer, "text", COLUMN_NAME, NULL);
190 gtk_tree_view_column_set_resizable(column, TRUE);
191 gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME);
192 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_NAME, compare_string_list_item, (void *)COLUMN_NAME, NULL);
193 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
194
195 column = gtk_tree_view_column_new_with_attributes(_("User"), cell_renderer, "text", COLUMN_UNAME, NULL);
196 gtk_tree_view_column_set_resizable(column, TRUE);
197 gtk_tree_view_column_set_sort_column_id(column, COLUMN_UNAME);
198 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_UNAME, compare_string_list_item, (void *)COLUMN_UNAME, NULL);
199 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
200
201 cell_renderer = gtk_cell_renderer_text_new();
202 g_object_set(cell_renderer, "xalign", 1.0, NULL);
203
204 column = gtk_tree_view_column_new_with_attributes(_("CPU%"), cell_renderer, "text", COLUMN_TIME, NULL);
205 gtk_tree_view_column_set_resizable(column, TRUE);
206 gtk_tree_view_column_set_sort_column_id(column, COLUMN_TIME);
207 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_TIME, compare_int_list_item, (void *)COLUMN_TIME, NULL);
208 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
209
210 column = gtk_tree_view_column_new_with_attributes(_("RSS"), cell_renderer, "text", COLUMN_RSS, NULL);
211 gtk_tree_view_column_set_resizable(column, TRUE);
212 gtk_tree_view_column_set_sort_column_id(column, COLUMN_RSS);
213 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_RSS, compare_size_list_item, (void *)COLUMN_RSS, NULL);
214 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
215
216 column = gtk_tree_view_column_new_with_attributes(_("VM-Size"), cell_renderer, "text", COLUMN_MEM, NULL);
217 gtk_tree_view_column_set_resizable(column, TRUE);
218 gtk_tree_view_column_set_sort_column_id(column, COLUMN_MEM);
219 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_MEM, compare_size_list_item, (void *)COLUMN_MEM, NULL);
220 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
221
222 column = gtk_tree_view_column_new_with_attributes(_("PID"), cell_renderer, "text", COLUMN_PID, NULL);
223 gtk_tree_view_column_set_resizable(column, TRUE);
224 gtk_tree_view_column_set_sort_column_id(column, COLUMN_PID);
225 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_PID, compare_int_list_item, (void *)COLUMN_PID, NULL);
226 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
227
228 column = gtk_tree_view_column_new_with_attributes(_("State"), cell_renderer, "text", COLUMN_STATE, NULL);
229 gtk_tree_view_column_set_resizable(column, TRUE);
230 gtk_tree_view_column_set_sort_column_id(column, COLUMN_STATE);
231 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_STATE, compare_string_list_item, (void *)COLUMN_STATE, NULL);
232 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
233
234 column = gtk_tree_view_column_new_with_attributes(_("Prio"), cell_renderer, "text", COLUMN_PRIO, NULL);
235 gtk_tree_view_column_set_resizable(column, TRUE);
236 gtk_tree_view_column_set_sort_column_id(column, COLUMN_PRIO);
237 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_PRIO, compare_int_list_item, (void *)COLUMN_PRIO, NULL);
238 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
239
240 column = gtk_tree_view_column_new_with_attributes(_("PPID"), cell_renderer, "text", COLUMN_PPID, NULL);
241 gtk_tree_view_column_set_resizable(column, TRUE);
242 gtk_tree_view_column_set_sort_column_id(column, COLUMN_PPID);
243 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_PPID, compare_int_list_item, (void *)COLUMN_PPID, NULL);
244 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
245
246 change_list_store_view();
247 }
248
249 GtkWidget* create_taskpopup (void)
250 {
251 GtkWidget *taskpopup;
252 GtkWidget *menu_item;
253
254 taskpopup = gtk_menu_new ();
255
256 menu_item = gtk_menu_item_new_with_mnemonic (_("Stop"));
257 gtk_widget_show (menu_item);
258 gtk_container_add (GTK_CONTAINER (taskpopup), menu_item);
259 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_task_menu), "STOP");
260
261 menu_item = gtk_menu_item_new_with_mnemonic (_("Continue"));
262 gtk_widget_show (menu_item);
263 gtk_container_add (GTK_CONTAINER (taskpopup), menu_item);
264 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_task_menu), "CONT");
265
266 menu_item = gtk_menu_item_new_with_mnemonic (_("Term"));
267 gtk_widget_show (menu_item);
268 gtk_container_add (GTK_CONTAINER (taskpopup), menu_item);
269 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_task_menu), "TERM");
270
271 menu_item = gtk_menu_item_new_with_mnemonic (_("Kill"));
272 gtk_widget_show (menu_item);
273 gtk_container_add (GTK_CONTAINER (taskpopup), menu_item);
274 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_task_menu), "KILL");
275
276 menu_item = gtk_menu_item_new_with_mnemonic ( _("Priority") );
277 gtk_menu_item_set_submenu((gpointer) menu_item, create_prio_submenu());
278 gtk_widget_show (menu_item);
279 gtk_container_add (GTK_CONTAINER (taskpopup), menu_item);
280
281 return taskpopup;
282 }
283
284 GtkWidget *create_prio_submenu(void)
285 {
286 GtkWidget *prio_submenu = gtk_menu_new ();
287 GtkWidget *menu_item;
288
289 menu_item = gtk_menu_item_new_with_mnemonic (_(" -10"));
290 gtk_widget_show (menu_item);
291 gtk_container_add (GTK_CONTAINER (prio_submenu), menu_item);
292 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_prio_menu), "-10");
293
294 menu_item = gtk_menu_item_new_with_mnemonic (_(" -5"));
295 gtk_widget_show (menu_item);
296 gtk_container_add (GTK_CONTAINER (prio_submenu), menu_item);
297 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_prio_menu), "-5");
298
299 menu_item = gtk_menu_item_new_with_mnemonic (_(" 0"));
300 gtk_widget_show (menu_item);
301 gtk_container_add (GTK_CONTAINER (prio_submenu), menu_item);
302 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_prio_menu), "0");
303
304 menu_item = gtk_menu_item_new_with_mnemonic (_(" 5"));
305 gtk_widget_show (menu_item);
306 gtk_container_add (GTK_CONTAINER (prio_submenu), menu_item);
307 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_prio_menu), "5");
308
309 menu_item = gtk_menu_item_new_with_mnemonic (_(" 10"));
310 gtk_widget_show (menu_item);
311 gtk_container_add (GTK_CONTAINER (prio_submenu), menu_item);
312 g_signal_connect ((gpointer) menu_item, "activate", G_CALLBACK (handle_prio_menu), "10");
313
314 return prio_submenu;
315 }
316
317 GtkWidget* create_mainmenu (void)
318 {
319 GtkWidget *mainmenu;
320 // GtkWidget *info1;
321 // GtkWidget *trennlinie1;
322 GtkWidget *preferences1;
323 GtkWidget *show_user_tasks1;
324 GtkWidget *show_root_tasks1;
325 GtkWidget *show_other_tasks1;
326 GtkWidget *show_cached_as_free1;
327 GtkWidget *show_full_path1;
328 GtkWidget *separator1;
329 GtkAccelGroup *accel_group;
330
331 accel_group = gtk_accel_group_new ();
332
333 mainmenu = gtk_menu_new ();
334
335 show_user_tasks1 = gtk_check_menu_item_new_with_mnemonic (_("Show user tasks"));
336 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_user_tasks1), show_user_tasks);
337 gtk_widget_show (show_user_tasks1);
338 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_user_tasks1);
339
340 show_root_tasks1 = gtk_check_menu_item_new_with_mnemonic (_("Show root tasks"));
341 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_root_tasks1), show_root_tasks);
342 gtk_widget_show (show_root_tasks1);
343 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_root_tasks1);
344
345 show_other_tasks1 = gtk_check_menu_item_new_with_mnemonic (_("Show other tasks"));
346 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_other_tasks1), show_other_tasks);
347 gtk_widget_show (show_other_tasks1);
348 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_other_tasks1);
349
350 show_full_path1 = gtk_check_menu_item_new_with_mnemonic (_("Show full cmdline"));
351 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_full_path1), show_full_path);
352 gtk_widget_show (show_full_path1);
353 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_full_path1);
354
355 show_cached_as_free1 = gtk_check_menu_item_new_with_mnemonic (_("Show memory used by cache as free"));
356 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_cached_as_free1), show_cached_as_free);
357 gtk_widget_show (show_cached_as_free1);
358 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_cached_as_free1);
359
360 separator1 = gtk_separator_menu_item_new();
361 gtk_widget_show(separator1);
362 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), separator1);
363
364 preferences1 = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES, NULL);
365 g_signal_connect(G_OBJECT (preferences1), "activate", G_CALLBACK (show_preferences), NULL);
366 gtk_widget_show(preferences1);
367 gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), preferences1);
368
369 g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)own_uid);
370 g_signal_connect ((gpointer) show_root_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)0);
371 g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-1);
372 g_signal_connect ((gpointer) show_full_path1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-2);
373 g_signal_connect ((gpointer) show_cached_as_free1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0);
374
375 gtk_menu_set_accel_group (GTK_MENU (mainmenu), accel_group);
376
377 return mainmenu;
378 }
379
380 void show_about_dialog(void)
381 {
382 GtkWidget * about_dlg;
383 const gchar *authors[] =
384 {
385 "Hong Jen Yee <pcman.tw@gmail.com>",
386 "Jan Dlabal <dlabaljan@gmail.com>",
387 _("LXTask is derived from Xfce4 Task Manager by:\n"
388 " * Johannes Zellner <webmaster@nebulon.de>"),
389 NULL
390 };
391 /* TRANSLATORS: Replace this string with your names, one name per line. */
392 gchar *translators = _( "translator-credits" );
393
394 /* gtk_about_dialog_set_url_hook( open_url, this, NULL); */
395
396 about_dlg = gtk_about_dialog_new ();
397
398 gtk_container_set_border_width ( ( GtkContainer*)about_dlg , 2 );
399 gtk_about_dialog_set_version ( (GtkAboutDialog*)about_dlg, VERSION );
400 #if !GTK_CHECK_VERSION(2,12,0)
401 gtk_about_dialog_set_name ( (GtkAboutDialog*)about_dlg, _( "LXTask" ) );
402 #else
403 gtk_about_dialog_set_program_name ( (GtkAboutDialog*)about_dlg, _( "LXTask" ) );
404 #endif
405 /* gtk_about_dialog_set_logo( (GtkAboutDialog*)about_dlg, gdk_pixbuf_new_from_file( PACKAGE_DATA_DIR"/pixmaps/lxtask.png", NULL ) ); */
406 gtk_about_dialog_set_copyright ( (GtkAboutDialog*)about_dlg, _( "Copyright (C) 2008 LXDE team" ) );
407 gtk_about_dialog_set_comments ( (GtkAboutDialog*)about_dlg, _( "Lightweight task manager for LXDE project" ) );
408 gtk_about_dialog_set_license ( (GtkAboutDialog*)about_dlg, "LXTask\n\nCopyright (C) 2008 LXDE team\n\nThis program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA." );
409 gtk_about_dialog_set_website ( (GtkAboutDialog*)about_dlg, "http://lxde.org/" );
410 gtk_about_dialog_set_authors ( (GtkAboutDialog*)about_dlg, authors );
411 gtk_about_dialog_set_translator_credits ( (GtkAboutDialog*)about_dlg, translators );
412 /*gtk_window_set_transient_for( (GtkWindow*) about_dlg, GTK_WINDOW( this ) );*/
413
414 gtk_dialog_run( ( GtkDialog*)about_dlg );
415 gtk_widget_destroy( about_dlg );
416 }
417
418 void change_list_store_view(void)
419 {
420 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_PPID), full_view);
421 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_MEM), full_view);
422 //gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_RSS), full_view);
423 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_STATE), full_view);
424 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_PRIO), full_view);
425
426 if(!show_root_tasks && !show_other_tasks)
427 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_UNAME), full_view);
428 else
429 gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_UNAME), TRUE);
430 }
431
432 void fill_list_item(guint i, GtkTreeIter *iter)
433 {
434 if(iter != NULL)
435 {
436 char buf[32];
437 struct task *task = &g_array_index(task_array, struct task, i);
438
439 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_NAME, task->name, -1);
440 sprintf(buf,"%u",(guint)task->pid);
441 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PID, buf, -1);
442 sprintf(buf,"%u",(guint)task->ppid);
443 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PPID, buf, -1);
444 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_STATE, task->state, -1);
445
446 /* size */
447 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, (task->size)*1024), -1);
448
449 /* rss */
450 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, (task->rss)*1024), -1);
451
452 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_UNAME, task->uname, -1);
453 sprintf(buf,"%0d%%", (guint)task->time_percentage);
454 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_TIME, buf, -1);
455 sprintf(buf,"%d",task->prio);
456 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PRIO, buf, -1); /* my change */
457 }
458 }
459
460 void add_new_list_item(guint i)
461 {
462 GtkTreeIter iter;
463 gtk_tree_store_append(GTK_TREE_STORE(list_store), &iter, NULL);
464
465 fill_list_item(i, &iter);
466 }
467
468 void refresh_list_item(guint i)
469 {
470 GtkTreeIter iter;
471 gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
472 struct task *task = &g_array_index(task_array, struct task, i);
473 while(valid)
474 {
475 gchar *str_data = NULL;
476 gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
477
478 if(str_data && task->pid == atol(str_data))
479 {
480 g_free(str_data);
481 fill_list_item(i, &iter);
482 break;
483 }
484
485 g_free(str_data);
486 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter);
487 }
488 }
489
490 void remove_list_item(pid_t pid)
491 {
492 GtkTreeIter iter;
493 gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
494
495 while(valid)
496 {
497 gchar *str_data = NULL;
498 gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
499
500 if(str_data && pid == atol(str_data))
501 {
502 g_free(str_data);
503 gtk_tree_store_remove(GTK_TREE_STORE(list_store), &iter);
504 break;
505 }
506
507 g_free(str_data);
508 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter);
509 }
510 }
511
512 gint compare_int_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column)
513 {
514 gchar *s1 = "";
515 gchar *s2 = "";
516
517 gint ret;
518
519 gtk_tree_model_get(model, iter1, column, &s1, -1);
520 gtk_tree_model_get(model, iter2, column, &s2, -1);
521
522 gint i1 = 0;
523 gint i2 = 0;
524
525 if(s1 != NULL)
526 i1 = atoi(s1);
527 if(s2 != NULL)
528 i2 = atoi(s2);
529
530 ret = i2 - i1;
531
532 g_free(s1);
533 g_free(s2);
534
535 return ret;
536 }
537
538 gint compare_size_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column)
539 {
540 gchar *s1 = "";
541 gchar *s2 = "";
542
543 gint ret;
544
545 gtk_tree_model_get(model, iter1, column, &s1, -1);
546 gtk_tree_model_get(model, iter2, column, &s2, -1);
547
548 gint64 i1 = string_to_size(s1);
549 gint64 i2 = string_to_size(s2);
550
551 ret = i2 - i1;
552
553 g_free(s1);
554 g_free(s2);
555
556 return ret;
557 }
558
559 gint compare_string_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column)
560 {
561 gchar *s1 = "";
562 gchar *s2 = "";
563
564 gint ret = 0;
565
566 gtk_tree_model_get(model, iter1, GPOINTER_TO_INT(column), &s1, -1);
567 gtk_tree_model_get(model, iter2, GPOINTER_TO_INT(column), &s2, -1);
568
569 if(s1 != NULL && s2 != NULL)
570 ret = strcmp(s2, s1);
571
572 g_free(s1);
573 g_free(s2);
574
575 return ret;
576 }
577
578 /* change the task view (user, root, other) */
579 void change_task_view(void)
580 {
581 gint i = 0;
582
583 gtk_tree_store_clear(GTK_TREE_STORE(list_store));
584 change_list_store_view();
585
586 for(i = 0; i < tasks; i++)
587 {
588 struct task *task = &g_array_index(task_array, struct task, i);
589
590 if((task->uid == own_uid && show_user_tasks) || (task->uid == 0 && show_root_tasks) || (task->uid != own_uid && task->uid != 0 && show_other_tasks))
591 add_new_list_item(i);
592 }
593
594 refresh_task_list();
595 }
596
597 void change_full_path(void)
598 {
599 guint i;
600 GArray *new_task_list;
601
602 /* gets the new task list */
603 new_task_list = (GArray*) get_task_list();
604
605 /* check if task is new and marks the task that its checked*/
606 for(i = 0; i < task_array->len; i++)
607 {
608 struct task *tmp = &g_array_index(task_array, struct task, i);
609 struct task *new_tmp = &g_array_index(new_task_list, struct task, i);
610 g_strlcpy(tmp->name, new_tmp->name, 255);
611 refresh_list_item(i);
612 }
613
614 g_array_free(new_task_list, TRUE);
615 }
616
617 void apply_prefs()
618 {
619 g_source_remove(rID);
620 refresh_interval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (refresh_spin));
621 rID = g_timeout_add(1000 * refresh_interval, (gpointer) refresh_task_list, NULL);
622 }
623
624
625 void show_preferences(void)
626 {
627 GtkWidget *dlg;
628 GtkWidget *c_area;
629 GtkWidget *notebook = gtk_notebook_new();
630 GtkWidget *general_box = gtk_vbox_new(FALSE, 0);
631 GtkWidget *refresh_box = gtk_hbox_new(FALSE, 0);
632 refresh_spin = gtk_spin_button_new_with_range(1, 60, 1);
633 gtk_spin_button_set_value(GTK_SPIN_BUTTON(refresh_spin), refresh_interval);
634
635 dlg = gtk_dialog_new_with_buttons(_("Preferences"), NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
636 c_area = gtk_dialog_get_content_area(GTK_DIALOG (dlg));
637
638 gtk_box_pack_start(GTK_BOX (c_area), notebook, TRUE, TRUE, 0);
639 gtk_notebook_append_page(GTK_NOTEBOOK (notebook), general_box, gtk_label_new(_("General")));
640 gtk_box_pack_start(GTK_BOX (refresh_box), gtk_label_new(_("Refresh rate (seconds):")), TRUE, TRUE, 0);
641 gtk_box_pack_start(GTK_BOX (refresh_box), refresh_spin, TRUE, TRUE, 0);
642 gtk_box_pack_start(GTK_BOX (general_box), refresh_box, TRUE, TRUE, 0);
643
644 gtk_widget_show_all(notebook);
645
646 if (gtk_dialog_run(GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
647 apply_prefs();
648 gtk_widget_destroy(dlg);
649 }