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) {
22 bf::path icon_text(icon->text);
23 bf::path icon_path = dst_path;
24 if (strcmp(icon->lang, DEFAULT_LOCALE)) {
26 icon_path += icon->lang;
28 if (icon_text.has_extension())
29 icon_path += icon_text.extension();
33 bf::copy_file(icon->text, icon_path,
34 bf::copy_option::overwrite_if_exists, error);
36 LOG(ERROR) << "Failed to move icon from " << icon->text << " to "
41 free(const_cast<char*>(icon->text));
42 icon->text = strdup(icon_path.c_str());
50 namespace filesystem {
52 common_installer::Step::Status StepWgtPatchIcons::process() {
53 bf::path common_icon_location = context_->pkg_path.get() / "shared" / "res";
55 bf::create_directories(common_icon_location, error);
57 GListRange<icon_x*>(context_->manifest_data.get()->icon)) {
58 bf::path icon_path = common_icon_location /
59 context_->manifest_data.get()->mainapp_id;
60 if (!PatchIcon(icon, icon_path))
61 return Status::ICON_ERROR;
63 for (application_x* app :
64 GListRange<application_x*>(context_->manifest_data.get()->application)) {
65 if (strcmp(app->type, "webapp") != 0)
68 // edit icon->text and copy icons to common location
69 for (auto& icon : GListRange<icon_x*>(app->icon)) {
70 bf::path icon_path = common_icon_location / app->appid;
71 if (!PatchIcon(icon, icon_path))
72 return Status::ICON_ERROR;
75 LOG(INFO) << "Application provides no icon. Using Tizen default icon.";
76 // create default icon if there is no icon at all
77 bf::path icon_path = common_icon_location / app->appid;
79 bf::copy_file(kDefaultIconPath, icon_path,
80 bf::copy_option::overwrite_if_exists, error);
82 LOG(ERROR) << "Failed to create default icon for web application";
83 return Status::ICON_ERROR;
85 icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
87 return Status::ICON_ERROR;
88 icon->text = strdup(icon_path.c_str());
89 icon->lang = strdup(DEFAULT_LOCALE);
90 app->icon = g_list_append(app->icon, icon);
96 } // namespace filesystem