00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <unistd.h>
00032 #include <stdio.h>
00033
00034 #include <gtk/gtk.h>
00035 #include <gdk/gdk.h>
00036 #include <glib.h>
00037
00038 #include <libergtk/ergtk.h>
00039
00040 #include "i18n.h"
00041 #include "log.h"
00042 #include "ipc.h"
00043 #include "settings.h"
00044 #include "settings_utils.h"
00045 #include "settings_style.h"
00046
00047 #include "device_info.h"
00048 #include "irex-account.h"
00049 #include "sd_capacity.h"
00050 #include "margins.h"
00051 #include "flipbar.h"
00052 #include "stylus.h"
00053 #include "flightmode.h"
00054 #include "reset.h"
00055 #include "datetime.h"
00056 #include "fdatetime.h"
00057 #include "languages.h"
00058 #include "power.h"
00059 #include "rotation.h"
00060 #include "sensors.h"
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 static const int SETTINGS_STYLE_TITLE_HEIGHT = 44;
00073 static const int SETTINGS_STYLE_TITLE_V_PADDING = 10;
00074 static const int SETTINGS_STYLE_TITLE_SPACING = 20;
00075
00076 static const GdkColor grey = { 0, 0x5500, 0x5500, 0x5500 };
00077
00078
00079
00080
00081 static GtkListStore* g_settings_filestore = NULL;
00082
00083
00084
00085 static void label_on_size_allocate( GtkWidget* label, GtkAllocation* allocation, gpointer data );
00086 static gboolean on_focus_in(GtkWidget* widget, gpointer data );
00087 static gboolean on_focus_out(GtkWidget* widget, gpointer data );
00088 static void on_listview_row_activated ( GtkTreeView *view,
00089 GtkTreePath *path,
00090 GtkTreeViewColumn *column,
00091 gpointer user_data );
00092 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00093 erGtkListViewKeyPress keycode,
00094 gpointer user_data );
00095 static void setting_set_focus(SettingType setting);
00096
00097
00098
00099
00100 GtkVBox * create_frame(GtkVBox* vbox)
00101 {
00102
00103 GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00104 gtk_box_pack_start(GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
00105
00106
00107 GtkWidget* frame = gtk_frame_new(NULL);
00108 gtk_widget_set_name(frame, "irex-margins-frame");
00109 gtk_container_add(GTK_CONTAINER(alignment), frame);
00110 gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00111
00112
00113 GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
00114 gtk_container_add(GTK_CONTAINER(frame), alignment2);
00115 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2),
00116 WINDOW_TOP_ALT_PADDING,
00117 WINDOW_BOTTOM_PADDING,
00118 WINDOW_H_PADDING,
00119 WINDOW_H_PADDING);
00120
00121
00122 GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00123 gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00124
00125 return GTK_VBOX(innervbox);
00126 }
00127
00128 void create_title(GtkVBox* parent, gchar* title, gchar* subtitle)
00129 {
00130 return create_title_keep_labels(parent, title, subtitle, NULL, NULL);
00131 }
00132
00133 void create_title_keep_labels(GtkVBox* parent, gchar* title, gchar* subtitle, GtkWidget** title_label, GtkWidget** subtitle_label)
00134 {
00135 GtkWidget* widget = gtk_hbox_new(FALSE, SETTINGS_STYLE_TITLE_SPACING);
00136 gtk_box_pack_start(GTK_BOX(parent), widget, FALSE, FALSE, SETTINGS_STYLE_TITLE_V_PADDING);
00137 gtk_widget_set_size_request(widget, -1, SETTINGS_STYLE_TITLE_HEIGHT);
00138 GtkBox *titlehbox = GTK_BOX(widget);
00139
00140 GtkWidget* label1 = gtk_label_new(title);
00141 gtk_label_set_ellipsize(GTK_LABEL(label1), PANGO_ELLIPSIZE_NONE);
00142 gtk_widget_set_name(label1, "irex-settings-title");
00143 gtk_box_pack_start(titlehbox, label1, FALSE, FALSE, 0);
00144 gtk_widget_show(label1);
00145
00146 GtkWidget* label2 = gtk_label_new("-");
00147 gtk_label_set_ellipsize(GTK_LABEL(label2), PANGO_ELLIPSIZE_NONE);
00148 gtk_widget_set_name(label2, "irex-settings-title");
00149 gtk_box_pack_start(titlehbox, label2, FALSE, FALSE, 0);
00150 gtk_widget_show(label2);
00151
00152 GtkWidget* label3 = gtk_label_new(subtitle);
00153 gtk_label_set_ellipsize(GTK_LABEL(label3), PANGO_ELLIPSIZE_NONE);
00154 gtk_widget_set_name(label3, "irex-settings-subtitle");
00155 gtk_box_pack_start(titlehbox, label3, FALSE, FALSE, 0);
00156 gtk_widget_show(label3);
00157 gtk_widget_show(GTK_WIDGET(titlehbox));
00158
00159 if ( title_label != NULL )
00160 {
00161 *title_label = label1;
00162 }
00163 if (subtitle_label != NULL )
00164 {
00165 *subtitle_label = label3;
00166 }
00167 }
00168
00169
00170
00171
00172
00173 static void add_settings_exit_item(void)
00174 {
00175 GError *err = NULL;
00176 GdkPixbuf* my_pixbuf = NULL;
00177
00178 char iconfile[512];
00179 snprintf(iconfile , 512, "%s/%s", DATADIR, "icon-back-small.png");
00180
00181 LOGPRINTF("iconfile at %s\n", iconfile);
00182
00183 my_pixbuf = gdk_pixbuf_new_from_file ( iconfile, &err );
00184
00185 if (my_pixbuf == NULL)
00186 {
00187 ERRORPRINTF("cannot load iconfile [%s] error [%s]", iconfile, err->message);
00188 g_clear_error(&err);
00189 }
00190
00191
00192 gtk_list_store_insert_with_values(
00193 g_settings_filestore
00194 , NULL
00195 , 3
00196 , 0, _("to Settings")
00197 , 1, _("Return to the Settings overview page")
00198 , 2, my_pixbuf
00199 , -1
00200 );
00201
00202 g_object_unref(my_pixbuf);
00203 }
00204
00205
00206 GtkWidget* create_settingsview (void)
00207 {
00208 GtkWidget *view = ergtk_list_view_new_with_model( get_settingsmodel() );
00209
00210
00211 gtk_widget_set_name(view, "contentview-irex-settings");
00212 GtkTreeView *treeview = GTK_TREE_VIEW(view);
00213 erGtkListView *er_listview = ERGTK_LIST_VIEW(view);
00214 gtk_tree_view_set_headers_visible(treeview, FALSE);
00215 ergtk_list_view_set_focus_mode(er_listview, TRUE, TRUE);
00216 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
00217 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
00218
00219
00220 GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new();
00221 g_object_set( G_OBJECT(renderer),
00222 "xpad", 10,
00223 "ypad", 0,
00224 "xalign", 0.5,
00225 "yalign", 0.5,
00226 NULL );
00227 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( NULL,
00228 renderer,
00229 "pixbuf", MODCOL_THUMBNAIL,
00230 NULL );
00231 g_object_set( G_OBJECT(column),
00232 "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
00233 "expand", FALSE,
00234 NULL );
00235 ergtk_list_view_append_column(er_listview, column);
00236
00237
00238 renderer = ergtk_cell_renderer_text_new(2);
00239 g_object_set( G_OBJECT(renderer),
00240 "xpad", 0,
00241 "ypad", 0,
00242 "xalign", 0.0,
00243 "yalign", 1.0,
00244 "ellipsize", PANGO_ELLIPSIZE_END,
00245 "ellipsize-set", TRUE,
00246 "font-0", "Normal 10",
00247 "font-1", "Normal italic 9",
00248 "height-0", 32,
00249 "height-1", 22,
00250 "foreground-0", "black",
00251 "foreground-1", "#555555",
00252 NULL );
00253 column = gtk_tree_view_column_new_with_attributes( "",
00254 renderer,
00255 "text-0", MODCOL_TITLE,
00256 "text-1", MODCOL_SUBTITLE,
00257 NULL );
00258 g_object_set( G_OBJECT(column),
00259 "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
00260 "expand", TRUE,
00261 NULL );
00262 ergtk_list_view_append_column(er_listview, column);
00263
00264
00265
00266 renderer = ergtk_cell_renderer_border_new();
00267 g_object_set( G_OBJECT(renderer),
00268 "xpad", 0,
00269 "ypad", 0,
00270 "xalign", 0.0,
00271 "yalign", 0.5,
00272 "border-width", 2,
00273 "border-offset", 3,
00274 "border-color", "dark grey",
00275 NULL );
00276 column = gtk_tree_view_column_new_with_attributes( "",
00277 renderer,
00278 NULL );
00279 g_object_set( G_OBJECT(column),
00280 "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
00281 "expand", FALSE,
00282 NULL );
00283 ergtk_list_view_append_column(er_listview, column);
00284
00285
00286 add_settings_exit_item();
00287
00288 return view;
00289 }
00290
00291 GtkWidget* create_settingsview_for_type( SettingType setting )
00292 {
00293 GtkWidget* view = create_settingsview();
00294 g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00295 g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00296
00297 g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), (gpointer) setting ) ;
00298 g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), (gpointer) setting ) ;
00299
00300 return view;
00301 }
00302
00303 void update_settings_exit_text(gchar* title, gchar* subtitle)
00304 {
00305 GtkTreeIter iter;
00306
00307 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(g_settings_filestore), &iter))
00308 {
00309 gtk_list_store_set(g_settings_filestore, &iter,
00310 MODCOL_TITLE, title,
00311 MODCOL_SUBTITLE, subtitle,
00312 -1 );
00313 }
00314 }
00315
00316 GtkTreeModel* get_settingsmodel(void)
00317 {
00318 static GtkTreeModel *settingsmodel = NULL;
00319
00320 if (g_settings_filestore == NULL)
00321 {
00322 g_settings_filestore = gtk_list_store_new( N_SETTINGSMODEL_COLUMNS, SETTINGSMODEL_COLUMN_TYPES);
00323 settingsmodel = GTK_TREE_MODEL(g_settings_filestore);
00324 }
00325
00326 return settingsmodel;
00327 }
00328
00329 GtkWidget* subject_create()
00330 {
00331 GtkWidget* label = gtk_label_new(NULL);
00332 gtk_widget_set_name(label, "irex-normal-text");
00333 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00334 return label;
00335 }
00336
00337 GtkWidget* description_create()
00338 {
00339 GtkWidget* label = gtk_label_new(NULL);
00340 gtk_label_set_single_line_mode(GTK_LABEL(label), FALSE);
00341 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00342 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_NONE);
00343 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00344 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &grey);
00345 gtk_widget_modify_font (label, pango_font_description_from_string ("Normal italic 9"));
00346 g_signal_connect( G_OBJECT(label), "size-allocate", G_CALLBACK(label_on_size_allocate), NULL);
00347 gtk_widget_set_size_request(label, -1, -1);
00348 return label;
00349 }
00350
00351
00352
00353
00354 static void label_on_size_allocate( GtkWidget* label, GtkAllocation* allocation, gpointer data )
00355 {
00356
00357 GtkRequisition r;
00358 gint w = -1;
00359 gint h = -1;
00360 gboolean needs_update = FALSE;
00361
00362 gtk_widget_size_request( label, &r );
00363 if ( r.width != allocation->width )
00364 {
00365 w = allocation->width;
00366 needs_update = TRUE;
00367 }
00368 if ( r.height != allocation->height )
00369 {
00370 h = allocation->height;
00371 needs_update = TRUE;
00372 }
00373 if ( needs_update )
00374 {
00375 gtk_widget_set_size_request( label, w, h );
00376 }
00377 else {
00378 return;
00379 }
00380 }
00381
00382
00383 static gboolean on_focus_in(GtkWidget* widget, gpointer data )
00384 {
00385 g_assert(widget != NULL ) ;
00386 ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0);
00387 return FALSE;
00388 }
00389
00390 static gboolean on_focus_out(GtkWidget* widget, gpointer data )
00391 {
00392 g_assert(widget != NULL ) ;
00393 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00394 g_assert( my_selection != NULL ) ;
00395 gtk_tree_selection_unselect_all(my_selection);
00396 return FALSE;
00397 }
00398
00399 static void on_listview_row_activated ( GtkTreeView *view,
00400 GtkTreePath *path,
00401 GtkTreeViewColumn *column,
00402 gpointer user_data )
00403 {
00404 SettingType setting = (SettingType) user_data;
00405 switch (setting)
00406 {
00407 case SETTING_MARGINS:
00408 save_margins_settings();
00409 break;
00410 case SETTING_MYIREX:
00411 save_account_settings();
00412 break;
00413 case SETTING_FLIPBAR:
00414 save_flipbar_settings();
00415 break;
00416 case SETTING_FLIGHTMODE:
00417 save_flightmode_settings();
00418 break;
00419 case SETTING_DATETIME:
00420 save_datetime_settings();
00421 break;
00422 case SETTING_LANGUAGE:
00423 save_language_settings();
00424 break;
00425 case SETTING_POWER:
00426 save_power_settings();
00427 break;
00428 case SETTING_ROTATION:
00429 save_rotation_settings();
00430 break;
00431 case SETTING_SENSORS:
00432 save_sensor_settings();
00433 break;
00434 case SETTING_DEVINFO:
00435 case SETTING_SD:
00436 case SETTING_RESET:
00437 case SETTING_STYLUS:
00438 case SETTING_NONE:
00439 case N_SETTING:
00440 default:
00441 break;
00442 }
00443 main_quit();
00444 }
00445
00446 static void on_listview_navigate_cursor ( erGtkListView *er_listview,
00447 erGtkListViewKeyPress keycode,
00448 gpointer user_data )
00449 {
00450 GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00451 g_assert( my_selection != NULL ) ;
00452
00453
00454 switch (keycode)
00455 {
00456 case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00457 case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00458 setting_set_focus((SettingType) user_data);
00459 gtk_tree_selection_unselect_all(my_selection);
00460 break;
00461 default:
00462 LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00463 ;
00464 break;
00465 }
00466 }
00467
00468 static void setting_set_focus(SettingType setting)
00469 {
00470 switch (setting)
00471 {
00472 #if 0
00473 case SETTING_MARGINS:
00474 margins_set_main_focus();
00475 break;
00476 case SETTING_MYIREX:
00477 myirex_set_main_focus();
00478 break;
00479 case SETTING_FLIPBAR:
00480 flipbar_set_main_focus();
00481 break;
00482 case SETTING_FLIGHTMODE:
00483 flightmode_set_main_focus();
00484 break;
00485 case SETTING_FDATETIME:
00486 fdatetime_set_main_focus();
00487 break;
00488 case SETTING_RESET:
00489 reset_set_main_focus();
00490 break;
00491 case SETTING_STYLUS:
00492 stylus_set_main_focus();
00493 break;
00494 case SETTING_POWER:
00495 power_set_main_focus();
00496 break;
00497 case SETTING_ROTATION:
00498 rotation_set_main_focus();
00499 break;
00500 case SETTING_SENSORS:
00501 sensor_set_main_focus();
00502 break;
00503 #endif
00504 case SETTING_DATETIME:
00505 datetime_set_main_focus();
00506 break;
00507 case SETTING_LANGUAGE:
00508 language_set_main_focus();
00509 break;
00510 case SETTING_DEVINFO:
00511 case SETTING_SD:
00512 case SETTING_NONE:
00513 case N_SETTING:
00514 default:
00515 break;
00516 }
00517 }
00518