00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <gtk/gtk.h>
00032 #include <gdk/gdk.h>
00033
00034
00035 #include <libergtk/ergtk.h>
00036
00037
00038 #include "i18n.h"
00039 #include "log.h"
00040 #include "settings.h"
00041 #include "settings_utils.h"
00042 #include "settings_style.h"
00043
00044 #include "sensors.h"
00045
00046
00047
00048
00049
00050
00051 typedef struct
00052 {
00053 gboolean lights_on;
00054 gboolean sound_on;
00055 gboolean lock_left_sensor;
00056 gboolean lock_middle_sensor;
00057 gboolean lock_right_sensor;
00058 } SensorSettings;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static SensorSettings g_orig_sensor_settings;
00072 static SensorSettings g_cur_sensor_settings;
00073
00074 static GtkWidget* g_sensor_settings_window = NULL;
00075 static GtkWidget* g_light_radios[2] = {NULL, NULL};
00076 static GtkWidget* g_sound_radios[2] = {NULL, NULL};
00077 static GtkWidget* g_lock_left_sensor_check = NULL;
00078 static GtkWidget* g_lock_middle_sensor_check = NULL;
00079 static GtkWidget* g_lock_right_sensor_check = NULL;
00080 static GtkWidget* g_sensor_lock_image = NULL;
00081
00082
00083
00084
00085
00086
00087 static GtkWidget* create_light_widgets (GtkBox* parent);
00088 static GtkWidget* create_sound_widgets (GtkBox* parent);
00089 static GtkWidget* create_lock_widgets (GtkBox* parent);
00090
00091 static void on_use_light_changed (GtkWidget *widget, gpointer data);
00092 static void on_use_sound_changed (GtkWidget *widget, gpointer data);
00093 static void on_lock_left_changed (GtkWidget *widget, gpointer data);
00094 static void on_lock_middle_changed (GtkWidget *widget, gpointer data);
00095 static void on_lock_right_changed (GtkWidget *widget, gpointer data);
00096 static void update_sensor_lock_image (gboolean lock_left,
00097 gboolean lock_middle,
00098 gboolean lock_right);
00099
00100 static void init_widgets_with_settings (void);
00101 static void on_listview_row_activated (GtkTreeView *view,
00102 GtkTreePath *path,
00103 GtkTreeViewColumn *column,
00104 gpointer user_data );
00105
00106 static void on_listview_navigate_cursor (erGtkListView *er_listview,
00107 erGtkListViewKeyPress keycode,
00108 gpointer user_data );
00109
00110 static gboolean on_focus_in(GtkWidget* widget, gpointer data );
00111 static gboolean on_focus_out(GtkWidget* widget, gpointer data );
00112
00113
00114
00115
00116
00117
00118
00119 void load_sensor_settings()
00120 {
00121 g_orig_sensor_settings.lights_on = get_value_bool(GCONF_USE_LIGHT);
00122 g_orig_sensor_settings.sound_on = get_value_bool(GCONF_USE_SOUND);
00123 g_orig_sensor_settings.lock_left_sensor = get_value_bool(GCONF_LOCK_LEFT_SENSOR);
00124 g_orig_sensor_settings.lock_middle_sensor = get_value_bool(GCONF_LOCK_MIDDLE_SENSOR);
00125 g_orig_sensor_settings.lock_right_sensor = get_value_bool(GCONF_LOCK_RIGHT_SENSOR);
00126
00127 g_cur_sensor_settings = g_orig_sensor_settings;
00128
00129 LOGPRINTF("Loading sensor settings, done.");
00130 }
00131
00132
00133 void save_sensor_settings()
00134 {
00135 if (g_cur_sensor_settings.lights_on != g_orig_sensor_settings.lights_on)
00136 {
00137 set_value_bool(GCONF_USE_LIGHT, g_cur_sensor_settings.lights_on);
00138 }
00139
00140 if (g_cur_sensor_settings.sound_on != g_orig_sensor_settings.sound_on)
00141 {
00142 set_value_bool(GCONF_USE_SOUND, g_cur_sensor_settings.sound_on);
00143 }
00144
00145 if (g_cur_sensor_settings.lock_left_sensor != g_orig_sensor_settings.lock_left_sensor)
00146 {
00147 set_value_bool(GCONF_LOCK_LEFT_SENSOR, g_cur_sensor_settings.lock_left_sensor);
00148 }
00149
00150 if (g_cur_sensor_settings.lock_middle_sensor != g_orig_sensor_settings.lock_middle_sensor)
00151 {
00152 set_value_bool(GCONF_LOCK_MIDDLE_SENSOR, g_cur_sensor_settings.lock_middle_sensor);
00153 }
00154
00155 if (g_cur_sensor_settings.lock_right_sensor != g_orig_sensor_settings.lock_right_sensor)
00156 {
00157 set_value_bool(GCONF_LOCK_RIGHT_SENSOR, g_cur_sensor_settings.lock_right_sensor);
00158 }
00159
00160 LOGPRINTF("Saving sensor settings, done.");
00161 }
00162
00163 GtkWidget* create_sensors_window(GtkWidget* parent)
00164 {
00165
00166 GtkWidget* top_window = parent;
00167 gtk_window_maximize(GTK_WINDOW(top_window));
00168 gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00169 gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING );
00170 gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00171
00172
00173 GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00174 gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00175
00176
00177 create_title(GTK_VBOX(vboxtop), _("Settings"), _("Navigation Sensors"));
00178
00179
00180 GtkWidget* view = create_settingsview();
00181 gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 );
00182 g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ;
00183 g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ;
00184 g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00185 g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00186
00187
00188 GtkWidget* vbox1 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00189 create_light_widgets(GTK_BOX(vbox1));
00190
00191 GtkWidget* vbox2 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00192 create_sound_widgets(GTK_BOX(vbox2));
00193
00194 GtkWidget* vbox3 = GTK_WIDGET( create_frame(GTK_VBOX(vboxtop)) );
00195 create_lock_widgets(GTK_BOX(vbox3));
00196
00197
00198 init_widgets_with_settings();
00199
00200 g_sensor_settings_window = top_window;
00201
00202 gtk_widget_grab_focus(view);
00203
00204 gtk_widget_show_all(top_window);
00205 return top_window;
00206 }
00207
00208
00209
00210
00211
00212
00213 static gboolean on_focus_in(GtkWidget* widget, gpointer data )
00214 {
00215 g_assert(widget != NULL ) ;
00216 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0);
00217 return FALSE;
00218 }
00219
00220 static gboolean on_focus_out(GtkWidget* widget, gpointer data )
00221 {
00222 g_assert(widget != NULL ) ;
00223 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00224 g_assert( my_selection != NULL ) ;
00225 gtk_tree_selection_unselect_all(my_selection);
00226 return FALSE;
00227 }
00228
00229 static void on_listview_row_activated ( GtkTreeView *view,
00230 GtkTreePath *path,
00231 GtkTreeViewColumn *column,
00232 gpointer user_data )
00233 {
00234 save_sensor_settings();
00235 main_quit();
00236 return;
00237 }
00238
00239 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00240 erGtkListViewKeyPress keycode,
00241 gpointer user_data )
00242 {
00243 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00244 g_assert( my_selection != NULL ) ;
00245
00246
00247 switch (keycode)
00248 {
00249 case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00250 case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00251 gtk_widget_grab_focus(GTK_WIDGET(g_light_radios[0]));
00252 gtk_tree_selection_unselect_all(my_selection);
00253 break;
00254 default:
00255 LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00256 ;
00257 break;
00258 }
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268 static GtkWidget* create_light_widgets(GtkBox* parent)
00269 {
00270
00271 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00272 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00273
00274
00275 GtkWidget* subject = subject_create();
00276 gtk_label_set_label(GTK_LABEL(subject), _("Lights"));
00277 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00278
00279
00280 GtkWidget* desc = description_create();
00281 gtk_label_set_label(GTK_LABEL(desc), _("This setting controls the green indication lights next to the sensor panels."));
00282 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00283
00284
00285
00286 GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00287 gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0);
00288
00289 int i = 0;
00290 for (i=0; i<2; i++)
00291 {
00292 if (i == 0)
00293 {
00294
00295 g_light_radios[i] = gtk_radio_button_new_with_label(NULL, _("On"));
00296 }
00297 else
00298 {
00299
00300 g_light_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_light_radios[0]), _("Off"));
00301 }
00302
00303
00304 g_signal_connect_after(G_OBJECT(g_light_radios[i]),
00305 "toggled",
00306 G_CALLBACK(on_use_light_changed),
00307 (gpointer)i);
00308
00309 gtk_box_pack_start(GTK_BOX(vbox), g_light_radios[i], FALSE, FALSE, 0);
00310 }
00311
00312 return top_level_vbox;
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322 static GtkWidget* create_sound_widgets(GtkBox* parent)
00323 {
00324
00325 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00326 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00327
00328
00329 GtkWidget* subject = subject_create();
00330 gtk_label_set_label(GTK_LABEL(subject), _("Sound"));
00331 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00332
00333
00334 GtkWidget* desc = description_create();
00335 gtk_label_set_label(GTK_LABEL(desc), _("You can turn the beep on or off with this setting."));
00336 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00337
00338
00339 GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00340 gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0);
00341
00342 int i=0;
00343 for (i=0; i<2; i++)
00344 {
00345 if (i == 0)
00346 {
00347
00348 g_sound_radios[i] = gtk_radio_button_new_with_label(NULL, _("On"));
00349 }
00350 else
00351 {
00352
00353 g_sound_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_sound_radios[0]), _("Off"));
00354 }
00355
00356
00357 g_signal_connect_after(G_OBJECT(g_sound_radios[i]),
00358 "toggled",
00359 G_CALLBACK(on_use_sound_changed),
00360 (gpointer)i);
00361
00362 gtk_box_pack_start(GTK_BOX(vbox), g_sound_radios[i], FALSE, FALSE, 0);
00363 }
00364
00365 return top_level_vbox;
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 static GtkWidget* create_lock_widgets(GtkBox* parent)
00380 {
00381
00382 GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00383 gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00384
00385
00386 GtkWidget* subject = subject_create();
00387 gtk_label_set_label(GTK_LABEL(subject), _("Sensor Lock"));
00388 gtk_box_pack_start(GTK_BOX(top_level_vbox), subject, FALSE, FALSE, 0);
00389
00390
00391 GtkWidget* desc = description_create();
00392 gtk_label_set_label(GTK_LABEL(desc), _("Customize your own sensor lock by choosing one or all of the lock options."));
00393 gtk_box_pack_start(GTK_BOX(top_level_vbox), desc, FALSE, FALSE, 0);
00394
00395
00396 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
00397 gtk_box_pack_start(GTK_BOX(top_level_vbox), hbox, FALSE, FALSE, 0);
00398
00399
00400 GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00401 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00402
00403
00404 g_lock_left_sensor_check = gtk_check_button_new_with_label(_("Lock Left Sensors"));
00405 g_signal_connect(G_OBJECT(g_lock_left_sensor_check),
00406 "toggled",
00407 G_CALLBACK(on_lock_left_changed),
00408 NULL);
00409 gtk_box_pack_start(GTK_BOX(vbox), g_lock_left_sensor_check, FALSE, FALSE, 0);
00410
00411
00412 g_lock_middle_sensor_check = gtk_check_button_new_with_label(_("Lock Middle Sensors"));
00413 g_signal_connect(G_OBJECT(g_lock_middle_sensor_check),
00414 "toggled",
00415 G_CALLBACK(on_lock_middle_changed),
00416 NULL);
00417 gtk_box_pack_start(GTK_BOX(vbox), g_lock_middle_sensor_check, FALSE, FALSE, 0);
00418
00419
00420 g_lock_right_sensor_check = gtk_check_button_new_with_label(_("Lock Right Sensors"));
00421 g_signal_connect(G_OBJECT(g_lock_right_sensor_check),
00422 "toggled",
00423 G_CALLBACK(on_lock_right_changed),
00424 NULL);
00425 gtk_box_pack_start(GTK_BOX(vbox), g_lock_right_sensor_check, FALSE, FALSE, 0);
00426
00427
00428 g_sensor_lock_image = gtk_image_new();
00429 gtk_box_pack_start(GTK_BOX(hbox), g_sensor_lock_image, TRUE, FALSE, 0);
00430 return top_level_vbox;
00431 }
00432
00433
00434
00435 static void on_use_light_changed(GtkWidget *widget, gpointer data)
00436 {
00437 int index = (int)data;
00438 gboolean is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00439
00440 if (is_active == TRUE)
00441 {
00442 g_cur_sensor_settings.lights_on = (index == 0) ? TRUE : FALSE;
00443 }
00444 }
00445
00446
00447 static void on_use_sound_changed(GtkWidget *widget, gpointer data)
00448 {
00449 int index = (int)data;
00450 gboolean is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00451
00452 if (is_active == TRUE)
00453 {
00454 g_cur_sensor_settings.sound_on = (index == 0) ? TRUE : FALSE;
00455 }
00456 }
00457
00458
00459 static void on_lock_left_changed(GtkWidget *widget, gpointer data)
00460 {
00461 g_cur_sensor_settings.lock_left_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00462
00463 update_sensor_lock_image(g_cur_sensor_settings.lock_left_sensor,
00464 g_cur_sensor_settings.lock_middle_sensor,
00465 g_cur_sensor_settings.lock_right_sensor);
00466 }
00467
00468
00469 static void on_lock_middle_changed(GtkWidget *widget, gpointer data)
00470 {
00471 g_cur_sensor_settings.lock_middle_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00472
00473 update_sensor_lock_image(g_cur_sensor_settings.lock_left_sensor,
00474 g_cur_sensor_settings.lock_middle_sensor,
00475 g_cur_sensor_settings.lock_right_sensor);
00476 }
00477
00478
00479 static void on_lock_right_changed(GtkWidget *widget, gpointer data)
00480 {
00481 g_cur_sensor_settings.lock_right_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00482
00483 update_sensor_lock_image(g_cur_sensor_settings.lock_left_sensor,
00484 g_cur_sensor_settings.lock_middle_sensor,
00485 g_cur_sensor_settings.lock_right_sensor);
00486 }
00487
00488
00489 static void update_sensor_lock_image(gboolean lock_left,
00490 gboolean lock_middle,
00491 gboolean lock_right)
00492 {
00493 gchar* image_file = g_strdup_printf(DATADIR"/sensor-lock%1d%1d%1d.png",
00494 lock_left ? 1 : 0,
00495 lock_middle ? 1 : 0,
00496 lock_right ? 1 : 0);
00497
00498 gtk_image_set_from_file(GTK_IMAGE(g_sensor_lock_image), image_file);
00499 g_free(image_file);
00500 }
00501
00502
00503 static void init_widgets_with_settings()
00504 {
00505 int to_be_activated = 0;
00506
00507 to_be_activated = g_cur_sensor_settings.lights_on == TRUE ? 0 : 1;
00508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_light_radios[to_be_activated]),
00509 TRUE);
00510
00511 to_be_activated = g_cur_sensor_settings.sound_on == TRUE ? 0 : 1;
00512 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_sound_radios[to_be_activated]),
00513 TRUE);
00514
00515 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_lock_left_sensor_check),
00516 g_cur_sensor_settings.lock_left_sensor);
00517
00518 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_lock_middle_sensor_check),
00519 g_cur_sensor_settings.lock_middle_sensor);
00520
00521 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_lock_right_sensor_check),
00522 g_cur_sensor_settings.lock_right_sensor);
00523
00524
00525 update_sensor_lock_image(g_cur_sensor_settings.lock_left_sensor,
00526 g_cur_sensor_settings.lock_middle_sensor,
00527 g_cur_sensor_settings.lock_right_sensor);
00528 }
00529
00530
00531