flightmode.c File Reference

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <libergtk/ergtk.h>
#include "i18n.h"
#include "log.h"
#include "ipc.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "flightmode.h"
Include dependency graph for flightmode.c:

Go to the source code of this file.

Data Structures

struct  FlightModeSettings

Enumerations

enum  { FLIGHTMODE_MODE_OFF = 0, FLIGHTMODE_MODE_ON, NUM_FLIGHTMODE_MODES }

Functions

static GtkWidget * create_flightmode_widgets (GtkBox *parent)
static void on_flightmode_changed (GtkWidget *widget, gpointer data)
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)
GtkWidget * create_flightmode_window (GtkWidget *parent)
void load_flightmode_settings ()
void save_flightmode_settings ()
static GtkWidget * create_radio_button_item (GtkWidget *group, gchar *title, gchar *subtitle)

Variables

enum { ... }  FlightModeModes_e
static gboolean g_orig_is_flightmode_enabled = FALSE
static gboolean g_cur_is_flightmode_enabled = FALSE
static GtkWidget * g_flightmode_radios [NUM_FLIGHTMODE_MODES]

Enumeration Type Documentation

anonymous enum
Enumerator:
FLIGHTMODE_MODE_OFF 
FLIGHTMODE_MODE_ON 
NUM_FLIGHTMODE_MODES 

Definition at line 61 of file flightmode.c.


Function Documentation

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

Definition at line 309 of file flightmode.c.

References create_radio_button_item(), g_flightmode_radios, ITEM_SPACING, NUM_FLIGHTMODE_MODES, and on_flightmode_changed().

Referenced by create_flightmode_window().

00310 {
00311 
00312     // Top level vbox.
00313     GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00314     gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00315 
00316     // The vbox containing radio buttons.
00317     GtkWidget* vbox = gtk_vbox_new(TRUE, 10);
00318     gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0);
00319 
00320     int i = 0 ;
00321     for (i=0; i<NUM_FLIGHTMODE_MODES; i++)
00322     {
00323         switch (i)
00324         {
00325             case 0:
00326             {
00327                 // The radio button "Normal margins".
00328                 g_flightmode_radios[i] = create_radio_button_item( NULL,
00329                                            _("Airplane Mode OFF"),
00330                                            _("Wireless is enabled and the device can connect to networks.") );
00331                 
00332                 break;
00333             }
00334             case 1:
00335             {
00336                 // the radio button "No Margins"
00337                 g_flightmode_radios[i] = create_radio_button_item( g_flightmode_radios[0],
00338                                            _("Airplane Mode ON"),
00339                                            _("Wireless is disabled and the device cannot connect to networks.") );
00340                 
00341                 break;
00342             }
00343             default:
00344             {
00345                 g_assert_not_reached();
00346             }
00347         }
00348 
00349         // Add signal handler.
00350         g_signal_connect_after(G_OBJECT(g_flightmode_radios[i]),
00351             "toggled",
00352             G_CALLBACK(on_flightmode_changed),
00353             (gpointer)i);
00354 
00355         gtk_box_pack_start(GTK_BOX(vbox), g_flightmode_radios[i], FALSE, FALSE, 0);
00356     }
00357 
00358     return top_level_vbox;
00359 }

Here is the call graph for this function:

Here is the caller graph for this function:

GtkWidget* create_flightmode_window ( GtkWidget *  parent  ) 

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

Definition at line 108 of file flightmode.c.

References create_flightmode_widgets(), create_settingsview(), create_title(), init_widgets_with_settings(), on_focus_in(), on_focus_out(), on_listview_navigate_cursor(), on_listview_row_activated(), SMALL_SPACING, WINDOW_BORDER_PADDING, WINDOW_BOTTOM_PADDING, WINDOW_H_PADDING, and WINDOW_TOP_ALT_PADDING.

Referenced by create_concrete_win().

