libyui  3.12.1
YApplication.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: YApplication.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YApplication_h
26 
27 #include <string>
28 #include <map>
29 #include "YUI.h"
30 #include "ImplPtr.h"
31 #include "YMenuItem.h"
32 #include "YIconLoader.h"
33 
34 
35 
36 class YWidget;
37 class YWidgetID;
38 struct YApplicationPrivate;
39 
40 
41 /**
42  * Class for application-wide values and functions.
43  * This is a singleton. Access and create it via the static functions in YUI.
44  **/
46 {
47 protected:
48 
49  friend class YUI;
50  /**
51  * Constructor.
52  *
53  * Use YUI::app() to get the singleton for this class.
54  **/
55  YApplication();
56 
57  /**
58  * Destructor.
59  **/
60  virtual ~YApplication();
61 
62 public:
63 
64  /**
65  * Find a widget in the topmost dialog by its ID.
66  *
67  * If there is no widget with that ID (or no dialog at all), this function
68  * throws a YUIWidgetNotFoundException if 'doThrow' is 'true'. It returns 0
69  * if 'doThrow' is 'false'.
70  **/
71  YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const;
72 
73  /**
74  * Get the base path for icons used by the UI. Selection widgets like
75  * YSelectionBox, YComboBox, etc. or YWizard prepend this to icon
76  * specifications that don't use an absolute path.
77  **/
78  virtual std::string iconBasePath() const;
79 
80  /**
81  * Set the icon base path.
82  **/
83  virtual void setIconBasePath( const std::string & newIconBasePath );
84 
85  /**
86  * Return the icon loader.
87  **/
89 
90  /**
91  * Return the default function key number for a widget with the specified
92  * label or 0 if there is none. Any keyboard shortcuts that may be
93  * contained in 'label' are stripped away before any comparison.
94  *
95  * The basic idea behind this concept is to have an easy default mapping
96  * from buttons etc. with the same semantics to function keys:
97  *
98  * "OK" -> F10
99  * "Accept" -> F10
100  * "Yes" -> F10
101  * "Next" -> F10
102  *
103  * "Cancel" -> F9
104  * "No" -> F9
105  * ...
106  *
107  * This function returns 10 for F10, F for F9 etc.;
108  * 0 means "no function key".
109  **/
110  int defaultFunctionKey( const std::string & label ) const;
111 
112  /**
113  * Add a mapping from the specified label to the specified F-key number.
114  * This is the counterpart to defaultFunctionKey().
115  *
116  * This only affects widgets that are created after this call.
117  **/
118  void setDefaultFunctionKey( const std::string & label, int fkey );
119 
120  /**
121  * Clear all previous label-to-function-key mappings.
122  **/
124 
125  /**
126  * Set language and encoding for the locale environment ($LANG).
127  *
128  * This affects UI-internal translations (e.g. for predefined dialogs like
129  * file selection), encoding and fonts.
130  *
131  * 'language' is the ISO short code ("de_DE", "en_US", ...).
132  *
133  * 'encoding' an (optional) encoding ("utf8", ...) that will be appended if
134  * present.
135  *
136  * Derived classes can overwrite this method, but they should call this
137  * base class method at the beginning of the new implementation.
138  **/
139  virtual void setLanguage( const std::string & language,
140  const std::string & encoding = std::string() );
141 
142  /**
143  * Return the current language from the locale environment ($LANG).
144  * If 'stripEncoding' is true, any encoding (".utf8" etc.) is removed.
145  **/
146  std::string language( bool stripEncoding = false ) const;
147 
148  /**
149  * Return a string for a named glyph:
150  *
151  * YUIGlyph_ArrowLeft
152  * YUIGlyph_ArrowRight
153  * YUIGlyph_ArrowUp
154  * YUIGlyph_ArrowDown
155  * YUIGlyph_CheckMark
156  * YUIGlyph_BulletArrowRight
157  * YUIGlyph_BulletCircle
158  * YUIGlyph_BulletSquare
159  *
160  * Using this is discouraged in new applications.
161  * This method is available for backward compatibility.
162  *
163  * This default implementation returns simple textual representations for
164  * each glyph simbol (e.g., "->" for YUIGlyphArrorRight).
165  *
166  * Derived classes are free to overwrite this. It does not make sense to
167  * call this base class method in a new implementation.
168  **/
169  virtual std::string glyph( const std::string & glyphSymbolName );
170 
171  /**
172  * Open a directory selection box and prompt the user for an existing
173  * directory.
174  *
175  * 'startDir' is the initial directory that is displayed.
176  *
177  * 'headline' is an explanatory text for the directory selection box.
178  * Graphical UIs may omit that if no window manager is running.
179  *
180  * Returns the selected directory name
181  * or an empty string if the user canceled the operation.
182  *
183  * Derived classes are required to implement this.
184  **/
185  virtual std::string askForExistingDirectory( const std::string & startDir,
186  const std::string & headline ) = 0;
187 
188  /**
189  * Open a file selection box and prompt the user for an existing file.
190  *
191  * 'startWith' is the initial directory or file.
192  *
193  * 'filter' is one or more blank-separated file patterns, e.g.
194  * "*.png *.jpg"
195  *
196  * 'headline' is an explanatory text for the file selection box.
197  * Graphical UIs may omit that if no window manager is running.
198  *
199  * Returns the selected file name
200  * or an empty string if the user canceled the operation.
201  *
202  * Derived classes are required to implement this.
203  **/
204  virtual std::string askForExistingFile( const std::string & startWith,
205  const std::string & filter,
206  const std::string & headline ) = 0;
207 
208  /**
209  * Open a file selection box and prompt the user for a file to save data
210  * to. Automatically asks for confirmation if the user selects an existing
211  * file.
212  *
213  * 'startWith' is the initial directory or file.
214  *
215  * 'filter' is one or more blank-separated file patterns, e.g.
216  * "*.png *.jpg"
217  *
218  * 'headline' is an explanatory text for the file selection box.
219  * Graphical UIs may omit that if no window manager is running.
220  *
221  * Returns the selected file name
222  * or an empty string if the user canceled the operation.
223  *
224  * Derived classes are required to implement this.
225  **/
226  virtual std::string askForSaveFileName( const std::string & startWith,
227  const std::string & filter,
228  const std::string & headline ) = 0;
229 
230  /**
231  * Open a context menu for a widget
232  *
233  * 'itemCollection' describes the menu structure
234  *
235  * Returns true on success (otherwise false).
236  *
237  * Derived classes are free to overwrite this.
238  **/
239  virtual bool openContextMenu( const YItemCollection & itemCollection );
240 
241 
242  /**
243  * Set the current product name ("openSUSE", "SLES", ...).
244  * This name will be expanded in help texts when the &product; entity is
245  * used.
246  *
247  * Derived classes can overwrite this method, but they should call this
248  * base class method in the new implementation.
249  **/
250  virtual void setProductName( const std::string & productName );
251 
252  /**
253  * Get the current product name ("openSUSE", "SLES", ...).
254  **/
255  std::string productName() const;
256 
257  /**
258  * Set release notes; map product => text
259  *
260  */
261  void setReleaseNotes( const std::map<std::string,std::string> & relNotes );
262 
263  /**
264  * Get the current release notes map
265  **/
266  std::map<std::string,std::string> releaseNotes() const;
267 
268  /**
269  * Set whether the product logo (in top bar) should be shown
270  */
271  void setShowProductLogo( bool show );
272 
273  /**
274  * Return true if product logo should be shown
275  */
276  bool showProductLogo() const;
277 
278  /**
279  * Convert logical layout spacing units into device dependent units.
280  * A default size dialog is assumed to be 80x25 layout spacing units.
281  *
282  * Derived classes may want to reimplement this method.
283  **/
284  virtual int deviceUnits( YUIDimension dim, float layoutUnits );
285 
286  /**
287  * Convert device dependent units into logical layout spacing units.
288  * A default size dialog is assumed to be 80x25 layout spacing units.
289  *
290  * Derived classes may want to reimplement this method.
291  **/
292  virtual float layoutUnits( YUIDimension dim, int deviceUnits );
293 
294  /**
295  * Set reverse layout for Arabic / Hebrew support.
296  *
297  * Derived classes can overwrite this method, but they should call this
298  * base class method in the new implementation.
299  **/
300  virtual void setReverseLayout( bool reverse );
301 
302  /**
303  * Returns 'true' if widget geometry should be reversed for languages that
304  * have right-to-left writing direction (Arabic, Hebrew).
305  **/
306  bool reverseLayout() const;
307 
308  /**
309  * Change the (mouse) cursor to indicate busy status.
310  * This default implementation does nothing.
311  **/
312  virtual void busyCursor() {}
313 
314  /**
315  * Change the (mouse) cursor back from busy status to normal.
316  * This default implementation does nothing.
317  **/
318  virtual void normalCursor() {}
319 
320  /**
321  * Make a screen shot and save it to the specified file.
322  * This default implementation does nothing.
323  **/
324  virtual void makeScreenShot( const std::string & fileName ) {}
325 
326  /**
327  * Beep.
328  * This default implementation does nothing.
329  **/
330  virtual void beep() {}
331 
332 
333  //
334  // NCurses (text mode) specific
335  //
336 
337  /**
338  * Redraw the screen.
339  * This default implementation does nothing.
340  **/
341  virtual void redrawScreen() {}
342 
343  /**
344  * Initialize the (text) console keyboard.
345  * This default implementation does nothing.
346  **/
347  virtual void initConsoleKeyboard() {}
348 
349  /**
350  * Set the (text) console font according to the current encoding etc.
351  * See the setfont(8) command and the console HowTo for details.
352  *
353  * This default implementation does nothing.
354  **/
355  virtual void setConsoleFont( const std::string & console_magic,
356  const std::string & font,
357  const std::string & screen_map,
358  const std::string & unicode_map,
359  const std::string & language )
360  {}
361 
362  /**
363  * Run a shell command (typically an interactive program using NCurses)
364  * in a terminal (window).
365  *
366  * This is useful for text UIs (e.g., NCurses) that need special
367  * preparation prior to running an NCurses-based application and special
368  * clean-up afterwards.
369  *
370  * This default implementation logs an error and returns -1.
371  **/
372  virtual int runInTerminal( const std::string & command );
373 
374 
375  /// @{
376  /**
377  * To mix TUI (NCurses) with stdio, enclose the UI parts
378  * within openUI/closeUI
379  *
380  * This default implementation does nothing.
381  */
382  virtual void openUI() {}
383  virtual void closeUI() {}
384  /// @}
385 
386  //
387  // Display information.
388  //
389  // Width and height are returned in the the UI's native dimension:
390  // Pixels for graphical UIs, character cells for text UIs.
391  // -1 means "value cannot be obtained" for int functions.
392  //
393  // Derived classes are required to implement these functions.
394  //
395 
396  virtual int displayWidth() = 0;
397  virtual int displayHeight() = 0;
398  virtual int displayDepth() = 0;
399  virtual long displayColors() = 0;
400 
401  // Size of main dialogs
402  virtual int defaultWidth() = 0;
403  virtual int defaultHeight() = 0;
404 
405  //
406  // UI capabilities
407  //
408 
409  virtual bool isTextMode() = 0;
410  virtual bool hasImageSupport() = 0;
411  virtual bool hasIconSupport() = 0;
412  virtual bool hasAnimationSupport() = 0;
413  virtual bool hasFullUtf8Support() = 0;
414  virtual bool richTextSupportsTable() = 0;
415  virtual bool leftHandedMouse() = 0;
416  virtual bool hasWizardDialogSupport() { return false; }
417 
418 
419  /**
420  * Set the application title
421  **/
422  virtual void setApplicationTitle ( const std::string& title );
423 
424  /**
425  * Get the application title
426  *
427  * Default title is the running command (argv[0])
428  **/
429  virtual const std::string& applicationTitle() const;
430 
431  /**
432  * Set the application Icon
433  **/
434  virtual void setApplicationIcon ( const std::string& icon );
435 
436  /**
437  * Get the application Icon
438  *
439  * Default icon is an empty string
440  **/
441  virtual const std::string& applicationIcon() const;
442 
443 private:
444 
446 
447 };
448 
449 #define YApplication_h
450 
451 #endif // YApplication_h
YApplication::beep
virtual void beep()
Beep.
Definition: YApplication.h:330
YApplication::setConsoleFont
virtual void setConsoleFont(const std::string &console_magic, const std::string &font, const std::string &screen_map, const std::string &unicode_map, const std::string &language)
Set the (text) console font according to the current encoding etc.
Definition: YApplication.h:355
YApplication::layoutUnits
virtual float layoutUnits(YUIDimension dim, int deviceUnits)
Convert device dependent units into logical layout spacing units.
Definition: YApplication.cc:269
YApplication::initConsoleKeyboard
virtual void initConsoleKeyboard()
Initialize the (text) console keyboard.
Definition: YApplication.h:347
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:55
YApplication::applicationIcon
virtual const std::string & applicationIcon() const
Get the application Icon.
Definition: YApplication.cc:297
YApplication::openUI
virtual void openUI()
To mix TUI (NCurses) with stdio, enclose the UI parts within openUI/closeUI.
Definition: YApplication.h:382
YApplication::setReleaseNotes
void setReleaseNotes(const std::map< std::string, std::string > &relNotes)
Set release notes; map product => text.
Definition: YApplication.cc:126
YApplication::setReverseLayout
virtual void setReverseLayout(bool reverse)
Set reverse layout for Arabic / Hebrew support.
Definition: YApplication.cc:150
YItemCollection
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Definition: YItem.h:39
YApplication::~YApplication
virtual ~YApplication()
Destructor.
Definition: YApplication.cc:75
YApplicationPrivate
Definition: YApplication.cc:46
YApplication::busyCursor
virtual void busyCursor()
Change the (mouse) cursor to indicate busy status.
Definition: YApplication.h:312
YUI
Abstract base class of a libYUI user interface.
Definition: YUI.h:49
YApplication::normalCursor
virtual void normalCursor()
Change the (mouse) cursor back from busy status to normal.
Definition: YApplication.h:318
YApplication::productName
std::string productName() const
Get the current product name ("openSUSE", "SLES", ...).
Definition: YApplication.cc:120
YApplication::findWidget
YWidget * findWidget(YWidgetID *id, bool doThrow=true) const
Find a widget in the topmost dialog by its ID.
Definition: YApplication.cc:82
YApplication::makeScreenShot
virtual void makeScreenShot(const std::string &fileName)
Make a screen shot and save it to the specified file.
Definition: YApplication.h:324
YApplication::iconLoader
YIconLoader * iconLoader()
Return the icon loader.
Definition: YApplication.cc:107
YApplication::setLanguage
virtual void setLanguage(const std::string &language, const std::string &encoding=std::string())
Set language and encoding for the locale environment ($LANG).
Definition: YApplication.cc:193
YApplication::YApplication
YApplication()
Constructor.
Definition: YApplication.cc:64
YApplication::releaseNotes
std::map< std::string, std::string > releaseNotes() const
Get the current release notes map.
Definition: YApplication.cc:132
YApplication::language
std::string language(bool stripEncoding=false) const
Return the current language from the locale environment ($LANG).
Definition: YApplication.cc:211
YApplication::glyph
virtual std::string glyph(const std::string &glyphSymbolName)
Return a string for a named glyph:
Definition: YApplication.cc:235
YIconLoader
Definition: YIconLoader.h:33
ImplPtr< YApplicationPrivate >
YApplication::setApplicationTitle
virtual void setApplicationTitle(const std::string &title)
Set the application title.
Definition: YApplication.cc:283
YApplication
Class for application-wide values and functions.
Definition: YApplication.h:46
YApplication::openContextMenu
virtual bool openContextMenu(const YItemCollection &itemCollection)
Open a context menu for a widget.
Definition: YApplication.cc:253
YApplication::redrawScreen
virtual void redrawScreen()
Redraw the screen.
Definition: YApplication.h:341
YApplication::askForSaveFileName
virtual std::string askForSaveFileName(const std::string &startWith, const std::string &filter, const std::string &headline)=0
Open a file selection box and prompt the user for a file to save data to.
YApplication::setApplicationIcon
virtual void setApplicationIcon(const std::string &icon)
Set the application Icon.
Definition: YApplication.cc:293
YApplication::reverseLayout
bool reverseLayout() const
Returns 'true' if widget geometry should be reversed for languages that have right-to-left writing di...
Definition: YApplication.cc:156
YApplication::defaultFunctionKey
int defaultFunctionKey(const std::string &label) const
Return the default function key number for a widget with the specified label or 0 if there is none.
Definition: YApplication.cc:163
YApplication::setProductName
virtual void setProductName(const std::string &productName)
Set the current product name ("openSUSE", "SLES", ...).
Definition: YApplication.cc:113
YApplication::deviceUnits
virtual int deviceUnits(YUIDimension dim, float layoutUnits)
Convert logical layout spacing units into device dependent units.
Definition: YApplication.cc:262
YApplication::applicationTitle
virtual const std::string & applicationTitle() const
Get the application title.
Definition: YApplication.cc:288
YApplication::askForExistingFile
virtual std::string askForExistingFile(const std::string &startWith, const std::string &filter, const std::string &headline)=0
Open a file selection box and prompt the user for an existing file.
YWidgetID
Abstract base class for widget IDs.
Definition: YWidgetID.h:37
YApplication::setIconBasePath
virtual void setIconBasePath(const std::string &newIconBasePath)
Set the icon base path.
Definition: YApplication.cc:101
YApplication::clearDefaultFunctionKeys
void clearDefaultFunctionKeys()
Clear all previous label-to-function-key mappings.
Definition: YApplication.cc:186
YApplication::showProductLogo
bool showProductLogo() const
Return true if product logo should be shown.
Definition: YApplication.cc:144
YApplication::askForExistingDirectory
virtual std::string askForExistingDirectory(const std::string &startDir, const std::string &headline)=0
Open a directory selection box and prompt the user for an existing directory.
YApplication::runInTerminal
virtual int runInTerminal(const std::string &command)
Run a shell command (typically an interactive program using NCurses) in a terminal (window).
Definition: YApplication.cc:276
YApplication::iconBasePath
virtual std::string iconBasePath() const
Get the base path for icons used by the UI.
Definition: YApplication.cc:94
YApplication::setDefaultFunctionKey
void setDefaultFunctionKey(const std::string &label, int fkey)
Add a mapping from the specified label to the specified F-key number.
Definition: YApplication.cc:176
YApplication::setShowProductLogo
void setShowProductLogo(bool show)
Set whether the product logo (in top bar) should be shown.
Definition: YApplication.cc:138