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 <yui/YApplication.h>
30 #include <WApplication>
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 // YApplication * app = new YApplication();
107 // YUI_CHECK_NEW( app );
114 void YWebUI::internalError( const char * msg )
121 void YWebUI::idleLoop( int fd_ycp )
124 _leave_idle_loop = true;
128 void YWebUI::leaveIdleLoop( int )
131 _leave_idle_loop = true;
135 void YWebUI::sendEvent( YEvent * event )
139 _event_handler.sendEvent( event );
141 if ( _do_exit_loop ) {
148 YEvent * YWebUI::userInput( unsigned long timeout_millisec )
152 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
154 if ( _user_input_timer.isActive() )
155 _user_input_timer.stop();
159 if ( timeout_millisec > 0 )
160 _user_input_timer.start( timeout_millisec, true ); // single shot
162 dialog->activate( true );
164 if ( qApp->focusWidget() )
165 qApp->focusWidget()->setFocus();
168 _do_exit_loop = true; // should exit_loop() be called in sendEvent()?
170 while ( ! pendingEvent() )
175 _do_exit_loop = false;
176 event = _event_handler.consumePendingEvent();
177 dialog->activate( false );
179 // Display a busy cursor, but only if there is no other activity within
180 // BUSY_CURSOR_TIMEOUT milliseconds (avoid cursor flicker)
182 _busy_cursor_timer.start( BUSY_CURSOR_TIMEOUT, true ); // single shot
185 if ( _user_input_timer.isActive() )
186 _user_input_timer.stop();
193 YEvent * YWebUI::pollInput()
198 if ( _user_input_timer.isActive() )
199 _user_input_timer.stop();
201 if ( ! pendingEvent() )
203 YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog( false ) );
207 dialog->activate( true );
208 qApp->processEvents();
209 event = _event_handler.consumePendingEvent();
210 dialog->activate( false );
214 if ( pendingEvent() )
215 event = _event_handler.consumePendingEvent();
221 YDialog * YWebUI::createDialog( YWidgetOpt & opt )
228 void YWebUI::showDialog( YDialog * dialog )
231 // event loop in Qt is here
235 void YWebUI::closeDialog( YDialog * dialog )
241 WApplication *createApplication(const WEnvironment& env)
243 // Instantiate the Wt application.
244 YWebUI *appl = new YWebUI( env, 0 );
248 std::string title( "YaST2" );
249 char hostname[ MAXHOSTNAMELEN+1 ];
251 if ( gethostname( hostname, sizeof( hostname )-1 ) == 0 )
253 hostname[ sizeof( hostname ) -1 ] = '\0'; // make sure it's terminated
255 if ( strlen( hostname ) > 0 )
257 if ( ( strcmp( hostname, "(none)" ) != 0 &&
258 strcmp( hostname, "linux" ) != 0 )
267 y2milestone( "Created WApplication (%p)", appl );
269 // Set application title
270 appl->setTitle(title);
273 // Set up a timer for handling YaST requests
282 void *start_webserver_thread( void * yui )
284 // FIXME: do the work
285 YWebUI* ui = (YWebUI*)yui;
287 WRun(ui->_argc, ui->_argv, &createApplication);