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 WrtUtilRemove(m_dirpath);
48 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
53 WidgetLocation::WidgetLocation()
57 WidgetLocation::WidgetLocation(const std::string & widgetname) :
62 WidgetLocation::~WidgetLocation()
66 WidgetLocation::WidgetLocation(const std::string & widgetname,
67 std::string sourcePath,
68 WrtDB::PackagingType t):
69 m_pkgname(widgetname),
70 m_widgetSource(sourcePath),
72 m_temp(new WidgetLocation::DirectoryDeletor())
76 WidgetLocation::WidgetLocation(const std::string & widgetname,
77 std::string sourcePath,
79 WrtDB::PackagingType t):
80 m_pkgname(widgetname),
81 m_widgetSource(sourcePath),
84 WidgetLocation::DirectoryDeletor(dirPath))
88 // TODO cache all these paths
89 std::string WidgetLocation::getInstallationDir() const
91 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
94 std::string WidgetLocation::getPackageInstallationDir() const
96 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
100 std::string WidgetLocation::getSourceDir() const
102 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
103 + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
106 std::string WidgetLocation::getBinaryDir() const
108 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
109 + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
112 std::string WidgetLocation::getExecFile() const
114 return getBinaryDir() + "/" + m_pkgname;
117 std::string WidgetLocation::getBackupDir() const
119 return getPackageInstallationDir() + "/backup";
122 std::string WidgetLocation::getBackupSourceDir() const
124 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
127 std::string WidgetLocation::getBackupBinaryDir() const
129 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
132 std::string WidgetLocation::getBackupExecFile() const
134 return getBackupBinaryDir() + "/" + m_pkgname;
137 std::string WidgetLocation::getTemporaryPackageDir() const
139 return m_temp->getTempPath();
142 std::string WidgetLocation::getTemporaryRootDir() const
144 if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP)
146 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
150 return getTemporaryPackageDir();
154 std::string WidgetLocation::getConfigurationDir() const
156 if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP)
158 std::string path = ".";
159 int index = m_widgetSource.find_last_of("\\/");
160 if (index != std::string::npos)
162 path = m_widgetSource.substr(0, index);
168 return getTemporaryRootDir();
172 DPL::String WidgetLocation::getPkgname() const
174 return DPL::FromUTF8String(m_pkgname);
177 std::string WidgetLocation::getInstalledIconPath() const
182 std::string WidgetLocation::getWidgetSource() const
184 return m_widgetSource;
187 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
192 void WidgetLocation::registerExternalLocation(const std::string & file)
194 m_externals.push_back(file);
197 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const