26 #define VERBOSE_COMM 0 // VERY verbose thread communication logging
38 #define YUILogComponent "ui"
42 #include "YUILoader.h"
43 #include "YUISymbols.h"
45 #include "YApplication.h"
47 #include "YButtonBox.h"
49 #include "YBuiltinCaller.h"
50 #include "YWidgetID.h"
51 #include "YUIPlugin.h"
60 #define ENV_BUTTON_ORDER "Y2_BUTTON_ORDER"
69 static bool uiDeleted =
false;
71 extern void * start_ui_thread(
void * yui );
75 : _withThreads( withThreads )
78 , _terminate_ui_thread( false )
79 , _eventsBlocked( false )
81 yuiMilestone() <<
"This is libyui " << VERSION << endl;
82 yuiMilestone() <<
"Creating UI " << ( withThreads ?
"with" :
"without" ) <<
" threads" << endl;
94 yuiError() <<
"shutdownThreads() was never called!" << endl;
95 yuiError() <<
"shutting down now - this might segfault" << endl;
141 YUI_CHECK_PTR( factory );
156 YUI_CHECK_PTR( factory );
171 YUI_CHECK_PTR(
app );
210 if ( fcntl(
pipe_to_ui[0], F_SETFL, arg | O_NONBLOCK ) < 0 )
212 yuiError() <<
"Couldn't set O_NONBLOCK: errno: " << errno <<
" " << strerror( errno ) << endl;
222 yuiDebug() <<
"Inter-thread communication pipes set up" << endl;
230 yuiError() <<
"pipe() failed: errno: " << errno <<
" " << strerror( errno ) << endl;
236 yuiMilestone() <<
"Running without threads" << endl;
244 pthread_attr_init( & attr );
245 int ret = pthread_create( &
_uiThread, & attr, start_ui_thread,
this );
248 yuiError() <<
"pthread_create() failed: " << errno <<
" " << strerror( errno ) << endl;
254 yuiDebug() <<
"Sending shutdown message to UI thread" << endl;
261 yuiDebug() <<
"UI thread shut down correctly" << endl;
281 static char arbitrary = 42;
282 if ( write (
pipe_to_ui[1], & arbitrary, 1 ) == -1 )
283 yuiError() <<
"Writing byte to UI thread failed" << endl;
286 yuiDebug() <<
"Wrote byte to UI thread" << endl;
298 yuiDebug() <<
"Waiting for ui thread..." << endl;
303 if ( errno == EINTR || errno == EAGAIN )
306 yuiError() <<
"waitForUIThread: errno: " << errno <<
" " << strerror( errno ) << endl;
308 }
while ( result == 0 );
311 yuiDebug() <<
"Read byte from ui thread" << endl;
321 static char arbitrary;
323 yuiError() <<
"Writing byte to YCP thread failed" << endl;
326 yuiDebug() <<
"Wrote byte to YCP thread" << endl;
338 yuiDebug() <<
"Waiting for YCP thread..." << endl;
340 result = read(
pipe_to_ui[0], & arbitrary, 1 );
343 if ( errno == EINTR || errno == EAGAIN )
346 yuiError() <<
"waitForYCPThread: errno: " << errno <<
" " << strerror( errno ) << endl;
348 }
while ( result == 0 );
351 yuiDebug() <<
"Read byte from YCP thread" << endl;
378 yuiDebug() <<
"Shutting down UI main loop" << endl;
385 yuiError() <<
"No builtinCaller set" << endl;
395 YButtonOrder oldButtonOrder = buttonOrder;
403 YEnvVar env(
"DESKTOP_SESSION" );
404 yuiDebug() << env << endl;
409 buttonOrder = YKDEButtonOrder;
412 else if ( env ==
"gnome" )
414 buttonOrder = YGnomeButtonOrder;
422 env =
YEnvVar(
"WINDOWMANAGER" );
423 yuiDebug() << env << endl;
427 buttonOrder = YGnomeButtonOrder;
432 buttonOrder = YKDEButtonOrder;
441 env =
YEnvVar( ENV_BUTTON_ORDER );
442 yuiDebug() << env << endl;
444 if ( env ==
"gnome" )
446 buttonOrder = YGnomeButtonOrder;
449 else if ( env ==
"kde" )
451 buttonOrder = YKDEButtonOrder;
454 else if ( ! env.
value().empty() )
456 yuiWarning() <<
"Ignoring unknown value of " << env << endl;
460 if ( buttonOrder != oldButtonOrder )
462 string buttonOrderStr;
464 switch ( buttonOrder )
466 case YKDEButtonOrder:
467 buttonOrderStr =
"KDE";
471 case YGnomeButtonOrder:
472 buttonOrderStr =
"GNOME";
479 yuiMilestone() <<
"Switching to " << buttonOrderStr
480 <<
" button order because of " << lastEnv
489 yuiMilestone() <<
"Sending ID \"" << id_str <<
"\"" << endl;
515 void * start_ui_thread(
void * yui )
520 yuiDebug() <<
"Starting UI thread" << endl;
int pipe_from_ui[2]
Used to synchronize data transfer with the ui thread.
static void deleteAllDialogs()
Delete all open dialogs.
virtual ~YUI()
Destructor.
void terminateUIThread()
Tells the ui thread that it should terminate and waits until it does so.
Abstract base class of a libYUI user interface.
static YUI * ui()
Access the global UI.
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
bool _terminate_ui_thread
This is a flag that signals the ui thread that it should terminate.
void shutdownThreads()
Shut down multithreading.
void setButtonOrderFromEnvironment()
Set the button order (in YButtonBox widgets) from environment variables:
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for optional ("special") widgets a...
static YOptionalWidgetFactory * optionalWidgetFactory()
Return the widget factory that provides all the createXY() methods for optional ("special") widgets a...
YWidget * sendWidgetID(const std::string &id)
Send a widget ID.
YBuiltinCaller * _builtinCaller
Inter-thread communication between the YCP thread and the UI thread: The YCP thread supplies data her...
virtual void call()=0
Call the built-in.
static void deleteRecorder()
Delete the current macro recorder if there is one.
bool waitForYCPThread()
Waits for the ycp thread to send one byte through the pipe to the ycp thread and reads this byte from...
Class for application-wide values and functions.
bool contains(const std::string &str, bool caseSensitive=false) const
Return 'true' if the environment variable is set and the value contains 'str'.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
bool waitForUIThread()
Waits for the ui thread to send one byte through the pipe to the ycp thread and reads this byte from ...
virtual YWidgetFactory * createWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for standard (mandatory,...
Helper class to represent an environment variable and its value.
virtual YApplication * createApplication()=0
Create the YApplication object that provides global methods.
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack.
void signalUIThread()
Signals the ui thread by sending one byte through the pipe to it.
void createUIThread()
Creates and launches the ui thread.
void topmostConstructorHasFinished()
Must be called after the constructor of the Qt/NCurses ui is ready.
static YApplication * app()
Return the global YApplication object.
virtual void idleLoop(int fd_ycp)=0
This virtual method is called when threads are activated in case the execution control is currently o...
virtual void uiThreadDestructor()
Destructor for the UI thread.
YUI(bool withThreads)
Constructor.
bool _withThreads
true if a seperate UI thread is created
static void ensureUICreated()
Make sure there is a UI (with a UI plug-in) created.
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory,...
static void deletePlayer()
Delete the current macro player if there is one.
pthread_t _uiThread
Handle to the ui thread.
Base class for UI Exceptions.
A window in the desktop environment.
void signalYCPThread()
Signals the ycp thread by sending one byte through the pipe to it.
std::string value() const
Return the value of the environment variable.
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
int pipe_to_ui[2]
Used to synchronize data transfer with the ui thread.
void uiThreadMainLoop()
This method implements the UI thread in case it is existing.