Monitor Web IME install/uninstall/update and update engine list 03/31603/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 23 Apr 2014 11:53:49 +0000 (20:53 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 8 Dec 2014 00:58:14 +0000 (09:58 +0900)
Change-Id: Ie40b014922887eab833a6f786a0d7cb7fdcc7b23

configure.ac
ism/extras/efl_panel/Makefile.am
ism/extras/efl_panel/isf_panel_efl.cpp
ism/extras/efl_panel/isf_panel_utility.cpp
ism/extras/efl_panel/isf_panel_utility.h
ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h
packaging/isf.spec

index 0c3ec8d..fc2ec11 100755 (executable)
@@ -310,6 +310,9 @@ PKG_CHECK_MODULES(FEEDBACK, [feedback],
                   [ISF_HAS_FEEDBACK=yes],
                   [ISF_HAS_FEEDBACK=no])
 
+# Check package manager
+PKG_CHECK_MODULES(PACKAGE_MANAGER, [capi-appfw-package-manager])
+
 if test "$ISF_HAS_VCONF" = "yes"; then
   AC_DEFINE(HAVE_VCONF,1,[Have VConf functions.])
 fi
index fc0ff09..c76d51b 100644 (file)
@@ -34,8 +34,20 @@ if ISF_BUILD_MINICONTROL
 isf_panel_efl_SOURCES  += minicontrol.cpp
 endif
 
-isf_panel_efl_CXXFLAGS = @EFL_CFLAGS@ @ECOREX_CFLAGS@ @EFL_ASSIST_CFLAGS@ @VCONF_CFLAGS@ @X11_CFLAGS@ @PRIVILEGE_CONTROL_CFLAGS@ @DLOG_CFLAGS@ \
-                         @MINICONTROL_PROVIDER_CFLAGS@ @NOTIFICATION_CFLAGS@ @TTS_CFLAGS@ @EDBUS_CFLAGS@ @BLUETOOTH_CFLAGS@ @FEEDBACK_CFLAGS@
+isf_panel_efl_CXXFLAGS = @EFL_CFLAGS@ \
+                         @EFL_ASSIST_CFLAGS@ \
+                         @VCONF_CFLAGS@ \
+                         @X11_CFLAGS@ \
+                         @PRIVILEGE_CONTROL_CFLAGS@ \
+                         @DLOG_CFLAGS@ \
+                         @MINICONTROL_PROVIDER_CFLAGS@ \
+                         @NOTIFICATION_CFLAGS@ \
+                         @TTS_CFLAGS@ \
+                         @EDBUS_CFLAGS@ \
+                         @BLUETOOTH_CFLAGS@ \
+                         @FEEDBACK_CFLAGS@ \
+                         @UIGADGET_CFLAGS@ \
+                         @PACKAGE_MANAGER_CFLAGS@
 
 isf_panel_efl_LDFLAGS  = @EFL_LIBS@ @LTLIBINTL@ -rpath $(libdir) \
                          @ECOREX_LIBS@ \
@@ -49,7 +61,8 @@ isf_panel_efl_LDFLAGS  = @EFL_LIBS@ @LTLIBINTL@ -rpath $(libdir) \
                          @TTS_LIBS@ \
                          @EDBUS_LIBS@ \
                          @BLUETOOTH_LIBS@ \
-                         @FEEDBACK_LIBS@
+                         @UIGADGET_LIBS@ \
+                         @PACKAGE_MANAGER_LIBS@
 
 isf_panel_efl_LDADD    = $(top_builddir)/ism/src/libscim@SCIM_EPOCH@.la
 
index 79c16a1..322d29a 100644 (file)
@@ -74,6 +74,7 @@
 #if HAVE_BLUETOOTH
 #include <bluetooth.h>
 #endif
+#include <package_manager.h>
 
 using namespace scim;
 
@@ -390,6 +391,7 @@ static Ecore_File_Monitor *_osp_helper_ise_em               = NULL;
 static Ecore_File_Monitor *_osp_keyboard_ise_em             = NULL;
 static OSPEmRepository     _osp_bin_em;
 static OSPEmRepository     _osp_info_em;
+static package_manager_h   pkgmgr                           = NULL;
 
 static bool               _launch_ise_on_request            = false;
 static bool               _soft_keyboard_launched           = false;
@@ -422,6 +424,8 @@ static E_DBus_Signal_Handler *edbus_handler;
 
 static Ecore_Event_Handler *_candidate_show_handler         = NULL;
 
+static HelperInfo         remove_helper_info;
+
 enum {
     EMOJI_IMAGE_WIDTH = 0,
     EMOJI_IMAGE_HEIGHT,
@@ -1013,6 +1017,120 @@ static unsigned int get_ise_index (const String uuid)
     return index;
 }
 
+static bool
+app_info_cb (package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
+{
+    HelperInfo *helper_info = (HelperInfo *)user_data;
+    if (!helper_info) return false;
+
+    /* FIXME : need to use generated UUID */
+    helper_info->uuid = String (app_id);
+
+    return true;
+}
+
+static bool get_helper_ise_info (const char *type, const char *package, HelperInfo *helper_info)
+{
+    package_info_h pkg_info;
+    char *pkg_label = NULL;
+    char *pkg_icon_path = NULL;
+    bool result = false;
+
+    if (!type)
+        return false;
+
+    if (strncmp (type, "wgt", 3) != 0)
+        return false;
+
+    package_manager_get_package_info (package, &pkg_info);
+    if (!pkg_info)
+        return false;
+
+    package_info_get_label (pkg_info, &pkg_label);
+    package_info_get_icon (pkg_info, &pkg_icon_path);
+
+    if (pkg_label && (strcasestr (pkg_label, "ime"))) {
+        package_info_foreach_app_from_package (pkg_info, PACKAGE_INFO_UIAPP, app_info_cb, helper_info);
+        helper_info->name = String (pkg_label);
+        helper_info->icon = String (pkg_icon_path);
+        helper_info->option = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_NEED_SPOT_LOCATION_INFO | SCIM_HELPER_AUTO_RESTART;
+
+        if (pkg_label)
+            free (pkg_label);
+
+        if (pkg_icon_path)
+            free (pkg_icon_path);
+
+        result = true;
+    }
+
+    package_info_destroy (pkg_info);
+
+    return result;
+}
+
+static void _package_manager_event_cb (const char *type, const char *package, package_manager_event_type_e event_type, package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data)
+{
+    if (!package || !type) return;
+
+    if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL ||
+        event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE) {
+        HelperInfo helper_info;
+
+        if (event_state != PACKAGE_MANAGER_EVENT_STATE_COMPLETED)
+            return;
+
+        if (get_helper_ise_info (type, package, &helper_info)) {
+            /* update engine list */
+            if (isf_remove_helper_ise (helper_info.uuid.c_str (), _config))
+                LOGD ("remove helper info. uuid : %s\n", helper_info.uuid.c_str ());
+
+            if (isf_add_helper_ise (helper_info, String ("ise-web-helper-agent"))) {
+                LOGD ("add helper info. uuid : %s\n", helper_info.uuid.c_str ());
+                _panel_agent->update_ise_list (_uuids);
+            }
+        }
+    } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
+        switch (event_state) {
+            case PACKAGE_MANAGER_EVENT_STATE_STARTED:
+                /* get package information and check whether the type of package is Web IME */
+                /* In COMPLETED status, it is impossible to get the package information,
+                   therefore it is necessary to get package information in the START status in advance */
+                if (get_helper_ise_info (type, package, &remove_helper_info)) {
+                    LOGD ("'%s' package has been uninstalled", remove_helper_info.name.c_str ());
+                }
+                break;
+            case PACKAGE_MANAGER_EVENT_STATE_COMPLETED:
+                if (remove_helper_info.uuid.length () == 0)
+                    return;
+
+                /* update engine list */
+                if (isf_remove_helper_ise (remove_helper_info.uuid.c_str (), _config)) {
+                    LOGD ("Completed to remove IME uuid : %s\n", remove_helper_info.uuid.c_str ());
+
+                    _panel_agent->update_ise_list (_uuids);
+
+                    String uuid  = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid);
+                    if (uuid == remove_helper_info.uuid) {
+                        /* switching to initial ISE */
+                        if (_soft_keyboard_launched) {
+                            _panel_agent->hide_helper (uuid);
+                            _panel_agent->stop_helper (uuid);
+                            _panel_agent->start_helper (_initial_ise_uuid);
+                        }
+                    }
+                }
+                remove_helper_info.uuid = String ("");
+                break;
+            case PACKAGE_MANAGER_EVENT_STATE_FAILED:
+                remove_helper_info.uuid = String ("");
+                break;
+            default:
+                break;
+        }
+    }
+}
+
 /**
  * @brief Get ISE module file path.
  *
@@ -1314,6 +1432,11 @@ static void delete_ise_directory_em (void) {
     }
     _osp_bin_em.clear ();
     _osp_info_em.clear ();
+
+    if (pkgmgr) {
+        package_manager_destroy (pkgmgr);
+        pkgmgr = NULL;
+    }
 }
 
 /**
@@ -1368,6 +1491,11 @@ static void add_ise_directory_em (void) {
     }
 
     add_monitor_for_all_osp_modules ();
+
+    if (!pkgmgr) {
+        package_manager_create (&pkgmgr);
+        package_manager_set_event_cb (pkgmgr, _package_manager_event_cb, NULL);
+    }
 }
 
 /**
index d538ccf..32503ad 100644 (file)
@@ -645,6 +645,65 @@ String isf_get_normalized_language (String src_str)
     return dst_str;
 }
 
+bool isf_add_helper_ise (HelperInfo helper_info, String module_name)
+{
+    String filename = String (USER_ENGINE_FILE_NAME);
+    FILE *engine_list_file = fopen (filename.c_str (), "a");
+    if (engine_list_file == NULL) {
+        LOGW ("Failed to open %s!!!\n", filename.c_str ());
+        return false;
+    }
+
+    _uuids.push_back (helper_info.uuid);
+    _names.push_back (helper_info.name);
+    _langs.push_back (isf_get_normalized_language ("en_US")); // FIXME
+    _module_names.push_back (module_name);
+    _icons.push_back (helper_info.icon);
+    _modes.push_back (TOOLBAR_HELPER_MODE);
+    _options.push_back (helper_info.option);
+
+    char mode[12];
+    char option[12];
+    snprintf (mode, sizeof (mode), "%d", (int)TOOLBAR_HELPER_MODE);
+    snprintf (option, sizeof (option), "%d", helper_info.option);
+
+    String line = isf_combine_ise_info_string (helper_info.name, helper_info.uuid, module_name, isf_get_normalized_language ("en_US"),
+                                               helper_info.icon, String (mode), String (option), String (""));
+    if (fputs (line.c_str (), engine_list_file) < 0) {
+         LOGW ("Failed to write (%s)!!!\n", line.c_str ());
+    }
+
+    if (fclose (engine_list_file) != 0)
+        LOGW ("Failed to fclose %s!!!\n", filename.c_str ());
+
+    return true;
+}
+
+bool isf_remove_helper_ise (const char *uuid, const ConfigPointer &config)
+{
+    String filename = String (USER_ENGINE_FILE_NAME);
+    if (isf_remove_ise_info_from_file_by_uuid (filename.c_str (), uuid)) {
+        isf_get_factory_list (ALL_ISE, config, _uuids, _names, _module_names, _langs, _icons, _modes, _options);
+
+        /* Update _groups */
+        _groups.clear ();
+        std::vector<String> ise_langs;
+        for (size_t i = 0; i < _uuids.size (); ++i) {
+            scim_split_string_list (ise_langs, _langs[i]);
+            for (size_t j = 0; j < ise_langs.size (); j++) {
+                if (std::find (_groups[ise_langs[j]].begin (), _groups[ise_langs[j]].end (), i) == _groups[ise_langs[j]].end ())
+                    _groups[ise_langs[j]].push_back (i);
+            }
+            ise_langs.clear ();
+        }
+        return true;
+    } else {
+        LOGW ("Failed to remove uuid : %s from cache file : %s!!!", uuid, filename.c_str ());
+        return false;
+    }
+}
+
+
 /*
 vi:ts=4:nowrap:ai:expandtab
 */
