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,
72 m_pkgname(widgetname),
73 m_widgetSource(sourcePath),
75 m_temp(new WidgetLocation::DirectoryDeletor())
78 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
80 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
84 WidgetLocation::WidgetLocation(const std::string & widgetname,
85 std::string sourcePath,
87 WrtDB::PackagingType t,
89 m_pkgname(widgetname),
90 m_widgetSource(sourcePath),
93 WidgetLocation::DirectoryDeletor(dirPath))
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_pkgname;
113 std::string WidgetLocation::getSourceDir() const
115 return m_installedPath + "/"
116 + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
119 std::string WidgetLocation::getBinaryDir() const
121 return m_installedPath + "/"
122 + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
125 std::string WidgetLocation::getExecFile() const
127 return getBinaryDir() + "/" + m_pkgname;
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_pkgname;
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::getTemporaryPackageDir() const
164 return m_temp->getTempPath();
167 std::string WidgetLocation::getTemporaryRootDir() const
169 if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
170 return getWidgetSource();
172 if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP)
174 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
178 return getTemporaryPackageDir();
182 std::string WidgetLocation::getConfigurationDir() const
184 if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP)
186 std::string path = ".";
187 int index = m_widgetSource.find_last_of("\\/");
188 if (index != std::string::npos)
190 path = m_widgetSource.substr(0, index);
196 return getTemporaryRootDir();
200 DPL::String WidgetLocation::getPkgname() const
202 return DPL::FromUTF8String(m_pkgname);
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