libyui-qt  2.46.1
 All Classes Functions Variables
YQUI.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQUI.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YQUI_h
26 #define YQUI_h
27 
28 #include <qapplication.h>
29 #include <QMap>
30 #include <QTimer>
31 #include <QPalette>
32 #include <vector>
33 #include <type_traits>
34 
35 #include <yui/YUI.h>
36 #include <yui/YSimpleEventHandler.h>
37 #include <yui/YCommandLine.h>
38 
39 #define YQWidgetMargin 4
40 #define YQWidgetSpacing 4
41 #define YQButtonBorder 3
42 
43 //! The class of a pointer expression.
44 // To be used in connect(foo, &pclass(foo)::mysignal, bar, &pclass(bar)::myslot);
45 // That checks types at compile time,
46 // unlike the string based SIGNAL and SLOT macros.
47 #define pclass(ptr) std::remove_reference<decltype(*ptr)>::type
48 
49 
50 class QCursor;
51 class QFrame;
52 class QStackedWidget;
53 class YEvent;
55 class YQWidgetFactory;
56 class YQApplication;
57 class YQUISignalReceiver;
58 
59 using std::string;
60 using std::vector;
61 
62 class YQUI: public YUI
63 {
64  friend class YQUISignalReceiver;
65 
66 public:
67 
68  /**
69  * Constructor.
70  **/
71  YQUI( bool withThreads );
72 
73  /**
74  * Destructor.
75  **/
76  virtual ~YQUI();
77 
78  /**
79  * Access the global Qt-UI.
80  **/
81  static YQUI * ui() { return _ui; }
82 
83  /**
84  * Post-constructor initialization. If running with threads, this has to be
85  * called in the UI thread. Any subsequent calls will do nothing.
86  **/
87  void initUI();
88 
89 protected:
90  /**
91  * Create the widget factory that provides all the createXY() methods for
92  * standard (mandatory, i.e. non-optional) widgets.
93  *
94  * Reimplemented from YUI.
95  **/
96  virtual YWidgetFactory * createWidgetFactory();
97 
98  /**
99  * Create the widget factory that provides all the createXY() methods for
100  * optional ("special") widgets and the corresponding hasXYWidget()
101  * methods.
102  *
103  * Reimplemented from YUI.
104  **/
105  virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
106 
107  /*
108  * Create the YApplication object that provides global methods.
109  *
110  * Reimplemented from YUI.
111  **/
112  virtual YApplication * createApplication();
113 
114 public:
115 
116  /**
117  * Return the global YApplication object as YQApplication.
118  *
119  * This will create the Y(Q)Application upon the first call and return a
120  * pointer to the one and only (singleton) Y(Q)Application upon each
121  * subsequent call. This may throw exceptions if the Y(Q)Application
122  * cannot be created.
123  **/
124  static YQApplication * yqApp();
125 
126  /**
127  * Widget event handlers (slots) call this when an event occured that
128  * should be the answer to a UserInput() / PollInput() (etc.) call.
129  *
130  * The UI assumes ownership of the event object that 'event' points to.
131  * In particular, it takes care to delete that object.
132  *
133  * It is an error to pass 0 for 'event'.
134  **/
135  void sendEvent( YEvent * event );
136 
137  /**
138  * Returns 'true' if there is any event pending for the specified widget.
139  **/
140  bool eventPendingFor( YWidget * widget ) const
141  { return _eventHandler.eventPendingFor( widget ); }
142 
143  /**
144  * Returns the last event that isn't processed yet or 0 if there is none.
145  *
146  * The Qt UI keeps track of only one single (the last one) event.
147  **/
148  YEvent * pendingEvent() const { return _eventHandler.pendingEvent(); }
149 
150  /**
151  * Return the pending event, if there is one, and mark it as "consumed".
152  *
153  * This returns 0 if there is no pending event.
154  **/
155  YEvent * consumePendingEvent() { return _eventHandler.consumePendingEvent(); }
156 
157  /**
158  * Notification that a widget is being deleted.
159  *
160  * Reimplemented from YUI.
161  **/
162  virtual void deleteNotify( YWidget * widget );
163 
164  /**
165  * Return 'true' if defaultsize windows should use the full screen.
166  **/
167  bool fullscreen() const { return _fullscreen; }
168 
169  /**
170  * Return 'true' if defaultsize windows should not get window manager
171  * borders / frames.
172  **/
173  bool noBorder() const { return _noborder; }
174  /**
175  * Returns 'true' if the UI had a fatal error that requires the application
176  * to abort.
177  **/
178  bool fatalError() const { return _fatalError; }
179 
180  /**
181  * Raise a fatal UI error. It will be delivered when it is safe to do so.
182  * The caller should make sure it can continue for some time until the
183  * error is delivered.
184  **/
185  void raiseFatalError() { _fatalError = true; }
186 
187  /**
188  * Returns size for `opt(`defaultsize) dialogs (in one dimension).
189  **/
190  int defaultSize( YUIDimension dim ) const;
191 
192  /**
193  * Make a screen shot in .png format and save it to 'filename'.
194  * Opens a file selection box if 'filename' is empty.
195  **/
196  void makeScreenShot( std::string filename );
197 
198  /**
199  * UI-specific runPkgSeleciton method: Start the package selection.
200  * This implementation does the same as UserInput().
201  *
202  * Reimplemented from YUI.
203  **/
204  virtual YEvent * runPkgSelection( YWidget * packageSelector );
205 
206  /**
207  * Toggle macro recording (activated by Ctrl-Shift-Alt-M):
208  * Stop macro recording if it is in progress,
209  * open a file selection box and ask for a macro file name to save to and
210  * start recording if no recording has been in progress.
211  **/
212  void toggleRecordMacro();
213 
214  /**
215  * Open file selection box and ask for a macro file to play
216  * (activated by Ctrl-Shift-Alt-P)
217  **/
218  void askPlayMacro();
219 
220  /**
221  * Block (or unblock) events. If events are blocked, any event sent
222  * should be ignored until events are unblocked again.
223  *
224  * Reimplemented from YUI.
225  **/
226  virtual void blockEvents( bool block = true );
227 
228  /**
229  * Returns 'true' if events are currently blocked.
230  *
231  * Reimplemented from YUI.
232  **/
233  virtual bool eventsBlocked() const;
234 
235  /**
236  * Force unblocking all events, no matter how many times blockEvents() has
237  * This returns 0 if there is no pending eventbeen called before.
238  **/
239  void forceUnblockEvents();
240 
241  /**
242  * Show mouse cursor indicating busy state.
243  **/
244  void busyCursor();
245 
246  /**
247  * Show normal mouse cursor not indicating busy status.
248  **/
249  void normalCursor();
250 
251  /**
252  * Show mouse cursor indicating busy state if the UI is unable to respond
253  * to user input for more than a predefined timeout (200 millisec).
254  **/
255  void timeoutBusyCursor();
256 
257  /**
258  * Open file selection box and let the user save y2logs to that location.
259  * (Shift-F8)
260  **/
261  void askSaveLogs();
262 
263  /**
264  * Open dialog to configure logging.
265  * (Shift-F7)
266  **/
267  void askConfigureLogging();
268 
269  /**
270  * Initialize and set a textdomain for gettext()
271  **/
272  static void setTextdomain( const char * domain );
273 
274  /**
275  * Returns a high-contrast color palette suitable for vision impaired users.
276  **/
277  static QPalette visionImpairedPalette();
278 
279  /**
280  * Returns the normal color palette
281  **/
282  QPalette normalPalette() const { return _normalPalette; }
283 
284  /**
285  * Toggle between the vision impaired and the normal color palette.
286  **/
288 
289  /**
290  * Returns 'true' if high-contrast colors for vision impaired users is in use.
291  * This should be queried at other places before using custom colors.
292  **/
293  bool usingVisionImpairedPalette() const { return _usingVisionImpairedPalette; }
294 
295  /**
296  * Returns the application name for the window title (e.g. "YaST2@hostname")
297  **/
298  QString applicationTitle() { return _applicationTitle; }
299 
300  /**
301  * Sets the application name for the window title
302  **/
303  void setApplicationTitle(const QString& title) { _applicationTitle=title; }
304 
305 protected:
306 
307  /**
308  * Handle command line args
309  **/
310  void processCommandLineArgs( int argc, char **argv );
311 
312  /**
313  * Probe the X11 display. Throw exception upon failure.
314  * A "-display" command line argument is taken into account.
315  **/
316  void probeX11Display( const YCommandLine & cmdLine );
317 
318  /**
319  * Calculate size of `opt(`defaultsize) dialogs
320  **/
321  void calcDefaultSize();
322 
323  /**
324  * Idle around until fd_ycp is readable and handle repaints.
325  * This is only used when a separate ui thread is running.
326  *
327  * Reimplemented from YUI.
328  **/
329  virtual void idleLoop( int fd_ycp );
330 
331  /**
332  * Notification that a YCP command has been received on fd_ycp
333  * to leave idleLoop()
334  **/
335  void receivedYCPCommand();
336 
337  /**
338  * Application shutdown
339  **/
340  bool close();
341 
342 
343  //
344  // Data members
345  //
346 
347  static YQUI * _ui;
348 
349  QMap<QString, int> screenShotNo;
350  QString screenShotNameTemplate;
351 
352  bool _fullscreen;
353  bool _noborder;
354  QSize _defaultSize;
355 
356  bool _do_exit_loop;
357  bool _received_ycp_command;
358  bool _fatalError;
359 
360  QTimer * _busyCursorTimer;
361 
362  YSimpleEventHandler _eventHandler;
363  int _blockedLevel;
364 
365  QPalette _normalPalette;
366  bool _usingVisionImpairedPalette;
367 
368  bool _leftHandedMouse;
369  bool _askedForLeftHandedMouse;
370 
371  bool _uiInitialized;
372 
373  YQUISignalReceiver * _signalReceiver;
374  QString _applicationTitle;
375 
376  // Qt copies the _reference_ to argc, so we need to store argc
377  int _ui_argc;
378 };
379 
380 
381 /**
382  * Helper class that acts as a Qt signal receiver for YQUI.
383  * YQUI itself cannot be a QObject to avoid problems with starting up the UI
384  * with multiple threads.
385  **/
386 class YQUISignalReceiver : public QObject
387 {
388  Q_OBJECT
389 
390 public:
392 
393 public slots:
394 
395  void slotBusyCursor();
396  void slotReceivedYCPCommand();
397 };
398 
399 
400 /**
401  * Create a new UI if there is none yet or return the existing one if there is.
402  *
403  * This is the UI plugin's interface to the outside world, so don't change the
404  * name or signature!
405  **/
406 YUI * createUI( bool withThreads );
407 
408 
409 #endif // YQUI_h
bool fullscreen() const
Definition: YQUI.h:167
void receivedYCPCommand()
Definition: YQUI.cc:471
static YQApplication * yqApp()
Definition: YQUI.cc:284
void askConfigureLogging()
void forceUnblockEvents()
Definition: YQUI.cc:545
bool eventPendingFor(YWidget *widget) const
Definition: YQUI.h:140
void setApplicationTitle(const QString &title)
Definition: YQUI.h:303
int defaultSize(YUIDimension dim) const
Definition: YQUI.cc:584
void makeScreenShot(std::string filename)
void askSaveLogs()
virtual YEvent * runPkgSelection(YWidget *packageSelector)
void toggleRecordMacro()
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()
Definition: YQUI.cc:370
QString applicationTitle()
Definition: YQUI.h:298
void calcDefaultSize()
Definition: YQUI.cc:389
bool usingVisionImpairedPalette() const
Definition: YQUI.h:293
void sendEvent(YEvent *event)
Definition: YQUI.cc:477
YQUI(bool withThreads)
Definition: YQUI.cc:92
virtual void idleLoop(int fd_ycp)
Definition: YQUI.cc:438
void probeX11Display(const YCommandLine &cmdLine)
Definition: YQUI.cc:590
virtual bool eventsBlocked() const
Definition: YQUI.cc:553
bool noBorder() const
Definition: YQUI.h:173
virtual void deleteNotify(YWidget *widget)
Definition: YQUI.cc:617
void busyCursor()
Definition: YQUI.cc:559
Definition: YQUI.h:62
void processCommandLineArgs(int argc, char **argv)
Definition: YQUI.cc:290
static QPalette visionImpairedPalette()
Definition: YQUI.cc:641
YEvent * consumePendingEvent()
Definition: YQUI.h:155
QPalette normalPalette() const
Definition: YQUI.h:282
virtual void blockEvents(bool block=true)
Definition: YQUI.cc:511
void timeoutBusyCursor()
Definition: YQUI.cc:575
bool fatalError() const
Definition: YQUI.h:178
bool close()
Definition: YQUI.cc:677
void normalCursor()
Definition: YQUI.cc:565
void initUI()
Definition: YQUI.cc:119
YEvent * pendingEvent() const
Definition: YQUI.h:148
void askPlayMacro()
virtual ~YQUI()
Definition: YQUI.cc:340
void raiseFatalError()
Definition: YQUI.h:185
static void setTextdomain(const char *domain)
Definition: YQUI.cc:497
void toggleVisionImpairedPalette()
Definition: YQUI.cc:623
static YQUI * ui()
Definition: YQUI.h:81
virtual YWidgetFactory * createWidgetFactory()
Definition: YQUI.cc:359