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>
32 WidgetLocation::DirectoryDeletor::DirectoryDeletor()
34 m_dirpath = Jobs::WidgetInstall::createTempPath();
37 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath)
42 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
44 LogDebug("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()
59 WidgetLocation::WidgetLocation(const std::string & widgetname) :
64 WidgetLocation::~WidgetLocation()
68 WidgetLocation::WidgetLocation(const std::string & widgetname,
69 std::string sourcePath,
70 WrtDB::PackagingType t,
71 InstallLocationType locationType):
73 m_widgetSource(sourcePath),
75 m_temp(new WidgetLocation::DirectoryDeletor())
77 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
78 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
80 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
84 WidgetLocation::WidgetLocation(const std::string & widgetname,
85 std::string sourcePath,
87 WrtDB::PackagingType t,
88 InstallLocationType locationType):
90 m_widgetSource(sourcePath),
93 WidgetLocation::DirectoryDeletor(dirPath))
95 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
96 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
98 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
102 // TODO cache all these paths
103 std::string WidgetLocation::getInstallationDir() const
105 return m_installedPath;
108 std::string WidgetLocation::getPackageInstallationDir() const
110 return m_installedPath + "/" + m_pkgid;
113 std::string WidgetLocation::getSourceDir() const
115 return m_installedPath + "/"
116 + m_pkgid + WrtDB::GlobalConfig::GetWidgetSrcPath();
119 std::string WidgetLocation::getBinaryDir() const
121 return m_installedPath + "/"
122 + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
125 std::string WidgetLocation::getExecFile() const
127 return getBinaryDir() + "/" + m_pkgid;
130 std::string WidgetLocation::getBackupDir() const
132 return getPackageInstallationDir() + "/backup";
135 std::string WidgetLocation::getBackupSourceDir() const
137 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
140 std::string WidgetLocation::getBackupBinaryDir() const
142 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
145 std::string WidgetLocation::getBackupExecFile() const
147 return getBackupBinaryDir() + "/" + m_pkgid;
150 std::string WidgetLocation::getUserDataRootDir() const
152 return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
156 std::string WidgetLocation::getPrivateStorageDir() const
158 return getUserDataRootDir() + "/" +
159 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
162 std::string WidgetLocation::getShareDir() const
164 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
165 + m_pkgid + "/" + WrtDB::GlobalConfig::GetWidgetSharePath();
168 std::string WidgetLocation::getTemporaryPackageDir() const
170 return m_temp->getTempPath();
173 std::string WidgetLocation::getTemporaryRootDir() const
175 if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
176 return getWidgetSource();
178 if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP)
180 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
184 return getTemporaryPackageDir();
188 std::string WidgetLocation::getConfigurationDir() const
190 if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP)
192 std::string path = ".";
193 int index = m_widgetSource.find_last_of("\\/");
194 if (index != std::string::npos)
196 path = m_widgetSource.substr(0, index);
200 else if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
202 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
205 return getTemporaryRootDir();
209 DPL::String WidgetLocation::getPkgId() const
211 return DPL::FromUTF8String(m_pkgid);
214 std::string WidgetLocation::getInstalledIconPath() const
219 std::string WidgetLocation::getWidgetSource() const
221 return m_widgetSource;
224 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
229 void WidgetLocation::registerExternalLocation(const std::string & file)
231 m_externals.push_back(file);
234 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const