Changeset 65
- Timestamp:
- 07/17/07 15:32:21 (1 year ago)
- Files:
-
- osso-statusbar-cpu/trunk/src/common.h (modified) (2 diffs)
- osso-statusbar-cpu/trunk/src/osso-applet-graph.c (modified) (9 diffs)
- osso-statusbar-cpu/trunk/src/osso-applet-graph.h (modified) (2 diffs)
- osso-statusbar-cpu/trunk/src/osso-statusbar-combo.c (modified) (14 diffs)
- osso-statusbar-cpu/trunk/src/osso-statusbar-combo.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
osso-statusbar-cpu/trunk/src/common.h
r61 r65 23 23 #define GCONF_PATH_COMMAND_NAMES GCONF_PATH "/command_names" 24 24 #define GCONF_PATH_COMMANDS GCONF_PATH "/commands" 25 #define GCONF_PATH_CPUMAX_ON GCONF_PATH "/cpumax_on" 26 #define GCONF_PATH_MAXED_CPU_SECS GCONF_PATH "/maxed_cpu_secs" 25 27 26 28 #define CPU_DEFAULT 0x1f6fff … … 28 30 #define CPU_ITEMS_DEFAULT 3 29 31 #define MEM_ITEMS_DEFAULT 3 32 #define GCONF_PATH_MAXED_CPU_SECS_DEFAULT 10 33 34 #define MAXED_CPU_NOTIFY_PCT 90 30 35 31 36 #define _(x) x osso-statusbar-cpu/trunk/src/osso-applet-graph.c
r61 r65 37 37 static void combo_toggled(GtkWidget *widget, GraphApplet *applet); 38 38 static void clock_toggled(GtkWidget *widget, GraphApplet *applet); 39 static void cpumax_toggled(GtkWidget *widget, GraphApplet *applet); 39 40 static void mem_color_clicked(GtkWidget *widget, GraphApplet *applet); 40 41 static void cpu_color_clicked(GtkWidget *widget, GraphApplet *applet); … … 76 77 77 78 if (response == GTK_RESPONSE_ACCEPT) { 79 gconf_client_set_bool(applet.gcc, GCONF_PATH_CPUMAX_ON, 80 applet.flags & CPUMAX_ON ? TRUE : FALSE, NULL); 78 81 gconf_client_set_bool(applet.gcc, GCONF_PATH_CLOCK_ON, 79 82 applet.flags & CLOCK ? TRUE : FALSE, NULL); … … 119 122 gboolean b_combine; 120 123 gboolean b_clock; 124 gboolean b_notify_cpumax; 121 125 122 126 GSList *l_cmds; … … 157 161 GCONF_PATH_CLOCK_ON, NULL); 158 162 163 b_notify_cpumax = gconf_client_get_bool(applet->gcc, 164 GCONF_PATH_CPUMAX_ON, NULL); 165 159 166 l_cmds = gconf_client_get_list(applet->gcc, 160 167 GCONF_PATH_COMMANDS, … … 171 178 b_show_cpu = FALSE; 172 179 b_show_mem = FALSE; 173 applet->flags = CPU_ON | MEM_ON | b_clock * CLOCK ;180 applet->flags = CPU_ON | MEM_ON | b_clock * CLOCK | b_notify_cpumax * CPUMAX_ON; 174 181 } else { 175 182 applet->flags = b_show_cpu * CPU_ON | 176 183 b_show_mem * MEM_ON | 177 b_clock * CLOCK; 184 b_clock * CLOCK | 185 b_notify_cpumax * CPUMAX_ON; 178 186 } 179 187 g_debug("cb: %d, cp: %d, me: %d", b_combine, b_show_cpu, b_show_mem); … … 281 289 HILDON_CAPTION_OPTIONAL); 282 290 291 applet->cpumax_check = gtk_check_button_new(); 292 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(applet->cpumax_check), 293 b_notify_cpumax); 294 applet->cpumax_caption = hildon_caption_new(size_group, 295 _("Notify if cpu is maxed"), applet->cpumax_check, NULL, 296 HILDON_CAPTION_OPTIONAL); 297 283 298 g_signal_connect_after(G_OBJECT(applet->combo_check), 284 299 "toggled", G_CALLBACK(combo_toggled), … … 289 304 applet); 290 305 306 g_signal_connect_after(G_OBJECT(applet->cpumax_check), 307 "toggled", G_CALLBACK(cpumax_toggled), 308 applet); 309 291 310 gtk_container_add(GTK_CONTAINER(dialog_vbox), 292 311 GTK_WIDGET(applet->combo_caption) … … 294 313 gtk_container_add(GTK_CONTAINER(dialog_vbox), 295 314 GTK_WIDGET(gtk_hseparator_new())); 315 gtk_container_add(GTK_CONTAINER(dialog_vbox), 316 GTK_WIDGET(applet->cpumax_caption) 317 ); 296 318 gtk_container_add(GTK_CONTAINER(dialog_vbox), 297 319 GTK_WIDGET(applet->clock_caption) … … 400 422 applet->flags &= ~CLOCK; 401 423 applet->flags |= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) * CLOCK; 424 gconf_client_clear_cache(applet->gcc); 425 while (gtk_events_pending()) 426 gtk_main_iteration(); 427 } 428 429 static void cpumax_toggled(GtkWidget *widget, GraphApplet *applet) 430 { 431 applet->flags &= ~CPUMAX_ON; 432 applet->flags |= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) * CPUMAX_ON; 402 433 gconf_client_clear_cache(applet->gcc); 403 434 while (gtk_events_pending()) osso-statusbar-cpu/trunk/src/osso-applet-graph.h
r3 r65 12 12 COMBO = 1 << 2, 13 13 CLOCK = 1 << 3, 14 CPUMAX_ON = 1 << 4, 14 15 } flag; 15 16 … … 20 21 GtkWidget *clock_check; 21 22 GtkWidget *clock_caption; 23 GtkWidget *cpumax_check; 24 GtkWidget *cpumax_caption; 22 25 23 26 GtkDialog *commands_dialog; osso-statusbar-cpu/trunk/src/osso-statusbar-combo.c
r61 r65 24 24 #endif 25 25 26 #include <hildon-widgets/hildon-banner.h> 27 26 28 #include <stdio.h> 27 29 #include <string.h> … … 53 55 GConfEntry *entry, gpointer user_data); 54 56 static void memon_gconf_handler(GConfClient *gcc, 57 guint con, 58 GConfEntry *entry, gpointer user_data); 59 static void cpumaxon_gconf_handler(GConfClient *gcc, 55 60 guint con, 56 61 GConfEntry *entry, gpointer user_data); … … 162 167 info->show_mem = gconf_client_get_bool(info->gcc, 163 168 GCONF_PATH_MEM_ON, NULL); 169 info->notify_cpumax = gconf_client_get_bool(info->gcc, 170 GCONF_PATH_CPUMAX_ON, NULL); 164 171 165 172 info->color_cpu = gc_get_int_fall(info->gcc, … … 169 176 info->clock = gconf_client_get_bool(info->gcc, 170 177 GCONF_PATH_CLOCK_ON, NULL); 178 info->maxed_cpu_secs = gc_get_int_fall(info->gcc, 179 GCONF_PATH_MAXED_CPU_SECS, GCONF_PATH_MAXED_CPU_SECS_DEFAULT); 180 181 if (info->maxed_cpu_secs < 5) { 182 info->maxed_cpu_secs = GCONF_PATH_MAXED_CPU_SECS_DEFAULT; 183 } 171 184 172 185 /* icon_pixbuf is owned by info->icon */ … … 183 196 #endif 184 197 198 info->maxed_cpu_last_notification = 0; 185 199 info->notify_id = 0; 186 if (info->show_cpu || info->show_mem ) {200 if (info->show_cpu || info->show_mem || info->notify_cpumax) { 187 201 info->notify_id = g_timeout_add(2000, my_timeout, info); 188 202 } … … 199 213 GCONF_PATH_MEM_ON, 200 214 memon_gconf_handler, 215 info, NULL, NULL); 216 info->gc_notify_id_cpumax = gconf_client_notify_add(info->gcc, 217 GCONF_PATH_CPUMAX_ON, 218 cpumaxon_gconf_handler, 201 219 info, NULL, NULL); 202 220 … … 213 231 my_gconf_clk_handler, 214 232 info, NULL, NULL); 233 info->gc_notify_id_maxed_cpu_secs = gconf_client_notify_add(info->gcc, 234 GCONF_PATH_MAXED_CPU_SECS, 235 my_gconf_handler, 236 info, NULL, NULL); 215 237 216 238 g_signal_connect(info->button, "toggled", G_CALLBACK(combo_popup), … … 256 278 gconf_client_notify_remove(info->gcc, info->gc_notify_id_mem); 257 279 gconf_client_notify_remove(info->gcc, info->gc_notify_id_clk); 280 gconf_client_notify_remove(info->gcc, info->gc_notify_id_cpumax); 281 gconf_client_notify_remove(info->gcc, info->gc_notify_id_maxed_cpu_secs); 258 282 gconf_client_remove_dir(info->gcc, GCONF_PATH, NULL); 259 283 … … 296 320 int x = info->show_cpu ? AREA_X + AREA_W / 2 : AREA_X; 297 321 298 if (info->show_cpu ) {322 if (info->show_cpu || info->notify_cpumax) { 299 323 FILE *foo = fopen("/proc/stat", "r"); 300 324 fscanf(foo, "cpu %d %d %d %d", &user, &nice, &kern, &idle); … … 302 326 total_change = user + nice + kern + idle - 303 327 (old_user + old_nice + old_kern + old_idle); 328 329 if (info->notify_cpumax) { 330 331 int user_pct = (user - old_user)*100 / total_change; 332 333 info->cpu_samples[info->cpu_cur_sample] = user_pct; 334 info->cpu_cur_sample++; 335 if (info->cpu_cur_sample >= CPU_NUM_SAMPLES) info->cpu_cur_sample = 0; 336 337 gint samples_to_go_back = (int)(info->maxed_cpu_secs / 2); /* timeout is 2000ms */ 338 if (samples_to_go_back >= CPU_NUM_SAMPLES) samples_to_go_back = CPU_NUM_SAMPLES; 339 340 gint cpu_avg = 0, i; 341 342 if (info->cpu_cur_sample==0) { /* condition one -- we have enough samples in the array, start from the end */ 343 for (i = CPU_NUM_SAMPLES - 1; i >= CPU_NUM_SAMPLES - samples_to_go_back; i-- ) cpu_avg += info->cpu_samples[i]; 344 } else if (info->cpu_cur_sample >= samples_to_go_back) { /* condition two -- we have enough samples in the first half of the array */ 345 for (i = info->cpu_cur_sample - 1; i >= info->cpu_cur_sample - samples_to_go_back; i-- ) cpu_avg += info->cpu_samples[i]; 346 } else { /* condition three - get some of the samples from the first half and some from the second half */ 347 for (i = info->cpu_cur_sample - 1; i >= 0; i-- ) cpu_avg += info->cpu_samples[i]; 348 int samples_left = samples_to_go_back - info->cpu_cur_sample; 349 for (i = CPU_NUM_SAMPLES - 1; i >= CPU_NUM_SAMPLES - samples_left; i-- ) cpu_avg += info->cpu_samples[i]; 350 } 351 352 gint avg = (int)(cpu_avg / samples_to_go_back); 353 354 if (avg >= MAXED_CPU_NOTIFY_PCT) { 355 guint ti = time(NULL); 356 if (info->maxed_cpu_last_notification == 0 || info->maxed_cpu_last_notification+CPUMAX_NOTIFY_FLOODPROTECTSECS < ti) { 357 info->maxed_cpu_last_notification = ti; 358 hildon_banner_show_information(info->icon, NULL, "Warning: Using excessive CPU"); 359 system("/usr/bin/play-sound /usr/share/sounds/ui-wrong_charger.wav"); 360 } 361 } 362 363 } 364 304 365 } 305 366 if (info->show_mem) { … … 334 395 gtk_image_set_from_pixbuf(image, buf); 335 396 336 if (info->show_cpu ) {397 if (info->show_cpu || info->notify_cpumax) { 337 398 old_user = user; 338 399 old_nice = nice; … … 360 421 g_timeout_add(2000, my_timeout, user_data); 361 422 } 362 } else if (!info->show_mem && info->notify_id) {423 } else if (!info->show_mem && !info->notify_cpumax && info->notify_id) { 363 424 g_source_remove(info->notify_id); 364 425 info->notify_id = 0; … … 383 444 g_timeout_add(2000, my_timeout, user_data); 384 445 } 385 } else if (!info->show_cpu && info->notify_id) { 446 } else if (!info->show_cpu && !info->notify_cpumax && info->notify_id) { 447 g_source_remove(info->notify_id); 448 info->notify_id = 0; 449 } 450 } 451 452 static void cpumaxon_gconf_handler(GConfClient *gcc, 453 guint con, 454 GConfEntry *entry, gpointer user_data) 455 { 456 OssoStatusbarCpuPrivate *info = user_data; 457 458 (void)gcc; 459 (void)con; 460 461 info->notify_cpumax = gconf_value_get_bool(entry->value); 462 463 if (info->notify_cpumax) { 464 if (!info->notify_id) { 465 info->notify_id = 466 g_timeout_add(2000, my_timeout, user_data); 467 } 468 } else if (!info->show_mem && !info->notify_cpumax && info->notify_id) { 386 469 g_source_remove(info->notify_id); 387 470 info->notify_id = 0; … … 402 485 } else if (strcmp(entry->key, GCONF_PATH_MEM_COLOR) == 0) { 403 486 info->color_mem = 487 gconf_value_get_int(gconf_entry_get_value(entry)); 488 } else if (strcmp(entry->key, GCONF_PATH_MAXED_CPU_SECS) == 0) { 489 info->maxed_cpu_secs = 404 490 gconf_value_get_int(gconf_entry_get_value(entry)); 405 491 } osso-statusbar-cpu/trunk/src/osso-statusbar-combo.h
r61 r65 44 44 #endif 45 45 46 #define CPU_NUM_SAMPLES 32 47 #define CPUMAX_NOTIFY_FLOODPROTECTSECS 10 48 46 49 typedef struct _OssoStatusbarCpuPrivate OssoStatusbarCpuPrivate; 47 50 … … 57 60 guint gc_notify_id_mem; 58 61 guint gc_notify_id_clk; 62 guint gc_notify_id_cpumax; 63 guint gc_notify_id_maxed_cpu_secs; 59 64 gint color_cpu; 60 65 gint color_mem; … … 63 68 gboolean show_cpu; 64 69 gboolean show_mem; 70 gboolean notify_cpumax; 71 gint maxed_cpu_secs; /* config value */ 72 73 gint cpu_samples[CPU_NUM_SAMPLES]; 74 gint cpu_cur_sample; 75 guint maxed_cpu_last_notification; 65 76 }; 66 77