index 1c79019..0cfc480 100644 (file)
@@ -66,6 +66,8 @@ void isf_load_ise_information (LOAD_ISE_TYPE type, const ConfigPointer &config);
 bool isf_update_ise_list (LOAD_ISE_TYPE type, const ConfigPointer &config);
 bool isf_update_ise_module (const String strModulePath, const ConfigPointer &config);
 String isf_get_normalized_language (String src_str);
+bool isf_add_helper_ise (HelperInfo helper_info, String module_name);
+bool isf_remove_helper_ise (const char *uuid, const ConfigPointer &config);
 
 #endif /* __ISF_PANEL_UTILITY_H */
 
index a9f6c96..4f74e27 100644 (file)
@@ -274,6 +274,25 @@ static void remove_ise_info_from_list (std::vector<ISEINFO> &info_list, const ch
     }
 }
 
+static void remove_ise_info_from_list_by_uuid (std::vector<ISEINFO> &info_list, const char *uuid)
+{
+    if (uuid == NULL)
+        return;
+
+    std::vector<ISEINFO>::iterator iter;
+    while (info_list.size () > 0) {
+        for (iter = info_list.begin (); iter != info_list.end (); iter++) {
+            if (iter->uuid == uuid)
+                break;
+        }
+
+        if (iter !=  info_list.end ())
+            info_list.erase (iter);
+        else
+            break;
+    }
+}
+
 EAPI bool isf_add_keyboard_info_to_file (const char *filename, const char *module_name, const ConfigPointer &config)
 {
     std::vector<ISEINFO> info_list;
@@ -316,6 +335,20 @@ EAPI bool isf_remove_ise_info_from_file (const char *filename, const char *modul
     return false;
 }
 
+EAPI bool isf_remove_ise_info_from_file_by_uuid (const char *filename, const char *uuid)
+{
+    std::vector<ISEINFO> info_list;
+    std::vector<ISEINFO>::iterator iter;
+
+    if (isf_read_ise_info_list (filename, info_list)) {
+
+        remove_ise_info_from_list_by_uuid (info_list, uuid);
+
+        return isf_write_ise_info_list (filename, info_list);
+    }
+    return false;
+}
+
 EAPI void isf_update_ise_info_to_file (const char *filename, const ConfigPointer &config)
 {
     if (filename == NULL)
index 908d1ea..aaca6c4 100644 (file)
@@ -65,6 +65,7 @@ EAPI bool isf_write_ise_info_list (const char *filename, std::vector<ISEINFO> &i
 EAPI bool isf_add_keyboard_info_to_file (const char *filename, const char *module_name, const ConfigPointer &config);
 EAPI bool isf_add_helper_info_to_file (const char *filename, const char *module_name);
 EAPI bool isf_remove_ise_info_from_file (const char *filename, const char *module_name);
+EAPI bool isf_remove_ise_info_from_file_by_uuid (const char *filename, const char *uuid);
 EAPI void isf_update_ise_info_to_file (const char *filename, const ConfigPointer &config);
 
 #endif /* __ISF_QUERY_UTILITY_H */
index 61f4cbd..0681b5f 100644 (file)
@@ -40,6 +40,7 @@ BuildRequires:  pkgconfig(feedback)
 BuildRequires:  efl-assist-devel
 BuildRequires:  pkgconfig(ail)
 BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  capi-appfw-package-manager-devel
 Requires(post): /sbin/ldconfig /usr/bin/vconftool
 Requires(postun): /sbin/ldconfig