Icon extension for package manager and manifest fix
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 19 Aug 2013 09:58:29 +0000 (11:58 +0200)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Tue, 20 Aug 2013 14:21:55 +0000 (23:21 +0900)
[Issue#]       LINUXWRT-804 / WGL-428
[Bug]          Hardcoded .png extension
[Cause]        N/A
[Solution]     Use extension of used icon
[SCMRequest]   This requries wrt-commons change: https://review.tizendev.org/gerrit/86777
[Verification] Install widget from https://bugs.tizendev.org/jira/browse/WGL-428.
Manifest file in /opt/share/packages/J7tHY89x22.xml should contain icon with .svg extension
(<icon>J7tHY89x22.Y2y1.svg</icon>).

Change-Id: Ifef3f38e1566b92817f62aa01c1ac73bc073d71b

src/jobs/widget_install/task_manifest_file.cpp
src/jobs/widget_install/task_manifest_file.h
src/jobs/widget_install/task_widget_config.cpp

index 37d856e..8308125 100644 (file)
@@ -52,6 +52,7 @@
 #include <libxml_utils.h>
 #include <pkgmgr/pkgmgr_parser.h>
 #include <dpl/localization/LanguageTagsProvider.h>
+#include <dpl/utils/path.h>
 
 #define DEFAULT_ICON_NAME   "icon.png"
 #define DEFAULT_PREVIEW_NAME   "preview.png"
@@ -219,53 +220,37 @@ void TaskManifestFile::stepCopyIconFiles()
             if (std::find(generatedLocales.begin(), generatedLocales.end(),
                     *locale) != generatedLocales.end())
             {
-                if (icon->src == L"icon.jpg") {
-                    generatedLocales.push_back(*locale);
-                } else if (icon->src == L"icon.gif") {
-                    generatedLocales.push_back(*locale);
-                } else if (icon->src == L"icon.png") {
-                    generatedLocales.push_back(*locale);
-                } else if (icon->src == L"icon.ico") {
-                    generatedLocales.push_back(*locale);
-                } else if (icon->src == L"icon.svg") {
-                    generatedLocales.push_back(*locale);
-                }
                 LogDebug("Skipping - has that locale");
                 continue;
             } else {
                 generatedLocales.push_back(*locale);
             }
 
-            std::ostringstream sourceFile;
-            std::ostringstream targetFile;
-
-            sourceFile << m_context.locations->getSourceDir() << "/";
-
+            DPL::Utils::Path sourceFile(m_context.locations->getSourceDir());
             if (!locale->empty()) {
-                sourceFile << "locales/" << *locale << "/";
+                sourceFile /= "locales";
+                sourceFile /= *locale;
             }
+            sourceFile /= src;
 
-            sourceFile << src;
-
-            targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
-            targetFile << getIconTargetFilename(*locale);
+            DPL::Utils::Path targetFile(GlobalConfig::GetUserWidgetDesktopIconPath());
+            targetFile /= getIconTargetFilename(*locale, sourceFile.Extension());
 
             if (m_context.widgetConfig.packagingType ==
                 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
             {
                 m_context.locations->setIconTargetFilenameForLocale(
-                    targetFile.str());
+                    targetFile.Fullpath());
             }
 
-            LogDebug("Copying icon: " << sourceFile.str() <<
-                     " -> " << targetFile.str());
+            LogDebug("Copying icon: " << sourceFile << " -> " << targetFile);
 
-            icon_list.push_back(targetFile.str());
+            icon_list.push_back(targetFile.Fullpath());
 
             Try
             {
-                DPL::FileInput input(sourceFile.str());
-                DPL::FileOutput output(targetFile.str());
+                DPL::FileInput input(sourceFile.Fullpath());
+                DPL::FileOutput output(targetFile.Fullpath());
                 DPL::Copy(&input, &output);
             }
 
@@ -442,7 +427,7 @@ void TaskManifestFile::stepAbortIconFiles()
 }
 
 DPL::String TaskManifestFile::getIconTargetFilename(
-    const DPL::String& languageTag) const
+    const DPL::String& languageTag, const std::string & ext) const
 {
     DPL::OStringStream filename;
     TizenAppId appid = m_context.widgetConfig.tzAppid;
@@ -465,7 +450,10 @@ DPL::String TaskManifestFile::getIconTargetFilename(
         }
     }
 
-    filename << L".png";
+    if(!ext.empty())
+    {
+        filename << L"." + DPL::FromUTF8String(ext);
+    }
     return filename.str();
 }
 
@@ -826,12 +814,13 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
                 tag = *locale;
             }
 
-            generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
+            generateWidgetIcon(uiApp, tag, *locale, DPL::Utils::Path(icon->src).Extension(), defaultIconSaved);
         }
     }
     if (!!defaultLocale && !defaultIconSaved) {
         generateWidgetIcon(uiApp, DPL::OptionalString::Null,
                            DPL::String(),
+                           std::string(),
                            defaultIconSaved);
     }
 }
@@ -839,6 +828,7 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
                                           const DPL::OptionalString& tag,
                                           const DPL::String& language,
+                                          const std::string & extension,
                                           bool & defaultIconSaved)
 {
     DPL::String locale;
@@ -849,7 +839,7 @@ void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
     }
 
     DPL::String iconText;
-    iconText += getIconTargetFilename(language);
+    iconText += getIconTargetFilename(language, extension);
 
     if (!locale.empty()) {
         uiApp.addIcon(IconType(iconText, locale));
@@ -858,8 +848,8 @@ void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
     }
     std::ostringstream iconPath;
     iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
-    iconPath << getIconTargetFilename(locale);
-     m_context.job->SendProgressIconPath(iconPath.str());
+    iconPath << getIconTargetFilename(locale, extension);
+    m_context.job->SendProgressIconPath(iconPath.str());
 }
 
 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
index a318fc8..98c3d23 100644 (file)
@@ -118,7 +118,7 @@ class TaskManifestFile :
                                    DPL::OptionalString description);
     void generateWidgetIcon(UiApplication & uiApp,
                             const DPL::OptionalString& tag,
-                            const DPL::String& language,
+                            const DPL::String& language, const std::string &extension,
                             bool & defaultIconSaved);
     void DynamicBoxFileCopy(const std::string& sourceFile,
                             const std::string& targetFile);
@@ -126,7 +126,8 @@ class TaskManifestFile :
     //for widget update
     void backupIconFiles();
     void getFileList(const char* path, std::list<std::string> &list);
-    DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
+    DPL::String getIconTargetFilename(const DPL::String& languageTag,
+                                      const std::string & ext) const;
 
     static void saveLocalizedKey(std::ofstream &file,
                                  const DPL::String& key,
index 221fd1c..c837279 100644 (file)
@@ -293,7 +293,7 @@ void TaskWidgetConfig::ProcessBackgroundPageFile()
 void TaskWidgetConfig::ProcessLocalizedIcons()
 {
     using namespace WrtDB;
-        FOREACH(i, m_installContext.widgetConfig.configInfo.iconsList)
+    FOREACH(i, m_installContext.widgetConfig.configInfo.iconsList)
     {
         ProcessIcon(*i);
     }