libyui  3.4.2
YUILoader.h
1 /*
2  Copyright (C) 2000-2017 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: YUILoader.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YUILoader_h
27 #define YUILoader_h
28 
29 
30 #include <string>
31 
32 #include "YUI.h"
33 #include "YExternalWidgets.h"
34 
35 
36 
37 #define YUIPlugin_Qt "qt"
38 #define YUIPlugin_NCurses "ncurses"
39 #define YUIPlugin_Gtk "gtk"
40 
41 
42 /**
43  * Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk.
44  **/
45 class YUILoader
46 {
47 public:
48  /**
49  * Load any of the available UI-plugins by this order and criteria:
50  *
51  * - Qt:
52  * - if $DISPLAY is set
53  * - NCurses is user-selected and stdout is *not* a TTY
54  *
55  * - Gtk:
56  * - if $DISPLAY is set and Qt is not available,
57  * - a GTK-based desktop environment is detected
58  * from the environment variable XDG_CURRENT_DESKTOP
59  * - any of the above pre-conditions are met and
60  * NCurses is user-selected, but stdout is *not* a TTY
61  *
62  * - NCurses:
63  * - if $DISPLAY is *not* set and stdout is a TTY
64  * - Qt and Gtk are not available and stdout is a TTY
65  *
66  * This can be overridden by either:
67  *
68  * - specifing one of the switches on the
69  * command-line of the program
70  * - '--gtk',
71  * - '--ncurses', or
72  * - '--qt'
73  *
74  * - setting the environment variable
75  * YUI_PREFERED_BACKEND to one of
76  * - 'gtk',
77  * - 'ncurses', or
78  * - 'qt'
79  *
80  * If a command-line switch is given to the program, the
81  * setting from the environment variable will be overridden
82  * by the UI-plugin chosen with the switch.
83  *
84  * If the user-selected UI-plugin is not installed on the
85  * system, an installed UI-plugin will be chosen by the
86  * above criteria.
87  **/
88  static void loadUI( bool withThreads = false );
89 
90  /**
91  * This will make sure the UI singleton is deleted.
92  * If the UI is already destroyed, it will do nothing. If
93  * there still is a UI object, it will be deleted.
94  *
95  * This is particularly important for the NCurses UI so that
96  * the terminal settings are properly restored.
97  **/
98  static void deleteUI();
99 
100  /**
101  * Load a UI plug-in. 'name' is one of the YUIPlugin_ -defines above.
102  *
103  * This might throw exceptions.
104  **/
105  static void loadPlugin( const std::string & name, bool withThreads = false );
106 
107  static bool pluginExists( const std::string & pluginBaseName );
108 
109  /**
110  * Load the given External Widgets plugin followed by its graphical extension implementation
111  * in the following order in the same way as loadUI:
112  * - Qt, Gtk or NCurses
113  *
114  * 'name' is the user defined plugin name, graphical extension implementations have to
115  * be called 'name'-qt, 'name'-gtk and 'name'-ncurses. Following this rule plugin
116  * file names are as libyui-XX-YY.so.VER where:
117  * XX is the user defined name
118  * YY is the UI used (ncurses, gtk, qt)
119  * VER is the libyui so version
120  * 'symbol' is the function symbol to be loaded, e.g. YExternalWidgets* 'symbol'(void)
121  * (e.g. default YExternalWidgets* createExternalWidgets(const char *)
122  * see createEWFunction_t definition)
123  **/
124  static void loadExternalWidgets( const std::string & name, const std::string & symbol="_Z21createExternalWidgetsPKc" );
125 
126 private:
127  YUILoader() {}
128  ~YUILoader() {}
129 
130  /**
131  * Used by loadExternalWidgets to load the graphical plugin specialization.
132  *
133  * 'name' is the original plugin name (e.g. the one passed to loadExternalWidgets)
134  * 'plugin_name' is the graphical plugin specialization name (e.g. 'name'-[gtk|ncurses|qt])
135  * 'symbol' is the function symbol to be loaded and executed (e.g. the one passed loadExternalWidgets)
136  * This might throw exceptions:
137  * YUIPluginException if the plugin has not been loaded
138  * specific exception can be thrown by funtion invoked (param symbol)
139  **/
140  static void loadExternalWidgetsPlugin( const std::string& name, const std::string& plugin_name, const std::string& symbol );
141 };
142 
143 
144 /**
145  * Every UI plug-in has to provide a function
146  *
147  * YUI * createUI( bool withThreads )
148  *
149  * that creates a UI of that specific type upon the first call and returns that
150  * singleton for all subsequent calls.
151  **/
152 typedef YUI * (*createUIFunction_t)( bool );
153 
154 /**
155  * Every WE extension plug-in has to provide a function
156  *
157  * YExternalWidgets * createWE( )
158  *
159  * that creates a WE of that specific type upon the first call and returns that
160  * singleton for all subsequent calls.
161  **/
162 typedef YExternalWidgets * (*createEWFunction_t)( const char * );
163 
164 #endif // YUILoader_h
Abstract base class of a libYUI user interface.
Definition: YUI.h:48
static void loadPlugin(const std::string &name, bool withThreads=false)
Load a UI plug-in.
Definition: YUILoader.cc:170
static void loadExternalWidgets(const std::string &name, const std::string &symbol="_Z21createExternalWidgetsPKc")
Load the given External Widgets plugin followed by its graphical extension implementation in the foll...
Definition: YUILoader.cc:218
Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk.
Definition: YUILoader.h:45
static void deleteUI()
This will make sure the UI singleton is deleted.
Definition: YUILoader.cc:159
Abstract base class of a libYUI Widget Extension interface.
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
Definition: YUILoader.cc:42