settings/src/iLiadLanguageScreen.c File Reference

settings -Language Selection Screen More...

#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <liberdm/display.h>
#include <libergtk/ergtk.h>
#include "iLiadLanguageData.h"
#include "iLiadLanguageScreen.h"
#include "languages.h"
#include "erbusy.h"
#include "displayStatus.h"
#include "setupLog.h"

Go to the source code of this file.

Functions

static void on_language_destroy (GtkWidget *widget, gpointer data)
static gboolean on_language_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
static gboolean on_language_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data)
static void on_language_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data)
static void on_language_selection_update (erGtkSelectionGroup *selection, gpointer button, gpointer data)
static void up_one_item (erGtkSelectionGroup *selection)
static void up_to_first_item (erGtkSelectionGroup *selection)
static void down_one_item (erGtkSelectionGroup *selection)
static void down_to_last_item (erGtkSelectionGroup *selection)
static gboolean confirm_current_item (gpointer data)
GtkWidget * iLiad_language_screen_create (void)
void iLiad_language_screen_display_data (void)

Variables

static iLiad_locale_tg_locale_installed_tbl = NULL
static guint g_locale_installed_num = 0
static gtkLanguage_t g_select_language


Detailed Description

settings -Language Selection Screen

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

Providing GUI to let users select language. Notes: This screen is not one page of gtk_notebook.

Definition in file iLiadLanguageScreen.c.


Function Documentation

static gboolean confirm_current_item ( gpointer  data  )  [static]

Definition at line 415 of file iLiadLanguageScreen.c.

00416 {
00417     const gboolean save = (gboolean)data;
00418     
00419     erbusy_blink();
00420     if (save)
00421     {
00422         iLiad_language_data_store();
00423     }
00424     gtk_main_quit();
00425 
00426     return FALSE;
00427 }

Here is the call graph for this function:

static void down_one_item ( erGtkSelectionGroup selection  )  [static]

Definition at line 375 of file iLiadLanguageScreen.c.

00376 {
00377     gint nButtons = ergtk_selection_group_get_length(selection);
00378     if (nButtons > 0)
00379     {
00380         int currentFocus = 0, newFocus = 0;
00381         GtkToggleButton* button= NULL;
00382 
00383         ergtk_selection_group_get_selected_buttons(ERGTK_SELECTION_GROUP(selection), &currentFocus, 1);
00384         if ((currentFocus < 0) || (currentFocus >= g_locale_installed_num))
00385         {
00386             newFocus = 0;
00387         }
00388         else
00389         {
00390             newFocus = currentFocus + 1;
00391             if (newFocus >= nButtons)
00392             {
00393                 newFocus = 0;
00394             }
00395         }
00396 
00397         button = ergtk_selection_group_get_button(selection, newFocus);
00398         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00399         gtk_widget_grab_focus(GTK_WIDGET(button));
00400      }
00401 }

Here is the call graph for this function:

static void down_to_last_item ( erGtkSelectionGroup selection  )  [static]

Definition at line 403 of file iLiadLanguageScreen.c.

00404 {
00405     gint nButtons = ergtk_selection_group_get_length(selection);
00406     if (nButtons > 0)
00407     {
00408         GtkToggleButton* button= NULL;
00409         button = ergtk_selection_group_get_button(selection, nButtons-1);
00410         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00411         gtk_widget_grab_focus(GTK_WIDGET(button));
00412     } 
00413 }

Here is the call graph for this function:

GtkWidget* iLiad_language_screen_create ( void   ) 

Definition at line 75 of file iLiadLanguageScreen.c.

