Initialize Tizen 2.3
[framework/web/wrt-installer.git] / src_mobile / misc / widget_location.h
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.h
18  * @author      Iwanek Tomasz (t.iwanek@smasung.com)
19  */
20 #ifndef WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
21 #define WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
22
23 #include <string>
24 #include <memory>
25
26 #include <dpl/wrt-dao-ro/common_dao_types.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28 #include <wrt_common_types.h>
29 #include <wrt_install_mode.h>
30
31 /**
32  * @brief The WidgetLocation class
33  *
34  * Object that stores locations of several files/directories according
35  * to package name
36  *
37  * Current package layout (of installed package) is following:
38  *
39  * /opt/apps/[package_name]
40  *           \_____________ /data
41  *           \_____________ /share
42  *           \_____________ /bin
43  *           \_____________ /bin/[id_of_installed_package]
44  *           \_____________ /res/wgt/
45  *                               \___ config.xml
46  *                               \___ [widgets_archive_content]
47  *
48  * 1) Normal Widget
49  *  Developer provides content of res/wgt directory (package contains that
50  * directory as root).
51  *
52  * 2) For OSP Service Hybrid App is actually a bit different:
53  *  Root is OSP Service directory, WebApp content is located in [root]/res/wgt
54  *
55  * Temporary directory is directory when widget is placed at the begining
56  * of installation process. After parsing process of config.xml, destination
57  * directory is created.
58  */
59 class WidgetLocation
60 {
61     class DirectoryDeletor
62     {
63       public:
64         DirectoryDeletor();
65         DirectoryDeletor(std::string tempPath);
66         DirectoryDeletor(bool isPreload);
67
68         ~DirectoryDeletor();
69         std::string getTempPath() const;
70
71       private:
72         std::string m_dirpath;
73     };
74
75   public:
76     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
77     DECLARE_EXCEPTION_TYPE(Base, NoTemporaryPath)
78     /**
79      * @brief WidgetLocation
80      *
81      * Creates useless object. Needed by DPL::Optional
82      */
83     WidgetLocation();
84     /**
85      * @brief WidgetLocation Builds paths for widget location during
86      * uninstallation
87      *
88      * Uninstallation process needs only installed package directory.
89      *
90      * @param widgetname name of widget
91      */
92     explicit WidgetLocation(const std::string & widgetname);
93     /**
94      * @brief WidgetLocation Builds paths for widget location during
95      * installation
96      *
97      * @param widgetname name of widget
98      * @param sourcePath given source path
99      * @param t declaraced type of widget if type is needed
100      *
101      * In destruction removes temporary directory
102      */
103     WidgetLocation(const std::string & widgetname, std::string sourcePath,
104                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
105                    bool isReadonly = false,
106                    InstallMode::ExtensionType eType =
107                    InstallMode::ExtensionType::WGT);
108
109     WidgetLocation(const std::string & widgetname, std::string sourcePath,
110                    std::string dirPath,
111                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
112                    bool isReadonly = false,
113                    InstallMode::ExtensionType eType =
114                    InstallMode::ExtensionType::WGT);
115
116     ~WidgetLocation();
117
118     // Installed paths
119     std::string getInstallationDir() const; // /opt/apps or /usr/apps
120     std::string getPackageInstallationDir() const; // /opt/apps/[package]
121     std::string getSourceDir() const;  // /opt/apps/[package]/res/wgt
122     std::string getBinaryDir() const;  // /opt/apps/[package]/bin or /usr/apps/[package]/bin
123     std::string getUserBinaryDir() const;  // /opt/apps/[package]/bin
124     std::string getExecFile() const;   // /opt/apps/[package]/bin/[package]
125     std::string getBackupDir() const;  // /opt/apps/[package].backup
126     std::string getBackupSourceDir() const; // /opt/apps/[pkg].backup/res/wgt
127     std::string getBackupBinaryDir() const; // /opt/apps/[pkg].backup/bin
128     std::string getBackupExecFile() const;  // /opt/apps/[pkg].backup/bin/[pkg]
129     std::string getBackupPrivateDir() const;  // /opt/apps/[pkg].backup/data
130     std::string getUserDataRootDir() const; // /opt/usr/apps/[package]
131     std::string getPrivateStorageDir() const; // /opt/usr/apps/[package]/data
132     std::string getPrivateTempStorageDir() const; // /opt/usr/apps/[package]/tmp
133     std::string getSharedRootDir() const; // /opt/usr/apps/[package]/shared
134     std::string getSharedResourceDir() const; // /opt/usr/apps/[package]/shared/res
135     std::string getSharedDataDir() const; // /opt/usr/apps/[package]/shared/data
136     std::string getSharedTrustedDir() const; // /opt/usr/apps/[package]/shared/trusted
137     std::string getBackupSharedDir() const; // /opt/usr/apps/[package].backup/shared
138     std::string getBackupSharedDataDir() const; // /opt/usr/apps/[package].backup/shared/data
139     std::string getBackupSharedTrustedDir() const; // /opt/usr/apps/[package].backup/shared/trusted
140     std::string getNPPluginsDir() const; // /opt/usr/apps/[package]/res/wgt/plugins
141     std::string getNPPluginsExecFile() const; // /opt/usr/apps/[package]/bin/{execfile}
142
143     // Temporary paths
144     /**
145      * @brief getTemporaryRootDir
146      * @return value of root for developer's provide package (root of unpacked
147      * .wgt file)
148      */
149     std::string getTemporaryPackageDir() const;
150     /**
151      * @brief getTemporaryRootDir
152      *
153      * Value of this will differs according to type of installed widget.
154      *
155      * @return value of root for content in temporary directory to be copied
156      * into 'res/wgt'
157      */
158     std::string getTemporaryRootDir() const;
159
160     //icons
161     /**
162      * @brief setIconTargetFilenameForLocale set installed ion path according to
163      * locale
164      * @param icon path of application icon
165      */
166     void setIconTargetFilenameForLocale(const std::string &icon);
167
168     /**
169      * @brief getIconTargetFilename gets icon full path
170      * @param languageTag language tag
171      * @return value of full path
172      */
173     std::string getInstalledIconPath() const;
174
175     /**
176      * @brief getWidgetSourcePath return widget's source path given to installer
177      * @return value of source path
178      */
179     std::string getWidgetSource() const;
180     /**
181      * @brief pkgid Returns pkgid
182      * @return pkgid
183      */
184     DPL::String getPkgId() const;
185
186     //external files
187     /**
188      * @brief registerExternalFile Registers file for database registration
189      * @param file
190      *
191      * Registered file will be stored in database and removed automatically a
192      *
193      * @return
194      */
195     void registerExternalLocation(const std::string & file);
196     /**
197      * @brief listExternalFile list all file to be registered
198      */
199     WrtDB::ExternalLocationList listExternalLocations() const;
200
201     /*
202      * @brief set appid
203      */
204     void registerAppid(const std::string & appid);
205
206   private:
207     std::string m_pkgid;                        //id of package
208     std::string m_widgetSource;                   // Source widget zip
209                                                   // file/widget url
210     std::string m_appid;                        //id of app
211     std::string m_iconPath;                       //installed icon path
212     WrtDB::PackagingType m_type;
213     std::shared_ptr<DirectoryDeletor> m_temp;      //directory
214     WrtDB::ExternalLocationList m_externals;
215     std::string m_installedPath;
216     InstallMode::ExtensionType m_extensionType;
217 };
218
219 #endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H