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