1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
7 #include <pkgmgr-info.h>
9 #include "common/utils/file_util.h"
10 #include "common/utils/glist_range.h"
12 namespace bf = boost::filesystem;
13 namespace bs = boost::system;
14 namespace ci = common_installer;
18 const char kDefaultIconPath[] = "/usr/share/wgt-backend/default.png";
20 bool PatchIcon(icon_x* icon, const bf::path& dst_path) {
24 bf::path icon_text(icon->text);
25 bf::path icon_path = dst_path;
26 if (strcmp(icon->lang, DEFAULT_LOCALE)) {
28 icon_path += icon->lang;
30 if (icon_text.has_extension())
31 icon_path += icon_text.extension();
35 bf::copy_file(icon->text, icon_path,
36 bf::copy_option::overwrite_if_exists, error);
38 LOG(ERROR) << "Failed to move icon from " << icon->text << " to "
43 free(const_cast<char*>(icon->text));
44 icon->text = strdup(icon_path.c_str());
52 namespace filesystem {
54 common_installer::Step::Status StepWgtPatchIcons::process() {
55 bf::path common_icon_location = context_->GetPkgPath() / "shared" / "res";
57 bf::create_directories(common_icon_location, error);
59 LOG(ERROR) << "Failed to create common icon location directory";
60 return Status::ICON_ERROR;
63 GListRange<icon_x*>(context_->manifest_data.get()->icon)) {
64 bf::path icon_path = common_icon_location /
65 context_->manifest_data.get()->mainapp_id;
66 if (!PatchIcon(icon, icon_path))
67 return Status::ICON_ERROR;
69 for (application_x* app :
70 GListRange<application_x*>(context_->manifest_data.get()->application)) {
71 if (strcmp(app->type, "webapp") != 0)
74 // edit icon->text and copy icons to common location
75 for (auto& icon : GListRange<icon_x*>(app->icon)) {
76 bf::path icon_path = common_icon_location / app->appid;
77 if (!PatchIcon(icon, icon_path))
78 return Status::ICON_ERROR;
81 LOG(INFO) << "Application provides no icon. Using Tizen default icon.";
82 // create default icon if there is no icon at all
83 bf::path icon_path = common_icon_location / app->appid;
85 bf::copy_file(kDefaultIconPath, icon_path,
86 bf::copy_option::overwrite_if_exists, error);
88 LOG(ERROR) << "Failed to create default icon for web application";
89 return Status::ICON_ERROR;
91 icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
93 LOG(ERROR) << "Out of memory";
94 return Status::ICON_ERROR;
96 icon->text = strdup(icon_path.c_str());
97 icon->lang = strdup(DEFAULT_LOCALE);
98 app->icon = g_list_append(app->icon, icon);
104 } // namespace filesystem