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