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>
29 class YWebOptionalWidgetFactory;
30 class YWebWidgetFactory;
36 class YWebUI: public Wt::WApplication, public YUI
43 YWebUI( const Wt::WEnvironment& env,
44 const char * macro_file );
52 * Access the global Qt-UI.
54 static YWebUI * ui() { return _ui; }
59 * Create the widget factory that provides all the createXY() methods for
60 * standard (mandatory, i.e. non-optional) widgets.
62 * Reimplemented from YUI.
64 virtual YWidgetFactory * createWidgetFactory();
67 * Create the widget factory that provides all the createXY() methods for
68 * optional ("special") widgets and the corresponding hasXYWidget()
71 * Reimplemented from YUI.
73 virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
76 * Create the YApplication object that provides global methods.
78 * Reimplemented from YUI.
80 virtual YApplication * createApplication();
85 * Widget event handlers (slots) call this when an event occured that
86 * should be the answer to a UserInput() / PollInput() (etc.) call.
88 * The UI assumes ownership of the event object that 'event' points to.
89 * In particular, it takes care to delete that object.
91 * It is an error to pass 0 for 'event'.
93 void sendEvent( YEvent * event );
96 * Returns 'true' if there is any event pending for the specified widget.
98 bool eventPendingFor( YWidget * widget ) const
99 { return _event_handler.eventPendingFor( widget ); }
102 * Returns the last event that isn't processed yet or 0 if there is none.
104 * The Qt UI keeps track of only one single (the last one) event.
106 YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
109 * Returns 'true' if the UI had a fatal error that requires the application
112 bool fatalError() const { return _fatal_error; }
115 * Raise a fatal UI error. It will be delivered when it is safe to do so.
116 * The caller should make sure it can continue for some time until the
117 * error is delivered.
119 void raiseFatalError() { _fatal_error = true; }
122 * UI-specific runPkgSeleciton method: Start the package selection.
123 * This implementation does the same as UserInput().
125 * Reimplemented from YUI.
127 YCPValue runPkgSelection( YWidget * packageSelector );
130 * Issue an internal error: Open popup with that message and wait.
132 * Reimplemented from YUI.
134 void internalError( const char * msg );
138 * Block (or unblock) events. If events are blocked, any event sent
139 * should be ignored until events are unblocked again.
141 * Reimplemented from YUI.
143 virtual void blockEvents( bool block = true )
144 { _event_handler.blockEvents( block ); }
147 * Returns 'true' if events are currently blocked.
149 * Reimplemented from YUI.
151 virtual bool eventsBlocked() const
152 { return _event_handler.eventsBlocked(); }
157 * Idle around until fd_ycp is readable and handle repaints.
158 * This is only used when a separate ui thread is running.
160 * Reimplemented from YUI.
162 void idleLoop( int fd_ycp );
165 * Return a representation for the glyph symbol specified in UTF-8 encoding
166 * or an empty string to get a default textual representation.
168 * Reimplemented from YUI.
170 YCPString glyph( const YCPSymbol & glyphSymbol );
173 * Go into event loop until next user input is available.
175 * Reimplemented from YUI.
177 YEvent * userInput( unsigned long timeout_millisec = 0 );
180 * Check the event queue for user input. Don't wait.
182 * Reimplemented from YUI.
184 YEvent * pollInput();
189 * Reimplemented from YUI.
191 YDialog * createDialog( YWidgetOpt & opt );
194 * Show and activate a dialog.
196 * Reimplemented from YUI.
198 void showDialog( YDialog * dialog );
201 * Decativate and close a dialog. This does not delete the dialog yet.
203 * Reimplemented from YUI.
205 void closeDialog( YDialog * dialog );
207 /*** Widget creation methods for optional widgets, all reimplemented from YUI ***/
210 YWidget * createBarGraph ( YWidget * parent, YWidgetOpt & opt);
213 bool hasDownloadProgress();
214 YWidget * createDownloadProgress ( YWidget * parent,
216 const YCPString & label,
217 const YCPString & filename,
221 YWidget * createDumbTab ( YWidget * parent,
225 YWidget * createSlider ( YWidget * parent,
227 const YCPString & label,
232 bool hasPartitionSplitter();
233 YWidget * createPartitionSplitter( YWidget * parent,
240 const YCPString & usedLabel,
241 const YCPString & freeLabel,
242 const YCPString & newPartLabel,
243 const YCPString & freeFieldLabel,
244 const YCPString & newPartFieldLabel );
247 /*** END widget creation methods ***/
254 * Open a directory selection box and prompt the user for an existing directory.
255 * [Reimplemented from YUI]
257 * 'startDir' is the initial directory that is displayed.
259 * 'headline' is an explanatory text for the directory selection box.
260 * Graphical UIs may omit that if no window manager is running.
262 * Returns the selected directory name
263 * or 'nil' (YCPVoid() ) if the user canceled the operation.
265 YCPValue askForExistingDirectory ( const YCPString & startDir,
266 const YCPString & headline );
269 * Open a file selection box and prompt the user for an existing file.
270 * [Reimplemented from YUI]
272 * 'startWith' is the initial directory or file.
274 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
276 * 'headline' is an explanatory text for the file selection box.
277 * Graphical UIs may omit that if no window manager is running.
279 * Returns the selected file name
280 * or 'nil' (YCPVoid() ) if the user canceled the operation.
282 YCPValue askForExistingFile ( const YCPString & startWith,
283 const YCPString & filter,
284 const YCPString & headline );
287 * Open a file selection box and prompt the user for a file to save data to.
288 * Automatically asks for confirmation if the user selects an existing file.
289 * [Reimplemented from YUI]
291 * 'startWith' is the initial directory or file.
293 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
295 * 'headline' is an explanatory text for the file selection box.
296 * Graphical UIs may omit that if no window manager is running.
298 * Returns the selected file name
299 * or 'nil' (YCPVoid() ) if the user canceled the operation.
301 YCPValue askForSaveFileName ( const YCPString & startWith,
302 const YCPString & filter,
303 const YCPString & headline );
306 * Lower-level version that works with QStrings and does not change
309 string askForSaveFileName( const string & startWith,
310 const string & filter,
311 const string & headline );
316 * Display capabilities.
317 * [Reimplemented from YUI]
318 * See UI builtin GetDisplayInfo() doc for details.
320 bool textMode() { return false; }
321 bool hasImageSupport() { return true; }
322 bool hasLocalImageSupport() { return false; }
323 bool hasAnimationSupport() { return true; }
324 bool hasIconSupport() { return false; } // not yet
325 bool hasFullUtf8Support() { return true; }
326 bool richTextSupportsTable() { return true; }
330 * Sets @ref #leave_idle_loop to true.
332 void leaveIdleLoop( int );
338 * Handle command line args
340 void processCommandLineArgs( int argc, char **argv );
343 * Calculate size of `opt(`defaultsize) dialogs
345 void calcDefaultSize();
353 * Stack to keep track of the stacking order of popup dialogs.
355 // FIXME: vector<QWidget *> _popup_stack;
358 * Numeric ID for defaultsize dialogs for the widget stack
363 * A flag used during the idle loop. If it is set to true,
364 * the idle loop is left. This happens, if the ycp-ui-communication
365 * pipe to the ui gets readable.
367 bool _leave_idle_loop;
370 * This flag is set during @ref #userInput in order to tell
371 * @ref #returnNow to call exit_loop, which only may be called
378 * Global reference to the UI
383 * Indicate a fatal error that requires the UI to terminate
388 * The handler for the single pending event this UI keeps track of
390 YSimpleEventHandler _event_handler;