libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQUI.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YQUI.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YQUI_h
00026 #define YQUI_h
00027 
00028 #include <qapplication.h>
00029 #include <QMap>
00030 #include <QTimer>
00031 #include <QPalette>
00032 #include <vector>
00033 
00034 #include <yui/YUI.h>
00035 #include <yui/YSimpleEventHandler.h>
00036 #include <yui/YCommandLine.h>
00037 
00038 #define YQWidgetMargin  4
00039 #define YQWidgetSpacing 4
00040 #define YQButtonBorder  3
00041 
00042 class QCursor;
00043 class QFrame;
00044 class QStackedWidget;
00045 class YEvent;
00046 class YQOptionalWidgetFactory;
00047 class YQWidgetFactory;
00048 class YQApplication;
00049 class YQUISignalReceiver;
00050 
00051 using std::string;
00052 using std::vector;
00053 
00054 
00055 class YQUI: public YUI
00056 {
00057     friend class YQUISignalReceiver;
00058 
00059 public:
00060 
00061     /**
00062      * Constructor.
00063      **/
00064     YQUI( bool withThreads );
00065 
00066     /**
00067      * Destructor.
00068      **/
00069     virtual ~YQUI();
00070 
00071     /**
00072      * Access the global Qt-UI.
00073      **/
00074     static YQUI * ui() { return _ui; }
00075 
00076     /**
00077      * Post-constructor initialization. If running with threads, this has to be
00078      * called in the UI thread. Any subsequent calls will do nothing.
00079      **/
00080     void initUI();
00081 
00082 protected:
00083     /**
00084      * Create the widget factory that provides all the createXY() methods for
00085      * standard (mandatory, i.e. non-optional) widgets.
00086      *
00087      * Reimplemented from YUI.
00088      **/
00089     virtual YWidgetFactory * createWidgetFactory();
00090 
00091     /**
00092      * Create the widget factory that provides all the createXY() methods for
00093      * optional ("special") widgets and the corresponding hasXYWidget()
00094      * methods.
00095      *
00096      * Reimplemented from YUI.
00097      **/
00098     virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
00099 
00100     /*
00101      * Create the YApplication object that provides global methods.
00102      *
00103      * Reimplemented from YUI.
00104      **/
00105     virtual YApplication * createApplication();
00106 
00107 public:
00108 
00109     /**
00110      * Return the global YApplication object as YQApplication.
00111      *
00112      * This will create the Y(Q)Application upon the first call and return a
00113      * pointer to the one and only (singleton) Y(Q)Application upon each
00114      * subsequent call.  This may throw exceptions if the Y(Q)Application
00115      * cannot be created.
00116      **/
00117     static YQApplication * yqApp();
00118 
00119     /**
00120      * Widget event handlers (slots) call this when an event occured that
00121      * should be the answer to a UserInput() / PollInput() (etc.) call.
00122      *
00123      * The UI assumes ownership of the event object that 'event' points to.
00124      * In particular, it takes care to delete that object.
00125      *
00126      * It is an error to pass 0 for 'event'.
00127      **/
00128     void sendEvent( YEvent * event );
00129 
00130     /**
00131      * Returns 'true' if there is any event pending for the specified widget.
00132      **/
00133     bool eventPendingFor( YWidget * widget ) const
00134         { return _eventHandler.eventPendingFor( widget ); }
00135 
00136     /**
00137      * Returns the last event that isn't processed yet or 0 if there is none.
00138      *
00139      * The Qt UI keeps track of only one single (the last one) event.
00140      **/
00141     YEvent * pendingEvent() const { return _eventHandler.pendingEvent(); }
00142 
00143     /**
00144      * Return the pending event, if there is one, and mark it as "consumed".
00145      *
00146      * This returns 0 if there is no pending event.
00147      **/
00148     YEvent * consumePendingEvent() { return _eventHandler.consumePendingEvent(); }
00149 
00150     /**
00151      * Notification that a widget is being deleted.
00152      *
00153      * Reimplemented from YUI.
00154      **/
00155     virtual void deleteNotify( YWidget * widget );
00156 
00157     /**
00158      * Return 'true' if defaultsize windows should use the full screen.
00159      **/
00160     bool fullscreen() const { return _fullscreen; }
00161 
00162     /**
00163      * Return 'true' if defaultsize windows should not get window manager
00164      * borders / frames.
00165      **/
00166     bool noBorder() const { return _noborder; }
00167     /**
00168      * Returns 'true' if the UI had a fatal error that requires the application
00169      * to abort.
00170      **/
00171     bool fatalError() const { return _fatalError; }
00172 
00173     /**
00174      * Raise a fatal UI error. It will be delivered when it is safe to do so.
00175      * The caller should make sure it can continue for some time until the
00176      * error is delivered.
00177      **/
00178     void raiseFatalError() { _fatalError = true; }
00179 
00180     /**
00181      * Returns size for `opt(`defaultsize) dialogs (in one dimension).
00182      **/
00183     int defaultSize( YUIDimension dim ) const;
00184 
00185     /**
00186      * Make a screen shot in .png format and save it to 'filename'.
00187      * Opens a file selection box if 'filename' is empty.
00188      **/
00189     void makeScreenShot( std::string filename );
00190 
00191     /**
00192      * UI-specific runPkgSeleciton method: Start the package selection.
00193      * This implementation does the same as UserInput().
00194      *
00195      * Reimplemented from YUI.
00196      **/
00197     virtual YEvent * runPkgSelection( YWidget * packageSelector );
00198 
00199     /**
00200      * Toggle macro recording (activated by Ctrl-Shift-Alt-M):
00201      * Stop macro recording if it is in progress,
00202      * open a file selection box and ask for a macro file name to save to and
00203      * start recording if no recording has been in progress.
00204      **/
00205     void toggleRecordMacro();
00206 
00207     /**
00208      * Open file selection box and ask for a macro file to play
00209      * (activated by Ctrl-Shift-Alt-P)
00210      **/
00211     void askPlayMacro();
00212 
00213     /**
00214      * Block (or unblock) events. If events are blocked, any event sent
00215      * should be ignored until events are unblocked again.
00216      *
00217      * Reimplemented from YUI.
00218      **/
00219     virtual void blockEvents( bool block = true );
00220 
00221     /**
00222      * Returns 'true' if events are currently blocked.
00223      *
00224      * Reimplemented from YUI.
00225      **/
00226     virtual bool eventsBlocked() const;
00227 
00228     /**
00229      * Force unblocking all events, no matter how many times blockEvents() has
00230      * This returns 0 if there is no pending eventbeen called before.
00231      **/
00232     void forceUnblockEvents();
00233 
00234     /**
00235      * Show mouse cursor indicating busy state.
00236      **/
00237     void busyCursor();
00238 
00239     /**
00240      * Show normal mouse cursor not indicating busy status.
00241      **/
00242     void normalCursor();
00243 
00244     /**
00245      * Show mouse cursor indicating busy state if the UI is unable to respond
00246      * to user input for more than a predefined timeout (200 millisec).
00247      **/
00248     void timeoutBusyCursor();
00249 
00250     /**
00251      * Open file selection box and let the user save y2logs to that location.
00252      * (Shift-F8)
00253      **/
00254     void askSaveLogs();
00255 
00256     /**
00257      * Open dialog to configure logging.
00258      * (Shift-F7)
00259      **/
00260     void askConfigureLogging();
00261 
00262     /**
00263      * Initialize and set a textdomain for gettext()
00264      **/
00265     static void setTextdomain( const char * domain );
00266 
00267     /**
00268      * Returns a high-contrast color palette suitable for vision impaired users.
00269      **/
00270     static QPalette visionImpairedPalette();
00271 
00272     /**
00273      * Returns the normal color palette
00274      **/
00275     QPalette normalPalette() const { return _normalPalette; }
00276 
00277     /**
00278      * Toggle between the vision impaired and the normal color palette.
00279      **/
00280     void toggleVisionImpairedPalette();
00281 
00282     /**
00283      * Returns 'true' if high-contrast colors for vision impaired users is in use.
00284      * This should be queried at other places before using custom colors.
00285      **/
00286     bool usingVisionImpairedPalette() const { return _usingVisionImpairedPalette; }
00287 
00288     /**
00289      * Returns the application name for the window title (e.g. "YaST2@hostname")
00290      **/
00291     QString applicationTitle() { return _applicationTitle; }
00292     
00293     /**
00294      * Sets the application name for the window title
00295      **/
00296     void setApplicationTitle(const QString& title) { _applicationTitle=title; }
00297     
00298 protected:
00299 
00300     /**
00301      * Handle command line args
00302      **/
00303     void processCommandLineArgs( int argc, char **argv );
00304 
00305     /**
00306      * Probe the X11 display. Throw exception upon failure.
00307      * A "-display" command line argument is taken into account.
00308      **/
00309     void probeX11Display( const YCommandLine & cmdLine );
00310 
00311     /**
00312      * Calculate size of `opt(`defaultsize) dialogs
00313      **/
00314     void calcDefaultSize();
00315 
00316     /**
00317      * Idle around until fd_ycp is readable and handle repaints.
00318      * This is only used when a separate ui thread is running.
00319      *
00320      * Reimplemented from YUI.
00321      **/
00322     virtual void idleLoop( int fd_ycp );
00323 
00324     /**
00325      * Notification that a YCP command has been received on fd_ycp
00326      * to leave idleLoop()
00327      **/
00328     void receivedYCPCommand();
00329 
00330     /**
00331      * Application shutdown
00332      **/
00333     bool close();
00334 
00335 
00336     //
00337     // Data members
00338     //
00339 
00340     static YQUI *       _ui;
00341 
00342     QMap<QString, int>  screenShotNo;
00343     QString             screenShotNameTemplate;
00344 
00345     bool                _fullscreen;
00346     bool                _noborder;
00347     QSize               _defaultSize;
00348 
00349     bool                _do_exit_loop;
00350     bool                _received_ycp_command;
00351     bool                _fatalError;
00352 
00353     QTimer *            _busyCursorTimer;
00354 
00355     YSimpleEventHandler _eventHandler;
00356     int                 _blockedLevel;
00357 
00358     QPalette            _normalPalette;
00359     bool                _usingVisionImpairedPalette;
00360 
00361     bool                _leftHandedMouse;
00362     bool                _askedForLeftHandedMouse;
00363 
00364     bool                _uiInitialized;
00365 
00366     YQUISignalReceiver * _signalReceiver;
00367     QString             _applicationTitle;
00368 
00369     // Qt copies the _reference_ to argc, so we need to store argc
00370     int _ui_argc;
00371 };
00372 
00373 
00374 /**
00375  * Helper class that acts as a Qt signal receiver for YQUI.
00376  * YQUI itself cannot be a QObject to avoid problems with starting up the UI
00377  * with multiple threads.
00378  **/
00379 class YQUISignalReceiver : public QObject
00380 {
00381     Q_OBJECT
00382 
00383 public:
00384     YQUISignalReceiver();
00385 
00386 public slots:
00387 
00388     void slotBusyCursor();
00389     void slotReceivedYCPCommand();
00390 };
00391 
00392 
00393 /**
00394  * Create a new UI if there is none yet or return the existing one if there is.
00395  *
00396  * This is the UI plugin's interface to the outside world, so don't change the
00397  * name or signature!
00398  **/
00399 YUI * createUI( bool withThreads );
00400 
00401 
00402 #endif // YQUI_h
 All Classes Functions Variables