#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <libergtk/ergtk.h>
#include "i18n.h"
#include "log.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "power.h"
Go to the source code of this file.
Data Structures | |
struct | PowerSettings |
Defines | |
#define | NUM_STANDBY_MODES 3 |
#define | NUM_STANDBY_TIMES 4 |
#define | STANDBY_NEVER (-1) |
Functions | |
static GtkWidget * | create_auto_shutdown_widgets (GtkBox *parent) |
static void | on_plugged_changed (GtkWidget *widget, gpointer data) |
static void | on_standby_changed (GtkWidget *widget, gpointer data) |
static void | greyout_radio_buttons (GtkWidget **widget_list, gboolean to_grey, int length) |
static gint | read_radio_buttons (GtkWidget **widget_list, int length) |
static void | init_widgets_with_settings (void) |
static void | on_listview_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) |
static void | on_listview_navigate_cursor (erGtkListView *er_listview, erGtkListViewKeyPress keycode, gpointer user_data) |
static gboolean | on_focus_in (GtkWidget *widget, gpointer data) |
static gboolean | on_focus_out (GtkWidget *widget, gpointer data) |
void | load_power_settings () |
void | save_power_settings () |
GtkWidget * | create_power_window (GtkWidget *parent) |
Variables | |
static PowerSettings | g_orig_power_settings |
static PowerSettings | g_cur_power_settings |
static GtkWidget * | g_power_settings_window = NULL |
static GtkWidget * | g_plugged_radios [NUM_STANDBY_MODES] = {NULL, NULL, NULL} |
static GtkWidget * | g_standby_radios [NUM_STANDBY_TIMES] = {NULL, NULL, NULL, NULL} |
static int | standby_times [NUM_STANDBY_TIMES] = {15, 30, 45, 60} |
#define NUM_STANDBY_MODES 3 |
Definition at line 60 of file power.c.
Referenced by create_auto_shutdown_widgets().
#define NUM_STANDBY_TIMES 4 |
Definition at line 61 of file power.c.
Referenced by create_auto_shutdown_widgets(), init_widgets_with_settings(), and on_plugged_changed().
#define STANDBY_NEVER (-1) |
Definition at line 62 of file power.c.
Referenced by init_widgets_with_settings(), and on_plugged_changed().
static GtkWidget * create_auto_shutdown_widgets | ( | GtkBox * | parent | ) | [static] |
Definition at line 249 of file power.c.
References description_create(), g_plugged_radios, g_standby_radios, ITEM_SPACING, name, NUM_STANDBY_MODES, NUM_STANDBY_TIMES, on_plugged_changed(), on_standby_changed(), standby_times, and subject_create().
Referenced by create_power_window().
00250 { 00251 // Top level vbox. 00252 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING); 00253 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0); 00254 00255 // Subject "Automatic Shutdown". 00256 GtkWidget* subject = subject_create(); 00257 gtk_label_set_label(GTK_LABEL(subject), _("Automatic Shutdown") ); 00258 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0); 00259 00260 // Description "To save power..." 00261 GtkWidget* desc = description_create(); 00262 gtk_label_set_label(GTK_LABEL(desc), _("To save power, automatic shutdown can be enabled.") ); 00263 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0); 00264 00265 // The vbox containing radio buttons for plugged. 00266 GtkWidget* vbox = gtk_vbox_new(TRUE, 0); 00267 gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0); 00268 00269 int i = 0; 00270 for (i=0; i<NUM_STANDBY_MODES; i++) 00271 { 00272 switch (i) 00273 { 00274 case 0: 00275 { 00276 // the radio button "Never" 00277 g_plugged_radios[i] = gtk_radio_button_new_with_label(NULL, _("Never use automatic shutdown")); 00278 break; 00279 } 00280 case 1: 00281 { 00282 // The radio button "Always". 00283 g_plugged_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_plugged_radios[0]), _("Always use automatic shutdown")); 00284 break; 00285 } 00286 case 2: 00287 { 00288 // The radio button "Only when running on battery". 00289 g_plugged_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_plugged_radios[1]), _("Only use automatic shutdown when running on battery")); 00290 break; 00291 } 00292 default: 00293 { 00294 // never happens 00295 break; 00296 } 00297 } 00298 00299 // Add signal handler. 00300 g_signal_connect_after(G_OBJECT(g_plugged_radios[i]), 00301 "toggled", 00302 G_CALLBACK(on_plugged_changed), 00303 (gpointer)i); 00304 00305 gtk_box_pack_start(GTK_BOX(vbox), g_plugged_radios[i], FALSE, FALSE, 0); 00306 00307 } 00308 00309 // Subject "Choose the automatic shutdown time". 00310 GtkWidget* choose = description_create(NULL); 00311 gtk_label_set_label(GTK_LABEL(choose), _("Choose the automatic shutdown time:")); 00312 gtk_box_pack_start(GTK_BOX(top_level_vbox), choose, FALSE, FALSE, 0); 00313 00314 // The vbox containing radio buttons for minutes. 00315 vbox = gtk_vbox_new(TRUE, 0); 00316 gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0); 00317 00318 for (i = 0; i < NUM_STANDBY_TIMES; i++) 00319 { 00320 // The radio button "after ...". 00321 // TRANSLATORS: this is an ngettext(3) call which needs a singular and plural translation 00322 gchar* name = g_strdup_printf(ngettext("after %d minute", "after %d minutes", standby_times[i]), standby_times[i]); 00323 if (i == 0) 00324 { 00325 g_standby_radios[i] = gtk_radio_button_new_with_label(NULL, name); 00326 } 00327 else 00328 { 00329 g_standby_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_standby_radios[0]), name); 00330 } 00331 g_free(name); 00332 00333 // Add signal handler. 00334 g_signal_connect_after(G_OBJECT(g_standby_radios[i]), 00335 "toggled", 00336 G_CALLBACK(on_standby_changed), 00337 (gpointer)i); 00338 00339 gtk_box_pack_start(GTK_BOX(vbox), g_standby_radios[i], FALSE, FALSE, 0); 00340 } 00341 00342 return top_level_vbox; 00343 }
GtkWidget* create_power_window | ( | GtkWidget * | parent | ) |
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 138 of file power.c.
References create_auto_shutdown_widgets(), create_frame(), create_settingsview(), create_title(), g_power_settings_window, init_widgets_with_settings(), on_focus_in(), on_focus_out(), on_listview_navigate_cursor(), on_listview_row_activated(), and WINDOW_BORDER_PADDING.
Referenced by create_concrete_win().
00139 { 00140 // create top window 00141 GtkWidget* top_window = parent; 00142 gtk_window_maximize(GTK_WINDOW(top_window)); 00143 gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE); 00144 gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING ); 00145 gtk_window_set_modal(GTK_WINDOW(top_window), TRUE); 00146 00147 // top level vbox (vboxtop) 00148 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0); 00149 gtk_container_add(GTK_CONTAINER(top_window), vboxtop); 00150 00151 // add header container the title and subtitle of this settings page 00152 create_title(GTK_VBOX(vboxtop), _("Settings"), _("Power Management")); 00153 00154 // add the back/exit bar below the title 00155 GtkWidget* view = create_settingsview(); 00156 gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE, 0); 00157 g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ; 00158 g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ; 00159 g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL ); 00160 g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL ); 00161 00162 GtkWidget* vbox = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) ); 00163 create_auto_shutdown_widgets(GTK_BOX(vbox)); 00164 00165 00166 // Update widget with current settings. 00167 init_widgets_with_settings(); 00168 00169 g_power_settings_window = top_window; 00170 00171 gtk_widget_grab_focus(view); 00172 00173 gtk_widget_show_all(top_window); 00174 return top_window; 00175 }
static void greyout_radio_buttons | ( | GtkWidget ** | widget_list, | |
gboolean | to_grey, | |||
int | length | |||
) | [static] |
Definition at line 402 of file power.c.
Referenced by init_widgets_with_settings(), and on_plugged_changed().
00403 { 00404 int i = 0; 00405 for ( i = 0; i < length; i++ ) 00406 { 00407 gtk_widget_set_sensitive(widget_list[i], !to_grey); // to_grey means set to insensitive 00408 } 00409 }
static void init_widgets_with_settings | ( | void | ) | [static] |
Definition at line 422 of file power.c.
References g_plugged_radios, g_standby_radios, greyout_radio_buttons(), PowerSettings::minutes_standby, NUM_STANDBY_TIMES, PowerSettings::standby_if_plugged, STANDBY_NEVER, and standby_times.
Referenced by create_power_window().
00423 { 00424 int i; 00425 int to_be_activated = 0; 00426 00427 //Note: first minutes radiobutton, then plugged radiobutton, because of depencency and callbacks 00428 00429 //minutes 00430 for (i = 0; i < NUM_STANDBY_TIMES; i++) 00431 { 00432 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_standby_radios[i]), 00433 (standby_times[i]==g_cur_power_settings.minutes_standby)); 00434 } 00435 00436 // plugged 00437 if ( STANDBY_NEVER == g_cur_power_settings.minutes_standby ) 00438 { 00439 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_plugged_radios[0]), TRUE); 00440 greyout_radio_buttons(g_standby_radios, TRUE, NUM_STANDBY_TIMES); 00441 } 00442 else 00443 { 00444 to_be_activated = g_cur_power_settings.standby_if_plugged == TRUE ? 1 : 2; 00445 00446 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_plugged_radios[to_be_activated]), 00447 TRUE); 00448 } 00449 }
void load_power_settings | ( | ) |
Definition at line 112 of file power.c.
References GCONF_MIN_STANDBY, GCONF_STANDBY_IF_PLUGGED, get_value_bool(), get_value_int(), LOGPRINTF, PowerSettings::minutes_standby, and PowerSettings::standby_if_plugged.
Referenced by create_concrete_win().
00113 { 00114 g_orig_power_settings.standby_if_plugged = get_value_bool(GCONF_STANDBY_IF_PLUGGED); 00115 g_orig_power_settings.minutes_standby = get_value_int (GCONF_MIN_STANDBY); 00116 00117 g_cur_power_settings = g_orig_power_settings; 00118 LOGPRINTF("Loading power settings, done."); 00119 }
static gboolean on_focus_in | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 182 of file power.c.
References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().
Referenced by create_power_window().
00183 { 00184 g_assert(widget != NULL ) ; 00185 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0; 00186 return FALSE; 00187 }
static gboolean on_focus_out | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 190 of file power.c.
Referenced by create_power_window().
00191 { 00192 g_assert(widget != NULL ) ; 00193 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget); 00194 g_assert( my_selection != NULL ) ; 00195 gtk_tree_selection_unselect_all(my_selection); 00196 return FALSE; 00197 }
static void on_listview_navigate_cursor | ( | erGtkListView * | er_listview, | |
erGtkListViewKeyPress | keycode, | |||
gpointer | user_data | |||
) | [static] |
Definition at line 212 of file power.c.
References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, g_plugged_radios, and LOGPRINTF.
Referenced by create_power_window().
00215 { 00216 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview); 00217 g_assert( my_selection != NULL ) ; 00218 00219 // determine new cursor position 00220 switch (keycode) 00221 { 00222 case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN: 00223 case ERGTK_LIST_VIEW_PRESS_LONG_DOWN: 00224 gtk_widget_grab_focus(GTK_WIDGET(g_plugged_radios[0])); // down: to first widget 00225 gtk_tree_selection_unselect_all(my_selection); 00226 break; 00227 default: 00228 LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode); 00229 ; // ignore 00230 break; 00231 } 00232 }
static void on_listview_row_activated | ( | GtkTreeView * | view, | |
GtkTreePath * | path, | |||
GtkTreeViewColumn * | column, | |||
gpointer | user_data | |||
) | [static] |
Definition at line 200 of file power.c.
References main_quit(), and save_power_settings().
Referenced by create_power_window().
00204 { 00205 save_power_settings(); 00206 main_quit(); 00207 00208 return; 00209 }
static void on_plugged_changed | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 346 of file power.c.
References g_standby_radios, greyout_radio_buttons(), is_active, PowerSettings::minutes_standby, NUM_STANDBY_TIMES, read_radio_buttons(), PowerSettings::standby_if_plugged, STANDBY_NEVER, and standby_times.
Referenced by create_auto_shutdown_widgets().
00347 { 00348 int index = (int)data; 00349 gboolean is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); 00350 00351 if (is_active == TRUE ) 00352 { 00353 switch (index) 00354 { 00355 case 0: 00356 { 00357 g_cur_power_settings.minutes_standby = STANDBY_NEVER ; // -1 indicates never 00358 break; 00359 } 00360 case 1: 00361 { 00362 g_cur_power_settings.standby_if_plugged = TRUE; 00363 break; 00364 } 00365 case 2: 00366 { 00367 g_cur_power_settings.standby_if_plugged = FALSE; 00368 } 00369 default: 00370 break; 00371 } 00372 00373 // minutes 00374 if (index == 0) 00375 { 00376 // greyout minutes 00377 greyout_radio_buttons(g_standby_radios, TRUE, NUM_STANDBY_TIMES); 00378 } 00379 else 00380 { 00381 // restore minutes (or read minutes buttons) 00382 g_cur_power_settings.minutes_standby = 00383 standby_times[read_radio_buttons(g_standby_radios, NUM_STANDBY_TIMES)]; 00384 00385 // ungreyout minutes 00386 if ( ! GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(g_standby_radios[0]))) 00387 { 00388 greyout_radio_buttons(g_standby_radios, FALSE, NUM_STANDBY_TIMES); 00389 } 00390 } 00391 } 00392 }
static void on_standby_changed | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 395 of file power.c.
References PowerSettings::minutes_standby, and standby_times.
Referenced by create_auto_shutdown_widgets().
00396 { 00397 int index = (int)data; 00398 g_cur_power_settings.minutes_standby = standby_times[index]; 00399 }
static gint read_radio_buttons | ( | GtkWidget ** | widget_list, | |
int | length | |||
) | [static] |
Definition at line 411 of file power.c.
Referenced by on_plugged_changed().
00412 { 00413 int i = 0; 00414 for ( i = 0; i < length; i++ ) 00415 { 00416 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget_list[i])) ) 00417 break; 00418 } 00419 return i; 00420 }
void save_power_settings | ( | ) |
Definition at line 122 of file power.c.
References GCONF_MIN_STANDBY, GCONF_STANDBY_IF_PLUGGED, LOGPRINTF, PowerSettings::minutes_standby, set_value_bool(), set_value_int(), and PowerSettings::standby_if_plugged.
Referenced by on_listview_row_activated().
00123 { 00124 if (g_cur_power_settings.standby_if_plugged != g_orig_power_settings.standby_if_plugged) 00125 { 00126 set_value_bool(GCONF_STANDBY_IF_PLUGGED, g_cur_power_settings.standby_if_plugged); 00127 } 00128 00129 if (g_cur_power_settings.minutes_standby != g_orig_power_settings.minutes_standby) 00130 { 00131 set_value_int(GCONF_MIN_STANDBY, g_cur_power_settings.minutes_standby); 00132 } 00133 00134 LOGPRINTF("Saving power settings, done."); 00135 }
PowerSettings g_cur_power_settings [static] |
PowerSettings g_orig_power_settings [static] |
GtkWidget* g_plugged_radios[NUM_STANDBY_MODES] = {NULL, NULL, NULL} [static] |
Definition at line 73 of file power.c.
Referenced by create_auto_shutdown_widgets(), init_widgets_with_settings(), and on_listview_navigate_cursor().
GtkWidget* g_power_settings_window = NULL [static] |
Definition at line 72 of file power.c.
Referenced by create_power_window().
GtkWidget* g_standby_radios[NUM_STANDBY_TIMES] = {NULL, NULL, NULL, NULL} [static] |
Definition at line 74 of file power.c.
Referenced by create_auto_shutdown_widgets(), init_widgets_with_settings(), and on_plugged_changed().
int standby_times[NUM_STANDBY_TIMES] = {15, 30, 45, 60} [static] |
Definition at line 76 of file power.c.
Referenced by create_auto_shutdown_widgets(), init_widgets_with_settings(), on_plugged_changed(), and on_standby_changed().