00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00031 #include <sys/wait.h>
00032 #include <signal.h>
00033
00034 #include <gtk/gtk.h>
00035 #include <gdk/gdkkeysyms.h>
00036
00037 #include <libergtk/ergtk.h>
00038 #include <liberipc/eripcsetup.h>
00039 #include <liberipc/eripctoolbar.h>
00040
00041 #include "setupLog.h"
00042 #include "displayStatus.h"
00043 #include "settings.h"
00044 #include "erbusy.h"
00045 #include "pagebar.h"
00046 #include "toolbar.h"
00047 #include "settingsData.h"
00048 #include "iLiadConfigScreen.h"
00049 #include "iLiadPincodeScreen.h"
00050 #include "system.h"
00051 #include "iLiadPincodeData.h"
00052 #include "iLiadConfigData.h"
00053 #include "iLiadUserScreen.h"
00054 #include "iLiadUserData.h"
00055 #include "iLiadBgConnectScreen.h"
00056 #include "iLiadBgConnectData.h"
00057 #include "iLiadPCConnectData.h"
00058 #include "iLiadPCConnectScreen.h"
00059 #include "iLiadArcLocData.h"
00060 #include "iLiadArcLocScreen.h"
00061 #include "iLiadDateTimeScreen.h"
00062 #include "iLiadStartUpScreen.h"
00063 #include "iLiadStartUpData.h"
00064 #include "iLiadDeviceOverview.h"
00065 #include "iLiadTimediDSScreen.h"
00066 #include <signal.h>
00067
00068
00069 static GtkWidget *g_settings = NULL;
00070
00071
00072 static void update_pagebar(void);
00073
00074
00075 static void on_goto_page(gint new_page);
00076 static void on_settings_switch_page(GtkNotebook *notebook, GtkNotebookPage *new_page, guint page_num, gpointer data);
00077 static gboolean hook_screen_refresh_typing(GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer user_data);
00078
00079
00080 #define SERVER_BUFFER_SIZE 1024
00081 static erServerChannel_t theServerChannel;
00082 static void setupMessageReceived(gpointer data, gint source_fd, GdkInputCondition condition);
00083
00084
00085
00086
00087 GtkWidget *settings_create(void)
00088 {
00089 GtkWidget* page;
00090 guint signal_id;
00091
00092 ST_LOGPRINTF("entry");
00093
00094 g_settings = gtk_notebook_new();
00095 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(g_settings), FALSE);
00096 gtk_notebook_set_show_border(GTK_NOTEBOOK(g_settings), FALSE);
00097 g_signal_connect_after(g_settings, "switch-page", G_CALLBACK(on_settings_switch_page), NULL);
00098
00099 page = iLiad_startup_screen_create();
00100 iLiad_startup_screen_set_text();
00101 iLiad_startup_screen_display_data();
00102 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00103
00104 page = iLiad_config_create();
00105 iLiad_config_set_text();
00106 iLiad_config_data_display();
00107 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00108
00109 page = iLiad_archive_location_create();
00110 iLiad_archive_location_set_text();
00111 iLiad_archive_location_display_data();
00112 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00113
00114 page = iLiad_user_create();
00115 iLiad_user_set_text();
00116 iLiad_user_data_display();
00117 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00118
00119 page = iLiad_pincode_create();
00120 iLiad_pincode_set_text();
00121 iLiad_pincode_display_data();
00122 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00123
00124 page = iLiad_pc_connect_screen_create();
00125 iLiad_pc_connect_screen_set_text();
00126 iLiad_pc_connect_screen_display_settings();
00127 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00128
00129 page = iLiad_autoconnect_create();
00130 iLiad_autoconnect_set_text();
00131 iLiad_autoconnect_data_display();
00132 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00133
00134 page = iLiad_timedids_screen_create();
00135 iLiad_timedids_screen_set_text();
00136 iLiad_timedids_screen_data_display();
00137 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00138
00139 page = iLiad_date_time_create();
00140 iLiad_date_time_set_text();
00141 iLiad_date_time_display_data();
00142 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00143
00144 page = iLiad_device_overview_create();
00145 iLiad_device_overview_set_text();
00146 iLiad_device_overview_display_data();
00147 gtk_notebook_append_page(GTK_NOTEBOOK(g_settings), page, NULL);
00148
00149
00150
00151 signal_id = g_signal_lookup("screen-refresh", ERGTK_ENTRY_TYPE);
00152 g_assert(signal_id > 0);
00153 g_signal_add_emission_hook(signal_id, 0, hook_screen_refresh_typing, (gpointer)TEXT_ENTRY_CHANGED_LEVEL, NULL);
00154
00155 signal_id = g_signal_lookup("toggled", ERGTK_TOGGLE_BUTTON_TYPE);
00156 g_assert(signal_id > 0);
00157 g_signal_add_emission_hook(signal_id, 0, hook_screen_refresh_typing, (gpointer)SETTING_ITEM_CHANGE, NULL);
00158
00159
00160 gtk_notebook_set_current_page(GTK_NOTEBOOK(g_settings), 0);
00161 gtk_widget_show(g_settings);
00162
00163 update_pagebar();
00164
00165 return g_settings;
00166 }
00167
00168
00169 gint settings_get_current_page(gint *pagecount)
00170 {
00171
00172 if (pagecount != NULL)
00173 {
00174 *pagecount = gtk_notebook_get_n_pages(GTK_NOTEBOOK(g_settings));
00175 }
00176
00177
00178 return gtk_notebook_get_current_page(GTK_NOTEBOOK(g_settings));
00179 }
00180
00181
00182
00183 void settings_page_down(gint count)
00184 {
00185 gint page;
00186 gint pagecount;
00187
00188 page = settings_get_current_page(&pagecount);
00189 page = page + count;
00190 if (page >= pagecount)
00191 {
00192 page = pagecount - 1;
00193 }
00194
00195 ST_LOGPRINTF("page %d - pagecount %d", page, pagecount);
00196 on_goto_page(page+1);
00197 }
00198
00199
00200 void settings_page_up(gint count)
00201 {
00202 gint page;
00203
00204 page = settings_get_current_page(NULL);
00205 if (page > 0)
00206 {
00207 page = page - count;
00208 if (page < 0)
00209 {
00210 page = 0;
00211 }
00212
00213 ST_LOGPRINTF("page %d", page);
00214 on_goto_page(page+1);
00215 }
00216 }
00217
00218 gboolean on_settings_keypress(GtkWidget* widget, GdkEventKey* event, gpointer data)
00219 {
00220 gboolean returnValue = FALSE;
00221 gboolean changed = FALSE;
00222
00223 ST_LOGPRINTF("entry");
00224 erbusy_off();
00225
00226 changed = iLiad_config_data_change_flipbar_direction();
00227
00228 switch (event->keyval)
00229 {
00230 case GDK_Page_Down:
00231 if (changed)
00232 settings_page_up(1);
00233 else
00234 settings_page_down(1);
00235 returnValue = TRUE;
00236 break;
00237
00238 case GDK_Page_Up:
00239 if (changed)
00240 settings_page_down(1);
00241 else
00242 settings_page_up(1);
00243 returnValue = TRUE;
00244 break;
00245
00246 case GDK_F1:
00247 if (changed)
00248 settings_page_up(5);
00249 else
00250 settings_page_down(5);
00251 returnValue = TRUE;
00252 break;
00253
00254 case GDK_F2:
00255 if (changed)
00256 settings_page_down(5);
00257 else
00258 settings_page_up(5);
00259 returnValue = TRUE;
00260 break;
00261
00262 case GDK_F5:
00263 if (get_xtscal_pid() != 0)
00264 {
00265 stop_xtscal();
00266 }
00267 else
00268 {
00269 erbusy_blink();
00270 gtk_main_quit();
00271 returnValue = TRUE;
00272 }
00273 break;
00274
00275 default:
00276 ;
00277 }
00278
00279 return returnValue;
00280 }
00281
00282
00283
00284
00285 static gboolean settings_on_idle_show_keyboard(gpointer data);
00286 static gboolean settings_on_idle_hide_keyboard(gpointer data);
00287
00288
00289
00290
00291
00292 static void settings_show_keyboard()
00293 {
00294 erbusy_blink();
00295
00296
00297 display_update_increase_level(KEYBOARD_SHOW_HIDE_LEVEL);
00298
00299
00300
00301 g_idle_add(settings_on_idle_show_keyboard, NULL);
00302
00303 }
00304 static gboolean settings_on_idle_show_keyboard(gpointer data)
00305 {
00306
00307
00308
00309 toolbar_setIconState(iconID_keyboard, iconState_selected);
00310
00311
00312 display_update_decrease_level(LOWEST_LEVEL);
00313
00314 return FALSE;
00315 }
00316
00317
00318
00319
00320
00321 static void settings_hide_keyboard(int iconState)
00322 {
00323 g_assert((iconState == iconState_grey) || (iconState == iconState_normal));
00324
00325 erbusy_blink();
00326
00327
00328 display_update_increase_level(KEYBOARD_SHOW_HIDE_LEVEL);
00329
00330
00331
00332 g_idle_add(settings_on_idle_hide_keyboard, (gpointer) iconState);
00333 }
00334
00335 static gboolean settings_on_idle_hide_keyboard(gpointer data)
00336 {
00337 int iconState = (int)data;
00338
00339
00340
00341
00342 toolbar_setIconState(iconID_keyboard, iconState);
00343
00344 display_update_request_screen_refresh(KEYBOARD_SHOW_HIDE_LEVEL, WAVEFORM_FULLSCREEN);
00345
00346 return FALSE;
00347 }
00348
00349
00350
00351 void show_keyboard(gboolean show)
00352 {
00353 static gboolean show_previous = FALSE;
00354 ST_LOGPRINTF("entry: show [%d]", show);
00355
00356 if (show)
00357 {
00358
00359 settings_show_keyboard();
00360 if (show_previous)
00361 {
00362 display_update_decrease_level(SETUP_SCREEN_EXPOSE_LEVEL);
00363 }
00364 }
00365 else
00366 {
00367
00368 settings_hide_keyboard(iconState_grey);
00369 }
00370 show_previous = show;
00371 }
00372
00373 void show_lock_screen_icon(gboolean enable)
00374 {
00375 if (FALSE == enable)
00376 {
00377 toolbar_setIconState(iconID_lock_screen, iconState_grey);
00378 }
00379 else
00380 {
00381 toolbar_setIconState(iconID_lock_screen, iconState_normal);
00382 }
00383 }
00384
00385 static void on_settings_switch_page(GtkNotebook *notebook, GtkNotebookPage *new_page, guint page_num, gpointer data)
00386 {
00387 ST_LOGPRINTF("Entry: new_page [%d]", (int)page_num);
00388
00389 switch (page_num)
00390 {
00391 case iLiad_user_screen_t:
00392 case iLiad_pc_connect_screen_t:
00393 case iLiad_autoconnect_screen_t:
00394 case iLiad_pincode_screen_t:
00395 case iLiad_timedids_screen_t:
00396 show_keyboard(TRUE);
00397 break;
00398 default:
00399 show_keyboard(FALSE);
00400 }
00401
00402 update_pagebar();
00403 display_update_request_screen_refresh(SETUP_SCREEN_EXPOSE_LEVEL, WAVEFORM_FULLSCREEN);
00404 }
00405
00406
00407 gboolean setupInstallIpcServer()
00408 {
00409 int returnValue;
00410 int fd = -1;
00411
00412 ST_IPCPRINTF("entry");
00413
00414 returnValue = erIpcOpenServerChannel(ER_SETUP_CHANNEL, &theServerChannel);
00415
00416 if (returnValue != (-1))
00417 {
00418 fd = erIpcGetServerFd(theServerChannel);
00419
00420 ST_IPCPRINTF("erIpcGetServerFd returned %d\n", fd);
00421
00422
00423 returnValue = gdk_input_add(fd, GDK_INPUT_READ, setupMessageReceived, (gpointer) theServerChannel);
00424
00425 ST_IPCPRINTF("gdk_input_add returned %d", returnValue);
00426 return TRUE;
00427 }
00428 else
00429 {
00430 ST_ERRORPRINTF("Could not open server channel");
00431 return FALSE;
00432 }
00433 }
00434
00435
00436 static void update_pagebar()
00437 {
00438
00439 gint current_page;
00440 gint page_num;
00441
00442 current_page = settings_get_current_page(&page_num);
00443 ST_LOGPRINTF("current_page %d - page_num %d", current_page, page_num);
00444
00445 pagebar_reset();
00446 pagebar_set_pagecount(page_num);
00447 pagebar_goto_page(current_page + 1);
00448 pagebar_redraw();
00449 }
00450
00451
00452 static void on_goto_page(gint new_page)
00453 {
00454 gint current_page;
00455 gint pagecount;
00456
00457 current_page = settings_get_current_page(&pagecount);
00458
00459 ST_LOGPRINTF("new_page %d - pagecount %d", new_page, pagecount);
00460
00461
00462 if (new_page > 0 && new_page <= pagecount)
00463 {
00464 ST_LOGPRINTF("switch to new_page %d", new_page);
00465
00466
00467
00468
00469 if (current_page == iLiad_timedids_screen_t)
00470 {
00471 iLiad_timedids_handle_page_switch();
00472 }
00473
00474 if (new_page-1 == iLiad_datetime_screen_t)
00475 {
00476 iLiad_date_time_handle_refresh();
00477 }
00478
00479
00480
00481
00482 display_update_increase_level(SETUP_SCREEN_EXPOSE_LEVEL);
00483 gtk_notebook_set_current_page(GTK_NOTEBOOK(g_settings), new_page-1);
00484
00485 settings_data_store_page(current_page);
00486
00487 }
00488 }
00489
00490 static gboolean hook_screen_refresh_typing(GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer user_data)
00491 {
00492 int level = (int)user_data;
00493
00494 ST_LOGPRINTF("entry: level [%d]", level);
00495
00496 display_update_request_screen_refresh(level, WAVEFORM_TYPING);
00497
00498 return TRUE;
00499 }
00500
00501
00502
00503
00504
00505 static void setupMessageReceived(gpointer data, gint source_fd, GdkInputCondition condition)
00506 {
00507 char szBuffer[SERVER_BUFFER_SIZE];
00508 int nBuf = SERVER_BUFFER_SIZE;
00509 int page;
00510
00511 erIpcCmd_t command;
00512
00513 erIpcGetMessage((erServerChannel_t) data, szBuffer, &nBuf);
00514
00515 ST_IPCPRINTF("Received %s\n", szBuffer);
00516
00517 if (stParseCommand(szBuffer, &command) >= 0)
00518 {
00519 switch (command.cc)
00520 {
00521 case ccStGotoPage:
00522 page = atoi(command.arg[0]);
00523 ST_IPCPRINTF("Setup Goto Page: %d\n", page);
00524 gdk_threads_enter();
00525 erbusy_blink();
00526 on_goto_page(page);
00527 gdk_threads_leave();
00528 break;
00529
00530 default:
00531 ST_IPCPRINTF("UNKNOWN COMMAND %d", command.cc);
00532 break;
00533 }
00534 }
00535 }