libyui  3.9.3
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 #define YUIPlugin_RestAPI "rest-api"
41 #define YUIPlugin_Ncurses_RestAPI "ncurses-rest-api"
42 #define YUIPlugin_Qt_RestAPI "qt-rest-api"
43 
44 /**
45  * Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk.
46  **/
47 class YUILoader
48 {
49 public:
50  /**
51  * Load any of the available UI-plugins by this order and criteria:
52  *
53  * - Qt:
54  * - if $DISPLAY is set
55  * - NCurses is user-selected and stdout is *not* a TTY
56  *
57  * - Gtk:
58  * - if $DISPLAY is set and Qt is not available,
59  * - a GTK-based desktop environment is detected
60  * from the environment variable XDG_CURRENT_DESKTOP
61  * - any of the above pre-conditions are met and
62  * NCurses is user-selected, but stdout is *not* a TTY
63  *
64  * - NCurses:
65  * - if $DISPLAY is *not* set and stdout is a TTY
66  * - Qt and Gtk are not available and stdout is a TTY
67  *
68  * This can be overridden by either:
69  *
70  * - specifing one of the switches on the
71  * command-line of the program
72  * - '--gtk',
73  * - '--ncurses', or
74  * - '--qt'
75  *
76  * - setting the environment variable
77  * YUI_PREFERED_BACKEND to one of
78  * - 'gtk',
79  * - 'ncurses', or
80  * - 'qt'
81  *
82  * If a command-line switch is given to the program, the
83  * setting from the environment variable will be overridden
84  * by the UI-plugin chosen with the switch.
85  *
86  * If the user-selected UI-plugin is not installed on the
87  * system, an installed UI-plugin will be chosen by the
88  * above criteria.
89  **/
90  static void loadUI( bool withThreads = false );
91 
92  /**
93  * This will make sure the UI singleton is deleted.
94  * If the UI is already destroyed, it will do nothing. If
95  * there still is a UI object, it will be deleted.
96  *
97  * This is particularly important for the NCurses UI so that
98  * the terminal settings are properly restored.
99  **/
100  static void deleteUI();
101 
102  /**
103  * Method handles loading integration test framework and load underlying GUI
104  * using hints from loadUI.
105  **/
106  static void loadRestAPIPlugin( const std::string & wantedGUI, bool withThreads = false );
107 
108  /**
109  * Load a UI plug-in. 'name' is one of the YUIPlugin_ -defines above.
110  *
111  * This might throw exceptions.
112  **/
113  static void loadPlugin( const std::string & name, bool withThreads = false );
114 
115  static bool pluginExists( const std::string & pluginBaseName );
116 
117  /**
118  * Load the given External Widgets plugin followed by its graphical extension implementation
119  * in the following order in the same way as loadUI:
120  * - Qt, Gtk or NCurses
121  *
122  * 'name' is the user defined plugin name, graphical extension implementations have to
123  * be called 'name'-qt, 'name'-gtk and 'name'-ncurses. Following this rule plugin
124  * file names are as libyui-XX-YY.so.VER where:
125  * XX is the user defined name
126  * YY is the UI used (ncurses, gtk, qt)
127  * VER is the libyui so version
128  * 'symbol' is the function symbol to be loaded, e.g. YExternalWidgets* 'symbol'(void)
129  * (e.g. default YExternalWidgets* createExternalWidgets(const char *)
130  * see createEWFunction_t definition)
131  **/
132  static void loadExternalWidgets( const std::string & name, const std::string & symbol="_Z21createExternalWidgetsPKc" );
133 
134 private:
135  YUILoader() {}
136  ~YUILoader() {}
137 
138  /**
139  * Used by loadExternalWidgets to load the graphical plugin specialization.
140  *
141  * 'name' is the original plugin name (e.g. the one passed to loadExternalWidgets)
142  * 'plugin_name' is the graphical plugin specialization name (e.g. 'name'-[gtk|ncurses|qt])
143  * 'symbol' is the function symbol to be loaded and executed (e.g. the one passed loadExternalWidgets)
144  * This might throw exceptions:
145  * YUIPluginException if the plugin has not been loaded
146  * specific exception can be thrown by funtion invoked (param symbol)
147  **/
148  static void loadExternalWidgetsPlugin( const std::string& name, const std::string& plugin_name, const std::string& symbol );
149 };
150 
151 
152 /**
153  * Every UI plug-in has to provide a function
154  *
155  * YUI * createUI( bool withThreads )
156  *
157  * that creates a UI of that specific type upon the first call and returns that
158  * singleton for all subsequent calls.
159  **/
160 typedef YUI * (*createUIFunction_t)( bool );
161 
162 /**
163  * Every WE extension plug-in has to provide a function
164  *
165  * YExternalWidgets * createWE( )
166  *
167  * that creates a WE of that specific type upon the first call and returns that
168  * singleton for all subsequent calls.
169  **/
170 typedef YExternalWidgets * (*createEWFunction_t)( const char * );
171 
172 /**
173  * For the integration testing YUI has separate framework which allows to have
174  * control over UI using REST API. Server has to be started after testing framework
175  * plugin is loaded, which is done by the method which creates server instance.
176  * Not to have additional definition imports, we define it as void here.
177  * In the framework calls it can be used to
178 **/
179 typedef void (*getServerFunction_t)();
180 
181 #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:241
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:295
static void loadRestAPIPlugin(const std::string &wantedGUI, bool withThreads=false)
Method handles loading integration test framework and load underlying GUI using hints from loadUI...
Definition: YUILoader.cc:180
Class to load one of the concrete UI plug-ins: Qt, NCurses, Gtk.
Definition: YUILoader.h:47
static void deleteUI()
This will make sure the UI singleton is deleted.
Definition: YUILoader.cc:230
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:51