settings/src/iLiadDateTimeScreen.c File Reference

settings - iLiad date time screen More...

#include <time.h>
#include <unistd.h>
#include "iLiadDateTimeScreen.h"
#include <libergtk/ergtk.h>
#include "gtkInfoItem.h"
#include "setupLog.h"
#include "gtkSettingItem.h"
#include "background.h"
#include "languages.h"

Go to the source code of this file.

Functions

static GtkWidget * create_current_time_display (void)
static GtkWidget * create_timezone_selection (void)
static void iLiad_update_datetime (int tzoffset)
static int get_current_tz_offset ()
static gboolean set_tz_offset (const char *tzfile)
static void on_selection_update (erGtkSelectionGroup *selection, gpointer button, gpointer data)
GtkWidget * iLiad_date_time_create ()
void iLiad_date_time_set_text (void)
void iLiad_date_time_display_data (void)
void iLiad_date_time_handle_refresh (void)

Variables

static gtk_datetime_screeng_datetime_screen = NULL
static const tz_info timezones [TOTAL_TIMEZONES]
static time_t g_utc_time = 0
static int g_date_boundary = 0
static int g_current_tz_offset = -1


Detailed Description

settings - iLiad date time screen

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

User interface for user to set iLiad date and time

Definition in file iLiadDateTimeScreen.c.


Function Documentation

GtkWidget * create_current_time_display ( void   )  [static]

Definition at line 141 of file iLiadDateTimeScreen.c.

00142 {
00143     GtkWidget* settingitem;
00144     GtkWidget* background;
00145     GtkWidget* alignment;
00146     GtkWidget* vbox;
00147     GtkWidget* label;
00148 
00149     // settingitem
00150     settingitem = gtk_settingitem_new("");
00151     gtk_widget_set_size_request(settingitem, -1, -1);
00152 
00153     // background
00154     background = gtk_event_box_new();
00155     gtk_widget_set_name(background, "datetime_display_background");
00156     gtk_widget_set_size_request(background, TITLE_MIN_WIDTH, DATETIME_DISPLAY_HEIGHT);
00157     gtk_settingitem_add_details(GTK_SETTINGITEM(settingitem), background);
00158 
00159     // alignment
00160     alignment = gtk_alignment_new(0, 0, 0, 0);
00161     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00162                               DATETIME_SCREEN_ITEM_PADDING_TOP,
00163                               DATETIME_SCREEN_ITEM_PADDING_BOTTOM,
00164                               DATETIME_SCREEN_ITEM_PADDING_LEFT,
00165                               DATETIME_SCREEN_ITEM_PADDING_RIGHT);
00166     gtk_container_add(GTK_CONTAINER(background), alignment);
00167 
00168     // vbox
00169     vbox = gtk_vbox_new(FALSE, DATETIME_DISPLAY_SPACING);
00170     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00171 
00172     label = gtk_label_new("");
00173     gtk_widget_set_name(label, "datetime_screen_info_text");
00174     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00175     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00176     g_datetime_screen->label_show_time_prompt = label;
00177 
00178     label = gtk_label_new("");
00179     gtk_widget_set_name(label, "datetime_screen_date_text");
00180     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00181     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00182     g_datetime_screen->label_current_time = label;
00183     
00184     gtk_widget_show_all(background);
00185     gtk_widget_show(settingitem);
00186     return settingitem;
00187 }

Here is the call graph for this function:

GtkWidget * create_timezone_selection ( void   )  [static]

Definition at line 210 of file iLiadDateTimeScreen.c.

