menutest.c

Go to the documentation of this file.
00001 /*
00002  * File Name: menutest.c
00003  */
00004 
00005 /*
00006  * This file is part of popupmenu.
00007  *
00008  * popupmenu 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  * popupmenu 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) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include "config.h"
00028 
00029 #include <glib.h>
00030 #include <stdlib.h> 
00031 #include <signal.h>
00032 #include <unistd.h>
00033 
00034 #include <liberipc/eripc.h>
00035 
00036 #include "i18n.h"
00037 
00038 #define DBUS_SERVICE            "com.irexnet.popupmenu"
00039 #define DBUS_SERVICE_MENUTEST   "com.irexnet.popupmenutest"
00040 
00041 int activated_handler = -1;
00042 eripc_context_t *ctx = NULL;
00043 
00044 /**
00045  * Utility to return a pointer to a statically allocated string giving
00046  * the textural representation of Muali errors. 
00047  */
00048 static const gchar* eripcErrorStr(eripc_error_t errorcode) 
00049 {
00050     switch (errorcode) 
00051     {
00052     case ERIPC_ERROR_SUCCESS:
00053         return "No error (ERIPC_ERROR_SUCCESS)";
00054     case ERIPC_ERROR:
00055         return "Some kind of error occurred (ERIPC_ERROR)";
00056     case ERIPC_ERROR_INVALID:
00057         return "At least one parameter is invalid (ERIPC_ERROR_INVALID)";
00058     case ERIPC_ERROR_OOM:
00059         return "Out of memory error (ERIPC_ERROR_OOM)";
00060     case ERIPC_ERROR_TIMEOUT:
00061         return "Timeout error (ERIPC_ERROR_TIMEOUT)";
00062     default:
00063         return "Unknown/Undefined";
00064     }
00065 }
00066 
00067 /**
00068  * Utility to print out the type and content of given eripc_rpc_t.
00069  * It also demonstrates the types available when using Muali for
00070  * the RPC. Most simple types are available, but arrays are not
00071  * (unfortunately).
00072  */
00073 static void printEventInfo(const eripc_event_info_t *event) 
00074 {
00075     int i=0;
00076     const eripc_arg_t *arg_array = event->args;
00077 
00078     for (i=0; arg_array[i].type != ERIPC_TYPE_INVALID; i++)
00079     {
00080         switch (arg_array[i].type) 
00081         {
00082         case ERIPC_TYPE_BOOL:
00083           g_print("boolean:%s", (arg_array[i].value.b == TRUE) ? "TRUE":"FALSE");
00084           break;
00085         case ERIPC_TYPE_DOUBLE:
00086           g_print("double:%.3f", arg_array[i].value.d);
00087           break;
00088         case ERIPC_TYPE_BYTE:
00089           g_print("byte:%d", arg_array[i].value.by);
00090           break;
00091         case ERIPC_TYPE_INT:
00092           g_print("int32:%d", arg_array[i].value.i);
00093           break;
00094         case ERIPC_TYPE_UINT:
00095           g_print("uint32:%u", arg_array[i].value.u);
00096           break;
00097         case ERIPC_TYPE_STRING:
00098           g_print("string:'%s'", arg_array[i].value.s);
00099           break;
00100         case ERIPC_TYPE_DATA:
00101           g_print("dataptr:'%p'", arg_array[i].value.data);
00102           break;
00103         default:
00104           g_print("unknown(type=%d)", arg_array[i].type);
00105           break;
00106         }
00107       g_print("\n");
00108     }
00109 }
00110  
00111 
00112 static void replyFunction_rh(eripc_context_t *context, 
00113         const eripc_event_info_t *info, 
00114         void *user_data)
00115 {
00116 //    g_print("replyFunction_rh reply!\n");
00117 //    printEventInfo(info);
00118     return;
00119 }
00120 
00121 
00122 static void menuActivated_rh(eripc_context_t *context, 
00123         const eripc_event_info_t *info, 
00124         void *user_data)
00125 {
00126     g_print("menuActivated_rh reply!\n");
00127     printEventInfo(info);
00128     
00129     eripc_reply_bool(context, info->message_id, TRUE);    
00130     return;
00131 }
00132 
00133 
00134 static void add_group(const char *name, const char *parent, const char *label, const char *icon) 
00135 {
00136     eripc_error_t result;
00137 
00138 //    g_print("menutest: add group `%s`\n",name);
00139 
00140     result = eripc_send_varargs(ctx,
00141                                 NULL, 
00142                                 NULL,
00143                                 ERIPC_BUS_SESSION,
00144                                 DBUS_SERVICE,
00145                                 "addGroup",
00146                                 ERIPC_TYPE_STRING, name,
00147                                 ERIPC_TYPE_STRING, parent,
00148                                 ERIPC_TYPE_STRING, label,
00149                                 ERIPC_TYPE_STRING, icon,
00150                                 ERIPC_TYPE_INVALID);
00151 
00152     if (result != ERIPC_ERROR_SUCCESS) 
00153     {
00154         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00155     }
00156 }
00157 
00158 
00159 static void add_item(const char *name, const char *parent, const char *label) 
00160 {
00161     eripc_error_t result;
00162     
00163 //    g_print("menutest: add item `%s.%s`\n",parent,name);
00164     
00165     result = eripc_send_varargs(ctx,
00166                                 NULL, 
00167                                 NULL,
00168                                 ERIPC_BUS_SESSION,
00169                                 DBUS_SERVICE,
00170                                 "addItem",
00171                                 ERIPC_TYPE_STRING, name,
00172                                 ERIPC_TYPE_STRING, parent,
00173                                 ERIPC_TYPE_STRING, label,
00174                                 ERIPC_TYPE_STRING, name,     /* icon name is same as iten name */
00175                                 ERIPC_TYPE_INVALID);
00176 
00177     if (result != ERIPC_ERROR_SUCCESS) 
00178     {
00179         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00180     } 
00181 }
00182 
00183 
00184 static void add_menu(const char *name, const char *label, const char *service,
00185                      const char *group1, const char *group2, const char *group3, const char *group4) 
00186 {
00187     eripc_error_t result;
00188 
00189     result = eripc_send_varargs(ctx,
00190                                 replyFunction_rh,
00191                                 NULL,
00192                                 ERIPC_BUS_SESSION,
00193                                 DBUS_SERVICE,
00194                                 "addMenu",
00195                                 ERIPC_TYPE_STRING, name,
00196                                 ERIPC_TYPE_STRING, label,
00197                                 ERIPC_TYPE_STRING, service,
00198                                 ERIPC_TYPE_STRING, group1,
00199                                 ERIPC_TYPE_STRING, group2,
00200                                 ERIPC_TYPE_STRING, group3,
00201                                 ERIPC_TYPE_STRING, group4,
00202                                 ERIPC_TYPE_INVALID);
00203 
00204     if (result != ERIPC_ERROR_SUCCESS) 
00205     {
00206         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00207     } 
00208 }
00209 
00210 
00211 static void remove_group(const char *name) 
00212 {
00213     eripc_error_t result;
00214     
00215     result = eripc_send_varargs(ctx,
00216                                 replyFunction_rh,
00217                                 NULL,
00218                                 ERIPC_BUS_SESSION,
00219                                 DBUS_SERVICE,
00220                                 "removeGroup",
00221                                 ERIPC_TYPE_STRING, name,
00222                                 ERIPC_TYPE_INVALID);
00223 
00224     if (result != ERIPC_ERROR_SUCCESS) 
00225    {
00226         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00227     }
00228 }
00229 
00230 
00231 static void remove_menu(const char *name) 
00232 {
00233     eripc_error_t result;
00234     
00235     result = eripc_send_varargs(ctx,
00236                                 replyFunction_rh,
00237                                 NULL,
00238                                 ERIPC_BUS_SESSION,
00239                                 DBUS_SERVICE,
00240                                 "removeMenu",
00241                                 ERIPC_TYPE_STRING, name,
00242                                 ERIPC_TYPE_INVALID);
00243 
00244     if (result != ERIPC_ERROR_SUCCESS) 
00245    {
00246         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00247     }
00248 }
00249 
00250 
00251 static void install_activation_handler()
00252 {
00253     eripc_error_t result;
00254     
00255     result = eripc_set_message_handler(ctx,
00256                                       menuActivated_rh,
00257                                       NULL,
00258                                       ERIPC_BUS_SESSION,
00259                                       DBUS_SERVICE_MENUTEST,
00260                                       "menuItemActivated",
00261                                       &activated_handler);
00262     
00263     if (result != ERIPC_ERROR_SUCCESS) 
00264     {
00265         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00266     }
00267 }
00268 
00269 void term_handler(int sig)
00270 {
00271     g_warning("menutest got SIGTERM, cleaning up\n");
00272     
00273     if (activated_handler != -1)
00274     {
00275       eripc_unset_handler(ctx, activated_handler);
00276     }
00277     
00278     remove_group("ctb_view");
00279     remove_group("ctb_sort");
00280     remove_group("ctb_content_tools");
00281     remove_group("ctb_trashcan_tools");
00282     remove_group("ctb_settings_tools");
00283     remove_group("uds_view");
00284     remove_group("uds_tools");
00285     remove_group("uds_navigation");
00286     remove_group("uds_actions");
00287     remove_group("uds_bookmark_actions");
00288     
00289     remove_menu("ctb_menu_content");
00290     remove_menu("ctb_menu_trashcan");
00291     remove_menu("ctb_menu_settings");
00292     remove_menu("uds_menu_reading");
00293     remove_menu("uds_menu_thumbnail"); 
00294     remove_menu("uds_menu_toc"); 
00295     remove_menu("uds_menu_bookmark");
00296     remove_menu("uds_menu_dictionary");
00297     remove_menu("uds_menu_search");
00298     remove_menu("uds_menu_info");
00299     
00300     g_warning("menutest exists\n");
00301    
00302     exit(0);
00303 }
00304 
00305 int main(int argc, char **argv) 
00306 {
00307     GMainLoop *gloop = NULL;
00308     const char *group = NULL;
00309    
00310     signal(SIGTERM, term_handler);
00311     signal(SIGINT, term_handler);
00312     
00313     gloop = g_main_loop_new(NULL, FALSE);
00314 
00315     ctx = eripc_init("menutest", "1.0", NULL);
00316     if (ctx == NULL) 
00317     {
00318         g_error("Failed to initialize IPC API\n");
00319     }
00320 
00321     eripc_set_timeout(ctx, 2000);
00322     
00323     
00324     g_print("-- Adding menu items...\n");
00325 
00326     // content browser groups
00327     //
00328     
00329     // content browser view 
00330     group = "ctb_view";
00331     add_group(group, NULL, _("View"), NULL);
00332         add_item("view_small",  group, _("Thumbnails"));
00333         add_item("view_detail", group, _("Details"));
00334         add_item("view_large",  group, _("Covers"));
00335 
00336     // content browser sort
00337     group = "ctb_sort";
00338     add_group(group, NULL, _("Sort by"), NULL);
00339         add_item("sort_name",   group, _("Name"));
00340         add_item("sort_type",   group, _("Type"));
00341         add_item("sort_date",   group, _("Date"));
00342         add_item("sort_size",   group, _("Size"));
00343         add_item("sort_author", group, _("Author"));
00344     
00345     // content browser tools
00346     group = "ctb_content_tools";
00347     add_group("ctb_content_tools",  NULL, _("Actions"), NULL);
00348         add_item("open",            group, _("Open"));
00349         add_item("search_library",  group, _("Search Documents"));
00350         add_item("create_shortcut", group, _("Add Shortcut"));
00351         add_item("delete",          group, _("Delete"));
00352         add_item("select_all",      group, _("Select All"));
00353         add_item("copy",            group, _("Copy"));
00354         add_item("cut",             group, _("Cut"));
00355         add_item("paste",           group, _("Paste"));
00356     
00357     // trashcan toools
00358     group = "ctb_trashcan_tools";
00359     add_group(group,                NULL,  _("Actions"), NULL);
00360         add_item("empty_trash",     group, _("Empty Recycle Bin"));
00361         add_item("delete",          group, _("Delete"));
00362         add_item("copy",            group, _("Copy"));
00363         add_item("cut",             group, _("Cut"));
00364         add_item("paste",           group, _("Paste"));
00365     
00366     // settings tools
00367     group = "ctb_settings_tools";
00368     add_group(group,               NULL,  _("Actions"), NULL);
00369         add_item("open",            group, _("Open"));
00370 
00371     // uds groups
00372     //
00373     
00374     // uds view 
00375     group = "uds_view";
00376     add_group("uds_view",           NULL,  _("View"), NULL);
00377         add_item("view_reading",    group, _("Normal Reading"));
00378         add_item("view_thumbnail",  group, _("Page Thumbnails"));
00379         add_item("view_bookmark",   group, _("All Bookmarks"));
00380         add_item("view_toc",        group, _("Table of Contents"));
00381         add_item("view_info",       group, _("Details"));
00382 
00383     // uds toolboxes
00384     add_group("uds_tools",          NULL, _("Tools"), NULL);
00385         add_group("tools_bookmark", "uds_tools", _("Bookmarking"), "tools_bookmark");
00386             group = "tools_bookmark_tools";
00387             add_group(group, "tools_bookmark", _("Actions"), NULL);
00388                 add_item("bookmark_add",      group, _("Add Bookmark"));
00389                 add_item("bookmark_toc",      group, _("Add Contents Bookmark"));
00390                 add_item("bookmark_delete",   group, _("Delete Bookmark"));
00391         add_group("tools_drawing", "uds_tools", _("Writing"), "tools_drawing");
00392             group = "pen_functions";
00393             add_group(group, "tools_drawing", _("Pen Types"), NULL);
00394                 add_item("pen",               group, _("Pen"));
00395                 add_item("eraser",            group, _("Eraser"));
00396             group = "pen_size";
00397             add_group(group, "tools_drawing", _("Shapes"), NULL);
00398                 add_item("stylus_1",          group, _("Size 1"));
00399                 add_item("stylus_2",          group, _("Size 2"));
00400                 add_item("stylus_3",          group, _("Size 3"));
00401                 add_item("stylus_4",          group, _("Size 4"));
00402                 add_item("stylus_5",          group, _("Size 5"));
00403             group = "pen_color";
00404             add_group(group, "tools_drawing", _("Colours"), NULL);
00405                 add_item("stylus_black",      group, _("Black"));
00406                 add_item("stylus_dark_grey",  group, _("Dark Grey"));
00407                 add_item("stylus_light_grey", group, _("Light Grey"));
00408                 add_item("stylus_white",      group, _("White"));
00409         add_group("tools_character", "uds_tools", _("Fonts"), "tools_character");
00410             group = "font_sizes_1";
00411             add_group(group, "tools_character", _("Font Sizes"), NULL);
00412                 add_item("font_size_6",       group, _("6pt"));
00413                 add_item("font_size_8",       group, _("8pt"));
00414                 add_item("font_size_10",      group, _("10pt"));
00415                 add_item("font_size_11",      group, _("11pt"));
00416             group = "font_sizes_2";
00417             add_group(group, "tools_character", _("Font Sizes"), NULL);
00418                 add_item("font_size_12",      group, _("12pt"));
00419                 add_item("font_size_14",      group, _("14pt"));
00420                 add_item("font_size_16",      group, _("16pt"));
00421                 add_item("font_size_18",      group, _("18pt"));
00422                 add_item("font_size_20",      group, _("20pt"));
00423             group = "font_sizes_3";
00424             add_group(group, "tools_character", _("Font Sizes"), NULL);
00425                 add_item("font_size_22",      group, _("22pt"));
00426                 add_item("font_size_24",      group, _("24pt"));
00427                 add_item("font_size_28",      group, _("28pt"));
00428                 add_item("font_size_30",      group, _("30pt"));
00429                 add_item("font_size_34",      group, _("34pt"));
00430         add_group("tools_zoom", "uds_tools", _("Zooming"), "tools_zoom");
00431             group = "zoom_page";
00432             add_group(group, "tools_zoom", _("Screen Mode"), "zoom_page");
00433                 add_item("mode_full_screen",  group, _("Full Screen"));
00434                 add_item("zoom_auto",         group, _("Hide Margins"));
00435                 add_item("zoom_fit",          group, _("Fit on Screen"));
00436                 add_item("mode_continuous",   group, _("Page Flow"));
00437             group = "zoom_factor";
00438             add_group(group, "tools_zoom", _("Zoom Factors"), NULL);
00439                 add_item("zoom_75",           group, _("75%"));
00440                 add_item("zoom_100",          group, _("100%"));
00441                 add_item("zoom_150",          group, _("150%"));
00442                 add_item("zoom_200",          group, _("200%"));
00443                 add_item("zoom_selection",    group, _("Selection Zoom"));
00444             group = "zoom_shift";
00445             add_group(group, "tools_zoom", _("Other"), NULL);
00446                 add_item("mode_pan",          group, _("Pan"));
00447 
00448     // navigation
00449     group = "uds_navigation";
00450     add_group(group,                   NULL,  _("Actions"), NULL);
00451         add_item("history_back",       group, _("Jump to Previous"));
00452         add_item("history_forward",    group, _("Jump to Next"));
00453         add_item("dictionary_lookup",  group, _("Look Up in Dictionary"));
00454         add_item("search_text",        group, _("Find Word"));
00455         add_item("close",              group, _("Close Document"));
00456     
00457     // actions
00458     group = "uds_actions";
00459     add_group(group,     NULL,  _("Actions"), NULL);
00460         add_item("open", group, _("Open"));
00461 
00462     // bookmark actions
00463     group = "uds_bookmark_actions";
00464     add_group(group,                   NULL,  _("Actions"), NULL);
00465         add_item("open",               group, _("Open"));
00466         add_item("bookmark_delete",    group, _("Delete Bookmark"));
00467         add_item("select_all",         group, _("Select All"));
00468 
00469     // add menus
00470     //
00471     // content browser
00472     add_menu("ctb_menu_content",       _("Menu"), DBUS_SERVICE_MENUTEST, "ctb_view", "ctb_sort", "ctb_content_tools", NULL);
00473     add_menu("ctb_menu_trashcan",      _("Menu"), DBUS_SERVICE_MENUTEST, "ctb_view", "ctb_sort", "ctb_trashcan_tools", NULL);
00474     add_menu("ctb_menu_settings",      _("Menu"), DBUS_SERVICE_MENUTEST, "ctb_view", "ctb_settings_tools", NULL, NULL);
00475     
00476     // universal document shell
00477     add_menu("uds_menu_reading",       _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", "uds_tools", "uds_navigation", NULL);
00478     add_menu("uds_menu_thumbnail",     _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", "uds_actions", NULL, NULL);
00479     add_menu("uds_menu_toc",           _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", "uds_actions", NULL, NULL);
00480     add_menu("uds_menu_bookmark",      _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", "uds_bookmark_actions", NULL, NULL);
00481     add_menu("uds_menu_dictionary",    _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", "uds_actions", NULL, NULL);
00482     add_menu("uds_menu_search",        _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", NULL, NULL, NULL);
00483     add_menu("uds_menu_info",          _("Menu"), DBUS_SERVICE_MENUTEST, "uds_view", NULL, NULL, NULL);
00484 
00485     // install callback handler on activation
00486     install_activation_handler(ctx);
00487 
00488     g_print("-- Enter main loop\n");
00489     g_main_loop_run(gloop);
00490     
00491     // normally we should not come here as we stay in the GMainloop
00492 
00493     g_print("-- Exit main loop\n");
00494     ctx = NULL;
00495 
00496     g_print("Quitting\n");
00497     return EXIT_SUCCESS;
00498 }
Generated by  doxygen 1.6.2-20100208