00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdio.h>
00033 #include <unistd.h>
00034
00035
00036
00037
00038 #include "log.h"
00039 #include "i18n.h"
00040 #include "ipc.h"
00041 #include "main.h"
00042 #include "menu.h"
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 static const char *MENU_MAIN = "helloworld_menu_main";
00057
00058
00059
00060 static const char *GROUP_VIEWS = "helloworld_view";
00061 static const char *GROUP_ACTIONS = "helloworld_actions";
00062
00063
00064
00065 static const char *ITEM_VIEW_ICON = "view_small";
00066 static const char *ITEM_VIEW_LIST = "view_detail";
00067
00068 static const char *ITEM_ACTION_OPEN = "open";
00069 static const char *ITEM_ACTION_COPY = "copy";
00070 static const char *ITEM_ACTION_CUT = "cut";
00071 static const char *ITEM_ACTION_PASTE = "paste";
00072 static const char *ITEM_ACTION_CLOSE = "close";
00073
00074
00075 static const char *STATE_NORMAL = "normal";
00076 static const char *STATE_SELECTED = "selected";
00077 static const char *STATE_DISABLED = "disabled";
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 void menu_init ( void )
00098 {
00099 static gboolean firsttime = TRUE;
00100 const char *group;
00101
00102 LOGPRINTF("entry");
00103
00104
00105 if ( !firsttime )
00106 {
00107 WARNPRINTF("function called twice");
00108 return;
00109 }
00110 firsttime = FALSE;
00111
00112
00113 group = GROUP_VIEWS;
00114 ipc_menu_add_group( group, "", "folder" );
00115 ipc_menu_add_item ( ITEM_VIEW_ICON, group, "view_small" );
00116 ipc_menu_add_item ( ITEM_VIEW_LIST, group, "view_detail" );
00117
00118 group = GROUP_ACTIONS;
00119 ipc_menu_add_group( group, "", "folder" );
00120 ipc_menu_add_item ( ITEM_ACTION_OPEN, group, "open" );
00121 ipc_menu_add_item ( ITEM_ACTION_COPY, group, "copy" );
00122 ipc_menu_add_item ( ITEM_ACTION_CUT, group, "cut" );
00123 ipc_menu_add_item ( ITEM_ACTION_PASTE, group, "paste" );
00124 ipc_menu_add_item ( ITEM_ACTION_CLOSE, group, "close" );
00125
00126
00127 ipc_menu_add_menu( MENU_MAIN, GROUP_VIEWS, GROUP_ACTIONS, NULL );
00128
00129
00130 menu_set_text();
00131
00132
00133
00134 group = GROUP_ACTIONS;
00135 ipc_menu_set_item_state ( ITEM_ACTION_COPY, group, STATE_DISABLED );
00136 ipc_menu_set_item_state ( ITEM_ACTION_CUT, group, STATE_DISABLED );
00137 ipc_menu_set_item_state ( ITEM_ACTION_PASTE, group, STATE_DISABLED );
00138
00139
00140 menu_show();
00141 }
00142
00143
00144
00145 void menu_destroy (void)
00146 {
00147 LOGPRINTF("entry");
00148
00149
00150 ipc_remove_menu( MENU_MAIN );
00151 }
00152
00153
00154
00155 void menu_show (void)
00156 {
00157 LOGPRINTF("entry");
00158
00159
00160 ipc_menu_show_menu( MENU_MAIN );
00161 }
00162
00163
00164
00165 void menu_set_text ( void )
00166 {
00167 const char *group;
00168
00169 LOGPRINTF("entry");
00170
00171
00172 group = GROUP_VIEWS;
00173 ipc_menu_set_group_label( group, _("View") );
00174 ipc_menu_set_item_label ( ITEM_VIEW_ICON, group, _("Thumbnails") );
00175 ipc_menu_set_item_label ( ITEM_VIEW_LIST, group, _("Details") );
00176
00177 group = GROUP_ACTIONS;
00178 ipc_menu_set_group_label( group, _("Actions") );
00179 ipc_menu_set_item_label ( ITEM_ACTION_OPEN, group, _("Open") );
00180 ipc_menu_set_item_label ( ITEM_ACTION_COPY, group, _("Copy") );
00181 ipc_menu_set_item_label ( ITEM_ACTION_CUT, group, _("Cut") );
00182 ipc_menu_set_item_label ( ITEM_ACTION_PASTE, group, _("Paste") );
00183 ipc_menu_set_item_label ( ITEM_ACTION_CLOSE, group, _("Close") );
00184
00185
00186 ipc_menu_set_menu_label( MENU_MAIN, _("Hello World Menu") );
00187 }
00188
00189
00190
00191 void menu_select_view_type ( const viewtypes_t view_type )
00192 {
00193 static const char *item_old = "";
00194 const char *item_new = "";
00195
00196 LOGPRINTF("entry: view_type [%d]", view_type);
00197 g_assert(view_type < N_VIEWTYPES);
00198
00199 switch (view_type)
00200 {
00201 case ICONVIEW:
00202 item_new = ITEM_VIEW_ICON;
00203 break;
00204 case LISTVIEW:
00205 item_new = ITEM_VIEW_LIST;
00206 break;
00207 default:
00208 ;
00209 }
00210
00211 if ( strcmp(item_old, item_new) != 0 )
00212 {
00213 if ( item_old[0] != '\0' )
00214 {
00215 ipc_menu_set_item_state ( item_old, GROUP_VIEWS, STATE_NORMAL );
00216 }
00217 ipc_menu_set_item_state ( item_new, GROUP_VIEWS, STATE_SELECTED );
00218
00219 item_old = item_new;
00220 }
00221 }
00222
00223
00224
00225
00226
00227
00228
00229 void menu_on_item_activated ( const gchar *item,
00230 const gchar *group,
00231 const gchar *menu,
00232 const gchar *state )
00233 {
00234 gboolean ok = TRUE;
00235 viewtypes_t view_type = 0;
00236 gchar *msg = NULL;
00237
00238 LOGPRINTF("entry: item [%s] group [%s]", item, group);
00239
00240 if ( strcmp(group, GROUP_VIEWS) == 0 )
00241 {
00242 if ( strcmp(state, STATE_NORMAL) == 0 )
00243 {
00244 if ( strcmp(item, ITEM_VIEW_ICON) == 0 )
00245 {
00246 view_type = ICONVIEW;
00247 }
00248 else if ( strcmp(item, ITEM_VIEW_LIST) == 0 )
00249 {
00250 view_type = LISTVIEW;
00251 }
00252 else
00253 {
00254 WARNPRINTF("unexpected menu item [%s] in group [%s]", item, group);
00255 ok = FALSE;
00256 }
00257
00258 if (ok)
00259 {
00260 main_set_view_type( view_type );
00261 }
00262 }
00263 else
00264 {
00265 WARNPRINTF("ignore state [%s] item [%s][%s]", state, item, group);
00266 }
00267 }
00268 else if ( strcmp(group, GROUP_ACTIONS) == 0 )
00269 {
00270 if ( strcmp(state, STATE_NORMAL) == 0 )
00271 {
00272 if ( strcmp(item, ITEM_ACTION_OPEN) == 0 )
00273 {
00274
00275 msg = g_strdup_printf("uds %s/%s", g_mountpoint, "test.pdf");
00276 ipc_sys_start_task(msg, g_mountpoint, "test.pdf", NULL, NULL);
00277 g_free(msg);
00278 }
00279 else if ( strcmp(item, ITEM_ACTION_CLOSE) == 0 )
00280 {
00281
00282 main_quit();
00283 _exit(0);
00284 return;
00285 }
00286 else
00287 {
00288 WARNPRINTF("unexpected menu item [%s] in group [%s]", item, group);
00289 ok = FALSE;
00290 }
00291
00292 if (ok)
00293 {
00294 main_set_view_type( view_type );
00295 }
00296 }
00297 else
00298 {
00299 WARNPRINTF("ignore state [%s] item [%s][%s]", state, item, group);
00300 }
00301 }
00302 else
00303 {
00304 WARNPRINTF("unexpected menu group [%s]", group);
00305 ok = FALSE;
00306 }
00307
00308 if (!ok)
00309 {
00310 msg = g_strdup_printf( _("Unhandled menu item.\n"
00311 "menu: %s\n"
00312 "group: %s\n"
00313 "item: %s\n"
00314 "state: %s"),
00315 menu,
00316 group,
00317 item,
00318 state );
00319 gtk_label_set_text( GTK_LABEL(g_action), msg);
00320 g_free(msg);
00321 }
00322 }