00211 {
00212     GtkWidget* background;
00213     GtkWidget* alignment;
00214     GtkWidget* vbox;
00215     GtkWidget* label;
00216     GtkWidget* button;
00217 
00218     // background
00219     background = gtk_event_box_new();
00220     gtk_widget_set_name(background, "timezone_selection_background");
00221     gtk_widget_set_size_request(background, TITLE_MIN_WIDTH, TIMEZONE_SELECTION_HEIGHT);
00222 
00223     // alignment
00224     alignment = gtk_alignment_new(0, 0, 0, 0);
00225     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00226                               DATETIME_SCREEN_ITEM_PADDING_TOP,
00227                               DATETIME_SCREEN_ITEM_PADDING_BOTTOM,
00228                               DATETIME_SCREEN_ITEM_PADDING_LEFT,
00229                               DATETIME_SCREEN_ITEM_PADDING_RIGHT);
00230     gtk_container_add(GTK_CONTAINER(background), alignment);
00231 
00232     // vbox
00233     vbox = gtk_vbox_new(FALSE, DATETIME_SCREEN_ITEM_SPACING);
00234     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00235     
00236     label = gtk_label_new("");
00237     gtk_widget_set_name(label, "datetime_screen_info_text");
00238     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00239     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00240     g_datetime_screen->label_timezone_prompt = label;
00241 
00242     g_utc_time = time(NULL);
00243     
00244     // divide the buttons into 2 parts, determine the boundary first
00245     int i;
00246     for (i=0; i<TOTAL_TIMEZONES; i++)
00247     {
00248         if ((g_utc_time+timezones[i].tzoffset) / 86400 > (g_utc_time+timezones[0].tzoffset) / 86400)
00249         {
00250             g_date_boundary = i;
00251             break;
00252         }
00253     }
00254     
00255     // draw the first possible date label
00256     label = gtk_label_new("");
00257     gtk_widget_set_name(label, "datetime_date_heading_text");
00258     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00259     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00260     g_datetime_screen->label_possible_date[0] = label;
00261 
00262     // draw the rest part
00263     int minutes_in_tz;
00264     char button_text[8];
00265     GtkWidget* hbox = NULL;
00266     for (i=0; i<TOTAL_TIMEZONES; i++)
00267     {
00268         if (i == g_date_boundary)
00269         {
00270             // draw the second possible date label
00271             label = gtk_label_new("");
00272             gtk_widget_set_name(label, "datetime_date_heading_text");
00273             gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00274             gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00275             g_datetime_screen->label_possible_date[1] = label;
00276         }
00277         
00278         if ((i<g_date_boundary && i%5 == 0) ||
00279             (i>=g_date_boundary && (i-g_date_boundary)%5 == 0))
00280         {
00281             // we should create a new hbox, for we have a new line of buttons
00282             hbox = gtk_hbox_new(FALSE, TIMEZONE_BUTTON_ITEM_SPACING);
00283             gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), FALSE, FALSE, 0);
00284         }
00285         
00286         minutes_in_tz = ((g_utc_time + timezones[i].tzoffset) % 86400) / 60;
00287         sprintf(button_text, "%02d:%02d", minutes_in_tz / 60, minutes_in_tz % 60);
00288 
00289         button = ergtk_toggle_button_new_with_label(button_text);
00290         gtk_widget_set_size_request(GTK_WIDGET(button), TZ_BUTTON_WIDTH, TZ_BUTTON_HEIGHT);
00291         gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(button), FALSE, FALSE, 0);
00292         g_datetime_screen->button_timezones[i] = GTK_TOGGLE_BUTTON(button);
00293     }
00294 
00295     g_datetime_screen->button_timezones[TOTAL_TIMEZONES] = NULL;
00296 
00297     gtk_widget_show_all(background);
00298     return background;
00299 }

Here is the call graph for this function:

static int get_current_tz_offset (  )  [static]

Definition at line 477 of file iLiadDateTimeScreen.c.

00478 {
00479     FILE* fp = fopen(TZ_FILE, "rb");
00480 
00481     if (NULL == fp)
00482     {
00483         ST_ERRORPRINTF("Can't open %s, use default timezone settings.", TZ_FILE);
00484         goto error;
00485     }
00486 
00487     fseek(fp, sizeof(struct tzhead), SEEK_SET);
00488     
00489     int offset;
00490     if (fread(&offset, sizeof(int), 1, fp) != 1)
00491     {
00492         ST_ERRORPRINTF("Error reading %s, use default timezone settings.", TZ_FILE);
00493         fclose(fp);
00494         goto error;
00495     }
00496     
00497     fclose(fp);
00498 
00499     return GINT32_FROM_BE(offset);
00500 
00501 error:
00502     set_tz_offset(DEFAULT_TIMEZONE_NAME);
00503     return DEFAULT_TIMEZONE_OFFSET;
00504 }

Here is the call graph for this function:

GtkWidget* iLiad_date_time_create (  ) 

Definition at line 97 of file iLiadDateTimeScreen.c.

