Update wrt-installer_0.0.69
[framework/web/wrt-installer.git] / src / misc / widget_location.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        widget_location.cpp
18  * @author      Iwanek Tomasz (t.iwanek@smasung.com)
19  */
20 #include "widget_location.h"
21
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>
28
29 #include <widget_install/task_commons.h>
30
31
32 WidgetLocation::DirectoryDeletor::DirectoryDeletor()
33 {
34     m_dirpath = Jobs::WidgetInstall::createTempPath();
35 }
36
37 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
38 {
39     LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str());
40     WrtUtilRemove(m_dirpath);
41 }
42
43 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
44 {
45     return m_dirpath;
46 }
47
48 WidgetLocation::WidgetLocation() : m_browser(false)
49 {
50 }
51
52 WidgetLocation::WidgetLocation(const std::string & widgetname) : m_pkgname(widgetname), m_browser(false)
53 {
54 }
55
56 WidgetLocation::~WidgetLocation()
57 {
58 }
59
60 WidgetLocation::WidgetLocation(const std::string & widgetname,
61                                std::string sourcePath,
62                                bool browserRequest,
63                                WrtDB::PkgType t):
64                                     m_pkgname(widgetname),
65                                     m_widgetSource(sourcePath),
66                                     m_browser(browserRequest),
67                                     m_type(t),
68                                     m_temp(new WidgetLocation::DirectoryDeletor())
69 {
70 }
71
72 // TODO cache all these paths
73 std::string WidgetLocation::getInstallationDir() const
74 {
75     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
76 }
77
78 std::string WidgetLocation::getPackageInstallationDir() const
79 {
80     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
81             + m_pkgname;
82 }
83
84 std::string WidgetLocation::getSourceDir() const
85 {
86     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
87             + m_pkgname + WrtDB::GlobalConfig::GetWidgetSrcPath();
88 }
89
90 std::string WidgetLocation::getBinaryDir() const
91 {
92     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
93             + m_pkgname + WrtDB::GlobalConfig::GetUserWidgetExecPath();
94 }
95
96 std::string WidgetLocation::getExecFile() const
97 {
98     return getBinaryDir() + "/" + m_pkgname;
99 }
100
101 std::string WidgetLocation::getBackupDir() const
102 {
103     return getPackageInstallationDir() + "/backup";
104 }
105
106 std::string WidgetLocation::getBackupSourceDir() const
107 {
108     return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
109 }
110
111 std::string WidgetLocation::getBackupBinaryDir() const
112 {
113     return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
114 }
115
116 std::string WidgetLocation::getBackupExecFile() const
117 {
118     return getBackupBinaryDir() + "/" + m_pkgname;
119 }
120
121 std::string WidgetLocation::getTemporaryPackageDir() const
122 {
123     return m_temp->getTempPath();
124 }
125
126 bool WidgetLocation::browserRequest() const
127 {
128     return m_browser;
129 }
130
131 std::string WidgetLocation::getTemporaryRootDir() const
132 {
133     if(m_type == WrtDB::PKG_TYPE_TIZEN_WITHSVCAPP)
134     {
135         return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
136     }
137     else
138     {
139         return getTemporaryPackageDir();
140     }
141 }
142
143 std::string WidgetLocation::getConfigurationDir() const
144 {
145     if(m_browser)
146     {
147         std::string path = ".";
148         int index = m_widgetSource.find_last_of("\\/");
149         if (index != std::string::npos)
150         {
151             path = m_widgetSource.substr(0, index);
152         }
153         return path;
154     }
155     else
156     {
157         return getTemporaryRootDir();
158     }
159 }
160
161 DPL::String WidgetLocation::getPkgname() const
162 {
163     return DPL::FromUTF8String(m_pkgname);
164 }
165
166 std::string WidgetLocation::getInstalledIconPath() const
167 {
168     return m_iconPath;
169 }
170
171 std::string WidgetLocation::getWidgetSource() const
172 {
173     return m_widgetSource;
174 }
175
176 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
177 {
178     m_iconPath = icon;
179 }
180
181 void WidgetLocation::registerExternalLocation(const std::string & file)
182 {
183     m_externals.push_back(file);
184 }
185
186 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
187 {
188     return m_externals;
189 }