#include <bundle_cpp.h>
+#include "theme_provider/theme_info_proxy.h"
+
namespace ttm {
namespace provider {
tizen_base::Bundle ControlRequestHandler::OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) {
- return {};
+ tizen_base::Bundle b;
+ if (cmd != dbus::Command::SET_ID) {
+ // this temporary return value should be fixed.
+ b.Add("result", "error");
+ return b;
+ }
+ bool r = proxy_->SetCurrentTheme(args.GetString("id"));
+ b.Add("result", r ? "ok" : "error");
+ return b;
}
} // namespace provider
const char kSelectQuery[] =
"SELECT id, version, tool_version, title, description, preview, resolution,"
" details WHERE id = ?";
+const char kCreateThemeSettingTableQuery[] =
+ "CREATE TABLE IF NOT EXISTS theme_setting (\n"
+ " current TEXT,\n"
+ " PRIMARY KEY (current))";
+const char kSetThemeQuery[] =
+ "INSERT OR REPLACE INTO theme_setting (current) VALUES (?)";
} // namespace
}
bool DbManager::UpdateCurrentId(const std::string& id) {
+ std::unique_ptr<SQLiteStatement> stmt =
+ conn_.PrepareStatement(kSetThemeQuery);
+ if (!stmt) {
+ LOG(ERROR) << "Failed to prepare statement";
+ return false;
+ }
+
+ if (!stmt->BindString(1, id))
+ return false;
+
+ if (stmt->Step() != SQLiteStatement::StepResult::DONE) {
+ LOG(ERROR) << "Failed to set current theme as " << id;
+ return false;
+ }
+
+ // should notify to listeners that current theme was changed.
+ for (const auto& listener : listeners_)
+ listener->OnThemePackageChanged(id);
+
return true;
}
#include <bundle_cpp.h>
+#include "theme/loader/theme_info.h"
+#include "theme/utils/logging.h"
+#include "theme_provider/theme_info_proxy.h"
+
namespace ttm {
namespace provider {
tizen_base::Bundle PackageEventRequestHandler::OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) {
- return {};
+ bool result = false;
+ switch (cmd) {
+ case dbus::Command::ADD:
+ result = InstallTheme(args);
+ break;
+ case dbus::Command::REMOVE:
+ result = UninstallTheme(args);
+ break;
+ case dbus::Command::UPDATE:
+ result = UpdateTheme(args);
+ break;
+ default:
+ LOG(ERROR) << "Invalid command type";
+ break;
+ }
+
+ tizen_base::Bundle b;
+ // this temporary return value should be fixed.
+ if (result)
+ b.Add("result", "ok");
+ else
+ b.Add("result", "error");
+
+ return b;
+}
+
+bool PackageEventRequestHandler::InstallTheme(const tizen_base::Bundle& args) {
+ return proxy_->SaveTheme(loader::ThemeInfo(args));
+}
+
+bool PackageEventRequestHandler::UpdateTheme(const tizen_base::Bundle& args) {
+ return proxy_->UpdateTheme(loader::ThemeInfo(args));
+}
+
+bool PackageEventRequestHandler::UninstallTheme(
+ const tizen_base::Bundle& args) {
+ return proxy_->RemoveTheme(args.GetString("id"));
}
} // namespace provider
const tizen_base::Bundle& args);
private:
+ bool InstallTheme(const tizen_base::Bundle& args);
+ bool UpdateTheme(const tizen_base::Bundle& args);
+ bool UninstallTheme(const tizen_base::Bundle& args);
+
std::shared_ptr<ThemeInfoProxy> proxy_;
};
#include <string>
+#include "theme/loader/theme_info.h"
+#include "theme_provider/theme_info_proxy.h"
+
namespace ttm {
namespace provider {
tizen_base::Bundle SelectionRequestHandler::OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) {
std::string id = args.GetString("id");
-
- return {};
+ std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
+ return themeinfo->Serialize();
}
} // namespace provider
return db_manager_.Insert(info.GetId(), info.Serialize());
}
+bool ThemeInfoProxy::UpdateTheme(const loader::ThemeInfo& info) {
+ return db_manager_.Update(info.GetId(), info.Serialize());
+}
+
+bool ThemeInfoProxy::RemoveTheme(const std::string& id) {
+ return db_manager_.Delete(id);
+}
+
std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetLoadedTheme() {
- return nullptr;
+ return cur_theme_;
}
bool ThemeInfoProxy::SetCurrentTheme(const std::string& id) {
- return true;
+ return db_manager_.UpdateCurrentId(id);
}
void ThemeInfoProxy::OnThemePackageChanged(const std::string& id) {
+ cur_theme_ = std::make_shared<loader::ThemeInfo>(db_manager_.Select(id));
}
} // namespace provider
public:
std::shared_ptr<loader::ThemeInfo> LoadTheme(const std::string& id);
bool SaveTheme(const loader::ThemeInfo& info);
+ bool UpdateTheme(const loader::ThemeInfo& info);
+ bool RemoveTheme(const std::string& id);
std::shared_ptr<loader::ThemeInfo> GetLoadedTheme();
bool SetCurrentTheme(const std::string& id);
void OnThemePackageChanged(const std::string& id) override;
private:
DbManager db_manager_;
+ std::shared_ptr<loader::ThemeInfo> cur_theme_;
};
} // namespace provider