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