00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <config.h>
00038
00039 #include <errno.h>
00040 #include <fcntl.h>
00041 #include <pthread.h>
00042 #include <signal.h>
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include <sys/time.h>
00046 #include <sys/ioctl.h>
00047 #include <time.h>
00048 #include <X11/Xlib.h>
00049 #include <X11/Xutil.h>
00050 #include <X11/extensions/XTest.h>
00051 #include <X11/keysymdef.h>
00052
00053 #include <gdk/gdkkeysyms.h>
00054 #include <gtk/gtk.h>
00055
00056 #include <liberregxml/erregapi.h>
00057 #include <libergtk/ergtk.h>
00058 #include <libermanifest/ermanifest.h>
00059
00060 #ifdef ENABLE_LOGGING
00061 #include <liberlog/erlog.h>
00062 #endif
00063
00064 #include "contentListerLog.h"
00065 #include "erbusy.h"
00066 #include "button.h"
00067 #include "erConnect.h"
00068 #include "system.h"
00069 #include "gtkPincodeScreen.h"
00070 #include "control.h"
00071 #include "programManager.h"
00072 #include "stack.h"
00073 #include "powerManager.h"
00074 #include "click.h"
00075 #include "toolbar.h"
00076 #include "gtkDistListWnd.h"
00077
00078
00079
00080 static gboolean g_block_all_keys = FALSE;
00081
00082
00083 static gboolean g_flipbar_direction = TRUE;
00084
00085
00086 static gint g_keybuffering_setting = FALSE;
00087
00088
00089
00090
00091
00092 static gboolean g_enable_key_buffering = TRUE;
00093
00094
00095 static int g_timeout_handler_id = 0;
00096
00097
00098 #ifdef COMMAND_LINE_INPUT
00099 static void *readFromNamedPipe(void *arg);
00100 #else
00101 static void *readFromButtons(void *arg);
00102 static void *buttonStateMachine(void *arg);
00103 static int button_get_timout(void);
00104 static pthread_cond_t buttonCond;
00105 static pthread_mutex_t buttonCondMutex;
00106 static int protectedButton;
00107 static struct timespec g_timoutValue;
00108 #endif //COMMAND_LINE_INPUT
00109
00110 static void button_handler(int button, gpointer data);
00111 static void default_button_handling(int button, gpointer data);
00112 static void misc_state_button_handling(int button, gpointer data);
00113 static void pincode_state_button_handling(int button, gpointer data);
00114 static void langsel_button_handling(int button, gpointer data);
00115
00116 static gboolean button_get_flipbar_direction_setting(void);
00117 static gboolean button_key_buffering_timeout(gpointer data);
00118 static gint button_get_key_buffering_setting(void);
00119
00120 int button_init(gpointer data)
00121 {
00122
00123 pthread_t theThread;
00124
00125 #ifdef COMMAND_LINE_INPUT
00126 CL_LOGPRINTF("Command line input");
00127
00128
00129 if (pthread_create(&theThread, NULL, readFromNamedPipe, (void *)data) != 0)
00130 {
00131 CL_ERRORPRINTF("Could not create thread");
00132 return -1;
00133 }
00134 else
00135 {
00136 return 0;
00137 }
00138 #else
00139 CL_LOGPRINTF("Button driver input");
00140 int timoutValue = button_get_timout();
00141 g_timoutValue.tv_sec = timoutValue / 1000;
00142 g_timoutValue.tv_nsec = (timoutValue % 1000) * 1000000;
00143 keybufferingSettingInit();
00144 flipbarDirectionSettingInit();
00145 protectedButton = -1;
00146 pthread_mutex_init(&buttonCondMutex, NULL);
00147 pthread_cond_init(&buttonCond, NULL);
00148
00149 if (pthread_create(&theThread, NULL, readFromButtons, (void *)data) != 0)
00150 {
00151 CL_ERRORPRINTF("Could not create thread");
00152 return -1;
00153 }
00154 if (pthread_create(&theThread, NULL, buttonStateMachine, (void *)data) != 0)
00155 {
00156 CL_ERRORPRINTF("Could not create thread");
00157 return -1;
00158 }
00159
00160 return 0;
00161 #endif //COMMAND_LINE_INPUT
00162 }
00163
00164
00165 void button_block_all_keys(gboolean do_block)
00166 {
00167 g_block_all_keys = do_block;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177 void button_enable_key_buffering(gboolean enable)
00178 {
00179 g_enable_key_buffering = enable;
00180
00181 CL_LOGPRINTF("set g_enable_key_buffering =%d", enable);
00182
00183 if (TRUE == enable)
00184 {
00185 if (g_timeout_handler_id != 0)
00186 {
00187 g_source_remove(g_timeout_handler_id);
00188 g_timeout_handler_id = 0;
00189 }
00190 }
00191 else
00192 {
00193 if (g_timeout_handler_id == 0)
00194 {
00195 g_timeout_handler_id = g_timeout_add (KEYBUFFERING_OFF_TIMEOUT,
00196 button_key_buffering_timeout, NULL);
00197 }
00198 }
00199 }
00200
00201 static gboolean button_is_enable_key_buffering()
00202 {
00203 return g_enable_key_buffering;
00204 }
00205
00206
00207 static gboolean button_key_buffering_timeout(gpointer data)
00208 {
00209 CL_LOGPRINTF("enable key buffering again for timeout");
00210 button_enable_key_buffering(TRUE);
00211 return TRUE;
00212 }
00213
00214 #ifdef COMMAND_LINE_INPUT
00215 static void *readFromNamedPipe(void *arg)
00216 {
00217 char szBuffer[MAX_COMMAND_SIZE];
00218 int button;
00219 int pipe_fd;
00220 int res;
00221 int exit = 0;
00222
00223 CL_LOGPRINTF("Enter");
00224
00225 while (exit == 0)
00226 {
00227 pipe_fd = open(FIFO_NAME, O_RDONLY);
00228
00229 CL_LOGPRINTF("%s open fd %d", FIFO_NAME, pipe_fd);
00230
00231 if (pipe_fd != -1)
00232 {
00233 res = read(pipe_fd, szBuffer, MAX_COMMAND_SIZE);
00234 if (res > 0)
00235 {
00236 CL_LOGPRINTF("read %s [%d]", szBuffer, button);
00237 button = atoi(szBuffer);
00238 button_handler(button, arg);
00239 }
00240 close(pipe_fd);
00241 }
00242 else
00243 {
00244
00245 CL_ERRORPRINTF("pipe_fd = -1");
00246 exit = 1;
00247 }
00248 }
00249
00250 pthread_exit(NULL);
00251 }
00252 #else
00253
00258 static void *readFromButtons(void *arg)
00259 {
00260 int status;
00261 int button_device;
00262 int ret;
00263
00264 button_device = open("/dev/buttons", O_RDWR);
00265 if (button_device == -1)
00266 {
00267 CL_ERRORPRINTF("Error opening buttondriver.");
00268 exit(-1);
00269 }
00270
00271
00272 ioctl(button_device, BUTTON_IOCTL_WRITE_ACTIVITY_LED, 0);
00273
00274
00275 int button;
00276 int button_old = 0xff;
00277 while (1)
00278 {
00279 usleep(100 * 1000L);
00280 ret = ioctl(button_device, BUTTON_IOCTL_GET_STATUS, &status);
00281 if (ret)
00282 {
00283 CL_ERRORPRINTF("ioctl returned 0x%x", ret);
00284 }
00285 else
00286 {
00287 button = GETBUTTON(status);
00288 if (button != button_old)
00289 {
00290
00291 CL_LOGPRINTF("Button changed: new 0x%04X, old 0x%04X", button, button_old);
00292 button_old = button;
00293 pthread_mutex_lock(&buttonCondMutex);
00294 protectedButton = button;
00295
00296
00297 if (protectedButton == 0xff)
00298 {
00299 CL_LOGPRINTF("ioctlthread: Button released");
00300 if (ret)
00301 {
00302 CL_ERRORPRINTF("ioctl returned 0x%x", ret);
00303 }
00304 }
00305 else if (protectedButton >= 0 && protectedButton < NUM_BUTTONS)
00306 {
00307 CL_LOGPRINTF
00308 ("ioctlthread: Button pressed: %d, Pen detect: %s",
00309 protectedButton, GETPENDETECT(status) ? "Yes" : "No");
00310 if (ret)
00311 {
00312 CL_ERRORPRINTF("ioctl returned 0x%x", ret);
00313 }
00314 }
00315 else
00316 {
00317 CL_LOGPRINTF("ioctlthread: button weirdness");
00318 }
00319 pthread_cond_signal(&buttonCond);
00320 pthread_mutex_unlock(&buttonCondMutex);
00321 }
00322 }
00323 }
00324 pthread_exit(NULL);
00325 }
00326
00339 static void *buttonStateMachine(void *arg)
00340 {
00341 int button;
00342 struct timespec times;
00343 struct timeval timev;
00344
00345 enum
00346 {
00347 buttonReleased,
00348 buttonPressed
00349 } state = buttonReleased;
00350
00351 button = -1;
00352 while (1)
00353 {
00354 CL_LOGPRINTF("smthread: start of loop, state %d", state);
00355 switch (state)
00356 {
00357 case buttonReleased:
00358 pthread_mutex_lock(&buttonCondMutex);
00359 CL_LOGPRINTF("smthread: waiting for press");
00360 pthread_cond_wait(&buttonCond, &buttonCondMutex);
00361 if (protectedButton == 0xFF)
00362 {
00363 CL_LOGPRINTF("smthread: release in released");
00364 pthread_mutex_unlock(&buttonCondMutex);
00365 }
00366 else
00367 {
00368 CL_LOGPRINTF("smthread: press in released");
00369 button = protectedButton;
00370 state = buttonPressed;
00371 pthread_mutex_unlock(&buttonCondMutex);
00372 }
00373 break;
00374
00375 case buttonPressed:
00376 pthread_mutex_lock(&buttonCondMutex);
00377
00378
00379 gettimeofday(&timev, NULL);
00380 times.tv_sec = timev.tv_sec + g_timoutValue.tv_sec;
00381 times.tv_nsec = (timev.tv_usec * 1000) + g_timoutValue.tv_nsec;
00382 if (times.tv_nsec >= 1000000000)
00383 {
00384 times.tv_nsec -= 1000000000;
00385 times.tv_sec += 1;
00386 }
00387 CL_LOGPRINTF("smthread: timed waiting for release");
00388 if (pthread_cond_timedwait(&buttonCond, &buttonCondMutex, ×) == ETIMEDOUT)
00389 {
00390 CL_LOGPRINTF("smthread: timeout in pressed");
00391 pthread_mutex_unlock(&buttonCondMutex);
00392 if (button >= 0 && button < NUM_BUTTONS)
00393 {
00394 CL_LOGPRINTF("smthread: long button handler");
00395 button_handler(button | BUTTON_LONG_PRESS, arg);
00396 }
00397 button = -1;
00398 state = buttonReleased;
00399 }
00400 else
00401 {
00402 if (protectedButton == 0xFF)
00403 {
00404 CL_LOGPRINTF("smthread: release in pressed");
00405 state = buttonReleased;
00406 pthread_mutex_unlock(&buttonCondMutex);
00407 if (button >= 0 && button < NUM_BUTTONS)
00408 {
00409 CL_LOGPRINTF("smthread: short button handler");
00410 button_handler(button, arg);
00411 }
00412 button = -1;
00413 }
00414 else
00415 {
00416 CL_LOGPRINTF("smthread: press in pressed");
00417 button = protectedButton;
00418 pthread_mutex_unlock(&buttonCondMutex);
00419 }
00420 }
00421 break;
00422 }
00423 }
00424 pthread_exit(NULL);
00425 }
00426
00427 static regUserSetting_t* btn_get_user_setting(void)
00428 {
00429 return erRegGetUserSetting();
00430 }
00431
00432 static int button_get_timout(void)
00433 {
00434 regUserSetting_t *theUserSetting = NULL;
00435 int value = BUTTON_LONG_PRESS_TIMEOUT;
00436
00437 theUserSetting = btn_get_user_setting();
00438 if ((theUserSetting) && (theUserSetting->longkeypressTimeout > 0))
00439 {
00440 value = theUserSetting->longkeypressTimeout;
00441 erRegFreeUserSetting(theUserSetting);
00442 }
00443 else
00444 {
00445 CL_WARNPRINTF("no reader settings");
00446 }
00447
00448 CL_LOGPRINTF("timout %d", value);
00449 return value;
00450 }
00451
00452 static gboolean button_get_flipbar_direction_setting(void)
00453 {
00454 regUserSetting_t *theUserSetting = NULL;
00455 gboolean value = TRUE;
00456
00457 theUserSetting = btn_get_user_setting();
00458 if (theUserSetting)
00459 {
00460 value = theUserSetting->flipbarLeftIsDown;
00461 erRegFreeUserSetting(theUserSetting);
00462 }
00463 else
00464 {
00465 CL_WARNPRINTF("no reader settings");
00466 }
00467
00468 CL_LOGPRINTF("flipbarDirection %d", value);
00469 return value;
00470 }
00471
00472 void flipbarDirectionSettingInit()
00473 {
00474
00475 g_flipbar_direction = button_get_flipbar_direction_setting();
00476 }
00477
00478 static gint button_get_key_buffering_setting(void)
00479 {
00480 regUserSetting_t *theUserSetting = NULL;
00481 gint value = 0;
00482
00483 theUserSetting = btn_get_user_setting();
00484 if (theUserSetting)
00485 {
00486 value = theUserSetting->keyBuffering;
00487 erRegFreeUserSetting(theUserSetting);
00488 }
00489 else
00490 {
00491 CL_WARNPRINTF("no reader settings");
00492 }
00493
00494 CL_LOGPRINTF("keybuffering %d", value);
00495 return value;
00496 }
00497
00498 void keybufferingSettingInit()
00499 {
00500
00501 g_keybuffering_setting = button_get_key_buffering_setting();
00502 }
00503
00504 #endif //COMMAND_LINE_INPUT
00505 static void button_handler(int button, gpointer data)
00506 {
00507 CL_LOGPRINTF("entry: button [0x%04X] state [%d]", button, getListerState());
00508
00509
00510 if (FALSE == g_flipbar_direction)
00511 {
00512 if (PAGETURN_FORWARD == button)
00513 {
00514 button = PAGETURN_BACK;
00515 }
00516 else if (PAGETURN_BACK == button)
00517 {
00518 button = PAGETURN_FORWARD;
00519 }
00520 else if ((PAGETURN_FORWARD | BUTTON_LONG_PRESS) == button)
00521 {
00522 button = (PAGETURN_BACK | BUTTON_LONG_PRESS);
00523 }
00524 else if ((PAGETURN_BACK | BUTTON_LONG_PRESS) == button)
00525 {
00526 button = (PAGETURN_FORWARD | BUTTON_LONG_PRESS);
00527 }
00528 }
00529
00530
00531 if (g_block_all_keys && button != (POWER) && button != (POWER | BUTTON_LONG_PRESS))
00532 {
00533 return;
00534 }
00535
00536
00537 static int keyclicks_when_locked = MAX_KEYCLICKS_WHEN_LOCKED;
00538
00539 if ( toolbar_is_locked_selected()
00540 && button != (POWER )
00541 && button != (POWER | BUTTON_LONG_PRESS) )
00542 {
00543
00544 if (keyclicks_when_locked > 0)
00545 {
00546 --keyclicks_when_locked;
00547 click_key_discard();
00548 }
00549
00550
00551 return;
00552 }
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 if (0 == g_keybuffering_setting)
00563 {
00564 if (FALSE == button_is_enable_key_buffering() )
00565 {
00566 CL_LOGPRINTF("ingore key =%d\n", button);
00567 click_key_discard();
00568 return;
00569 }
00570 button_enable_key_buffering(FALSE);
00571 }
00572
00573
00574
00575 keyclicks_when_locked = MAX_KEYCLICKS_WHEN_LOCKED;
00576
00577
00578
00579
00580
00581 #ifdef ENABLE_LOGGING
00582
00583 erlog_event_button(button);
00584 #endif
00585
00586
00587 click_key();
00588
00589 listerState_t lister_state = getListerState();
00590 if (lister_state == STATE_NORMAL)
00591 {
00592 if (listerIsErrorScreenVisible())
00593 {
00594 gdk_threads_enter();
00595 listerHideErrorScreen();
00596 gdk_threads_leave();
00597 }
00598 else
00599 {
00600 default_button_handling(button, data);
00601 }
00602 }
00603 else if (lister_state == STATE_USB_CONNECTED)
00604 {
00605 switch (button)
00606 {
00607 case POWER:
00608 case POWER | BUTTON_LONG_PRESS:
00609
00610 gdk_threads_enter();
00611 ctrl_shutdown();
00612 gdk_threads_leave();
00613 break;
00614
00615 default:
00616 ctrl_usbmode_keypress();
00617 }
00618 }
00619 else if (lister_state == STATE_DOWNLOADMGR)
00620 {
00621
00622 if (TRUE == ctrl_is_connect_from_pincode())
00623 {
00624 switch (button)
00625 {
00626 case OVERVIEW:
00627 case OVERVIEW | BUTTON_LONG_PRESS:
00628 case POWER:
00629 case POWER | BUTTON_LONG_PRESS:
00630 CL_LOGPRINTF("OVERVIEW_BUTTON or POWER_BUTTON");
00631 ctrl_disconnect(connectScrUnchanged);
00632 break;
00633
00634 default:
00635 CL_WARNPRINTF("DownloadMgr state from pincode: buttons disabled");
00636 erbusy_off();
00637 }
00638 }
00639 else
00640 {
00641 erbusy_blink();
00642
00643 switch (button)
00644 {
00645 case OVERVIEW:
00646 case OVERVIEW | BUTTON_LONG_PRESS:
00647 CL_LOGPRINTF("OVERVIEW_BUTTON");
00648 gdk_threads_enter();
00649 pm_SendKey(GDK_F5);
00650 gdk_threads_leave();
00651 break;
00652
00653 case MODE:
00654 case MODE | BUTTON_LONG_PRESS:
00655 case POWER:
00656 case POWER | BUTTON_LONG_PRESS:
00657 CL_LOGPRINTF("MODE_BUTTON or POWER_BUTTON");
00658 ctrl_disconnect(connectScrMode);
00659 break;
00660
00661 case NEWSPAPER:
00662 case NEWSPAPER | BUTTON_LONG_PRESS:
00663 CL_LOGPRINTF("MY_NEWSPAPERS_BUTTON");
00664 ctrl_disconnect(connectScrNews);
00665 break;
00666
00667 case BOOKS:
00668 case BOOKS | BUTTON_LONG_PRESS:
00669 CL_LOGPRINTF("MY_BOOKS_BUTTON");
00670 ctrl_disconnect(connectScrBooks);
00671 break;
00672
00673 case DOCUMENTS:
00674 case DOCUMENTS | BUTTON_LONG_PRESS:
00675 CL_LOGPRINTF("MY_DOCS_BUTTON");
00676 ctrl_disconnect(connectScrDocs);
00677 break;
00678
00679 case NOTES:
00680 case NOTES | BUTTON_LONG_PRESS:
00681 CL_LOGPRINTF("MY_NOTES_BUTTON");
00682 ctrl_disconnect(connectScrNotes);
00683 break;
00684
00685 default:
00686 CL_WARNPRINTF("DownloadMgr state: send key to connectionMgr");
00687 default_button_handling(button, data);
00688 erbusy_off();
00689 }
00690 }
00691 }
00692 else if (lister_state == STATE_MISC)
00693 {
00694 misc_state_button_handling(button, data);
00695 }
00696 else if (lister_state == STATE_PINCODE)
00697 {
00698 if (listerIsErrorScreenVisible())
00699 {
00700 gdk_threads_enter();
00701 listerHideErrorScreen();
00702 gdk_threads_leave();
00703 }
00704 else
00705 {
00706 pincode_state_button_handling(button, data);
00707 }
00708 }
00709 else if (lister_state == STATE_LANG_SEL)
00710 {
00711 if (listerIsErrorScreenVisible())
00712 {
00713 gdk_threads_enter();
00714 listerHideErrorScreen();
00715 gdk_threads_leave();
00716 }
00717 else
00718 {
00719 langsel_button_handling(button, data);
00720 }
00721 }
00722 else
00723 {
00724 CL_ERRORPRINTF("Unexpected lister_state [%d]", lister_state);
00725 }
00726
00727 CL_LOGPRINTF("leave");
00728 }
00729
00730 static void default_button_handling(int button, gpointer data)
00731 {
00732 CL_LOGPRINTF("entry: button [0x%04X]", button);
00733
00734 erbusy_blink();
00735
00736 switch (button)
00737 {
00738 case NEWSPAPER:
00739 case NEWSPAPER | BUTTON_LONG_PRESS:
00740 CL_LOGPRINTF("MY_NEWSPAPERS_BUTTON");
00741 gdk_threads_enter();
00742 ctrl_contentType_button_clicked(st_ContentTypeNews);
00743 gdk_threads_leave();
00744 break;
00745
00746 case BOOKS:
00747 case BOOKS | BUTTON_LONG_PRESS:
00748 CL_LOGPRINTF("MY_BOOKS_BUTTON");
00749 gdk_threads_enter();
00750 ctrl_contentType_button_clicked(st_ContentTypeBooks);
00751 gdk_threads_leave();
00752 break;
00753
00754 case DOCUMENTS:
00755 case DOCUMENTS | BUTTON_LONG_PRESS:
00756 CL_LOGPRINTF("MY_DOCS_BUTTON");
00757 gdk_threads_enter();
00758 ctrl_contentType_button_clicked(st_ContentTypeDocs);
00759 gdk_threads_leave();
00760 break;
00761
00762 case NOTES:
00763 case NOTES | BUTTON_LONG_PRESS:
00764 CL_LOGPRINTF("MY_NOTES_BUTTON");
00765 gdk_threads_enter();
00766 ctrl_contentType_button_clicked(st_ContentTypeNotes);
00767 gdk_threads_leave();
00768 break;
00769
00770 case MODE:
00771 CL_LOGPRINTF("MODE_BUTTON");
00772 gdk_threads_enter();
00773 ctrl_mode_button_clicked();
00774 gdk_threads_leave();
00775 break;
00776
00777 case MODE | BUTTON_LONG_PRESS:
00778 CL_LOGPRINTF("MODE_BUTTON LONG");
00779 gdk_threads_enter();
00780 ctrl_mode_button_long_clicked();
00781 gdk_threads_leave();
00782 break;
00783
00784 case PAGETURN_FORWARD:
00785 CL_LOGPRINTF("PAGETURN_FORWARD");
00786 gdk_threads_enter();
00787 pm_SendKey(GDK_Page_Down);
00788 gdk_threads_leave();
00789 break;
00790
00791 case PAGETURN_FORWARD | BUTTON_LONG_PRESS:
00792 CL_LOGPRINTF("PAGETURN_FORWARD LONG");
00793 gdk_threads_enter();
00794 pm_SendKey(GDK_F1);
00795 gdk_threads_leave();
00796 break;
00797
00798 case PAGETURN_BACK:
00799 CL_LOGPRINTF("PAGETURN_BACK");
00800 gdk_threads_enter();
00801 pm_SendKey(GDK_Page_Up);
00802 gdk_threads_leave();
00803 break;
00804
00805 case PAGETURN_BACK | BUTTON_LONG_PRESS:
00806 CL_LOGPRINTF("PAGETURN_BACK LONG");
00807 gdk_threads_enter();
00808 pm_SendKey(GDK_F2);
00809 gdk_threads_leave();
00810 break;
00811
00812 case OVERVIEW:
00813 CL_LOGPRINTF("OVERVIEW_BUTTON");
00814 gdk_threads_enter();
00815 pm_SendKey(GDK_F5);
00816 gdk_threads_leave();
00817 break;
00818
00819 case OVERVIEW | BUTTON_LONG_PRESS:
00820 CL_LOGPRINTF("OVERVIEW_BUTTON LONG");
00821 gdk_threads_enter();
00822 pm_SendKey(GDK_Home);
00823 gdk_threads_leave();
00824 break;
00825
00826 case NAVIGATE_3:
00827 CL_LOGPRINTF("NEXT_LINK_BUTTON");
00828 gdk_threads_enter();
00829 pm_SendKey(GDK_Down);
00830 gdk_threads_leave();
00831 break;
00832
00833 case NAVIGATE_3 | BUTTON_LONG_PRESS:
00834 CL_LOGPRINTF("NEXT_LINK_BUTTON LONG");
00835 gdk_threads_enter();
00836 pm_SendKey(GDK_F3);
00837 gdk_threads_leave();
00838 break;
00839
00840 case NAVIGATE_1:
00841 CL_LOGPRINTF("PREVIOUS_LINK_BUTTON");
00842 gdk_threads_enter();
00843 pm_SendKey(GDK_Up);
00844 gdk_threads_leave();
00845 break;
00846
00847 case NAVIGATE_1 | BUTTON_LONG_PRESS:
00848 CL_LOGPRINTF("PREVIOUS_LINK_BUTTON LONG");
00849 gdk_threads_enter();
00850 pm_SendKey(GDK_F4);
00851 gdk_threads_leave();
00852 break;
00853
00854 case NAVIGATE_2:
00855 CL_LOGPRINTF("CONFIRM_BUTTON");
00856 gdk_threads_enter();
00857 pm_SendKey(GDK_Return);
00858 gdk_threads_leave();
00859 break;
00860
00861 case NAVIGATE_2 | BUTTON_LONG_PRESS:
00862 CL_LOGPRINTF("CONFIRM_BUTTON LONG");
00863 gdk_threads_enter();
00864 pm_SendKey(GDK_F6);
00865 gdk_threads_leave();
00866 break;
00867
00868 case CONNECT:
00869 CL_LOGPRINTF("CONNECT_BUTTON");
00870 gdk_threads_enter();
00871 ctrl_display_download_history();
00872 gdk_threads_leave();
00873 break;
00874
00875 case CONNECT | BUTTON_LONG_PRESS:
00876 CL_LOGPRINTF("CONNECT_BUTTON LONG");
00877 gdk_threads_enter();
00878 ctrl_connect_button_clicked();
00879 gdk_threads_leave();
00880 break;
00881
00882 case POWER:
00883 case POWER | BUTTON_LONG_PRESS:
00884 gdk_threads_enter();
00885 ctrl_shutdown();
00886 gdk_threads_leave();
00887 break;
00888
00889 default:
00890 CL_ERRORPRINTF("unknown value %d", button);
00891 erbusy_off();
00892 }
00893 }
00894
00895
00896 static void misc_state_button_handling(int button, gpointer data)
00897 {
00898 CL_LOGPRINTF("entry");
00899
00900 int i;
00901
00902 erbusy_blink();
00903
00904 switch (button)
00905 {
00906 case OVERVIEW:
00907 case OVERVIEW | BUTTON_LONG_PRESS:
00908 gdk_threads_enter();
00909 ctrl_hide_misc_screen();
00910 gdk_threads_leave();
00911 break;
00912
00913 case MODE:
00914 case MODE | BUTTON_LONG_PRESS:
00915 case NEWSPAPER:
00916 case NEWSPAPER | BUTTON_LONG_PRESS:
00917 case BOOKS:
00918 case BOOKS | BUTTON_LONG_PRESS:
00919 case DOCUMENTS:
00920 case DOCUMENTS | BUTTON_LONG_PRESS:
00921 case NOTES:
00922 case NOTES | BUTTON_LONG_PRESS:
00923 case POWER:
00924 case POWER | BUTTON_LONG_PRESS:
00925 default_button_handling(button, data);
00926 break;
00927
00928 case PAGETURN_FORWARD:
00929 case PAGETURN_FORWARD | BUTTON_LONG_PRESS:
00930 gdk_threads_enter();
00931 if (dist_list_wnd_is_visible())
00932 {
00933 i = (button & BUTTON_LONG_PRESS) ? 5 : 1;
00934 dist_list_wnd_page_forward(i);
00935 }
00936 else
00937 {
00938 CL_WARNPRINTF("misc state: buttons disabled");
00939 erbusy_off();
00940 }
00941 gdk_threads_leave();
00942 break;
00943
00944 case PAGETURN_BACK:
00945 case PAGETURN_BACK | BUTTON_LONG_PRESS:
00946 gdk_threads_enter();
00947 if (dist_list_wnd_is_visible())
00948 {
00949 i = (button & BUTTON_LONG_PRESS) ? 5 : 1;
00950 dist_list_wnd_page_back(i);
00951 }
00952 else
00953 {
00954 CL_WARNPRINTF("misc state: buttons disabled");
00955 erbusy_off();
00956 }
00957 gdk_threads_leave();
00958 break;
00959
00960 default:
00961 CL_WARNPRINTF("misc state: buttons disabled");
00962 erbusy_off();
00963 }
00964 }
00965
00966 static void pincode_state_button_handling(int button, gpointer data)
00967 {
00968 erbusy_blink();
00969
00970 switch (button)
00971 {
00972 case OVERVIEW:
00973 CL_LOGPRINTF("OVERVIEW_BUTTON");
00974 gdk_threads_enter();
00975 ctrl_pincode_overview_button_clicked();
00976 gdk_threads_leave();
00977 break;
00978
00979 case CONNECT | BUTTON_LONG_PRESS:
00980 CL_LOGPRINTF("CONNECT_BUTTON LONG");
00981 gdk_threads_enter();
00982 ctrl_pincode_connect_button_clicked();
00983 gdk_threads_leave();
00984 break;
00985
00986 case POWER:
00987 case POWER | BUTTON_LONG_PRESS:
00988 gdk_threads_enter();
00989 ctrl_shutdown();
00990 gdk_threads_leave();
00991 break;
00992
00993 default:
00994 CL_WARNPRINTF("Pincode state: buttons(%d) disabled", button);
00995 ctrl_pincode_button_clicked();
00996 }
00997 }
00998
00999 static void langsel_button_handling(int button, gpointer data)
01000 {
01001 CL_LOGPRINTF("entry: button [0x%04X]", button);
01002
01003 erbusy_blink();
01004
01005 switch (button)
01006 {
01007 case OVERVIEW:
01008 case OVERVIEW | BUTTON_LONG_PRESS:
01009 case NAVIGATE_3:
01010 case NAVIGATE_3 | BUTTON_LONG_PRESS:
01011 case NAVIGATE_1:
01012 case NAVIGATE_1 | BUTTON_LONG_PRESS:
01013 case NAVIGATE_2:
01014 case NAVIGATE_2 | BUTTON_LONG_PRESS:
01015 case POWER:
01016 case POWER | BUTTON_LONG_PRESS:
01017 default_button_handling(button, data);
01018 break;
01019 default:
01020 CL_ERRORPRINTF("unknown value %d", button);
01021 erbusy_off();
01022 break;
01023 }
01024 }
01025
01026