00109 {
00110     // create top window
00111     GtkWidget* top_window = parent;
00112     gtk_window_maximize(GTK_WINDOW(top_window));
00113     gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00114     gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING  );
00115     gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00116 
00117     // top level vbox (vboxtop)
00118     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 3);
00119     gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00120 
00121     // add header container the title and subtitle of this settings page
00122     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Airplane Mode"));
00123     
00124     // add the back/exit bar below the title 
00125     GtkWidget* view = create_settingsview();
00126     gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 ); 
00127     g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ;
00128     g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ;
00129     g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00130     g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00131 
00132     // add an alignment below the exit bar
00133     GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00134     gtk_container_add(GTK_CONTAINER(vboxtop), alignment);
00135 
00136     // introdude a frame in the alignment
00137     GtkWidget* frame = gtk_frame_new(NULL);
00138     gtk_widget_set_name(frame, "irex-margins-frame");
00139     gtk_container_add(GTK_CONTAINER(alignment), frame);
00140     gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00141 
00142     // alignment in frame 
00143     GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
00144     gtk_container_add(GTK_CONTAINER(frame), alignment2);
00145     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2),
00146                               WINDOW_TOP_ALT_PADDING,
00147                               WINDOW_BOTTOM_PADDING,
00148                               WINDOW_H_PADDING,
00149                               WINDOW_H_PADDING);
00150    
00151     // vbox in alignment2
00152     GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00153     gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00154     
00155     // The margin settings section.
00156     create_flightmode_widgets(GTK_BOX(innervbox));
00157 
00158     // Update widget with current settings.
00159     init_widgets_with_settings();
00160 
00161     // back button has initial focus
00162     gtk_widget_grab_focus(view);
00163 
00164     gtk_widget_show_all(top_window);
00165     return top_window;
00166 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget* create_radio_button_item ( GtkWidget *  group,
gchar *  title,
gchar *  subtitle 
) [static]

Definition at line 253 of file flightmode.c.

References label, and SETTINGS_LABEL_MAX_WIDTH.

Referenced by create_flightmode_widgets().

00254 {
00255     GtkWidget* radio_button = NULL ;
00256     if ( group == NULL ) 
00257     {
00258         radio_button = gtk_radio_button_new(NULL); 
00259     }
00260     else
00261     {
00262         radio_button = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(group)); 
00263 
00264     }
00265     gtk_widget_set_name(radio_button, "irex-settings-checkbutton");
00266 
00267     // alignment in radio button for some padding
00268     GtkWidget* align = gtk_alignment_new(0, 0.0, 1.0, 1.0);
00269     gtk_container_add(GTK_CONTAINER(radio_button), align);
00270     gtk_alignment_set_padding(GTK_ALIGNMENT(align)
00271                                 , 6 // top
00272                                 , 6 // bottom
00273                                 , 6 // left
00274                                 , 6 // right
00275             );
00276  
00277     // vbox in radio button
00278     GtkWidget* radiovbox = gtk_vbox_new( FALSE, 0);
00279     gtk_container_add(GTK_CONTAINER(align), radiovbox);
00280 
00281     // top level label for radio button ( no margins )
00282     GtkWidget* label = gtk_label_new( title );
00283     gtk_widget_set_name(label, "irex-radio-title");
00284     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00285     gtk_box_pack_start(GTK_BOX(radiovbox), label, FALSE, FALSE, 0);
00286 
00287     // second level label for radio button ( descriptive test )
00288     label = gtk_label_new( subtitle  );
00289     gtk_widget_set_name(label, "irex-radio-subtitle");
00290     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00291     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00292     gtk_widget_set_size_request(label, SETTINGS_LABEL_MAX_WIDTH - 40 , -1);
00293     gtk_box_pack_start(GTK_BOX(radiovbox), label, FALSE, FALSE, 0);
00294 
00295     return radio_button;
00296 }

Here is the caller graph for this function:

static void init_widgets_with_settings ( void   )  [static]

Definition at line 387 of file flightmode.c.

References g_cur_is_flightmode_enabled, g_flightmode_radios, and NUM_FLIGHTMODE_MODES.

Referenced by create_flightmode_window().

