libyui

/data/gitorious.org/libyui/libyui-master/src/YUI.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YUI.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YUI_h
00041 #define YUI_h
00042 
00043 #include <pthread.h>
00044 #include <string>
00045 
00046 #include "YTypes.h"
00047 
00048 using std::string;
00049 
00050 class YApplication;
00051 class YWidget;
00052 class YWidgetFactory;
00053 class YOptionalWidgetFactory;
00054 class YEvent;
00055 class YBuiltinCaller;
00056 class YDialog;
00057 class YMacroPlayer;
00058 class YMacroRecorder;
00059 
00060 
00064 class YUI
00065 {
00066     friend class YUIFunction;
00067     friend class YUITerminator;
00068 
00069 protected:
00073     YUI( bool withThreads );
00074 
00075 public:
00076 
00080     virtual ~YUI();
00081 
00087     void shutdownThreads();
00088 
00092     static YUI * ui();
00093 
00102     static YWidgetFactory * widgetFactory();
00103 
00113     static YOptionalWidgetFactory * optionalWidgetFactory();
00114 
00123     static YApplication * app();
00124 
00128     static YApplication * application() { return app(); }
00129     static YApplication * yApp()        { return app(); }
00130 
00137     static void ensureUICreated();
00138 
00139     
00140 protected:
00141     
00148     virtual YWidgetFactory * createWidgetFactory() = 0;
00149 
00157     virtual YOptionalWidgetFactory * createOptionalWidgetFactory() = 0;
00158 
00164     virtual YApplication * createApplication() = 0;
00165 
00166     
00167 public:
00168 
00177     virtual void blockEvents( bool block = true ) { _eventsBlocked = block; }
00178 
00185     void unblockEvents() { blockEvents( false ); }
00186 
00192     virtual bool eventsBlocked() const { return _eventsBlocked; }
00193 
00201     virtual void deleteNotify( YWidget * widget ) {}
00202 
00207     void topmostConstructorHasFinished();
00208 
00212     bool runningWithThreads() const { return _withThreads; }
00213 
00222     void uiThreadMainLoop();
00223 
00228     YBuiltinCaller * builtinCaller() const { return _builtinCaller; }
00229 
00234     void setBuiltinCaller( YBuiltinCaller * caller )
00235         { _builtinCaller = caller; }
00236 
00247     virtual YEvent * runPkgSelection( YWidget * packageSelector ) = 0;
00248 
00249 
00250 protected:
00251 
00266     virtual void idleLoop( int fd_ycp ) = 0;
00267 
00272     void terminateUIThread();
00273 
00277     void createUIThread();
00278     friend void *start_ui_thread( void *ui_int );
00279 
00287     virtual void uiThreadDestructor();
00288 
00293     void signalUIThread();
00294 
00299     bool waitForUIThread();
00300 
00305     void signalYCPThread();
00306 
00311     bool waitForYCPThread();
00312 
00322     void setButtonOrderFromEnvironment();
00323 
00324 
00325     //
00326     // Data members
00327     //
00328 
00332     bool _withThreads;
00333 
00337     pthread_t _uiThread;
00338 
00346     YBuiltinCaller * _builtinCaller;
00347 
00353     int pipe_to_ui[2];
00354 
00360     int pipe_from_ui[2];
00361 
00368     bool _terminate_ui_thread;
00369 
00374     bool _eventsBlocked;
00375 
00376 private:
00377     
00378     static YUI * _ui;
00379 };
00380 
00381 
00382 
00383 #endif // YUI_h
 All Classes Functions Variables Enumerations Friends