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()
39 LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str());
40 WrtUtilRemove(m_dirpath);
43 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
48 WidgetLocation::WidgetLocation() : m_browser(false)
52 WidgetLocation::WidgetLocation(const std::string & widgetname) : m_pkgname(widgetname), m_browser(false)
56 WidgetLocation::~WidgetLocation()
60 WidgetLocation::WidgetLocation(const std::string & widgetname,
61 std::string sourcePath,
64 m_pkgname(widgetname),
65 m_widgetSource(sourcePath),
66 m_browser(browserRequest),
68 m_temp(new WidgetLocation::DirectoryDeletor())
72 // TODO cache all these paths
73 std::string WidgetLocation::getInstallationDir() const
75 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
78 std::string WidgetLocation::getPackageInstallationDir() const
80 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
84 std::string WidgetLocation::getSourceDir() const
86 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
87 + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
90 std::string WidgetLocation::getBinaryDir() const
92 return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
93 + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
96 std::string WidgetLocation::getExecFile() const
98 return getBinaryDir() + "/" + m_pkgname;
101 std::string WidgetLocation::getBackupDir() const
103 return getPackageInstallationDir() + "/backup";
106 std::string WidgetLocation::getBackupSourceDir() const
108 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
111 std::string WidgetLocation::getBackupBinaryDir() const
113 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
116 std::string WidgetLocation::getBackupExecFile() const
118 return getBackupBinaryDir() + "/" + m_pkgname;
121 std::string WidgetLocation::getTemporaryPackageDir() const
123 return m_temp->getTempPath();
126 bool WidgetLocation::browserRequest() const
131 std::string WidgetLocation::getTemporaryRootDir() const
133 if(m_type == WrtDB::PKG_TYPE_TIZEN_WITHSVCAPP)
135 return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
139 return getTemporaryPackageDir();
143 std::string WidgetLocation::getConfigurationDir() const
147 std::string path = ".";
148 int index = m_widgetSource.find_last_of("\\/");
149 if (index != std::string::npos)
151 path = m_widgetSource.substr(0, index);
157 return getTemporaryRootDir();
161 DPL::String WidgetLocation::getPkgname() const
163 return DPL::FromUTF8String(m_pkgname);
166 std::string WidgetLocation::getInstalledIconPath() const
171 std::string WidgetLocation::getWidgetSource() const
173 return m_widgetSource;
176 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
181 void WidgetLocation::registerExternalLocation(const std::string & file)
183 m_externals.push_back(file);
186 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const