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() :
32 m_dirpath(Jobs::WidgetInstall::createTempPath())
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),
70 m_temp(new WidgetLocation::DirectoryDeletor())
72 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
73 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
75 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
79 WidgetLocation::WidgetLocation(const std::string & widgetname,
80 std::string sourcePath,
82 WrtDB::PackagingType t,
83 InstallLocationType locationType) :
85 m_widgetSource(sourcePath),
88 WidgetLocation::DirectoryDeletor(dirPath))
90 if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
91 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
93 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
97 // TODO cache all these paths
98 std::string WidgetLocation::getInstallationDir() const
100 return m_installedPath;
103 std::string WidgetLocation::getPackageInstallationDir() const
105 return m_installedPath + "/" + m_pkgid;
108 std::string WidgetLocation::getSourceDir() const
110 return m_installedPath + "/"
111 + m_pkgid + WrtDB::GlobalConfig::GetWidgetSrcPath();
114 std::string WidgetLocation::getBinaryDir() const
116 return m_installedPath + "/"
117 + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
120 std::string WidgetLocation::getExecFile() const
122 return getBinaryDir() + "/" + m_appid;
125 std::string WidgetLocation::getBackupDir() const
127 return getPackageInstallationDir() + "/backup";
130 std::string WidgetLocation::getBackupSourceDir() const
132 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
135 std::string WidgetLocation::getBackupBinaryDir() const
137 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
140 std::string WidgetLocation::getBackupExecFile() const
142 return getBackupBinaryDir() + "/" + m_appid;
145 std::string WidgetLocation::getUserDataRootDir() const
147 return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
151 std::string WidgetLocation::getPrivateStorageDir() const
153 return getUserDataRootDir() + "/" +
154 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
157 std::string WidgetLocation::getTemporaryPackageDir() const
159 return m_temp->getTempPath();
162 std::string WidgetLocation::getTemporaryRootDir() const
164 if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
165 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
167 if (m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP) {
168 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
170 return getTemporaryPackageDir();
174 std::string WidgetLocation::getConfigurationDir() const
176 if (m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
177 std::string path = ".";
178 std::size_t index = m_widgetSource.find_last_of("\\/");
179 if (index != std::string::npos) {
180 path = m_widgetSource.substr(0, index);
183 } else if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
184 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
186 return getTemporaryRootDir();
190 DPL::String WidgetLocation::getPkgId() const
192 return DPL::FromUTF8String(m_pkgid);
195 std::string WidgetLocation::getInstalledIconPath() const
200 std::string WidgetLocation::getWidgetSource() const
202 return m_widgetSource;
205 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
210 void WidgetLocation::registerExternalLocation(const std::string & file)
212 m_externals.push_back(file);
215 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
220 void WidgetLocation::registerAppid(const std::string & appid)