libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YUILoader.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #include <stdlib.h> // getenv() 00026 #include <unistd.h> // isatty()a 00027 #include <sys/stat.h> 00028 #include <string.h> 00029 00030 #include "YCommandLine.h" 00031 #include "YUILoader.h" 00032 #include "YUIPlugin.h" 00033 #include "YUIException.h" 00034 #include "YPath.h" 00035 00036 #include "Libyui_config.h" 00037 00038 00039 void YUILoader::loadUI( bool withThreads ) 00040 { 00041 const char * envDisplay = getenv( "DISPLAY" ); 00042 00043 YCommandLine cmdline; 00044 00045 bool wantNcurses = cmdline.find("--ncurses") != -1; 00046 bool wantQt = cmdline.find("--qt") != -1; 00047 bool wantGtk = cmdline.find("--gtk") != -1; 00048 00049 bool haveQt = pluginExists( YUIPlugin_Qt ); 00050 bool haveGtk = pluginExists( YUIPlugin_Gtk ); 00051 00052 if ( envDisplay && !wantNcurses ) 00053 { 00054 std::string wantedGUI; 00055 00056 if ( haveQt && !wantGtk) 00057 wantedGUI = YUIPlugin_Qt; 00058 else if ( haveGtk && !wantQt ) 00059 wantedGUI = YUIPlugin_Gtk; 00060 00061 if ( strcmp( wantedGUI.c_str(), "" ) ) 00062 { 00063 try 00064 { 00065 loadPlugin( wantedGUI, withThreads ); 00066 return; 00067 } 00068 catch ( YUIException & ex) 00069 { 00070 YUI_CAUGHT( ex ); 00071 } 00072 } 00073 } 00074 00075 if ( isatty( STDOUT_FILENO ) ) 00076 { 00077 // 00078 // NCurses UI 00079 // 00080 00081 try 00082 { 00083 loadPlugin( YUIPlugin_NCurses, withThreads ); 00084 return; 00085 } 00086 catch ( YUIException & ex) 00087 { 00088 YUI_CAUGHT( ex ); 00089 YUI_RETHROW( ex ); // what else to do here? 00090 } 00091 } 00092 else 00093 { 00094 YUI_THROW( YUICantLoadAnyUIException() ); 00095 } 00096 } 00097 00098 00099 void YUILoader::loadPlugin( const std::string & name, bool withThreads ) 00100 { 00101 YUIPlugin uiPlugin( name.c_str() ); 00102 00103 if ( uiPlugin.success() ) 00104 { 00105 createUIFunction_t createUI = (createUIFunction_t) uiPlugin.locateSymbol( "_Z8createUIb" ); // createUI(bool) 00106 00107 if ( createUI ) 00108 { 00109 YUI * ui = createUI( withThreads ); // no threads 00110 00111 if ( ui ) 00112 return; 00113 } 00114 } 00115 00116 YUI_THROW( YUIPluginException( name ) ); 00117 } 00118 00119 bool YUILoader::pluginExists( const std::string & pluginBaseName ) 00120 { 00121 struct stat fileinfo; 00122 std::string pluginName = PLUGIN_PREFIX; 00123 00124 pluginName.append( pluginBaseName ); 00125 pluginName.append( PLUGIN_SUFFIX ); 00126 00127 YPath plugin ( PLUGINDIR, pluginName ); 00128 00129 return stat( plugin.path().c_str(), &fileinfo) == 0; 00130 00131 }