00076 {
00077     GtkWidget*  window;
00078     GtkWidget*  background;
00079     GtkWidget*  alignment;
00080     GtkWidget*  vbox;
00081     GtkWidget*  button;
00082     GtkWidget*  selection;
00083     gint        i, nbuttons; 
00084     GtkToggleButton* button_tbl[LANGUAGE_MAX_BUTTON_NUMBER + 1];
00085     gint        paddingTop, paddingBottom;
00086 
00087     g_locale_installed_num = find_installed_locales(&g_locale_installed_tbl);
00088     // calculate how many buttons to be created
00089     nbuttons = ( (g_locale_installed_num <= LANGUAGE_MAX_BUTTON_NUMBER) 
00090                   ? g_locale_installed_num : LANGUAGE_MAX_BUTTON_NUMBER);
00091 
00092     // window
00093     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00094     gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION);
00095     gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
00096     gtk_container_set_border_width(GTK_CONTAINER(window), 0);
00097     gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT);
00098     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
00099     gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
00100     gtk_window_fullscreen(GTK_WINDOW(window)); 
00101     g_select_language.window = window; 
00102 
00103     // background
00104     background = gtk_event_box_new();
00105     gtk_widget_set_name(background, "language_background");
00106     gtk_widget_set_size_request(background, LANGUAGE_SCREEN_WIDTH, LANGUAGE_SCREEN_HEIGHT);
00107     gtk_container_add(GTK_CONTAINER(window), background);
00108 
00109     // alignment
00110     alignment = gtk_alignment_new(0, 0, 0, 0);
00111     // calculate top padding and bottom padding
00112     paddingTop = (LANGUAGE_SCREEN_HEIGHT + LANGUAGE_SCREEN_SPACING
00113                      - (LANGUAGE_BUTTON_HEIGHT + LANGUAGE_SCREEN_SPACING) * nbuttons) / 2;
00114     paddingBottom = paddingTop;
00115     ST_LOGPRINTF("top padding = %d, bottom padding = %d", paddingTop, paddingBottom);
00116     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00117                               paddingTop, paddingBottom,
00118                               LANGUAGE_SCREEN_PADDING_LEFT, LANGUAGE_SCREEN_PADDING_RIGHT);
00119     gtk_container_add(GTK_CONTAINER(background), alignment);
00120     
00121     // vbox
00122     vbox = gtk_vbox_new(FALSE, LANGUAGE_SCREEN_SPACING);
00123     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00124     
00125     // button
00126     ST_LOGPRINTF("Creating %d buttons.", nbuttons);
00127     
00128     for (i = 0 ; i < nbuttons ; i++)
00129     {
00130         button = ergtk_toggle_button_new_with_label( g_locale_installed_tbl[i].long_name );
00131         button_tbl[i] = GTK_TOGGLE_BUTTON(button);
00132         gtk_widget_set_size_request(button, LANGUAGE_BUTTON_WIDTH, LANGUAGE_BUTTON_HEIGHT);
00133         gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00134         g_signal_connect(G_OBJECT(button), "button_press_event", 
00135                 G_CALLBACK(on_language_button_press), button);
00136     }
00137     button_tbl[i] = NULL;
00138     
00139     // selection
00140     selection = ergtk_selection_group_new(button_tbl);
00141     ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection), 0, 1);
00142     g_select_language.selection = selection;
00143 
00144     // signal handlers
00145     g_signal_connect(G_OBJECT(background), "expose-event", G_CALLBACK(on_language_expose), NULL);
00146     g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_language_destroy), &g_select_language);
00147     g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(on_language_key_press), &g_select_language);
00148 
00149     g_signal_connect(G_OBJECT(selection), "selection-update", 
00150             G_CALLBACK(on_language_selection_update), &g_select_language);
00151 
00152     gtk_widget_show_all(background);
00153     
00154     // return
00155     return window;
00156 }

Here is the call graph for this function:

void iLiad_language_screen_display_data ( void   ) 

Definition at line 158 of file iLiadLanguageScreen.c.

00159 {
00160     gint        i;
00161     const char* locale;
00162 
00163     ST_LOGPRINTF("entry");
00164 
00165     // get the current language setting
00166     locale = iLiad_language_data_get();
00167    
00168     // get the index of button 
00169     for (i = 0 ; i < g_locale_installed_num ; i++)
00170     {
00171         if (strcmp(locale, g_locale_installed_tbl[i].code) == 0)
00172         {
00173             // found
00174             break;   // exit for
00175         }
00176     }
00177     
00178     if (i == g_locale_installed_num)
00179     {
00180         // not found
00181         ST_WARNPRINTF("Locale [%s] not installed.", locale);
00182     }
00183     else
00184     {
00185         // found
00186         GtkToggleButton* button = NULL;
00187         ST_LANGUAGEPRINTF("%s %s", locale, g_locale_installed_tbl[i].name);
00188         button = ergtk_selection_group_get_button((erGtkSelectionGroup*)g_select_language.selection, i);
00189         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00190         gtk_widget_grab_focus(GTK_WIDGET(button));
00191     }
00192 }

