#include "theme/utils/glist_range.h"
#include "theme/utils/logging.h"
+#include "theme/loader/theme_info.h"
#include "theme_plugin/theme_parser.h"
+using ttm::loader::ThemeInfo;
+using ttm::plugin::ThemeParser;
+
namespace {
const char kThemeMetadataKey[] = "http://tizen.org/metadata/theme";
return path;
}
-} // namespace
-
-bool InstallTheme(const std::string& id, const std::string& pkgid,
- const std::string& path) {
+bool ParseAndCommitTheme(ThemeParser::ThemeOperation op, const std::string& id,
+ const std::string& pkgid, const std::string& path) {
uid_t uid;
int r = pkgmgr_installer_info_get_target_uid(&uid);
if (r < 0) {
LOG(ERROR) << "Failed to get target uid";
return false;
}
- ttm::plugin::ThemeParser parser(path);
- ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid);
+ ThemeParser parser(path);
+ ThemeInfo theme = parser.Inflate(id, pkgid, uid);
if (!theme.IsValid()) {
LOG(ERROR) << "Failed to parse theme";
return false;
}
- if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD, theme))
+ if (!parser.Commit(op, theme))
return false;
return true;
}
+} // namespace
+
extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(
const char* pkgid, const char* appid, GList* metadata) {
std::string root_path = GetThemeFilePath(pkgid);
for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
if (!strcmp(md->key, kThemeMetadataKey)) {
- if (!InstallTheme(appid, pkgid, (root_path + md->value)))
+ if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::ADD, appid, pkgid,
+ (root_path + md->value)))
return -1;
}
}
return 0;
}
-bool UpgradeTheme(const std::string& id, const std::string& pkgid,
- const std::string& path) {
- uid_t uid;
- int r = pkgmgr_installer_info_get_target_uid(&uid);
- if (r < 0) {
- LOG(ERROR) << "Failed to get target uid";
- return false;
- }
- ttm::plugin::ThemeParser parser(path);
- ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid);
- if (!theme.IsValid()) {
- LOG(ERROR) << "Failed to parse theme";
- return false;
- }
- if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE, theme))
- return false;
- return true;
-}
-
extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(
const char* pkgid, const char* appid, GList* metadata) {
std::string root_path = GetThemeFilePath(pkgid);
for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
if (!strcmp(md->key, kThemeMetadataKey)) {
- if (!UpgradeTheme(appid, pkgid, (root_path + md->value)))
+ if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::UPDATE, appid,
+ pkgid, (root_path + md->value)))
return -1;
}
}
return 0;
}
-bool UninstallTheme(const std::string& id, const std::string& pkgid,
- const std::string& path) {
- uid_t uid;
- int r = pkgmgr_installer_info_get_target_uid(&uid);
- if (r < 0) {
- LOG(ERROR) << "Failed to get target uid";
- return false;
- }
- ttm::plugin::ThemeParser parser(path);
- ttm::loader::ThemeInfo theme = parser.Inflate(id, pkgid, uid);
- if (!theme.IsValid()) {
- LOG(ERROR) << "Failed to parse theme";
- return false;
- }
- if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE, theme))
- return false;
- return true;
-}
-
extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(
const char* pkgid, const char* appid, GList* metadata) {
std::string root_path = GetThemeFilePath(pkgid);
for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
if (!strcmp(md->key, kThemeMetadataKey)) {
- if (!UninstallTheme(appid, pkgid, (root_path + md->value)))
+ if (!ParseAndCommitTheme(ThemeParser::ThemeOperation::REMOVE, appid,
+ pkgid, (root_path + md->value)))
return -1;
}
}