SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
## Targets
+SET(TARGET_THEME_CMD "theme-cmd")
SET(TARGET_THEME_PROVIDER "theme-provider")
SET(TARGET_TIZEN_THEME "tizen-theme")
SET(TARGET_TIZEN_THEME_API "capi-appfw-tizen-theme")
ADD_SUBDIRECTORY(api)
ADD_SUBDIRECTORY(main)
ADD_SUBDIRECTORY(theme)
+ADD_SUBDIRECTORY(theme_cmd)
ADD_SUBDIRECTORY(theme_plugin)
ADD_SUBDIRECTORY(theme_provider)
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} CMD_SRCS)
+ADD_EXECUTABLE(${TARGET_THEME_CMD} ${CMD_SRCS})
+TARGET_INCLUDE_DIRECTORIES(${TARGET_THEME_CMD} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_THEME_CMD} PUBLIC
+ DATABASE_DEPS
+ GLIB_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_THEME_CMD} PRIVATE ${TARGET_TIZEN_THEME} ${TARGET_TIZEN_THEME_PROVIDER})
+SET_TARGET_PROPERTIES(${TARGET_THEME_CMD} PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_THEME_CMD} PROPERTIES LINK_FLAGS "-pie")
+
+INSTALL(TARGETS ${TARGET_THEME_CMD} DESTINATION ${BINDIR})
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <any>
+#include <exception>
+#include <iostream>
+#include <map>
+#include <string>
+
+#include "theme_cmd/parser.h"
+#include "theme_cmd/theme_cmd.h"
+
+int main(int argc, char* argv[]) {
+ ttm::cmd::Parser parser;
+ auto args = parser.Parse(argc, argv);
+ if (args.empty())
+ return 1;
+
+ try {
+ ttm::cmd::Cmd cmd;
+ if (args.find("set-default") != args.end()) {
+ std::string id = std::any_cast<std::string>(args["set-default"]);
+ cmd.SetDefaultTheme(id);
+ } else if (args.find("get") != args.end()) {
+ std::string id = std::any_cast<std::string>(args["get"]);
+ cmd.PrintThemeInfo(id);
+ } else if (args.find("get-current") != args.end()) {
+ cmd.PrintCurrentTheme();
+ } else if (args.find("list") != args.end()) {
+ cmd.PrintThemeList();
+ }
+ } catch (const std::exception& e) {
+ std::cerr << "exception caught: " << e.what() << std::endl;
+ }
+
+ return 0;
+}
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "theme_cmd/parser.h"
+
+#include <getopt.h>
+
+#include <any>
+#include <iostream>
+#include <map>
+#include <string>
+
+namespace {
+
+constexpr char short_opts[] = "hs:g:cl";
+const struct option long_opts[] = {
+ { "help", no_argument, nullptr, 'h' },
+ { "set-default", required_argument, nullptr, 's' },
+ { "get", required_argument, nullptr, 'g' },
+ { "get-current", no_argument, nullptr, 'c' },
+ { "list", no_argument, nullptr, 'l' },
+ { 0, 0, 0, 0 },
+};
+
+const char kHelpMessage[] = R"(Allowed options:
+ -h, --help display this help message
+ -s, --set-default set default theme
+ -g, --get get specific theme info
+ -c, --get-current get current theme info
+ -l, --list print list of installed themes
+)";
+
+} // namespace
+
+namespace ttm {
+namespace cmd {
+
+std::map<std::string, std::any> Parser::Parse(int argc, char* argv[]) {
+ std::map<std::string, std::any> args;
+ while (true) {
+ int opt = getopt_long(argc, argv, short_opts, long_opts, nullptr);
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case 'h':
+ PrintHelp();
+ return {};
+ case 's':
+ if (!optarg) {
+ std::cerr << "missing argument for \"set-default\"" << std::endl;
+ return {};
+ }
+ args["set-default"] = std::string(optarg);
+ break;
+ case 'g':
+ if (!optarg) {
+ std::cerr << "missing argument for \"get\"" << std::endl;
+ return {};
+ }
+ args["get"] = std::string(optarg);
+ break;
+ case 'c':
+ args["get-current"] = true;
+ break;
+ case 'l':
+ args["list"] = true;
+ break;
+ default:
+ break;
+ }
+ }
+ return args;
+}
+
+void Parser::PrintHelp() {
+ std::cerr << kHelpMessage;
+}
+
+} // namespace cmd
+} // namespace ttm
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef THEME_CMD_PARSER_H_
+#define THEME_CMD_PARSER_H_
+
+#include <any>
+#include <map>
+#include <string>
+
+namespace ttm {
+namespace cmd {
+
+class Parser {
+ public:
+ Parser() {}
+ ~Parser() {}
+ std::map<std::string, std::any> Parse(int argc, char* argv[]);
+
+ private:
+ void PrintHelp();
+};
+
+} // cmd
+} // ttm
+
+#endif // THEME_CMD_PARSER_H_
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "theme_cmd/theme_cmd.h"
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include "theme/dbus/request_broker.h"
+#include "theme/loader/theme_info_loader.h"
+#include "theme_provider/theme_info_proxy.h"
+
+namespace {
+
+constexpr char kThemeDbPath[] = "/opt/dbspace/.tizen_theme.db";
+
+} // namespace
+
+namespace ttm {
+namespace cmd {
+
+Cmd::Cmd() {
+ if (ttm::dbus::RequestBroker::GetInst().GetConnection() == nullptr) {
+ std::cout << "Running in offline mode" << std::endl;
+ loader_ = nullptr;
+ offline_mode_ = true;
+ } else {
+ loader_ = std::make_shared<ttm::loader::ThemeInfoLoader>();
+ offline_mode_ = false;
+ }
+}
+
+Cmd::~Cmd() {
+}
+
+void Cmd::SetDefaultTheme(const std::string& id) {
+ if (offline_mode_) {
+ ttm::provider::ThemeInfoProxy proxy(kThemeDbPath);
+ proxy.SetCurrentTheme(id);
+ } else {
+ loader_->SetCurrent(id);
+ }
+}
+
+void Cmd::PrintCurrentTheme() {
+ std::shared_ptr<ttm::loader::ThemeInfo> theme;
+ if (offline_mode_) {
+ ttm::provider::ThemeInfoProxy proxy(kThemeDbPath);
+ theme = proxy.GetLoadedTheme();
+ } else {
+ theme = loader_->LoadCurrent();
+ }
+ if (!theme) {
+ std::cerr << "Failed to load current theme" << std::endl;
+ return;
+ }
+ std::cout << theme->GetId() << std::endl;
+}
+
+void Cmd::PrintThemeInfo(const std::string& id) {
+ std::shared_ptr<ttm::loader::ThemeInfo> theme;
+ if (offline_mode_) {
+ ttm::provider::ThemeInfoProxy proxy(kThemeDbPath);
+ theme = proxy.LoadTheme(id);
+ } else {
+ theme = loader_->Load(id);
+ }
+ if (!theme) {
+ std::cerr << "Failed to load theme info" << std::endl;
+ return;
+ }
+ std::cout << theme->GetId() << " " << theme->GetVersion() << std::endl;
+}
+
+void Cmd::PrintThemeList() {
+ std::vector<std::string> list;
+ if (offline_mode_) {
+ ttm::provider::ThemeInfoProxy proxy(kThemeDbPath);
+ list = proxy.GetThemeIds();
+ } else {
+ list = loader_->QueryThemeId();
+ }
+ for (const auto& id : list) {
+ std::cout << id << std::endl;
+ }
+}
+
+} // namespace cmd
+} // namespace ttm
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef THEME_CMD_THEME_CMD_H_
+#define THEME_CMD_THEME_CMD_H_
+
+
+#include <memory>
+
+#include "theme/loader/theme_info.h"
+#include "theme/loader/theme_info_loader.h"
+
+namespace ttm {
+namespace cmd {
+
+class Cmd {
+ public:
+ Cmd();
+ ~Cmd();
+
+ void SetDefaultTheme(const std::string& id);
+ void PrintCurrentTheme();
+ void PrintThemeInfo(const std::string& id);
+ void PrintThemeList();
+
+ private:
+ // NOTE: current ThemeInfoLoader class cannot be used with unique_ptr
+ std::shared_ptr<ttm::loader::ThemeInfoLoader> loader_;
+ bool offline_mode_;
+};
+
+} // namespace cmd
+} // namespace ttm
+
+#endif // THEME_CMD_THEME_CMD_H_