Update memory sizes to 64 bit and fix compilation warnings.
[lxde/lxtask.git] / src / interface.c
CommitLineData
580e78c2
HJYP
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
7df4dd3e
HJYP
20/* 2008-04-26 modified by Hong Jen Yee to be used in LXDE. */
21
580e78c2
HJYP
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
401eb707 36void show_preferences(void);
4ab5f812 37extern gint refresh_interval;
401eb707 38extern guint rID;
39GtkWidget *refresh_spin;
40
580e78c2
HJYP
41GtkWidget* create_main_window (void)
42{
43 GtkWidget *window;
e3568c63 44 GtkWidget *menubar, *menu, *item;// *sub;
580e78c2
HJYP
45 GtkWidget *vbox1;
46 GtkWidget *bbox1;
47 GtkWidget *scrolledwindow1;
48 GtkWidget *button1;
e3568c63 49 // GtkWidget *button2;
580e78c2
HJYP
50 GtkWidget *button3;
51
52 GtkWidget *system_info_box;
53
580e78c2
HJYP
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);
d26006f1 57 gtk_window_set_icon_name (GTK_WINDOW (window),"utilities-system-monitor");
580e78c2 58
7df4dd3e
HJYP
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 );
d99df952 65 gtk_box_pack_start(GTK_BOX (bbox1), menubar, FALSE, TRUE, 0 );
7df4dd3e
HJYP
66
67 /* build menu */
68 menu = gtk_menu_new();
0d63e935 69
7df4dd3e 70 item = gtk_menu_item_new_with_mnemonic( _("_File") );
d99df952 71 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
7df4dd3e
HJYP
72 gtk_menu_shell_append( (GtkMenuShell*)menubar, item );
73
74 item = gtk_image_menu_item_new_from_stock( GTK_STOCK_QUIT, NULL );
0d63e935 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
7df4dd3e
HJYP
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();
d99df952 95 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
7df4dd3e
HJYP
96
97 item = gtk_menu_item_new_with_mnemonic( _("_Help") );
98 gtk_menu_shell_append( (GtkMenuShell*)menubar, item );
99 menu = gtk_menu_new();
d99df952 100 gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu );
7df4dd3e
HJYP
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 */
580e78c2
HJYP
110 vbox1 = gtk_vbox_new (FALSE, 10);
111 gtk_widget_show (vbox1);
d99df952 112 gtk_box_pack_start( GTK_BOX(bbox1), vbox1, TRUE, TRUE, 0 );
7df4dd3e 113 gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6);
580e78c2 114
5bf733ea 115 system_info_box = gtk_hbox_new (TRUE, 10);
580e78c2
HJYP
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 ();
b4cdfbff 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
580e78c2
HJYP
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 ();
b4cdfbff 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
580e78c2
HJYP
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
0d40bfa3 157 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list_store), COLUMN_TIME, GTK_SORT_ASCENDING);
580e78c2
HJYP
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
580e78c2
HJYP
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);
580e78c2
HJYP
175 g_signal_connect ((gpointer) button3, "toggled", G_CALLBACK (on_button3_toggled_event), NULL);
176
177 return window;
178}
179
180void 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
0d40bfa3 189 column = gtk_tree_view_column_new_with_attributes(_("Command"), cell_renderer, "text", COLUMN_NAME, NULL);
580e78c2 190 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3
HJYP
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);
580e78c2
HJYP
193 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
194
0d40bfa3 195 column = gtk_tree_view_column_new_with_attributes(_("User"), cell_renderer, "text", COLUMN_UNAME, NULL);
580e78c2 196 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3 197 gtk_tree_view_column_set_sort_column_id(column, COLUMN_UNAME);
02fb78fb 198 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_UNAME, compare_string_list_item, (void *)COLUMN_UNAME, NULL);
580e78c2
HJYP
199 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
200
a6523680 201 cell_renderer = gtk_cell_renderer_text_new();
202 g_object_set(cell_renderer, "xalign", 1.0, NULL);
203
0d40bfa3 204 column = gtk_tree_view_column_new_with_attributes(_("CPU%"), cell_renderer, "text", COLUMN_TIME, NULL);
580e78c2 205 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3 206 gtk_tree_view_column_set_sort_column_id(column, COLUMN_TIME);
5bb52e79 207 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_TIME, compare_int_list_item, (void *)COLUMN_TIME, NULL);
580e78c2
HJYP
208 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
209
0d40bfa3 210 column = gtk_tree_view_column_new_with_attributes(_("RSS"), cell_renderer, "text", COLUMN_RSS, NULL);
580e78c2 211 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3 212 gtk_tree_view_column_set_sort_column_id(column, COLUMN_RSS);
13bcb2f5 213 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_RSS, compare_size_list_item, (void *)COLUMN_RSS, NULL);
580e78c2
HJYP
214 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
215
0d40bfa3 216 column = gtk_tree_view_column_new_with_attributes(_("VM-Size"), cell_renderer, "text", COLUMN_MEM, NULL);
580e78c2 217 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3 218 gtk_tree_view_column_set_sort_column_id(column, COLUMN_MEM);
13bcb2f5 219 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_MEM, compare_size_list_item, (void *)COLUMN_MEM, NULL);
580e78c2
HJYP
220 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
221
0d40bfa3 222 column = gtk_tree_view_column_new_with_attributes(_("PID"), cell_renderer, "text", COLUMN_PID, NULL);
580e78c2 223 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3
HJYP
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);
580e78c2
HJYP
226 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
227
0d40bfa3 228 column = gtk_tree_view_column_new_with_attributes(_("State"), cell_renderer, "text", COLUMN_STATE, NULL);
580e78c2 229 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3
HJYP
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);
580e78c2
HJYP
232 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
233
0d40bfa3 234 column = gtk_tree_view_column_new_with_attributes(_("Prio"), cell_renderer, "text", COLUMN_PRIO, NULL);
580e78c2 235 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3
HJYP
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);
580e78c2
HJYP
238 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
239
0d40bfa3 240 column = gtk_tree_view_column_new_with_attributes(_("PPID"), cell_renderer, "text", COLUMN_PPID, NULL);
580e78c2 241 gtk_tree_view_column_set_resizable(column, TRUE);
0d40bfa3
HJYP
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);
580e78c2 244 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
580e78c2
HJYP
245
246 change_list_store_view();
247}
248
249GtkWidget* 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
284GtkWidget *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
317GtkWidget* create_mainmenu (void)
318{
319 GtkWidget *mainmenu;
e3568c63
AF
320// GtkWidget *info1;
321// GtkWidget *trennlinie1;
401eb707 322 GtkWidget *preferences1;
580e78c2
HJYP
323 GtkWidget *show_user_tasks1;
324 GtkWidget *show_root_tasks1;
325 GtkWidget *show_other_tasks1;
326 GtkWidget *show_cached_as_free1;
5ff47b84 327 GtkWidget *show_full_path1;
401eb707 328 GtkWidget *separator1;
580e78c2
HJYP
329 GtkAccelGroup *accel_group;
330
331 accel_group = gtk_accel_group_new ();
332
333 mainmenu = gtk_menu_new ();
334
580e78c2
HJYP
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
5ff47b84 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
580e78c2
HJYP
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
401eb707 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
580e78c2
HJYP
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);
5ff47b84 372 g_signal_connect ((gpointer) show_full_path1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-2);
0d40bfa3 373 g_signal_connect ((gpointer) show_cached_as_free1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0);
580e78c2
HJYP
374
375 gtk_menu_set_accel_group (GTK_MENU (mainmenu), accel_group);
376
377 return mainmenu;
378}
379
380void show_about_dialog(void)
381{
4de43a83
HJYP
382 GtkWidget * about_dlg;
383 const gchar *authors[] =
384 {
385 "Hong Jen Yee <pcman.tw@gmail.com>",
401eb707 386 "Jan Dlabal <dlabaljan@gmail.com>",
4de43a83
HJYP
387 _("LXTask is derived from Xfce4 Task Manager by:\n"
388 " * Johannes Zellner <webmaster@nebulon.de>"),
389 NULL
390 };
aed2946c 391 /* TRANSLATORS: Replace this string with your names, one name per line. */
4de43a83
HJYP
392 gchar *translators = _( "translator-credits" );
393
aed2946c 394 /* gtk_about_dialog_set_url_hook( open_url, this, NULL); */
4de43a83
HJYP
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 );
b4cdfbff 400#if !GTK_CHECK_VERSION(2,12,0)
4de43a83 401 gtk_about_dialog_set_name ( (GtkAboutDialog*)about_dlg, _( "LXTask" ) );
b4cdfbff 402#else
403 gtk_about_dialog_set_program_name ( (GtkAboutDialog*)about_dlg, _( "LXTask" ) );
404#endif
4de43a83
HJYP
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" ) );
aed2946c 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." );
3307ac17 409 gtk_about_dialog_set_website ( (GtkAboutDialog*)about_dlg, "http://lxde.org/" );
4de43a83
HJYP
410 gtk_about_dialog_set_authors ( (GtkAboutDialog*)about_dlg, authors );
411 gtk_about_dialog_set_translator_credits ( (GtkAboutDialog*)about_dlg, translators );
aed2946c 412 /*gtk_window_set_transient_for( (GtkWindow*) about_dlg, GTK_WINDOW( this ) );*/
4de43a83
HJYP
413
414 gtk_dialog_run( ( GtkDialog*)about_dlg );
415 gtk_widget_destroy( about_dlg );
580e78c2
HJYP
416}
417
418void 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);
92c3dce6 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);
580e78c2
HJYP
430}
431
4ab5f812 432void fill_list_item(guint i, GtkTreeIter *iter)
580e78c2
HJYP
433{
434 if(iter != NULL)
435 {
bdc67cb1 436 char buf[32];
580e78c2
HJYP
437 struct task *task = &g_array_index(task_array, struct task, i);
438
bdc67cb1 439 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_NAME, task->name, -1);
4ab5f812 440 sprintf(buf,"%u",(guint)task->pid);
bdc67cb1 441 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PID, buf, -1);
4ab5f812 442 sprintf(buf,"%u",(guint)task->ppid);
bdc67cb1 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);
e49a81f3
HJYP
445
446 /* size */
4ab5f812 447 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, (task->size)*1024), -1);
e49a81f3
HJYP
448
449 /* rss */
4ab5f812 450 gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, (task->rss)*1024), -1);
e49a81f3 451
bdc67cb1 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 */
580e78c2
HJYP
457 }
458}
459
4ab5f812 460void add_new_list_item(guint i)
580e78c2
HJYP
461{
462 GtkTreeIter iter;
580e78c2
HJYP
463 gtk_tree_store_append(GTK_TREE_STORE(list_store), &iter, NULL);
464
465 fill_list_item(i, &iter);
466}
467
4ab5f812 468void refresh_list_item(guint i)
580e78c2
HJYP
469{
470 GtkTreeIter iter;
471 gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
ac6cc864 472 struct task *task = &g_array_index(task_array, struct task, i);
580e78c2
HJYP
473 while(valid)
474 {
ac6cc864 475 gchar *str_data = NULL;
0d40bfa3 476 gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
580e78c2 477
4ab5f812 478 if(str_data && task->pid == atol(str_data))
580e78c2
HJYP
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
4ab5f812 490void remove_list_item(pid_t pid)
580e78c2
HJYP
491{
492 GtkTreeIter iter;
493 gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
494
495 while(valid)
496 {
ac6cc864 497 gchar *str_data = NULL;
7df4dd3e 498 gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
580e78c2 499
4ab5f812 500 if(str_data && pid == atol(str_data))
580e78c2
HJYP
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
512gint compare_int_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column)
513{
514 gchar *s1 = "";
515 gchar *s2 = "";
516
bdc67cb1 517 gint ret;
580e78c2
HJYP
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);
580e78c2
HJYP
527 if(s2 != NULL)
528 i2 = atoi(s2);
529
530 ret = i2 - i1;
531
bdc67cb1 532 g_free(s1);
533 g_free(s2);
580e78c2
HJYP
534
535 return ret;
536}
537
13bcb2f5 538gint compare_size_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column)
539{
540 gchar *s1 = "";
541 gchar *s2 = "";
542
bdc67cb1 543 gint ret;
13bcb2f5 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
580e78c2
HJYP
559gint 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);
580e78c2 571
bdc67cb1 572 g_free(s1);
573 g_free(s2);
580e78c2
HJYP
574
575 return ret;
576}
577
578/* change the task view (user, root, other) */
579void change_task_view(void)
580{
580e78c2
HJYP
581 gint i = 0;
582
92c3dce6 583 gtk_tree_store_clear(GTK_TREE_STORE(list_store));
584 change_list_store_view();
585
580e78c2
HJYP
586 for(i = 0; i < tasks; i++)
587 {
ac6cc864 588 struct task *task = &g_array_index(task_array, struct task, i);
580e78c2 589
ac6cc864 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))
580e78c2
HJYP
591 add_new_list_item(i);
592 }
593
594 refresh_task_list();
595}
596
5ff47b84 597void change_full_path(void)
598{
4ab5f812 599 guint i;
5ff47b84 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}
580e78c2 616
401eb707 617void 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
625void 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
b4cdfbff 638 gtk_box_pack_start(GTK_BOX (c_area), notebook, TRUE, TRUE, 0);
401eb707 639 gtk_notebook_append_page(GTK_NOTEBOOK (notebook), general_box, gtk_label_new(_("General")));
b4cdfbff 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);
401eb707 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}