sensors.c File Reference

#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 "sensors.h"
Include dependency graph for sensors.c:

Go to the source code of this file.

Data Structures

struct  SensorSettings

Functions

static GtkWidget * create_light_widgets (GtkBox *parent)
static GtkWidget * create_sound_widgets (GtkBox *parent)
static GtkWidget * create_lock_widgets (GtkBox *parent)
static void on_use_light_changed (GtkWidget *widget, gpointer data)
static void on_use_sound_changed (GtkWidget *widget, gpointer data)
static void on_lock_left_changed (GtkWidget *widget, gpointer data)
static void on_lock_middle_changed (GtkWidget *widget, gpointer data)
static void on_lock_right_changed (GtkWidget *widget, gpointer data)
static void update_sensor_lock_image (gboolean lock_left, gboolean lock_middle, gboolean lock_right)
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_sensor_settings ()
void save_sensor_settings ()
GtkWidget * create_sensors_window (GtkWidget *parent)

Variables

static SensorSettings g_orig_sensor_settings
static SensorSettings g_cur_sensor_settings
static GtkWidget * g_sensor_settings_window = NULL
static GtkWidget * g_light_radios [2] = {NULL, NULL}
static GtkWidget * g_sound_radios [2] = {NULL, NULL}
static GtkWidget * g_lock_left_sensor_check = NULL
static GtkWidget * g_lock_middle_sensor_check = NULL
static GtkWidget * g_lock_right_sensor_check = NULL
static GtkWidget * g_sensor_lock_image = NULL

Function Documentation

static GtkWidget * create_light_widgets ( GtkBox *  parent  )  [static]

Definition at line 268 of file sensors.c.

References description_create(), g_light_radios, ITEM_SPACING, on_use_light_changed(), and subject_create().

Referenced by create_sensors_window().

00269 {
00270     // Top level vbox.
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     // Subject "Lights".
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     // Description "This setting controls..."
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     // The vbox containing radio buttons.
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             // The radio button "On".
00295             g_light_radios[i] = gtk_radio_button_new_with_label(NULL, _("On"));
00296         }
00297         else
00298         {
00299             // The radio button "Off".
00300             g_light_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_light_radios[0]), _("Off"));
00301         }
00302 
00303         // Add signal handler.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget * create_lock_widgets ( GtkBox *  parent  )  [static]

Definition at line 379 of file sensors.c.

References description_create(), g_lock_left_sensor_check, g_lock_middle_sensor_check, g_lock_right_sensor_check, g_sensor_lock_image, ITEM_SPACING, on_lock_left_changed(), on_lock_middle_changed(), on_lock_right_changed(), and subject_create().

Referenced by create_sensors_window().

00380 {
00381     // Top level vbox.
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     // Subject "Sensor Lock".
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     // Description "Customize your own..."
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     // The hbox containing check buttons and image.
00396     GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
00397     gtk_box_pack_start(GTK_BOX(top_level_vbox), hbox, FALSE, FALSE, 0);
00398 
00399     // The vbox containing check buttons.
00400     GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
00401     gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
00402 
00403     // The fist check button "Lock Left Sensors".
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     // The second check button "Lock Middle Sensors".
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     // The third check button "Lock Right Sensors".
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     // The sensor lock image.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

GtkWidget* create_sensors_window ( GtkWidget *  parent  ) 

Copyright (C) 2010 iRex Technologies B.V. All rights reserved.

Definition at line 163 of file sensors.c.

References create_frame(), create_light_widgets(), create_lock_widgets(), create_settingsview(), create_sound_widgets(), create_title(), g_sensor_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().

00164 {
00165     // create top window
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     // top level vbox (vboxtop)
00173     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00174     gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00175 
00176     // add header container the title and subtitle of this settings page
00177     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Navigation Sensors"));
00178     
00179     // add the back/exit bar below the title 
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     // Update widget with current settings.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget * create_sound_widgets ( GtkBox *  parent  )  [static]

Definition at line 322 of file sensors.c.

References description_create(), g_sound_radios, ITEM_SPACING, on_use_sound_changed(), and subject_create().

Referenced by create_sensors_window().

00323 {
00324     // Top level vbox.
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     // Subject "Sound".
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     // Description "You can turn..."
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     // The vbox containing radio buttons.
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             // The radio button "On".
00348             g_sound_radios[i] = gtk_radio_button_new_with_label(NULL, _("On"));
00349         }
00350         else
00351         {
00352             // The radio button "Off".
00353             g_sound_radios[i] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(g_sound_radios[0]), _("Off"));
00354         }
00355 
00356         // Add signal handler.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_widgets_with_settings ( void   )  [static]

Definition at line 503 of file sensors.c.

References g_light_radios, g_lock_left_sensor_check, g_lock_middle_sensor_check, g_lock_right_sensor_check, g_sound_radios, SensorSettings::lights_on, SensorSettings::lock_left_sensor, SensorSettings::lock_middle_sensor, SensorSettings::lock_right_sensor, SensorSettings::sound_on, and update_sensor_lock_image().

Referenced by create_sensors_window().

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     // Update sensor lock image.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

void load_sensor_settings (  ) 
static gboolean on_focus_in ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 213 of file sensors.c.

References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().

Referenced by create_sensors_window().

00214 {
00215     g_assert(widget != NULL ) ;
00216     ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0;
00217     return FALSE;
00218 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_focus_out ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 220 of file sensors.c.

Referenced by create_sensors_window().

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 }

Here is the caller graph for this function:

static void on_listview_navigate_cursor ( erGtkListView er_listview,
erGtkListViewKeyPress  keycode,
gpointer  user_data 
) [static]

Definition at line 239 of file sensors.c.

References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, g_light_radios, and LOGPRINTF.

Referenced by create_sensors_window().

00242 {
00243     GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00244     g_assert( my_selection != NULL ) ;
00245 
00246     // determine new cursor position
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])); // down: to first widget
00252             gtk_tree_selection_unselect_all(my_selection);
00253             break;
00254         default:
00255             LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00256             ;  // ignore
00257             break;
00258     }
00259 }

