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 = getenv(
"XDG_CURRENT_DESKTOP" ) ?:
"";
46 const char * envDisplay = getenv(
"DISPLAY" ) ?:
"";
47 const char * envPreset = getenv(
"YUI_PREFERED_BACKEND" ) ?:
"";
48 std::string wantedGUI;
50 yuiMilestone () <<
"DISPLAY: \"" << envDisplay <<
"\"" << std::endl;
51 yuiMilestone () <<
"XDG_CURRENT_DESKTOP: \"" << envDesktop <<
"\"" << std::endl;
52 yuiMilestone () <<
"YUI_PREFERED_BACKEND: \"" << envPreset <<
"\"" << std::endl;
55 isGtk = ( ( strstr( envDesktop,
"Cinnamon" ) != NULL ) || isGtk );
56 isGtk = ( ( strstr( envDesktop,
"GNOME" ) != NULL ) || isGtk );
57 isGtk = ( ( strstr( envDesktop,
"LXDE" ) != NULL ) || isGtk );
58 isGtk = ( ( strstr( envDesktop,
"MATE" ) != NULL ) || isGtk );
59 isGtk = ( ( strstr( envDesktop,
"Pantheon" ) != NULL ) || isGtk );
60 isGtk = ( ( strstr( envDesktop,
"ROX" ) != NULL ) || isGtk );
61 isGtk = ( ( strstr( envDesktop,
"Unity" ) != NULL ) || isGtk );
62 isGtk = ( ( strstr( envDesktop,
"XFCE" ) != NULL ) || isGtk );
64 if( isGtk ) yuiMilestone () <<
"Detected a Gtk-based desktop environment." << std::endl
65 <<
"Prefering Gtk-UI if available and no" << std::endl
66 <<
"user-selected override is present." << std::endl;
70 bool wantGtk = ( cmdline.
find(
"--gtk" ) != -1 );
71 bool wantNcurses = ( cmdline.
find(
"--ncurses" ) != -1 );
72 bool wantQt = ( cmdline.
find(
"--qt" ) != -1 );
73 bool haveUIPreset = ( wantGtk || wantNcurses || wantQt );
77 wantGtk = ( strcmp( envPreset, YUIPlugin_Gtk ) == 0 );
78 wantNcurses = ( strcmp( envPreset, YUIPlugin_NCurses ) == 0 );
79 wantQt = ( strcmp( envPreset, YUIPlugin_Qt ) == 0 );
82 if( wantGtk ) wantedGUI = YUIPlugin_Gtk;
83 if( wantNcurses ) wantedGUI = YUIPlugin_NCurses;
84 if( wantQt ) wantedGUI = YUIPlugin_Qt;
86 yuiMilestone () <<
"User-selected UI-plugin: \"" << wantedGUI <<
"\"" << std::endl;
88 bool haveGtk = pluginExists( YUIPlugin_Gtk );
89 bool haveNcurses = pluginExists( YUIPlugin_NCurses );
90 bool haveQt = pluginExists( YUIPlugin_Qt );
97 if ( ( haveGtk || haveQt ) && strcmp ( envDisplay,
"" ) &&
98 ( !wantNcurses || !isatty( STDOUT_FILENO ) ) )
102 wantedGUI = YUIPlugin_Qt;
105 if ( haveGtk && ( ( ( isGtk || wantGtk ) && !wantQt ) || !haveQt ) )
106 wantedGUI = YUIPlugin_Gtk;
109 else if ( haveNcurses && isatty( STDOUT_FILENO ) )
112 wantedGUI = YUIPlugin_NCurses;
116 if( wantedGUI !=
"" )
118 yuiMilestone () <<
"Using UI-plugin: \"" << wantedGUI <<
"\""<< std::endl;
132 if( wantedGUI != YUIPlugin_NCurses && haveNcurses && isatty( STDOUT_FILENO ) )
134 yuiWarning () <<
"Defaulting to: \"" << YUIPlugin_NCurses <<
"\""<< std::endl;
163 yuiMilestone() <<
"Shutting down UI" << std::endl;
176 createUIFunction_t createUI = (createUIFunction_t) uiPlugin.
locateSymbol(
"_Z8createUIb" );
180 YUI * ui = createUI( withThreads );
198 void YUILoader::loadExternalWidgetsPlugin (
const std::string& name,
const std::string& plugin_name,
const std::string& symbol )
200 YUIPlugin uiPlugin ( plugin_name.c_str() );
202 if ( uiPlugin.success() )
204 createEWFunction_t createEW = ( createEWFunction_t ) uiPlugin.locateSymbol ( symbol.c_str() );
220 std::string wantedGUI = name;
221 wantedGUI.append(
"-" );
224 bool haveExternal = pluginExists( wantedGUI );
230 loadExternalWidgetsPlugin(name, wantedGUI, symbol );
246 bool YUILoader::pluginExists(
const std::string & pluginBaseName )
248 struct stat fileinfo;
249 std::string pluginName = PLUGIN_PREFIX;
251 pluginName.append( pluginBaseName );
252 pluginName.append( PLUGIN_SUFFIX );
254 YPath plugin ( PLUGINDIR, pluginName );
256 return stat( plugin.path().c_str(), &fileinfo) == 0;