tizen beta release
[framework/web/wrt-installer.git] / src / wrt-installer / wrt_installer.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    wrt_installer.h
18  * @version 1.0
19  * @brief   Implementation file for installer
20  */
21 #ifndef WRT_CLIENT_H
22 #define WRT_CLIENT_H
23
24 #include <dpl/application.h>
25 #include <dpl/generic_event.h>
26 #include <dpl/event/controller.h>
27 #include <dpl/type_list.h>
28 #include <dpl/task.h>
29 #include <dpl/log/log.h>
30 #include <dpl/string.h>
31 #include <string>
32 #include <utilX.h>
33 #include <wrt_installer_api.h>
34 #include <pkgmgr_installer.h>
35
36 namespace WRTInstallerNS { //anonymous
37 DECLARE_GENERIC_EVENT_0(QuitEvent)
38 DECLARE_GENERIC_EVENT_0(NextStepEvent)
39 DECLARE_GENERIC_EVENT_0(InstallPluginEvent)
40 }
41
42 typedef void (*ShowResultCallback)(void *data, Evas_Object *obj,
43                                    void *event_info);
44
45 enum ReturnValue
46 {
47     RE_SUCCESS,
48     RE_FAIL
49 };
50
51 class WrtInstaller :
52         public DPL::Application,
53         private DPL::Event::Controller<DPL::TypeListDecl<
54             WRTInstallerNS::QuitEvent,
55             WRTInstallerNS::NextStepEvent,
56             WRTInstallerNS::InstallPluginEvent>::Type>,
57         public DPL::TaskDecl<WrtInstaller>
58 {
59   public:
60     WrtInstaller(int argc,
61               char **argv);
62     virtual ~WrtInstaller();
63
64
65     int getReturnStatus() const;
66
67     class InstallerPopup
68     {
69         public:
70             InstallerPopup();
71             virtual ~InstallerPopup();
72
73             void init();
74             Evas_Object* createWin(const char* name);
75             void showPopup(void* userdata, const DPL::String& pkgMsg,
76                            ShowResultCallback callback);
77
78             Evas_Object* m_win;
79             Evas_Object* m_popup;
80             Evas_Object* m_progressbar;
81     };
82
83   protected:
84     virtual void OnStop();
85     virtual void OnCreate();
86     virtual void OnReset(bundle *b);
87     virtual void OnTerminate();
88
89   private:
90     void         showHelpAndQuit();
91
92     // Events
93     virtual void OnEventReceived(const WRTInstallerNS::QuitEvent &event);
94     virtual void OnEventReceived(const WRTInstallerNS::NextStepEvent& event);
95     virtual void OnEventReceived(const WRTInstallerNS::InstallPluginEvent& event);
96
97     // Installation steps
98     void initStep();
99     void installStep();
100     void installNewPlugins();
101     void installPluginsStep();
102     void uninstallStep();
103     void uninstallPkgNameStep();
104     void uninstallGuidStep();
105     void shutdownStep();
106     void registerCallbackStep();
107     void queryListStep();
108
109
110     // Static callbacks
111     static void staticWrtInitCallback(WrtErrStatus status,
112                                       void* userdata);
113     static void staticWrtStatusCallback(int handle,
114                                         WrtErrStatus status,
115                                         void* userdata);
116     static void staticWrtPluginInstallationCallback(WrtErrStatus status,
117                                                     void* userdata);
118     static void staticWrtPluginInstallProgressCb(float percent,
119                                                  const char* description,
120                                                  void* userdata);
121     static void staticWrtInstallProgressCallback(float percent,
122                                                 const char* description,
123                                                 void* userdata);
124
125     static void staticWrtUninstallProgressCallback(float percent,
126                                                 const char* description,
127                                                 void* userdata);
128
129     static void showResultCallback(void *data, Evas_Object *obj,
130                                    void *event_info);
131     static void failResultCallback(void *data, Evas_Object *obj,
132                                    void *event_info);
133
134     // Private data
135     wrt_widget_install_mode_e m_installPolicy;
136     std::string m_bundleValue;
137     std::string m_packagePath;
138     int m_handle;
139     std::string m_name;
140     bool m_initialized;
141     size_t m_numPluginsToInstall;
142     size_t m_totalPlugins;
143     int m_returnStatus;
144     //For package manager
145     pkgmgr_installer *m_installer;
146     bool m_installByPkgmgr;
147     bool m_quiet;
148     bool m_sendSig;
149     InstallerPopup *m_popup;
150     bool m_startupPluginInstallation;
151     std::string m_webAppUrl;
152     std::string m_webAppIcon;
153
154     typedef std::list<std::string> PluginPathList;
155     DPL::Optional<PluginPathList> m_pluginsPaths;
156 };
157 #endif // WRT_CLIENT_H