Here is the caller graph for this function:

static void on_listview_row_activated ( GtkTreeView *  view,
GtkTreePath *  path,
GtkTreeViewColumn *  column,
gpointer  user_data 
) [static]

Definition at line 229 of file sensors.c.

References main_quit(), and save_sensor_settings().

Referenced by create_sensors_window().

00233 {
00234     save_sensor_settings();
00235     main_quit();
00236     return;
00237 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_lock_left_changed ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 459 of file sensors.c.

References SensorSettings::lock_left_sensor, SensorSettings::lock_middle_sensor, SensorSettings::lock_right_sensor, and update_sensor_lock_image().

Referenced by create_lock_widgets().

00460 {
00461     g_cur_sensor_settings.lock_left_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00462     // Update sensor lock image.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_lock_middle_changed ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 469 of file sensors.c.

References SensorSettings::lock_left_sensor, SensorSettings::lock_middle_sensor, SensorSettings::lock_right_sensor, and update_sensor_lock_image().

Referenced by create_lock_widgets().

00470 {
00471     g_cur_sensor_settings.lock_middle_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00472     // Update sensor lock image.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_lock_right_changed ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 479 of file sensors.c.

References SensorSettings::lock_left_sensor, SensorSettings::lock_middle_sensor, SensorSettings::lock_right_sensor, and update_sensor_lock_image().

Referenced by create_lock_widgets().

00480 {
00481     g_cur_sensor_settings.lock_right_sensor = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00482     // Update sensor lock image.
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_use_light_changed ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 435 of file sensors.c.

References is_active, and SensorSettings::lights_on.

Referenced by create_light_widgets().

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 }

Here is the caller graph for this function:

static void on_use_sound_changed ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 447 of file sensors.c.

References is_active, and SensorSettings::sound_on.

Referenced by create_sound_widgets().

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 }

Here is the caller graph for this function:

void save_sensor_settings (  ) 

Definition at line 133 of file sensors.c.

References GCONF_LOCK_LEFT_SENSOR, GCONF_LOCK_MIDDLE_SENSOR, GCONF_LOCK_RIGHT_SENSOR, GCONF_USE_LIGHT, GCONF_USE_SOUND, SensorSettings::lights_on, SensorSettings::lock_left_sensor, SensorSettings::lock_middle_sensor, SensorSettings::lock_right_sensor, LOGPRINTF, set_value_bool(), and SensorSettings::sound_on.

Referenced by on_listview_row_activated().

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_sensor_lock_image ( gboolean  lock_left,
gboolean  lock_middle,
gboolean  lock_right 
) [static]

Definition at line 489 of file sensors.c.

References g_sensor_lock_image.

Referenced by init_widgets_with_settings(), on_lock_left_changed(), on_lock_middle_changed(), and on_lock_right_changed().

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 }

Here is the caller graph for this function:


Variable Documentation

Definition at line 72 of file sensors.c.

GtkWidget* g_light_radios[2] = {NULL, NULL} [static]
GtkWidget* g_lock_left_sensor_check = NULL [static]

Definition at line 77 of file sensors.c.

Referenced by create_lock_widgets(), and init_widgets_with_settings().

GtkWidget* g_lock_middle_sensor_check = NULL [static]

Definition at line 78 of file sensors.c.

Referenced by create_lock_widgets(), and init_widgets_with_settings().

GtkWidget* g_lock_right_sensor_check = NULL [static]

Definition at line 79 of file sensors.c.

Referenced by create_lock_widgets(), and init_widgets_with_settings().

Definition at line 71 of file sensors.c.

GtkWidget* g_sensor_lock_image = NULL [static]

Definition at line 80 of file sensors.c.

Referenced by create_lock_widgets(), and update_sensor_lock_image().

GtkWidget* g_sensor_settings_window = NULL [static]

Definition at line 74 of file sensors.c.

Referenced by create_sensors_window().

GtkWidget* g_sound_radios[2] = {NULL, NULL} [static]

Definition at line 76 of file sensors.c.

Referenced by create_sound_widgets(), and init_widgets_with_settings().

Generated by  doxygen 1.6.2-20100208