Fix backendlib - wrong icon returned
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 3 Sep 2013 09:04:53 +0000 (11:04 +0200)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Wed, 4 Sep 2013 02:01:25 +0000 (11:01 +0900)
[Issue#]  LINUXWRT-824
[Problem] First icon is always returned from backendlib
          i.e., Curent locale settigns are not taken into account.
[Cause]   This was just not handled before.
            - The exact problem is that after installation icon is ok(notiication)
              but before it is read from package file.
            - This operation does not involve full steps in case of installation.
              Backend lib should do it in more checking to find best icon.
[Solution] Added workaround to return icon according to locale setting

[Verification] Install bm.wgt (W3C P&C icon test) from MyFiles app.
    Icon in "install prompt view" (before installing) and in notification
    should be used for proper locale (change locale to en).

Change-Id: If9d9d32dd2a69914bf72aacf6a82c7881cab2918

src/pkg-manager/backendlib.cpp

index 7995119..40665f5 100644 (file)
@@ -319,8 +319,8 @@ int getConfigParserData(const std::string &widgetPath, ConfigParserData& configI
     return TRUE;
 }
 
-char* getIconInfo(const std::string widgetPath,
-        const std::string icon_name, int &icon_size)
+char* getIconInfo(const std::string &widgetPath,
+        const std::string &icon_name, int &icon_size)
 {
     Try {
         std::unique_ptr<DPL::ZipInput> zipFile(
@@ -349,16 +349,62 @@ char* getIconInfo(const std::string widgetPath,
     }
     Catch(DPL::ZipInput::Exception::OpenFailed)
     {
-        LogError("Failed to open widget package");
+        LogDebug("Failed to open widget package");
         return NULL;
     }
     Catch(DPL::ZipInput::Exception::OpenFileFailed)
     {
-        LogError("Failed to open icon file");
+        LogDebug("Not found icon file " << icon_name);
         return NULL;
     }
 }
 
+char* getIconForLocale(const std::string& bp, const std::string& tag,
+                                     const std::string& icon, int & size)
+{
+    std::string iconPath;
+    if (!tag.empty()) {
+        iconPath += std::string("locales/") + tag;
+    }
+    if (!iconPath.empty()) {
+        iconPath += "/";
+    }
+
+    iconPath += icon;
+    return getIconInfo(bp, iconPath, size);
+}
+
+char* getIcon(const std::string & basepath, const WrtDB::ConfigParserData & config, int & size)
+{
+    const std::list<std::string> defaultIcons{ "icon.svg", "icon.ico", "icon.png", "icon.gif", "icon.jpg" };
+    LanguageTags tagsList =
+        LanguageTagsProviderSingleton::Instance().getLanguageTags();
+
+    char * result = NULL;
+
+    //for each locale tag - searching for icon presence and returning raw data
+    //first found is best as locale tags are ordered
+    FOREACH(tag, tagsList)
+    {
+        FOREACH(icon, config.iconsList)
+        {
+            std::string src = DPL::ToUTF8String(icon->src);
+            result = getIconForLocale(basepath, DPL::ToUTF8String(*tag), src, size);
+            if(result) {
+                return result;
+            }
+        }
+        FOREACH(i, defaultIcons)
+        {
+            result = getIconForLocale(basepath, DPL::ToUTF8String(*tag), *i, size);
+            if(result) {
+                return result;
+            }
+        }
+    }
+    return NULL;
+}
+
 int getWidgetDetailInfoFromPackage(const char* pkgPath,
         package_manager_pkg_detail_info_t* pkg_detail_info)
 {
@@ -463,16 +509,16 @@ int getWidgetDetailInfoFromPackage(const char* pkgPath,
             g_list_append(pkg_detail_info->privilege_list, privilege);
     }
 
-    std::string icon_name;
-    FOREACH(i, configInfo.iconsList) {
-        LogDebug("icon name: " << i->src);
-        icon_name = DPL::ToUTF8String(i->src);
-        break;
-    }
+    char* icon_buf = getIcon(widget_path, configInfo, pkg_detail_info->icon_size);
 
-    pkg_detail_info->icon_buf = getIconInfo(widget_path, icon_name,
-            pkg_detail_info->icon_size);
-    LogDebug("icon size : " << pkg_detail_info->icon_size);
+    if (icon_buf) {
+        LogDebug("icon size : " << pkg_detail_info->icon_size);
+        pkg_detail_info->icon_buf = icon_buf;
+    } else {
+        LogDebug("No icon");
+        pkg_detail_info->icon_size = 0;
+        pkg_detail_info->icon_buf = NULL;
+    }
 
     return TRUE;
 }