30 #define YUILogComponent "ui"
32 #include "YCommandLine.h"
33 #include "YUILoader.h"
34 #include "YUIPlugin.h"
35 #include "YUIException.h"
37 #include "YSettings.h"
39 #include "Libyui_config.h"
46 const char *env = getenv(
"YUI_HTTP_PORT");
47 return env && atoi(env) > 0;
54 const char * envDesktop = getenv(
"XDG_CURRENT_DESKTOP" ) ?:
"";
55 const char * envDisplay = getenv(
"DISPLAY" ) ?:
"";
56 const char * envPreset = getenv(
"YUI_PREFERED_BACKEND" ) ?:
"";
60 yuiMilestone () <<
"DISPLAY: \"" << envDisplay <<
"\"" << endl;
61 yuiMilestone () <<
"XDG_CURRENT_DESKTOP: \"" << envDesktop <<
"\"" << endl;
62 yuiMilestone () <<
"YUI_PREFERED_BACKEND: \"" << envPreset <<
"\"" << endl;
65 isGtk = ( ( strstr( envDesktop,
"Cinnamon" ) != NULL ) || isGtk );
66 isGtk = ( ( strstr( envDesktop,
"GNOME" ) != NULL ) || isGtk );
67 isGtk = ( ( strstr( envDesktop,
"LXDE" ) != NULL ) || isGtk );
68 isGtk = ( ( strstr( envDesktop,
"MATE" ) != NULL ) || isGtk );
69 isGtk = ( ( strstr( envDesktop,
"Pantheon" ) != NULL ) || isGtk );
70 isGtk = ( ( strstr( envDesktop,
"ROX" ) != NULL ) || isGtk );
71 isGtk = ( ( strstr( envDesktop,
"Unity" ) != NULL ) || isGtk );
72 isGtk = ( ( strstr( envDesktop,
"XFCE" ) != NULL ) || isGtk );
74 if ( isGtk ) yuiMilestone () <<
"Detected a Gtk-based desktop environment." << endl
75 <<
"Prefering Gtk-UI if available and no" << endl
76 <<
"user-selected override is present." << endl;
80 bool wantGtk = ( cmdline.
find(
"--gtk" ) != -1 );
81 bool wantNcurses = ( cmdline.
find(
"--ncurses" ) != -1 );
82 bool wantQt = ( cmdline.
find(
"--qt" ) != -1 );
83 bool haveUIPreset = ( wantGtk || wantNcurses || wantQt );
87 wantGtk = ( strcmp( envPreset, YUIPlugin_Gtk ) == 0 );
88 wantNcurses = ( strcmp( envPreset, YUIPlugin_NCurses ) == 0 );
89 wantQt = ( strcmp( envPreset, YUIPlugin_Qt ) == 0 );
92 if ( wantGtk ) wantedGUI = YUIPlugin_Gtk;
93 if ( wantNcurses ) wantedGUI = YUIPlugin_NCurses;
94 if ( wantQt ) wantedGUI = YUIPlugin_Qt;
96 yuiMilestone () <<
"User-selected UI-plugin: \"" << wantedGUI <<
"\"" << endl;
98 bool haveGtk = pluginExists( YUIPlugin_Gtk );
99 bool haveNcurses = pluginExists( YUIPlugin_NCurses );
100 bool haveQt = pluginExists( YUIPlugin_Qt );
107 if ( ( haveGtk || haveQt ) && strcmp ( envDisplay,
"" ) &&
108 ( !wantNcurses || !isatty( STDOUT_FILENO ) ) )
112 wantedGUI = YUIPlugin_Qt;
115 if ( haveGtk && ( ( ( isGtk || wantGtk ) && !wantQt ) || !haveQt ) )
116 wantedGUI = YUIPlugin_Gtk;
119 else if ( haveNcurses && isatty( STDOUT_FILENO ) )
122 wantedGUI = YUIPlugin_NCurses;
126 if ( wantedGUI !=
"" )
128 yuiMilestone () <<
"Using UI-plugin: \"" << wantedGUI <<
"\""<< endl;
136 if ( rest_enabled() && wantedGUI != YUIPlugin_Gtk )
153 if ( wantedGUI != YUIPlugin_NCurses && haveNcurses && isatty( STDOUT_FILENO ) )
155 yuiWarning () <<
"Defaulting to: \"" << YUIPlugin_NCurses <<
"\""<< endl;
183 yuiMilestone () <<
"Requested to start http server to control UI." << endl;
185 if ( pluginExists( YUIPlugin_RestAPI ) )
187 YUIPlugin uiRestPlugin( YUIPlugin_RestAPI );
188 createUIFunction_t createUI =
nullptr;
189 yuiMilestone () <<
"User-selected underlying UI-plugin: \"" << wantedGUI <<
"\"" << endl;
191 if (wantedGUI == YUIPlugin_Qt)
194 YUIPlugin uiPluginQTRest( YUIPlugin_Qt_RestAPI );
198 yuiMilestone () <<
"Loading the http server to control the Qt UI" << endl;
199 createUI = (createUIFunction_t) uiPluginQTRest.
locateSymbol(
"createYQHttpUI" );
202 yuiError() <<
"Cannot load Qt REST API UI" << endl;
206 if (wantedGUI == YUIPlugin_NCurses || createUI ==
nullptr)
208 YUIPlugin uiPluginNC( YUIPlugin_NCurses );
209 YUIPlugin uiPluginNCRest( YUIPlugin_Ncurses_RestAPI );
212 yuiMilestone () <<
"Loading the http server to control the ncurses UI" << endl;
213 createUI = (createUIFunction_t) uiPluginNCRest.
locateSymbol(
"createYNCHttpUI" );
219 YUI * ui = createUI( withThreads );
234 yuiMilestone() <<
"Shutting down UI" << endl;
243 if (rest_enabled() && (name == YUIPlugin_NCurses || name == YUIPlugin_Qt))
253 createUIFunction_t createUI = (createUIFunction_t) uiPlugin.
locateSymbol(
"_Z8createUIb" );
257 YUI * ui = createUI( withThreads );
275 void YUILoader::loadExternalWidgetsPlugin (
const string& name,
const string& plugin_name,
const string& symbol )
277 YUIPlugin uiPlugin ( plugin_name.c_str() );
279 if ( uiPlugin.success() )
281 createEWFunction_t createEW = ( createEWFunction_t ) uiPlugin.locateSymbol ( symbol.c_str() );
297 string wantedGUI = name;
298 wantedGUI.append(
"-" );
301 bool haveExternal = pluginExists( wantedGUI );
307 loadExternalWidgetsPlugin(name, wantedGUI, symbol );
323 bool YUILoader::pluginExists(
const string & pluginBaseName )
325 struct stat fileinfo;
326 string pluginName = PLUGIN_PREFIX;
328 pluginName.append( pluginBaseName );
329 pluginName.append( PLUGIN_SUFFIX );
331 YPath plugin ( PLUGINDIR, pluginName );
333 return stat( plugin.path().c_str(), &fileinfo) == 0;
Utility class to access /proc/<pid>/cmdline to retrieve argc and argv.
int find(const std::string &argName) const
Find a command line argument 'argName' ("-display" etc.).
static std::string loadedUI()
Returns the value of the loaded UI-backend.
Exception class for UI plugin load failure.
Base class for UI Exceptions.
static void loadRestAPIPlugin(const std::string &wantedGUI, bool withThreads=false)
Method handles loading integration test framework and load underlying GUI using hints from loadUI.
static void deleteUI()
This will make sure the UI singleton is deleted.
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...
static void loadPlugin(const std::string &name, bool withThreads=false)
Load a UI plug-in.
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
Exception class for plugin load failure.
Wrapper class for dlopen() and related.
void * locateSymbol(const char *symbol)
Try to locate the specified symbol (function or global variable) in the plugin library.
bool success() const
Returns 'true' if there was no error loading the plugin.
Abstract base class of a libYUI user interface.