25 #include <sys/param.h> 33 #include <QSocketNotifier> 34 #include <QDesktopWidget> 38 #include <QMessageLogContext> 39 #include <QMessageBox> 40 #include <QInputDialog> 43 #define YUILogComponent "qt-ui" 44 #include <yui/YUILog.h> 45 #include <yui/Libyui_config.h> 49 #include <yui/YEvent.h> 50 #include <yui/YCommandLine.h> 51 #include <yui/YButtonBox.h> 52 #include <yui/YUISymbols.h> 54 #include "QY2Styler.h" 55 #include "YQApplication.h" 57 #include "YQWidgetFactory.h" 58 #include "YQOptionalWidgetFactory.h" 60 #include "YQWizardButton.h" 73 #define BUSY_CURSOR_TIMEOUT 200 // milliseconds 74 #define VERBOSE_EVENT_LOOP 0 78 static void qMessageHandler( QtMsgType type,
const QMessageLogContext &,
const QString & msg );
82 YUI * createUI(
bool withThreads )
88 if ( ui && ! withThreads )
101 , _do_exit_loop( false )
103 yuiDebug() <<
"YQUI constructor start" << std::endl;
104 yuiMilestone() <<
"This is libyui-qt " << VERSION << std::endl;
107 _uiInitialized =
false;
111 screenShotNameTemplate =
"";
114 qInstallMessageHandler( qMessageHandler );
116 yuiDebug() <<
"YQUI constructor finished" << std::endl;
118 topmostConstructorHasFinished();
124 if ( _uiInitialized )
127 _uiInitialized =
true;
128 yuiDebug() <<
"Initializing Qt part" << std::endl;
130 YCommandLine cmdLine;
131 std::string progName;
133 if ( cmdLine.argc() > 0 )
135 progName = cmdLine[0];
136 std::size_t lastSlashPos = progName.find_last_of(
'/' );
138 if ( lastSlashPos != std::string::npos )
139 progName = progName.substr( lastSlashPos+1 );
145 if ( progName ==
"y2base" )
146 cmdLine.replace( 0,
"YaST2" );
149 _ui_argc = cmdLine.argc();
150 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 (void) QY2Styler::styler();
163 setButtonOrderFromEnvironment();
167 _do_exit_loop =
false;
175 _main_win =
new QWidget( 0, Qt::Window );
176 _main_win->setFocusPolicy( Qt::StrongFocus );
177 _main_win->setObjectName(
"main_window" );
179 _main_win->resize( _defaultSize );
182 _main_win->move( 0, 0 );
191 if ( progName ==
"y2base" )
192 _applicationTitle = QString(
"YaST2" );
194 _applicationTitle = fromUTF8( progName );
197 int displayArgPos = cmdLine.find(
"-display" );
200 if ( displayArgPos > 0 && displayArgPos+1 < cmdLine.argc() )
201 displayName = cmdLine[ displayArgPos+1 ].c_str();
203 displayName = getenv(
"DISPLAY" );
206 char hostname[ MAXHOSTNAMELEN+1 ];
207 if ( gethostname( hostname,
sizeof( hostname )-1 ) == 0 )
208 hostname[
sizeof( hostname ) -1 ] =
'\0';
213 if ( !displayName.startsWith(
":" ) && strlen( hostname ) > 0 )
215 _applicationTitle += QString(
"@" );
216 _applicationTitle += fromUTF8( hostname );
228 YButtonBoxMargins buttonBoxMargins;
229 buttonBoxMargins.left = 8;
230 buttonBoxMargins.right = 8;
231 buttonBoxMargins.top = 6;
232 buttonBoxMargins.bottom = 6;
234 buttonBoxMargins.spacing = 4;
235 buttonBoxMargins.helpButtonExtraSpacing = 16;
236 YButtonBox::setDefaultMargins( buttonBoxMargins );
240 qApp->setFont(
yqApp()->currentFont() );
244 QObject::connect( _busyCursorTimer, &pclass(_busyCursorTimer)::timeout,
245 _signalReceiver, &pclass(_signalReceiver)::slotBusyCursor );
247 yuiMilestone() <<
"YQUI initialized. Thread ID: 0x" 248 << hex << QThread::currentThreadId () << dec
251 qApp->processEvents();
266 for(
int i=0; i < argc; i++ )
268 QString opt = argv[i];
270 yuiMilestone() <<
"Qt argument: " << argv[i] << std::endl;
274 if ( opt.startsWith(
"--" ) )
277 if ( opt == QString(
"-fullscreen" ) ) _fullscreen =
true;
278 else if ( opt == QString(
"-noborder" ) ) _noborder =
true;
281 else if ( opt == QString(
"-gnome-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::gnomeLayoutPolicy() );
282 else if ( opt == QString(
"-kde-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::kdeLayoutPolicy() );
284 else if ( opt == QString(
"-help" ) )
287 "Command line options for the YaST2 Qt UI:\n" 289 "--nothreads run without additional UI threads\n" 290 "--fullscreen use full screen for `opt(`defaultsize) dialogs\n" 291 "--noborder no window manager border for `opt(`defaultsize) dialogs\n" 292 "--auto-fonts automatically pick fonts, disregard Qt standard settings\n" 293 "--help this help text\n" 295 "--macro <macro-file> play a macro right on startup\n" 297 "-no-wm, -noborder etc. are accepted as well as --no-wm, --noborder\n" 298 "to maintain backwards compatibility.\n" 314 yuiMilestone() <<
"Closing down Qt UI." << std::endl;
325 delete _signalReceiver;
331 yuiMilestone() <<
"Destroying UI thread" << std::endl;
335 if ( YDialog::openDialogsCount() > 0 )
337 yuiError() << YDialog::openDialogsCount() <<
" open dialogs left over" << endl;
338 yuiError() <<
"Topmost dialog:" << endl;
339 YDialog::topmostDialog()->dumpWidgetTree();
342 YDialog::deleteAllDialogs();
353 YUI_CHECK_NEW( factory );
360 YOptionalWidgetFactory *
364 YUI_CHECK_NEW( factory );
371 YQUI::createApplication()
374 YUI_CHECK_NEW( app );
382 QSize primaryScreenSize = qApp->desktop()->screenGeometry( qApp->desktop()->primaryScreen() ).size();
383 QSize availableSize = qApp->desktop()->availableGeometry( qApp->desktop()->primaryScreen() ).size();
387 _defaultSize = availableSize;
389 yuiMilestone() <<
"-fullscreen: using " 390 << _defaultSize.width() <<
" x " << _defaultSize.height()
391 <<
"for `opt(`defaultsize)" 400 if ( _defaultSize.width() < 800 ||
401 _defaultSize.height() < 600 )
403 if ( primaryScreenSize.width() >= 1024 && primaryScreenSize.height() >= 768 )
407 _defaultSize.setWidth ( max( (
int) (availableSize.width() * 0.7), 800 ) );
408 _defaultSize.setHeight( max( (
int) (availableSize.height() * 0.7), 600 ) );
412 _defaultSize = availableSize;
417 yuiMilestone() <<
"Forced size (via -geometry): " 418 << _defaultSize.width() <<
" x " << _defaultSize.height()
423 yuiMilestone() <<
"Default size: " 424 << _defaultSize.width() <<
" x " << _defaultSize.height()
433 _received_ycp_command =
false;
434 QSocketNotifier * notifier =
new QSocketNotifier( fd_ycp, QSocketNotifier::Read );
435 QObject::connect( notifier, &pclass(notifier)::activated,
436 _signalReceiver, &pclass(_signalReceiver)::slotReceivedYCPCommand );
438 notifier->setEnabled(
true );
445 #if VERBOSE_EVENT_LOOP 446 yuiDebug() <<
"Entering idle loop" << std::endl;
449 QEventLoop eventLoop( qApp );
451 while ( !_received_ycp_command )
452 eventLoop.processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents );
454 #if VERBOSE_EVENT_LOOP 455 yuiDebug() <<
"Leaving idle loop" << std::endl;
464 _received_ycp_command =
true;
472 _eventHandler.sendEvent( event );
482 yuiError() <<
"No dialog" << std::endl;
490 bindtextdomain( domain, YSettings::localeDir().c_str() );
491 bind_textdomain_codeset( domain,
"utf8" );
492 textdomain( domain );
496 extern int _nl_msg_cat_cntr;
508 if ( ++_blockedLevel == 1 )
510 _eventHandler.blockEvents(
true );
514 if ( dialog && dialog->
eventLoop()->isRunning() )
516 yuiWarning() <<
"blocking events in active event loop of " << dialog << std::endl;
523 if ( --_blockedLevel == 0 )
525 _eventHandler.blockEvents(
false );
540 _eventHandler.blockEvents(
false );
546 return _eventHandler.eventsBlocked();
552 qApp->setOverrideCursor( Qt::BusyCursor );
558 if ( _busyCursorTimer->isActive() )
559 _busyCursorTimer->stop();
561 while ( qApp->overrideCursor() )
562 qApp->restoreOverrideCursor();
571 _busyCursorTimer->start( BUSY_CURSOR_TIMEOUT );
577 return dim == YD_HORIZ ? _defaultSize.width() : _defaultSize.height();
589 _eventHandler.deletePendingEventsFor( widget );
595 yuiMilestone() <<
"Closing application" << std::endl;
603 QWidget * parent = 0;
604 YDialog * dialog = YDialog::currentDialog(
false );
607 parent = (QWidget *) dialog->widgetRep();
609 QString
id = QInputDialog::getText( parent,
611 _(
"Enter Widget ID:" )
613 if ( !
id.isEmpty() )
617 YWidget * widget = sendWidgetID( toUTF8(
id ) );
622 yuiMilestone() <<
"Activating " << widget << endl;
626 catch ( YUIWidgetNotFoundException & ex )
629 QMessageBox::warning( parent,
631 _(
"No widget with ID \"%1\"" ).arg(
id ) );
640 YQUISignalReceiver::YQUISignalReceiver()
646 void YQUISignalReceiver::slotBusyCursor()
652 void YQUISignalReceiver::slotReceivedYCPCommand()
660 qMessageHandler( QtMsgType type,
const QMessageLogContext &,
const QString & msg )
665 yuiMilestone() <<
"<libqt-debug> " << msg << std::endl;
668 #if QT_VERSION >= 0x050500 670 yuiMilestone() <<
"<libqt-info> " << msg << std::endl;
675 yuiWarning() <<
"<libqt-warning> " << msg << std::endl;
679 yuiError() <<
"<libqt-critical>" << msg << std::endl;
683 yuiError() <<
"<libqt-fatal> " << msg << std::endl;
688 if ( QString( msg ).contains(
"Fatal IO error", Qt::CaseInsensitive ) &&
689 QString( msg ).contains(
"client killed", Qt::CaseInsensitive ) )
690 yuiError() <<
"Client killed. Possibly caused by X server shutdown or crash." << std::endl;
int defaultSize(YUIDimension dim) const
Returns size for opt(defaultsize) dialogs (in one dimension).
void receivedYCPCommand()
Notification that a YCP command has been received on fd_ycp to leave idleLoop()
static YQApplication * yqApp()
Return the global YApplication object as YQApplication.
void forceUnblockEvents()
Force unblocking all events, no matter how many times blockEvents() has This returns 0 if there is no...
void setAutoFonts(bool useAutoFonts)
Set whether or not fonts should automatically be picked.
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()
Create the widget factory that provides all the createXY() methods for optional ("special") widgets a...
void askSendWidgetID()
Open a pop-up dialog to ask the user for a widget ID and then send it with sendWidgetID().
void calcDefaultSize()
Calculate size of opt(defaultsize) dialogs.
QEventLoop * eventLoop()
Access to this dialog's event loop.
Helper class that acts as a Qt signal receiver for YQUI.
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
YQUI(bool withThreads)
Constructor.
virtual void idleLoop(int fd_ycp)
Idle around until fd_ycp is readable and handle repaints.
void probeX11Display(const YCommandLine &cmdLine)
Probe the X11 display.
virtual void deleteNotify(YWidget *widget)
Notification that a widget is being deleted.
void busyCursor()
Show mouse cursor indicating busy state.
void processCommandLineArgs(int argc, char **argv)
Handle command line args.
virtual void uiThreadDestructor()
Destroy whatever needs to be destroyed within the UI thread.
virtual void blockEvents(bool block=true)
Block (or unblock) events.
void timeoutBusyCursor()
Show mouse cursor indicating busy state if the UI is unable to respond to user input for more than a ...
bool close()
Application shutdown.
void normalCursor()
Show normal mouse cursor not indicating busy status.
void initUI()
Post-constructor initialization.
virtual ~YQUI()
Destructor.
void raiseFatalError()
Raise a fatal UI error.
static void setTextdomain(const char *domain)
Initialize and set a textdomain for gettext()
static YQUI * ui()
Access the global Qt-UI.
virtual bool eventsBlocked() const
Returns 'true' if events are currently blocked.
virtual YWidgetFactory * createWidgetFactory()
Create the widget factory that provides all the createXY() methods for standard (mandatory, i.e.