25 #include <rpc/types.h>
33 #include <QSocketNotifier>
34 #include <QDesktopWidget>
38 #include <QMessageLogContext>
41 #define YUILogComponent "qt-ui"
42 #include <yui/YUILog.h>
43 #include <yui/Libyui_config.h>
47 #include <yui/YEvent.h>
48 #include <yui/YCommandLine.h>
49 #include <yui/YButtonBox.h>
50 #include <yui/YUISymbols.h>
52 #include "QY2Styler.h"
53 #include "YQApplication.h"
55 #include "YQWidgetFactory.h"
56 #include "YQOptionalWidgetFactory.h"
69 #define BUSY_CURSOR_TIMEOUT 200 // milliseconds
70 #define VERBOSE_EVENT_LOOP 0
74 static void qMessageHandler( QtMsgType type,
const QMessageLogContext &,
const QString & msg );
78 YUI * createUI(
bool withThreads )
84 if ( ui && ! withThreads )
97 , _do_exit_loop( false )
99 yuiDebug() <<
"YQUI constructor start" << std::endl;
100 yuiMilestone() <<
"This is libyui-qt " << VERSION << std::endl;
103 _uiInitialized =
false;
106 _usingVisionImpairedPalette =
false;
108 screenShotNameTemplate =
"";
111 qInstallMessageHandler( qMessageHandler );
113 yuiDebug() <<
"YQUI constructor finished" << std::endl;
115 topmostConstructorHasFinished();
121 if ( _uiInitialized )
124 _uiInitialized =
true;
125 yuiDebug() <<
"Initializing Qt part" << std::endl;
127 YCommandLine cmdLine;
128 std::string progName;
130 if ( cmdLine.argc() > 0 )
132 progName = cmdLine[0];
133 std::size_t lastSlashPos = progName.find_last_of(
'/' );
135 if ( lastSlashPos != std::string::npos )
136 progName = progName.substr( lastSlashPos+1 );
142 if ( progName ==
"y2base" )
143 cmdLine.replace( 0,
"YaST2" );
146 _ui_argc = cmdLine.argc();
147 char ** argv = cmdLine.argv();
152 yuiDebug() <<
"Creating QApplication" << std::endl;
153 new QApplication( _ui_argc, argv );
158 _busyCursorTimer =
new QTimer( _signalReceiver );
159 _busyCursorTimer->setSingleShot(
true );
161 _normalPalette = qApp->palette();
162 (void) QY2Styler::styler();
164 setButtonOrderFromEnvironment();
168 _do_exit_loop =
false;
176 _main_win =
new QWidget( 0, Qt::Window );
177 _main_win->setFocusPolicy( Qt::StrongFocus );
178 _main_win->setObjectName(
"main_window" );
180 _main_win->resize( _defaultSize );
183 _main_win->move( 0, 0 );
192 if ( progName ==
"y2base" )
193 _applicationTitle = QString(
"YaST2" );
195 _applicationTitle = fromUTF8( progName );
198 int displayArgPos = cmdLine.find(
"-display" );
201 if ( displayArgPos > 0 && displayArgPos+1 < cmdLine.argc() )
202 displayName = cmdLine[ displayArgPos+1 ].c_str();
204 displayName = getenv(
"DISPLAY" );
207 char hostname[ MAXHOSTNAMELEN+1 ];
208 if ( gethostname( hostname,
sizeof( hostname )-1 ) == 0 )
209 hostname[
sizeof( hostname ) -1 ] =
'\0';
214 if ( !displayName.startsWith(
":" ) && strlen( hostname ) > 0 )
216 _applicationTitle += QString(
"@" );
217 _applicationTitle += fromUTF8( hostname );
229 YButtonBoxMargins buttonBoxMargins;
230 buttonBoxMargins.left = 8;
231 buttonBoxMargins.right = 8;
232 buttonBoxMargins.top = 6;
233 buttonBoxMargins.bottom = 6;
235 buttonBoxMargins.spacing = 4;
236 buttonBoxMargins.helpButtonExtraSpacing = 16;
237 YButtonBox::setDefaultMargins( buttonBoxMargins );
259 QString qt_lib_name = QString( QTLIBDIR
"/libQtGui.so.%1" ).arg( QT_VERSION >> 16 );;
260 void * qt_lib = dlopen( qt_lib_name.toUtf8().constData(), RTLD_LAZY | RTLD_GLOBAL );
262 yuiMilestone() <<
"Forcing " << qt_lib_name.toUtf8().constData() <<
" open successful" << std::endl;
264 yuiError() <<
"Forcing " << qt_lib_name.toUtf8().constData() <<
" open failed" << std::endl;
268 qApp->setFont(
yqApp()->currentFont() );
272 QObject::connect( _busyCursorTimer, &pclass(_busyCursorTimer)::timeout,
273 _signalReceiver, &pclass(_signalReceiver)::slotBusyCursor );
275 yuiMilestone() <<
"YQUI initialized. Thread ID: 0x"
276 << hex << QThread::currentThreadId () << dec
279 qApp->processEvents();
294 for(
int i=0; i < argc; i++ )
296 QString opt = argv[i];
298 yuiMilestone() <<
"Qt argument: " << argv[i] << std::endl;
302 if ( opt.startsWith(
"--" ) )
305 if ( opt == QString(
"-fullscreen" ) ) _fullscreen =
true;
306 else if ( opt == QString(
"-noborder" ) ) _noborder =
true;
309 else if ( opt == QString(
"-gnome-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::gnomeLayoutPolicy() );
310 else if ( opt == QString(
"-kde-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::kdeLayoutPolicy() );
312 else if ( opt == QString(
"-help" ) )
315 "Command line options for the YaST2 Qt UI:\n"
317 "--nothreads run without additional UI threads\n"
318 "--fullscreen use full screen for `opt(`defaultsize) dialogs\n"
319 "--noborder no window manager border for `opt(`defaultsize) dialogs\n"
320 "--auto-fonts automatically pick fonts, disregard Qt standard settings\n"
321 "--help this help text\n"
323 "--macro <macro-file> play a macro right on startup\n"
325 "-no-wm, -noborder etc. are accepted as well as --no-wm, --noborder\n"
326 "to maintain backwards compatibility.\n"
342 yuiDebug() <<
"Closing down Qt UI." << std::endl;
353 delete _signalReceiver;
362 YUI_CHECK_NEW( factory );
369 YOptionalWidgetFactory *
373 YUI_CHECK_NEW( factory );
380 YQUI::createApplication()
383 YUI_CHECK_NEW( app );
391 QSize primaryScreenSize = qApp->desktop()->screenGeometry( qApp->desktop()->primaryScreen() ).size();
392 QSize availableSize = qApp->desktop()->availableGeometry( qApp->desktop()->primaryScreen() ).size();
396 _defaultSize = availableSize;
398 yuiMilestone() <<
"-fullscreen: using "
399 << _defaultSize.width() <<
" x " << _defaultSize.height()
400 <<
"for `opt(`defaultsize)"
409 if ( _defaultSize.width() < 800 ||
410 _defaultSize.height() < 600 )
412 if ( primaryScreenSize.width() >= 1024 && primaryScreenSize.height() >= 768 )
416 _defaultSize.setWidth ( max( (
int) (availableSize.width() * 0.7), 800 ) );
417 _defaultSize.setHeight( max( (
int) (availableSize.height() * 0.7), 600 ) );
421 _defaultSize = availableSize;
426 yuiMilestone() <<
"Forced size (via -geometry): "
427 << _defaultSize.width() <<
" x " << _defaultSize.height()
432 yuiMilestone() <<
"Default size: "
433 << _defaultSize.width() <<
" x " << _defaultSize.height()
442 _received_ycp_command =
false;
443 QSocketNotifier * notifier =
new QSocketNotifier( fd_ycp, QSocketNotifier::Read );
444 QObject::connect( notifier, &pclass(notifier)::activated,
445 _signalReceiver, &pclass(_signalReceiver)::slotReceivedYCPCommand );
447 notifier->setEnabled(
true );
454 #if VERBOSE_EVENT_LOOP
455 yuiDebug() <<
"Entering idle loop" << std::endl;
458 QEventLoop eventLoop( qApp );
460 while ( !_received_ycp_command )
461 eventLoop.processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents );
463 #if VERBOSE_EVENT_LOOP
464 yuiDebug() <<
"Leaving idle loop" << std::endl;
473 _received_ycp_command =
true;
481 _eventHandler.sendEvent( event );
491 yuiError() <<
"No dialog" << std::endl;
499 bindtextdomain( domain, YSettings::localeDir().c_str() );
500 bind_textdomain_codeset( domain,
"utf8" );
501 textdomain( domain );
505 extern int _nl_msg_cat_cntr;
517 if ( ++_blockedLevel == 1 )
519 _eventHandler.blockEvents(
true );
523 if ( dialog && dialog->
eventLoop()->isRunning() )
525 yuiWarning() <<
"blocking events in active event loop of " << dialog << std::endl;
532 if ( --_blockedLevel == 0 )
534 _eventHandler.blockEvents(
false );
549 _eventHandler.blockEvents(
false );
555 return _eventHandler.eventsBlocked();
561 qApp->setOverrideCursor( Qt::BusyCursor );
567 if ( _busyCursorTimer->isActive() )
568 _busyCursorTimer->stop();
570 while ( qApp->overrideCursor() )
571 qApp->restoreOverrideCursor();
580 _busyCursorTimer->start( BUSY_CURSOR_TIMEOUT );
586 return dim == YD_HORIZ ? _defaultSize.width() : _defaultSize.height();
592 int displayArgPos = cmdLine.find(
"-display" );
593 std::string displayNameStr;
595 if ( displayArgPos > 0 && displayArgPos+1 < cmdLine.argc() )
597 displayNameStr = cmdLine[ displayArgPos+1 ];
598 yuiMilestone() <<
"Using X11 display \"" << displayNameStr <<
"\"" << std::endl;
601 const char * displayName = ( displayNameStr.empty() ? 0 : displayNameStr.c_str() );
602 Display * display = XOpenDisplay( displayName );
606 yuiDebug() <<
"Probing X11 display successful" << std::endl;
607 XCloseDisplay( display );
611 string msg =
"Can't open display " + displayNameStr;
612 YUI_THROW( YUIException( msg ) );
619 _eventHandler.deletePendingEventsFor( widget );
625 if ( _usingVisionImpairedPalette )
629 _usingVisionImpairedPalette =
false;
635 _usingVisionImpairedPalette =
true;
643 const QColor dark ( 0x20, 0x20, 0x20 );
647 pal.setColor( QPalette::Active, QPalette::Background, Qt::black );
648 pal.setColor( QPalette::Active, QPalette::Foreground, Qt::cyan );
649 pal.setColor( QPalette::Active, QPalette::Text, Qt::cyan );
650 pal.setColor( QPalette::Active, QPalette::Base, dark );
651 pal.setColor( QPalette::Active, QPalette::Button, dark );
652 pal.setColor( QPalette::Active, QPalette::ButtonText, Qt::green );
653 pal.setColor( QPalette::Active, QPalette::Highlight, Qt::yellow );
654 pal.setColor( QPalette::Active, QPalette::HighlightedText, Qt::black );
657 pal.setColor( QPalette::Inactive, QPalette::Background, Qt::black );
658 pal.setColor( QPalette::Inactive, QPalette::Foreground, Qt::cyan );
659 pal.setColor( QPalette::Inactive, QPalette::Text, Qt::cyan );
660 pal.setColor( QPalette::Inactive, QPalette::Base, dark );
661 pal.setColor( QPalette::Inactive, QPalette::Button, dark );
662 pal.setColor( QPalette::Inactive, QPalette::ButtonText, Qt::green );
665 pal.setColor( QPalette::Disabled, QPalette::Background, Qt::black );
666 pal.setColor( QPalette::Disabled, QPalette::Foreground, Qt::gray );
667 pal.setColor( QPalette::Disabled, QPalette::Text, Qt::gray );
668 pal.setColor( QPalette::Disabled, QPalette::Base, dark );
669 pal.setColor( QPalette::Disabled, QPalette::Button, dark );
670 pal.setColor( QPalette::Disabled, QPalette::ButtonText, Qt::gray );
679 yuiMilestone() <<
"Closing application" << std::endl;
687 YQUISignalReceiver::YQUISignalReceiver()
693 void YQUISignalReceiver::slotBusyCursor()
699 void YQUISignalReceiver::slotReceivedYCPCommand()
707 qMessageHandler( QtMsgType type,
const QMessageLogContext &,
const QString & msg )
712 yuiMilestone() <<
"<libqt-debug> " << msg << std::endl;
716 yuiWarning() <<
"<libqt-warning> " << msg << std::endl;
720 yuiError() <<
"<libqt-critical>" << msg << std::endl;
724 yuiError() <<
"<libqt-fatal> " << msg << std::endl;
729 if ( QString( msg ).contains(
"Fatal IO error", Qt::CaseInsensitive ) &&
730 QString( msg ).contains(
"client killed", Qt::CaseInsensitive ) )
731 yuiError() <<
"Client killed. Possibly caused by X server shutdown or crash." << std::endl;
void receivedYCPCommand()
static YQApplication * yqApp()
void forceUnblockEvents()
int defaultSize(YUIDimension dim) const
void setAutoFonts(bool useAutoFonts)
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()
void sendEvent(YEvent *event)
virtual void idleLoop(int fd_ycp)
void probeX11Display(const YCommandLine &cmdLine)
virtual bool eventsBlocked() const
virtual void deleteNotify(YWidget *widget)
void processCommandLineArgs(int argc, char **argv)
static QPalette visionImpairedPalette()
QPalette normalPalette() const
virtual void blockEvents(bool block=true)
static void setTextdomain(const char *domain)
void toggleVisionImpairedPalette()
virtual YWidgetFactory * createWidgetFactory()