]> icculus.org git repositories - duncan/yast2-web-wt.git/blob - src/YWebUI.h
- move the UICOmponent functions to its own fle
[duncan/yast2-web-wt.git] / src / YWebUI.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YWebUI.h
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16                 Stanislav Visnovsky <visnov@suse.cz>
17
18 /-*/
19
20 #ifndef YWebUI_h
21 #define YWebUI_h
22
23 #include "YSimpleEventHandler.h"
24 #include <YUI.h>
25
26 #include <WApplication>
27 #include <WEnvironment>
28
29 class YEvent;
30 class YWebOptionalWidgetFactory;
31 class YWebWidgetFactory;
32
33 using std::string;
34 using std::vector;
35
36
37 Wt::WApplication *createApplication(const Wt::WEnvironment& env);
38 void *start_webserver_thread( void * yui );
39
40 class YWebUI: public Wt::WApplication, public YUI
41 {
42 public:
43
44     /**
45      * Constructor.
46      **/
47     YWebUI( const Wt::WEnvironment& env,
48           const char *  macro_file );
49
50     /**
51      * Destructor.
52      **/
53     ~YWebUI();
54
55     /**
56      * Access the global Qt-UI.
57      **/
58     static YWebUI * ui() { return _ui; }
59
60
61 protected:
62     /**
63      * Create the widget factory that provides all the createXY() methods for
64      * standard (mandatory, i.e. non-optional) widgets.
65      *
66      * Reimplemented from YUI.
67      **/
68     virtual YWidgetFactory * createWidgetFactory();
69
70     /**
71      * Create the widget factory that provides all the createXY() methods for
72      * optional ("special") widgets and the corresponding hasXYWidget()
73      * methods.
74      *
75      * Reimplemented from YUI.
76      **/
77     virtual YOptionalWidgetFactory * createOptionalWidgetFactory();
78
79     /*
80      * Create the YApplication object that provides global methods.
81      *
82      * Reimplemented from YUI.
83      **/
84     virtual YApplication * createApplication();
85
86 public:
87
88     /**
89      * Widget event handlers (slots) call this when an event occured that
90      * should be the answer to a UserInput() / PollInput() (etc.) call.
91      *
92      * The UI assumes ownership of the event object that 'event' points to.
93      * In particular, it takes care to delete that object.
94      *
95      * It is an error to pass 0 for 'event'.
96      **/
97     void sendEvent( YEvent * event );
98
99     /**
100      * Returns 'true' if there is any event pending for the specified widget.
101      **/
102     bool eventPendingFor( YWidget * widget ) const
103         { return _event_handler.eventPendingFor( widget ); }
104
105     /**
106      * Returns the last event that isn't processed yet or 0 if there is none.
107      *
108      * The Qt UI keeps track of only one single (the last one) event.
109      **/
110     YEvent * pendingEvent() const { return _event_handler.pendingEvent(); }
111
112     /**
113      * Returns 'true' if the UI had a fatal error that requires the application
114      * to abort.
115      **/
116     bool fatalError() const { return _fatal_error; }
117
118     /**
119      * Raise a fatal UI error. It will be delivered when it is safe to do so.
120      * The caller should make sure it can continue for some time until the
121      * error is delivered.
122      **/
123     void raiseFatalError() { _fatal_error = true; }
124
125     /**
126      * UI-specific runPkgSeleciton method: Start the package selection.
127      * This implementation does the same as UserInput().
128      *
129      * Reimplemented from YUI.
130      **/
131     YCPValue runPkgSelection( YWidget * packageSelector );
132
133     /**
134      * Issue an internal error: Open popup with that message and wait.
135      *
136      * Reimplemented from YUI.
137      **/
138     void internalError( const char * msg );
139
140
141     /**
142      * Block (or unblock) events. If events are blocked, any event sent
143      * should be ignored until events are unblocked again.
144      *
145      * Reimplemented from YUI.
146      **/
147     virtual void blockEvents( bool block = true )
148         { _event_handler.blockEvents( block ); }
149
150     /**
151      * Returns 'true' if events are currently blocked.
152      *
153      * Reimplemented from YUI.
154      **/
155     virtual bool eventsBlocked() const
156         { return _event_handler.eventsBlocked(); }
157
158 protected:
159
160     /**
161      * Idle around until fd_ycp is readable and handle repaints.
162      * This is only used when a separate ui thread is running.
163      *
164      * Reimplemented from YUI.
165      **/
166     void idleLoop( int fd_ycp );
167
168     /**
169      * Return a representation for the glyph symbol specified in UTF-8 encoding
170      * or an empty string to get a default textual representation.
171      *
172      * Reimplemented from YUI.
173      **/
174     YCPString glyph( const YCPSymbol & glyphSymbol );
175
176     /**
177      * Go into event loop until next user input is available.
178      *
179      * Reimplemented from YUI.
180      **/
181     YEvent * userInput( unsigned long timeout_millisec = 0 );
182
183     /**
184      * Check the event queue for user input. Don't wait.
185      *
186      * Reimplemented from YUI.
187      **/
188     YEvent * pollInput();
189
190     /**
191      * Create a dialog.
192      *
193      * Reimplemented from YUI.
194      **/
195     YDialog * createDialog( YWidgetOpt & opt );
196
197     /**
198      * Show and activate a dialog.
199      *
200      * Reimplemented from YUI.
201      **/
202     void showDialog( YDialog * dialog );
203
204     /**
205      * Decativate and close a dialog. This does not delete the dialog yet.
206      *
207      * Reimplemented from YUI.
208      **/
209     void closeDialog( YDialog * dialog );
210
211     /*** Widget creation methods for optional widgets, all reimplemented from YUI ***/
212
213     bool        hasBarGraph();
214     YWidget *   createBarGraph          ( YWidget * parent, YWidgetOpt & opt);
215
216
217     bool        hasDownloadProgress();
218     YWidget *   createDownloadProgress  ( YWidget *             parent,
219                                           YWidgetOpt &          opt,
220                                           const YCPString &     label,
221                                           const YCPString &     filename,
222                                           int                   expectedSize );
223
224     bool        hasDumbTab();
225     YWidget *   createDumbTab           ( YWidget *             parent,
226                                           YWidgetOpt &          opt );
227
228     bool        hasSlider();
229     YWidget *   createSlider            ( YWidget *             parent,
230                                           YWidgetOpt &          opt,
231                                           const YCPString &     label,
232                                           int                   minValue,
233                                           int                   maxValue,
234                                           int                   initialValue );
235
236     bool        hasPartitionSplitter();
237     YWidget *   createPartitionSplitter( YWidget *              parent,
238                                          YWidgetOpt &           opt,
239                                          int                    usedSize,
240                                          int                    totalFreeSize,
241                                          int                    newPartSize,
242                                          int                    minNewPartSize,
243                                          int                    minFreeSize,
244                                          const YCPString &      usedLabel,
245                                          const YCPString &      freeLabel,
246                                          const YCPString &      newPartLabel,
247                                          const YCPString &      freeFieldLabel,
248                                          const YCPString &      newPartFieldLabel );
249
250
251     /*** END widget creation methods ***/
252
253
254 public:
255
256     /**
257      *
258      * Open a directory selection box and prompt the user for an existing directory.
259      * [Reimplemented from YUI]
260      *
261      * 'startDir' is the initial directory that is displayed.
262      *
263      * 'headline' is an explanatory text for the directory selection box.
264      * Graphical UIs may omit that if no window manager is running.
265      *
266      * Returns the selected directory name
267      * or 'nil' (YCPVoid() ) if the user canceled the operation.
268      **/
269     YCPValue askForExistingDirectory ( const YCPString & startDir,
270                                        const YCPString & headline );
271
272     /**
273      * Open a file selection box and prompt the user for an existing file.
274      * [Reimplemented from YUI]
275      *
276      * 'startWith' is the initial directory or file.
277      *
278      * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
279      *
280      * 'headline' is an explanatory text for the file selection box.
281      * Graphical UIs may omit that if no window manager is running.
282      *
283      * Returns the selected file name
284      * or 'nil' (YCPVoid() ) if the user canceled the operation.
285      **/
286     YCPValue askForExistingFile ( const YCPString & startWith,
287                                   const YCPString & filter,
288                                   const YCPString & headline );
289
290     /**
291      * Open a file selection box and prompt the user for a file to save data to.
292      * Automatically asks for confirmation if the user selects an existing file.
293      * [Reimplemented from YUI]
294      *
295      * 'startWith' is the initial directory or file.
296      *
297      * 'filter' is one or more blank-separated file patterns, e.g. "*.png *.jpg"
298      *
299      * 'headline' is an explanatory text for the file selection box.
300      * Graphical UIs may omit that if no window manager is running.
301      *
302      * Returns the selected file name
303      * or 'nil' (YCPVoid() ) if the user canceled the operation.
304      **/
305     YCPValue askForSaveFileName ( const YCPString & startWith,
306                                   const YCPString & filter,
307                                   const YCPString & headline );
308
309     /**
310      * Lower-level version that works with QStrings and does not change
311      * the mouse cursor.
312      **/
313     string askForSaveFileName(  const string & startWith,
314                                 const string & filter,
315                                 const string & headline );
316
317 protected:
318
319     /**
320      * Display capabilities.
321      * [Reimplemented from YUI]
322      * See UI builtin GetDisplayInfo() doc for details.
323      **/
324     bool textMode()                     { return false; }
325     bool hasImageSupport()              { return true;  }
326     bool hasLocalImageSupport()         { return false; }
327     bool hasAnimationSupport()          { return true;  }
328     bool hasIconSupport()               { return false; }       // not yet
329     bool hasFullUtf8Support()           { return true;  }
330     bool richTextSupportsTable()        { return true; }
331
332
333     /**
334      * Sets @ref #leave_idle_loop to true.
335      **/
336     void leaveIdleLoop( int );
337
338
339 protected:
340
341     /**
342      * Handle command line args
343      **/
344     void processCommandLineArgs( int argc, char **argv );
345
346     /**
347      * Calculate size of `opt(`defaultsize) dialogs
348      **/
349     void calcDefaultSize();
350
351
352     //
353     // Data members
354     //
355
356     /**
357      * Stack to keep track of the stacking order of popup dialogs.
358      **/
359     // FIXME: vector<QWidget *> _popup_stack;
360
361     /**
362      * Numeric ID for defaultsize dialogs for the widget stack
363      **/
364     int _main_dialog_id;
365
366     /**
367      * A flag used during the idle loop. If it is set to true,
368      * the idle loop is left. This happens, if the ycp-ui-communication
369      * pipe to the ui gets readable.
370      **/
371     bool _leave_idle_loop;
372
373     /**
374      * This flag is set during @ref #userInput in order to tell
375      * @ref #returnNow to call exit_loop, which only may be called
376      * after enter_loop.
377      **/
378     bool _do_exit_loop;
379
380
381     /**
382      * Global reference to the UI
383      **/
384     static YWebUI * _ui;
385
386     /**
387      * Indicate a fatal error that requires the UI to terminate
388      **/
389     bool _fatal_error;
390
391     /**
392      * The handler for the single pending event this UI keeps track of
393      **/
394     YSimpleEventHandler _event_handler;
395
396 public:
397     static int _argc;
398     static char** _argv;
399 };
400
401
402 #endif // YWebUI_h