2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file widget_location.cpp
18 * @author Iwanek Tomasz (t.iwanek@smasung.com)
20 #include "widget_location.h"
22 #include <dpl/utils/wrt_utility.h>
23 #include <dpl/wrt-dao-ro/global_config.h>
24 #include <dpl/assert.h>
25 #include <dpl/log/log.h>
26 #include <dpl/sstream.h>
27 #include <dpl/localization/localization_utils.h>
29 #include <widget_install/task_commons.h>
31 WidgetLocation::DirectoryDeletor::DirectoryDeletor(bool isPreload) :
32 m_dirpath(Jobs::WidgetInstall::createTempPath(isPreload))
35 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
39 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
42 "Removing widget installation temporary directory: " << m_dirpath.c_str());
43 if (!WrtUtilRemove(m_dirpath)) {
44 LogError("Fail at removing directory: " << m_dirpath.c_str());
48 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
53 WidgetLocation::WidgetLocation()
56 WidgetLocation::WidgetLocation(const std::string & widgetname) :
60 WidgetLocation::~WidgetLocation()
63 WidgetLocation::WidgetLocation(const std::string & widgetname,
64 std::string sourcePath,
65 WrtDB::PackagingType t,
66 InstallLocationType locationType) :
68 m_widgetSource(sourcePath),
71 new WidgetLocation::DirectoryDeletor(
72 INSTALL_LOCATION_TYPE_PRELOAD == locationType))
74 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
75 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
77 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
80 if (access(m_widgetSource.c_str(), F_OK) != 0) {
81 m_widgetSource = m_installedPath + "/" + m_pkgid;
85 WidgetLocation::WidgetLocation(const std::string & widgetname,
86 std::string sourcePath,
88 WrtDB::PackagingType t,
89 InstallLocationType locationType) :
91 m_widgetSource(sourcePath),
94 WidgetLocation::DirectoryDeletor(dirPath))
96 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
97 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
99 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
102 if (access(m_widgetSource.c_str(), F_OK) != 0) {
103 m_widgetSource = m_installedPath + "/" + m_pkgid;
107 // TODO cache all these paths
108 std::string WidgetLocation::getInstallationDir() const
110 return m_installedPath;
113 std::string WidgetLocation::getPackageInstallationDir() const
115 return m_installedPath + "/" + m_pkgid;
118 std::string WidgetLocation::getSourceDir() const
120 return m_installedPath + "/"
121 + m_pkgid + WrtDB::GlobalConfig::GetWidgetSrcPath();
124 std::string WidgetLocation::getBinaryDir() const
126 return m_installedPath + "/"
127 + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
130 std::string WidgetLocation::getExecFile() const
132 return getBinaryDir() + "/" + m_appid;
135 std::string WidgetLocation::getBackupDir() const
137 return getPackageInstallationDir() + "/backup";
140 std::string WidgetLocation::getBackupSourceDir() const
142 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
145 std::string WidgetLocation::getBackupBinaryDir() const
147 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
150 std::string WidgetLocation::getBackupExecFile() const
152 return getBackupBinaryDir() + "/" + m_appid;
155 std::string WidgetLocation::getUserDataRootDir() const
157 return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
161 std::string WidgetLocation::getPrivateStorageDir() const
163 return getUserDataRootDir() + "/" +
164 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
167 std::string WidgetLocation::getTemporaryPackageDir() const
169 return m_temp->getTempPath();
172 std::string WidgetLocation::getTemporaryRootDir() const
174 if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
175 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
177 if (m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP) {
178 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
180 return getTemporaryPackageDir();
184 std::string WidgetLocation::getConfigurationDir() const
186 if (m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
187 std::string path = ".";
188 std::size_t index = m_widgetSource.find_last_of("\\/");
189 if (index != std::string::npos) {
190 path = m_widgetSource.substr(0, index);
193 } else if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
194 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
196 return getTemporaryRootDir();
200 DPL::String WidgetLocation::getPkgId() const
202 return DPL::FromUTF8String(m_pkgid);
205 std::string WidgetLocation::getInstalledIconPath() const
210 std::string WidgetLocation::getWidgetSource() const
212 return m_widgetSource;
215 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
220 void WidgetLocation::registerExternalLocation(const std::string & file)
222 m_externals.push_back(file);
225 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
230 void WidgetLocation::registerAppid(const std::string & appid)