notepad_ipc.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: notepad_ipc.cpp
00003  */
00004 
00005 /*
00006  * This file is part of notepad.
00007  *
00008  * notepad 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  * notepad 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) 2010 IREX Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include <cstdio>
00032 #include <cstring>
00033 #include <sys/types.h>
00034 #include <stdlib.h>
00035 #include <unistd.h>
00036 #include <string.h>
00037 #include <gconf/gconf-client.h>
00038 #include <liberipc/eripc.h>
00039 #include <liberipc/eripc_support.h>
00040 #include <liberutils/er_error.h>
00041 #include <liberscribble/scb.h>
00042 
00043 #include "config.h"
00044 #include "i18n.h"
00045 #include "log.h" 
00046 
00047 #include "notepad_window.h"
00048 #include "notepad_utils.h"
00049 #include "notepad_ipc.h"
00050 
00051 namespace notepad
00052 {
00053 
00054     //----------------------------------------------------------------------------
00055     // Static Variables
00056     //----------------------------------------------------------------------------
00057     static eripc_client_context_t  *eripcClient = 0;
00058     static int g_xid = 0;
00059 
00060     // reference to notepad window instance
00061     static notepad::CNotepadWindow* gInstance = 0;
00062 
00063     // reference to configuration
00064     static GConfClient* gClient = 0;
00065     static PenSize      gPensize = GCONF_DEFAULT_PEN_SIZE;
00066     static gchar        gMountpoint[88];
00067 
00068 
00069     //----------------------------------------------------------------------------
00070     // Constants
00071     //----------------------------------------------------------------------------
00072 
00073     // menu 
00074     static const char *MENU                     = "notepad_menu";
00075     static const char *ipc_menu                 = NULL;
00076     // |
00077     // |
00078     // |-- Pen type 
00079     static const char *GROUP_PEN_TYPE           = "notepad_pen_types";
00080     static const char *ITEM_PEN                 = "pen";
00081     static const char *ITEM_ERASER              = "eraser";
00082     // |-- 
00083     static const char *GROUP_PEN                = "notepad_pen";
00084     //     |
00085     static const char *GROUP_PEN2               = "notepad_pen2";
00086     //     |-- line sizes options
00087     static const char *GROUP_PEN_SIZE           = "notepad_pen_size";
00088     static const char *ITEM_PEN_FINE            = "pen_fine";
00089     static const char *ITEM_PEN_SMALL           = "pen_small";
00090     static const char *ITEM_PEN_MEDIUM          = "pen_medium";
00091     static const char *ITEM_PEN_LARGE           = "pen_large";
00092     static const char *ITEM_PEN_XLARGE          = "pen_xlarge";
00093     // |
00094     // |-- actions
00095     static const char *GROUP_ACTIONS            = "notepad_actions";
00096     static const char *ITEM_ACTION_GOTOPAGE     = "goto_page";
00097     static const char *ITEM_ACTION_INSERTPAGE   = "insert_page";
00098     static const char *ITEM_ACTION_DELETEPAGE   = "delete_page";
00099     static const char *ITEM_ACTION_CLEARPAGE    = "clear_page";
00100     static const char *ITEM_ACTION_RENAME       = "rename";
00101 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00102     static const char *ITEM_ACTION_CLOSE        = "close";
00103 #endif
00104 
00105     // states of a menu item
00106     static const char *MENU_STATE_NORMAL        = "normal";
00107     static const char *MENU_STATE_SELECTED      = "selected";
00108     static const char *MENU_STATE_DISABLED      = "disabled"; 
00109 
00110     // stylus states
00111     static const char *STYLUS_PEN               = "pen";
00112     static const char *STYLUS_ERASER            = "eraser";
00113 
00114 
00115     //============================================================================
00116     // Local Function Declarations
00117     //============================================================================
00118 
00119     static void ipc_gconf_initialize(void);     // initalize gconf client
00120     static void ipc_gconf_read(void);           // read settings from gconf
00121     static void ipc_gconf_write(void);          // write settings to gconf 
00122     static void ipc_gconf_finalize(void);       // close gconf client
00123 
00124     static void ipc_menu_update_toolbar(void);  // upate toolbar
00125     static void menu_show(void);                // show selected menu items
00126     static void menu_set_text(void);            // fill in menu labels
00127     static gboolean ipc_status_set_stylus( const char *state ); // draw stylus on toolbar
00128 
00129 
00130     // Callbacks from popupmenu
00131     static void on_page_change( 
00132             eripc_context_t          *context,
00133             const eripc_event_info_t *info,
00134             void                     *user_data );
00135 
00136     static void on_window_activated( 
00137             eripc_context_t          *context,
00138             const eripc_event_info_t *info,
00139             void                     *user_data );
00140 
00141     static void on_window_deactivated( 
00142             eripc_context_t          *context,
00143             const eripc_event_info_t *info,
00144             void                     *user_data );
00145 
00146     static void on_menu_item( 
00147             eripc_context_t          *context,
00148             const eripc_event_info_t *info,
00149             void                     *user_data );
00150 
00151     static void on_changed_locale( 
00152             eripc_context_t          *context,
00153             const eripc_event_info_t *info,
00154             void                     *user_data );
00155 
00156     static void on_changed_pen( 
00157             eripc_context_t          *context,
00158             const eripc_event_info_t *info,
00159             void                     *user_data );
00160 
00161     static void on_prepare_unmount( 
00162             eripc_context_t          *context,
00163             const eripc_event_info_t *info,
00164             void                     *user_data );
00165 
00166     static void on_volume_unmounted( 
00167             eripc_context_t          *context,
00168             const eripc_event_info_t *info,
00169             void                     *user_data );
00170 
00171     static void on_prepare_standby( 
00172             eripc_context_t          *context,
00173             const eripc_event_info_t *info,
00174             void                     *user_data );
00175 
00176 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00177     static void on_sys_changed_pageturn_inverted (eripc_context_t *context,
00178             const eripc_event_info_t *info,
00179             void                     *user_data);
00180 #endif 
00181 
00182     static void on_changed_orientation( 
00183             eripc_context_t          *context,
00184             const eripc_event_info_t *info,
00185             void                     *user_data );
00186 
00187 
00188 
00189     // Exported DBUS API list
00190     static eripc_callback_function_t service_functions[] = {
00191         { on_menu_item,         "menuItemActivated",   NULL                        , 0 },
00192         { on_window_activated,  "activatedWindow",     NULL                        , 0 },
00193         { on_window_deactivated,"deactivatedWindow",   NULL                        , 0 },
00194         { on_page_change,       "pageChange",          NULL                        , 0 },
00195         { on_changed_pen,       "statusItemActivated", NULL                        , 0 },
00196         { on_changed_locale,    "sysChangedLocale",    DBUS_SERVICE_SYSTEM_CONTROL , 0 },
00197         { on_prepare_unmount,   "sysPrepareUnmount",   DBUS_SERVICE_SYSTEM_CONTROL , 0 },
00198         { on_volume_unmounted,  "sysVolumeUnmounted",  DBUS_SERVICE_SYSTEM_CONTROL , 0 },
00199         { on_prepare_standby,   "sysPrepareStandby",   DBUS_SERVICE_SYSTEM_CONTROL , 0 },
00200 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00201         { on_sys_changed_pageturn_inverted, "sysChangedPageturnInverted", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00202 #endif 
00203         { on_changed_orientation, "sysChangedOrientation",  DBUS_SERVICE_SYSTEM_CONTROL , 0 },
00204         { NULL, NULL, NULL, 0 }  // end of list
00205     };
00206 
00207 
00208     //============================================================================
00209     // Functions Implementation
00210     //============================================================================
00211 
00212     // initialise
00213     gboolean ipc_set_services(void)
00214     {
00215 
00216         pid_t pid = getpid();
00217         char name[128];
00218         sprintf(name, "%s_%05d", DBUS_APPL_NAME, pid);
00219         char service[128];
00220         sprintf(service, "%s_%05d", DBUS_SERVICE, pid);
00221         char path[128];
00222         sprintf(path, "%s_%05d", DBUS_PATH, pid);
00223         char interface[128];
00224         sprintf(interface, "%s_%05d", DBUS_INTERFACE, pid);
00225 
00226         eripcClient = eripc_client_context_new(
00227                 name,
00228                 "1.0",
00229                 service,
00230                 path,
00231                 interface,
00232                 service_functions);
00233         return (eripcClient != NULL);
00234     }
00235 
00236 
00237     void ipc_unset_services(void)
00238     {
00239         ipc_gconf_finalize(); // destruct gconf client
00240         eripc_client_context_free(eripcClient, service_functions);
00241         //menu_destroy();
00242     }
00243 
00244     gboolean ipc_sys_busy(gboolean busy)  //  Send message sysSetBusy to system daemon
00245     {
00246         LOGPRINTF("entry %d", busy);
00247 
00248         if (busy)
00249         {
00250             return eripc_sysd_set_busy(eripcClient, "delaydialog", NULL);
00251         }
00252         else
00253         {
00254             return eripc_sysd_reset_busy(eripcClient);
00255         }
00256     }
00257 
00258     gboolean ipc_sys_bg_busy(gboolean busy)  // set/unset busy state without dialog
00259     {
00260         LOGPRINTF("entry %d", busy);
00261 
00262         if (busy)
00263         {
00264             return eripc_sysd_set_bg_busy(eripcClient);
00265         }
00266         else
00267         {
00268             return eripc_sysd_reset_bg_busy(eripcClient);
00269         }
00270     }
00271 
00272     const char* ipc_get_mountpoint()
00273     {
00274         if (0 == g_strcmp0(gMountpoint, ""))
00275         {
00276             g_assert(eripcClient);
00277             eripc_event_info_t* reply = NULL;
00278             eripc_error_t result = eripc_send_varargs_and_wait( eripcClient->context,
00279                     &reply,                // reply handler
00280                     ERIPC_BUS_SESSION,
00281                     DBUS_SERVICE_SYSTEM_CONTROL,
00282                     "sysGetCardMountPoint",
00283                     ERIPC_TYPE_INVALID);
00284             if (result != ERIPC_ERROR_SUCCESS)
00285             {
00286                 ERRORPRINTF("%s: eripc_send_varargs returns [%d]", __func__, result);
00287                 return NULL;
00288             }
00289             g_assert(reply);
00290             g_assert(reply->args);
00291             g_assert(reply->args[0].type == ERIPC_TYPE_STRING);
00292             const char* valuestr = reply->args[0].value.s;
00293             if (valuestr[0] != 0) 
00294                 strncpy(gMountpoint, valuestr, 88-1);
00295             LOGPRINTF("mountpoint %s", gMountpoint);
00296             eripc_event_info_free(eripcClient->context, reply);
00297         }
00298         return gMountpoint;
00299     }
00300 
00301 
00302     void ipc_sys_startup_complete(int xid)
00303     {
00304         // before sending startup_complete contruct default values;
00305         gMountpoint[0] = 0;
00306         gPensize = GCONF_DEFAULT_PEN_SIZE;
00307 
00308         ipc_gconf_initialize(); // initalize gconf client
00309         ipc_gconf_read();
00310 
00311         // send startup_complete
00312         g_xid = xid;
00313         eripc_sysd_startup_complete( eripcClient, getpid(), FALSE, xid);
00314 
00315         // re-read initialized items
00316         menu_show();
00317     }
00318 
00319     void ipc_change_filename(const gchar* filename, const gchar* label)
00320     {
00321         g_assert(g_xid);
00322         eripc_send_varargs(eripcClient->context, NULL, NULL, ERIPC_BUS_SESSION,
00323                 DBUS_SERVICE_SYSTEM_CONTROL, "renameTask",
00324                 ERIPC_TYPE_INT, g_xid,
00325                 ERIPC_TYPE_STRING, filename,
00326                 ERIPC_TYPE_STRING, label,
00327                 ERIPC_TYPE_INVALID);
00328     }
00329 
00330 
00331     PenSize ipc_get_pensize(void)
00332     {
00333         PenSize size = gPensize;
00334         LOGPRINTF("get_pensize %d", size);
00335         if ((size < PEN_FINE) || (size > PEN_XLARGE) ) 
00336         {
00337             WARNPRINTF("invalid pensize setting, using default");
00338             size = GCONF_DEFAULT_PEN_SIZE;
00339         }
00340         return size;
00341     }
00342 
00343 
00344     void ipc_set_pensize(const PenSize new_pen_size)
00345     {
00346         if ((gPensize < PEN_FINE) || (gPensize > PEN_XLARGE) )
00347         {
00348             WARNPRINTF("invalid new pen size, using default");
00349         }
00350         else
00351         {
00352             gPensize = new_pen_size;
00353             ipc_gconf_write(); 
00354             // write here: 
00355             // because we can have multiple instances, and on window switch the 
00356             // on_window_activate of the selected comes before the on_window_deactivate 
00357             // of the current 
00358         }
00359         LOGPRINTF("set pensize %d", gPensize);
00360     }
00361 
00362     np_rotation ipc_get_rotation(void)
00363     {
00364         LOGPRINTF("entry");
00365 
00366         eripc_error_t retval;
00367         eripc_event_info_t *info = NULL;
00368         np_rotation rotation = NP_PORTRAIT;
00369 
00370         retval = eripc_send_varargs_and_wait(eripcClient->context,
00371                 &info,
00372                 ERIPC_BUS_SESSION,
00373                 DBUS_SERVICE_SYSTEM_CONTROL,
00374                 "sysGetOrientation",
00375                 ERIPC_TYPE_INVALID);
00376 
00377         if (retval == ERIPC_ERROR_SUCCESS)
00378         {
00379             const eripc_arg_t *arg_array = info->args;
00380             if (arg_array[0].type == ERIPC_TYPE_STRING)
00381             {
00382                 const char* orientation = arg_array[0].value.s;
00383                 if (orientation)
00384                 {
00385                     if ( 0 == strcasecmp( orientation, "landscape_anticlockwise") )
00386                     {
00387                         rotation = NP_ANTICLOCKWISE;
00388                     }
00389                     else if ( 0 == strcasecmp( orientation, "landscape_clockwise") )
00390                     {
00391                         rotation = NP_CLOCKWISE;
00392                     }
00393                     else
00394                     {
00395                         rotation = NP_PORTRAIT;
00396                     }
00397                 }
00398             }
00399         }
00400 
00401         LOGPRINTF("exit %d", rotation);
00402         return rotation;
00403     }
00404 
00405     // popup menu and toolbar
00406     static void ipc_menu_update_toolbar(void)
00407     {
00408         eripc_send_varargs(eripcClient->context, NULL, NULL, ERIPC_BUS_SESSION,
00409                 DBUS_SERVICE_POPUP_MENU, "updatesFinished", ERIPC_TYPE_INVALID);
00410     }
00411 
00412     void ipc_menu_set_pagecounter(int cur_page, int num_pages)
00413     {
00414         gboolean boundary_check = (num_pages != cur_page); // allow next to create new page
00415         eripc_menu_set_pagecounter(eripcClient, cur_page, num_pages, boundary_check);
00416         ipc_menu_update_toolbar();  
00417 
00418         if (num_pages == 1)
00419         {
00420             eripc_menu_set_item_state(eripcClient, ITEM_ACTION_GOTOPAGE, GROUP_ACTIONS, MENU_STATE_DISABLED );
00421         }
00422         else 
00423         {
00424             eripc_menu_set_item_state(eripcClient, ITEM_ACTION_GOTOPAGE, GROUP_ACTIONS, MENU_STATE_NORMAL );
00425         }
00426     }
00427 
00428     void menu_init(int pid, gpointer appwindow) 
00429     {
00430         LOGPRINTF("entry");
00431         g_assert( appwindow != 0 ); 
00432         if (appwindow == 0)
00433         {
00434             fprintf(stderr, "menu without window\n");
00435             return;
00436         }
00437         gInstance = static_cast <notepad::CNotepadWindow*> (appwindow);
00438 
00439         ipc_menu = g_strdup_printf("%s_%05d", MENU, pid);
00440         // MENU
00441         // |
00442         // |-- Pen type
00443         eripc_menu_add_group(eripcClient, GROUP_PEN_TYPE,       "",             "pen_type"          );
00444         eripc_menu_add_item(eripcClient, ITEM_PEN   ,           GROUP_PEN_TYPE, "pen"               ); 
00445         eripc_menu_add_item(eripcClient, ITEM_ERASER,           GROUP_PEN_TYPE, "eraser"            ); 
00446         // |
00447         // |-- PEN 
00448         eripc_menu_add_group(eripcClient, GROUP_PEN,            "",             "notepad_pen_menu"  ); 
00449         eripc_menu_add_group(eripcClient, GROUP_PEN2,           GROUP_PEN,      "tools_drawing"     ); 
00450         //     |
00451         //     |-- line sizes 
00452         eripc_menu_add_group(eripcClient, GROUP_PEN_SIZE,       GROUP_PEN2,     "notepad_pen_size"  ); 
00453         eripc_menu_add_item(eripcClient, ITEM_PEN_FINE,         GROUP_PEN_SIZE, "stylus_1"          ); 
00454         eripc_menu_add_item(eripcClient, ITEM_PEN_SMALL,        GROUP_PEN_SIZE, "stylus_2"          ); 
00455         eripc_menu_add_item(eripcClient, ITEM_PEN_MEDIUM,       GROUP_PEN_SIZE, "stylus_3"          ); 
00456         eripc_menu_add_item(eripcClient, ITEM_PEN_LARGE,        GROUP_PEN_SIZE, "stylus_4"          ); 
00457         eripc_menu_add_item(eripcClient, ITEM_PEN_XLARGE,       GROUP_PEN_SIZE, "stylus_5"          ); 
00458         // |
00459         // |-- actions
00460         eripc_menu_add_group(eripcClient, GROUP_ACTIONS,        "",             "notepad_actions"   );
00461         eripc_menu_add_item(eripcClient, ITEM_ACTION_GOTOPAGE,  GROUP_ACTIONS,  "goto_page"         );
00462         eripc_menu_add_item(eripcClient, ITEM_ACTION_INSERTPAGE,GROUP_ACTIONS,  "insert_page"       );
00463         eripc_menu_add_item(eripcClient, ITEM_ACTION_DELETEPAGE,GROUP_ACTIONS,  "delete_page"       );
00464         eripc_menu_add_item(eripcClient, ITEM_ACTION_CLEARPAGE, GROUP_ACTIONS,  "clear_page"        );
00465         eripc_menu_add_item(eripcClient, ITEM_ACTION_RENAME,    GROUP_ACTIONS,  "rename"            );
00466 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00467         eripc_menu_add_item(eripcClient, ITEM_ACTION_CLOSE,     GROUP_ACTIONS,  "close"             );
00468 #endif
00469 
00470         // add menus
00471         eripc_menu_add_menu(eripcClient, ipc_menu, GROUP_ACTIONS, GROUP_PEN, GROUP_PEN_TYPE, NULL);
00472 
00473         // localize text
00474         menu_set_text();
00475 
00476         menu_show();
00477         LOGPRINTF("exit");
00478     }
00479 
00480 
00481     void menu_destroy(void)
00482     {
00483         eripc_menu_remove_menu(eripcClient, ipc_menu);
00484     }
00485 
00486 
00487 
00488     //============================================================================
00489     // Local Function Definitions
00490     //============================================================================
00491 
00492     // gconf
00493     static void ipc_gconf_initialize(void) // initalize gconf client
00494     {
00495         LOGPRINTF("gconf_initialize");
00496         if (gClient == 0)
00497         {
00498             gClient = gconf_client_get_default();
00499         }
00500     }
00501 
00502     static void ipc_gconf_finalize(void) // destruct gconf client
00503     {
00504         LOGPRINTF("gconf_finalize");
00505         if (gClient != 0)
00506         {
00507             g_object_unref(G_OBJECT(gClient));
00508             gClient = 0;
00509         }
00510     }
00511 
00512     static void ipc_gconf_read(void) // read settings from gconf
00513     {
00514         LOGPRINTF("gconf_read");
00515         if (gClient)
00516         {
00517             gPensize = (PenSize) gconf_client_get_int(gClient, GCONF_PEN_SIZE, NULL);
00518             LOGPRINTF("getPenSize %d", gPensize);
00519             if ((gPensize < PEN_FINE) || (gPensize > PEN_XLARGE) )
00520             {
00521                 WARNPRINTF("invalid pensize setting, using default");
00522                 gPensize = GCONF_DEFAULT_PEN_SIZE;
00523             }
00524         }
00525     }
00526 
00527     static void ipc_gconf_write(void) // write settings to gconf 
00528     {
00529         LOGPRINTF("gconf_write pensize %d", gPensize);
00530         if (gClient)
00531         {
00532             (void) gconf_client_set_int(gClient, GCONF_PEN_SIZE, (gint) gPensize, NULL);
00533         }
00534     }
00535 
00536     // popupmenu and toolbar
00537 
00538 
00539     static gboolean ipc_status_set_stylus( const char *state )
00540     {
00541         g_return_val_if_fail( (state != NULL), FALSE);
00542         return eripc_menu_set_statusitem_state(eripcClient, "statusbar_stylus", state);
00543     }
00544 
00545     static void menu_set_text(void)
00546     {
00547         // MENU
00548         // |
00549         // |-- Pen type
00550         eripc_menu_set_item_label(eripcClient, ITEM_PEN,                GROUP_PEN_TYPE, _("Pen"         ));
00551         eripc_menu_set_item_label(eripcClient, ITEM_ERASER,             GROUP_PEN_TYPE, _("Eraser"      ));
00552         // |
00553         // |-- PEN 
00554         eripc_menu_set_group_label(eripcClient, GROUP_PEN2, _("Pen Size")); 
00555         //     |
00556         //     |-- line sizes options
00557         eripc_menu_set_item_label(eripcClient, ITEM_PEN_FINE,           GROUP_PEN_SIZE, _("Fine"        ));
00558         eripc_menu_set_item_label(eripcClient, ITEM_PEN_SMALL,          GROUP_PEN_SIZE, _("Small"       ));
00559         eripc_menu_set_item_label(eripcClient, ITEM_PEN_MEDIUM,         GROUP_PEN_SIZE, _("Medium"      ));
00560         eripc_menu_set_item_label(eripcClient, ITEM_PEN_LARGE,          GROUP_PEN_SIZE, _("Large"       ));
00561         eripc_menu_set_item_label(eripcClient, ITEM_PEN_XLARGE,         GROUP_PEN_SIZE, _("X-Large"     ));
00562         // |
00563         // |-- actions
00564         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_GOTOPAGE,    GROUP_ACTIONS,  _("Go to Page..."));
00565         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_INSERTPAGE,  GROUP_ACTIONS,  _("Insert Page" ));
00566         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_CLEARPAGE,   GROUP_ACTIONS,  _("Clear Page..."  ));
00567         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_DELETEPAGE,  GROUP_ACTIONS,  _("Delete Page..."  ));
00568         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_RENAME,      GROUP_ACTIONS,  _("Rename..."   ));
00569 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00570         eripc_menu_set_item_label(eripcClient, ITEM_ACTION_CLOSE,       GROUP_ACTIONS,  _("Close" ));
00571 #endif    
00572     }
00573 
00574 
00575     static void menu_show(void)
00576     {
00577         LOGPRINTF("entry");
00578         // show selections
00579         gboolean scribblemode = gInstance->get_scribble_mode();
00580         if (scribblemode)
00581         {
00582             eripc_menu_set_item_state(eripcClient, ITEM_PEN, GROUP_PEN_TYPE, MENU_STATE_SELECTED );
00583             eripc_menu_set_item_state(eripcClient, ITEM_ERASER, GROUP_PEN_TYPE, MENU_STATE_NORMAL );
00584             ipc_status_set_stylus( STYLUS_PEN );
00585             eripc_send_varargs(eripcClient->context, NULL, NULL, ERIPC_BUS_SESSION,
00586                     DBUS_SERVICE_POPUP_MENU, "updatesFinished", ERIPC_TYPE_INVALID);
00587         }
00588         else
00589         {
00590             eripc_menu_set_item_state(eripcClient, ITEM_ERASER, GROUP_PEN_TYPE, MENU_STATE_SELECTED );
00591             eripc_menu_set_item_state(eripcClient, ITEM_PEN, GROUP_PEN_TYPE, MENU_STATE_NORMAL );
00592             ipc_status_set_stylus( STYLUS_ERASER );
00593             eripc_send_varargs(eripcClient->context, NULL, NULL, ERIPC_BUS_SESSION,
00594                     DBUS_SERVICE_POPUP_MENU, "updatesFinished", ERIPC_TYPE_INVALID);
00595         }
00596 
00597         PenSize ps = ipc_get_pensize();
00598         switch (ps)
00599         {
00600             case PEN_FINE:
00601                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_FINE,   GROUP_PEN_SIZE, MENU_STATE_SELECTED );
00602                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_SMALL,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00603                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_MEDIUM, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00604                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_LARGE,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00605                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_XLARGE, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00606                 break;
00607             case PEN_SMALL:
00608                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_FINE,   GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00609                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_SMALL,  GROUP_PEN_SIZE, MENU_STATE_SELECTED );
00610                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_MEDIUM, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00611                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_LARGE,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00612                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_XLARGE, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00613                 break;
00614             case PEN_MEDIUM:
00615                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_FINE,   GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00616                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_SMALL,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00617                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_MEDIUM, GROUP_PEN_SIZE, MENU_STATE_SELECTED );
00618                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_LARGE,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00619                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_XLARGE, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00620                 break;
00621             case PEN_LARGE:
00622                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_FINE,   GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00623                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_SMALL,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00624                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_MEDIUM, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00625                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_LARGE,  GROUP_PEN_SIZE, MENU_STATE_SELECTED );
00626                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_XLARGE, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00627                 break;
00628             case PEN_XLARGE:
00629                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_FINE,   GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00630                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_SMALL,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00631                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_MEDIUM, GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00632                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_LARGE,  GROUP_PEN_SIZE, MENU_STATE_NORMAL );
00633                 eripc_menu_set_item_state(eripcClient, ITEM_PEN_XLARGE, GROUP_PEN_SIZE, MENU_STATE_SELECTED );
00634                 break;
00635             default:
00636                 WARNPRINTF("unsupported pensize\n");
00637         }
00638 
00639         eripc_menu_show_menu(eripcClient, ipc_menu);
00640         gInstance->update_page_counter();
00641         ipc_menu_update_toolbar();  
00642 
00643         LOGPRINTF("exit");
00644     }
00645 
00646     void menu_block(gboolean block)
00647     {
00648         if (block)
00649         {
00650             eripc_sysd_set_menu_state(eripcClient, "block");
00651         }
00652         else
00653         {
00654             eripc_sysd_set_menu_state(eripcClient, "unblock");
00655         }
00656     }
00657 
00658 
00659 
00660     //----------------------------------------------------------------------------
00661     // Signal/message handlers
00662     //----------------------------------------------------------------------------
00663 
00664     static void on_page_change( 
00665             eripc_context_t          *context,
00666             const eripc_event_info_t *info,
00667             void                     *user_data )
00668     {
00669         const eripc_arg_t *arg_array = info->args;
00670         g_return_if_fail(arg_array[0].type == ERIPC_TYPE_STRING);
00671         gchar* direction = arg_array[0].value.s;
00672 
00673         if (strcmp(direction, "prev") == 0) 
00674         {   
00675             gInstance->pageflip_back();
00676         }
00677         if (strcmp(direction, "next") == 0) 
00678         {
00679             gInstance->pageflip_forward();
00680         }
00681     }
00682 
00683 
00684     static void on_window_activated( 
00685             eripc_context_t          *context,
00686             const eripc_event_info_t *info,
00687             void                     *user_data )
00688     {
00689         LOGPRINTF("entry");
00690 
00691         (void) gInstance->save();
00692         ipc_gconf_read();
00693         menu_show();
00694         gInstance->update_page_counter();
00695         ipc_menu_update_toolbar();  
00696 
00697         LOGPRINTF("exit");
00698     }
00699 
00700 
00701     static void on_window_deactivated( 
00702             eripc_context_t          *context,
00703             const eripc_event_info_t *info,
00704             void                     *user_data )
00705     {
00706         LOGPRINTF("entry");
00707 
00708         (void) gInstance->save();
00709         ipc_gconf_write();
00710 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00711         gInstance->quit();
00712 #endif
00713 
00714         LOGPRINTF("exit");
00715     }
00716 
00717 
00718     static void on_menu_item( 
00719             eripc_context_t          *context,
00720             const eripc_event_info_t *info,
00721             void                     *user_data )
00722     {
00723         g_return_if_fail(info->args);
00724         g_return_if_fail(info->args[0].type == ERIPC_TYPE_STRING);
00725         g_return_if_fail(info->args[1].type == ERIPC_TYPE_STRING);
00726         g_return_if_fail(info->args[2].type == ERIPC_TYPE_STRING);
00727         g_return_if_fail(info->args[3].type == ERIPC_TYPE_STRING);
00728 
00729         g_return_if_fail(info->args[0].value.s != 0);
00730         g_return_if_fail(info->args[1].value.s != 0);
00731         g_return_if_fail(info->args[2].value.s != 0);
00732         g_return_if_fail(info->args[3].value.s != 0);
00733 
00734         const eripc_arg_t *arg_array = info->args;
00735         const char        *item      = arg_array[0].value.s;
00736         const char        *group     = arg_array[1].value.s;
00737         const char        *menu      = arg_array[2].value.s;
00738         const char        *state     = arg_array[3].value.s;
00739 
00740         LOGPRINTF("entry: on_menu_item: item [%s] group [%s] menu [%s] state [%s]", item, group, menu, state);
00741 
00742         if (item && group && menu && state)
00743         {
00744             if ( strcmp(group, GROUP_PEN_TYPE) == 0 )
00745             {
00746                 if ( strcmp(state, MENU_STATE_NORMAL) == 0 )
00747                 {
00748                     if ( strcmp(item, ITEM_PEN) == 0 )
00749                     {
00750                         LOGPRINTF("pen");
00751                         gInstance->set_scribble_mode(TRUE);
00752                     }
00753                     else if ( strcmp(item, ITEM_ERASER  ) == 0 )
00754                     {
00755                         LOGPRINTF("erase");
00756                         gInstance->set_scribble_mode(FALSE);
00757                     }
00758                 }
00759                 menu_show();
00760             }
00761             else if ( strcmp(group, GROUP_PEN_SIZE) == 0 )
00762             {
00763 
00764                 if ( strcmp(state, MENU_STATE_NORMAL) == 0 )
00765                 {
00766                     if ( strcmp(item, ITEM_PEN_FINE) == 0 )
00767                     {
00768                         LOGPRINTF("pen_fine");
00769                         ipc_set_pensize(PEN_FINE);
00770                     }
00771                     else if ( strcmp(item, ITEM_PEN_SMALL) == 0 )
00772                     {
00773                         LOGPRINTF("pen_small");
00774                         ipc_set_pensize(PEN_SMALL);
00775                     }
00776                     else if ( strcmp(item, ITEM_PEN_MEDIUM) == 0 )
00777                     {
00778                         LOGPRINTF("pen_medium");
00779                         ipc_set_pensize(PEN_MEDIUM);
00780                     }
00781                     else if ( strcmp(item, ITEM_PEN_LARGE) == 0 )
00782                     {
00783                         LOGPRINTF("pen_large");
00784                         ipc_set_pensize(PEN_LARGE);
00785                     }
00786                     else if ( strcmp(item, ITEM_PEN_XLARGE) == 0 )
00787                     {
00788                         LOGPRINTF("pen_xlarge");
00789                         ipc_set_pensize(PEN_XLARGE);
00790                     }
00791                 }
00792                 // Do not stay on eraser mode
00793                 gInstance->set_scribble_mode(TRUE);
00794                 menu_show();
00795             }
00796             else if ( strcmp(group, GROUP_ACTIONS) == 0 )
00797             {
00798                 if ( strcmp(state, MENU_STATE_NORMAL) == 0 )
00799                 {
00800                     if ( strcmp(item, ITEM_ACTION_RENAME ) == 0 )
00801                     {
00802                         LOGPRINTF("rename");
00803                         gInstance->rename();
00804                     }
00805 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00806                     else if ( strcmp(item, ITEM_ACTION_CLOSE ) == 0 )
00807                     {
00808                         LOGPRINTF("close");
00809                         (void) gInstance->save();
00810                         gInstance->quit();
00811                     }
00812 #endif                
00813                     else if ( strcmp(item, ITEM_ACTION_GOTOPAGE ) == 0 )
00814                     {
00815                         LOGPRINTF("gotopage");
00816                         gInstance->goto_page();
00817                     }
00818                     else if ( strcmp(item, ITEM_ACTION_INSERTPAGE ) == 0 )
00819                     {
00820                         LOGPRINTF("insertpage");
00821                         gInstance->insert_page();
00822                     }
00823                     else if ( strcmp(item, ITEM_ACTION_CLEARPAGE ) == 0 )
00824                     {
00825                         LOGPRINTF("clearpage");
00826                         gInstance->clear_current_page();
00827                     }
00828                     else if ( strcmp(item, ITEM_ACTION_DELETEPAGE ) == 0 )
00829                     {
00830                         LOGPRINTF("deletepage");
00831                         gInstance->delete_current_page();
00832                     }
00833                     else
00834                     {
00835                         fprintf(stderr, "ignore state [%s] item [%s][%s]", state, item, group);
00836                     }
00837                 }
00838                 else
00839                 {
00840                     fprintf(stderr, "unexpected menu group [%s]", group);
00841                 }
00842             }
00843             ipc_menu_update_toolbar();  
00844         }
00845     }
00846 
00847     static void on_changed_locale( 
00848             eripc_context_t          *context,
00849             const eripc_event_info_t *info,
00850             void                     *user_data )
00851     {
00852         menu_set_text();
00853     }
00854 
00855     static void on_changed_pen( 
00856             eripc_context_t          *context,
00857             const eripc_event_info_t *info,
00858             void                     *user_data )
00859     {
00860         g_return_if_fail(info->args);
00861         g_return_if_fail(info->args[0].type == ERIPC_TYPE_STRING);
00862 
00863         const eripc_arg_t *arg_array = info->args;
00864         const char        *item      = arg_array[0].value.s;
00865         const char        *value     = arg_array[1].value.s;
00866 
00867         LOGPRINTF("entry: on_changed_pen: item [%s] value [%s]", item, value);
00868         if ( strcmp(item, "statusbar_stylus") == 0 )
00869         {
00870             if ( strcmp(value, STYLUS_PEN) == 0 )
00871             {
00872                 LOGPRINTF("pen");
00873                 gInstance->set_scribble_mode(FALSE); //toggle
00874                 menu_show();
00875             }
00876             else if ( strcmp(value, STYLUS_ERASER  ) == 0 )
00877             {
00878                 LOGPRINTF("erase");
00879                 gInstance->set_scribble_mode(TRUE); //toggle
00880                 menu_show();
00881             }
00882         }
00883     }
00884 
00885     static void on_prepare_unmount( 
00886             eripc_context_t          *context,
00887             const eripc_event_info_t *info,
00888             void                     *user_data )
00889     {
00890         LOGPRINTF("entry");
00891         (void) gInstance->save(true);
00892         gInstance->quit();
00893         LOGPRINTF("exit");
00894     }
00895 
00896     static void on_volume_unmounted( 
00897             eripc_context_t          *context,
00898             const eripc_event_info_t *info,
00899             void                     *user_data )
00900     {
00901         LOGPRINTF("entry");
00902         gInstance->quit();
00903         LOGPRINTF("exit");
00904     }
00905 
00906     static void on_prepare_standby( 
00907             eripc_context_t          *context,
00908             const eripc_event_info_t *info,
00909             void                     *user_data )
00910     {
00911         LOGPRINTF("entry");
00912         (void) gInstance->save();
00913         LOGPRINTF("exit");
00914     }
00915 
00916     // -- flipbar and orientation -- 
00917 
00918     /* @brief Called when the display's orientation has changed
00919      *
00920      * Application may need to adapt its screen size, coordinates and/or origin.
00921      * Possible values: "portrait", "landscape_clockwise", "landscape_anticlockwise"
00922      */
00923     static void on_changed_orientation( 
00924             eripc_context_t          *context,
00925             const eripc_event_info_t *info,
00926             void                     *user_data )
00927     {
00928         LOGPRINTF("entry");
00929 
00930         const eripc_arg_t *arg_array = info->args;
00931         if (arg_array[0].type == ERIPC_TYPE_STRING)
00932         {
00933             const char* orientation = arg_array[0].value.s;
00934             if (orientation)
00935             {
00936                 if ( strcmp(orientation, "portrait") == 0)
00937                 {
00938 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00939                     gboolean is_inverted = ipc_sys_is_pageturn_inverted();
00940                     (void) gInstance->set_pageturn_inverted(is_inverted);
00941 #else
00942                     ;
00943 #endif 
00944                 }
00945                 else
00946                 {
00947                     // landscapee
00948 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00949                     (void) gInstance->set_pageturn_inverted(FALSE);
00950 #else           
00951                     ;
00952 #endif 
00953                 }
00954                 // Note: dont call set_rotation from here, window gets configure event.
00955                 // Note: timing of this on_changed_orientation depends on rotation direction.
00956             }
00957         }
00958         LOGPRINTF("exit");
00959     }
00960 
00961 
00962 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00963     static void on_sys_changed_pageturn_inverted(  eripc_context_t *context,
00964             const eripc_event_info_t *info,
00965             void *user_data)
00966     {
00967         LOGPRINTF("entry");
00968 
00969         const eripc_arg_t *arg_array = info->args;
00970 
00971         if (arg_array[0].type == ERIPC_TYPE_BOOL)
00972         {
00973             gboolean is_inverted = arg_array[0].value.b;
00974             if ( ipc_sys_is_in_portrait_mode() )
00975             {
00976                 (void) gInstance->set_pageturn_inverted(is_inverted);
00977             }
00978         }
00979     }
00980 #endif 
00981 
00982 
00983     // the following functions queries sysd about the
00984     // custom setting of the flipbar.
00985 
00986     // Function: ipc_sys_is_pageturn_inverted()
00987     //
00988     // Return value: False -> pageturning is not inverted i.e. left to right gives next page
00989     //               True  -> pageturning is     inverted i.e. left to right gives previous page
00990     // Intended use: during application initialisation and only useful in portrait reading mode
00991 
00992     gboolean ipc_sys_is_pageturn_inverted()
00993     {
00994         gboolean result = FALSE;
00995 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00996         eripc_error_t retval;
00997         eripc_event_info_t* info = NULL;
00998 
00999         LOGPRINTF("entry");
01000 
01001         retval = eripc_send_varargs_and_wait(eripcClient->context,
01002                 &info,
01003                 ERIPC_BUS_SESSION,
01004                 DBUS_SERVICE_SYSTEM_CONTROL,
01005                 "sysGetPageturnInverted",
01006                 ERIPC_TYPE_INVALID);
01007 
01008         if (retval != ERIPC_ERROR_SUCCESS)
01009         {
01010             ERRORPRINTF("Error launching eripc handler");
01011         }
01012         else if (info == NULL || info->args == NULL)
01013         {
01014             ERRORPRINTF("sysd returns OK but no reply structure");
01015         }
01016         else
01017         {
01018             const eripc_arg_t *arg_array = info->args;
01019 
01020             if (arg_array[0].type == ERIPC_TYPE_BOOL)
01021             {
01022                 result = (gboolean) arg_array[0].value.b;
01023             }
01024             else
01025             {
01026                 result = FALSE ;
01027             }
01028         }
01029 
01030         eripc_event_info_free(eripcClient->context, info);
01031 #endif 
01032         return result;
01033     }
01034 
01035     // Function: ipc_sys_is_in_portrait_mode()
01036     //
01037     // Return value: False -> the device is in landscape mode i.e. flipbar up should be interpreted as previous page.
01038     //               True  ->  the device is in portrait mode i.e. flipbar interpretation should depend on sys_is_pageturn_inverted result.
01039     // Intended use: during application initialisation
01040     gboolean ipc_sys_is_in_portrait_mode(void)
01041     {
01042 
01043         gboolean result = TRUE;
01044 
01045         eripc_error_t retval;
01046         eripc_event_info_t* info = NULL;
01047 
01048         LOGPRINTF("entry");
01049 
01050         retval = eripc_send_varargs_and_wait(eripcClient->context,
01051                 &info,
01052                 ERIPC_BUS_SESSION,
01053                 DBUS_SERVICE_SYSTEM_CONTROL,
01054                 "sysGetOrientation",
01055                 ERIPC_TYPE_INVALID);
01056 
01057         if (retval != ERIPC_ERROR_SUCCESS)
01058         {
01059             ERRORPRINTF("Error launching eripc handler");
01060         }
01061         else if (info == NULL || info->args == NULL)
01062         {
01063             ERRORPRINTF("sysd returns OK but no reply structure");
01064         }
01065         else
01066         {
01067             const eripc_arg_t *arg_array = info->args;
01068 
01069             if (arg_array[0].type == ERIPC_TYPE_STRING)
01070             {
01071                 if ( strcmp("portrait", arg_array[0].value.s) == 0 )
01072                 {
01073                     result = TRUE;
01074                 }
01075                 else
01076                 {
01077                     result = FALSE;
01078                 }
01079             }
01080             else
01081             {
01082                 result = FALSE ;
01083             }
01084         }
01085         eripc_event_info_free(eripcClient->context, info);
01086         return result;
01087     }
01088 
01089 } //namespace
Generated by  doxygen 1.6.2-20100208