datetime.c

Go to the documentation of this file.
00001 /*
00002  * File Name: datetime.c
00003  */
00004 
00005 /*
00006  * This file is part of settings.
00007  *
00008  * settings is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * settings is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 // system include files, between < >
00032 #include <gtk/gtk.h>
00033 #include <gdk/gdk.h>
00034 #include <glib.h>
00035 #include <gdk/gdkkeysyms.h>
00036 
00037 #include <libergtk/ergtk.h>
00038 
00039 #include "i18n.h"
00040 #include "log.h"
00041 #include "settings.h"
00042 #include "settings_utils.h"
00043 #include "settings_style.h"
00044 #include "datetime_base.h"
00045 #include "datetime.h"
00046 
00047 //----------------------------------------------------------------------------
00048 // Static Variables
00049 //----------------------------------------------------------------------------
00050 static DateTimeSettings g_settings;
00051 static DateTimeWidgets  g_widgets;
00052 
00053 static GtkWidget* g_list_view           = NULL;
00054 static GtkWidget* g_top_window          = NULL;
00055 
00056 //============================================================================
00057 // Local Function Definitions
00058 //============================================================================
00059 static void locale_changed (void);
00060 
00061 // Signal handlers.
00062 static gboolean on_button_focus_in(GtkWidget* widget, 
00063                                    GdkEventFocus* event, 
00064                                    gpointer data);
00065 
00066 //============================================================================
00067 // Functions Implementation
00068 //============================================================================
00069 void load_datetime_settings()
00070 {
00071     LOGPRINTF("entry");
00072 
00073     datetime_base_load_datetime(&g_settings);
00074 }
00075 
00076 void save_datetime_settings()
00077 {
00078     LOGPRINTF("entry");
00079 
00080     if ( ! datetime_base_save_datetime(&g_widgets, &g_settings) )
00081     {
00082         LOGPRINTF("save datetime failed.");
00083         /* Create a messagebox. */
00084         GtkWidget *dialog = gtk_message_dialog_new(
00085                 GTK_WINDOW(g_top_window), 
00086                 GTK_DIALOG_MODAL,
00087                 GTK_MESSAGE_WARNING, 
00088                 GTK_BUTTONS_OK,
00089                 _("The date was not saved.") );
00090 
00091         gtk_dialog_run(GTK_DIALOG(dialog));
00092         gtk_widget_destroy(dialog);
00093     }
00094 }
00095 
00096 // Widget Hierarchy
00097 // |--top_window
00098 //    |--vboxtop
00099 //       |--title bar
00100 //       |--back area
00101 //       |--time
00102 //       |--date
00103 GtkWidget* create_datetime_window(GtkWidget* parent)
00104 {
00105     LOGPRINTF("entry");
00106     // create top window
00107     g_top_window = parent;
00108     gtk_window_maximize(GTK_WINDOW(parent));
00109     gtk_window_set_resizable(GTK_WINDOW(parent), FALSE);
00110     gtk_container_set_border_width(GTK_CONTAINER(parent),WINDOW_BORDER_PADDING  );
00111     gtk_window_set_modal(GTK_WINDOW(parent), TRUE);
00112 
00113     // top level vbox (vboxtop)
00114     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00115     gtk_container_add(GTK_CONTAINER(parent), vboxtop);
00116 
00117     // add header container the title and subtitle of this settings page
00118     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Time & Date"));
00119     
00120     // add the back/exit bar below the title 
00121     g_list_view = create_settingsview_for_type( SETTING_DATETIME );
00122     gtk_box_pack_start(GTK_BOX(vboxtop), g_list_view, FALSE, FALSE, 0); 
00123 
00124     // Time and date.
00125     datetime_base_create_widgets(&g_widgets, &g_settings);
00126     g_signal_connect(G_OBJECT(g_widgets.hidden_button),
00127                     "focus-in-event",
00128                     G_CALLBACK(on_button_focus_in),
00129                     (gpointer) NULL );
00130     gtk_box_pack_start(GTK_BOX(vboxtop), g_widgets.parent, FALSE, FALSE, 0);
00131 
00132     // Set the text.
00133     locale_changed();
00134 
00135     gtk_widget_grab_focus(g_list_view);
00136 
00137     gtk_widget_show_all(parent);
00138 
00139     return parent;
00140 }
00141 
00142 void datetime_set_main_focus(void)
00143 {
00144     gtk_widget_grab_focus(GTK_WIDGET(g_widgets.timezone_button));
00145 }
00146 
00147 void datetime_set_orientation(gboolean is_portrait )
00148 {
00149     LOGPRINTF("entry");
00150     g_widgets.is_portrait = is_portrait;
00151 }
00152 
00153 //============================================================================
00154 // Local Functions Implementation
00155 //============================================================================
00156 
00157 static void locale_changed()
00158 {
00159     LOGPRINTF("entry");
00160 
00161     // Timezone section.
00162     gtk_label_set_label(GTK_LABEL(g_widgets.label_timezone), _("Time Zone"));
00163     gtk_label_set_label(GTK_LABEL(g_widgets.label_timezone_desc),
00164             _("Tap on the up or down arrow to scroll through the time zones. "
00165               "Setting this to the area where you reside is essential for "
00166               "purchased content to work correctly."));
00167     gtk_label_set_label(GTK_LABEL(g_widgets.label_dst_desc),
00168             _("Check the box below if daylight saving time (DST) is currently "
00169               "in effect in your location."));
00170     
00171     // Time section.
00172     gtk_label_set_label(GTK_LABEL(g_widgets.label_time), _("Time"));
00173     gtk_label_set_label(GTK_LABEL(g_widgets.label_time_desc),
00174             _("Tap on the up or down arrow to scroll through the numbers."));
00175   
00176     // Date section.
00177     gtk_label_set_label(GTK_LABEL(g_widgets.label_date), _("Date"));
00178     gtk_label_set_label(GTK_LABEL(g_widgets.label_date_desc),
00179             _("Tap on the up or down arrow to scroll through the numbers."));
00180 
00181     datetime_base_locale_changed(&g_widgets, &g_settings);
00182 }
00183 
00184 static gboolean change_focus(gpointer data)
00185 {
00186     gtk_widget_grab_focus(GTK_WIDGET(data));
00187     return FALSE; // once
00188 }
00189 
00190 static gboolean on_button_focus_in(GtkWidget* widget,  
00191                                    GdkEventFocus* event, 
00192                                    gpointer data)
00193 {
00194     // timeout is needed, otherwise the year spin button does not 
00195     // update its cursor on focus out
00196     g_timeout_add(200, change_focus, (gpointer)g_list_view);
00197     return FALSE;
00198 }
00199 
Generated by  doxygen 1.6.2-20100208