diff --git a/2023-05-15-084858-6149-1@d2839764fa8b_help-translations/index.html b/2023-05-15-084858-6149-1@d2839764fa8b_help-translations/index.html new file mode 100644 index 00000000..3e6e8f3b --- /dev/null +++ b/2023-05-15-084858-6149-1@d2839764fa8b_help-translations/index.html @@ -0,0 +1,136 @@ + +
+User: | root@e0d6701afb77 |
---|---|
Working Directory: | /rootdir |
Command Line: | make -j 2 |
Clang Version: | clang version 16.0.2 (Fedora 16.0.2-1.fc38) + |
Date: | Mon May 15 08:48:58 2023 |
Bug Type | Quantity | Display? |
All Bugs | 14 | |
Logic error | ||
---|---|---|
Use of identical expressions | 1 | |
Unused code | ||
Dead assignment | 1 | |
Unreachable code | 12 |
Bug Group | +Bug Type ▾ | +File | +Function/Method | +Line | +Path Length | ++ + |
Unused code | Dead assignment | rootdir/src/disks.cpp | get_mount_opt | 201 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/procman-app.cpp | on_command_line | 381 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | io_rate_cell_data_func | 494 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | status_cell_data_func | 591 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/iconthemewrapper.cpp | load_gicon | 42 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | duration_cell_data_func | 535 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | memory_size_na_cell_data_func | 384 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | storage_size_na_cell_data_func | 456 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | storage_size_cell_data_func | 422 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/iconthemewrapper.cpp | load_icon | 13 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | time_cell_data_func | 564 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/procman-app.cpp | timeouts_changed_cb | 151 | 1 | View Report | + +
Unused code | Unreachable code | rootdir/src/util.cpp | memory_size_cell_data_func | 350 | 1 | View Report | + +
Logic error | Use of identical expressions | usr/include/sigc++-2.0/sigc++/visit_each.h | operator() | 98 | 1 | View Report | + +
File: | rootdir/src/procman-app.cpp |
Warning: | line 381, column 5 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <glib/gi18n.h> |
2 | #include <glibtop.h> |
3 | #include <glibtop/close.h> |
4 | #include <glibtop/cpu.h> |
5 | #include <glibtop/sysinfo.h> |
6 | |
7 | #include "procman-app.h" |
8 | #include "procman.h" |
9 | #include "interface.h" |
10 | #include "proctable.h" |
11 | #include "callbacks.h" |
12 | #include "load-graph.h" |
13 | #include "settings-keys.h" |
14 | #include "argv.h" |
15 | #include "util.h" |
16 | |
17 | static void |
18 | mount_changed(const Glib::RefPtr<Gio::Mount>&) |
19 | { |
20 | cb_update_disks(ProcData::get_instance()); |
21 | } |
22 | |
23 | |
24 | static void |
25 | init_volume_monitor(ProcData *procdata) |
26 | { |
27 | using namespace Gio; |
28 | using namespace Glib; |
29 | |
30 | RefPtr<VolumeMonitor> monitor = VolumeMonitor::get(); |
31 | |
32 | monitor->signal_mount_added().connect(sigc::ptr_fun(&mount_changed)); |
33 | monitor->signal_mount_changed().connect(sigc::ptr_fun(&mount_changed)); |
34 | monitor->signal_mount_removed().connect(sigc::ptr_fun(&mount_changed)); |
35 | } |
36 | |
37 | static gboolean |
38 | has_key (gchar **keys, const gchar *key) |
39 | { |
40 | gchar **loop = keys; |
41 | |
42 | while (*loop) { |
43 | if (!strcmp (*loop++, key)) |
44 | return TRUE(!(0)); |
45 | } |
46 | |
47 | return FALSE(0); |
48 | } |
49 | |
50 | static void |
51 | tree_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
52 | { |
53 | ProcData *procdata = static_cast<ProcData*>(data); |
54 | |
55 | procdata->config.show_tree = g_settings_get_boolean(settings, key); |
56 | |
57 | g_object_set(G_OBJECT(procdata->tree)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->tree)), (((GType) ((20) << (2)))))))), |
58 | "show-expanders", procdata->config.show_tree, |
59 | NULL__null); |
60 | |
61 | proctable_clear_tree (procdata); |
62 | proctable_update (procdata); |
63 | } |
64 | |
65 | static void |
66 | solaris_mode_changed_cb(GSettings *settings, const gchar *key, gpointer data) |
67 | { |
68 | ProcData *procdata = static_cast<ProcData*>(data); |
69 | |
70 | procdata->config.solaris_mode = g_settings_get_boolean(settings, key); |
71 | proctable_update (procdata); |
72 | } |
73 | |
74 | |
75 | static void |
76 | network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data) |
77 | { |
78 | ProcData *procdata = static_cast<ProcData*>(data); |
79 | |
80 | procdata->config.network_in_bits = g_settings_get_boolean(settings, key); |
81 | // force scale to be redrawn |
82 | procdata->net_graph->clear_background(); |
83 | } |
84 | |
85 | static void |
86 | view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
87 | { |
88 | ProcData *procdata = static_cast<ProcData*>(data); |
89 | |
90 | procdata->config.whose_process = g_settings_get_int (settings, key); |
91 | procdata->config.whose_process = CLAMP (procdata->config.whose_process, 0, 2)(((procdata->config.whose_process) > (2)) ? (2) : (((procdata ->config.whose_process) < (0)) ? (0) : (procdata->config .whose_process))); |
92 | proctable_clear_tree (procdata); |
93 | proctable_update (procdata); |
94 | } |
95 | |
96 | static void |
97 | warning_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
98 | { |
99 | ProcData *procdata = static_cast<ProcData*>(data); |
100 | |
101 | if (g_str_equal (key, "kill-dialog")(strcmp ((const char *) (key), (const char *) ("kill-dialog") ) == 0)) { |
102 | procdata->config.show_kill_warning = g_settings_get_boolean (settings, key); |
103 | } |
104 | } |
105 | |
106 | static void |
107 | timeouts_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
108 | { |
109 | ProcData *procdata = static_cast<ProcData*>(data); |
110 | |
111 | if (g_str_equal (key, "update-interval")(strcmp ((const char *) (key), (const char *) ("update-interval" )) == 0)) { |
112 | procdata->config.update_interval = g_settings_get_int (settings, key); |
113 | procdata->config.update_interval = |
114 | MAX (procdata->config.update_interval, 1000)(((procdata->config.update_interval) > (1000)) ? (procdata ->config.update_interval) : (1000)); |
115 | |
116 | procdata->smooth_refresh->reset(); |
117 | |
118 | if(procdata->timeout) { |
119 | g_source_remove (procdata->timeout); |
120 | procdata->timeout = g_timeout_add (procdata->config.update_interval, |
121 | cb_timeout, |
122 | procdata); |
123 | } |
124 | } |
125 | else if (g_str_equal (key, "graph-update-interval")(strcmp ((const char *) (key), (const char *) ("graph-update-interval" )) == 0)){ |
126 | procdata->config.graph_update_interval = g_settings_get_int (settings, key); |
127 | procdata->config.graph_update_interval = |
128 | MAX (procdata->config.graph_update_interval,(((procdata->config.graph_update_interval) > (250)) ? ( procdata->config.graph_update_interval) : (250)) |
129 | 250)(((procdata->config.graph_update_interval) > (250)) ? ( procdata->config.graph_update_interval) : (250)); |
130 | load_graph_change_speed(procdata->cpu_graph, |
131 | procdata->config.graph_update_interval); |
132 | load_graph_change_speed(procdata->mem_graph, |
133 | procdata->config.graph_update_interval); |
134 | load_graph_change_speed(procdata->net_graph, |
135 | procdata->config.graph_update_interval); |
136 | } |
137 | else if (g_str_equal(key, "disks-interval")(strcmp ((const char *) (key), (const char *) ("disks-interval" )) == 0)) { |
138 | procdata->config.disks_update_interval = g_settings_get_int (settings, key); |
139 | procdata->config.disks_update_interval = |
140 | MAX (procdata->config.disks_update_interval, 1000)(((procdata->config.disks_update_interval) > (1000)) ? ( procdata->config.disks_update_interval) : (1000)); |
141 | |
142 | if(procdata->disk_timeout) { |
143 | g_source_remove (procdata->disk_timeout); |
144 | procdata->disk_timeout = \ |
145 | g_timeout_add (procdata->config.disks_update_interval, |
146 | cb_update_disks, |
147 | procdata); |
148 | } |
149 | } |
150 | else { |
151 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "procman-app.cpp" , 151, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
152 | } |
153 | } |
154 | |
155 | static void |
156 | color_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
157 | { |
158 | ProcData * const procdata = static_cast<ProcData*>(data); |
159 | gchar *color = g_settings_get_string (settings, key); |
160 | |
161 | if (g_str_has_prefix (key, "cpu-color")(__builtin_constant_p ("cpu-color")? __extension__ ({ const char * const __str = (key); const char * const __prefix = ("cpu-color" ); gboolean __result = (0); if (__str == __null || __prefix == __null) __result = (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len = strlen (((__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (key, "cpu-color") )) { |
162 | for (int i = 0; i < procdata->config.num_cpus; i++) { |
163 | string cpu_key = make_string(g_strdup_printf("cpu-color%d", i)); |
164 | if (cpu_key == key) { |
165 | gdk_rgba_parse (&procdata->config.cpu_color[i], color); |
166 | procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i]; |
167 | break; |
168 | } |
169 | } |
170 | } |
171 | else if (g_str_equal (key, "mem-color")(strcmp ((const char *) (key), (const char *) ("mem-color")) == 0)) { |
172 | gdk_rgba_parse (&procdata->config.mem_color, color); |
173 | procdata->mem_graph->colors.at(0) = procdata->config.mem_color; |
174 | } |
175 | else if (g_str_equal (key, "swap-color")(strcmp ((const char *) (key), (const char *) ("swap-color")) == 0)) { |
176 | gdk_rgba_parse (&procdata->config.swap_color, color); |
177 | procdata->mem_graph->colors.at(1) = procdata->config.swap_color; |
178 | } |
179 | else if (g_str_equal (key, "net-in-color")(strcmp ((const char *) (key), (const char *) ("net-in-color" )) == 0)) { |
180 | gdk_rgba_parse (&procdata->config.net_in_color, color); |
181 | procdata->net_graph->colors.at(0) = procdata->config.net_in_color; |
182 | } |
183 | else if (g_str_equal (key, "net-out-color")(strcmp ((const char *) (key), (const char *) ("net-out-color" )) == 0)) { |
184 | gdk_rgba_parse (&procdata->config.net_out_color, color); |
185 | procdata->net_graph->colors.at(1) = procdata->config.net_out_color; |
186 | } |
187 | else { |
188 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "procman-app.cpp" , 188, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
189 | } |
190 | g_free(color); |
191 | } |
192 | |
193 | static void |
194 | show_all_fs_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
195 | { |
196 | ProcData * const procdata = static_cast<ProcData*>(data); |
197 | |
198 | procdata->config.show_all_fs = g_settings_get_boolean (settings, key); |
199 | |
200 | cb_update_disks (data); |
201 | } |
202 | |
203 | static ProcData * |
204 | procman_data_new (GSettings *settings) |
205 | { |
206 | GSettingsSchema *schema; |
207 | ProcData *pd; |
208 | gchar *color; |
209 | gchar **keys; |
210 | glibtop_cpu cpu; |
211 | |
212 | pd = ProcData::get_instance(); |
213 | |
214 | g_settings_get (settings, "window-state", "(iiii)", |
215 | &pd->config.width, &pd->config.height, |
216 | &pd->config.xpos, &pd->config.ypos); |
217 | |
218 | pd->config.maximized = g_settings_get_boolean(settings, "maximized"); |
219 | |
220 | pd->config.show_tree = g_settings_get_boolean (settings, "show-tree"); |
221 | g_signal_connect (G_OBJECT(settings), "changed::show-tree", G_CALLBACK(tree_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::show-tree"), (((GCallback) (tree_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
222 | |
223 | pd->config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str()); |
224 | std::string detail_string("changed::" + procman::settings::solaris_mode); |
225 | g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(solaris_mode_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (solaris_mode_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
226 | |
227 | pd->config.network_in_bits = g_settings_get_boolean(settings, procman::settings::network_in_bits.c_str()); |
228 | detail_string = "changed::" + procman::settings::network_in_bits; |
229 | g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(network_in_bits_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (network_in_bits_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
230 | |
231 | pd->config.show_kill_warning = g_settings_get_boolean (settings, "kill-dialog"); |
232 | g_signal_connect (G_OBJECT(settings), "changed::kill-dialog", G_CALLBACK(warning_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::kill-dialog"), (((GCallback) (warning_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
233 | pd->config.update_interval = g_settings_get_int (settings, "update-interval"); |
234 | g_signal_connect (G_OBJECT(settings), "changed::update-interval", G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::update-interval"), (((GCallback) (timeouts_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
235 | pd->config.graph_update_interval = g_settings_get_int (settings, |
236 | "graph-update-interval"); |
237 | g_signal_connect (G_OBJECT(settings), "changed::graph-update-interval",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::graph-update-interval"), (((GCallback) ( timeouts_changed_cb))), (pd), __null, (GConnectFlags) 0) |
238 | G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::graph-update-interval"), (((GCallback) ( timeouts_changed_cb))), (pd), __null, (GConnectFlags) 0); |
239 | pd->config.disks_update_interval = g_settings_get_int (settings, "disks-interval"); |
240 | g_signal_connect (G_OBJECT(settings), "changed::disks-interval", G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::disks-interval"), (((GCallback) (timeouts_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
241 | |
242 | |
243 | /* show_all_fs */ |
244 | pd->config.show_all_fs = g_settings_get_boolean (settings, "show-all-fs"); |
245 | g_signal_connect (settings, "changed::show-all-fs", G_CALLBACK(show_all_fs_changed_cb), pd)g_signal_connect_data ((settings), ("changed::show-all-fs"), ( ((GCallback) (show_all_fs_changed_cb))), (pd), __null, (GConnectFlags ) 0); |
246 | |
247 | |
248 | pd->config.whose_process = g_settings_get_int (settings, "view-as"); |
249 | g_signal_connect (G_OBJECT(settings), "changed::view-as", G_CALLBACK(view_as_changed_cb),pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::view-as"), (((GCallback) (view_as_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
250 | pd->config.current_tab = g_settings_get_int (settings, "current-tab"); |
251 | |
252 | glibtop_get_cpu (&cpu); |
253 | pd->frequency = cpu.frequency; |
254 | pd->config.num_cpus = glibtop_get_sysinfo()->ncpu; // or server->ncpu + 1 |
255 | |
256 | g_object_get (settings, "settings-schema", &schema, NULL__null); |
257 | keys = g_settings_schema_list_keys (schema); |
258 | g_settings_schema_unref (schema); |
259 | |
260 | for (int i = 0; i < pd->config.num_cpus; i++) { |
261 | gchar *key; |
262 | key = g_strdup_printf ("cpu-color%d", i); |
263 | |
264 | if (has_key (keys, key)) |
265 | color = g_settings_get_string (settings, key); |
266 | else |
267 | color = g_strdup ("#f25915e815e8")g_strdup_inline ("#f25915e815e8"); |
268 | detail_string = std::string("changed::") + std::string(key); |
269 | g_signal_connect (G_OBJECT(settings), detail_string.c_str(),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
270 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
271 | gdk_rgba_parse (&pd->config.cpu_color[i], color); |
272 | g_free (color); |
273 | g_free (key); |
274 | } |
275 | g_strfreev (keys); |
276 | |
277 | color = g_settings_get_string (settings, "mem-color"); |
278 | if (!color) |
279 | color = g_strdup ("#000000ff0082")g_strdup_inline ("#000000ff0082"); |
280 | g_signal_connect (G_OBJECT(settings), "changed::mem-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::mem-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
281 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::mem-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
282 | gdk_rgba_parse(&pd->config.mem_color, color); |
283 | g_free (color); |
284 | |
285 | color = g_settings_get_string (settings, "swap-color"); |
286 | if (!color) |
287 | color = g_strdup ("#00b6000000ff")g_strdup_inline ("#00b6000000ff"); |
288 | g_signal_connect (G_OBJECT(settings), "changed::swap-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::swap-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
289 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::swap-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
290 | gdk_rgba_parse(&pd->config.swap_color, color); |
291 | g_free (color); |
292 | |
293 | color = g_settings_get_string (settings, "net-in-color"); |
294 | if (!color) |
295 | color = g_strdup ("#000000f200f2")g_strdup_inline ("#000000f200f2"); |
296 | g_signal_connect (G_OBJECT(settings), "changed::net-in-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-in-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
297 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-in-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
298 | gdk_rgba_parse(&pd->config.net_in_color, color); |
299 | g_free (color); |
300 | |
301 | color = g_settings_get_string (settings, "net-out-color"); |
302 | if (!color) |
303 | color = g_strdup ("#00f2000000c1")g_strdup_inline ("#00f2000000c1"); |
304 | g_signal_connect (G_OBJECT(settings), "changed::net-out-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-out-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
305 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-out-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
306 | gdk_rgba_parse(&pd->config.net_out_color, color); |
307 | g_free (color); |
308 | |
309 | /* Sanity checks */ |
310 | GdkDisplay *display; |
311 | GdkMonitor *monitor; |
312 | GdkRectangle monitor_geometry; |
313 | |
314 | display = gdk_display_get_default (); |
315 | monitor = gdk_display_get_monitor_at_point (display, pd->config.xpos, pd->config.ypos); |
316 | if (monitor == NULL__null) { |
317 | monitor = gdk_display_get_monitor (display, 0); |
318 | } |
319 | gdk_monitor_get_geometry (monitor, &monitor_geometry); |
320 | |
321 | pd->config.width = CLAMP (pd->config.width, 50, monitor_geometry.width)(((pd->config.width) > (monitor_geometry.width)) ? (monitor_geometry .width) : (((pd->config.width) < (50)) ? (50) : (pd-> config.width))); |
322 | pd->config.height = CLAMP (pd->config.height, 50, monitor_geometry.height)(((pd->config.height) > (monitor_geometry.height)) ? (monitor_geometry .height) : (((pd->config.height) < (50)) ? (50) : (pd-> config.height))); |
323 | pd->config.update_interval = MAX (pd->config.update_interval, 1000)(((pd->config.update_interval) > (1000)) ? (pd->config .update_interval) : (1000)); |
324 | pd->config.graph_update_interval = MAX (pd->config.graph_update_interval, 250)(((pd->config.graph_update_interval) > (250)) ? (pd-> config.graph_update_interval) : (250)); |
325 | pd->config.disks_update_interval = MAX (pd->config.disks_update_interval, 1000)(((pd->config.disks_update_interval) > (1000)) ? (pd-> config.disks_update_interval) : (1000)); |
326 | pd->config.whose_process = CLAMP (pd->config.whose_process, 0, 2)(((pd->config.whose_process) > (2)) ? (2) : (((pd->config .whose_process) < (0)) ? (0) : (pd->config.whose_process ))); |
327 | pd->config.current_tab = CLAMP(pd->config.current_tab,(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))) |
328 | PROCMAN_TAB_SYSINFO,(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))) |
329 | PROCMAN_TAB_DISKS)(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))); |
330 | |
331 | // delayed initialization as SmoothRefresh() needs ProcData |
332 | // i.e. we can't call ProcData::get_instance |
333 | pd->smooth_refresh = new SmoothRefresh(settings); |
334 | |
335 | pd->terminating = FALSE(0); |
336 | |
337 | return pd; |
338 | } |
339 | |
340 | static void |
341 | procman_free_data (ProcData *procdata) |
342 | { |
343 | |
344 | proctable_free_table (procdata); |
345 | delete procdata->smooth_refresh; |
346 | } |
347 | |
348 | ProcmanApp::ProcmanApp() : Gtk::Application("org.mate.SystemMonitor", Gio::APPLICATION_HANDLES_COMMAND_LINE) |
349 | { |
350 | Glib::set_application_name(_("System Monitor")gettext ("System Monitor")); |
351 | } |
352 | |
353 | Glib::RefPtr<ProcmanApp> ProcmanApp::create () |
354 | { |
355 | return Glib::RefPtr<ProcmanApp>(new ProcmanApp()); |
356 | } |
357 | |
358 | void ProcmanApp::on_activate() |
359 | { |
360 | gtk_window_present (GTK_WINDOW (procdata->app)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->app)), ((gtk_window_get_type ()))))))); |
361 | } |
362 | |
363 | static void |
364 | set_tab(GtkNotebook* notebook, gint tab, ProcData* procdata) |
365 | { |
366 | gtk_notebook_set_current_page(notebook, tab); |
367 | cb_change_current_page(notebook, tab, procdata); |
368 | } |
369 | |
370 | int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line) |
371 | { |
372 | int argc = 0; |
373 | char** argv = command_line->get_arguments(argc); |
374 | |
375 | Glib::OptionContext context; |
376 | context.set_summary(_("A simple process and system monitor.")gettext ("A simple process and system monitor.")); |
377 | context.set_ignore_unknown_options(true); |
378 | procman::OptionGroup option_group; |
379 | context.set_main_group(option_group); |
380 | |
381 | try { |
This statement is never executed | |
382 | context.parse(argc, argv); |
383 | } catch (const Glib::Error& ex) { |
384 | g_error("Arguments parse error : %s", ex.what().c_str()); |
385 | } |
386 | |
387 | if (option_group.show_system_tab) { |
388 | procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request")procman_debug_real("procman-app.cpp", 388, __func__, "Starting with PROCMAN_TAB_SYSINFO by commandline request" ); |
389 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_SYSINFO, procdata); |
390 | } else if (option_group.show_processes_tab) { |
391 | procman_debug("Starting with PROCMAN_TAB_PROCESSES by commandline request")procman_debug_real("procman-app.cpp", 391, __func__, "Starting with PROCMAN_TAB_PROCESSES by commandline request" ); |
392 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_PROCESSES, procdata); |
393 | } else if (option_group.show_resources_tab) { |
394 | procman_debug("Starting with PROCMAN_TAB_RESOURCES by commandline request")procman_debug_real("procman-app.cpp", 394, __func__, "Starting with PROCMAN_TAB_RESOURCES by commandline request" ); |
395 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_RESOURCES, procdata); |
396 | } else if (option_group.show_file_systems_tab) { |
397 | procman_debug("Starting with PROCMAN_TAB_DISKS by commandline request")procman_debug_real("procman-app.cpp", 397, __func__, "Starting with PROCMAN_TAB_DISKS by commandline request" ); |
398 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_DISKS, procdata); |
399 | } |
400 | |
401 | on_activate (); |
402 | |
403 | return 0; |
404 | } |
405 | |
406 | void ProcmanApp::on_startup() |
407 | { |
408 | Gtk::Application::on_startup(); |
409 | |
410 | GSettings *settings; |
411 | |
412 | Gtk::Window::set_default_icon_name ("utilities-system-monitor"); |
413 | |
414 | settings = g_settings_new (GSM_GSETTINGS_SCHEMA"org.mate.system-monitor"); |
415 | |
416 | glibtop_init (); |
417 | |
418 | procdata = procman_data_new (settings); |
419 | procdata->settings = g_settings_new(GSM_GSETTINGS_SCHEMA"org.mate.system-monitor"); |
420 | |
421 | create_main_window (procdata); |
422 | init_volume_monitor (procdata); |
423 | |
424 | Gtk::Window *window = Glib::wrap(GTK_WINDOW(procdata->app)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->app)), ((gtk_window_get_type ()))))))); |
425 | window->show(); |
426 | window->set_name ("mate-system-monitor"); |
427 | |
428 | add_window (*window); |
429 | } |
430 | |
431 | void ProcmanApp::on_shutdown() |
432 | { |
433 | procman_free_data(procdata); |
434 | glibtop_close(); |
435 | } |
436 |
File: | rootdir/src/util.cpp |
Warning: | line 494, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/util.cpp |
Warning: | line 591, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/iconthemewrapper.cpp |
Warning: | line 42, column 5 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <gtkmm/icontheme.h> |
4 | #include <giomm/error.h> |
5 | |
6 | #include "iconthemewrapper.h" |
7 | |
8 | |
9 | Glib::RefPtr<Gdk::Pixbuf> |
10 | procman::IconThemeWrapper::load_icon(const Glib::ustring& icon_name, int size) const |
11 | { |
12 | gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ()); |
13 | try |
14 | { |
15 | return Gtk::IconTheme::get_default()->load_icon(icon_name, size, scale, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE); |
16 | } |
17 | catch (Gtk::IconThemeError &error) |
18 | { |
19 | if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND) |
20 | g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str()); |
21 | return Glib::RefPtr<Gdk::Pixbuf>(); |
22 | } |
23 | catch (Gio::Error &error) |
24 | { |
25 | g_debug("Could not load icon '%s' : %s", icon_name.c_str(), error.what().c_str()); |
26 | return Glib::RefPtr<Gdk::Pixbuf>(); |
27 | } |
28 | } |
29 | |
30 | Glib::RefPtr<Gdk::Pixbuf> |
31 | procman::IconThemeWrapper::load_gicon(const Glib::RefPtr<Gio::Icon>& gicon, |
32 | int size, Gtk::IconLookupFlags flags) const |
33 | { |
34 | Gtk::IconInfo icon_info; |
35 | gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ()); |
36 | icon_info = Gtk::IconTheme::get_default()->lookup_icon(gicon, size, scale, flags); |
37 | |
38 | if (!icon_info) { |
39 | return Glib::RefPtr<Gdk::Pixbuf>(); |
40 | } |
41 | |
42 | try |
This statement is never executed | |
43 | { |
44 | return icon_info.load_icon(); |
45 | } |
46 | catch (Gtk::IconThemeError &error) |
47 | { |
48 | if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND) |
49 | g_error("Cannot load gicon from theme: %s", error.what().c_str()); |
50 | return Glib::RefPtr<Gdk::Pixbuf>(); |
51 | } |
52 | catch (Gio::Error &error) |
53 | { |
54 | g_debug("Could not load gicon: %s", error.what().c_str()); |
55 | return Glib::RefPtr<Gdk::Pixbuf>(); |
56 | } |
57 | } |
File: | rootdir/src/util.cpp |
Warning: | line 535, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | usr/include/sigc++-2.0/sigc++/visit_each.h |
Warning: | line 98, column 64 identical expressions on both sides of logical operator |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | /* |
2 | * Copyright 2002, The libsigc++ Development Team |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library 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 GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | */ |
18 | #ifndef _SIGC_VISIT_EACH_HPP_ |
19 | #define _SIGC_VISIT_EACH_HPP_ |
20 | |
21 | #include <sigc++/type_traits.h> |
22 | #include <type_traits> |
23 | |
24 | namespace sigc { |
25 | |
26 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
27 | namespace internal { |
28 | |
29 | //This should really be an inner class of limit_derived_target, without the T_limit template type, |
30 | //But the SUN CC 5.7 (not earlier versions) compiler finds it ambiguous when we specify a particular specialization of it. |
31 | //and does not seem to allow us to tell it explicitly that it's an inner class. |
32 | template <bool I_derived, class T_type, class T_limit> |
33 | struct with_type; |
34 | |
35 | //Specialization for I_derived = false |
36 | template <class T_type, class T_limit> struct |
37 | with_type<false, T_type, T_limit> |
38 | { |
39 | static void execute_(const T_type&, const T_limit&) {} |
40 | }; |
41 | |
42 | //Specialization for I_derived = true |
43 | template <class T_type, class T_limit> |
44 | struct with_type<true, T_type, T_limit> |
45 | { |
46 | static void execute_(const T_type& _A_type, const T_limit& _A_action) |
47 | { _A_action.action_(_A_type); } |
48 | }; |
49 | |
50 | |
51 | /// Helper struct for visit_each_type(). |
52 | template <class T_target, class T_action> |
53 | struct limit_derived_target |
54 | { |
55 | typedef limit_derived_target<T_target, T_action> T_self; |
56 | |
57 | template <class T_type> |
58 | void operator()(const T_type& _A_type) const |
59 | { |
60 | with_type<std::is_base_of<T_target, T_type>::value || std::is_same<T_target, T_type>::value, T_type, T_self>::execute_(_A_type, *this); |
61 | } |
62 | |
63 | limit_derived_target(const T_action& _A_action) |
64 | : action_(_A_action) |
65 | {} |
66 | |
67 | T_action action_; |
68 | }; |
69 | |
70 | // Specialization for T_target pointer types, to provide a slightly different execute_() implementation. |
71 | |
72 | template <bool I_derived, class T_type, class T_limit> |
73 | struct with_type_pointer; |
74 | |
75 | //Specialization for I_derived = false |
76 | template <class T_type, class T_limit> |
77 | struct with_type_pointer<false, T_type, T_limit> |
78 | { |
79 | static void execute_(const T_type&, const T_limit&) {} |
80 | }; |
81 | |
82 | //Specialization for I_derived = true |
83 | template <class T_type, class T_limit> |
84 | struct with_type_pointer<true, T_type, T_limit> |
85 | { |
86 | static void execute_(const T_type& _A_type, const T_limit& _A_action) |
87 | { _A_action.action_(&_A_type); } |
88 | }; |
89 | |
90 | template <class T_target, class T_action> |
91 | struct limit_derived_target<T_target*, T_action> |
92 | { |
93 | typedef limit_derived_target<T_target*, T_action> T_self; |
94 | |
95 | template <class T_type> |
96 | void operator()(const T_type& _A_type) const |
97 | { |
98 | with_type_pointer<std::is_base_of<T_target, T_type>::value || std::is_same<T_target, T_type>::value, T_type, T_self>::execute_(_A_type, *this); |
identical expressions on both sides of logical operator | |
99 | } |
100 | |
101 | limit_derived_target(const T_action& _A_action) |
102 | : action_(_A_action) |
103 | {} |
104 | |
105 | T_action action_; |
106 | }; |
107 | |
108 | } /* namespace internal */ |
109 | #endif // DOXYGEN_SHOULD_SKIP_THIS |
110 | |
111 | // struct visitor was introduced as a result of https://bugzilla.gnome.org/show_bug.cgi?id=724496 |
112 | // The advantage of using specializations of a template struct instead of overloads of |
113 | // a template function is described by Herb Sutter in http://www.gotw.ca/publications/mill17.htm |
114 | // In libsigc++ the main reason for using this technique is that we can avoid using ADL |
115 | // (argument-dependent lookup), and therefore there is no risk that a visit_each() overload |
116 | // in e.g. Boost is selected by mistake. |
117 | |
118 | /** sigc::visitor<T_functor>::do_visit_each() performs a functor on each of the targets of a functor. |
119 | * All unknown types just call @a _A_action on them. |
120 | * Add specializations that specialize the @a T_functor argument for your own |
121 | * functor types, so that subobjects get visited. This is needed to enable |
122 | * auto-disconnection support for your functor types. |
123 | * |
124 | * @par Example: |
125 | * @code |
126 | * namespace some_ns |
127 | * { |
128 | * struct some_functor |
129 | * { |
130 | * void operator()() {} |
131 | * some_possibly_sigc_trackable_derived_type some_data_member; |
132 | * some_other_functor_type some_other_functor; |
133 | * }; |
134 | * } |
135 | * |
136 | * namespace sigc |
137 | * { |
138 | * template <> |
139 | * struct visitor<some_ns::some_functor> |
140 | * { |
141 | * template <class T_action> |
142 | * static void do_visit_each(const T_action& _A_action, |
143 | * const some_ns::some_functor& _A_target) |
144 | * { |
145 | * sigc::visit_each(_A_action, _A_target.some_data_member); |
146 | * sigc::visit_each(_A_action, _A_target.some_other_functor); |
147 | * } |
148 | * }; |
149 | * } |
150 | * @endcode |
151 | * |
152 | * @ingroup sigcfunctors |
153 | */ |
154 | template <class T_functor> |
155 | struct visitor |
156 | { |
157 | template <class T_action> |
158 | static void do_visit_each(const T_action& _A_action, const T_functor& _A_functor) |
159 | { |
160 | _A_action(_A_functor); |
161 | } |
162 | }; |
163 | |
164 | /** This function performs a functor on each of the targets of a functor. |
165 | * |
166 | * @ingroup sigcfunctors |
167 | */ |
168 | template <class T_action, class T_functor> |
169 | void visit_each(const T_action& _A_action, const T_functor& _A_functor) |
170 | { sigc::visitor<T_functor>::do_visit_each(_A_action, _A_functor); } |
171 | |
172 | /** This function performs a functor on each of the targets |
173 | * of a functor limited to a restricted type. |
174 | * |
175 | * @ingroup sigcfunctors |
176 | */ |
177 | template <class T_type, class T_action, class T_functor> |
178 | void visit_each_type(const T_action& _A_action, const T_functor& _A_functor) |
179 | { |
180 | typedef internal::limit_derived_target<T_type, T_action> type_limited_action; |
181 | |
182 | type_limited_action limited_action(_A_action); |
183 | |
184 | //specifying the types of the template specialization prevents disconnection of bound trackable references (such as with std::ref()), |
185 | //probably because the visit_each<> specializations take various different template types, |
186 | //in various sequences, and we are probably specifying only a subset of them with this. |
187 | // |
188 | //But this is required by the AIX (and maybe IRIX MipsPro and Tru64) compilers. |
189 | //I guess that std::ref() therefore does not work on those platforms. murrayc |
190 | // sigc::visit_each<type_limited_action, T_functor>(limited_action, _A_functor); |
191 | |
192 | //g++ (even slightly old ones) is our primary platform, so we could use the non-crashing version. |
193 | //However, the explicit version also fixes a crash in a slightly more common case: http://bugzilla.gnome.org/show_bug.cgi?id=169225 |
194 | //Users (and distributors) of libsigc++ on AIX (and maybe IRIX MipsPro and Tru64) do |
195 | //need to use the version above instead, to allow compilation. |
196 | |
197 | //Added 2014-03-20: The preceding comment probably does not apply any more, |
198 | //now when the visit_each<>() overloads have been replaced by visitor<> specializations. |
199 | //It's probably safe to add explicit template parameters on calls to visit_each(), |
200 | //visit_each_type() and visitor::do_visit_each(), if necessary. |
201 | |
202 | sigc::visit_each(limited_action, _A_functor); |
203 | } |
204 | |
205 | } /* namespace sigc */ |
206 | #endif |
File: | rootdir/src/util.cpp |
Warning: | line 384, column 15 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/util.cpp |
Warning: | line 456, column 15 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/util.cpp |
Warning: | line 422, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/iconthemewrapper.cpp |
Warning: | line 13, column 5 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <gtkmm/icontheme.h> |
4 | #include <giomm/error.h> |
5 | |
6 | #include "iconthemewrapper.h" |
7 | |
8 | |
9 | Glib::RefPtr<Gdk::Pixbuf> |
10 | procman::IconThemeWrapper::load_icon(const Glib::ustring& icon_name, int size) const |
11 | { |
12 | gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ()); |
13 | try |
This statement is never executed | |
14 | { |
15 | return Gtk::IconTheme::get_default()->load_icon(icon_name, size, scale, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE); |
16 | } |
17 | catch (Gtk::IconThemeError &error) |
18 | { |
19 | if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND) |
20 | g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str()); |
21 | return Glib::RefPtr<Gdk::Pixbuf>(); |
22 | } |
23 | catch (Gio::Error &error) |
24 | { |
25 | g_debug("Could not load icon '%s' : %s", icon_name.c_str(), error.what().c_str()); |
26 | return Glib::RefPtr<Gdk::Pixbuf>(); |
27 | } |
28 | } |
29 | |
30 | Glib::RefPtr<Gdk::Pixbuf> |
31 | procman::IconThemeWrapper::load_gicon(const Glib::RefPtr<Gio::Icon>& gicon, |
32 | int size, Gtk::IconLookupFlags flags) const |
33 | { |
34 | Gtk::IconInfo icon_info; |
35 | gint scale = gdk_window_get_scale_factor (gdk_get_default_root_window ()); |
36 | icon_info = Gtk::IconTheme::get_default()->lookup_icon(gicon, size, scale, flags); |
37 | |
38 | if (!icon_info) { |
39 | return Glib::RefPtr<Gdk::Pixbuf>(); |
40 | } |
41 | |
42 | try |
43 | { |
44 | return icon_info.load_icon(); |
45 | } |
46 | catch (Gtk::IconThemeError &error) |
47 | { |
48 | if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND) |
49 | g_error("Cannot load gicon from theme: %s", error.what().c_str()); |
50 | return Glib::RefPtr<Gdk::Pixbuf>(); |
51 | } |
52 | catch (Gio::Error &error) |
53 | { |
54 | g_debug("Could not load gicon: %s", error.what().c_str()); |
55 | return Glib::RefPtr<Gdk::Pixbuf>(); |
56 | } |
57 | } |
File: | rootdir/src/disks.cpp |
Warning: | line 201, column 13 Value stored to 'res' is never read |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #ifdef __linux__1 |
4 | #include <mntent.h> |
5 | #endif // __linux__ |
6 | |
7 | #include <giomm.h> |
8 | #include <giomm/themedicon.h> |
9 | #include <gtk/gtk.h> |
10 | #include <glibtop/mountlist.h> |
11 | #include <glibtop/fsusage.h> |
12 | #include <glib/gi18n.h> |
13 | |
14 | #include "procman.h" |
15 | #include "disks.h" |
16 | #include "util.h" |
17 | #include "interface.h" |
18 | #include "iconthemewrapper.h" |
19 | |
20 | namespace |
21 | { |
22 | const unsigned DISK_ICON_SIZE = 24; |
23 | } |
24 | |
25 | enum DiskColumns |
26 | { |
27 | /* string columns* */ |
28 | DISK_DEVICE, |
29 | DISK_DIR, |
30 | DISK_TYPE, |
31 | DISK_SUBVOLUME, |
32 | DISK_TOTAL, |
33 | DISK_FREE, |
34 | DISK_AVAIL, |
35 | /* USED has to be the last column */ |
36 | DISK_USED, |
37 | // then unvisible columns |
38 | /* Surface column */ |
39 | DISK_ICON, |
40 | /* numeric columns */ |
41 | DISK_USED_PERCENTAGE, |
42 | DISK_N_COLUMNS |
43 | }; |
44 | |
45 | |
46 | |
47 | static void |
48 | fsusage_stats(const glibtop_fsusage *buf, |
49 | guint64 *bused, guint64 *bfree, guint64 *bavail, guint64 *btotal, |
50 | gint *percentage) |
51 | { |
52 | guint64 total = buf->blocks * buf->block_size; |
53 | |
54 | if (!total) { |
55 | /* not a real device */ |
56 | *btotal = *bfree = *bavail = *bused = 0ULL; |
57 | *percentage = 0; |
58 | } else { |
59 | int percent; |
60 | *btotal = total; |
61 | *bfree = buf->bfree * buf->block_size; |
62 | *bavail = buf->bavail * buf->block_size; |
63 | *bused = *btotal - *bfree; |
64 | /* percent = 100.0f * *bused / *btotal; */ |
65 | percent = 100 * *bused / (*bused + *bavail); |
66 | *percentage = CLAMP(percent, 0, 100)(((percent) > (100)) ? (100) : (((percent) < (0)) ? (0) : (percent))); |
67 | } |
68 | } |
69 | |
70 | |
71 | namespace |
72 | { |
73 | string get_icon_for_path(const std::string& path) |
74 | { |
75 | using namespace Glib; |
76 | using namespace Gio; |
77 | |
78 | // FIXME: I don't know whether i should use Volume or Mount or UnixMount |
79 | // all i need an icon name. |
80 | RefPtr<VolumeMonitor> monitor = VolumeMonitor::get(); |
81 | |
82 | std::vector<RefPtr<Mount> > mounts = monitor->get_mounts(); |
83 | |
84 | for (size_t i = 0; i != mounts.size(); ++i) { |
85 | if (mounts[i]->get_name() != path) |
86 | continue; |
87 | |
88 | RefPtr<Icon> icon = mounts[i]->get_icon(); |
89 | RefPtr<ThemedIcon> themed_icon = RefPtr<ThemedIcon>::cast_dynamic(icon); |
90 | |
91 | if (themed_icon) { |
92 | char* name = 0; |
93 | // FIXME: not wrapped yet |
94 | g_object_get(G_OBJECT(themed_icon->gobj())((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((themed_icon->gobj())), (((GType) ((20) << (2))) ))))), "name", &name, NULL__null); |
95 | return make_string(name); |
96 | } |
97 | } |
98 | |
99 | return ""; |
100 | } |
101 | } |
102 | |
103 | |
104 | static Glib::RefPtr<Gdk::Pixbuf> |
105 | get_icon_for_device(const char *mountpoint) |
106 | { |
107 | procman::IconThemeWrapper icon_theme; |
108 | string icon_name = get_icon_for_path(mountpoint); |
109 | if (icon_name == "") |
110 | // FIXME: defaults to a safe value |
111 | icon_name = "drive-harddisk"; // get_icon_for_path("/"); |
112 | return icon_theme->load_icon(icon_name, DISK_ICON_SIZE); |
113 | } |
114 | |
115 | |
116 | static gboolean |
117 | find_disk_in_model(GtkTreeModel *model, const char *mountpoint, |
118 | GtkTreeIter *result) |
119 | { |
120 | GtkTreeIter iter; |
121 | gboolean found = FALSE(0); |
122 | |
123 | if (gtk_tree_model_get_iter_first(model, &iter)) { |
124 | do { |
125 | char *dir; |
126 | |
127 | gtk_tree_model_get(model, &iter, |
128 | DISK_DIR, &dir, |
129 | -1); |
130 | |
131 | if (dir && !strcmp(dir, mountpoint)) { |
132 | *result = iter; |
133 | found = TRUE(!(0)); |
134 | } |
135 | |
136 | g_free(dir); |
137 | |
138 | } while (!found && gtk_tree_model_iter_next(model, &iter)); |
139 | } |
140 | |
141 | return found; |
142 | } |
143 | |
144 | |
145 | |
146 | static void |
147 | remove_old_disks(GtkTreeModel *model, const glibtop_mountentry *entries, guint n) |
148 | { |
149 | GtkTreeIter iter; |
150 | |
151 | if (!gtk_tree_model_get_iter_first(model, &iter)) |
152 | return; |
153 | |
154 | while (true) { |
155 | char *dir; |
156 | guint i; |
157 | gboolean found = FALSE(0); |
158 | |
159 | gtk_tree_model_get(model, &iter, |
160 | DISK_DIR, &dir, |
161 | -1); |
162 | |
163 | for (i = 0; i != n; ++i) { |
164 | if (!strcmp(dir, entries[i].mountdir)) { |
165 | found = TRUE(!(0)); |
166 | break; |
167 | } |
168 | } |
169 | |
170 | g_free(dir); |
171 | |
172 | if (!found) { |
173 | if (!gtk_list_store_remove(GTK_LIST_STORE(model)((((GtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_list_store_get_type ())))))), &iter)) |
174 | break; |
175 | else |
176 | continue; |
177 | } |
178 | |
179 | if (!gtk_tree_model_iter_next(model, &iter)) |
180 | break; |
181 | } |
182 | } |
183 | |
184 | #ifdef __linux__1 |
185 | static char * |
186 | get_mount_opt(const glibtop_mountentry *entry, const char* opt) |
187 | { |
188 | char *opt_value = NULL__null; |
189 | const struct mntent *mnt; |
190 | FILE *fp; |
191 | |
192 | if (!(fp = setmntent(MOUNTED"/etc/mtab", "r"))) { |
193 | goto out; |
194 | } |
195 | |
196 | while ((mnt = getmntent(fp))) { |
197 | if ((g_strcmp0(entry->mountdir, mnt->mnt_dir) == 0) && |
198 | (g_strcmp0(entry->devname, mnt->mnt_fsname) == 0)) { |
199 | char *res; |
200 | |
201 | res = hasmntopt(mnt, "subvol"); |
Value stored to 'res' is never read | |
202 | if ((res = hasmntopt(mnt, "subvol")) != NULL__null) { |
203 | char **strs = g_strsplit_set(res, "=", 2); |
204 | |
205 | if (g_strv_length(strs) == 2) { |
206 | char *value = strs[1]; |
207 | if (g_strcmp0 (value,"/root") == 0) |
208 | opt_value = g_strdup("/")g_strdup_inline ("/"); |
209 | else |
210 | opt_value = g_strdup(strs[1])g_strdup_inline (strs[1]); |
211 | g_strfreev(strs); |
212 | } |
213 | } |
214 | break; |
215 | } |
216 | } |
217 | |
218 | endmntent(fp); |
219 | |
220 | out: |
221 | return opt_value; |
222 | } |
223 | #endif // __linux__ |
224 | |
225 | |
226 | static void |
227 | add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs) |
228 | { |
229 | Glib::RefPtr<Gdk::Pixbuf> pixbuf; |
230 | cairo_surface_t *surface; |
231 | GtkTreeIter iter; |
232 | glibtop_fsusage usage; |
233 | guint64 bused, bfree, bavail, btotal; |
234 | gint percentage; |
235 | #ifdef __linux__1 |
236 | char *subvol = NULL__null; |
237 | #endif // __linux__ |
238 | |
239 | glibtop_get_fsusage(&usage, entry->mountdir); |
240 | |
241 | if (not show_all_fs and usage.blocks == 0) { |
242 | if (find_disk_in_model(GTK_TREE_MODEL(list)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((list)), ((gtk_tree_model_get_type ())))))), entry->mountdir, &iter)) |
243 | gtk_list_store_remove(list, &iter); |
244 | return; |
245 | } |
246 | |
247 | fsusage_stats(&usage, &bused, &bfree, &bavail, &btotal, &percentage); |
248 | #ifdef __linux__1 |
249 | subvol = get_mount_opt(entry, "subvol"); |
250 | #endif // __linux__ |
251 | pixbuf = get_icon_for_device(entry->mountdir); |
252 | surface = gdk_cairo_surface_create_from_pixbuf (pixbuf->gobj(), 0, NULL__null); |
253 | |
254 | /* if we can find a row with the same mountpoint, we get it but we |
255 | still need to update all the fields. |
256 | This makes selection persistent. |
257 | */ |
258 | if (!find_disk_in_model(GTK_TREE_MODEL(list)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((list)), ((gtk_tree_model_get_type ())))))), entry->mountdir, &iter)) |
259 | gtk_list_store_append(list, &iter); |
260 | |
261 | gtk_list_store_set(list, &iter, |
262 | DISK_ICON, surface, |
263 | DISK_DEVICE, entry->devname, |
264 | DISK_DIR, entry->mountdir, |
265 | DISK_TYPE, entry->type, |
266 | #ifdef __linux__1 |
267 | |
268 | DISK_SUBVOLUME, subvol != NULL__null ? subvol : "", |
269 | #else |
270 | DISK_SUBVOLUME, "", |
271 | #endif // __linux__ |
272 | DISK_USED_PERCENTAGE, percentage, |
273 | DISK_TOTAL, btotal, |
274 | DISK_FREE, bfree, |
275 | DISK_AVAIL, bavail, |
276 | DISK_USED, bused, |
277 | -1); |
278 | #ifdef __linux__1 |
279 | g_free (subvol); |
280 | #endif // __linux__ |
281 | } |
282 | |
283 | |
284 | |
285 | int |
286 | cb_update_disks(gpointer data) |
287 | { |
288 | ProcData *const procdata = static_cast<ProcData*>(data); |
289 | |
290 | GtkListStore *list; |
291 | glibtop_mountentry * entries; |
292 | glibtop_mountlist mountlist; |
293 | guint i; |
294 | |
295 | list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->disk_list)))((((GtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((gtk_tree_view_get_model(((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((procdata->disk_list)), ((gtk_tree_view_get_type ()))))))))), ((gtk_list_store_get_type ())))))); |
296 | |
297 | entries = glibtop_get_mountlist(&mountlist, procdata->config.show_all_fs); |
298 | |
299 | remove_old_disks(GTK_TREE_MODEL(list)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((list)), ((gtk_tree_model_get_type ())))))), entries, mountlist.number); |
300 | |
301 | for (i = 0; i < mountlist.number; i++) |
302 | add_disk(list, &entries[i], procdata->config.show_all_fs); |
303 | |
304 | g_free(entries); |
305 | |
306 | return TRUE(!(0)); |
307 | } |
308 | |
309 | |
310 | static void |
311 | cb_disk_columns_changed(GtkTreeView *treeview, gpointer user_data) |
312 | { |
313 | ProcData * const procdata = static_cast<ProcData*>(user_data); |
314 | |
315 | procman_save_tree_state(procdata->settings, |
316 | GTK_WIDGET(treeview)((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((treeview)), ((gtk_widget_get_type ())))))), |
317 | "disktreenew"); |
318 | } |
319 | |
320 | |
321 | static void |
322 | open_dir(GtkTreeView *tree_view, |
323 | GtkTreePath *path, |
324 | GtkTreeViewColumn *column, |
325 | gpointer user_data) |
326 | { |
327 | GtkTreeIter iter; |
328 | GtkTreeModel *model; |
329 | char *dir, *url; |
330 | |
331 | model = gtk_tree_view_get_model(tree_view); |
332 | |
333 | if (!gtk_tree_model_get_iter(model, &iter, path)) { |
334 | char *p; |
335 | p = gtk_tree_path_to_string(path); |
336 | g_warning("Cannot get iter for path '%s'\n", p); |
337 | g_free(p); |
338 | return; |
339 | } |
340 | |
341 | gtk_tree_model_get(model, &iter, DISK_DIR, &dir, -1); |
342 | |
343 | url = g_strdup_printf("file://%s", dir); |
344 | |
345 | GError* error = 0; |
346 | if (!g_app_info_launch_default_for_uri(url, NULL__null, &error)) { |
347 | g_warning("Cannot open '%s' : %s\n", url, error->message); |
348 | g_error_free(error); |
349 | } |
350 | |
351 | g_free(url); |
352 | g_free(dir); |
353 | } |
354 | |
355 | static guint timeout_id = 0; |
356 | static GtkTreeViewColumn *current_column; |
357 | |
358 | static gboolean |
359 | save_column_width (gpointer data) |
360 | { |
361 | gint width; |
362 | gchar *key; |
363 | int id; |
364 | GSettings *settings; |
365 | |
366 | settings = g_settings_get_child (G_SETTINGS (data)((((GSettings*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((g_settings_get_type ())))))), "disktreenew"); |
367 | id = gtk_tree_view_column_get_sort_column_id (current_column); |
368 | width = gtk_tree_view_column_get_width (current_column); |
369 | |
370 | key = g_strdup_printf ("col-%d-width", id); |
371 | g_settings_set_int(settings, key, width); |
372 | g_free (key); |
373 | |
374 | if (timeout_id) { |
375 | g_source_remove (timeout_id); |
376 | timeout_id = 0; |
377 | } |
378 | |
379 | return FALSE(0); |
380 | } |
381 | |
382 | static void |
383 | cb_disks_column_resized(GtkWidget *widget, GParamSpec *pspec, gpointer data) |
384 | { |
385 | current_column = GTK_TREE_VIEW_COLUMN(widget)((((GtkTreeViewColumn*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((widget)), ((gtk_tree_view_column_get_type ( ))))))); |
386 | |
387 | if (timeout_id) |
388 | g_source_remove (timeout_id); |
389 | |
390 | timeout_id = g_timeout_add (250, save_column_width, data); |
391 | } |
392 | |
393 | void |
394 | create_disk_view(ProcData *procdata, GtkBuilder *builder) |
395 | { |
396 | GtkWidget *scrolled; |
397 | GtkWidget *disk_tree; |
398 | GtkListStore *model; |
399 | GtkTreeViewColumn *col; |
400 | GtkCellRenderer *cell; |
401 | guint i; |
402 | |
403 | const gchar * const titles[] = { |
404 | N_("Device")("Device"), |
405 | N_("Directory")("Directory"), |
406 | N_("Type")("Type"), |
407 | N_("SubVolume")("SubVolume"), |
408 | N_("Total")("Total"), |
409 | N_("Free")("Free"), |
410 | N_("Available")("Available"), |
411 | N_("Used")("Used") |
412 | }; |
413 | |
414 | scrolled = GTK_WIDGET (gtk_builder_get_object (builder, "disks_scrolled"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((gtk_builder_get_object (builder, "disks_scrolled"))), (( gtk_widget_get_type ())))))); |
415 | |
416 | model = gtk_list_store_new(DISK_N_COLUMNS, /* n columns */ |
417 | G_TYPE_STRING((GType) ((16) << (2))), /* DISK_DEVICE */ |
418 | G_TYPE_STRING((GType) ((16) << (2))), /* DISK_DIR */ |
419 | G_TYPE_STRING((GType) ((16) << (2))), /* DISK_TYPE */ |
420 | G_TYPE_STRING((GType) ((16) << (2))), /* DISK_SUBVOLUME */ |
421 | G_TYPE_UINT64((GType) ((11) << (2))), /* DISK_TOTAL */ |
422 | G_TYPE_UINT64((GType) ((11) << (2))), /* DISK_FREE */ |
423 | G_TYPE_UINT64((GType) ((11) << (2))), /* DISK_AVAIL */ |
424 | G_TYPE_UINT64((GType) ((11) << (2))), /* DISK_USED */ |
425 | CAIRO_GOBJECT_TYPE_SURFACEcairo_gobject_surface_get_type (), /* DISK_ICON */ |
426 | G_TYPE_INT((GType) ((6) << (2)))); /* DISK_USED_PERCENTAGE */ |
427 | |
428 | disk_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_model_get_type ()))))))); |
429 | g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((disk_tree)), (((GType) ((20) << (2 ))))))))), ("row-activated"), (((GCallback) (open_dir))), (__null ), __null, (GConnectFlags) 0); |
430 | procdata->disk_list = disk_tree; |
431 | gtk_container_add(GTK_CONTAINER(scrolled)((((GtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((scrolled)), ((gtk_container_get_type ())))))), disk_tree); |
432 | g_object_unref(G_OBJECT(model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2))))))))); |
433 | |
434 | /* icon + device */ |
435 | |
436 | col = gtk_tree_view_column_new(); |
437 | cell = gtk_cell_renderer_pixbuf_new(); |
438 | gtk_tree_view_column_pack_start(col, cell, FALSE(0)); |
439 | gtk_tree_view_column_set_attributes(col, cell, "surface", DISK_ICON, |
440 | NULL__null); |
441 | |
442 | cell = gtk_cell_renderer_text_new(); |
443 | gtk_tree_view_column_pack_start(col, cell, FALSE(0)); |
444 | gtk_tree_view_column_set_attributes(col, cell, "text", DISK_DEVICE, |
445 | NULL__null); |
446 | gtk_tree_view_column_set_title(col, _(titles[DISK_DEVICE])gettext (titles[DISK_DEVICE])); |
447 | gtk_tree_view_column_set_sort_column_id(col, DISK_DEVICE); |
448 | gtk_tree_view_column_set_reorderable(col, TRUE(!(0))); |
449 | gtk_tree_view_column_set_resizable(col, TRUE(!(0))); |
450 | gtk_tree_view_column_set_min_width (col, 30); |
451 | gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); |
452 | g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((col)), (((GType) ((20) << (2)))))) ))), ("notify::fixed-width"), (((GCallback) (cb_disks_column_resized ))), (procdata->settings), __null, (GConnectFlags) 0); |
453 | gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((disk_tree)), ((gtk_tree_view_get_type ())))))), col); |
454 | |
455 | /* sizes - used */ |
456 | |
457 | for (i = DISK_DIR; i <= DISK_AVAIL; i++) { |
458 | cell = gtk_cell_renderer_text_new(); |
459 | col = gtk_tree_view_column_new(); |
460 | gtk_tree_view_column_pack_start(col, cell, TRUE(!(0))); |
461 | gtk_tree_view_column_set_title(col, _(titles[i])gettext (titles[i])); |
462 | gtk_tree_view_column_set_sort_column_id(col, i); |
463 | gtk_tree_view_column_set_reorderable(col, TRUE(!(0))); |
464 | gtk_tree_view_column_set_resizable(col, TRUE(!(0))); |
465 | gtk_tree_view_column_set_min_width (col, 30); |
466 | gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); |
467 | g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((col)), (((GType) ((20) << (2)))))) ))), ("notify::fixed-width"), (((GCallback) (cb_disks_column_resized ))), (procdata->settings), __null, (GConnectFlags) 0); |
468 | gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((disk_tree)), ((gtk_tree_view_get_type ())))))), col); |
469 | |
470 | switch (i) { |
471 | case DISK_TOTAL: |
472 | case DISK_FREE: |
473 | case DISK_AVAIL: |
474 | g_object_set(cell, "xalign", 1.0f, NULL__null); |
475 | gtk_tree_view_column_set_cell_data_func(col, cell, |
476 | &procman::storage_size_cell_data_func, |
477 | GUINT_TO_POINTER(i)((gpointer) (gulong) (i)), |
478 | NULL__null); |
479 | break; |
480 | |
481 | default: |
482 | gtk_tree_view_column_set_attributes(col, cell, |
483 | "text", i, |
484 | NULL__null); |
485 | break; |
486 | } |
487 | } |
488 | |
489 | /* used + percentage */ |
490 | |
491 | col = gtk_tree_view_column_new(); |
492 | cell = gtk_cell_renderer_text_new(); |
493 | g_object_set(cell, "xalign", 1.0f, NULL__null); |
494 | gtk_tree_view_column_pack_start(col, cell, FALSE(0)); |
495 | gtk_tree_view_column_set_cell_data_func(col, cell, |
496 | &procman::storage_size_cell_data_func, |
497 | GUINT_TO_POINTER(DISK_USED)((gpointer) (gulong) (DISK_USED)), |
498 | NULL__null); |
499 | |
500 | cell = gtk_cell_renderer_progress_new(); |
501 | gtk_tree_view_column_pack_start(col, cell, TRUE(!(0))); |
502 | gtk_tree_view_column_set_attributes(col, cell, "value", |
503 | DISK_USED_PERCENTAGE, NULL__null); |
504 | gtk_tree_view_column_set_title(col, _(titles[DISK_USED])gettext (titles[DISK_USED])); |
505 | gtk_tree_view_column_set_sort_column_id(col, DISK_USED); |
506 | gtk_tree_view_column_set_reorderable(col, TRUE(!(0))); |
507 | gtk_tree_view_column_set_resizable(col, TRUE(!(0))); |
508 | gtk_tree_view_column_set_min_width (col, 150); |
509 | gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); |
510 | g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((col)), (((GType) ((20) << (2)))))) ))), ("notify::fixed-width"), (((GCallback) (cb_disks_column_resized ))), (procdata->settings), __null, (GConnectFlags) 0); |
511 | gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((disk_tree)), ((gtk_tree_view_get_type ())))))), col); |
512 | |
513 | /* numeric sort */ |
514 | |
515 | procman_get_tree_state(procdata->settings, disk_tree, |
516 | "disktreenew"); |
517 | |
518 | g_signal_connect (G_OBJECT(disk_tree), "columns-changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((disk_tree)), (((GType) ((20) << (2 ))))))))), ("columns-changed"), (((GCallback) (cb_disk_columns_changed ))), (procdata), __null, (GConnectFlags) 0) |
519 | G_CALLBACK(cb_disk_columns_changed), procdata)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((disk_tree)), (((GType) ((20) << (2 ))))))))), ("columns-changed"), (((GCallback) (cb_disk_columns_changed ))), (procdata), __null, (GConnectFlags) 0); |
520 | } |
File: | rootdir/src/util.cpp |
Warning: | line 564, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |
File: | rootdir/src/procman-app.cpp |
Warning: | line 151, column 9 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <glib/gi18n.h> |
2 | #include <glibtop.h> |
3 | #include <glibtop/close.h> |
4 | #include <glibtop/cpu.h> |
5 | #include <glibtop/sysinfo.h> |
6 | |
7 | #include "procman-app.h" |
8 | #include "procman.h" |
9 | #include "interface.h" |
10 | #include "proctable.h" |
11 | #include "callbacks.h" |
12 | #include "load-graph.h" |
13 | #include "settings-keys.h" |
14 | #include "argv.h" |
15 | #include "util.h" |
16 | |
17 | static void |
18 | mount_changed(const Glib::RefPtr<Gio::Mount>&) |
19 | { |
20 | cb_update_disks(ProcData::get_instance()); |
21 | } |
22 | |
23 | |
24 | static void |
25 | init_volume_monitor(ProcData *procdata) |
26 | { |
27 | using namespace Gio; |
28 | using namespace Glib; |
29 | |
30 | RefPtr<VolumeMonitor> monitor = VolumeMonitor::get(); |
31 | |
32 | monitor->signal_mount_added().connect(sigc::ptr_fun(&mount_changed)); |
33 | monitor->signal_mount_changed().connect(sigc::ptr_fun(&mount_changed)); |
34 | monitor->signal_mount_removed().connect(sigc::ptr_fun(&mount_changed)); |
35 | } |
36 | |
37 | static gboolean |
38 | has_key (gchar **keys, const gchar *key) |
39 | { |
40 | gchar **loop = keys; |
41 | |
42 | while (*loop) { |
43 | if (!strcmp (*loop++, key)) |
44 | return TRUE(!(0)); |
45 | } |
46 | |
47 | return FALSE(0); |
48 | } |
49 | |
50 | static void |
51 | tree_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
52 | { |
53 | ProcData *procdata = static_cast<ProcData*>(data); |
54 | |
55 | procdata->config.show_tree = g_settings_get_boolean(settings, key); |
56 | |
57 | g_object_set(G_OBJECT(procdata->tree)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->tree)), (((GType) ((20) << (2)))))))), |
58 | "show-expanders", procdata->config.show_tree, |
59 | NULL__null); |
60 | |
61 | proctable_clear_tree (procdata); |
62 | proctable_update (procdata); |
63 | } |
64 | |
65 | static void |
66 | solaris_mode_changed_cb(GSettings *settings, const gchar *key, gpointer data) |
67 | { |
68 | ProcData *procdata = static_cast<ProcData*>(data); |
69 | |
70 | procdata->config.solaris_mode = g_settings_get_boolean(settings, key); |
71 | proctable_update (procdata); |
72 | } |
73 | |
74 | |
75 | static void |
76 | network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data) |
77 | { |
78 | ProcData *procdata = static_cast<ProcData*>(data); |
79 | |
80 | procdata->config.network_in_bits = g_settings_get_boolean(settings, key); |
81 | // force scale to be redrawn |
82 | procdata->net_graph->clear_background(); |
83 | } |
84 | |
85 | static void |
86 | view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
87 | { |
88 | ProcData *procdata = static_cast<ProcData*>(data); |
89 | |
90 | procdata->config.whose_process = g_settings_get_int (settings, key); |
91 | procdata->config.whose_process = CLAMP (procdata->config.whose_process, 0, 2)(((procdata->config.whose_process) > (2)) ? (2) : (((procdata ->config.whose_process) < (0)) ? (0) : (procdata->config .whose_process))); |
92 | proctable_clear_tree (procdata); |
93 | proctable_update (procdata); |
94 | } |
95 | |
96 | static void |
97 | warning_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
98 | { |
99 | ProcData *procdata = static_cast<ProcData*>(data); |
100 | |
101 | if (g_str_equal (key, "kill-dialog")(strcmp ((const char *) (key), (const char *) ("kill-dialog") ) == 0)) { |
102 | procdata->config.show_kill_warning = g_settings_get_boolean (settings, key); |
103 | } |
104 | } |
105 | |
106 | static void |
107 | timeouts_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
108 | { |
109 | ProcData *procdata = static_cast<ProcData*>(data); |
110 | |
111 | if (g_str_equal (key, "update-interval")(strcmp ((const char *) (key), (const char *) ("update-interval" )) == 0)) { |
112 | procdata->config.update_interval = g_settings_get_int (settings, key); |
113 | procdata->config.update_interval = |
114 | MAX (procdata->config.update_interval, 1000)(((procdata->config.update_interval) > (1000)) ? (procdata ->config.update_interval) : (1000)); |
115 | |
116 | procdata->smooth_refresh->reset(); |
117 | |
118 | if(procdata->timeout) { |
119 | g_source_remove (procdata->timeout); |
120 | procdata->timeout = g_timeout_add (procdata->config.update_interval, |
121 | cb_timeout, |
122 | procdata); |
123 | } |
124 | } |
125 | else if (g_str_equal (key, "graph-update-interval")(strcmp ((const char *) (key), (const char *) ("graph-update-interval" )) == 0)){ |
126 | procdata->config.graph_update_interval = g_settings_get_int (settings, key); |
127 | procdata->config.graph_update_interval = |
128 | MAX (procdata->config.graph_update_interval,(((procdata->config.graph_update_interval) > (250)) ? ( procdata->config.graph_update_interval) : (250)) |
129 | 250)(((procdata->config.graph_update_interval) > (250)) ? ( procdata->config.graph_update_interval) : (250)); |
130 | load_graph_change_speed(procdata->cpu_graph, |
131 | procdata->config.graph_update_interval); |
132 | load_graph_change_speed(procdata->mem_graph, |
133 | procdata->config.graph_update_interval); |
134 | load_graph_change_speed(procdata->net_graph, |
135 | procdata->config.graph_update_interval); |
136 | } |
137 | else if (g_str_equal(key, "disks-interval")(strcmp ((const char *) (key), (const char *) ("disks-interval" )) == 0)) { |
138 | procdata->config.disks_update_interval = g_settings_get_int (settings, key); |
139 | procdata->config.disks_update_interval = |
140 | MAX (procdata->config.disks_update_interval, 1000)(((procdata->config.disks_update_interval) > (1000)) ? ( procdata->config.disks_update_interval) : (1000)); |
141 | |
142 | if(procdata->disk_timeout) { |
143 | g_source_remove (procdata->disk_timeout); |
144 | procdata->disk_timeout = \ |
145 | g_timeout_add (procdata->config.disks_update_interval, |
146 | cb_update_disks, |
147 | procdata); |
148 | } |
149 | } |
150 | else { |
151 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "procman-app.cpp" , 151, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
152 | } |
153 | } |
154 | |
155 | static void |
156 | color_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
157 | { |
158 | ProcData * const procdata = static_cast<ProcData*>(data); |
159 | gchar *color = g_settings_get_string (settings, key); |
160 | |
161 | if (g_str_has_prefix (key, "cpu-color")(__builtin_constant_p ("cpu-color")? __extension__ ({ const char * const __str = (key); const char * const __prefix = ("cpu-color" ); gboolean __result = (0); if (__str == __null || __prefix == __null) __result = (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len = strlen (((__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (key, "cpu-color") )) { |
162 | for (int i = 0; i < procdata->config.num_cpus; i++) { |
163 | string cpu_key = make_string(g_strdup_printf("cpu-color%d", i)); |
164 | if (cpu_key == key) { |
165 | gdk_rgba_parse (&procdata->config.cpu_color[i], color); |
166 | procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i]; |
167 | break; |
168 | } |
169 | } |
170 | } |
171 | else if (g_str_equal (key, "mem-color")(strcmp ((const char *) (key), (const char *) ("mem-color")) == 0)) { |
172 | gdk_rgba_parse (&procdata->config.mem_color, color); |
173 | procdata->mem_graph->colors.at(0) = procdata->config.mem_color; |
174 | } |
175 | else if (g_str_equal (key, "swap-color")(strcmp ((const char *) (key), (const char *) ("swap-color")) == 0)) { |
176 | gdk_rgba_parse (&procdata->config.swap_color, color); |
177 | procdata->mem_graph->colors.at(1) = procdata->config.swap_color; |
178 | } |
179 | else if (g_str_equal (key, "net-in-color")(strcmp ((const char *) (key), (const char *) ("net-in-color" )) == 0)) { |
180 | gdk_rgba_parse (&procdata->config.net_in_color, color); |
181 | procdata->net_graph->colors.at(0) = procdata->config.net_in_color; |
182 | } |
183 | else if (g_str_equal (key, "net-out-color")(strcmp ((const char *) (key), (const char *) ("net-out-color" )) == 0)) { |
184 | gdk_rgba_parse (&procdata->config.net_out_color, color); |
185 | procdata->net_graph->colors.at(1) = procdata->config.net_out_color; |
186 | } |
187 | else { |
188 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "procman-app.cpp" , 188, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
189 | } |
190 | g_free(color); |
191 | } |
192 | |
193 | static void |
194 | show_all_fs_changed_cb (GSettings *settings, const gchar *key, gpointer data) |
195 | { |
196 | ProcData * const procdata = static_cast<ProcData*>(data); |
197 | |
198 | procdata->config.show_all_fs = g_settings_get_boolean (settings, key); |
199 | |
200 | cb_update_disks (data); |
201 | } |
202 | |
203 | static ProcData * |
204 | procman_data_new (GSettings *settings) |
205 | { |
206 | GSettingsSchema *schema; |
207 | ProcData *pd; |
208 | gchar *color; |
209 | gchar **keys; |
210 | glibtop_cpu cpu; |
211 | |
212 | pd = ProcData::get_instance(); |
213 | |
214 | g_settings_get (settings, "window-state", "(iiii)", |
215 | &pd->config.width, &pd->config.height, |
216 | &pd->config.xpos, &pd->config.ypos); |
217 | |
218 | pd->config.maximized = g_settings_get_boolean(settings, "maximized"); |
219 | |
220 | pd->config.show_tree = g_settings_get_boolean (settings, "show-tree"); |
221 | g_signal_connect (G_OBJECT(settings), "changed::show-tree", G_CALLBACK(tree_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::show-tree"), (((GCallback) (tree_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
222 | |
223 | pd->config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str()); |
224 | std::string detail_string("changed::" + procman::settings::solaris_mode); |
225 | g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(solaris_mode_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (solaris_mode_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
226 | |
227 | pd->config.network_in_bits = g_settings_get_boolean(settings, procman::settings::network_in_bits.c_str()); |
228 | detail_string = "changed::" + procman::settings::network_in_bits; |
229 | g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(network_in_bits_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (network_in_bits_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
230 | |
231 | pd->config.show_kill_warning = g_settings_get_boolean (settings, "kill-dialog"); |
232 | g_signal_connect (G_OBJECT(settings), "changed::kill-dialog", G_CALLBACK(warning_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::kill-dialog"), (((GCallback) (warning_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
233 | pd->config.update_interval = g_settings_get_int (settings, "update-interval"); |
234 | g_signal_connect (G_OBJECT(settings), "changed::update-interval", G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::update-interval"), (((GCallback) (timeouts_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
235 | pd->config.graph_update_interval = g_settings_get_int (settings, |
236 | "graph-update-interval"); |
237 | g_signal_connect (G_OBJECT(settings), "changed::graph-update-interval",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::graph-update-interval"), (((GCallback) ( timeouts_changed_cb))), (pd), __null, (GConnectFlags) 0) |
238 | G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::graph-update-interval"), (((GCallback) ( timeouts_changed_cb))), (pd), __null, (GConnectFlags) 0); |
239 | pd->config.disks_update_interval = g_settings_get_int (settings, "disks-interval"); |
240 | g_signal_connect (G_OBJECT(settings), "changed::disks-interval", G_CALLBACK(timeouts_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::disks-interval"), (((GCallback) (timeouts_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
241 | |
242 | |
243 | /* show_all_fs */ |
244 | pd->config.show_all_fs = g_settings_get_boolean (settings, "show-all-fs"); |
245 | g_signal_connect (settings, "changed::show-all-fs", G_CALLBACK(show_all_fs_changed_cb), pd)g_signal_connect_data ((settings), ("changed::show-all-fs"), ( ((GCallback) (show_all_fs_changed_cb))), (pd), __null, (GConnectFlags ) 0); |
246 | |
247 | |
248 | pd->config.whose_process = g_settings_get_int (settings, "view-as"); |
249 | g_signal_connect (G_OBJECT(settings), "changed::view-as", G_CALLBACK(view_as_changed_cb),pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::view-as"), (((GCallback) (view_as_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
250 | pd->config.current_tab = g_settings_get_int (settings, "current-tab"); |
251 | |
252 | glibtop_get_cpu (&cpu); |
253 | pd->frequency = cpu.frequency; |
254 | pd->config.num_cpus = glibtop_get_sysinfo()->ncpu; // or server->ncpu + 1 |
255 | |
256 | g_object_get (settings, "settings-schema", &schema, NULL__null); |
257 | keys = g_settings_schema_list_keys (schema); |
258 | g_settings_schema_unref (schema); |
259 | |
260 | for (int i = 0; i < pd->config.num_cpus; i++) { |
261 | gchar *key; |
262 | key = g_strdup_printf ("cpu-color%d", i); |
263 | |
264 | if (has_key (keys, key)) |
265 | color = g_settings_get_string (settings, key); |
266 | else |
267 | color = g_strdup ("#f25915e815e8")g_strdup_inline ("#f25915e815e8"); |
268 | detail_string = std::string("changed::") + std::string(key); |
269 | g_signal_connect (G_OBJECT(settings), detail_string.c_str(),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
270 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), (detail_string.c_str()), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
271 | gdk_rgba_parse (&pd->config.cpu_color[i], color); |
272 | g_free (color); |
273 | g_free (key); |
274 | } |
275 | g_strfreev (keys); |
276 | |
277 | color = g_settings_get_string (settings, "mem-color"); |
278 | if (!color) |
279 | color = g_strdup ("#000000ff0082")g_strdup_inline ("#000000ff0082"); |
280 | g_signal_connect (G_OBJECT(settings), "changed::mem-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::mem-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
281 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::mem-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
282 | gdk_rgba_parse(&pd->config.mem_color, color); |
283 | g_free (color); |
284 | |
285 | color = g_settings_get_string (settings, "swap-color"); |
286 | if (!color) |
287 | color = g_strdup ("#00b6000000ff")g_strdup_inline ("#00b6000000ff"); |
288 | g_signal_connect (G_OBJECT(settings), "changed::swap-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::swap-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
289 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::swap-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
290 | gdk_rgba_parse(&pd->config.swap_color, color); |
291 | g_free (color); |
292 | |
293 | color = g_settings_get_string (settings, "net-in-color"); |
294 | if (!color) |
295 | color = g_strdup ("#000000f200f2")g_strdup_inline ("#000000f200f2"); |
296 | g_signal_connect (G_OBJECT(settings), "changed::net-in-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-in-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
297 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-in-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
298 | gdk_rgba_parse(&pd->config.net_in_color, color); |
299 | g_free (color); |
300 | |
301 | color = g_settings_get_string (settings, "net-out-color"); |
302 | if (!color) |
303 | color = g_strdup ("#00f2000000c1")g_strdup_inline ("#00f2000000c1"); |
304 | g_signal_connect (G_OBJECT(settings), "changed::net-out-color",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-out-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0) |
305 | G_CALLBACK(color_changed_cb), pd)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((settings)), (((GType) ((20) << (2) )))))))), ("changed::net-out-color"), (((GCallback) (color_changed_cb ))), (pd), __null, (GConnectFlags) 0); |
306 | gdk_rgba_parse(&pd->config.net_out_color, color); |
307 | g_free (color); |
308 | |
309 | /* Sanity checks */ |
310 | GdkDisplay *display; |
311 | GdkMonitor *monitor; |
312 | GdkRectangle monitor_geometry; |
313 | |
314 | display = gdk_display_get_default (); |
315 | monitor = gdk_display_get_monitor_at_point (display, pd->config.xpos, pd->config.ypos); |
316 | if (monitor == NULL__null) { |
317 | monitor = gdk_display_get_monitor (display, 0); |
318 | } |
319 | gdk_monitor_get_geometry (monitor, &monitor_geometry); |
320 | |
321 | pd->config.width = CLAMP (pd->config.width, 50, monitor_geometry.width)(((pd->config.width) > (monitor_geometry.width)) ? (monitor_geometry .width) : (((pd->config.width) < (50)) ? (50) : (pd-> config.width))); |
322 | pd->config.height = CLAMP (pd->config.height, 50, monitor_geometry.height)(((pd->config.height) > (monitor_geometry.height)) ? (monitor_geometry .height) : (((pd->config.height) < (50)) ? (50) : (pd-> config.height))); |
323 | pd->config.update_interval = MAX (pd->config.update_interval, 1000)(((pd->config.update_interval) > (1000)) ? (pd->config .update_interval) : (1000)); |
324 | pd->config.graph_update_interval = MAX (pd->config.graph_update_interval, 250)(((pd->config.graph_update_interval) > (250)) ? (pd-> config.graph_update_interval) : (250)); |
325 | pd->config.disks_update_interval = MAX (pd->config.disks_update_interval, 1000)(((pd->config.disks_update_interval) > (1000)) ? (pd-> config.disks_update_interval) : (1000)); |
326 | pd->config.whose_process = CLAMP (pd->config.whose_process, 0, 2)(((pd->config.whose_process) > (2)) ? (2) : (((pd->config .whose_process) < (0)) ? (0) : (pd->config.whose_process ))); |
327 | pd->config.current_tab = CLAMP(pd->config.current_tab,(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))) |
328 | PROCMAN_TAB_SYSINFO,(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))) |
329 | PROCMAN_TAB_DISKS)(((pd->config.current_tab) > (PROCMAN_TAB_DISKS)) ? (PROCMAN_TAB_DISKS ) : (((pd->config.current_tab) < (PROCMAN_TAB_SYSINFO)) ? (PROCMAN_TAB_SYSINFO) : (pd->config.current_tab))); |
330 | |
331 | // delayed initialization as SmoothRefresh() needs ProcData |
332 | // i.e. we can't call ProcData::get_instance |
333 | pd->smooth_refresh = new SmoothRefresh(settings); |
334 | |
335 | pd->terminating = FALSE(0); |
336 | |
337 | return pd; |
338 | } |
339 | |
340 | static void |
341 | procman_free_data (ProcData *procdata) |
342 | { |
343 | |
344 | proctable_free_table (procdata); |
345 | delete procdata->smooth_refresh; |
346 | } |
347 | |
348 | ProcmanApp::ProcmanApp() : Gtk::Application("org.mate.SystemMonitor", Gio::APPLICATION_HANDLES_COMMAND_LINE) |
349 | { |
350 | Glib::set_application_name(_("System Monitor")gettext ("System Monitor")); |
351 | } |
352 | |
353 | Glib::RefPtr<ProcmanApp> ProcmanApp::create () |
354 | { |
355 | return Glib::RefPtr<ProcmanApp>(new ProcmanApp()); |
356 | } |
357 | |
358 | void ProcmanApp::on_activate() |
359 | { |
360 | gtk_window_present (GTK_WINDOW (procdata->app)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->app)), ((gtk_window_get_type ()))))))); |
361 | } |
362 | |
363 | static void |
364 | set_tab(GtkNotebook* notebook, gint tab, ProcData* procdata) |
365 | { |
366 | gtk_notebook_set_current_page(notebook, tab); |
367 | cb_change_current_page(notebook, tab, procdata); |
368 | } |
369 | |
370 | int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line) |
371 | { |
372 | int argc = 0; |
373 | char** argv = command_line->get_arguments(argc); |
374 | |
375 | Glib::OptionContext context; |
376 | context.set_summary(_("A simple process and system monitor.")gettext ("A simple process and system monitor.")); |
377 | context.set_ignore_unknown_options(true); |
378 | procman::OptionGroup option_group; |
379 | context.set_main_group(option_group); |
380 | |
381 | try { |
382 | context.parse(argc, argv); |
383 | } catch (const Glib::Error& ex) { |
384 | g_error("Arguments parse error : %s", ex.what().c_str()); |
385 | } |
386 | |
387 | if (option_group.show_system_tab) { |
388 | procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request")procman_debug_real("procman-app.cpp", 388, __func__, "Starting with PROCMAN_TAB_SYSINFO by commandline request" ); |
389 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_SYSINFO, procdata); |
390 | } else if (option_group.show_processes_tab) { |
391 | procman_debug("Starting with PROCMAN_TAB_PROCESSES by commandline request")procman_debug_real("procman-app.cpp", 391, __func__, "Starting with PROCMAN_TAB_PROCESSES by commandline request" ); |
392 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_PROCESSES, procdata); |
393 | } else if (option_group.show_resources_tab) { |
394 | procman_debug("Starting with PROCMAN_TAB_RESOURCES by commandline request")procman_debug_real("procman-app.cpp", 394, __func__, "Starting with PROCMAN_TAB_RESOURCES by commandline request" ); |
395 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_RESOURCES, procdata); |
396 | } else if (option_group.show_file_systems_tab) { |
397 | procman_debug("Starting with PROCMAN_TAB_DISKS by commandline request")procman_debug_real("procman-app.cpp", 397, __func__, "Starting with PROCMAN_TAB_DISKS by commandline request" ); |
398 | set_tab(GTK_NOTEBOOK(procdata->notebook)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->notebook)), ((gtk_notebook_get_type ()))))) ), PROCMAN_TAB_DISKS, procdata); |
399 | } |
400 | |
401 | on_activate (); |
402 | |
403 | return 0; |
404 | } |
405 | |
406 | void ProcmanApp::on_startup() |
407 | { |
408 | Gtk::Application::on_startup(); |
409 | |
410 | GSettings *settings; |
411 | |
412 | Gtk::Window::set_default_icon_name ("utilities-system-monitor"); |
413 | |
414 | settings = g_settings_new (GSM_GSETTINGS_SCHEMA"org.mate.system-monitor"); |
415 | |
416 | glibtop_init (); |
417 | |
418 | procdata = procman_data_new (settings); |
419 | procdata->settings = g_settings_new(GSM_GSETTINGS_SCHEMA"org.mate.system-monitor"); |
420 | |
421 | create_main_window (procdata); |
422 | init_volume_monitor (procdata); |
423 | |
424 | Gtk::Window *window = Glib::wrap(GTK_WINDOW(procdata->app)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((procdata->app)), ((gtk_window_get_type ()))))))); |
425 | window->show(); |
426 | window->set_name ("mate-system-monitor"); |
427 | |
428 | add_window (*window); |
429 | } |
430 | |
431 | void ProcmanApp::on_shutdown() |
432 | { |
433 | procman_free_data(procdata); |
434 | glibtop_close(); |
435 | } |
436 |
File: | rootdir/src/util.cpp |
Warning: | line 350, column 17 This statement is never executed |
Press '?' + to see keyboard shortcuts
+ + +Keyboard shortcuts:
+1 | #include <config.h> |
2 | |
3 | #include <glib/gprintf.h> |
4 | #include <glib/gi18n.h> |
5 | #include <glib.h> |
6 | #include <gtk/gtk.h> |
7 | |
8 | #include <glibtop/proctime.h> |
9 | #include <glibtop/procstate.h> |
10 | #include <unistd.h> |
11 | |
12 | #include <stddef.h> |
13 | #include <cstring> |
14 | |
15 | #include "util.h" |
16 | #include "procman.h" |
17 | |
18 | gchar * |
19 | procman_format_date_for_display(time_t time_raw) |
20 | { |
21 | gchar *result = NULL__null; |
22 | const char *format; |
23 | GDateTime *date_time, *today; |
24 | GTimeSpan date_age; |
25 | |
26 | date_time = g_date_time_new_from_unix_local (time_raw); |
27 | today = g_date_time_new_now_local (); |
28 | |
29 | date_age = g_date_time_difference (today, date_time); |
30 | if (date_age < G_TIME_SPAN_DAY((86400000000L))) { |
31 | format = _("Today %l:%M %p")gettext ("Today %l:%M %p"); |
32 | } else if (date_age < 2 * G_TIME_SPAN_DAY((86400000000L))) { |
33 | format = _("Yesterday %l:%M %p")gettext ("Yesterday %l:%M %p"); |
34 | } else if (date_age < 7 * G_TIME_SPAN_DAY((86400000000L))) { |
35 | format = _("%a %l:%M %p")gettext ("%a %l:%M %p"); |
36 | } else if (g_date_time_get_year (date_time) == g_date_time_get_year (today)) { |
37 | format = _("%b %d %l:%M %p")gettext ("%b %d %l:%M %p"); |
38 | } else { |
39 | format = _("%b %d %Y")gettext ("%b %d %Y"); |
40 | } |
41 | |
42 | g_date_time_unref (today); |
43 | result = g_date_time_format (date_time, format); |
44 | g_date_time_unref (date_time); |
45 | |
46 | return result; |
47 | } |
48 | |
49 | const char* |
50 | format_process_state(guint state) |
51 | { |
52 | const char *status; |
53 | |
54 | switch (state) |
55 | { |
56 | case GLIBTOP_PROCESS_RUNNING1: |
57 | status = _("Running")gettext ("Running"); |
58 | break; |
59 | |
60 | case GLIBTOP_PROCESS_STOPPED16: |
61 | status = _("Stopped")gettext ("Stopped"); |
62 | break; |
63 | |
64 | case GLIBTOP_PROCESS_ZOMBIE8: |
65 | status = _("Zombie")gettext ("Zombie"); |
66 | break; |
67 | |
68 | case GLIBTOP_PROCESS_UNINTERRUPTIBLE4: |
69 | status = _("Uninterruptible")gettext ("Uninterruptible"); |
70 | break; |
71 | |
72 | default: |
73 | status = _("Sleeping")gettext ("Sleeping"); |
74 | break; |
75 | } |
76 | |
77 | return status; |
78 | } |
79 | |
80 | |
81 | |
82 | static char * |
83 | mnemonic_safe_process_name(const char *process_name) |
84 | { |
85 | const char *p; |
86 | GString *name; |
87 | |
88 | name = g_string_new (""); |
89 | |
90 | for(p = process_name; *p; ++p) |
91 | { |
92 | g_string_append_c (name, *p)g_string_append_c_inline (name, *p); |
93 | |
94 | if(*p == '_') |
95 | g_string_append_c (name, '_')g_string_append_c_inline (name, '_'); |
96 | } |
97 | |
98 | return g_string_free (name, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((name ), ((0))) : g_string_free_and_steal (name)) : (g_string_free) ((name), ((0)))); |
99 | } |
100 | |
101 | |
102 | |
103 | static inline unsigned divide(unsigned *q, unsigned *r, unsigned d) |
104 | { |
105 | *q = *r / d; |
106 | *r = *r % d; |
107 | return *q != 0; |
108 | } |
109 | |
110 | |
111 | /* |
112 | * @param d: duration in centiseconds |
113 | * @type d: unsigned |
114 | */ |
115 | gchar * |
116 | procman::format_duration_for_display(unsigned centiseconds) |
117 | { |
118 | unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; |
119 | |
120 | (void)(divide(&seconds, ¢iseconds, 100) |
121 | && divide(&minutes, &seconds, 60) |
122 | && divide(&hours, &minutes, 60) |
123 | && divide(&days, &hours, 24) |
124 | && divide(&weeks, &days, 7)); |
125 | |
126 | if (weeks) |
127 | /* xgettext: weeks, days */ |
128 | return g_strdup_printf(_("%uw%ud")gettext ("%uw%ud"), weeks, days); |
129 | |
130 | if (days) |
131 | /* xgettext: days, hours (0 -> 23) */ |
132 | return g_strdup_printf(_("%ud%02uh")gettext ("%ud%02uh"), days, hours); |
133 | |
134 | if (hours) |
135 | /* xgettext: hours (0 -> 23), minutes, seconds */ |
136 | return g_strdup_printf(_("%u:%02u:%02u")gettext ("%u:%02u:%02u"), hours, minutes, seconds); |
137 | |
138 | /* xgettext: minutes, seconds, centiseconds */ |
139 | return g_strdup_printf(_("%u:%02u.%02u")gettext ("%u:%02u.%02u"), minutes, seconds, centiseconds); |
140 | } |
141 | |
142 | |
143 | |
144 | GtkWidget* |
145 | procman_make_label_for_mmaps_or_ofiles(const char *format, |
146 | const char *process_name, |
147 | unsigned pid) |
148 | { |
149 | GtkWidget *label; |
150 | char *name, *title; |
151 | |
152 | name = mnemonic_safe_process_name (process_name); |
153 | title = g_strdup_printf(format, name, pid); |
154 | label = gtk_label_new_with_mnemonic (title); |
155 | gtk_label_set_xalign (GTK_LABEL (label)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((gtk_label_get_type ())))))), 0.0); |
156 | |
157 | g_free (title); |
158 | g_free (name); |
159 | |
160 | return label; |
161 | } |
162 | |
163 | gchar * |
164 | procman::get_nice_level (gint nice) |
165 | { |
166 | if (nice < -7) |
167 | return _("Very High")gettext ("Very High"); |
168 | else if (nice < -2) |
169 | return _("High")gettext ("High"); |
170 | else if (nice < 3) |
171 | return _("Normal")gettext ("Normal"); |
172 | else if (nice < 7) |
173 | return _("Low")gettext ("Low"); |
174 | else |
175 | return _("Very Low")gettext ("Very Low"); |
176 | } |
177 | |
178 | |
179 | gboolean |
180 | load_symbols(const char *module, ...) |
181 | { |
182 | GModule *mod; |
183 | gboolean found_all = TRUE(!(0)); |
184 | va_list args; |
185 | |
186 | mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
187 | |
188 | if (!mod) |
189 | return FALSE(0); |
190 | |
191 | procman_debug("Found %s", module)procman_debug_real("util.cpp", 191, __func__, "Found %s", module ); |
192 | |
193 | va_start(args, module)__builtin_va_start(args, module); |
194 | |
195 | while (1) { |
196 | const char *name; |
197 | void **symbol; |
198 | |
199 | name = va_arg(args, char*)__builtin_va_arg(args, char*); |
200 | |
201 | if (!name) |
202 | break; |
203 | |
204 | symbol = va_arg(args, void**)__builtin_va_arg(args, void**); |
205 | |
206 | if (g_module_symbol(mod, name, symbol)) { |
207 | procman_debug("Loaded %s from %s", name, module)procman_debug_real("util.cpp", 207, __func__, "Loaded %s from %s" , name, module); |
208 | } |
209 | else { |
210 | procman_debug("Could not load %s from %s", name, module)procman_debug_real("util.cpp", 210, __func__, "Could not load %s from %s" , name, module); |
211 | found_all = FALSE(0); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | va_end(args)__builtin_va_end(args); |
217 | |
218 | |
219 | if (found_all) |
220 | g_module_make_resident(mod); |
221 | else |
222 | g_module_close(mod); |
223 | |
224 | return found_all; |
225 | } |
226 | |
227 | |
228 | static gboolean |
229 | is_debug_enabled(void) |
230 | { |
231 | static gboolean init; |
232 | static gboolean enabled; |
233 | |
234 | if (!init) { |
235 | enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL__null; |
236 | init = TRUE(!(0)); |
237 | } |
238 | |
239 | return enabled; |
240 | } |
241 | |
242 | |
243 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
244 | static gint64 |
245 | get_relative_time(void) |
246 | { |
247 | static unsigned long start_time; |
248 | gint64 tv; |
249 | |
250 | if (G_UNLIKELY(!start_time)(!start_time)) { |
251 | glibtop_proc_time buf; |
252 | glibtop_get_proc_time(&buf, getpid()); |
253 | start_time = buf.start_time; |
254 | } |
255 | |
256 | tv = g_get_real_time (); |
257 | return tv - (gint64) start_time; |
258 | } |
259 | #else |
260 | static double |
261 | get_relative_time(void) |
262 | { |
263 | static unsigned long start_time; |
264 | GTimeVal tv; |
265 | |
266 | if (G_UNLIKELY(!start_time)(!start_time)) { |
267 | glibtop_proc_time buf; |
268 | glibtop_get_proc_time(&buf, getpid()); |
269 | start_time = buf.start_time; |
270 | } |
271 | |
272 | g_get_current_time(&tv); |
273 | return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; |
274 | } |
275 | #endif |
276 | |
277 | static guint64 |
278 | get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, |
279 | const guint index) |
280 | { |
281 | GValue value = { 0 }; |
282 | gtk_tree_model_get_value(model, first, index, &value); |
283 | |
284 | guint64 size; |
285 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
286 | case G_TYPE_UINT((GType) ((7) << (2))): |
287 | size = g_value_get_uint(&value); |
288 | break; |
289 | case G_TYPE_ULONG((GType) ((9) << (2))): |
290 | size = g_value_get_ulong(&value); |
291 | break; |
292 | case G_TYPE_UINT64((GType) ((11) << (2))): |
293 | size = g_value_get_uint64(&value); |
294 | break; |
295 | default: |
296 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 296, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
297 | } |
298 | |
299 | g_value_unset(&value); |
300 | return size; |
301 | } |
302 | |
303 | void |
304 | procman_debug_real(const char *file, int line, const char *func, |
305 | const char *format, ...) |
306 | { |
307 | va_list args; |
308 | char *msg; |
309 | |
310 | if (G_LIKELY(!is_debug_enabled())(!is_debug_enabled())) |
311 | return; |
312 | |
313 | va_start(args, format)__builtin_va_start(args, format); |
314 | msg = g_strdup_vprintf(format, args); |
315 | va_end(args)__builtin_va_end(args); |
316 | |
317 | #if GLIB_CHECK_VERSION(2,61,2)(2 > (2) || (2 == (2) && 76 > (61)) || (2 == (2 ) && 76 == (61) && 2 >= (2))) |
318 | g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
319 | #else |
320 | g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); |
321 | #endif |
322 | g_free(msg); |
323 | } |
324 | |
325 | |
326 | |
327 | namespace procman |
328 | { |
329 | void memory_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
330 | GtkTreeModel *model, GtkTreeIter *iter, |
331 | gpointer user_data) |
332 | { |
333 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
334 | |
335 | guint64 size; |
336 | GValue value = { 0 }; |
337 | |
338 | gtk_tree_model_get_value(model, iter, index, &value); |
339 | |
340 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
341 | case G_TYPE_ULONG((GType) ((9) << (2))): |
342 | size = g_value_get_ulong(&value); |
343 | break; |
344 | |
345 | case G_TYPE_UINT64((GType) ((11) << (2))): |
346 | size = g_value_get_uint64(&value); |
347 | break; |
348 | |
349 | default: |
350 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 350, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
This statement is never executed | |
351 | } |
352 | |
353 | g_value_unset(&value); |
354 | |
355 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
356 | g_object_set(renderer, "text", str, NULL__null); |
357 | g_free(str); |
358 | } |
359 | |
360 | /* |
361 | Same as above but handles size == 0 as not available |
362 | */ |
363 | void memory_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
364 | GtkTreeModel *model, GtkTreeIter *iter, |
365 | gpointer user_data) |
366 | { |
367 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
368 | |
369 | guint64 size; |
370 | GValue value = { 0 }; |
371 | |
372 | gtk_tree_model_get_value(model, iter, index, &value); |
373 | |
374 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
375 | case G_TYPE_ULONG((GType) ((9) << (2))): |
376 | size = g_value_get_ulong(&value); |
377 | break; |
378 | |
379 | case G_TYPE_UINT64((GType) ((11) << (2))): |
380 | size = g_value_get_uint64(&value); |
381 | break; |
382 | |
383 | default: |
384 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 384, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
385 | } |
386 | |
387 | g_value_unset(&value); |
388 | |
389 | if (size == 0) { |
390 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
391 | g_object_set(renderer, "markup", str, NULL__null); |
392 | g_free(str); |
393 | } |
394 | else { |
395 | char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS); |
396 | g_object_set(renderer, "text", str, NULL__null); |
397 | g_free(str); |
398 | } |
399 | } |
400 | |
401 | void storage_size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
402 | GtkTreeModel *model, GtkTreeIter *iter, |
403 | gpointer user_data) |
404 | { |
405 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
406 | |
407 | guint64 size; |
408 | GValue value = { 0 }; |
409 | |
410 | gtk_tree_model_get_value(model, iter, index, &value); |
411 | |
412 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
413 | case G_TYPE_ULONG((GType) ((9) << (2))): |
414 | size = g_value_get_ulong(&value); |
415 | break; |
416 | |
417 | case G_TYPE_UINT64((GType) ((11) << (2))): |
418 | size = g_value_get_uint64(&value); |
419 | break; |
420 | |
421 | default: |
422 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 422, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
423 | } |
424 | |
425 | g_value_unset(&value); |
426 | |
427 | char *str = g_format_size(size); |
428 | g_object_set(renderer, "text", str, NULL__null); |
429 | g_free(str); |
430 | } |
431 | |
432 | /* |
433 | Same as above but handles size == 0 as not available |
434 | */ |
435 | void storage_size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, |
436 | GtkTreeModel *model, GtkTreeIter *iter, |
437 | gpointer user_data) |
438 | { |
439 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
440 | |
441 | guint64 size; |
442 | GValue value = { 0 }; |
443 | |
444 | gtk_tree_model_get_value(model, iter, index, &value); |
445 | |
446 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
447 | case G_TYPE_ULONG((GType) ((9) << (2))): |
448 | size = g_value_get_ulong(&value); |
449 | break; |
450 | |
451 | case G_TYPE_UINT64((GType) ((11) << (2))): |
452 | size = g_value_get_uint64(&value); |
453 | break; |
454 | |
455 | default: |
456 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 456, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
457 | } |
458 | |
459 | g_value_unset(&value); |
460 | |
461 | if (size == 0) { |
462 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
463 | g_object_set(renderer, "markup", str, NULL__null); |
464 | g_free(str); |
465 | } |
466 | else { |
467 | char *str = g_format_size(size); |
468 | g_object_set(renderer, "text", str, NULL__null); |
469 | g_free(str); |
470 | } |
471 | } |
472 | |
473 | void io_rate_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
474 | GtkTreeModel *model, GtkTreeIter *iter, |
475 | gpointer user_data) |
476 | { |
477 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
478 | |
479 | guint64 size; |
480 | GValue value = { 0 }; |
481 | |
482 | gtk_tree_model_get_value(model, iter, index, &value); |
483 | |
484 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
485 | case G_TYPE_ULONG((GType) ((9) << (2))): |
486 | size = g_value_get_ulong(&value); |
487 | break; |
488 | |
489 | case G_TYPE_UINT64((GType) ((11) << (2))): |
490 | size = g_value_get_uint64(&value); |
491 | break; |
492 | |
493 | default: |
494 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 494, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
495 | } |
496 | |
497 | g_value_unset(&value); |
498 | |
499 | if (size == 0) { |
500 | char *str = g_strdup_printf ("<i>%s</i>", _("N/A")gettext ("N/A")); |
501 | g_object_set(renderer, "markup", str, NULL__null); |
502 | g_free(str); |
503 | } |
504 | else { |
505 | char *str = g_format_size(size); |
506 | char *formatted_str = g_strdup_printf(_("%s/s")gettext ("%s/s"), str); |
507 | g_object_set(renderer, "text", formatted_str, NULL__null); |
508 | g_free(formatted_str); |
509 | g_free(str); |
510 | } |
511 | |
512 | } |
513 | |
514 | void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
515 | GtkTreeModel *model, GtkTreeIter *iter, |
516 | gpointer user_data) |
517 | { |
518 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
519 | |
520 | unsigned time; |
521 | GValue value = { 0 }; |
522 | |
523 | gtk_tree_model_get_value(model, iter, index, &value); |
524 | |
525 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
526 | case G_TYPE_ULONG((GType) ((9) << (2))): |
527 | time = g_value_get_ulong(&value); |
528 | break; |
529 | |
530 | case G_TYPE_UINT64((GType) ((11) << (2))): |
531 | time = g_value_get_uint64(&value); |
532 | break; |
533 | |
534 | default: |
535 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 535, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
536 | } |
537 | |
538 | g_value_unset(&value); |
539 | |
540 | time = 100 * time / ProcData::get_instance()->frequency; |
541 | char *str = format_duration_for_display(time); |
542 | g_object_set(renderer, "text", str, NULL__null); |
543 | g_free(str); |
544 | } |
545 | |
546 | |
547 | void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
548 | GtkTreeModel *model, GtkTreeIter *iter, |
549 | gpointer user_data) |
550 | { |
551 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
552 | |
553 | time_t time; |
554 | GValue value = { 0 }; |
555 | |
556 | gtk_tree_model_get_value(model, iter, index, &value); |
557 | |
558 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
559 | case G_TYPE_ULONG((GType) ((9) << (2))): |
560 | time = g_value_get_ulong(&value); |
561 | break; |
562 | |
563 | default: |
564 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 564, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
565 | } |
566 | |
567 | g_value_unset(&value); |
568 | |
569 | gchar *str = procman_format_date_for_display(time); |
570 | g_object_set(renderer, "text", str, NULL__null); |
571 | g_free(str); |
572 | } |
573 | |
574 | void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
575 | GtkTreeModel *model, GtkTreeIter *iter, |
576 | gpointer user_data) |
577 | { |
578 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
579 | |
580 | guint state; |
581 | GValue value = { 0 }; |
582 | |
583 | gtk_tree_model_get_value(model, iter, index, &value); |
584 | |
585 | switch (G_VALUE_TYPE(&value)(((GValue*) (&value))->g_type)) { |
586 | case G_TYPE_UINT((GType) ((7) << (2))): |
587 | state = g_value_get_uint(&value); |
588 | break; |
589 | |
590 | default: |
591 | g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "util.cpp", 591, ((const char*) (__PRETTY_FUNCTION__)), __null); } while (0); |
592 | } |
593 | |
594 | g_value_unset(&value); |
595 | |
596 | const char *str = format_process_state(state); |
597 | g_object_set(renderer, "text", str, NULL__null); |
598 | } |
599 | |
600 | void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer, |
601 | GtkTreeModel *model, GtkTreeIter *iter, |
602 | gpointer user_data) |
603 | { |
604 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
605 | |
606 | GValue value = { 0 }; |
607 | |
608 | gtk_tree_model_get_value(model, iter, index, &value); |
609 | |
610 | gint priority = g_value_get_int(&value); |
611 | |
612 | g_value_unset(&value); |
613 | |
614 | g_object_set(renderer, "text", procman::get_nice_level(priority), NULL__null); |
615 | |
616 | } |
617 | |
618 | gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
619 | GtkTreeIter* second, gpointer user_data) |
620 | { |
621 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
622 | GValue value1 = { 0 }; |
623 | GValue value2 = { 0 }; |
624 | gtk_tree_model_get_value(model, first, index, &value1); |
625 | gtk_tree_model_get_value(model, second, index, &value2); |
626 | gint result = g_value_get_int(&value1) - g_value_get_int(&value2); |
627 | g_value_unset(&value1); |
628 | g_value_unset(&value2); |
629 | return result; |
630 | } |
631 | |
632 | gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first, |
633 | GtkTreeIter* second, gpointer user_data) |
634 | { |
635 | const guint index = GPOINTER_TO_UINT(user_data)((guint) (gulong) (user_data)); |
636 | |
637 | guint64 size1, size2; |
638 | size1 = get_size_from_column(model, first, index); |
639 | size2 = get_size_from_column(model, second, index); |
640 | |
641 | if ( size2 > size1 ) |
642 | return 1; |
643 | else if ( size2 < size1 ) |
644 | return -1; |
645 | return 0; |
646 | } |
647 | |
648 | template<> |
649 | void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value) |
650 | { |
651 | char* current_value; |
652 | |
653 | gtk_tree_model_get(model, iter, column, ¤t_value, -1); |
654 | |
655 | if (g_strcmp0(current_value, new_value) != 0) |
656 | gtk_tree_store_set(GTK_TREE_STORE(model)((((GtkTreeStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((gtk_tree_store_get_type ())))))), iter, column, new_value, -1); |
657 | |
658 | g_free(current_value); |
659 | } |
660 | } |