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" 45 const char * envDesktop;
46 const char * envDisplay;
47 const char * envPreset;
48 std::string wantedGUI;
50 if( getenv(
"DISPLAY" ) )
51 envDisplay = getenv(
"DISPLAY" );
55 if( getenv(
"XDG_CURRENT_DESKTOP" ) )
56 envDesktop = getenv(
"XDG_CURRENT_DESKTOP" );
60 if( getenv(
"YUI_PREFERED_BACKEND" ) )
61 envPreset = getenv(
"YUI_PREFERED_BACKEND" );
65 yuiMilestone () <<
"DISPLAY: \"" << envDisplay <<
"\"" << std::endl;
66 yuiMilestone () <<
"XDG_CURRENT_DESKTOP: \"" << envDesktop <<
"\"" << std::endl;
67 yuiMilestone () <<
"YUI_PREFERED_BACKEND: \"" << envPreset <<
"\"" << std::endl;
70 isGtk = ( ( strstr( envDesktop,
"Cinnamon" ) != NULL ) || isGtk );
71 isGtk = ( ( strstr( envDesktop,
"GNOME" ) != NULL ) || isGtk );
72 isGtk = ( ( strstr( envDesktop,
"LXDE" ) != NULL ) || isGtk );
73 isGtk = ( ( strstr( envDesktop,
"MATE" ) != NULL ) || isGtk );
74 isGtk = ( ( strstr( envDesktop,
"Pantheon" ) != NULL ) || isGtk );
75 isGtk = ( ( strstr( envDesktop,
"ROX" ) != NULL ) || isGtk );
76 isGtk = ( ( strstr( envDesktop,
"Unity" ) != NULL ) || isGtk );
77 isGtk = ( ( strstr( envDesktop,
"XFCE" ) != NULL ) || isGtk );
79 if( isGtk ) yuiMilestone () <<
"Detected a Gtk-based desktop environment." << std::endl
80 <<
"Prefering Gtk-UI if available and no" << std::endl
81 <<
"user-selected override is present." << std::endl;
85 bool wantGtk = ( cmdline.
find(
"--gtk" ) != -1 );
86 bool wantNcurses = ( cmdline.
find(
"--ncurses" ) != -1 );
87 bool wantQt = ( cmdline.
find(
"--qt" ) != -1 );
88 wantGtk = ( wantGtk || ( strcmp( envPreset, YUIPlugin_Gtk ) == 0 ) ) && !( wantNcurses || wantQt );
89 wantNcurses = ( wantNcurses || ( strcmp( envPreset, YUIPlugin_NCurses ) == 0 ) ) && !( wantGtk || wantQt );
90 wantQt = ( wantQt || ( strcmp( envPreset, YUIPlugin_Qt ) == 0 ) ) && !( wantGtk || wantNcurses );
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 <<
"\"" << std::endl;
98 bool haveGtk = pluginExists( YUIPlugin_Gtk );
99 bool haveNcurses = pluginExists( YUIPlugin_NCurses );
100 bool haveQt = pluginExists( YUIPlugin_Qt );
105 if ( ( haveGtk || haveQt ) && strcmp ( envDisplay,
"" ) &&
106 ( !wantNcurses || !isatty( STDOUT_FILENO ) ) )
110 wantedGUI = YUIPlugin_Qt;
113 if ( haveGtk && ( ( ( isGtk || wantGtk ) && !wantQt ) || !haveQt ) )
114 wantedGUI = YUIPlugin_Gtk;
117 else if ( haveNcurses && isatty( STDOUT_FILENO ) )
120 wantedGUI = YUIPlugin_NCurses;
124 if( wantedGUI !=
"" )
126 yuiMilestone () <<
"Using UI-plugin: \"" << wantedGUI <<
"\""<< std::endl;
140 if( wantedGUI != YUIPlugin_NCurses && haveNcurses && isatty( STDOUT_FILENO ) )
142 yuiWarning () <<
"Defaulting to: \"" << YUIPlugin_NCurses <<
"\""<< std::endl;
171 yuiMilestone() <<
"Shutting down UI" << std::endl;
182 if ( uiPlugin.success() )
184 createUIFunction_t createUI = (createUIFunction_t) uiPlugin.locateSymbol(
"_Z8createUIb" );
188 YUI * ui = createUI( withThreads );
206 void YUILoader::loadExternalWidgetsPlugin (
const std::string& name,
const std::string& plugin_name,
const std::string& symbol )
208 YUIPlugin uiPlugin ( plugin_name.c_str() );
210 if ( uiPlugin.success() )
212 createEWFunction_t createEW = ( createEWFunction_t ) uiPlugin.locateSymbol ( symbol.c_str() );
228 std::string wantedGUI = name;
229 wantedGUI.append(
"-" );
232 bool haveExternal = pluginExists( wantedGUI );
238 loadExternalWidgetsPlugin(name, wantedGUI, symbol );
254 bool YUILoader::pluginExists(
const std::string & pluginBaseName )
256 struct stat fileinfo;
257 std::string pluginName = PLUGIN_PREFIX;
259 pluginName.append( pluginBaseName );
260 pluginName.append( PLUGIN_SUFFIX );
262 YPath plugin ( PLUGINDIR, pluginName );
264 return stat( plugin.
path().c_str(), &fileinfo) == 0;
std::string path()
Returns the full path of the file if found; if not found just the filename given in constructor...
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.
Abstract base class of a libYUI user interface.
static void loadPlugin(const std::string &name, bool withThreads=false)
Load a UI plug-in.
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...
Exception class for plugin load failure.
static void deleteUI()
This will make sure the UI singleton is deleted.
Utility class to access /proc/<pid>/cmdline to retrieve argc and argv.
Exception class for UI plugin load failure.
Wrapper class for dlopen() and related.
Base class for UI Exceptions.
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria: