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()
33 m_dirpath = Jobs::WidgetInstall::createTempPath();
36 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath)
41 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
44 "Removing widget installation temporary directory: " << m_dirpath.c_str());
45 if (!WrtUtilRemove(m_dirpath)) {
46 LogError("Fail at removing directory: " << m_dirpath.c_str());
50 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
55 WidgetLocation::WidgetLocation()
58 WidgetLocation::WidgetLocation(const std::string & widgetname) :
62 WidgetLocation::~WidgetLocation()
65 WidgetLocation::WidgetLocation(const std::string & widgetname,
66 std::string sourcePath,
67 WrtDB::PackagingType t,
68 InstallLocationType locationType) :
70 m_widgetSource(sourcePath),
72 m_temp(new WidgetLocation::DirectoryDeletor())
74 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
75 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
77 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
81 WidgetLocation::WidgetLocation(const std::string & widgetname,
82 std::string sourcePath,
84 WrtDB::PackagingType t,
85 InstallLocationType locationType) :
87 m_widgetSource(sourcePath),
90 WidgetLocation::DirectoryDeletor(dirPath))
92 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
93 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
95 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
99 // TODO cache all these paths
100 std::string WidgetLocation::getInstallationDir() const
102 return m_installedPath;
105 std::string WidgetLocation::getPackageInstallationDir() const
107 return m_installedPath + "/" + m_pkgid;
110 std::string WidgetLocation::getSourceDir() const
112 return m_installedPath + "/"
113 + m_pkgid + WrtDB::GlobalConfig::GetWidgetSrcPath();
116 std::string WidgetLocation::getBinaryDir() const
118 return m_installedPath + "/"
119 + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
122 std::string WidgetLocation::getExecFile() const
124 return getBinaryDir() + "/" + m_appid;
127 std::string WidgetLocation::getBackupDir() const
129 return getPackageInstallationDir() + "/backup";
132 std::string WidgetLocation::getBackupSourceDir() const
134 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
137 std::string WidgetLocation::getBackupBinaryDir() const
139 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
142 std::string WidgetLocation::getBackupExecFile() const
144 return getBackupBinaryDir() + "/" + m_appid;
147 std::string WidgetLocation::getUserDataRootDir() const
149 return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
153 std::string WidgetLocation::getPrivateStorageDir() const
155 return getUserDataRootDir() + "/" +
156 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
159 std::string WidgetLocation::getTemporaryPackageDir() const
161 return m_temp->getTempPath();
164 std::string WidgetLocation::getTemporaryRootDir() const
166 if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
167 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
169 if (m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP) {
170 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
172 return getTemporaryPackageDir();
176 std::string WidgetLocation::getConfigurationDir() const
178 if (m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
179 std::string path = ".";
180 int index = m_widgetSource.find_last_of("\\/");
181 if (index != std::string::npos) {
182 path = m_widgetSource.substr(0, index);
185 } else if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
186 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
188 return getTemporaryRootDir();
192 DPL::String WidgetLocation::getPkgId() const
194 return DPL::FromUTF8String(m_pkgid);
197 std::string WidgetLocation::getInstalledIconPath() const
202 std::string WidgetLocation::getWidgetSource() const
204 return m_widgetSource;
207 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
212 void WidgetLocation::registerExternalLocation(const std::string & file)
214 m_externals.push_back(file);
217 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
222 void WidgetLocation::registerAppid(const std::string & appid)