25 #include "YNCursesUI.h" 32 #include <yui/YEvent.h> 33 #include <yui/YDialog.h> 34 #include <yui/YCommandLine.h> 35 #include <yui/YButtonBox.h> 36 #include <yui/YMacro.h> 38 #define YUILogComponent "ncurses" 39 #include <yui/YUILog.h> 42 #include "NCWidgetFactory.h" 43 #include "NCOptionalWidgetFactory.h" 44 #include "NCPackageSelectorPluginStub.h" 45 #include "NCPopupTextEntry.h" 48 extern std::string language2encoding( std::string lang );
53 YUI * createUI(
bool withThreads )
65 yuiMilestone() <<
"Start YNCursesUI" << std::endl;
68 if ( getenv(
"LANG" ) != NULL )
70 setlocale ( LC_CTYPE,
"" );
71 std::string language = getenv(
"LANG" );
72 std::string encoding = nl_langinfo( CODESET );
73 yuiMilestone() <<
"getenv LANG: " << language <<
" encoding: " << encoding << std::endl;
77 std::string locale = setlocale( LC_CTYPE, NULL );
78 setenv(
"LC_CTYPE", locale.c_str(), 1 );
79 yuiMilestone() <<
"setenv LC_CTYPE: " << locale <<
" encoding: " << encoding << std::endl;
83 NCstring::setTerminalEncoding( encoding );
84 app()->setLanguage( language, encoding );
87 YButtonBoxMargins buttonBoxMargins;
88 buttonBoxMargins.left = 1;
89 buttonBoxMargins.right = 1;
90 buttonBoxMargins.top = 1;
91 buttonBoxMargins.bottom = 0;
92 buttonBoxMargins.spacing = 1;
93 buttonBoxMargins.helpButtonExtraSpacing = 3;
94 YButtonBox::setDefaultMargins( buttonBoxMargins );
102 yuiMilestone() << err << std::endl;
107 topmostConstructorHasFinished();
114 YDialog::deleteAllDialogs();
115 yuiMilestone() <<
"Stop YNCursesUI" << std::endl;
123 YUI_CHECK_NEW( factory );
129 YOptionalWidgetFactory *
133 YUI_CHECK_NEW( factory );
140 YNCursesUI::createApplication()
143 YUI_CHECK_NEW( app );
165 FD_SET( fd_ycp, &fdset );
167 retval = select( fd_ycp + 1, &fdset, 0, 0, &tv );
171 if ( errno != EINTR )
172 yuiError() <<
"idleLoop error in select() (" << errno <<
')' << std::endl;
174 else if ( retval != 0 )
178 YDialog *currentDialog = YDialog::currentDialog(
false );
188 if ( NCBusyIndicatorObject )
189 NCBusyIndicatorObject->
handler( 0 );
196 while ( !FD_ISSET( fd_ycp, &fdset ) );
225 YDialog *dialog = YDialog::currentDialog();
230 yuiError() <<
"ERROR package selection: No dialog rexisting." << std::endl;
236 yuiError() <<
"ERROR package selection: No package selector existing." << std::endl;
241 dialog->dumpDialogWidgetTree();
252 void YNCursesUI::init_title()
255 YCommandLine cmdline;
261 std::string progName = YUILog::basename( cmdline[0] );
263 if ( progName ==
"y2base" )
273 if ( cmdline.size() > 1 )
274 progName +=
" - " + cmdline[1];
277 if ( progName.find(
"lt-" ) == 0 )
280 progName = progName.substr(
sizeof(
"lt-" ) - 1 );
288 std::string hostName;
290 char hostNameBuffer[ 256 ];
292 if ( gethostname( hostNameBuffer,
sizeof( hostNameBuffer ) - 1 ) != -1 )
298 hostNameBuffer[
sizeof( hostNameBuffer ) -1 ] =
'\0';
299 hostName = hostNameBuffer;
302 if ( hostName ==
"(none)" )
309 std::string windowTitle = progName;
311 if ( ! hostName.empty() )
312 windowTitle +=
" @ " + hostName;
314 NCurses::SetTitle( windowTitle );
318 bool YNCursesUI::want_colors()
320 if ( getenv(
"Y2NCURSES_BW" ) != NULL )
322 yuiMilestone() <<
"Y2NCURSES_BW is std::set - won't use colors" << std::endl;
340 const std::string & font,
341 const std::string & screen_map,
342 const std::string & unicode_map,
343 const std::string & lang )
345 std::string cmd(
"setfont" );
346 cmd +=
" -C " + myTerm;
349 if ( !screen_map.empty() )
350 cmd +=
" -m " + screen_map;
352 if ( !unicode_map.empty() )
353 cmd +=
" -u " + unicode_map;
355 yuiMilestone() << cmd << std::endl;
357 int ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
362 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
368 cmd =
"(echo -en \"\\033";
370 if ( console_magic.length() )
371 cmd += console_magic;
375 cmd +=
"\" >" + myTerm +
")";
377 yuiMilestone() << cmd << std::endl;
379 ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
383 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
392 if ( NCstring::terminalEncoding() !=
"UTF-8" )
394 std::string language = lang;
395 std::string::size_type pos = language.find(
'.' );
397 if ( pos != std::string::npos )
399 language.erase( pos );
402 pos = language.find(
'_' );
404 if ( pos != std::string::npos )
406 language.erase( pos );
409 std::string code = language2encoding( language );
411 yuiMilestone() <<
"setConsoleFont( ENCODING: " << code <<
" )" << std::endl;
413 if ( NCstring::setTerminalEncoding( code ) )
431 std::string
id = NCPopupTextEntry::askForText(
wpos( 0, 0 ),
432 _(
"Enter Widget ID:"),
439 return sendWidgetID(
id );
441 catch ( YUIWidgetNotFoundException & ex )
static YNCursesUI * _ui
Global reference to the UI.
virtual YWidgetFactory * createWidgetFactory()
Create the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
virtual void setConsoleFont(const std::string &console_magic, const std::string &font, const std::string &screen_map, const std::string &unicode_map, const std::string &lang)
Set the (text) console font according to the current encoding etc.
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()
Create the widget factory that provides all the createXY() methods for optional ("special") widgets a...
YWidget * askSendWidgetID()
Open a pop-up dialog to ask the user for a widget ID and then send it with sendWidgetID().
static YNCursesUI * ui()
Access the global Y2NCursesUI.
void handler(int sig_num)
handler, called by NCBusyIndicatorHandlerWrapper
virtual void idleLoop(int fd_ycp)
Idle around until fd_ycp is readable.
virtual YEvent * runPkgSelection(YDialog *currentDialog, YWidget *packageSelector)
Fills the PackageSelector widget (runs the package selection).
NCPackageSelectorPluginStub * packageSelectorPlugin()
Returns the package selector plugin singleton of this UI or creates it (including loading the plugin ...
virtual YEvent * runPkgSelection(YWidget *packageSelector)
Fills the PackageSelector widget and runs package selection.
YNCursesUI(bool withThreads)
Constructor.