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";
23 namespace filesystem {
25 common_installer::Step::Status StepWgtPatchIcons::process() {
26 bf::path common_icon_location = context_->pkg_path.get() / "shared" / "res";
28 bf::create_directories(common_icon_location, error);
29 for (application_x* app :
30 GListRange<application_x*>(context_->manifest_data.get()->application)) {
31 if (strcmp(app->type, "webapp") != 0)
34 // edit icon->text and copy icons to common location
35 for (auto& icon : GListRange<icon_x*>(app->icon)) {
36 bf::path icon_text(icon->text);
37 bf::path icon_path = common_icon_location / app->appid;
38 if (strcmp(icon->lang, DEFAULT_LOCALE)) {
40 icon_path += icon->lang;
42 if (icon_text.has_extension())
43 icon_path += icon_text.extension();
47 bf::copy_file(icon->text, icon_path,
48 bf::copy_option::overwrite_if_exists, error);
50 LOG(ERROR) << "Failed to move icon from " << icon->text << " to "
52 return Status::ICON_ERROR;
55 free(const_cast<char*>(icon->text));
56 icon->text = strdup(icon_path.c_str());
59 LOG(INFO) << "Application provides no icon. Using Tizen default icon.";
60 // create default icon if there is no icon at all
61 bf::path icon_path = common_icon_location / app->appid;
63 bf::copy_file(kDefaultIconPath, icon_path, bf::copy_option::overwrite_if_exists, error);
65 LOG(ERROR) << "Failed to create default icon for web application";
66 return Status::ICON_ERROR;
68 icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
69 icon->text = strdup(icon_path.c_str());
70 icon->lang = strdup(DEFAULT_LOCALE);
71 app->icon = g_list_append(app->icon, icon);
77 } // namespace filesystem