]> icculus.org git repositories - duncan/yast2-web-wt.git/blob - src/YWebUI_core.cc
fixes YUIComponent.cc(createUI):93 createUI() called before
[duncan/yast2-web-wt.git] / src / YWebUI_core.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YWebUI_core.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16                 Stanislav Visnovsky <visnov@suse.cz>
17
18 /-*/
19
20 #include <rpc/types.h>          // MAXHOSTNAMELEN
21 #include <dlfcn.h>
22
23 #include <ycp/YCPTerm.h>
24 #include <ycp/YCPCode.h>
25
26 #define y2log_component "web-ui"
27 #include <ycp/y2log.h>
28
29 #include <WApplication>
30
31 #include "YWebUI.h"
32 #include "YWebApplication.h"
33 #include "YWebWidgetFactory.h"
34 #include "YWebOptionalWidgetFactory.h"
35 #include "YEvent.h"
36 #include "YUISymbols.h"
37
38 using namespace Wt;
39
40 YWebUI * YWebUI::_ui = 0;
41 int YWebUI::_argc = 0;
42 char ** YWebUI::_argv = 0L;
43
44 YWebUI::YWebUI( const Wt::WEnvironment& env, const char * macro_file )
45     : WApplication(env),
46     YUI( true /* with_threads */ )
47     , _main_dialog_id(0)
48     , _do_exit_loop( false )
49 {
50     _ui                         = this;
51     _fatal_error                = false;
52
53 //    processCommandLineArgs( argc, argv );
54
55     topmostConstructorHasFinished();
56 }
57
58
59 void YWebUI::processCommandLineArgs( int argc, char **argv )
60 {
61     if ( argv )
62     {
63         for( int i=0; i < argc; i++ )
64         {
65             string opt = argv[i];
66
67             y2milestone ("Web argument: %s", argv[i]);
68
69         }
70     }
71 }
72
73
74
75 YWebUI::~YWebUI()
76 {
77     y2debug("Closing down Web UI.");
78 }
79
80
81
82 YWidgetFactory *
83 YWebUI::createWidgetFactory()
84 {
85     YWebWidgetFactory * factory = new YWebWidgetFactory();
86     YUI_CHECK_NEW( factory );
87
88     return factory;
89 }
90
91
92
93 YOptionalWidgetFactory *
94 YWebUI::createOptionalWidgetFactory()
95 {
96     YWebOptionalWidgetFactory * factory = new YWebOptionalWidgetFactory();
97     YUI_CHECK_NEW( factory );
98
99     return factory;
100 }
101
102
103 YApplication *
104 YWebUI::createApplication()
105 {
106     YWebApplication * app = new YWebApplication();
107                 YUI_CHECK_NEW( app );
108                 return app;
109 }
110
111
112
113 void YWebUI::internalError( const char * msg )
114 {
115     raiseFatalError();
116     abort();
117 }
118
119
120 void YWebUI::idleLoop( int fd_ycp )
121 {
122     // FIXME
123     _leave_idle_loop = true;
124 }
125
126
127 void YWebUI::leaveIdleLoop( int )
128 {
129     // FIXME
130     _leave_idle_loop = true;
131 }
132
133
134 void YWebUI::sendEvent( YEvent * event )
135 {
136     if ( event )
137     {
138         _event_handler.sendEvent( event );
139
140         if ( _do_exit_loop ) {
141         // FIXME:
142         }
143     }
144 }
145
146
147 YEvent * YWebUI::userInput( unsigned long timeout_millisec )
148 {
149     YEvent *    event  = 0;
150 #if 0
151     YQDialog *  dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
152
153     if ( _user_input_timer.isActive() )
154         _user_input_timer.stop();
155
156     if ( dialog )
157     {
158         if ( timeout_millisec > 0 )
159             _user_input_timer.start( timeout_millisec, true ); // single shot
160
161         dialog->activate( true );
162
163         if ( qApp->focusWidget() )
164             qApp->focusWidget()->setFocus();
165
166         normalCursor();
167         _do_exit_loop = true; // should exit_loop() be called in sendEvent()?
168
169         while ( ! pendingEvent() )
170         {
171             qApp->enter_loop();
172         }
173
174         _do_exit_loop = false;
175         event = _event_handler.consumePendingEvent();
176         dialog->activate( false );
177
178         // Display a busy cursor, but only if there is no other activity within
179         // BUSY_CURSOR_TIMEOUT milliseconds (avoid cursor flicker)
180
181         _busy_cursor_timer.start( BUSY_CURSOR_TIMEOUT, true ); // single shot
182     }
183
184     if ( _user_input_timer.isActive() )
185         _user_input_timer.stop();
186
187 #endif
188     return event;
189 }
190
191
192 YEvent * YWebUI::pollInput()
193 {
194     YEvent * event = 0;
195
196 #if 0
197     if ( _user_input_timer.isActive() )
198         _user_input_timer.stop();
199
200     if ( ! pendingEvent() )
201     {
202         YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
203
204         if ( dialog )
205         {
206             dialog->activate( true );
207             qApp->processEvents();
208             event = _event_handler.consumePendingEvent();
209             dialog->activate( false );
210         }
211     }
212
213     if ( pendingEvent() )
214         event = _event_handler.consumePendingEvent();
215 #endif
216     return event;
217 }
218
219
220 YDialog * YWebUI::createDialog( YWidgetOpt & opt )
221 {
222     // FIXME
223     return 0L;
224 }
225
226
227 void YWebUI::showDialog( YDialog * dialog )
228 {
229     // FIXME
230     // event loop in Qt is here
231 }
232
233
234 void YWebUI::closeDialog( YDialog * dialog )
235 {
236     // FIXME
237 }
238
239
240 WApplication *createApplication(const WEnvironment& env)
241 {
242   // Instantiate the Wt application.
243   YWebUI *appl = new YWebUI( env, 0 );
244
245     // Set window title
246
247     std::string title( "YaST2" );
248     char hostname[ MAXHOSTNAMELEN+1 ];
249
250     if ( gethostname( hostname, sizeof( hostname )-1 ) == 0 )
251     {
252         hostname[ sizeof( hostname ) -1 ] = '\0'; // make sure it's terminated
253
254         if ( strlen( hostname ) > 0 )
255         {
256             if ( ( strcmp( hostname, "(none)" ) != 0 &&
257                    strcmp( hostname, "linux"  ) != 0 )
258                   )
259             {
260                 title += "@";
261                 title += hostname;
262             }
263         }
264     }
265
266   y2milestone( "Created WApplication (%p)", appl );
267
268   // Set application title
269   appl->setTitle(title);
270
271 #if 0
272   // Set up a timer for handling YaST requests
273   appl->createTimer();
274
275   _wtimer_work = true;
276 #endif
277
278   return appl;
279 }
280
281 void *start_webserver_thread( void * yui )
282 {
283     // FIXME: do the work
284     YWebUI* ui = (YWebUI*)yui;
285
286     WRun(ui->_argc, ui->_argv, &createApplication);
287
288     return 0;
289 }