00098 {
00099     GtkWidget* vbox;
00100     GtkWidget* settingitem;
00101     GtkWidget* background;
00102     GtkWidget* info;
00103     GtkWidget* selection;
00104 
00105     ST_LOGPRINTF("entry");
00106     g_datetime_screen = g_new0(gtk_datetime_screen, 1);
00107 
00108     vbox = gtk_vbox_new(FALSE, DATETIME_SCREEN_ITEM_SPACING);
00109     g_datetime_screen->top_vbox = vbox;
00110     
00111     settingitem = create_current_time_display();
00112     gtk_box_pack_start(GTK_BOX(vbox), settingitem, FALSE, FALSE, 0);
00113     g_datetime_screen->settingitem = settingitem;
00114 
00115     background = create_timezone_selection();
00116     gtk_box_pack_start(GTK_BOX(vbox), background, FALSE, FALSE, 0);
00117     g_datetime_screen->timezones = background;
00118 
00119     // selection group not part of widget hierarchy
00120     selection = ergtk_selection_group_new(g_datetime_screen->button_timezones);
00121     ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection), 1, 1);
00122     g_signal_connect(G_OBJECT(selection), "selection-update", G_CALLBACK(on_selection_update), NULL);
00123     g_datetime_screen->selection = selection;
00124  
00125     info = gtk_infoitem_new(FALSE);
00126     gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
00127     g_datetime_screen->infoitem = info;
00128 
00129     // Show widgets
00130     gtk_widget_show(vbox);
00131     return vbox;
00132 }

Here is the call graph for this function:

void iLiad_date_time_display_data ( void   ) 

Definition at line 347 of file iLiadDateTimeScreen.c.

00348 {
00349     int i = 0;
00350     
00351     ST_LOGPRINTF("entry");
00352 
00353     g_current_tz_offset = get_current_tz_offset();
00354 
00355     for (i=0; i<TOTAL_TIMEZONES; i++)
00356     {
00357         if (timezones[i].tzoffset == g_current_tz_offset)
00358         {
00359             break;
00360         }
00361     }
00362 
00363     GtkToggleButton* button_to_be_active = g_datetime_screen->button_timezones[i];
00364     gtk_toggle_button_set_active(button_to_be_active, TRUE);
00365 }

Here is the call graph for this function:

void iLiad_date_time_handle_refresh ( void   ) 

Definition at line 367 of file iLiadDateTimeScreen.c.

00368 {
00369     GtkWidget* background;
00370     GtkWidget* info;
00371     GtkWidget* selection;
00372     GtkWidget* vbox = g_datetime_screen->top_vbox;
00373 
00374     ST_LOGPRINTF("entry");
00375 
00376     if (g_datetime_screen->timezones)
00377     {
00378         gtk_widget_destroy(g_datetime_screen->timezones);
00379         g_datetime_screen->timezones = NULL;
00380     }
00381 
00382     if (g_datetime_screen->selection)
00383     {
00384         gtk_object_destroy(GTK_OBJECT(g_datetime_screen->selection));
00385         g_datetime_screen->selection = NULL;
00386     }
00387 
00388     if (g_datetime_screen->infoitem)
00389     {
00390         gtk_widget_destroy(g_datetime_screen->infoitem);
00391         g_datetime_screen->infoitem = NULL;
00392     }
00393 
00394     background = create_timezone_selection();
00395     gtk_box_pack_start(GTK_BOX(vbox), background, FALSE, FALSE, 0);
00396     g_datetime_screen->timezones = background;
00397 
00398     // selection group not part of widget hierarchy
00399     selection = ergtk_selection_group_new(g_datetime_screen->button_timezones);
00400     ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection), 1, 1);
00401     g_signal_connect(G_OBJECT(selection), "selection-update", G_CALLBACK(on_selection_update), NULL);
00402     g_datetime_screen->selection = selection;
00403 
00404     info = gtk_infoitem_new(FALSE);
00405     gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
00406     g_datetime_screen->infoitem = info;
00407 
00408     // Refresh the text displayed on the widget
00409     g_current_tz_offset = -1;
00410     iLiad_date_time_set_text();
00411 
00412     // Set the selected button and update current time
00413     iLiad_date_time_display_data();
00414 }

Here is the call graph for this function:

void iLiad_date_time_set_text ( void   ) 

Definition at line 301 of file iLiadDateTimeScreen.c.

