28 #include "YNCursesUI.h"
35 #include <yui/YEvent.h>
36 #include <yui/YDialog.h>
37 #include <yui/YCommandLine.h>
38 #include <yui/YButtonBox.h>
39 #include <yui/YMacro.h>
41 #define YUILogComponent "ncurses"
42 #include <yui/YUILog.h>
45 #include "NCWidgetFactory.h"
46 #include "NCOptionalWidgetFactory.h"
47 #include "NCPackageSelectorPluginStub.h"
48 #include "NCPopupTextEntry.h"
51 extern std::string language2encoding( std::string lang );
56 YUI * createUI(
bool withThreads )
67 yuiMilestone() <<
"Start YNCursesUI" << std::endl;
70 if ( getenv(
"LANG" ) != NULL )
72 setlocale ( LC_CTYPE,
"" );
73 std::string language = getenv(
"LANG" );
74 std::string encoding = nl_langinfo( CODESET );
75 yuiMilestone() <<
"getenv LANG: " << language <<
" encoding: " << encoding << std::endl;
79 std::string locale = setlocale( LC_CTYPE, NULL );
80 setenv(
"LC_CTYPE", locale.c_str(), 1 );
81 yuiMilestone() <<
"setenv LC_CTYPE: " << locale <<
" encoding: " << encoding << std::endl;
85 NCstring::setTerminalEncoding( encoding );
86 app()->setLanguage( language, encoding );
89 YButtonBoxMargins buttonBoxMargins;
90 buttonBoxMargins.left = 1;
91 buttonBoxMargins.right = 1;
92 buttonBoxMargins.top = 1;
93 buttonBoxMargins.bottom = 0;
94 buttonBoxMargins.spacing = 1;
95 buttonBoxMargins.helpButtonExtraSpacing = 3;
96 YButtonBox::setDefaultMargins( buttonBoxMargins );
104 yuiMilestone() << err << std::endl;
109 if ( topmostConstructor )
112 topmostConstructorHasFinished();
120 YDialog::deleteAllDialogs();
121 yuiMilestone() <<
"Stop YNCursesUI" << std::endl;
129 YUI_CHECK_NEW( factory );
135 YOptionalWidgetFactory *
139 YUI_CHECK_NEW( factory );
146 YNCursesUI::createApplication()
149 YUI_CHECK_NEW( app );
171 FD_SET( fd_ycp, &fdset );
173 retval = select( fd_ycp + 1, &fdset, 0, 0, &tv );
177 if ( errno != EINTR )
178 yuiError() <<
"idleLoop error in select() (" << errno <<
')' << std::endl;
180 else if ( retval != 0 )
184 YDialog *currentDialog = YDialog::currentDialog(
false );
194 if ( NCBusyIndicatorObject )
195 NCBusyIndicatorObject->
handler( 0 );
202 while ( !FD_ISSET( fd_ycp, &fdset ) );
231 YDialog *dialog = YDialog::currentDialog();
236 yuiError() <<
"ERROR package selection: No dialog rexisting." << std::endl;
242 yuiError() <<
"ERROR package selection: No package selector existing." << std::endl;
247 dialog->dumpDialogWidgetTree();
258 void YNCursesUI::init_title()
261 YCommandLine cmdline;
267 std::string progName = YUILog::basename( cmdline[0] );
269 if ( progName ==
"y2base" )
279 if ( cmdline.size() > 1 )
280 progName +=
" - " + cmdline[1];
283 if ( progName.find(
"lt-" ) == 0 )
286 progName = progName.substr(
sizeof(
"lt-" ) - 1 );
294 std::string hostName;
296 char hostNameBuffer[ 256 ];
298 if ( gethostname( hostNameBuffer,
sizeof( hostNameBuffer ) - 1 ) != -1 )
304 hostNameBuffer[
sizeof( hostNameBuffer ) -1 ] =
'\0';
305 hostName = hostNameBuffer;
308 if ( hostName ==
"(none)" )
315 std::string windowTitle = progName;
317 if ( ! hostName.empty() )
318 windowTitle +=
" @ " + hostName;
320 NCurses::SetTitle( windowTitle );
324 bool YNCursesUI::want_colors()
326 if ( getenv(
"Y2NCURSES_BW" ) != NULL )
328 yuiMilestone() <<
"Y2NCURSES_BW is std::set - won't use colors" << std::endl;
346 const std::string & font,
347 const std::string & screen_map,
348 const std::string & unicode_map,
349 const std::string & lang )
351 std::string cmd(
"setfont" );
352 cmd +=
" -C " + myTerm;
355 if ( !screen_map.empty() )
356 cmd +=
" -m " + screen_map;
358 if ( !unicode_map.empty() )
359 cmd +=
" -u " + unicode_map;
361 yuiMilestone() << cmd << std::endl;
363 int ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
368 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
374 cmd =
"(echo -en \"\\033";
376 if ( console_magic.length() )
377 cmd += console_magic;
381 cmd +=
"\" >" + myTerm +
")";
383 yuiMilestone() << cmd << std::endl;
385 ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
389 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
398 if ( NCstring::terminalEncoding() !=
"UTF-8" )
400 std::string language = lang;
401 std::string::size_type pos = language.find(
'.' );
403 if ( pos != std::string::npos )
405 language.erase( pos );
408 pos = language.find(
'_' );
410 if ( pos != std::string::npos )
412 language.erase( pos );
415 std::string code = language2encoding( language );
417 yuiMilestone() <<
"setConsoleFont( ENCODING: " << code <<
" )" << std::endl;
419 if ( NCstring::setTerminalEncoding( code ) )
437 std::string
id = NCPopupTextEntry::askForText(
wpos( 0, 0 ),
438 _(
"Enter Widget ID:"),
445 return sendWidgetID(
id );
447 catch ( YUIWidgetNotFoundException & ex )
463 yuiDebug() <<
"Events blocked, ignoring event " <<
event << std::endl;
468 NCDialog *dialog =
dynamic_cast<NCDialog *
>(NCDialog::currentDialog(
false));
473 yuiDebug() <<
"Sending event: " <<
event << std::endl;
475 dialog->setPendingEvent(event);
479 yuiError() <<
"No dialog" << std::endl;