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 )
68 yuiMilestone() <<
"Start YNCursesUI" << std::endl;
71 if ( getenv(
"LANG" ) != NULL )
73 setlocale ( LC_CTYPE,
"" );
74 std::string language = getenv(
"LANG" );
75 std::string encoding = nl_langinfo( CODESET );
76 yuiMilestone() <<
"getenv LANG: " << language <<
" encoding: " << encoding << std::endl;
80 std::string locale = setlocale( LC_CTYPE, NULL );
81 setenv(
"LC_CTYPE", locale.c_str(), 1 );
82 yuiMilestone() <<
"setenv LC_CTYPE: " << locale <<
" encoding: " << encoding << std::endl;
86 NCstring::setTerminalEncoding( encoding );
87 app()->setLanguage( language, encoding );
90 YButtonBoxMargins buttonBoxMargins;
91 buttonBoxMargins.left = 1;
92 buttonBoxMargins.right = 1;
93 buttonBoxMargins.top = 1;
94 buttonBoxMargins.bottom = 0;
95 buttonBoxMargins.spacing = 1;
96 buttonBoxMargins.helpButtonExtraSpacing = 3;
97 YButtonBox::setDefaultMargins( buttonBoxMargins );
105 yuiMilestone() << err << std::endl;
110 topmostConstructorHasFinished();
117 YDialog::deleteAllDialogs();
118 yuiMilestone() <<
"Stop YNCursesUI" << std::endl;
126 YUI_CHECK_NEW( factory );
132 YOptionalWidgetFactory *
136 YUI_CHECK_NEW( factory );
143 YNCursesUI::createApplication()
146 YUI_CHECK_NEW( app );
168 FD_SET( fd_ycp, &fdset );
170 retval = select( fd_ycp + 1, &fdset, 0, 0, &tv );
174 if ( errno != EINTR )
175 yuiError() <<
"idleLoop error in select() (" << errno <<
')' << std::endl;
177 else if ( retval != 0 )
181 YDialog *currentDialog = YDialog::currentDialog(
false );
191 if ( NCBusyIndicatorObject )
192 NCBusyIndicatorObject->
handler( 0 );
199 while ( !FD_ISSET( fd_ycp, &fdset ) );
228 YDialog *dialog = YDialog::currentDialog();
233 yuiError() <<
"ERROR package selection: No dialog rexisting." << std::endl;
239 yuiError() <<
"ERROR package selection: No package selector existing." << std::endl;
244 dialog->dumpDialogWidgetTree();
255 void YNCursesUI::init_title()
258 YCommandLine cmdline;
264 std::string progName = YUILog::basename( cmdline[0] );
266 if ( progName ==
"y2base" )
276 if ( cmdline.size() > 1 )
277 progName +=
" - " + cmdline[1];
280 if ( progName.find(
"lt-" ) == 0 )
283 progName = progName.substr(
sizeof(
"lt-" ) - 1 );
291 std::string hostName;
293 char hostNameBuffer[ 256 ];
295 if ( gethostname( hostNameBuffer,
sizeof( hostNameBuffer ) - 1 ) != -1 )
301 hostNameBuffer[
sizeof( hostNameBuffer ) -1 ] =
'\0';
302 hostName = hostNameBuffer;
305 if ( hostName ==
"(none)" )
312 std::string windowTitle = progName;
314 if ( ! hostName.empty() )
315 windowTitle +=
" @ " + hostName;
317 NCurses::SetTitle( windowTitle );
321 bool YNCursesUI::want_colors()
323 if ( getenv(
"Y2NCURSES_BW" ) != NULL )
325 yuiMilestone() <<
"Y2NCURSES_BW is std::set - won't use colors" << std::endl;
343 const std::string & font,
344 const std::string & screen_map,
345 const std::string & unicode_map,
346 const std::string & lang )
348 std::string cmd(
"setfont" );
349 cmd +=
" -C " + myTerm;
352 if ( !screen_map.empty() )
353 cmd +=
" -m " + screen_map;
355 if ( !unicode_map.empty() )
356 cmd +=
" -u " + unicode_map;
358 yuiMilestone() << cmd << std::endl;
360 int ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
365 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
371 cmd =
"(echo -en \"\\033";
373 if ( console_magic.length() )
374 cmd += console_magic;
378 cmd +=
"\" >" + myTerm +
")";
380 yuiMilestone() << cmd << std::endl;
382 ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
386 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
395 if ( NCstring::terminalEncoding() !=
"UTF-8" )
397 std::string language = lang;
398 std::string::size_type pos = language.find(
'.' );
400 if ( pos != std::string::npos )
402 language.erase( pos );
405 pos = language.find(
'_' );
407 if ( pos != std::string::npos )
409 language.erase( pos );
412 std::string code = language2encoding( language );
414 yuiMilestone() <<
"setConsoleFont( ENCODING: " << code <<
" )" << std::endl;
416 if ( NCstring::setTerminalEncoding( code ) )
434 std::string
id = NCPopupTextEntry::askForText(
wpos( 0, 0 ),
435 _(
"Enter Widget ID:"),
442 return sendWidgetID(
id );
444 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.