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"
36 #include "YUISymbols.h"
40 YWebUI * YWebUI::_ui = 0;
41 int YWebUI::_argc = 0;
42 char ** YWebUI::_argv = 0L;
44 YWebUI::YWebUI( const Wt::WEnvironment& env, const char * macro_file )
46 YUI( true /* with_threads */ )
48 , _do_exit_loop( false )
53 // processCommandLineArgs( argc, argv );
55 topmostConstructorHasFinished();
59 void YWebUI::processCommandLineArgs( int argc, char **argv )
63 for( int i=0; i < argc; i++ )
67 y2milestone ("Web argument: %s", argv[i]);
77 y2debug("Closing down Web UI.");
83 YWebUI::createWidgetFactory()
85 YWebWidgetFactory * factory = new YWebWidgetFactory();
86 YUI_CHECK_NEW( factory );
93 YOptionalWidgetFactory *
94 YWebUI::createOptionalWidgetFactory()
96 YWebOptionalWidgetFactory * factory = new YWebOptionalWidgetFactory();
97 YUI_CHECK_NEW( factory );
104 YWebUI::createApplication()
106 YWebApplication * app = new YWebApplication();
107 YUI_CHECK_NEW( app );
113 void YWebUI::internalError( const char * msg )
120 void YWebUI::idleLoop( int fd_ycp )
123 _leave_idle_loop = true;
127 void YWebUI::leaveIdleLoop( int )
130 _leave_idle_loop = true;
134 void YWebUI::sendEvent( YEvent * event )
138 _event_handler.sendEvent( event );
140 if ( _do_exit_loop ) {
147 YEvent * YWebUI::userInput( unsigned long timeout_millisec )
151 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
153 if ( _user_input_timer.isActive() )
154 _user_input_timer.stop();
158 if ( timeout_millisec > 0 )
159 _user_input_timer.start( timeout_millisec, true ); // single shot
161 dialog->activate( true );
163 if ( qApp->focusWidget() )
164 qApp->focusWidget()->setFocus();
167 _do_exit_loop = true; // should exit_loop() be called in sendEvent()?
169 while ( ! pendingEvent() )
174 _do_exit_loop = false;
175 event = _event_handler.consumePendingEvent();
176 dialog->activate( false );
178 // Display a busy cursor, but only if there is no other activity within
179 // BUSY_CURSOR_TIMEOUT milliseconds (avoid cursor flicker)
181 _busy_cursor_timer.start( BUSY_CURSOR_TIMEOUT, true ); // single shot
184 if ( _user_input_timer.isActive() )
185 _user_input_timer.stop();
192 YEvent * YWebUI::pollInput()
197 if ( _user_input_timer.isActive() )
198 _user_input_timer.stop();
200 if ( ! pendingEvent() )
202 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
206 dialog->activate( true );
207 qApp->processEvents();
208 event = _event_handler.consumePendingEvent();
209 dialog->activate( false );
213 if ( pendingEvent() )
214 event = _event_handler.consumePendingEvent();
220 YDialog * YWebUI::createDialog( YWidgetOpt & opt )
227 void YWebUI::showDialog( YDialog * dialog )
230 // event loop in Qt is here
234 void YWebUI::closeDialog( YDialog * dialog )
240 WApplication *createApplication(const WEnvironment& env)
242 // Instantiate the Wt application.
243 YWebUI *appl = new YWebUI( env, 0 );
247 std::string title( "YaST2" );
248 char hostname[ MAXHOSTNAMELEN+1 ];
250 if ( gethostname( hostname, sizeof( hostname )-1 ) == 0 )
252 hostname[ sizeof( hostname ) -1 ] = '\0'; // make sure it's terminated
254 if ( strlen( hostname ) > 0 )
256 if ( ( strcmp( hostname, "(none)" ) != 0 &&
257 strcmp( hostname, "linux" ) != 0 )
266 y2milestone( "Created WApplication (%p)", appl );
268 // Set application title
269 appl->setTitle(title);
272 // Set up a timer for handling YaST requests
281 void *start_webserver_thread( void * yui )
283 // FIXME: do the work
284 YWebUI* ui = (YWebUI*)yui;
286 WRun(ui->_argc, ui->_argv, &createApplication);