Here is the call graph for this function:

static void on_language_button_press ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  data 
) [static]

Definition at line 293 of file iLiadLanguageScreen.c.

00294 {
00295     ST_LOGPRINTF("entry");
00296     
00297     gboolean pressed;  
00298     GtkToggleButton* button;
00299 
00300     button = GTK_TOGGLE_BUTTON(data);
00301     pressed = gtk_toggle_button_get_active(button);
00302     if (!pressed)
00303     {
00304         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00305         gtk_widget_grab_focus(GTK_WIDGET(button));
00306     
00307         // show button selected, then ...
00308         g_timeout_add(500, confirm_current_item, (gpointer)TRUE);
00309     }
00310     else
00311     {
00312         confirm_current_item((gpointer)TRUE);
00313     }
00314 }

Here is the call graph for this function:

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

Definition at line 194 of file iLiadLanguageScreen.c.

00195 {
00196     ST_LOGPRINTF("entry");
00197 
00198     // free memory  
00199     if (g_locale_installed_tbl)
00200     {
00201         free_installed_locales(&g_locale_installed_tbl, g_locale_installed_num);
00202         g_locale_installed_num = 0;
00203     }
00204 
00205     // quit gtk_main
00206     gtk_main_quit();
00207 }

Here is the call graph for this function:

static gboolean on_language_expose ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  data 
) [static]

Definition at line 209 of file iLiadLanguageScreen.c.

00210 {
00211     ST_LOGPRINTF("entry");
00212     
00213     int x, y, w, h;
00214     
00215     x = event->area.x;
00216     y = event->area.y;
00217     w = event->area.width;
00218     h = event->area.height;
00219 
00220     ST_LOGPRINTF("entry, x[%d], y[%d], w[%d], h[%d]", x, y, w, h);
00221  
00222     if ((0 == x) && (0 == y) && (SCREEN_WIDTH == w) &&(SCREEN_HEIGHT == h))
00223     {
00224         display_update_request_screen_refresh(MAIN_WINDOW_EXPOSE_LEVEL, WAVEFORM_FULLSCREEN);
00225     }
00226 
00227     return FALSE;
00228 }

Here is the call graph for this function:

static gboolean on_language_key_press ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  data 
) [static]

Definition at line 230 of file iLiadLanguageScreen.c.

00231 {
00232     ST_LOGPRINTF("entry");
00233 
00234     gtkLanguage_t* language;
00235     erGtkSelectionGroup* selection;
00236     gboolean returnValue = FALSE;    // return FALSE => default gtk handling
00237 
00238     erbusy_off();
00239     
00240     language = (gtkLanguage_t*)data;
00241     g_return_val_if_fail(language != NULL, returnValue);
00242     selection = (erGtkSelectionGroup*)language->selection;
00243     g_assert(selection != NULL);
00244 
00245     switch (event->keyval)
00246     {
00247         case GDK_Up:
00248             ST_LOGPRINTF("Press UP one item key");
00249             up_one_item(selection);
00250             returnValue = TRUE;  // no further event handling
00251             break;
00252         case GDK_F4:
00253             ST_LOGPRINTF("Long press UP to the first key");
00254             up_to_first_item(selection);
00255             returnValue = TRUE;  // no further event handling
00256             break;
00257 
00258         case GDK_Down:
00259             ST_LOGPRINTF("Press DOWN one item key");
00260             down_one_item(selection);
00261             returnValue = TRUE;  // no further event handling
00262             break;
00263         case GDK_F3:
00264             ST_LOGPRINTF("Long press DOWN to the last key");
00265             down_to_last_item(selection); 
00266             returnValue = TRUE;  // no further event handling
00267             break;
00268 
00269         case GDK_Return:
00270         case GDK_F6:
00271             ST_LOGPRINTF("Press CONFIRM key");
00272             confirm_current_item((gpointer)TRUE);
00273             returnValue = TRUE;  // no further event handling
00274             break;
00275 
00276         case GDK_F5:
00277             ST_LOGPRINTF("Press TOP LEVEL key");
00278             // de-select all language keys
00279             ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection), 0, 0);
00280             // show buttons unselected, then quit without save ...
00281             g_timeout_add(500, confirm_current_item, (gpointer)FALSE);
00282 
00283             returnValue = TRUE; // no further event handling
00284             break;
00285             
00286         default:
00287             /* ignore */ 
00288             break;
00289     }
00290     return returnValue;
00291 }

