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