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 #include "config.h"
00032
00033
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <gdk/gdkx.h>
00037 #include <sys/types.h>
00038 #include <unistd.h>
00039
00040
00041 #include <liberipc/eripc.h>
00042 #include <liberipc/eripc_support.h>
00043
00044
00045 #include "log.h"
00046 #include "i18n.h"
00047 #include "ipc.h"
00048 #include "main.h"
00049 #include "menu.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #define DBUS_APPL_NAME "helloworld" // lower-case and digits only
00064 #define DBUS_SERVICE "com.irexnet." DBUS_APPL_NAME
00065 #define DBUS_PATH "/com/irexnet/" DBUS_APPL_NAME
00066 #define DBUS_INTERFACE "com.irexnet." DBUS_APPL_NAME
00067
00068
00069 #define DBUS_SERVICE_SYSTEM_CONTROL "com.irexnet.sysd"
00070
00071
00072 #define DBUS_SERVICE_POPUP_MENU "com.irexnet.popupmenu"
00073
00074
00075
00076
00077
00078
00079 static eripc_client_context_t *eripcClient = NULL;
00080
00081
00082
00083
00084
00085 static void on_menu_item ( eripc_context_t *context,
00086 const eripc_event_info_t *info,
00087 void *user_data );
00088
00089 static void on_mounted ( eripc_context_t *context,
00090 const eripc_event_info_t *info,
00091 void *user_data );
00092
00093 static void on_file_open ( eripc_context_t *context,
00094 const eripc_event_info_t *info,
00095 void *user_data );
00096
00097 static void on_file_close ( eripc_context_t *context,
00098 const eripc_event_info_t *info,
00099 void *user_data );
00100
00101 static void on_window_activated ( eripc_context_t *context,
00102 const eripc_event_info_t *info,
00103 void *user_data );
00104
00105 static void on_window_deactivated( eripc_context_t *context,
00106 const eripc_event_info_t *info,
00107 void *user_data );
00108
00109 static void on_prepare_unmount ( eripc_context_t *context,
00110 const eripc_event_info_t *info,
00111 void *user_data );
00112
00113 static void on_unmounted ( eripc_context_t *context,
00114 const eripc_event_info_t *info,
00115 void *user_data );
00116
00117 static void on_prepare_standby ( eripc_context_t *context,
00118 const eripc_event_info_t *info,
00119 void *user_data );
00120
00121 static void on_changed_locale ( eripc_context_t *context,
00122 const eripc_event_info_t *info,
00123 void *user_data );
00124
00125 static void on_changed_orientation(eripc_context_t *context,
00126 const eripc_event_info_t *info,
00127 void *user_data );
00128
00129 static void on_page_change (eripc_context_t *context,
00130 const eripc_event_info_t *info,
00131 void *user_data);
00132
00133 static void on_sys_changed_pageturn_inverted (eripc_context_t *context,
00134 const eripc_event_info_t *info,
00135 void *user_data);
00136
00137
00138
00139 static eripc_callback_function_t service_functions[] = {
00140
00141 { on_menu_item, "menuItemActivated", NULL , 0 },
00142 { on_mounted, "sysVolumeMounted", NULL , 0 },
00143 { on_file_open, "openFile", NULL , 0 },
00144 { on_file_close, "closeFile", NULL , 0 },
00145 { on_window_activated, "activatedWindow", NULL , 0 },
00146 { on_window_deactivated, "deactivatedWindow", NULL , 0 },
00147
00148 { on_mounted, "sysVolumeMounted", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00149 { on_prepare_unmount, "sysPrepareUnmount", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00150 { on_unmounted, "sysVolumeUnmounted", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00151 { on_prepare_standby, "sysPrepareStandby", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00152 { on_changed_locale, "sysChangedLocale", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00153 { on_changed_orientation, "sysChangedOrientation", DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00154 { on_page_change, "pageChange", NULL , 0 },
00155 { on_sys_changed_pageturn_inverted, "sysChangedPageturnInverted", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00156 { NULL, NULL, NULL, 0 }
00157 };
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void ipc_set_services (void)
00171 {
00172 eripcClient = eripc_client_context_new(
00173 DBUS_APPL_NAME,
00174 "1.0",
00175 DBUS_SERVICE,
00176 DBUS_PATH,
00177 DBUS_INTERFACE,
00178 service_functions);
00179 }
00180
00181
00182
00183 void ipc_unset_services (void)
00184 {
00185 eripc_client_context_free(eripcClient, service_functions);
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 void ipc_sys_startup_complete ( void )
00195 {
00196 const int xid = GDK_WINDOW_XID(g_main_window->window);
00197 eripc_sysd_startup_complete( eripcClient, getpid(), TRUE, xid);
00198 }
00199
00200
00201
00202 gint ipc_sys_start_task ( const gchar *cmd_line,
00203 const gchar *work_dir,
00204 const gchar *label,
00205 const gchar *thumbnail_path,
00206 gchar **err_message )
00207 {
00208 LOGPRINTF("entry: cmd_line [%s] work_dir [%s] label [%s] thumbnail_path [%s]",
00209 cmd_line, work_dir, label, thumbnail_path );
00210 g_assert( cmd_line && *cmd_line );
00211 return eripc_sysd_start_task( eripcClient,
00212 cmd_line,
00213 work_dir,
00214 label,
00215 thumbnail_path,
00216 err_message);
00217 }
00218
00219
00220
00221 gboolean ipc_sys_stop_task ( const gchar *cmd_line )
00222 {
00223 LOGPRINTF("entry: cmd_line [%s]", cmd_line );
00224 g_assert( cmd_line && *cmd_line );
00225 return eripc_sysd_stop_task( eripcClient, cmd_line );
00226 }
00227
00228
00229
00230
00231
00232
00233
00234 gboolean ipc_menu_add_menu( const char *name,
00235 const char *group1,
00236 const char *group2,
00237 const char *group3 )
00238 {
00239 return eripc_menu_add_menu(eripcClient, name, group1, group2, group3, "");
00240 }
00241
00242
00243
00244 gboolean ipc_menu_add_group( const char *name,
00245 const char *parent,
00246 const char *image )
00247 {
00248 return eripc_menu_add_group(eripcClient, name, parent, image);
00249 }
00250
00251
00252
00253 gboolean ipc_menu_add_item( const char *name,
00254 const char *parent,
00255 const char *image )
00256 {
00257 return eripc_menu_add_item(eripcClient, name, parent, image);
00258 }
00259
00260
00261
00262 gboolean ipc_menu_set_menu_label ( const char *name,
00263 const char *label )
00264 {
00265 return eripc_menu_set_menu_label(eripcClient, name, label);
00266 }
00267
00268
00269
00270 gboolean ipc_menu_set_group_label ( const char *name,
00271 const char *label )
00272 {
00273 return eripc_menu_set_group_label(eripcClient, name, label);
00274 }
00275
00276
00277
00278 gboolean ipc_menu_set_item_label ( const char *name,
00279 const char *parent,
00280 const char *label )
00281 {
00282 return eripc_menu_set_item_label(eripcClient, name, parent, label);
00283 }
00284
00285
00286
00287 gboolean ipc_menu_show_menu( const char *name )
00288 {
00289 return eripc_menu_show_menu(eripcClient, name);
00290 }
00291
00292
00293
00294 gboolean ipc_remove_menu( const char *name )
00295 {
00296 return eripc_menu_remove_menu(eripcClient, name);
00297 }
00298
00299
00300
00301 gboolean ipc_menu_set_group_state( const char *name,
00302 const char *state )
00303 {
00304 return eripc_menu_set_group_state(eripcClient, name, state);
00305 }
00306
00307
00308
00309 gboolean ipc_menu_set_item_state( const char *name,
00310 const char *parent,
00311 const char *state )
00312 {
00313 return eripc_menu_set_item_state(eripcClient, name, parent, state);
00314 }
00315
00316
00317
00318 gboolean ipc_sys_busy( gboolean look_busy )
00319 {
00320 if (look_busy)
00321 return eripc_sysd_set_busy(eripcClient, "delaydialog", NULL);
00322 else
00323 return eripc_sysd_reset_busy(eripcClient);
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 static void on_menu_item ( eripc_context_t *context,
00340 const eripc_event_info_t *info,
00341 void *user_data )
00342 {
00343 LOGPRINTF("entry");
00344 const eripc_arg_t *arg_array = info->args;
00345
00346 if ((arg_array[0].type == ERIPC_TYPE_STRING) &&
00347 (arg_array[1].type == ERIPC_TYPE_STRING) &&
00348 (arg_array[2].type == ERIPC_TYPE_STRING) &&
00349 (arg_array[3].type == ERIPC_TYPE_STRING))
00350 {
00351 const char *item = arg_array[0].value.s;
00352 const char *group = arg_array[1].value.s;
00353 const char *menu = arg_array[2].value.s;
00354 const char *state = arg_array[3].value.s;
00355
00356 if (item && group && menu && state)
00357 {
00358 menu_on_item_activated( item, group, menu, state );
00359 }
00360 }
00361 }
00362
00363
00364
00365
00366
00367
00368
00369 static void on_window_activated( eripc_context_t *context,
00370 const eripc_event_info_t *info,
00371 void *user_data )
00372 {
00373 LOGPRINTF("entry");
00374 gchar *msg = NULL;
00375 gboolean result = FALSE;
00376 const eripc_arg_t *arg_array = info->args;
00377
00378 if (arg_array[0].type == ERIPC_TYPE_INT)
00379 {
00380
00381
00382 gint window = arg_array[0].value.i;
00383
00384 menu_show();
00385
00386 msg = g_strdup_printf("Window activated: %d", window);
00387 gtk_label_set_text( GTK_LABEL(g_action), msg);
00388 LOGPRINTF("%s", msg);
00389 g_free(msg);
00390
00391 result = TRUE;
00392 }
00393
00394
00395 eripc_reply_bool(context, info->message_id, result);
00396 }
00397
00398
00399
00400
00401
00402
00403 static void on_window_deactivated( eripc_context_t *context,
00404 const eripc_event_info_t *info,
00405 void *user_data )
00406 {
00407 LOGPRINTF("entry");
00408 gchar *msg = NULL;
00409 gboolean result = FALSE;
00410 const eripc_arg_t *arg_array = info->args;
00411
00412 if (arg_array[0].type == ERIPC_TYPE_INT)
00413 {
00414
00415
00416 gint window = arg_array[0].value.i;
00417
00418 msg = g_strdup_printf("Window deactivated: %d", window);
00419 gtk_label_set_text( GTK_LABEL(g_action), msg);
00420 LOGPRINTF("%s", msg);
00421 g_free(msg);
00422
00423 result = TRUE;
00424 }
00425
00426
00427 eripc_reply_bool(context, info->message_id, result);
00428
00429
00430 main_quit();
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 static void on_file_open ( eripc_context_t *context,
00446 const eripc_event_info_t *info,
00447 void *user_data )
00448 {
00449 LOGPRINTF("entry");
00450 gchar *msg = NULL;
00451 gchar *error_msg = NULL;
00452 gint my_xid = -1;
00453
00454 const eripc_arg_t *arg_array = info->args;
00455
00456 if (arg_array[0].type == ERIPC_TYPE_STRING)
00457 {
00458 const char *file = arg_array[0].value.s;
00459 if (file)
00460 {
00461
00462
00463 msg = g_strdup_printf("File to open: %s", file);
00464 gtk_label_set_text( GTK_LABEL(g_action), msg);
00465 LOGPRINTF("%s", msg);
00466 g_free(msg);
00467
00468
00469
00470 gboolean success = TRUE;
00471
00472 if (success)
00473 {
00474 my_xid = GDK_WINDOW_XID(g_main_window->window);
00475 menu_show();
00476 }
00477 else
00478 {
00479 error_msg = g_strdup_printf(_("Error opening '%s'"), file);
00480 }
00481 }
00482 }
00483
00484
00485 eripc_reply_varargs(context, info->message_id,
00486 ERIPC_TYPE_INT, my_xid,
00487 ERIPC_TYPE_STRING, error_msg,
00488 ERIPC_TYPE_INVALID);
00489 g_free(error_msg);
00490 }
00491
00492
00493
00494
00495
00496
00497
00498 static void on_file_close ( eripc_context_t *context,
00499 const eripc_event_info_t *info,
00500 void *user_data )
00501 {
00502 LOGPRINTF("entry");
00503 gchar *msg = NULL;
00504 gboolean result = FALSE;
00505 const eripc_arg_t *arg_array = info->args;
00506
00507 if (arg_array[0].type == ERIPC_TYPE_STRING)
00508 {
00509 const char *file = arg_array[0].value.s;
00510 if (file)
00511 {
00512
00513
00514 msg = g_strdup_printf("File to close: %s", file);
00515 gtk_label_set_text( GTK_LABEL(g_action), msg);
00516 LOGPRINTF("%s", msg);
00517 g_free(msg);
00518
00519 result = TRUE;
00520 }
00521 }
00522
00523
00524 eripc_reply_bool(context, info->message_id, result);
00525 }
00526
00527
00528
00529
00530
00531
00532 static void on_mounted ( eripc_context_t *context,
00533 const eripc_event_info_t *info,
00534 void *user_data )
00535 {
00536 LOGPRINTF("entry");
00537 gchar *msg = NULL;
00538 const eripc_arg_t *arg_array = info->args;
00539
00540 if (arg_array[0].type == ERIPC_TYPE_STRING)
00541 {
00542 const char *mountpoint = arg_array[0].value.s;
00543 if (mountpoint)
00544 {
00545
00546
00547 g_free(g_mountpoint);
00548 g_mountpoint = g_strdup(mountpoint);
00549
00550 msg = g_strdup_printf("Device mounted: %s", mountpoint);
00551 gtk_label_set_text( GTK_LABEL(g_volume), msg);
00552 LOGPRINTF("%s", msg);
00553 g_free(msg);
00554 }
00555 }
00556 }
00557
00558
00559
00560
00561
00562
00563
00564 static void on_prepare_unmount ( eripc_context_t *context,
00565 const eripc_event_info_t *info,
00566 void *user_data )
00567 {
00568 LOGPRINTF("entry");
00569 gchar *msg = NULL;
00570 const eripc_arg_t *arg_array = info->args;
00571
00572 if (arg_array[0].type == ERIPC_TYPE_STRING)
00573 {
00574 const char *mountpoint = arg_array[0].value.s;
00575 if (mountpoint)
00576 {
00577
00578
00579 msg = g_strdup_printf("Device to unmount: %s", mountpoint);
00580 gtk_label_set_text( GTK_LABEL(g_volume), msg);
00581 LOGPRINTF("%s", msg);
00582 g_free(msg);
00583 }
00584 }
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594 static void on_unmounted ( eripc_context_t *context,
00595 const eripc_event_info_t *info,
00596 void *user_data )
00597 {
00598 LOGPRINTF("entry");
00599 gchar *msg = NULL;
00600 const eripc_arg_t *arg_array = info->args;
00601
00602 if (arg_array[0].type == ERIPC_TYPE_STRING)
00603 {
00604 const char *mountpoint = arg_array[0].value.s;
00605 if (mountpoint)
00606 {
00607
00608
00609 if (g_mountpoint && (strcmp(mountpoint, g_mountpoint) == 0))
00610 {
00611 g_free(g_mountpoint);
00612 g_mountpoint = NULL;
00613 }
00614
00615 msg = g_strdup_printf("Device unmounted: %s", mountpoint);
00616 gtk_label_set_text( GTK_LABEL(g_volume), msg);
00617 LOGPRINTF("%s", msg);
00618 g_free(msg);
00619 }
00620 }
00621 }
00622
00623
00624
00625
00626
00627
00628
00629 static void on_prepare_standby ( eripc_context_t *context,
00630 const eripc_event_info_t *info,
00631 void *user_data )
00632 {
00633 LOGPRINTF("entry");
00634
00635
00636 }
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646 static void on_changed_locale ( eripc_context_t *context,
00647 const eripc_event_info_t *info,
00648 void *user_data )
00649 {
00650 LOGPRINTF("entry");
00651 const eripc_arg_t *arg_array = info->args;
00652
00653 if (arg_array[0].type == ERIPC_TYPE_STRING)
00654 {
00655 const char *locale = arg_array[0].value.s;
00656 if (locale)
00657 {
00658 const char *old_locale = g_getenv("LANG");
00659 if (!old_locale || (strcmp(old_locale, locale) != 0))
00660 {
00661 main_set_locale(locale);
00662 }
00663 }
00664 }
00665 }
00666
00667
00668
00669
00670
00671
00672
00673 static void on_changed_orientation ( eripc_context_t *context,
00674 const eripc_event_info_t *info,
00675 void *user_data )
00676 {
00677 LOGPRINTF("entry");
00678 gchar *msg = NULL;
00679 const eripc_arg_t *arg_array = info->args;
00680
00681 if (arg_array[0].type == ERIPC_TYPE_STRING)
00682 {
00683 const char *orientation = arg_array[0].value.s;
00684 if (orientation)
00685 {
00686
00687
00688 msg = g_strdup_printf("Orientation changed: %s", orientation);
00689 gtk_label_set_text( GTK_LABEL(g_action), msg);
00690 LOGPRINTF("%s", msg);
00691 g_free(msg);
00692 }
00693 }
00694 }
00695
00696
00697
00698
00699
00700
00701 static void on_sys_changed_pageturn_inverted( eripc_context_t *context,
00702 const eripc_event_info_t *info,
00703 void *user_data)
00704 {
00705 LOGPRINTF("entry");
00706
00707 gchar *msg = NULL;
00708 const eripc_arg_t *arg_array = info->args;
00709
00710 if (arg_array[0].type == ERIPC_TYPE_BOOL)
00711 {
00712 gboolean is_inverted = arg_array[0].value.b;
00713
00714
00715 msg = g_strdup_printf("page turning setting from from flipbar change, is_inverted = %d", is_inverted);
00716 gtk_label_set_text( GTK_LABEL(g_action), msg);
00717 LOGPRINTF("%s", msg);
00718 g_free(msg);
00719 }
00720
00721 }
00722
00723
00724 static void on_page_change( eripc_context_t *context,
00725 const eripc_event_info_t *info,
00726 void *user_data)
00727 {
00728 LOGPRINTF("entry");
00729
00730 gchar *msg = NULL;
00731 const eripc_arg_t *arg_array = info->args;
00732
00733 g_return_if_fail(arg_array[0].type == ERIPC_TYPE_STRING);
00734
00735 const gchar* direction = arg_array[0].value.s;
00736
00737 if (direction)
00738 {
00739
00740 msg = g_strdup_printf("page change from menubar, direction: %s", direction);
00741 gtk_label_set_text( GTK_LABEL(g_action), msg);
00742 LOGPRINTF("%s", msg);
00743 g_free(msg);
00744 }
00745
00746 }
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 gboolean ipc_sys_is_pageturn_inverted()
00764 {
00765 gboolean result = FALSE;
00766
00767 eripc_error_t retval;
00768 eripc_event_info_t* info = NULL;
00769
00770 LOGPRINTF("entry");
00771
00772 retval = eripc_send_varargs_and_wait(eripcClient->context,
00773 &info,
00774 ERIPC_BUS_SESSION,
00775 DBUS_SERVICE_SYSTEM_CONTROL,
00776 "sysGetPageturnInverted",
00777 ERIPC_TYPE_INVALID);
00778
00779 if (retval != ERIPC_ERROR_SUCCESS)
00780 {
00781 ERRORPRINTF("Error launching eripc handler");
00782 }
00783 else if (info == NULL || info->args == NULL)
00784 {
00785 ERRORPRINTF("sysd returns OK but no reply structure");
00786 }
00787 else
00788 {
00789 const eripc_arg_t *arg_array = info->args;
00790
00791 if (arg_array[0].type == ERIPC_TYPE_BOOL)
00792 {
00793 result = (gboolean) arg_array[0].value.b;
00794 }
00795 else
00796 {
00797 result = FALSE ;
00798 }
00799 }
00800
00801 eripc_event_info_free(eripcClient->context, info);
00802 return result;
00803 }
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 gboolean ipc_sys_is_in_portrait_mode(void)
00814 {
00815
00816 gboolean result = TRUE;
00817
00818 eripc_error_t retval;
00819 eripc_event_info_t* info = NULL;
00820
00821 LOGPRINTF("entry");
00822
00823 retval = eripc_send_varargs_and_wait(eripcClient->context,
00824 &info,
00825 ERIPC_BUS_SESSION,
00826 DBUS_SERVICE_SYSTEM_CONTROL,
00827 "sysGetOrientation",
00828 ERIPC_TYPE_INVALID);
00829
00830 if (retval != ERIPC_ERROR_SUCCESS)
00831 {
00832 ERRORPRINTF("Error launching eripc handler");
00833 }
00834 else if (info == NULL || info->args == NULL)
00835 {
00836 ERRORPRINTF("sysd returns OK but no reply structure");
00837 }
00838 else
00839 {
00840 const eripc_arg_t *arg_array = info->args;
00841
00842 if (arg_array[0].type == ERIPC_TYPE_STRING)
00843 {
00844 if ( strcmp("portrait", arg_array[0].value.s) == 0 )
00845 {
00846 result = TRUE;
00847 }
00848 else
00849 {
00850 result = FALSE;
00851 }
00852 }
00853 else
00854 {
00855 result = FALSE ;
00856 }
00857 }
00858 eripc_event_info_free(eripcClient->context, info);
00859 return result;
00860 }
00861
00862