1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
16 Stanislav Visnovsky <visnov@suse.cz>
20 #include <rpc/types.h> // MAXHOSTNAMELEN
23 #include <ycp/YCPTerm.h>
24 #include <ycp/YCPCode.h>
26 #define y2log_component "web-ui"
27 #include <ycp/y2log.h>
29 #include <WApplication>
32 #include "YWebApplication.h"
33 #include "YWebWidgetFactory.h"
34 #include "YWebOptionalWidgetFactory.h"
35 #include "YWebDialog.h"
39 YWebUI * YWebUI::_ui = 0;
40 int YWebUI::_argc = 0;
41 char ** YWebUI::_argv = 0L;
43 YWebUI::YWebUI( const Wt::WEnvironment& env, const char * macro_file )
45 YUI( true /* with_threads */ )
47 , _do_exit_loop( false )
52 // processCommandLineArgs( argc, argv );
54 topmostConstructorHasFinished();
58 void YWebUI::processCommandLineArgs( int argc, char **argv )
62 for( int i=0; i < argc; i++ )
66 y2milestone ("Web argument: %s", argv[i]);
76 y2debug("Closing down Web UI.");
82 YWebUI::createWidgetFactory()
84 YWebWidgetFactory * factory = new YWebWidgetFactory();
85 YUI_CHECK_NEW( factory );
92 YOptionalWidgetFactory *
93 YWebUI::createOptionalWidgetFactory()
95 YWebOptionalWidgetFactory * factory = new YWebOptionalWidgetFactory();
96 YUI_CHECK_NEW( factory );
103 YWebUI::createApplication()
105 YWebApplication * app = new YWebApplication();
106 YUI_CHECK_NEW( app );
112 void YWebUI::internalError( const char * msg )
119 void YWebUI::idleLoop( int fd_ycp )
122 _leave_idle_loop = true;
126 void YWebUI::leaveIdleLoop( int )
129 _leave_idle_loop = true;
133 void YWebUI::sendEvent( YEvent * event )
137 _event_handler.sendEvent( event );
139 if ( _do_exit_loop ) {
146 YEvent * YWebUI::userInput( unsigned long timeout_millisec )
150 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
152 if ( _user_input_timer.isActive() )
153 _user_input_timer.stop();
157 if ( timeout_millisec > 0 )
158 _user_input_timer.start( timeout_millisec, true ); // single shot
160 dialog->activate( true );
162 if ( qApp->focusWidget() )
163 qApp->focusWidget()->setFocus();
166 _do_exit_loop = true; // should exit_loop() be called in sendEvent()?
168 while ( ! pendingEvent() )
173 _do_exit_loop = false;
174 event = _event_handler.consumePendingEvent();
175 dialog->activate( false );
177 // Display a busy cursor, but only if there is no other activity within
178 // BUSY_CURSOR_TIMEOUT milliseconds (avoid cursor flicker)
180 _busy_cursor_timer.start( BUSY_CURSOR_TIMEOUT, true ); // single shot
183 if ( _user_input_timer.isActive() )
184 _user_input_timer.stop();
191 YEvent * YWebUI::pollInput()
196 if ( _user_input_timer.isActive() )
197 _user_input_timer.stop();
199 if ( ! pendingEvent() )
201 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
205 dialog->activate( true );
206 qApp->processEvents();
207 event = _event_handler.consumePendingEvent();
208 dialog->activate( false );
212 if ( pendingEvent() )
213 event = _event_handler.consumePendingEvent();
219 YDialog * YWebUI::createDialog( YWidgetOpt & opt )
221 return new YWebDialog( opt );
225 void YWebUI::showDialog( YDialog * dialog )
228 // event loop in Qt is here
232 void YWebUI::closeDialog( YDialog * dialog )
238 WApplication *createApplication(const WEnvironment& env)
240 // Instantiate the Wt application.
241 YWebUI *appl = new YWebUI( env, 0 );
245 std::string title( "YaST2" );
246 char hostname[ MAXHOSTNAMELEN+1 ];
248 if ( gethostname( hostname, sizeof( hostname )-1 ) == 0 )
250 hostname[ sizeof( hostname ) -1 ] = '\0'; // make sure it's terminated
252 if ( strlen( hostname ) > 0 )
254 if ( ( strcmp( hostname, "(none)" ) != 0 &&
255 strcmp( hostname, "linux" ) != 0 )
264 y2milestone( "Created WApplication (%p)", appl );
266 // Set application title
267 appl->setTitle(title);
270 // Set up a timer for handling YaST requests
279 void *start_webserver_thread( void * yui )
281 // FIXME: do the work
282 YWebUI* ui = (YWebUI*)yui;
284 WRun(ui->_argc, ui->_argv, &createApplication);