[Release] wrt-installer_0.1.9
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_widget_config.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    task_widget_config.h
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task widget config
21  */
22 #ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H
23 #define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H
24
25 #include <set>
26 #include <list>
27
28 #include <dpl/task.h>
29 #include <dpl/task_list.h>
30 #include <dpl/string.h>
31 #include <dpl/optional.h>
32 #include <dpl/wrt-dao-ro/config_parser_data.h>
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34 #include <dpl/wrt-dao-ro/global_config.h>
35
36 #include <wrt_common_types.h>
37 #include <widget_install/widget_install_popup.h>
38
39 class InstallerContext;
40
41 namespace Jobs {
42 namespace WidgetInstall {
43 namespace InstallerTaskWidgetPopupData {
44 struct PopupData
45 {
46     DPL::String widgetInfo;
47     void addWidgetInfo(const DPL::String &info);
48 };
49 } // InstalllerTaskWidgetPopupData
50
51 class TaskWidgetConfig :
52     public DPL::TaskDecl<TaskWidgetConfig>,
53     public WidgetInstallPopup
54 {
55   private:
56     class Exception
57     {
58       public:
59         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
60         DECLARE_EXCEPTION_TYPE(Base, ConfigParseFailed)
61     };
62
63     typedef std::list<std::pair<DPL::String, DPL::String> > StringPairList;
64
65     InstallerContext& m_installContext;
66     WrtDB::LocaleSet m_localeFolders;
67     std::set<DPL::String> m_processedIconSet;
68     InstallerTaskWidgetPopupData::PopupData m_popupData;
69
70     void StepProcessConfigurationFile();
71     void ReadLocaleFolders();
72     void ProcessLocalizedStartFiles();
73     void ProcessStartFile(
74         const DPL::OptionalString& path,
75         const DPL::OptionalString& type,
76         const DPL::OptionalString& encoding =
77             DPL::OptionalString::Null,
78         bool typeForcedInConfig = false);
79     void ProcessBackgroundPageFile();
80     void ProcessLocalizedIcons();
81     void ProcessIcon(const WrtDB::ConfigParserData::Icon& icon);
82     void ProcessWidgetInstalledPath();
83     void StepVerifyFeatures();
84     void StepShowWidgetInfo();
85     void StepCheckMinVersionInfo();
86
87     template <typename Ex, const char* Msg>
88     void StepCancelInstallation();
89
90     void StepDeletePopupWin();
91     void StepCancelWidgetInstallationAfterVerifyFeatures();
92     void StepCancelWidgetInstallation();
93     void StepCancelWidgetInstallationAfterMinVersion();
94     void createInstallPopup(PopupType type, const std::string &label);
95     DPL::String createAuthorWidgetInfo() const;
96     bool isFeatureAllowed(
97         WrtDB::AppType appType, DPL::String featureName);
98     bool isMinVersionCompatible(
99         WrtDB::AppType appType,
100         const DPL::OptionalString &widgetVersion) const;
101     /**
102      * @brief Parses version string in format "major.minor.micro anything"
103      * Returns false if format is invalid
104      */
105     bool isTizenWebApp() const;
106     bool parseVersionString(const std::string &version, long &majorVersion,
107                             long &minorVersion, long &microVersion) const;
108     /**
109      * This method is used to process the config.xml of widget, get
110      * the corresponding configuration to pWidgetConfigInfo
111      *
112      * @param[in] path Specified the widget archive file path (absolute path).
113      * @return         Configuration information of  widget
114      */
115     void processFile(const std::string& path,
116                      WrtDB::WidgetRegisterInfo &wConfig);
117
118     bool locateAndParseConfigurationFile(
119         const std::string& currentPath,
120         WrtDB::WidgetRegisterInfo&
121         pWidgetConfigInfo,
122         const std::string& baseFolder);
123     bool parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo,
124                                        const std::string& _currentPath);
125     bool parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo,
126                                       const std::string& _currentPath);
127     bool fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
128                           WrtDB::ConfigParserData& configInfo);
129
130   public:
131     TaskWidgetConfig(InstallerContext& installTaskContext);
132 };
133 } //namespace WidgetInstall
134 } //namespace Jobs
135
136 #endif // INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H