1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #include <qapplication.h>
28 #include "YSimpleEventHandler.h"
31 #define YQWidgetMargin 4
32 #define YQWidgetSpacing 4
33 #define YQButtonBorder 3
41 class YQOptionalWidgetFactory;
42 class YQPackageSelectorPlugin;
43 class YQWidgetFactory;
50 class YQUI: public QObject, public YUI
61 const char * macro_file );
69 * Access the global Qt-UI.
71 static YQUI * ui() { return _ui; }
76 * Create the widget factory that provides all the createXY() methods for
77 * standard (mandatory, i.e. non-optional) widgets.
79 * Reimplemented from YUI.
81 virtual YWidgetFactory * createWidgetFactory();
84 * Create the widget factory that provides all the createXY() methods for
85 * optional ("special") widgets and the corresponding hasXYWidget()
88 * Reimplemented from YUI.
90 virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
93 * Create the YApplication object that provides global methods.
95 * Reimplemented from YUI.
97 virtual YApplication * createApplication();
102 * Return the global YApplication object as YQApplication.
104 * This will create the Y(Q)Application upon the first call and return a
105 * pointer to the one and only (singleton) Y(Q)Application upon each
106 * subsequent call. This may throw exceptions if the Y(Q)Application
109 static YQApplication * yqApp();
112 * Widget event handlers (slots) call this when an event occured that
113 * should be the answer to a UserInput() / PollInput() (etc.) call.
115 * The UI assumes ownership of the event object that 'event' points to.
116 * In particular, it takes care to delete that object.
118 * It is an error to pass 0 for 'event'.
120 void sendEvent( YEvent * event );
123 * Returns 'true' if there is any event pending for the specified widget.
125 bool eventPendingFor( YWidget * widget ) const
126 { return _event_handler.eventPendingFor( widget ); }
129 * Returns the last event that isn't processed yet or 0 if there is none.
131 * The Qt UI keeps track of only one single (the last one) event.
133 YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
136 * Return 'true' if defaultsize windows should use the full screen.
138 bool fullscreen() const { return _fullscreen; }
141 * Return 'true' if defaultsize windows should not get window manager
144 bool noBorder() const { return _noborder; }
146 * Returns 'true' if the UI had a fatal error that requires the application
149 bool fatalError() const { return _fatal_error; }
152 * Raise a fatal UI error. It will be delivered when it is safe to do so.
153 * The caller should make sure it can continue for some time until the
154 * error is delivered.
156 void raiseFatalError() { _fatal_error = true; }
159 * Returns size for `opt(`defaultsize) dialogs (in one dimension).
161 int defaultSize( YUIDimension dim ) const;
164 * Make a screen shot in .png format and save it to 'filename'.
165 * Opens a file selection box if 'filename' is empty.
167 void makeScreenShot( string filename );
170 * UI-specific runPkgSeleciton method: Start the package selection.
171 * This implementation does the same as UserInput().
173 * Reimplemented from YUI.
175 YCPValue runPkgSelection( YWidget * packageSelector );
178 * Toggle macro recording (activated by Ctrl-Shift-Alt-M):
179 * Stop macro recording if it is in progress,
180 * open a file selection box and ask for a macro file name to save to and
181 * start recording if no recording has been in progress.
183 void toggleRecordMacro();
186 * Open file selection box and ask for a macro file to play
187 * (activated by Ctrl-Shift-Alt-P)
192 * Issue an internal error: Open popup with that message and wait.
194 * Reimplemented from YUI.
196 void internalError( const char * msg );
199 * Block (or unblock) events. If events are blocked, any event sent
200 * should be ignored until events are unblocked again.
202 * Reimplemented from YUI.
204 virtual void blockEvents( bool block = true );
207 * Returns 'true' if events are currently blocked.
209 * Reimplemented from YUI.
211 virtual bool eventsBlocked() const;
214 * Returns the current product name
215 * ("SuSE Linux", "SuSE Linux Enterprise Server", "United Linux", etc.)
218 QString productName() const;
221 * Beep - activate the system (X11) bell.
223 * Reimplemented from YUI.
231 * Show hourglass cursor.
233 * Reimplemented from YUI.
238 * Show pointer cursor.
240 * Reimplemented from YUI.
245 * Open file selection box and let the user Save y2logs to that location.
251 * Open dialog to configure logging.
254 void askConfigureLogging();
257 * A mouse click with the wrong mouse button was detected - e.g., a right
258 * click on a push button. The user might be left-handed, but his mouse
259 * might not (yet) be configured for left-handed use - e.g., during
260 * installation. Ask him if he would like his mouse temporarily configured
261 * as a left-handed mouse.
263 * This status can be queried with UI::GetDisplayInfo() ("LeftHandedMouse").
265 void maybeLeftHandedUser();
271 * Idle around until fd_ycp is readable and handle repaints.
272 * This is only used when a separate ui thread is running.
274 * Reimplemented from YUI.
276 void idleLoop( int fd_ycp );
279 * Return a representation for the glyph symbol specified in UTF-8 encoding
280 * or an empty string to get a default textual representation.
282 * Reimplemented from YUI.
284 YCPString glyph( const YCPSymbol & glyphSymbol );
287 * Go into event loop until next user input is available.
289 * Reimplemented from YUI.
291 YEvent * userInput( unsigned long timeout_millisec = 0 );
294 * Check the event queue for user input. Don't wait.
296 * Reimplemented from YUI.
298 YEvent * pollInput();
301 * Show and activate a dialog.
303 * Reimplemented from YUI.
305 void showDialog( YDialog * dialog );
308 * Decativate and close a dialog. This does not delete the dialog yet.
310 * Reimplemented from YUI.
312 void closeDialog( YDialog * dialog );
319 * Open a directory selection box and prompt the user for an existing directory.
320 * [Reimplemented from YUI]
322 * 'startDir' is the initial directory that is displayed.
324 * 'headline' is an explanatory text for the directory selection box.
325 * Graphical UIs may omit that if no window manager is running.
327 * Returns the selected directory name
328 * or 'nil' (YCPVoid() ) if the user canceled the operation.
330 YCPValue askForExistingDirectory ( const YCPString & startDir,
331 const YCPString & headline );
334 * Open a file selection box and prompt the user for an existing file.
335 * [Reimplemented from YUI]
337 * 'startWith' is the initial directory or file.
339 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
341 * 'headline' is an explanatory text for the file selection box.
342 * Graphical UIs may omit that if no window manager is running.
344 * Returns the selected file name
345 * or 'nil' (YCPVoid() ) if the user canceled the operation.
347 YCPValue askForExistingFile ( const YCPString & startWith,
348 const YCPString & filter,
349 const YCPString & headline );
352 * Open a file selection box and prompt the user for a file to save data to.
353 * Automatically asks for confirmation if the user selects an existing file.
354 * [Reimplemented from YUI]
356 * 'startWith' is the initial directory or file.
358 * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
360 * 'headline' is an explanatory text for the file selection box.
361 * Graphical UIs may omit that if no window manager is running.
363 * Returns the selected file name
364 * or 'nil' (YCPVoid() ) if the user canceled the operation.
366 YCPValue askForSaveFileName ( const YCPString & startWith,
367 const YCPString & filter,
368 const YCPString & headline );
371 * Lower-level version that works with QStrings and does not change
374 QString askForSaveFileName( const QString & startWith,
375 const QString & filter,
376 const QString & headline );
379 * Initialize and set a textdomain for gettext()
381 static void setTextdomain( const char * domain );
384 * Returns a high-contrast color palette suitable for vision impaired users.
386 static QPalette visionImpairedPalette();
389 * Returns the normal color palette
391 QPalette normalPalette() const { return _normalPalette; }
394 * Toggle between the vision impaired and the normal color palette.
396 void toggleVisionImpairedPalette();
399 * Returns 'true' if high-contrast colors for vision impaired users is in use.
400 * This should be queried at other places before using custom colors.
402 bool usingVisionImpairedPalette() const { return _usingVisionImpairedPalette; }
405 * Convert logical layout spacing units into device dependent units.
406 * A default size dialog is assumed to be 80x25 layout spacing units
407 * and 640x480 device dependent spacing units.
409 * Reimplemented from YUI.
411 virtual int deviceUnits( YUIDimension dim, float layout_units );
414 * Convert device dependent units into logical layout spacing units.
415 * A default size dialog is assumed to be 80x25 layout spacing units
416 * and 640x480 device dependent spacing units.
418 * Reimplemented from YUI.
420 virtual float layoutUnits( YUIDimension dim, int device_units );
423 * Returns the package selector plugin singleton of this UI or creates it
424 * (including loading the plugin lib) if it does not exist yet.
426 YQPackageSelectorPlugin * packageSelectorPlugin();
432 * Display capabilities.
433 * [Reimplemented from YUI]
434 * See UI builtin GetDisplayInfo() doc for details.
436 int getDisplayWidth();
437 int getDisplayHeight();
438 int getDisplayDepth();
439 long getDisplayColors();
440 int getDefaultWidth();
441 int getDefaultHeight();
442 bool textMode() { return false; }
443 bool hasImageSupport() { return true; }
444 bool hasLocalImageSupport() { return true; }
445 bool hasAnimationSupport() { return true; }
446 bool hasIconSupport() { return false; } // not yet
447 bool hasFullUtf8Support() { return true; }
448 bool richTextSupportsTable() { return true; }
449 bool leftHandedMouse() { return _leftHandedMouse; }
452 QMap<QString, int> screenShotNo;
453 QString screenShotNameTemplate;
458 * Application shutdown
463 * Timeout during TimeoutUserInput() / WaitForEvent()
465 void userInputTimeout();
470 * Handle command line args
472 void processCommandLineArgs( int argc, char **argv );
475 * Calculate size of `opt(`defaultsize) dialogs
477 void calcDefaultSize();
486 * Use the entire available screen
491 * No window border for the main window
496 * Container for the widget stack. QWidgetStack cannot handle a WFlags
497 * argument, so this needs to be embedded into something else - and a QVBox
498 * at least handles all the sizeHint and resize stuff.
503 * Size for `opt(`defaultsize) dialogs.
508 * This flag is set during @ref #userInput in order to tell
509 * @ref #returnNow to call exit_loop, which only may be called
515 * Event loop object. Required since a YaST2 UI needs to react to commands
516 * from the YCP command stream as well as to X11 / Qt events.
518 QEventLoop * _eventLoop;
521 * Global reference to the UI
526 * Indicate a fatal error that requires the UI to terminate
531 * Timer for TimeoutUserInput() / WaitForEvent().
533 QTimer _user_input_timer;
536 * Timer for delayed busy cursor
538 QTimer *_busy_cursor_timer;
541 * The handler for the single pending event this UI keeps track of
543 YSimpleEventHandler _event_handler;
548 * Saved normal palette
550 QPalette _normalPalette;
553 * Flag: currently using special palette for vision impaired users?
555 bool _usingVisionImpairedPalette;
558 * Flag: Does the user want to use a left-handed mouse?
560 bool _leftHandedMouse;
563 * Flag: Was the user already asked if he wants to use a left-handed mouse?
565 bool _askedForLeftHandedMouse;
572 * Reads the style sheet, parses some comments and passes it to qapp