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