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 ) {
110 yuiDebug() <<
"YNCursesUI is the top most constructor" << std::endl;
111 topmostConstructorHasFinished();
119 YDialog::deleteAllDialogs();
120 yuiMilestone() <<
"Stop YNCursesUI" << std::endl;
128 YUI_CHECK_NEW( factory );
134 YOptionalWidgetFactory *
138 YUI_CHECK_NEW( factory );
145 YNCursesUI::createApplication()
148 YUI_CHECK_NEW( app );
170 FD_SET( fd_ycp, &fdset );
172 retval = select( fd_ycp + 1, &fdset, 0, 0, &tv );
176 if ( errno != EINTR )
177 yuiError() <<
"idleLoop error in select() (" << errno <<
')' << std::endl;
179 else if ( retval != 0 )
183 YDialog *currentDialog = YDialog::currentDialog(
false );
193 if ( NCBusyIndicatorObject )
194 NCBusyIndicatorObject->
handler( 0 );
201 while ( !FD_ISSET( fd_ycp, &fdset ) );
230 YDialog *dialog = YDialog::currentDialog();
235 yuiError() <<
"ERROR package selection: No dialog rexisting." << std::endl;
241 yuiError() <<
"ERROR package selection: No package selector existing." << std::endl;
246 dialog->dumpDialogWidgetTree();
257 void YNCursesUI::init_title()
260 YCommandLine cmdline;
266 std::string progName = YUILog::basename( cmdline[0] );
268 if ( progName ==
"y2base" )
278 if ( cmdline.size() > 1 )
279 progName +=
" - " + cmdline[1];
282 if ( progName.find(
"lt-" ) == 0 )
285 progName = progName.substr(
sizeof(
"lt-" ) - 1 );
293 std::string hostName;
295 char hostNameBuffer[ 256 ];
297 if ( gethostname( hostNameBuffer,
sizeof( hostNameBuffer ) - 1 ) != -1 )
303 hostNameBuffer[
sizeof( hostNameBuffer ) -1 ] =
'\0';
304 hostName = hostNameBuffer;
307 if ( hostName ==
"(none)" )
314 std::string windowTitle = progName;
316 if ( ! hostName.empty() )
317 windowTitle +=
" @ " + hostName;
319 NCurses::SetTitle( windowTitle );
323 bool YNCursesUI::want_colors()
325 if ( getenv(
"Y2NCURSES_BW" ) != NULL )
327 yuiMilestone() <<
"Y2NCURSES_BW is std::set - won't use colors" << std::endl;
345 const std::string & font,
346 const std::string & screen_map,
347 const std::string & unicode_map,
348 const std::string & lang )
350 std::string cmd(
"setfont" );
351 cmd +=
" -C " + myTerm;
354 if ( !screen_map.empty() )
355 cmd +=
" -m " + screen_map;
357 if ( !unicode_map.empty() )
358 cmd +=
" -u " + unicode_map;
360 yuiMilestone() << cmd << std::endl;
362 int ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
367 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
373 cmd =
"(echo -en \"\\033";
375 if ( console_magic.length() )
376 cmd += console_magic;
380 cmd +=
"\" >" + myTerm +
")";
382 yuiMilestone() << cmd << std::endl;
384 ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
388 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
397 if ( NCstring::terminalEncoding() !=
"UTF-8" )
399 std::string language = lang;
400 std::string::size_type pos = language.find(
'.' );
402 if ( pos != std::string::npos )
404 language.erase( pos );
407 pos = language.find(
'_' );
409 if ( pos != std::string::npos )
411 language.erase( pos );
414 std::string code = language2encoding( language );
416 yuiMilestone() <<
"setConsoleFont( ENCODING: " << code <<
" )" << std::endl;
418 if ( NCstring::setTerminalEncoding( code ) )
436 std::string
id = NCPopupTextEntry::askForText(
wpos( 0, 0 ),
437 _(
"Enter Widget ID:"),
444 return sendWidgetID(
id );
446 catch ( YUIWidgetNotFoundException & ex )
462 yuiDebug() <<
"Events blocked, ignoring event " <<
event << std::endl;
467 NCDialog *dialog =
dynamic_cast<NCDialog *
>(NCDialog::currentDialog(
false));
471 yuiDebug() <<
"Sending event: " <<
event << std::endl;
472 dialog->setPendingEvent(event);
476 yuiError() <<
"No dialog" << std::endl;
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 sendEvent(NCursesEvent event)
Send an event to the UI.
void handler(int sig_num)
handler, called by NCBusyIndicatorHandlerWrapper
YNCursesUI(bool withThreads, bool topmostConstructor=true)
Having boolean topmostConstructor to be called only when there is topmost constructor and not a plugi...
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.