libyui-ncurses
2.44.1
|
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: NCApplication.cc 00020 00021 Authors: Gabriele Mohr <gs@suse.de> 00022 Stefan Hundhammer <sh@suse.de> 00023 00024 /-*/ 00025 00026 #include <ncursesw/curses.h> 00027 00028 #define YUILogComponent "ncurses" 00029 #include <yui/YUILog.h> 00030 #include "NCurses.h" 00031 #include "YNCursesUI.h" 00032 #include "NCApplication.h" 00033 #include "NCAskForDirectory.h" 00034 #include "NCAskForFile.h" 00035 00036 00037 NCApplication::NCApplication() 00038 { 00039 00040 } 00041 00042 00043 NCApplication::~NCApplication() 00044 { 00045 00046 } 00047 00048 void 00049 NCApplication::setLanguage( const std::string & language, 00050 const std::string & encoding ) 00051 { 00052 // Intentionally NOT calling 00053 // YApplication::setLanguage( language, encoding ); 00054 // This would implicitly overwrite LC_CTYPE which might result in encoding bugs. 00055 00056 setlocale( LC_NUMERIC, "C" ); // always format numbers with "." 00057 NCurses::Refresh(); 00058 00059 yuiDebug() << "Language: " << language << " Encoding: " << (( encoding != "" ) ? encoding : "NOT SET" ) << std::endl; 00060 00061 } 00062 00063 00064 std::string 00065 NCApplication::askForSaveFileName( const std::string & startDir, 00066 const std::string & filter, 00067 const std::string & headline ) 00068 { 00069 NCAskForSaveFileName * filePopup = new NCAskForSaveFileName( wpos( 1, 1 ), startDir, filter, headline ); 00070 YUI_CHECK_NEW( filePopup ); 00071 00072 NCursesEvent retEvent = filePopup->showDirPopup( ); 00073 YDialog::deleteTopmostDialog(); 00074 00075 yuiMilestone() << "Returning: " << retEvent.result << std::endl; 00076 return retEvent.result; 00077 } 00078 00079 00080 std::string 00081 NCApplication::askForExistingFile( const std::string & startDir, 00082 const std::string & filter, 00083 const std::string & headline ) 00084 { 00085 NCAskForExistingFile * filePopup = new NCAskForExistingFile( wpos( 1, 1 ), startDir, filter, headline ); 00086 YUI_CHECK_NEW( filePopup ); 00087 00088 NCursesEvent retEvent = filePopup->showDirPopup( ); 00089 YDialog::deleteTopmostDialog(); 00090 00091 yuiMilestone() << "Returning: " << retEvent.result << std::endl; 00092 return retEvent.result; 00093 } 00094 00095 00096 std::string 00097 NCApplication::askForExistingDirectory( const std::string & startDir, 00098 const std::string & headline ) 00099 { 00100 NCAskForExistingDirectory * dirPopup = new NCAskForExistingDirectory( wpos( 1, 1 ), startDir, headline ); 00101 YUI_CHECK_NEW( dirPopup ); 00102 00103 NCursesEvent retEvent = dirPopup->showDirPopup( ); 00104 YDialog::deleteTopmostDialog(); 00105 00106 yuiMilestone() << "Returning: " << retEvent.result << std::endl; 00107 return retEvent.result; 00108 } 00109 00110 00111 void 00112 NCApplication::beep() 00113 { 00114 ::beep(); 00115 } 00116 00117 00118 void NCApplication::redrawScreen() 00119 { 00120 YNCursesUI::ui()->Refresh(); 00121 } 00122 00123 00124 void 00125 NCApplication::initConsoleKeyboard() 00126 { 00127 /* 00128 * Following code breaks the console keyboard e.g. for czech language during 00129 * installation (bnc #433016). According to bnc #367801 comment #18/#19 the 00130 * line isn't needed at all. 00131 * "dumpkeys | loadkeys -C "$KBD_TTY" --unicode" has been also removed from kbd 00132 * initscript. If dumpkeys has to be called for any reason it definitely needs 00133 * the codepage argument, otherwise it cannot work. 00134 */ 00135 #if 0 00136 std::string cmd = "/bin/dumpkeys | /bin/loadkeys --unicode"; 00137 00138 if ( NCstring::terminalEncoding() == "UTF-8" ) 00139 { 00140 int ret = system(( cmd + " >/dev/null 2>&1" ).c_str() ); 00141 00142 if ( ret != 0 ) 00143 { 00144 yuiError() << "ERROR: /bin/dumpkeys | /bin/loadkeys --unicode returned: " << ret << std::endl; 00145 } 00146 } 00147 #endif 00148 } 00149 00150 00151 void 00152 NCApplication::setConsoleFont( const std::string & console_magic, 00153 const std::string & font, 00154 const std::string & screen_map, 00155 const std::string & unicode_map, 00156 const std::string & language ) 00157 { 00158 /** 00159 * Moving that code from YNCursesUI to this class turned out to be 00160 * impossible (or at least a lot more work than it's worth) that I finally 00161 * gave it up. 00162 * 00163 * - sh@suse.de 2008-02-06 00164 **/ 00165 YNCursesUI::ui()->setConsoleFont( console_magic, 00166 font, 00167 screen_map, 00168 unicode_map, 00169 language ); 00170 } 00171 00172 00173 int 00174 NCApplication::runInTerminal( const std::string & cmd ) 00175 { 00176 int ret; 00177 00178 // Save tty modes and end ncurses mode temporarily 00179 ::def_prog_mode(); 00180 ::endwin(); 00181 00182 // Regenerate saved stdout and stderr, so that app called 00183 // via system() can use them and draw something to the terminal 00184 dup2( YNCursesUI::ui()->stdout_save, 1 ); 00185 dup2( YNCursesUI::ui()->stderr_save, 2 ); 00186 00187 // Call external program 00188 ret = system( cmd.c_str() ); 00189 00190 if ( ret != 0 ) 00191 { 00192 yuiError() << cmd << " returned:" << ret << std::endl; 00193 } 00194 00195 // Redirect stdout and stderr to y2log again 00196 YNCursesUI::ui()->RedirectToLog(); 00197 00198 // Resume tty modes and refresh the screen 00199 ::reset_prog_mode(); 00200 00201 ::refresh(); 00202 00203 return ret; 00204 } 00205 00206 00207 int 00208 NCApplication::displayWidth() 00209 { 00210 return ::COLS; // exported from ncurses.h 00211 } 00212 00213 00214 int 00215 NCApplication::displayHeight() 00216 { 00217 return ::LINES; // exported from ncurses.h 00218 } 00219 00220 00221 int 00222 NCApplication::displayDepth() 00223 { 00224 return -1; 00225 } 00226 00227 00228 long 00229 NCApplication::displayColors() 00230 { 00231 return NCattribute::colors(); 00232 } 00233 00234 00235 int 00236 NCApplication::defaultWidth() 00237 { 00238 return ::COLS; // exported from ncurses.h 00239 } 00240 00241 00242 int 00243 NCApplication::defaultHeight() 00244 { 00245 return ::LINES; // exported from ncurses.h 00246 } 00247 00248 00249 bool 00250 NCApplication::hasFullUtf8Support() 00251 { 00252 return ( NCstring::terminalEncoding() == "UTF-8" ); 00253 } 00254 00255 void NCApplication::setApplicationTitle ( const std::string& title ) 00256 { 00257 YApplication::setApplicationTitle ( title ); 00258 NCurses::SetTitle(title); 00259 } 00260