erbrowser/src/menu.c

Go to the documentation of this file.
00001 /*
00002  * File Name: menu.c
00003  */
00004 
00005 /*
00006  * This file is part of erbrowser.
00007  *
00008  * erbrowser 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  * erbrowser 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) 2009 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <stdio.h>
00035 #include <unistd.h>
00036 
00037 // ereader include files, between < >
00038 
00039 // local include files, between " "
00040 #include "log.h"
00041 #include "i18n.h"
00042 #include "ipc.h"
00043 #include "main.h"
00044 #include "menu.h"
00045 #include "view.h"
00046 
00047 #define UNUSED(x) (void)(x)
00048 
00049 
00050 //----------------------------------------------------------------------------
00051 // Type Declarations
00052 //----------------------------------------------------------------------------
00053 
00054 
00055 //----------------------------------------------------------------------------
00056 // Constants
00057 //----------------------------------------------------------------------------
00058 
00059 // menus for application, must be unique
00060 static const char *MENU_MAIN                = "erbrowser_menu_main";
00061                                             
00062 // menu groups, must be unique
00063 static const char *GROUP_ACTIONS            = "erbrowser_actions";
00064                                             
00065 // menu items
00066 static const char *GROUP_TOOLS              = "erbrowser_tools";
00067 static const char *GROUP_ZOOM_FONT_TOOLS    = "erbrowser_zoom";
00068 static const char *ITEM_FONT_SIZE_SMALL     = "zoom_small";
00069 static const char *ITEM_FONT_SIZE_MEDIUM    = "zoom_medium";
00070 static const char *ITEM_FONT_SIZE_LARGE     = "zoom_large";
00071 static const char *ITEM_FONT_SIZE_XLARGE    = "zoom_xlarge";
00072 static const char *GROUP_TOOLS_FONTSIZE     = "erbrowser_font_size";
00073 
00074 //   group "Actions"                        
00075 static const char *ITEM_ACTION_BACK         = "history_back";
00076 static const char *ITEM_ACTION_FORWARD      = "history_forward";
00077 static const char *ITEM_ACTION_RELOAD       = "reload";
00078 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00079 static const char *ITEM_ACTION_FULL_SCREEN  = "mode_full_screen";
00080 static const char *ITEM_ACTION_CLOSE        = "close";
00081 #endif
00082                                             
00083 // item states                              
00084 static const char *STATE_NORMAL             = "normal";
00085 static const char *STATE_SELECTED           = "selected";
00086 
00087 static const gfloat ZOOM_LEVEL_SMALL        = 0.8f;
00088 static const gfloat ZOOM_LEVEL_MEDIUM       = 1.0f; // default
00089 static const gfloat ZOOM_LEVEL_LARGE        = 1.2f;
00090 static const gfloat ZOOM_LEVEL_XLARGE       = 1.5f;
00091 
00092 
00093 //----------------------------------------------------------------------------
00094 // Static Variables
00095 //----------------------------------------------------------------------------
00096 
00097 
00098 //============================================================================
00099 // Local Function Definitions
00100 //============================================================================
00101 
00102 
00103 //============================================================================
00104 // Functions Implementation
00105 //============================================================================
00106 
00107 // initialise popup menu
00108 void menu_init(void)
00109 {
00110     LOGPRINTF("entry");
00111 
00112     const char *group;
00113     group = GROUP_TOOLS;
00114     ipc_menu_add_group( group,                  "",    "folder"               );
00115     ipc_menu_add_group( GROUP_TOOLS_FONTSIZE,   group, "tools_character"      );  // reuse UDS icon
00116     
00117     group = GROUP_ZOOM_FONT_TOOLS;
00118     ipc_menu_add_group( group,  GROUP_TOOLS_FONTSIZE,  "folder"               );
00119     ipc_menu_add_item ( ITEM_FONT_SIZE_SMALL,   group, ITEM_FONT_SIZE_SMALL   );
00120     ipc_menu_add_item ( ITEM_FONT_SIZE_MEDIUM,  group, ITEM_FONT_SIZE_MEDIUM  );
00121     ipc_menu_set_item_state( ITEM_FONT_SIZE_MEDIUM, group, STATE_SELECTED     );
00122     ipc_menu_add_item ( ITEM_FONT_SIZE_LARGE,   group, ITEM_FONT_SIZE_LARGE   );
00123     ipc_menu_add_item ( ITEM_FONT_SIZE_XLARGE,  group, ITEM_FONT_SIZE_XLARGE  );
00124 
00125     group = GROUP_ACTIONS;
00126     ipc_menu_add_group( group,                  "",    "folder"               );
00127     ipc_menu_add_item ( ITEM_ACTION_BACK,       group, ITEM_ACTION_BACK       );
00128     ipc_menu_add_item ( ITEM_ACTION_FORWARD,    group, ITEM_ACTION_FORWARD    );
00129     ipc_menu_add_item ( ITEM_ACTION_RELOAD,     group, ITEM_ACTION_RELOAD     );
00130 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00131     ipc_menu_add_item ( ITEM_ACTION_FULL_SCREEN, group, ITEM_ACTION_FULL_SCREEN );
00132     ipc_menu_add_item ( ITEM_ACTION_CLOSE,       group, ITEM_ACTION_CLOSE       );
00133 #endif
00134 
00135     ipc_menu_add_menu ( MENU_MAIN, GROUP_ACTIONS, GROUP_TOOLS, NULL );
00136 
00137     menu_set_text();
00138     
00139     // set menu context
00140     menu_show();    
00141 }
00142 
00143 
00144 // remove the proper popup menu
00145 void menu_destroy(void)
00146 {
00147     LOGPRINTF("entry");
00148 
00149     // remove the main menu
00150     ipc_remove_menu( MENU_MAIN );
00151 }
00152 
00153 
00154 // show the proper popup menu
00155 void menu_show(void)
00156 {
00157     LOGPRINTF("entry");
00158 
00159     // show the main menu
00160     ipc_menu_show_menu( MENU_MAIN );
00161 }
00162 
00163 
00164 void menu_set_full_screen(gboolean mode)
00165 {
00166     LOGPRINTF("entry");
00167 
00168 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00169     if (mode)
00170     {
00171         ipc_menu_set_item_state(ITEM_ACTION_FULL_SCREEN, GROUP_ACTIONS, STATE_SELECTED);
00172     }
00173     else
00174     {
00175         ipc_menu_set_item_state(ITEM_ACTION_FULL_SCREEN, GROUP_ACTIONS, STATE_NORMAL);
00176     }
00177 #else
00178     UNUSED(mode);
00179 #endif    
00180 }
00181 
00182 
00183 void menu_set_text(void)
00184 {
00185     LOGPRINTF("entry");
00186 
00187     const char *group;
00188     group = GROUP_TOOLS;
00189     ipc_menu_set_group_label( GROUP_TOOLS_FONTSIZE,         _("Adjust Font Size"));
00190 
00191     group = GROUP_ZOOM_FONT_TOOLS;
00192     ipc_menu_set_group_label( group,                        _("Actions")         );
00193     ipc_menu_set_item_label ( ITEM_FONT_SIZE_SMALL,  group, _("Small")           );
00194     ipc_menu_set_item_label ( ITEM_FONT_SIZE_MEDIUM, group, _("Medium")          );
00195     ipc_menu_set_item_label ( ITEM_FONT_SIZE_LARGE,  group, _("Large")           );
00196     ipc_menu_set_item_label ( ITEM_FONT_SIZE_XLARGE, group, _("X-Large")         );
00197 
00198     group = GROUP_ACTIONS;                                                     
00199     ipc_menu_set_group_label( group,                        _("Actions")         );
00200     ipc_menu_set_item_label ( ITEM_ACTION_BACK,    group,   _("Previous")        );
00201     ipc_menu_set_item_label ( ITEM_ACTION_FORWARD, group,   _("Next")            );
00202     ipc_menu_set_item_label ( ITEM_ACTION_RELOAD,  group,   _("Reload Page")     );
00203 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00204     ipc_menu_set_item_label ( ITEM_ACTION_FULL_SCREEN, group, _("Full Screen")   );
00205     ipc_menu_set_item_label ( ITEM_ACTION_CLOSE,   group,     _("Close")         );
00206 #endif
00207 }
00208 
00209 
00210 void menu_set_zoom_level(gfloat zoom_level)
00211 {
00212     const gchar *selected = NULL;
00213     
00214     // pick font size
00215     if (zoom_level <= ZOOM_LEVEL_SMALL)
00216         selected = ITEM_FONT_SIZE_SMALL;
00217     else if (zoom_level <= ZOOM_LEVEL_MEDIUM)
00218         selected = ITEM_FONT_SIZE_MEDIUM;
00219     else if (zoom_level <=  ZOOM_LEVEL_LARGE)
00220         selected = ITEM_FONT_SIZE_LARGE;
00221     else
00222         selected = ITEM_FONT_SIZE_XLARGE;
00223 
00224     // select font size in menu
00225     if (selected != ITEM_FONT_SIZE_SMALL)
00226         ipc_menu_set_item_state(ITEM_FONT_SIZE_SMALL,  GROUP_ZOOM_FONT_TOOLS, STATE_NORMAL);            
00227     if (selected != ITEM_FONT_SIZE_MEDIUM)
00228         ipc_menu_set_item_state(ITEM_FONT_SIZE_MEDIUM, GROUP_ZOOM_FONT_TOOLS, STATE_NORMAL);
00229     if (selected != ITEM_FONT_SIZE_LARGE)
00230         ipc_menu_set_item_state(ITEM_FONT_SIZE_LARGE,  GROUP_ZOOM_FONT_TOOLS, STATE_NORMAL);
00231     if (selected != ITEM_FONT_SIZE_XLARGE)
00232         ipc_menu_set_item_state(ITEM_FONT_SIZE_XLARGE, GROUP_ZOOM_FONT_TOOLS, STATE_NORMAL);
00233     if (selected) 
00234         ipc_menu_set_item_state(selected, GROUP_ZOOM_FONT_TOOLS, STATE_SELECTED);
00235 }
00236 
00237 
00238 //----------------------------------------------------------------------------
00239 // Callbacks from popupmenu
00240 //----------------------------------------------------------------------------
00241 
00242 // user has pressed a menu button
00243 void menu_on_item_activated ( const gchar *item,
00244                               const gchar *group,
00245                               const gchar *menu,
00246                               const gchar *state )
00247 {
00248     gboolean    ok = TRUE;
00249 
00250     LOGPRINTF("entry: item [%s] group [%s]", item, group);
00251 
00252     if ( strcmp(group, GROUP_ACTIONS) == 0 )
00253     {
00254         if ( strcmp(item, ITEM_ACTION_BACK) == 0 )
00255         {
00256             view_go_back();
00257         }
00258         else if ( strcmp(item, ITEM_ACTION_FORWARD) == 0 )
00259         {
00260             view_go_forward();
00261         }
00262         else if ( strcmp(item, ITEM_ACTION_RELOAD) == 0 )
00263         {
00264             view_reload();
00265         }
00266 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00267         else if ( strcmp(item, ITEM_ACTION_FULL_SCREEN) == 0 )
00268         {
00269             if ( strcmp(state, STATE_NORMAL) == 0 )
00270             {
00271                 view_full_screen(TRUE);
00272             }
00273             else if ( strcmp(state, STATE_SELECTED) == 0 )
00274             {
00275                 view_full_screen(FALSE);
00276             }
00277         }
00278         else if ( strcmp(item, ITEM_ACTION_CLOSE) == 0 )
00279         {
00280             // quit and exit application
00281             main_quit();
00282         }
00283 #endif
00284         else
00285         {
00286             WARNPRINTF("unexpected menu item [%s] in group [%s]", item, group);
00287             ok = FALSE;
00288         }
00289     }
00290     else if ( strcmp(group, GROUP_ZOOM_FONT_TOOLS) == 0 )
00291     {
00292         if ( strcmp(item, ITEM_FONT_SIZE_SMALL) == 0 )
00293         {
00294             view_set_zoom_level(ZOOM_LEVEL_SMALL);
00295         }
00296         else if ( strcmp(item, ITEM_FONT_SIZE_MEDIUM) == 0 )
00297         {
00298             view_set_zoom_level(ZOOM_LEVEL_MEDIUM);
00299         }
00300         else if ( strcmp(item, ITEM_FONT_SIZE_LARGE) == 0 )
00301         {
00302             view_set_zoom_level(ZOOM_LEVEL_LARGE);
00303         }
00304         else if ( strcmp(item, ITEM_FONT_SIZE_XLARGE) == 0 )
00305         {
00306             view_set_zoom_level(ZOOM_LEVEL_XLARGE);
00307         }
00308         else
00309         {
00310             WARNPRINTF("unexpected menu item [%s] in group [%s]", item, group);
00311             ok = FALSE;
00312         }
00313     }
00314     else
00315     {
00316         WARNPRINTF("unexpected menu group [%s]", group);
00317         ok = FALSE;
00318     }
00319 
00320     if (!ok)
00321     {
00322         WARNPRINTF("unhandled menu item.\n"
00323                                  "menu: %s\n"
00324                                  "group: %s\n"
00325                                  "item: %s\n"
00326                                  "state: %s",
00327                                menu,
00328                                group,
00329                                item,
00330                                state );
00331     }
00332 }
Generated by  doxygen 1.6.2-20100208