00302 {
00303     ST_LOGPRINTF("entry");
00304     if (g_datetime_screen->settingitem)
00305     {
00306         gtk_settingitem_set_header_text(GTK_SETTINGITEM(g_datetime_screen->settingitem),
00307                 _("Time Selection"));
00308         
00309         gtk_label_set_text(GTK_LABEL(g_datetime_screen->label_show_time_prompt),
00310                 _("The current time and date on your iLiad is:"));
00311 
00312         if (g_current_tz_offset != -1)
00313         {
00314             iLiad_update_datetime(g_current_tz_offset);
00315         }
00316     }
00317 
00318     if (g_datetime_screen->timezones)
00319     {
00320         gtk_label_set_text(GTK_LABEL(g_datetime_screen->label_timezone_prompt),
00321                 _("To change the clock, select your current date and time from the list below."));
00322 
00323         // set label text for the first possible date
00324         time_t tm = g_utc_time + timezones[0].tzoffset;
00325         char buf[DATE_STRING_LENGTH];
00326         /* TRANSLATORS: This is a date and time format specifier, according to the strftime(3) man page.
00327            The corresponding string should be something like Monday, July 30 2007. */
00328         // xgettext:no-c-format
00329         strftime(buf, DATE_STRING_LENGTH, _("%A, %x"), gmtime(&tm));  // xgettext:no-c-format
00330         gtk_label_set_text(GTK_LABEL(g_datetime_screen->label_possible_date[0]), buf);
00331 
00332         // set label text for the second possible date
00333         tm = g_utc_time + timezones[g_date_boundary].tzoffset;
00334         // xgettext:no-c-format
00335         strftime(buf, DATE_STRING_LENGTH, _("%A, %x"), gmtime(&tm));  // xgettext:no-c-format
00336         gtk_label_set_text(GTK_LABEL(g_datetime_screen->label_possible_date[1]), buf);
00337     }
00338 
00339     if (g_datetime_screen->infoitem)
00340     {
00341         // set help text
00342         gtk_infoitem_set_text(GTK_INFOITEM(g_datetime_screen->infoitem),
00343                 _("You can set your date and time by connecting to iDS. Afterwards you can use this page to update the time for your current timezone."));
00344     }
00345 }

Here is the call graph for this function:

void iLiad_update_datetime ( int  tzoffset  )  [static]

Definition at line 462 of file iLiadDateTimeScreen.c.

00463 {
00464     if (g_datetime_screen)
00465     {
00466         char buf[DATE_STRING_LENGTH];
00467         time_t tm_local = g_utc_time + tzoffset;
00468         /* TRANSLATORS: This is a date and time format specifier, according to the strftime(3) man page.
00469            The corresponding string should be something like 13:23 Monday, July 30 2007.
00470            Keep %R unchanged. */
00471         // xgettext:no-c-format
00472         strftime(buf, DATE_STRING_LENGTH, _("%R %A, %x"), gmtime(&tm_local));  // xgettext:no-c-format
00473         gtk_label_set_text(GTK_LABEL(g_datetime_screen->label_current_time), buf);
00474     }
00475 }

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

Definition at line 416 of file iLiadDateTimeScreen.c.

00417 {
00418     int index = 0;
00419 
00420     ST_LOGPRINTF("entry");
00421     ergtk_selection_group_get_selected_buttons(ERGTK_SELECTION_GROUP(selection), &index, 1);
00422 
00423     int tzoffset = timezones[index].tzoffset;
00424     
00425     // Update current timezone offset settings
00426     if (g_current_tz_offset != tzoffset)
00427     {
00428         g_current_tz_offset = tzoffset;
00429         
00430         // Update symbol link /mnt/settings/timezone
00431         // re-direct to the correct timezone file
00432         set_tz_offset(timezones[index].tzname);
00433     }
00434 
00435     // Update current date time displayed in the screen
00436     iLiad_update_datetime(g_current_tz_offset);
00437 }

Here is the call graph for this function:

gboolean set_tz_offset ( const char *  tzfile  )  [static]

Definition at line 439 of file iLiadDateTimeScreen.c.

00440 {
00441     char actual_tzfile[256];
00442     
00443     snprintf(actual_tzfile, 256, "%s%s", TZ_FILES_DIR, tzfile);
00444     if (access(TZ_SETTING_FILE, F_OK) == 0)
00445     {
00446         if (unlink(TZ_SETTING_FILE) != 0)
00447         {
00448             ST_ERRORPRINTF("Can't remove %s", TZ_SETTING_FILE);
00449             return FALSE;
00450         }
00451     }
00452    
00453     if (symlink(actual_tzfile, TZ_SETTING_FILE) != 0)
00454     {
00455         ST_ERRORPRINTF("Can't create symbol link from %s to %s", actual_tzfile, TZ_SETTING_FILE);
00456         return FALSE;
00457     }
00458 
00459     return TRUE;
00460 }


Variable Documentation

int g_current_tz_offset = -1 [static]

Definition at line 83 of file iLiadDateTimeScreen.c.

int g_date_boundary = 0 [static]

Definition at line 82 of file iLiadDateTimeScreen.c.

Definition at line 42 of file iLiadDateTimeScreen.c.

time_t g_utc_time = 0 [static]

Definition at line 81 of file iLiadDateTimeScreen.c.

const tz_info timezones[TOTAL_TIMEZONES] [static]

Definition at line 43 of file iLiadDateTimeScreen.c.


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