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;
51 class YQUI: public YUI
63 const char * macro_file );
71 * Access the global Qt-UI.
73 static YQUI * ui() { return _ui; }
78 * Create the widget factory that provides all the createXY() methods for
79 * standard (mandatory, i.e. non-optional) widgets.
81 * Reimplemented from YUI.
83 virtual YWidgetFactory * createWidgetFactory();
86 * Create the widget factory that provides all the createXY() methods for
87 * optional ("special") widgets and the corresponding hasXYWidget()
90 * Reimplemented from YUI.
92 virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
95 * Create the YApplication object that provides global methods.
97 * Reimplemented from YUI.
99 virtual YApplication * createApplication();
104 * Return the global YApplication object as YQApplication.
106 * This will create the Y(Q)Application upon the first call and return a
107 * pointer to the one and only (singleton) Y(Q)Application upon each
108 * subsequent call. This may throw exceptions if the Y(Q)Application
111 static YQApplication * yqApp();
114 * Widget event handlers (slots) call this when an event occured that
115 * should be the answer to a UserInput() / PollInput() (etc.) call.
117 * The UI assumes ownership of the event object that 'event' points to.
118 * In particular, it takes care to delete that object.
120 * It is an error to pass 0 for 'event'.
122 void sendEvent( YEvent * event );
125 * Returns 'true' if there is any event pending for the specified widget.
127 bool eventPendingFor( YWidget * widget ) const
128 { return _event_handler.eventPendingFor( widget ); }
131 * Returns the last event that isn't processed yet or 0 if there is none.
133 * The Qt UI keeps track of only one single (the last one) event.
135 YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
138 * Return 'true' if defaultsize windows should use the full screen.
140 bool fullscreen() const { return _fullscreen; }
143 * Return 'true' if defaultsize windows should not get window manager
146 bool noBorder() const { return _noborder; }
148 * Returns 'true' if the UI had a fatal error that requires the application
151 bool fatalError() const { return _fatal_error; }
154 * Raise a fatal UI error. It will be delivered when it is safe to do so.
155 * The caller should make sure it can continue for some time until the
156 * error is delivered.
158 void raiseFatalError() { _fatal_error = true; }
161 * Returns size for `opt(`defaultsize) dialogs (in one dimension).
163 int defaultSize( YUIDimension dim ) const;
166 * Make a screen shot in .png format and save it to 'filename'.
167 * Opens a file selection box if 'filename' is empty.
169 void makeScreenShot( string filename );
172 * UI-specific runPkgSeleciton method: Start the package selection.
173 * This implementation does the same as UserInput().
175 * Reimplemented from YUI.
177 YCPValue runPkgSelection( YWidget * packageSelector );
180 * Toggle macro recording (activated by Ctrl-Shift-Alt-M):
181 * Stop macro recording if it is in progress,
182 * open a file selection box and ask for a macro file name to save to and
183 * start recording if no recording has been in progress.
185 void toggleRecordMacro();
188 * Open file selection box and ask for a macro file to play
189 * (activated by Ctrl-Shift-Alt-P)
194 * Issue an internal error: Open popup with that message and wait.
196 * Reimplemented from YUI.
198 void internalError( const char * msg );
201 * Block (or unblock) events. If events are blocked, any event sent
202 * should be ignored until events are unblocked again.
204 * Reimplemented from YUI.
206 virtual void blockEvents( bool block = true );
209 * Returns 'true' if events are currently blocked.
211 * Reimplemented from YUI.
213 virtual bool eventsBlocked() const;
216 * Returns the current product name
217 * ("SuSE Linux", "SuSE Linux Enterprise Server", "United Linux", etc.)
220 QString productName() const;
223 * Beep - activate the system (X11) bell.
225 * Reimplemented from YUI.
230 * Show pointer cursor.
232 * Reimplemented from YUI.
237 * Open file selection box and let the user Save y2logs to that location.
243 * Open dialog to configure logging.
246 void askConfigureLogging();
249 * A mouse click with the wrong mouse button was detected - e.g., a right
250 * click on a push button. The user might be left-handed, but his mouse
251 * might not (yet) be configured for left-handed use - e.g., during
252 * installation. Ask him if he would like his mouse temporarily configured
253 * as a left-handed mouse.
255 * This status can be queried with UI::GetDisplayInfo() ("LeftHandedMouse").
257 void maybeLeftHandedUser();
263 * Idle around until fd_ycp is readable and handle repaints.
264 * This is only used when a separate ui thread is running.
266 * Reimplemented from YUI.
268 void idleLoop( int fd_ycp );
271 * Return a representation for the glyph symbol specified in UTF-8 encoding
272 * or an empty string to get a default textual representation.
274 * Reimplemented from YUI.
276 YCPString glyph( const YCPSymbol & glyphSymbol );
279 * Go into event loop until next user input is available.
281 * Reimplemented from YUI.
283 YEvent * userInput( unsigned long timeout_millisec = 0 );
286 * Check the event queue for user input. Don't wait.
288 * Reimplemented from YUI.
290 YEvent * pollInput();
293 * Show and activate a dialog.
295 * Reimplemented from YUI.
297 void showDialog( YDialog * dialog );
300 * Decativate and close a dialog. This does not delete the dialog yet.
302 * Reimplemented from YUI.
304 void closeDialog( YDialog * dialog );
310 * Initialize and set a textdomain for gettext()
312 static void setTextdomain( const char * domain );
315 * Returns a high-contrast color palette suitable for vision impaired users.
317 static QPalette visionImpairedPalette();
320 * Returns the normal color palette
322 QPalette normalPalette() const { return _normalPalette; }
325 * Toggle between the vision impaired and the normal color palette.
327 void toggleVisionImpairedPalette();
330 * Returns 'true' if high-contrast colors for vision impaired users is in use.
331 * This should be queried at other places before using custom colors.
333 bool usingVisionImpairedPalette() const { return _usingVisionImpairedPalette; }
336 * Convert logical layout spacing units into device dependent units.
337 * A default size dialog is assumed to be 80x25 layout spacing units
338 * and 640x480 device dependent spacing units.
340 * Reimplemented from YUI.
342 virtual int deviceUnits( YUIDimension dim, float layout_units );
345 * Convert device dependent units into logical layout spacing units.
346 * A default size dialog is assumed to be 80x25 layout spacing units
347 * and 640x480 device dependent spacing units.
349 * Reimplemented from YUI.
351 virtual float layoutUnits( YUIDimension dim, int device_units );
354 * Returns the package selector plugin singleton of this UI or creates it
355 * (including loading the plugin lib) if it does not exist yet.
357 YQPackageSelectorPlugin * packageSelectorPlugin();
360 * Show hourglass cursor.
362 * Reimplemented from YUI.
364 virtual void busyCursor();
369 * Display capabilities.
370 * [Reimplemented from YUI]
371 * See UI builtin GetDisplayInfo() doc for details.
373 int getDisplayWidth();
374 int getDisplayHeight();
375 int getDisplayDepth();
376 long getDisplayColors();
377 int getDefaultWidth();
378 int getDefaultHeight();
379 bool textMode() { return false; }
380 bool hasImageSupport() { return true; }
381 bool hasLocalImageSupport() { return true; }
382 bool hasAnimationSupport() { return true; }
383 bool hasIconSupport() { return false; } // not yet
384 bool hasFullUtf8Support() { return true; }
385 bool richTextSupportsTable() { return true; }
386 bool leftHandedMouse() { return _leftHandedMouse; }
389 QMap<QString, int> screenShotNo;
390 QString screenShotNameTemplate;
393 * Application shutdown
400 * Handle command line args
402 void processCommandLineArgs( int argc, char **argv );
405 * Calculate size of `opt(`defaultsize) dialogs
407 void calcDefaultSize();
412 * Timeout during TimeoutUserInput() / WaitForEvent()
414 void userInputTimeout();
416 void leaveIdleLoop();
423 * Use the entire available screen
428 * No window border for the main window
433 * Container for the widget stack. QWidgetStack cannot handle a WFlags
434 * argument, so this needs to be embedded into something else - and a QVBox
435 * at least handles all the sizeHint and resize stuff.
440 * Size for `opt(`defaultsize) dialogs.
445 * This flag is set during @ref #userInput in order to tell
446 * @ref #returnNow to call exit_loop, which only may be called
451 bool _leave_idle_loop;
454 * Event loop object. Required since a YaST2 UI needs to react to commands
455 * from the YCP command stream as well as to X11 / Qt events.
457 QEventLoop * _eventLoop;
460 * Global reference to the UI
465 * Indicate a fatal error that requires the UI to terminate
470 * Timer for TimeoutUserInput() / WaitForEvent().
472 QTimer *_user_input_timer;
475 * Timer for delayed busy cursor
477 QTimer *_busy_cursor_timer;
480 * The handler for the single pending event this UI keeps track of
482 YSimpleEventHandler _event_handler;
487 * Saved normal palette
489 QPalette _normalPalette;
492 * Flag: currently using special palette for vision impaired users?
494 bool _usingVisionImpairedPalette;
497 * Flag: Does the user want to use a left-handed mouse?
499 bool _leftHandedMouse;
502 * Flag: Was the user already asked if he wants to use a left-handed mouse?
504 bool _askedForLeftHandedMouse;
511 * Reads the style sheet, parses some comments and passes it to qapp
518 class YQUI_Ui : public QObject
528 * Show hourglass cursor.
530 * Reimplemented from YUI.
532 void slotBusyCursor();
535 * Timeout during TimeoutUserInput() / WaitForEvent()
537 void slotUserInputTimeout();
539 void slotLeaveIdleLoop();