Fix file key generation
[platform/core/appfw/tizen-theme-manager.git] / src / theme_plugin / theme_info_builder.cc
1 // Copyright (c) 2020 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.
4
5 #include "theme_plugin/theme_info_builder.h"
6
7 #include <boost/filesystem.hpp>
8
9 #include <algorithm>
10 #include <string>
11
12 #include "theme/utils/logging.h"
13
14 namespace bf = boost::filesystem;
15
16 namespace {
17
18 const char kThemeFilesPrefix[] = "/theme/files/";
19
20 }  // namespace
21
22 namespace ttm {
23 namespace plugin {
24
25 ThemeInfoBuilder::ThemeInfoBuilder(const std::string& id) {
26   bundle_.Add("id", id);
27 }
28
29 ThemeInfoBuilder& ThemeInfoBuilder::PutString(const std::string& key,
30     const std::string& value) {
31   bundle_.Add(key, value);
32   return *this;
33 }
34
35 ThemeInfoBuilder& ThemeInfoBuilder::PutStringArray(const std::string& key,
36     const std::vector<std::string>& value) {
37   bundle_.Add(key, value);
38   return *this;
39 }
40
41 loader::ThemeInfo ThemeInfoBuilder::Build() {
42   return loader::ThemeInfo(bundle_);
43 }
44
45 void ThemeInfoBuilder::GenerateFileKey(const std::string& root) {
46   for (bf::recursive_directory_iterator it(root);
47       it != bf::recursive_directory_iterator(); ++it) {
48     if (!bf::is_directory(it->path()))
49       continue;
50
51     std::string filepath = it->path().string().substr(root.size());
52     std::string key = kThemeFilesPrefix + filepath;
53     std::string val = "shared/res/" + filepath;
54     bundle_.Add(key, val);
55   }
56 }
57
58 }  // namespace plugin
59 }  // namespace ttm