fdatetime.c

Go to the documentation of this file.
00001 /*
00002  * File Name: fdatetime.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 "fdatetime.h"
00046 
00047 //----------------------------------------------------------------------------
00048 // Static Variables
00049 //----------------------------------------------------------------------------
00050 static DateTimeSettings g_settings;
00051 static DateTimeWidgets  g_widgets;
00052 
00053 static GtkWidget* g_top_window;
00054 
00055 // Widgets related to continue
00056 static GtkWidget* g_label_continue       = NULL;
00057 static GtkWidget* g_label_continue_desc  = NULL;
00058 static GtkWidget* g_continue_button      = NULL;
00059 static GtkWidget* g_hidden_button        = NULL;
00060 
00061 static const GdkColor white = {0, 0xFF00, 0xFF00, 0xFF00};
00062 
00063 //============================================================================
00064 // Local Function Definitions
00065 //============================================================================
00066 
00067 // Functions of creating widgets.
00068 static void create_continue_widget(GtkVBox* vbox);
00069 static void locale_changed(void);
00070 
00071 // Signal handlers.
00072 
00073 static gboolean on_continue_button_clicked(GtkWidget* widget, gpointer data);
00074 static gboolean on_button_focus_in(GtkWidget* widget, 
00075                                           GdkEventFocus* event, 
00076                                           gpointer data);
00077 
00078 //============================================================================
00079 // Functions Implementation
00080 //============================================================================
00081 void load_fdatetime_settings()
00082 {
00083     LOGPRINTF("entry");
00084 
00085     datetime_base_load_datetime(&g_settings);
00086 }
00087 
00088 
00089 gboolean save_fdatetime_settings()
00090 {
00091     LOGPRINTF("entry");
00092     gboolean ret = TRUE;
00093 
00094     if ( ! datetime_base_save_datetime(&g_widgets, &g_settings) )
00095     {
00096         LOGPRINTF("save datetime failed.");
00097         ret = FALSE;
00098 
00099         /* Create a messagebox. */
00100         GtkWidget *dialog = gtk_message_dialog_new(
00101                 GTK_WINDOW(g_top_window),
00102                 GTK_DIALOG_MODAL,
00103                 GTK_MESSAGE_WARNING,
00104                 GTK_BUTTONS_OK,
00105                 _("The date was not saved.") );
00106 
00107         gtk_dialog_run(GTK_DIALOG(dialog));
00108         gtk_widget_destroy(dialog);
00109 
00110     }
00111     return ret;
00112 }
00113 
00114 
00115 // Widget Hierarchy
00116 // |--top_window
00117 //    |--vboxtop
00118 //       |--title bar
00119 //       |--time
00120 //       |--date
00121 GtkWidget* create_fdatetime_window(GtkWidget* parent)
00122 {
00123     // create top window
00124     g_top_window = parent;
00125     gtk_window_fullscreen(GTK_WINDOW(parent));
00126     gtk_window_set_resizable(GTK_WINDOW(parent), FALSE);
00127     gtk_container_set_border_width(GTK_CONTAINER(parent),WINDOW_BORDER_PADDING  );
00128     gtk_window_set_modal(GTK_WINDOW(parent), TRUE);
00129 
00130     // top level vbox (vboxtop)
00131     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 0);
00132     gtk_container_add(GTK_CONTAINER(parent), vboxtop);
00133 
00134     // add header container the title and subtitle of this settings page
00135     create_title(GTK_VBOX(vboxtop), _("Setup"), _("Time & Date"));
00136      
00137     // Time and date.
00138     datetime_base_create_widgets(&g_widgets, &g_settings);
00139     g_signal_connect(G_OBJECT(g_widgets.hidden_button),
00140                     "focus-in-event",
00141                     G_CALLBACK(on_button_focus_in),
00142                     (gpointer)NULL);
00143     gtk_box_pack_start(GTK_BOX(vboxtop), g_widgets.parent, FALSE, FALSE, 0);
00144 
00145     // save button and continue
00146     create_continue_widget(GTK_VBOX(vboxtop));
00147 
00148     // Set the text.
00149     locale_changed();
00150 
00151     gtk_widget_grab_focus(g_widgets.timezone_button);
00152 
00153     gtk_widget_show_all(parent);
00154 
00155     return parent;
00156 }
00157 
00158 void fdatetime_set_orientation(gboolean is_portrait )
00159 {
00160     g_widgets.is_portrait = is_portrait;
00161 }
00162 
00163 //============================================================================
00164 // Local Functions Implementation
00165 //============================================================================
00166 
00167 static void create_continue_widget(GtkVBox* parent)
00168 {
00169     GtkVBox* frame = create_frame(parent);
00170 
00171     // The label "Continue"
00172     g_label_continue = gtk_label_new(NULL);
00173     gtk_widget_set_name(g_label_continue, "irex-section-title");
00174     gtk_widget_set_size_request(g_label_continue, -1, -1);
00175     gtk_misc_set_alignment(GTK_MISC(g_label_continue), 0.0, 0.0);
00176     gtk_box_pack_start(GTK_BOX(frame), g_label_continue, FALSE, FALSE, 0);
00177 
00178     // The label "description".
00179     g_label_continue_desc = description_create();
00180     gtk_box_pack_start(GTK_BOX(frame), g_label_continue_desc, FALSE, FALSE, 0);
00181 
00182     // create button box
00183     GtkWidget* button_box = gtk_hbutton_box_new();
00184     gtk_box_pack_start(GTK_BOX(frame), button_box, FALSE, FALSE, 9);
00185     gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
00186     gtk_box_set_spacing(GTK_BOX(button_box), SMALL_SPACING);
00187     
00188     g_continue_button = gtk_button_new();
00189     gtk_box_pack_start(GTK_BOX(button_box), g_continue_button, FALSE, FALSE, 0);
00190     // Add signal handler.
00191     g_signal_connect(G_OBJECT(g_continue_button),
00192             "clicked",
00193             G_CALLBACK(on_continue_button_clicked ),
00194             (gpointer) NULL );
00195 
00196     g_hidden_button = gtk_button_new();
00197     gtk_box_pack_start(GTK_BOX(button_box), g_hidden_button, FALSE, FALSE, 0);
00198     // Add signal handler.
00199     g_object_set(G_OBJECT(g_hidden_button), "focus-on-click", FALSE, NULL);
00200     g_signal_connect(G_OBJECT(g_hidden_button),
00201             "focus-in-event",
00202             G_CALLBACK(on_button_focus_in ),
00203             (gpointer) NULL );
00204 
00205     gtk_widget_modify_fg(g_hidden_button, GTK_STATE_NORMAL, &white);
00206     gtk_widget_modify_fg(g_hidden_button, GTK_STATE_ACTIVE, &white);
00207     gtk_widget_modify_fg(g_hidden_button, GTK_STATE_SELECTED, &white);
00208 }
00209 
00210 static void locale_changed(void)
00211 {
00212     // Timezone section.
00213     gtk_label_set_label(GTK_LABEL(g_widgets.label_timezone), _("Time Zone"));
00214     gtk_label_set_label(GTK_LABEL(g_widgets.label_timezone_desc),
00215             _("Tap on the up or down arrow to scroll through the time zones. "
00216               "Setting this to the area where you reside is essential for "
00217               "purchased content to work correctly."));
00218     gtk_label_set_label(GTK_LABEL(g_widgets.label_dst_desc),
00219             _("Check the box below if daylight saving time (DST) is currently "
00220               "in effect in your location."));
00221 
00222     // Time section.
00223     gtk_label_set_label(GTK_LABEL(g_widgets.label_time), _("Time"));
00224     gtk_label_set_label(GTK_LABEL(g_widgets.label_time_desc),
00225             _("Tap on the up or down arrow to scroll through the numbers."));
00226     
00227     // Date section.
00228     gtk_label_set_label(GTK_LABEL(g_widgets.label_date), _("Date"));
00229     gtk_label_set_label(GTK_LABEL(g_widgets.label_date_desc),
00230             _("Tap on the up or down arrow to scroll through the numbers."));
00231 
00232     // Continue section
00233     gtk_label_set_label(GTK_LABEL(g_label_continue), _("Save & Continue"));
00234     gtk_label_set_label(GTK_LABEL(g_label_continue_desc),
00235             _("Continue to save the changes and start using the device."));
00236     gtk_button_set_label(GTK_BUTTON(g_continue_button),  _("Save") );
00237 
00238     datetime_base_locale_changed(&g_widgets, &g_settings);
00239 }
00240 
00241 static gboolean on_continue_button_clicked(GtkWidget* widget, gpointer data)
00242 {
00243     if ( TRUE == save_fdatetime_settings() )
00244     {
00245         // quit if valid date entered.
00246         // but stay if invalid date is entered
00247         main_quit(); 
00248     }
00249     return FALSE;
00250 }
00251 
00252 static gboolean on_button_focus_in(GtkWidget * widget, 
00253                                    GdkEventFocus * event, 
00254                                    gpointer data)
00255 {
00256     if (widget == g_widgets.hidden_button)
00257     {
00258         gtk_widget_grab_focus(g_continue_button);
00259     }
00260     else if (widget == g_hidden_button)
00261     {
00262         gtk_widget_grab_focus(g_widgets.timezone_button);
00263     }
00264     return FALSE;
00265 }
00266 
Generated by  doxygen 1.6.2-20100208