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 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
154 new QApplication( _ui_argc, argv );
159 _busyCursorTimer =
new QTimer( _signalReceiver );
160 _busyCursorTimer->setSingleShot(
true );
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 );
241 qApp->setFont(
yqApp()->currentFont() );
245 QObject::connect( _busyCursorTimer, &pclass(_busyCursorTimer)::timeout,
246 _signalReceiver, &pclass(_signalReceiver)::slotBusyCursor );
248 yuiMilestone() <<
"YQUI initialized. Thread ID: 0x" 249 << hex << QThread::currentThreadId () << dec
252 qApp->processEvents();
259 return static_cast<YQApplication *>( app() );
267 for(
int i=0; i < argc; i++ )
269 QString opt = argv[i];
271 yuiMilestone() <<
"Qt argument: " << argv[i] << std::endl;
275 if ( opt.startsWith(
"--" ) )
278 if ( opt == QString(
"-fullscreen" ) ) _fullscreen =
true;
279 else if ( opt == QString(
"-noborder" ) ) _noborder =
true;
282 else if ( opt == QString(
"-gnome-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::gnomeLayoutPolicy() );
283 else if ( opt == QString(
"-kde-button-order" ) ) YButtonBox::setLayoutPolicy( YButtonBox::kdeLayoutPolicy() );
285 else if ( opt == QString(
"-help" ) )
288 "Command line options for the YaST2 Qt UI:\n" 290 "--nothreads run without additional UI threads\n" 291 "--fullscreen use full screen for `opt(`defaultsize) dialogs\n" 292 "--noborder no window manager border for `opt(`defaultsize) dialogs\n" 293 "--auto-fonts automatically pick fonts, disregard Qt standard settings\n" 294 "--help this help text\n" 296 "--macro <macro-file> play a macro right on startup\n" 298 "-no-wm, -noborder etc. are accepted as well as --no-wm, --noborder\n" 299 "to maintain backwards compatibility.\n" 315 yuiMilestone() <<
"Closing down Qt UI." << std::endl;
326 delete _signalReceiver;
332 yuiMilestone() <<
"Destroying UI thread" << std::endl;
336 if ( YDialog::openDialogsCount() > 0 )
338 yuiError() << YDialog::openDialogsCount() <<
" open dialogs left over" << endl;
339 yuiError() <<
"Topmost dialog:" << endl;
340 YDialog::topmostDialog()->dumpWidgetTree();
343 YDialog::deleteAllDialogs();
354 YUI_CHECK_NEW( factory );
361 YOptionalWidgetFactory *
365 YUI_CHECK_NEW( factory );
372 YQUI::createApplication()
375 YUI_CHECK_NEW( app );
383 QSize primaryScreenSize = qApp->desktop()->screenGeometry( qApp->desktop()->primaryScreen() ).size();
384 QSize availableSize = qApp->desktop()->availableGeometry( qApp->desktop()->primaryScreen() ).size();
388 _defaultSize = availableSize;
390 yuiMilestone() <<
"-fullscreen: using " 391 << _defaultSize.width() <<
" x " << _defaultSize.height()
392 <<
"for `opt(`defaultsize)" 401 if ( _defaultSize.width() < 800 ||
402 _defaultSize.height() < 600 )
404 if ( primaryScreenSize.width() >= 1024 && primaryScreenSize.height() >= 768 )
408 _defaultSize.setWidth ( max( (
int) (availableSize.width() * 0.7), 800 ) );
409 _defaultSize.setHeight( max( (
int) (availableSize.height() * 0.7), 600 ) );
413 _defaultSize = availableSize;
418 yuiMilestone() <<
"Forced size (via -geometry): " 419 << _defaultSize.width() <<
" x " << _defaultSize.height()
424 yuiMilestone() <<
"Default size: " 425 << _defaultSize.width() <<
" x " << _defaultSize.height()
434 _received_ycp_command =
false;
435 QSocketNotifier * notifier =
new QSocketNotifier( fd_ycp, QSocketNotifier::Read );
436 QObject::connect( notifier, &pclass(notifier)::activated,
437 _signalReceiver, &pclass(_signalReceiver)::slotReceivedYCPCommand );
439 notifier->setEnabled(
true );
446 #if VERBOSE_EVENT_LOOP 447 yuiDebug() <<
"Entering idle loop" << std::endl;
450 QEventLoop eventLoop( qApp );
452 while ( !_received_ycp_command )
453 eventLoop.processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents );
455 #if VERBOSE_EVENT_LOOP 456 yuiDebug() <<
"Leaving idle loop" << std::endl;
465 _received_ycp_command =
true;
473 _eventHandler.sendEvent( event );
483 yuiError() <<
"No dialog" << std::endl;
491 bindtextdomain( domain, YSettings::localeDir().c_str() );
492 bind_textdomain_codeset( domain,
"utf8" );
493 textdomain( domain );
497 extern int _nl_msg_cat_cntr;
509 if ( ++_blockedLevel == 1 )
511 _eventHandler.blockEvents(
true );
515 if ( dialog && dialog->
eventLoop()->isRunning() )
517 yuiWarning() <<
"blocking events in active event loop of " << dialog << std::endl;
524 if ( --_blockedLevel == 0 )
526 _eventHandler.blockEvents(
false );
541 _eventHandler.blockEvents(
false );
547 return _eventHandler.eventsBlocked();
553 qApp->setOverrideCursor( Qt::BusyCursor );
559 if ( _busyCursorTimer->isActive() )
560 _busyCursorTimer->stop();
562 while ( qApp->overrideCursor() )
563 qApp->restoreOverrideCursor();
572 _busyCursorTimer->start( BUSY_CURSOR_TIMEOUT );
578 return dim == YD_HORIZ ? _defaultSize.width() : _defaultSize.height();
590 _eventHandler.deletePendingEventsFor( widget );
596 yuiMilestone() <<
"Closing application" << std::endl;
604 QWidget * parent = 0;
605 YDialog * dialog = YDialog::currentDialog(
false );
608 parent = (QWidget *) dialog->widgetRep();
610 QString
id = QInputDialog::getText( parent,
612 _(
"Enter Widget ID:" )
614 if ( !
id.isEmpty() )
618 YWidget * widget = sendWidgetID( toUTF8(
id ) );
619 YQGenericButton * yqButton = dynamic_cast<YQGenericButton *>( widget );
623 yuiMilestone() <<
"Activating " << widget << endl;
627 catch ( YUIWidgetNotFoundException & ex )
630 QMessageBox::warning( parent,
632 _(
"No widget with ID \"%1\"" ).arg(
id ) );
641 YQUISignalReceiver::YQUISignalReceiver()
647 void YQUISignalReceiver::slotBusyCursor()
653 void YQUISignalReceiver::slotReceivedYCPCommand()
661 qMessageHandler( QtMsgType type,
const QMessageLogContext &,
const QString & msg )
666 yuiMilestone() <<
"<libqt-debug> " << msg << std::endl;
669 #if QT_VERSION >= 0x050500 671 yuiMilestone() <<
"<libqt-info> " << msg << std::endl;
676 yuiWarning() <<
"<libqt-warning> " << msg << std::endl;
680 yuiError() <<
"<libqt-critical>" << msg << std::endl;
684 yuiError() <<
"<libqt-fatal> " << msg << std::endl;
689 if ( QString( msg ).contains(
"Fatal IO error", Qt::CaseInsensitive ) &&
690 QString( msg ).contains(
"client killed", Qt::CaseInsensitive ) )
691 yuiError() <<
"Client killed. Possibly caused by X server shutdown or crash." << std::endl;
694 QIcon YQUI::loadIcon(
const string & iconName )
const 697 const QString resource =
":/";
698 if ( QIcon::hasThemeIcon( iconName.c_str() ) )
700 yuiDebug() <<
"Trying theme icon from: " << iconName << std::endl;
701 icon = QIcon::fromTheme( iconName.c_str(), QIcon( resource + iconName.c_str() ) );
706 yuiDebug() <<
"Trying icon from resource: " << iconName << std::endl;
707 icon = QIcon( resource + iconName.c_str() );
713 yuiDebug() <<
"Trying icon from path: " << iconName << std::endl;
714 icon = QIcon( iconName.c_str() );
718 yuiWarning() <<
"Couldn't load icon: " << iconName << 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,...