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