00388 {
00389     int i;
00390     int item_to_activate = g_cur_is_flightmode_enabled ? 1 : 0;
00391 
00392     for (i = 0; i < NUM_FLIGHTMODE_MODES; i++)
00393     {
00394         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(g_flightmode_radios[i]),
00395                                       (i == item_to_activate) ? TRUE : FALSE );
00396     }
00397 }

Here is the caller graph for this function:

void load_flightmode_settings (  ) 

Definition at line 228 of file flightmode.c.

References g_cur_is_flightmode_enabled, g_orig_is_flightmode_enabled, GCONF_FLIGHTMODE_MODE, and get_value_bool().

Referenced by create_concrete_win().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 362 of file flightmode.c.

References g_cur_is_flightmode_enabled, is_active, and NUM_FLIGHTMODE_MODES.

Referenced by create_flightmode_widgets().

00363 {
00364     int index = (int)data;
00365 
00366     g_assert( 0 <= index );
00367     g_assert( index < NUM_FLIGHTMODE_MODES );
00368 
00369     gboolean is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00370 
00371     if (is_active == TRUE )
00372     {
00373         switch (index)
00374         {
00375             case 0:
00376                 g_cur_is_flightmode_enabled = FALSE;
00377                 break;
00378             case 1:
00379                 g_cur_is_flightmode_enabled = TRUE;
00380                 break;
00381             default:
00382                 g_assert_not_reached();
00383         }
00384     }
00385 }

Here is the caller graph for this function:

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

Definition at line 207 of file flightmode.c.

References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().

Referenced by create_flightmode_window().

00208 {
00209     g_assert(widget != NULL ) ;
00210     ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0;
00211     return FALSE;
00212 }

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 214 of file flightmode.c.

Referenced by create_flightmode_window().

00215 {
00216     g_assert(widget != NULL ) ;
00217     GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00218     g_assert( my_selection != NULL ) ;
00219     gtk_tree_selection_unselect_all(my_selection);
00220     return FALSE;
00221 }

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 184 of file flightmode.c.

References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, g_flightmode_radios, and LOGPRINTF.

Referenced by create_flightmode_window().

00187 {
00188    GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00189   g_assert( my_selection != NULL ) ;
00190 
00191     // determine new cursor position
00192     switch (keycode)
00193     {
00194         case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00195         case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00196             gtk_widget_grab_focus(GTK_WIDGET(g_flightmode_radios[0]));
00197             gtk_tree_selection_unselect_all(my_selection);
00198             break;
00199         default:
00200             LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00201             ;  // ignore
00202             break;
00203     }
00204 
00205 }

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 172 of file flightmode.c.

References main_quit(), and save_flightmode_settings().

Referenced by create_flightmode_window().

00176 {
00177 
00178     // save flightmode if changed
00179     save_flightmode_settings();
00180     main_quit();
00181     return;
00182 }

Here is the call graph for this function:

Here is the caller graph for this function:

void save_flightmode_settings (  ) 

Definition at line 236 of file flightmode.c.

References g_cur_is_flightmode_enabled, g_orig_is_flightmode_enabled, GCONF_FLIGHTMODE_MODE, LOGPRINTF, and set_value_bool().

Referenced by on_listview_row_activated().

00237 {
00238     if (g_cur_is_flightmode_enabled  != g_orig_is_flightmode_enabled )
00239     {
00240         set_value_bool(GCONF_FLIGHTMODE_MODE, g_cur_is_flightmode_enabled);
00241         g_orig_is_flightmode_enabled = g_cur_is_flightmode_enabled;
00242     }
00243 
00244     LOGPRINTF("Saving flightmode settings, done.");
00245 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

enum { ... } FlightModeModes_e
gboolean g_cur_is_flightmode_enabled = FALSE [static]
GtkWidget* g_flightmode_radios[NUM_FLIGHTMODE_MODES] [static]
gboolean g_orig_is_flightmode_enabled = FALSE [static]

Definition at line 78 of file flightmode.c.

Referenced by load_flightmode_settings(), and save_flightmode_settings().

Generated by  doxygen 1.6.2-20100208