Update wrt-installer_0.0.54
[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     _WrtUtilRemoveDir(m_dirpath.c_str());
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 std::string WidgetLocation::getInstallationDir() const
73 {
74     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath());
75 }
76
77 std::string WidgetLocation::getPackageInstallationDir() const
78 {
79     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
80             + m_pkgname;
81 }
82
83 std::string WidgetLocation::getSourceDir() const
84 {
85     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
86             + m_pkgname + "/" + WrtDB::GlobalConfig::GetWidgetSrcPath();
87 }
88
89 std::string WidgetLocation::getBinaryDir() const
90 {
91     return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/"
92             + m_pkgname + "/" + WrtDB::GlobalConfig::GetUserWidgetExecPath();
93 }
94
95 std::string WidgetLocation::getBackupDir() const
96 {
97     return getPackageInstallationDir() + "/backup";
98 }
99
100 std::string WidgetLocation::getTemporaryPackageDir() const
101 {
102     return m_temp->getTempPath();
103 }
104
105 bool WidgetLocation::browserRequest() const
106 {
107     return m_browser;
108 }
109
110 std::string WidgetLocation::getTemporaryRootDir() const
111 {
112     if(m_type == WrtDB::PKG_TYPE_TIZEN_WITHSVCAPP)
113     {
114         return getTemporaryPackageDir() + "/" + WrtDB::GlobalConfig::GetWidgetSrcPath();
115     }
116     else
117     {
118         return getTemporaryPackageDir();
119     }
120 }
121
122 std::string WidgetLocation::getConfigurationDir() const
123 {
124     if(m_browser)
125     {
126         std::string path = ".";
127         int index = m_widgetSource.find_last_of("\\/");
128         if (index != std::string::npos)
129         {
130             path = m_widgetSource.substr(0, index);
131         }
132         return path;
133     }
134     else
135     {
136         return getTemporaryRootDir();
137     }
138 }
139
140 std::string WidgetLocation::getInstalledIconPath() const
141 {
142     return m_iconPath;
143 }
144
145 std::string WidgetLocation::getWidgetSource() const
146 {
147     return m_widgetSource;
148 }
149
150 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
151 {
152     m_iconPath = icon;
153 }