890f42d9613a4b29c2d3d2ab0f7d3fc3bc30565a
[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_INSTALLER_H
22 #define WRT_INSTALLER_H
23
24 #include <dpl/application.h>
25 #include <dpl/generic_event.h>
26 #include <dpl/event/controller.h>
27 #include <dpl/task.h>
28 #include <dpl/string.h>
29 #include <string>
30 #include <wrt_installer_api.h>
31
32 namespace WRTInstallerNS { //anonymous
33 DECLARE_GENERIC_EVENT_0(QuitEvent)
34 DECLARE_GENERIC_EVENT_0(NextStepEvent)
35 DECLARE_GENERIC_EVENT_0(InstallPluginEvent)
36 }
37
38 typedef void (*ShowResultCallback)(void *data, Evas_Object *obj,
39                                    void *event_info);
40
41 enum ReturnValue
42 {
43     RE_SUCCESS,
44     RE_FAIL
45 };
46
47 class WrtInstaller :
48     public DPL::Application,
49     private DPL::Event::Controller<DPL::TypeListDecl<
50                                        WRTInstallerNS::QuitEvent,
51                                        WRTInstallerNS::NextStepEvent,
52                                        WRTInstallerNS::InstallPluginEvent>::
53                                        Type>,
54     public DPL::TaskDecl<WrtInstaller>
55 {
56   public:
57     WrtInstaller(int argc,
58                  char **argv);
59     virtual ~WrtInstaller();
60
61     int getReturnStatus() const;
62
63     class InstallerPopup
64     {
65       public:
66         InstallerPopup();
67         virtual ~InstallerPopup();
68
69         void init();
70         Evas_Object* createWin(const char* name);
71         void showPopup(void* userdata, const DPL::String& pkgMsg,
72                        ShowResultCallback callback);
73
74         Evas_Object* m_win;
75         Evas_Object* m_popup;
76         Evas_Object* m_progressbar;
77     };
78
79   protected:
80     virtual void OnStop();
81     virtual void OnCreate();
82     virtual void OnReset(bundle *b);
83     virtual void OnTerminate();
84
85   private:
86     void         showHelpAndQuit();
87
88     // Events
89     virtual void OnEventReceived(const WRTInstallerNS::QuitEvent &event);
90     virtual void OnEventReceived(const WRTInstallerNS::NextStepEvent& event);
91     virtual void OnEventReceived(
92         const WRTInstallerNS::InstallPluginEvent& event);
93
94     // Installation steps
95     void initStep();
96     void installStep();
97     void installPluginsStep();
98     void uninstallPkgNameStep();
99     void unistallWgtFileStep();
100     void shutdownStep();
101
102     // Static callbacks
103     static void staticWrtInitCallback(WrtErrStatus status,
104                                       void* userdata);
105     static void staticWrtStatusCallback(std::string tizenId,
106                                         WrtErrStatus status,
107                                         void* userdata);
108     static void staticWrtPluginInstallationCallback(WrtErrStatus status,
109                                                     void* userdata);
110     static void staticWrtPluginInstallProgressCb(float percent,
111                                                  const char* description,
112                                                  void* userdata);
113     static void staticWrtInstallProgressCallback(float percent,
114                                                  const char* description,
115                                                  void* userdata);
116
117     static void staticWrtUninstallProgressCallback(float percent,
118                                                    const char* description,
119                                                    void* userdata);
120
121     static void showResultCallback(void *data, Evas_Object *obj,
122                                    void *event_info);
123     static void failResultCallback(void *data, Evas_Object *obj,
124                                    void *event_info);
125
126     void installNewPlugins();
127     bool popupsEnabled() const;
128
129     // Private data
130     std::shared_ptr<PackageManager::IPkgmgrSignal> pkgmgrSignalInterface;
131     WrtInstallMode m_installMode;
132     std::string m_packagePath;
133     std::string m_name;
134     bool m_initialized;
135     size_t m_numPluginsToInstall;
136     size_t m_totalPlugins;
137     int m_returnStatus;
138     bool m_installByPkgmgr;
139     bool m_quiet;
140     InstallerPopup *m_popup;
141     bool m_startupPluginInstallation;
142
143     typedef std::list<std::string> PluginPathList;
144     DPL::Optional<PluginPathList> m_pluginsPaths;
145 };
146 #endif // WRT_INSTALLER_H