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>
27 #include <WEnvironment>
30 class YWebOptionalWidgetFactory;
31 class YWebWidgetFactory;
37 Wt::WApplication *createApplication(const Wt::WEnvironment& env);
38 void *start_webserver_thread( void * yui );
40 class YWebUI: public Wt::WApplication, public YUI
47 YWebUI( const Wt::WEnvironment& env,
48 const char * macro_file );
56 * Access the global Qt-UI.
58 static YWebUI * ui() { return _ui; }
63 * Create the widget factory that provides all the createXY() methods for
64 * standard (mandatory, i.e. non-optional) widgets.
66 * Reimplemented from YUI.
68 virtual YWidgetFactory * createWidgetFactory();
71 * Create the widget factory that provides all the createXY() methods for
72 * optional ("special") widgets and the corresponding hasXYWidget()
75 * Reimplemented from YUI.
77 virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
80 * Create the YApplication object that provides global methods.
82 * Reimplemented from YUI.
84 virtual YApplication * createApplication();
89 * Widget event handlers (slots) call this when an event occured that
90 * should be the answer to a UserInput() / PollInput() (etc.) call.
92 * The UI assumes ownership of the event object that 'event' points to.
93 * In particular, it takes care to delete that object.
95 * It is an error to pass 0 for 'event'.
97 void sendEvent( YEvent * event );
100 * Returns 'true' if there is any event pending for the specified widget.
102 bool eventPendingFor( YWidget * widget ) const
103 { return _event_handler.eventPendingFor( widget ); }
106 * Returns the last event that isn't processed yet or 0 if there is none.
108 * The Qt UI keeps track of only one single (the last one) event.
110 YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
113 * Returns 'true' if the UI had a fatal error that requires the application
116 bool fatalError() const { return _fatal_error; }
119 * Raise a fatal UI error. It will be delivered when it is safe to do so.
120 * The caller should make sure it can continue for some time until the
121 * error is delivered.
123 void raiseFatalError() { _fatal_error = true; }
126 * UI-specific runPkgSeleciton method: Start the package selection.
127 * This implementation does the same as UserInput().
129 * Reimplemented from YUI.
131 YCPValue runPkgSelection( YWidget * packageSelector );
134 * Issue an internal error: Open popup with that message and wait.
136 * Reimplemented from YUI.
138 void internalError( const char * msg );
142 * Block (or unblock) events. If events are blocked, any event sent
143 * should be ignored until events are unblocked again.
145 * Reimplemented from YUI.
147 virtual void blockEvents( bool block = true )
148 { _event_handler.blockEvents( block ); }
151 * Returns 'true' if events are currently blocked.
153 * Reimplemented from YUI.
155 virtual bool eventsBlocked() const
156 { return _event_handler.eventsBlocked(); }
161 * Idle around until fd_ycp is readable and handle repaints.
162 * This is only used when a separate ui thread is running.
164 * Reimplemented from YUI.
166 void idleLoop( int fd_ycp );
169 * Return a representation for the glyph symbol specified in UTF-8 encoding
170 * or an empty string to get a default textual representation.
172 * Reimplemented from YUI.
174 YCPString glyph( const YCPSymbol & glyphSymbol );
177 * Go into event loop until next user input is available.
179 * Reimplemented from YUI.
181 YEvent * userInput( unsigned long timeout_millisec = 0 );
184 * Check the event queue for user input. Don't wait.
186 * Reimplemented from YUI.
188 YEvent * pollInput();
193 * Reimplemented from YUI.
195 YDialog * createDialog( YWidgetOpt & opt );
198 * Show and activate a dialog.
200 * Reimplemented from YUI.
202 void showDialog( YDialog * dialog );
205 * Decativate and close a dialog. This does not delete the dialog yet.
207 * Reimplemented from YUI.
209 void closeDialog( YDialog * dialog );
211 /*** Widget creation methods for optional widgets, all reimplemented from YUI ***/
214 YWidget * createBarGraph ( YWidget * parent, YWidgetOpt & opt);
217 bool hasDownloadProgress();
218 YWidget * createDownloadProgress ( YWidget * parent,
220 const YCPString & label,
221 const YCPString & filename,
225 YWidget * createDumbTab ( YWidget * parent,
229 YWidget * createSlider ( YWidget * parent,
231 const YCPString & label,
236 bool hasPartitionSplitter();
237 YWidget * createPartitionSplitter( YWidget * parent,
244 const YCPString & usedLabel,
245 const YCPString & freeLabel,
246 const YCPString & newPartLabel,
247 const YCPString & freeFieldLabel,
248 const YCPString & newPartFieldLabel );
251 /*** END widget creation methods ***/
258 * Open a directory selection box and prompt the user for an existing directory.
259 * [Reimplemented from YUI]
261 * 'startDir' is the initial directory that is displayed.
263 * 'headline' is an explanatory text for the directory selection box.
264 * Graphical UIs may omit that if no window manager is running.
266 * Returns the selected directory name
267 * or 'nil' (YCPVoid() ) if the user canceled the operation.
269 YCPValue askForExistingDirectory ( const YCPString & startDir,
270 const YCPString & headline );
273 * Open a file selection box and prompt the user for an existing file.
274 * [Reimplemented from YUI]
276 * 'startWith' is the initial directory or file.
278 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
280 * 'headline' is an explanatory text for the file selection box.
281 * Graphical UIs may omit that if no window manager is running.
283 * Returns the selected file name
284 * or 'nil' (YCPVoid() ) if the user canceled the operation.
286 YCPValue askForExistingFile ( const YCPString & startWith,
287 const YCPString & filter,
288 const YCPString & headline );
291 * Open a file selection box and prompt the user for a file to save data to.
292 * Automatically asks for confirmation if the user selects an existing file.
293 * [Reimplemented from YUI]
295 * 'startWith' is the initial directory or file.
297 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
299 * 'headline' is an explanatory text for the file selection box.
300 * Graphical UIs may omit that if no window manager is running.
302 * Returns the selected file name
303 * or 'nil' (YCPVoid() ) if the user canceled the operation.
305 YCPValue askForSaveFileName ( const YCPString & startWith,
306 const YCPString & filter,
307 const YCPString & headline );
310 * Lower-level version that works with QStrings and does not change
313 string askForSaveFileName( const string & startWith,
314 const string & filter,
315 const string & headline );
320 * Display capabilities.
321 * [Reimplemented from YUI]
322 * See UI builtin GetDisplayInfo() doc for details.
324 bool textMode() { return false; }
325 bool hasImageSupport() { return true; }
326 bool hasLocalImageSupport() { return false; }
327 bool hasAnimationSupport() { return true; }
328 bool hasIconSupport() { return false; } // not yet
329 bool hasFullUtf8Support() { return true; }
330 bool richTextSupportsTable() { return true; }
334 * Sets @ref #leave_idle_loop to true.
336 void leaveIdleLoop( int );
342 * Handle command line args
344 void processCommandLineArgs( int argc, char **argv );
347 * Calculate size of `opt(`defaultsize) dialogs
349 void calcDefaultSize();
357 * Stack to keep track of the stacking order of popup dialogs.
359 // FIXME: vector<QWidget *> _popup_stack;
362 * Numeric ID for defaultsize dialogs for the widget stack
367 * A flag used during the idle loop. If it is set to true,
368 * the idle loop is left. This happens, if the ycp-ui-communication
369 * pipe to the ui gets readable.
371 bool _leave_idle_loop;
374 * This flag is set during @ref #userInput in order to tell
375 * @ref #returnNow to call exit_loop, which only may be called
382 * Global reference to the UI
387 * Indicate a fatal error that requires the UI to terminate
392 * The handler for the single pending event this UI keeps track of
394 YSimpleEventHandler _event_handler;