Here is the call graph for this function:

static void on_language_selection_update ( erGtkSelectionGroup selection,
gpointer  button,
gpointer  data 
) [static]

Definition at line 252 of file iLiadConfigData.c.

00253 {
00254     g_assert(NULL != g_user_settings);
00255     g_assert(NULL != g_user_settings->language);
00256 
00257     ST_LOGPRINTF("entry");
00258 
00259     const gchar *theLanguage = iLiad_config_get_language();
00260 
00261     if ( strcmp(theLanguage, g_user_settings->language) != 0 )
00262     {
00263         erbusy_blink();
00264 
00265         g_free(g_user_settings->language);
00266         g_user_settings->language = strdup(theLanguage);
00267         ST_LANGUAGEPRINTF("language [%s]", g_user_settings->language);
00268 
00269         // update languages 
00270         languagesInit();
00271         bg_set_text();
00272         iLiad_startup_screen_set_text();
00273         iLiad_config_set_text();
00274         iLiad_archive_location_set_text();
00275         iLiad_user_set_text();
00276         iLiad_pincode_set_text();
00277         iLiad_pc_connect_screen_set_text();
00278         iLiad_autoconnect_set_text();
00279         iLiad_timedids_screen_set_text();
00280         iLiad_date_time_set_text();
00281         iLiad_device_overview_set_text();
00282 
00283         display_update_request_screen_refresh(SETTING_ITEM_CHANGE, WAVEFORM_FULLSCREEN);
00284     }
00285 
00286     ST_LOGPRINTF("done");
00287 }

Here is the call graph for this function:

static void up_one_item ( erGtkSelectionGroup selection  )  [static]

Definition at line 335 of file iLiadLanguageScreen.c.

00336 {
00337     gint nButtons = ergtk_selection_group_get_length(selection);
00338     if (nButtons > 0)
00339     {
00340         int currentFocus = 0, newFocus = 0;
00341         GtkToggleButton* button= NULL;
00342 
00343         ergtk_selection_group_get_selected_buttons(ERGTK_SELECTION_GROUP(selection), &currentFocus, 1);
00344         if ((currentFocus < 0) || (currentFocus >= g_locale_installed_num))
00345         {
00346             newFocus = 0;
00347         }
00348         else if (currentFocus == 0)
00349         {
00350             newFocus = nButtons - 1;
00351         }
00352         else
00353         {
00354             newFocus = currentFocus - 1;
00355         }
00356         
00357         button = ergtk_selection_group_get_button(selection, newFocus);
00358         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00359         gtk_widget_grab_focus(GTK_WIDGET(button));
00360     }   
00361 }

Here is the call graph for this function:

static void up_to_first_item ( erGtkSelectionGroup selection  )  [static]

Definition at line 363 of file iLiadLanguageScreen.c.

00364 {
00365     gint nButtons = ergtk_selection_group_get_length(selection);
00366     if (nButtons > 0)
00367     {
00368         GtkToggleButton* button= NULL;
00369         button = ergtk_selection_group_get_button(selection, 0);
00370         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
00371         gtk_widget_grab_focus(GTK_WIDGET(button));
00372     } 
00373 }

Here is the call graph for this function:


Variable Documentation

guint g_locale_installed_num = 0 [static]

Definition at line 49 of file iLiadLanguageScreen.c.

Definition at line 48 of file iLiadLanguageScreen.c.

Definition at line 51 of file iLiadLanguageScreen.c.


Generated on Sun Dec 14 17:17:13 2008 by  doxygen 1.5.6