12c247919a68dc04834ff419e8620b7a71d905ce
[platform/core/appfw/tizen-theme-manager.git] / src / theme_plugin / theme_parser.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_parser.h"
6
7 #include <json/json.h>
8 #include <sys/types.h>
9
10 #include <fstream>
11 #include <streambuf>
12 #include <string>
13
14 #include "theme/loader/theme_info.h"
15 #include "theme/utils/logging.h"
16 #include "theme_plugin/theme_info_builder.h"
17
18 namespace ttm {
19 namespace plugin {
20
21 loader::ThemeInfo ThemeParser::Inflate(const std::string id,
22     const std::string pkgid, uid_t uid) {
23   Json::CharReaderBuilder rbuilder;
24   rbuilder["collectComments"] = false;
25
26   std::ifstream ifs(path_);
27   Json::Value root;
28   std::string error;
29   if (!Json::parseFromStream(rbuilder, ifs, &root, &error)) {
30     LOG(ERROR) << "Failed to read json file: " << error;
31     ifs.close();
32     return {};
33   }
34
35   // FIXME: this parser should parse more theme information.
36   ThemeInfoBuilder builder("testid");
37   builder.PutString("pkgid", pkgid).
38       PutString("uid", std::to_string(uid)).
39       PutString("version", root["version"].asString()).
40       PutString("tool_version", root["tool_version"].asString()).
41       PutString("title", root["header"]["title"].asString()).
42       PutString("description", root["header"]["description"].asString());
43
44   return builder.Build();
45 }
46
47 int ThemeParser::Commit(ThemeOperation operation,
48   const loader::ThemeInfo& theme) {
49   switch (operation) {
50     case ThemeOperation::ADD:
51       LOG(DEBUG) << "Add Theme: " << theme.GetId();
52       // send dbus request at here
53       break;
54     case ThemeOperation::UPDATE:
55       LOG(DEBUG) << "Update Theme: " << theme.GetId();
56       // send dbus request at here
57       break;
58     case ThemeOperation::REMOVE:
59       LOG(DEBUG) << "Remove Theme: " << theme.GetId();
60       // send dbus request at here
61       break;
62   }
63   return 0;
64 }
65
66 }  // namespace plugin
67 }  // namespace ttm