1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
16 Stanislav Visnovsky <visnov@suse.cz>
23 #include "YSimpleEventHandler.h"
26 #include <WApplication>
28 #include <WEnvironment>
31 class YWebOptionalWidgetFactory;
32 class YWebWidgetFactory;
38 Wt::WApplication *createApplication(const Wt::WEnvironment& env);
39 void *start_webserver_thread( void * yui );
41 class YWebUI: public Wt::WApplication, public YUI
48 YWebUI( const Wt::WEnvironment& env,
49 const char * macro_file );
57 * Access the global Qt-UI.
59 static YWebUI * ui() { return _ui; }
64 * Create the widget factory that provides all the createXY() methods for
65 * standard (mandatory, i.e. non-optional) widgets.
67 * Reimplemented from YUI.
69 virtual YWidgetFactory * createWidgetFactory();
72 * Create the widget factory that provides all the createXY() methods for
73 * optional ("special") widgets and the corresponding hasXYWidget()
76 * Reimplemented from YUI.
78 virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
81 * Create the YApplication object that provides global methods.
83 * Reimplemented from YUI.
85 virtual YApplication * createApplication();
90 * Widget event handlers (slots) call this when an event occured that
91 * should be the answer to a UserInput() / PollInput() (etc.) call.
93 * The UI assumes ownership of the event object that 'event' points to.
94 * In particular, it takes care to delete that object.
96 * It is an error to pass 0 for 'event'.
98 void sendEvent( YEvent * event );
101 * Returns 'true' if there is any event pending for the specified widget.
103 bool eventPendingFor( YWidget * widget ) const
104 { return _event_handler.eventPendingFor( widget ); }
107 * Returns the last event that isn't processed yet or 0 if there is none.
109 * The Qt UI keeps track of only one single (the last one) event.
111 YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
114 * Returns 'true' if the UI had a fatal error that requires the application
117 bool fatalError() const { return _fatal_error; }
120 * Raise a fatal UI error. It will be delivered when it is safe to do so.
121 * The caller should make sure it can continue for some time until the
122 * error is delivered.
124 void raiseFatalError() { _fatal_error = true; }
127 * UI-specific runPkgSeleciton method: Start the package selection.
128 * This implementation does the same as UserInput().
130 * Reimplemented from YUI.
132 YCPValue runPkgSelection( YWidget * packageSelector );
135 * Issue an internal error: Open popup with that message and wait.
137 * Reimplemented from YUI.
139 void internalError( const char * msg );
143 * Block (or unblock) events. If events are blocked, any event sent
144 * should be ignored until events are unblocked again.
146 * Reimplemented from YUI.
148 virtual void blockEvents( bool block = true )
149 { _event_handler.blockEvents( block ); }
152 * Returns 'true' if events are currently blocked.
154 * Reimplemented from YUI.
156 virtual bool eventsBlocked() const
157 { return _event_handler.eventsBlocked(); }
162 * Idle around until fd_ycp is readable and handle repaints.
163 * This is only used when a separate ui thread is running.
165 * Reimplemented from YUI.
167 void idleLoop( int fd_ycp );
170 * Return a representation for the glyph symbol specified in UTF-8 encoding
171 * or an empty string to get a default textual representation.
173 * Reimplemented from YUI.
175 YCPString glyph( const YCPSymbol & glyphSymbol );
178 * Go into event loop until next user input is available.
180 * Reimplemented from YUI.
182 YEvent * userInput( unsigned long timeout_millisec = 0 );
185 * Check the event queue for user input. Don't wait.
187 * Reimplemented from YUI.
189 YEvent * pollInput();
194 * Reimplemented from YUI.
196 YDialog * createDialog( YWidgetOpt & opt );
199 * Show and activate a dialog.
201 * Reimplemented from YUI.
203 void showDialog( YDialog * dialog );
206 * Decativate and close a dialog. This does not delete the dialog yet.
208 * Reimplemented from YUI.
210 void closeDialog( YDialog * dialog );
212 /*** Widget creation methods for optional widgets, all reimplemented from YUI ***/
215 YWidget * createBarGraph ( YWidget * parent, YWidgetOpt & opt);
218 bool hasDownloadProgress();
219 YWidget * createDownloadProgress ( YWidget * parent,
221 const YCPString & label,
222 const YCPString & filename,
226 YWidget * createDumbTab ( YWidget * parent,
230 YWidget * createSlider ( YWidget * parent,
232 const YCPString & label,
237 bool hasPartitionSplitter();
238 YWidget * createPartitionSplitter( YWidget * parent,
245 const YCPString & usedLabel,
246 const YCPString & freeLabel,
247 const YCPString & newPartLabel,
248 const YCPString & freeFieldLabel,
249 const YCPString & newPartFieldLabel );
252 /*** END widget creation methods ***/
259 * Open a directory selection box and prompt the user for an existing directory.
260 * [Reimplemented from YUI]
262 * 'startDir' is the initial directory that is displayed.
264 * 'headline' is an explanatory text for the directory selection box.
265 * Graphical UIs may omit that if no window manager is running.
267 * Returns the selected directory name
268 * or 'nil' (YCPVoid() ) if the user canceled the operation.
270 YCPValue askForExistingDirectory ( const YCPString & startDir,
271 const YCPString & headline );
274 * Open a file selection box and prompt the user for an existing file.
275 * [Reimplemented from YUI]
277 * 'startWith' is the initial directory or file.
279 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
281 * 'headline' is an explanatory text for the file selection box.
282 * Graphical UIs may omit that if no window manager is running.
284 * Returns the selected file name
285 * or 'nil' (YCPVoid() ) if the user canceled the operation.
287 YCPValue askForExistingFile ( const YCPString & startWith,
288 const YCPString & filter,
289 const YCPString & headline );
292 * Open a file selection box and prompt the user for a file to save data to.
293 * Automatically asks for confirmation if the user selects an existing file.
294 * [Reimplemented from YUI]
296 * 'startWith' is the initial directory or file.
298 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
300 * 'headline' is an explanatory text for the file selection box.
301 * Graphical UIs may omit that if no window manager is running.
303 * Returns the selected file name
304 * or 'nil' (YCPVoid() ) if the user canceled the operation.
306 YCPValue askForSaveFileName ( const YCPString & startWith,
307 const YCPString & filter,
308 const YCPString & headline );
311 * Lower-level version that works with QStrings and does not change
314 string askForSaveFileName( const string & startWith,
315 const string & filter,
316 const string & headline );
321 * Display capabilities.
322 * [Reimplemented from YUI]
323 * See UI builtin GetDisplayInfo() doc for details.
325 bool textMode() { return false; }
326 bool hasImageSupport() { return true; }
327 bool hasLocalImageSupport() { return false; }
328 bool hasAnimationSupport() { return true; }
329 bool hasIconSupport() { return false; } // not yet
330 bool hasFullUtf8Support() { return true; }
331 bool richTextSupportsTable() { return true; }
335 * Sets @ref #leave_idle_loop to true.
337 void leaveIdleLoop( int );
343 * Handle command line args
345 void processCommandLineArgs( int argc, char **argv );
348 * Calculate size of `opt(`defaultsize) dialogs
350 void calcDefaultSize();
358 * Stack to keep track of the stacking order of popup dialogs.
360 // FIXME: vector<QWidget *> _popup_stack;
363 * Numeric ID for defaultsize dialogs for the widget stack
368 * A flag used during the idle loop. If it is set to true,
369 * the idle loop is left. This happens, if the ycp-ui-communication
370 * pipe to the ui gets readable.
372 bool _leave_idle_loop;
375 * This flag is set during @ref #userInput in order to tell
376 * @ref #returnNow to call exit_loop, which only may be called
383 * Global reference to the UI
388 * Indicate a fatal error that requires the UI to terminate
393 * The handler for the single pending event this UI keeps track of
395 YSimpleEventHandler _event_handler;
400 void triggeredTimer();