]> icculus.org git repositories - duncan/yast2-web-wt.git/blob - src/YWebUI_core.cc
8ed20a10f07e0e30c06e31ac4929a8ca107ac607
[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 <yui/YApplication.h>
30 #include <WApplication>
31
32 #include "YWebUI.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 //    YApplication * app = new YApplication();
107 //    YUI_CHECK_NEW( app );
108 // FIXME
109     return 0L;
110 }
111
112
113
114 void YWebUI::internalError( const char * msg )
115 {
116     raiseFatalError();
117     abort();
118 }
119
120
121 void YWebUI::idleLoop( int fd_ycp )
122 {
123     // FIXME
124     _leave_idle_loop = true;
125 }
126
127
128 void YWebUI::leaveIdleLoop( int )
129 {
130     // FIXME
131     _leave_idle_loop = true;
132 }
133
134
135 void YWebUI::sendEvent( YEvent * event )
136 {
137     if ( event )
138     {
139         _event_handler.sendEvent( event );
140
141         if ( _do_exit_loop ) {
142         // FIXME:
143         }
144     }
145 }
146
147
148 YEvent * YWebUI::userInput( unsigned long timeout_millisec )
149 {
150     YEvent *    event  = 0;
151 #if 0
152     YQDialog *  dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
153
154     if ( _user_input_timer.isActive() )
155         _user_input_timer.stop();
156
157     if ( dialog )
158     {
159         if ( timeout_millisec > 0 )
160             _user_input_timer.start( timeout_millisec, true ); // single shot
161
162         dialog->activate( true );
163
164         if ( qApp->focusWidget() )
165             qApp->focusWidget()->setFocus();
166
167         normalCursor();
168         _do_exit_loop = true; // should exit_loop() be called in sendEvent()?
169
170         while ( ! pendingEvent() )
171         {
172             qApp->enter_loop();
173         }
174
175         _do_exit_loop = false;
176         event = _event_handler.consumePendingEvent();
177         dialog->activate( false );
178
179         // Display a busy cursor, but only if there is no other activity within
180         // BUSY_CURSOR_TIMEOUT milliseconds (avoid cursor flicker)
181
182         _busy_cursor_timer.start( BUSY_CURSOR_TIMEOUT, true ); // single shot
183     }
184
185     if ( _user_input_timer.isActive() )
186         _user_input_timer.stop();
187
188 #endif
189     return event;
190 }
191
192
193 YEvent * YWebUI::pollInput()
194 {
195     YEvent * event = 0;
196
197 #if 0
198     if ( _user_input_timer.isActive() )
199         _user_input_timer.stop();
200
201     if ( ! pendingEvent() )
202     {
203         YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
204
205         if ( dialog )
206         {
207             dialog->activate( true );
208             qApp->processEvents();
209             event = _event_handler.consumePendingEvent();
210             dialog->activate( false );
211         }
212     }
213
214     if ( pendingEvent() )
215         event = _event_handler.consumePendingEvent();
216 #endif
217     return event;
218 }
219
220
221 YDialog * YWebUI::createDialog( YWidgetOpt & opt )
222 {
223     // FIXME
224     return 0L;
225 }
226
227
228 void YWebUI::showDialog( YDialog * dialog )
229 {
230     // FIXME
231     // event loop in Qt is here
232 }
233
234
235 void YWebUI::closeDialog( YDialog * dialog )
236 {
237     // FIXME
238 }
239
240
241 WApplication *createApplication(const WEnvironment& env)
242 {
243   // Instantiate the Wt application.
244   YWebUI *appl = new YWebUI( env, 0 );
245
246     // Set window title
247
248     std::string title( "YaST2" );
249     char hostname[ MAXHOSTNAMELEN+1 ];
250
251     if ( gethostname( hostname, sizeof( hostname )-1 ) == 0 )
252     {
253         hostname[ sizeof( hostname ) -1 ] = '\0'; // make sure it's terminated
254
255         if ( strlen( hostname ) > 0 )
256         {
257             if ( ( strcmp( hostname, "(none)" ) != 0 &&
258                    strcmp( hostname, "linux"  ) != 0 )
259                   )
260             {
261                 title += "@";
262                 title += hostname;
263             }
264         }
265     }
266
267   y2milestone( "Created WApplication (%p)", appl );
268
269   // Set application title
270   appl->setTitle(title);
271
272 #if 0
273   // Set up a timer for handling YaST requests
274   appl->createTimer();
275
276   _wtimer_work = true;
277 #endif
278
279   return appl;
280 }
281
282 void *start_webserver_thread( void * yui )
283 {
284     // FIXME: do the work
285     YWebUI* ui = (YWebUI*)yui;
286
287     WRun(ui->_argc, ui->_argv, &createApplication);
288
289     return 0;
290 }