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" 56 #define ENV_BUTTON_ORDER "Y2_BUTTON_ORDER" 65 static bool uiDeleted =
false;
67 extern void * start_ui_thread(
void * yui );
71 : _withThreads( withThreads )
74 , _terminate_ui_thread( false )
75 , _eventsBlocked( false )
77 yuiMilestone() <<
"This is libyui " << VERSION << std::endl;
78 yuiMilestone() <<
"Creating UI " << ( withThreads ?
"with" :
"without" ) <<
" threads" << endl;
89 yuiError() <<
"shutdownThreads() was never called!" << endl;
90 yuiError() <<
"shutting down now - this might segfault" << endl;
136 YUI_CHECK_PTR( factory );
151 YUI_CHECK_PTR( factory );
166 YUI_CHECK_PTR( app );
205 if ( fcntl(
pipe_to_ui[0], F_SETFL, arg | O_NONBLOCK ) < 0 )
207 yuiError() <<
"Couldn't set O_NONBLOCK: errno: " << errno <<
" " << strerror( errno ) << endl;
217 yuiDebug() <<
"Inter-thread communication pipes set up" << endl;
225 yuiError() <<
"pipe() failed: errno: " << errno <<
" " << strerror( errno ) << endl;
231 yuiMilestone() <<
"Running without threads" << endl;
239 pthread_attr_init( & attr );
240 int ret = pthread_create( &
_uiThread, & attr, start_ui_thread,
this );
243 yuiError() <<
"pthread_create() failed: " << errno <<
" " << strerror( errno ) << endl;
249 yuiDebug() <<
"Sending shutdown message to UI thread" << endl;
256 yuiDebug() <<
"UI thread shut down correctly" << endl;
276 static char arbitrary = 42;
277 if ( write (
pipe_to_ui[1], & arbitrary, 1 ) == -1 )
278 yuiError() <<
"Writing byte to UI thread failed" << endl;
281 yuiDebug() <<
"Wrote byte to UI thread" << endl;
293 yuiDebug() <<
"Waiting for ui thread..." << endl;
298 if ( errno == EINTR || errno == EAGAIN )
301 yuiError() <<
"waitForUIThread: errno: " << errno <<
" " << strerror( errno ) << endl;
303 }
while ( result == 0 );
306 yuiDebug() <<
"Read byte from ui thread" << endl;
316 static char arbitrary;
318 yuiError() <<
"Writing byte to YCP thread failed" << endl;
321 yuiDebug() <<
"Wrote byte to YCP thread" << endl;
333 yuiDebug() <<
"Waiting for YCP thread..." << endl;
335 result = read(
pipe_to_ui[0], & arbitrary, 1 );
338 if ( errno == EINTR || errno == EAGAIN )
341 yuiError() <<
"waitForYCPThread: errno: " << errno <<
" " << strerror( errno ) << endl;
343 }
while ( result == 0 );
346 yuiDebug() <<
"Read byte from YCP thread" << endl;
373 yuiDebug() <<
"Shutting down UI main loop" << endl;
380 yuiError() <<
"No builtinCaller set" << endl;
390 YButtonOrder oldButtonOrder = buttonOrder;
398 YEnvVar env(
"DESKTOP_SESSION" );
399 yuiDebug() << env << endl;
404 buttonOrder = YKDEButtonOrder;
407 else if ( env ==
"gnome" )
409 buttonOrder = YGnomeButtonOrder;
417 env =
YEnvVar(
"WINDOWMANAGER" );
418 yuiDebug() << env << endl;
422 buttonOrder = YGnomeButtonOrder;
427 buttonOrder = YKDEButtonOrder;
436 env =
YEnvVar( ENV_BUTTON_ORDER );
437 yuiDebug() << env << endl;
439 if ( env ==
"gnome" )
441 buttonOrder = YGnomeButtonOrder;
444 else if ( env ==
"kde" )
446 buttonOrder = YKDEButtonOrder;
449 else if ( ! env.
value().empty() )
451 yuiWarning() <<
"Ignoring unknown value of " << env << endl;
455 if ( buttonOrder != oldButtonOrder )
457 std::string buttonOrderStr;
459 switch ( buttonOrder )
461 case YKDEButtonOrder:
462 buttonOrderStr =
"KDE";
466 case YGnomeButtonOrder:
467 buttonOrderStr =
"GNOME";
474 yuiMilestone() <<
"Switching to " << buttonOrderStr
475 <<
" button order because of " << lastEnv
484 yuiMilestone() <<
"Sending ID \"" << id_str <<
"\"" << endl;
510 void * start_ui_thread(
void * yui )
515 yuiDebug() <<
"Starting UI thread" << endl;
int pipe_from_ui[2]
Used to synchronize data transfer with the ui thread.
void setButtonOrderFromEnvironment()
Set the button order (in YButtonBox widgets) from environment variables:
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
Abstract base class of a libYUI user interface.
void createUIThread()
Creates and launches the ui thread.
virtual YApplication * createApplication()=0
Create the YApplication object that provides global methods.
void topmostConstructorHasFinished()
Must be called after the constructor of the Qt/NCurses ui is ready.
int pipe_to_ui[2]
Used to synchronize data transfer with the ui thread.
void terminateUIThread()
Tells the ui thread that it should terminate and waits until it does so.
static void deletePlayer()
Delete the current macro player if there is one.
YWidget * sendWidgetID(const std::string &id)
Send a widget ID.
bool _withThreads
true if a seperate UI thread is created
std::string value() const
Return the value of the environment variable.
void signalUIThread()
Signals the ui thread by sending one byte through the pipe to it.
static void ensureUICreated()
Make sure there is a UI (with a UI plug-in) created.
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for optional ("special") widgets a...
virtual void uiThreadDestructor()
Destructor for the UI thread.
void shutdownThreads()
Shut down multithreading.
bool waitForYCPThread()
Waits for the ycp thread to send one byte through the pipe to the ycp thread and reads this byte from...
void uiThreadMainLoop()
This method implements the UI thread in case it is existing.
static void deleteAllDialogs()
Delete all open dialogs.
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
Helper class to represent an environment variable and its value.
Class for application-wide values and functions.
static YOptionalWidgetFactory * optionalWidgetFactory()
Return the widget factory that provides all the createXY() methods for optional ("special") widgets a...
bool contains(const std::string &str, bool caseSensitive=false) const
Return 'true' if the environment variable is set and the value contains 'str'.
virtual void call()=0
Call the built-in.
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack...
bool waitForUIThread()
Waits for the ui thread to send one byte through the pipe to the ycp thread and reads this byte from ...
void signalYCPThread()
Signals the ycp thread by sending one byte through the pipe to it.
virtual ~YUI()
Destructor.
static YApplication * app()
Return the global YApplication object.
virtual YWidgetFactory * createWidgetFactory()=0
Create the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
bool _terminate_ui_thread
This is a flag that signals the ui thread that it should terminate.
A window in the desktop environment.
YUI(bool withThreads)
Constructor.
pthread_t _uiThread
Handle to the ui thread.
static YUI * ui()
Access the global UI.
Base class for UI Exceptions.
virtual void idleLoop(int fd_ycp)=0
This virtual method is called when threads are activated in case the execution control is currently o...
static void loadUI(bool withThreads=false)
Load any of the available UI-plugins by this order and criteria:
static void deleteRecorder()
Delete the current macro recorder if there is one.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
YBuiltinCaller * _builtinCaller
Inter-thread communication between the YCP thread and the UI thread: The YCP thread supplies data her...