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 <unistd.h>
00038
00039
00040 #include <liberipc/eripc.h>
00041 #include <liberipc/eripc_support.h>
00042
00043
00044 #include "log.h"
00045 #include "i18n.h"
00046 #include "ipc.h"
00047 #include "main.h"
00048 #include "menu.h"
00049 #include "view.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #define DBUS_APPL_NAME PACKAGE
00062 #define DBUS_SERVICE "com.irexnet." DBUS_APPL_NAME
00063 #define DBUS_PATH "/com/irexnet/" DBUS_APPL_NAME
00064 #define DBUS_INTERFACE "com.irexnet." DBUS_APPL_NAME
00065
00066
00067 #define DBUS_SERVICE_SYSTEM_CONTROL "com.irexnet.sysd"
00068
00069
00070 #define DBUS_SERVICE_POPUP_MENU "com.irexnet.popupmenu"
00071
00072
00073
00074
00075
00076
00077 static eripc_client_context_t *eripcClient = NULL;
00078
00079 static ipc_callback_t g_connect_cb = NULL;
00080 static ipc_callback_t g_disconnect_cb = NULL;
00081 static ipc_callback_t g_locale_cb = NULL;
00082
00083
00084
00085
00086
00087
00088 static void on_menu_item ( eripc_context_t *context,
00089 const eripc_event_info_t *info,
00090 void *user_data );
00091
00092 static void on_mounted ( eripc_context_t *context,
00093 const eripc_event_info_t *info,
00094 void *user_data );
00095
00096 static void on_file_open ( eripc_context_t *context,
00097 const eripc_event_info_t *info,
00098 void *user_data );
00099
00100 static void on_file_close ( eripc_context_t *context,
00101 const eripc_event_info_t *info,
00102 void *user_data );
00103
00104 static void on_window_activated ( eripc_context_t *context,
00105 const eripc_event_info_t *info,
00106 void *user_data );
00107
00108 static void on_window_deactivated( eripc_context_t *context,
00109 const eripc_event_info_t *info,
00110 void *user_data );
00111
00112 static void on_connection_status ( eripc_context_t *context,
00113 const eripc_event_info_t *info,
00114 void *user_data );
00115
00116 static void on_prepare_unmount ( eripc_context_t *context,
00117 const eripc_event_info_t *info,
00118 void *user_data );
00119
00120 static void on_unmounted ( eripc_context_t *context,
00121 const eripc_event_info_t *info,
00122 void *user_data );
00123
00124 static void on_changed_locale ( eripc_context_t *context,
00125 const eripc_event_info_t *info,
00126 void *user_data );
00127
00128
00129 static eripc_callback_function_t service_functions[] = {
00130
00131 { on_menu_item, "menuItemActivated", NULL , 0},
00132 { on_mounted, "sysVolumeMounted", NULL , 0},
00133 { on_file_open, "openFile", NULL , 0},
00134 { on_file_close, "closeFile", NULL , 0},
00135 { on_window_activated, "activatedWindow", NULL , 0},
00136 { on_window_deactivated, "deactivatedWindow", NULL , 0},
00137 { on_connection_status, "connConnectionStatus", NULL , 0},
00138
00139 { on_mounted, "sysVolumeMounted", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00140 { on_prepare_unmount, "sysPrepareUnmount", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00141 { on_unmounted, "sysVolumeUnmounted", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00142 { on_changed_locale, "sysChangedLocale", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00143 { on_connection_status, "connConnectionStatus", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00144 { NULL, NULL, NULL, 0 }
00145 };
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 void ipc_set_services (ipc_callback_t connect_cb, ipc_callback_t disconnect_cb, ipc_callback_t locale_cb)
00158 {
00159 LOGPRINTF("entry");
00160 eripcClient = eripc_client_context_new(
00161 DBUS_APPL_NAME,
00162 "1.0",
00163 DBUS_SERVICE,
00164 DBUS_PATH,
00165 DBUS_INTERFACE,
00166 service_functions);
00167
00168 g_connect_cb = connect_cb;
00169 g_disconnect_cb = disconnect_cb;
00170 g_locale_cb = locale_cb;
00171
00172
00173 g_mountpoint = NULL;
00174 }
00175
00176
00177 void ipc_unset_services (void)
00178 {
00179 LOGPRINTF("entry");
00180 eripc_client_context_free(eripcClient, service_functions);
00181 }
00182
00183
00184
00185
00186
00187
00188 void ipc_sys_startup_complete ( void )
00189 {
00190 LOGPRINTF("entry");
00191 const int xid = GDK_WINDOW_XID(g_main_window->window);
00192 eripc_sysd_startup_complete( eripcClient, getpid(), TRUE, xid);
00193 }
00194
00195
00196 gboolean ipc_sys_bg_busy ( gboolean on )
00197 {
00198 LOGPRINTF("entry [%d]", on);
00199 if (on)
00200 return eripc_sysd_set_bg_busy(eripcClient);
00201 else
00202 return eripc_sysd_reset_bg_busy(eripcClient);
00203 }
00204
00205
00206 gboolean ipc_sys_set_busy ( gboolean on, const gchar *message )
00207 {
00208 LOGPRINTF("entry [%d]", on);
00209 if (on)
00210 return eripc_sysd_set_busy(eripcClient, "delaydialog", message);
00211 else
00212 return eripc_sysd_reset_busy(eripcClient);
00213 }
00214
00215
00216 gboolean ipc_sys_set_busy_nodialog ( gboolean on )
00217 {
00218 LOGPRINTF("entry [%d]", on);
00219 if (on)
00220 return eripc_sysd_set_busy(eripcClient, "nodialog", NULL);
00221 else
00222 return eripc_sysd_reset_busy(eripcClient);
00223 }
00224
00225
00226 gboolean ipc_sys_connect ( void )
00227 {
00228 LOGPRINTF("entry");
00229 return eripc_sysd_conn_connect(eripcClient, NULL, NULL);
00230 }
00231
00232
00233 gboolean ipc_sys_disconnect ( void )
00234 {
00235 LOGPRINTF("entry");
00236 return eripc_sysd_conn_disconnect(eripcClient);
00237 }
00238
00239
00240 gint ipc_sys_start_task ( const gchar *cmd_line,
00241 const gchar *work_dir,
00242 const gchar *label,
00243 const gchar *thumbnail_path,
00244 gchar **err_message )
00245 {
00246 LOGPRINTF("entry");
00247 return eripc_sysd_start_task(eripcClient,
00248 cmd_line,
00249 work_dir,
00250 label,
00251 thumbnail_path,
00252 err_message);
00253 }
00254
00255
00256
00257
00258
00259
00260 gboolean ipc_menu_add_menu( const char *name,
00261 const char *group1,
00262 const char *group2,
00263 const char *group3 )
00264 {
00265 LOGPRINTF("entry");
00266 return eripc_menu_add_menu(eripcClient, name, group1, group2, group3, "");
00267 }
00268
00269
00270 gboolean ipc_menu_add_group( const char *name,
00271 const char *parent,
00272 const char *image )
00273 {
00274
00275 return eripc_menu_add_group(eripcClient, name, parent, image);
00276 }
00277
00278
00279 gboolean ipc_menu_add_item( const char *name,
00280 const char *parent,
00281 const char *image )
00282 {
00283
00284 return eripc_menu_add_item(eripcClient, name, parent, image);
00285 }
00286
00287
00288 gboolean ipc_menu_set_menu_label ( const char *name,
00289 const char *label )
00290 {
00291
00292 return eripc_menu_set_menu_label(eripcClient, name, label);
00293 }
00294
00295
00296 gboolean ipc_menu_set_group_label ( const char *name,
00297 const char *label )
00298 {
00299
00300 return eripc_menu_set_group_label(eripcClient, name, label);
00301 }
00302
00303
00304 gboolean ipc_menu_set_item_label ( const char *name,
00305 const char *parent,
00306 const char *label )
00307 {
00308
00309 return eripc_menu_set_item_label(eripcClient, name, parent, label);
00310 }
00311
00312
00313 gboolean ipc_menu_show_menu( const char *name )
00314 {
00315 LOGPRINTF("entry");
00316 return eripc_menu_show_menu(eripcClient, name);
00317 }
00318
00319
00320 gboolean ipc_remove_menu( const char *name )
00321 {
00322 LOGPRINTF("entry");
00323 return eripc_menu_remove_menu(eripcClient, name);
00324 }
00325
00326
00327 gboolean ipc_menu_set_group_state( const char *name,
00328 const char *state )
00329 {
00330 LOGPRINTF("entry");
00331 return eripc_menu_set_group_state(eripcClient, name, state);
00332 }
00333
00334
00335 gboolean ipc_menu_set_item_state( const char *name,
00336 const char *parent,
00337 const char *state )
00338 {
00339
00340 return eripc_menu_set_item_state(eripcClient, name, parent, state);
00341 }
00342
00343
00344 const device_caps_t* ipc_sys_get_device_capabilities ( void )
00345 {
00346 static device_caps_t dev_caps;
00347
00348 eripc_device_caps_t er_dev_caps;
00349
00350 eripc_sysd_get_device_capabilities( eripcClient, &er_dev_caps );
00351
00352 dev_caps.has_stylus = er_dev_caps.has_stylus;
00353 dev_caps.has_wifi = er_dev_caps.has_wifi;
00354 dev_caps.has_bluetooth = er_dev_caps.has_bluetooth;
00355 dev_caps.has_3g = er_dev_caps.has_3g;
00356
00357 return &dev_caps;
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 static void on_menu_item ( eripc_context_t *context,
00374 const eripc_event_info_t *info,
00375 void *user_data )
00376 {
00377 LOGPRINTF("entry");
00378 const eripc_arg_t *arg_array = info->args;
00379
00380 if ((arg_array[0].type == ERIPC_TYPE_STRING) &&
00381 (arg_array[1].type == ERIPC_TYPE_STRING) &&
00382 (arg_array[2].type == ERIPC_TYPE_STRING) &&
00383 (arg_array[3].type == ERIPC_TYPE_STRING))
00384 {
00385 const char *item = arg_array[0].value.s;
00386 const char *group = arg_array[1].value.s;
00387 const char *menu = arg_array[2].value.s;
00388 const char *state = arg_array[3].value.s;
00389
00390 if (item && group && menu && state)
00391 {
00392 menu_on_item_activated( item, group, menu, state );
00393 }
00394 }
00395 }
00396
00397
00398
00399
00400
00401
00402
00403 static void on_window_activated( eripc_context_t *context,
00404 const eripc_event_info_t *info,
00405 void *user_data )
00406 {
00407 LOGPRINTF("entry");
00408 gboolean result = FALSE;
00409 const eripc_arg_t *arg_array = info->args;
00410
00411 if (arg_array[0].type == ERIPC_TYPE_INT)
00412 {
00413 menu_show();
00414 result = TRUE;
00415 }
00416
00417
00418 eripc_reply_bool(context, info->message_id, result);
00419 }
00420
00421
00422
00423
00424
00425
00426 static void on_window_deactivated( eripc_context_t *context,
00427 const eripc_event_info_t *info,
00428 void *user_data )
00429 {
00430 LOGPRINTF("entry");
00431 gboolean result = FALSE;
00432 const eripc_arg_t *arg_array = info->args;
00433
00434 if (arg_array[0].type == ERIPC_TYPE_INT)
00435 {
00436 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00437 view_deactivated();
00438 #endif
00439 result = TRUE;
00440 }
00441
00442
00443 eripc_reply_bool(context, info->message_id, result);
00444 }
00445
00446
00447
00448
00449
00450 static void on_connection_status ( eripc_context_t *context,
00451 const eripc_event_info_t *info,
00452 void *user_data )
00453 {
00454 LOGPRINTF("entry");
00455 const eripc_arg_t *arg_array = info->args;
00456
00457 if ((arg_array[0].type == ERIPC_TYPE_BOOL) &&
00458 (arg_array[1].type == ERIPC_TYPE_STRING) &&
00459 (arg_array[2].type == ERIPC_TYPE_STRING) &&
00460 (arg_array[3].type == ERIPC_TYPE_STRING))
00461 {
00462 gboolean is_connected = arg_array[0].value.b;
00463
00464
00465
00466
00467 if (is_connected)
00468 {
00469 LOGPRINTF("Network connection established");
00470 g_connect_cb();
00471 }
00472 else
00473 {
00474 LOGPRINTF("Network connection terminated - reason [%s]", arg_array[3].value.s);
00475 g_disconnect_cb();
00476 }
00477 }
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 static void on_file_open ( eripc_context_t *context,
00493 const eripc_event_info_t *info,
00494 void *user_data )
00495 {
00496 LOGPRINTF("entry");
00497 gchar *error_msg = NULL;
00498 gint my_xid = -1;
00499
00500 const eripc_arg_t *arg_array = info->args;
00501
00502 if (arg_array[0].type == ERIPC_TYPE_STRING)
00503 {
00504 const char *file = arg_array[0].value.s;
00505 if (file)
00506 {
00507 menu_show();
00508 my_xid = GDK_WINDOW_XID(g_main_window->window);
00509 view_open_uri(file);
00510 }
00511 }
00512
00513
00514 eripc_reply_varargs(context, info->message_id,
00515 ERIPC_TYPE_INT, my_xid,
00516 ERIPC_TYPE_STRING, error_msg,
00517 ERIPC_TYPE_INVALID);
00518 g_free(error_msg);
00519 }
00520
00521
00522
00523
00524
00525
00526
00527 static void on_file_close ( eripc_context_t *context,
00528 const eripc_event_info_t *info,
00529 void *user_data )
00530 {
00531 LOGPRINTF("entry");
00532
00533
00534 eripc_reply_bool(context, info->message_id, TRUE);
00535
00536 main_quit();
00537 }
00538
00539
00540
00541
00542
00543
00544 static void on_mounted ( eripc_context_t *context,
00545 const eripc_event_info_t *info,
00546 void *user_data )
00547 {
00548 LOGPRINTF("entry");
00549 const eripc_arg_t *arg_array = info->args;
00550
00551 if (arg_array[0].type == ERIPC_TYPE_STRING)
00552 {
00553 const char *mountpoint = arg_array[0].value.s;
00554 if (mountpoint)
00555 {
00556 LOGPRINTF("Device mounted: %s", mountpoint);
00557 g_free(g_mountpoint);
00558 g_mountpoint = g_strdup(mountpoint);
00559 }
00560 }
00561 }
00562
00563
00564
00565
00566
00567
00568
00569 static void on_prepare_unmount ( eripc_context_t *context,
00570 const eripc_event_info_t *info,
00571 void *user_data )
00572 {
00573 LOGPRINTF("entry");
00574 const eripc_arg_t *arg_array = info->args;
00575
00576 if (arg_array[0].type == ERIPC_TYPE_STRING)
00577 {
00578 const char *mountpoint = arg_array[0].value.s;
00579 if (mountpoint)
00580 {
00581 g_free(g_mountpoint);
00582 g_mountpoint = NULL;
00583 main_quit();
00584 }
00585 }
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595 static void on_unmounted ( eripc_context_t *context,
00596 const eripc_event_info_t *info,
00597 void *user_data )
00598 {
00599 LOGPRINTF("entry");
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 main_quit();
00608 }
00609 }
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 static void on_changed_locale ( eripc_context_t *context,
00621 const eripc_event_info_t *info,
00622 void *user_data )
00623 {
00624 LOGPRINTF("entry");
00625 const eripc_arg_t *arg_array = info->args;
00626
00627 if (arg_array[0].type == ERIPC_TYPE_STRING)
00628 {
00629 const char *locale = arg_array[0].value.s;
00630 if (locale)
00631 {
00632 const char *old_locale = g_getenv("LANG");
00633 if (!old_locale || (strcmp(old_locale, locale) != 0))
00634 {
00635 g_setenv("LANG", locale, TRUE);
00636 setlocale(LC_ALL, "");
00637
00638 g_locale_cb();
00639 }
00640 }
00641 }
00642 }