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