[yast-commit] r39873 - in /branches/tmp/sh/qt4-port/qt/src: Makefile.am YQUIThreadHandler.cc YQUIThreadHandler.h
Author: sh-sh-sh Date: Wed Aug 1 15:34:06 2007 New Revision: 39873 URL: http://svn.opensuse.org/viewcvs/yast?rev=39873&view=rev Log: added generic thread handler Added: branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.cc branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.h Modified: branches/tmp/sh/qt4-port/qt/src/Makefile.am Modified: branches/tmp/sh/qt4-port/qt/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/qt4-port/qt/src/Makefile.am?rev=39873&r1=39872&r2=39873&view=diff ============================================================================== --- branches/tmp/sh/qt4-port/qt/src/Makefile.am (original) +++ branches/tmp/sh/qt4-port/qt/src/Makefile.am Wed Aug 1 15:34:06 2007 @@ -45,6 +45,7 @@ YQUI_widgets.cc \ YQUI_builtins.cc \ YQUI_x11.cc \ + YQUIThreadHandler.cc \ YQPackageSelectorPlugin.cc \ \ YQIconPool.cc \ @@ -115,6 +116,7 @@ BUILT_SOURCES = \ YQUI.moc \ + YQUIThreadHandler.moc \ \ YQAlignment.moc \ YQBarGraph.moc \ @@ -167,6 +169,8 @@ YQUI_builtins.o YQUI_builtins.lo: YQUI.moc YQUI_x11.o YQUI_x11.lo: YQUI.moc +YQUIThreadHandler.o YQUIThreadHandler.lo: YQUIThreadHandler.moc + YQAlignment.o YQAlignment.lo: YQAlignment.moc YQBarGraph.o YQBarGraph.lo: YQBarGraph.moc YQCheckBox.o YQCheckBox.lo: YQCheckBox.moc @@ -217,6 +221,7 @@ YQUI.moc: YQUI.h +YQUIThreadHandler.moc: YQUIThreadHandler.h YQAlignment.moc: YQAlignment.h YQBarGraph.moc: YQBarGraph.h Added: branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.cc?rev=39873&view=auto ============================================================================== --- branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.cc (added) +++ branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.cc Wed Aug 1 15:34:06 2007 @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YQUIThreadHandler.cc + + Authors: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#define y2log_component "qt-ui" +#include <ycp/y2log.h> + +#include "qthread.h" +#include "YQUIThreadHandler.h" + + +YQUIThreadHandler::YQUIThreadHandler( voidPtrFunction startFunc, + void * startFuncArg ) + : YUIThreadHandler( startFunc, startFuncArg ) + , _yquiThread( 0 ) +{ +} + + +YQUIThreadHandler::~YQUIThreadHandler() +{ + if ( _yquiThread ) + delete _yquiThread; +} + + +void YQUIThreadHandler::startUIThread() +{ + y2debug( "Starting UI thread" ); + + if ( ! _yquiThread ) + _yquiThread = new YQUIThread( _startFunc, _startFuncArg ); + + _yquiThread->start(); + _uiThreadRunning = true; +} + + +void YQUIThreadHandler::terminateUIThread() +{ + y2debug( "Terminating UI thread" ); + + if ( _yquiThread ) + _yquiThread->terminate(); + + _uiThreadRunning = false; +} + + +#include "YQUIThreadHandler.moc" Added: branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.h?rev=39873&view=auto ============================================================================== --- branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.h (added) +++ branches/tmp/sh/qt4-port/qt/src/YQUIThreadHandler.h Wed Aug 1 15:34:06 2007 @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YQUIThreadHandler.h + + Authors: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YQUIThreadHandler_h +#define YQUIThreadHandler_h + +#include <YUIThreadHandler.h> + + +#include "qthread.h" + +class YQUIThread; + + +/** + * Helper class to manage UI threads based on QThread. + **/ +class YQUIThreadHandler: public YUIThreadHandler +{ +public: + + /** + * Constructor. Takes the function to be started upon startThread() and the + * sole argument to that function. The constructor just stores both + * parameters; it will neither create a thread nor call the function. + * Use startThread() for that at some later time. + **/ + YQUIThreadHandler( voidPtrFunction startFunc, void * startFuncArg ); + + /** + * Destructor. + * + * Notice that this will NOT call terminateUIThread() since + * virtual functions can't be used (as virtual functions) in the + * destructor. Remember to call terminateUIThread() manually. + **/ + virtual ~YQUIThreadHandler(); + + /*** + * Start the UI thread with the function (and the argument to that + * function) passed in the constructor. + * + * Reimplemented from YUIThreadHandler. + **/ + virtual void startUIThread(); + + /** + * Terminate the UI thread if it running. + * + * Reimplemented from YUIThreadHandler. + **/ + virtual void terminateUIThread(); + + +protected: + + YQUIThread * _yquiThread; +}; + + +class YQUIThread: public QThread +{ + Q_OBJECT + +public: + + /** + * Constructor. + **/ + YQUIThread( voidPtrFunction startFunc, void * startFuncArg ) + : _startFunc( startFunc ) + , _startFuncArg( startFuncArg ) + {} + + /** + * Destructor. + **/ + virtual ~YQUIThread() {} + + /** + * The worker function. Calls startfunc( startFuncArg ). + **/ + virtual void run() + { _startFunc( _startFuncArg ); } + + +private: + + voidPtrFunction _startFunc; + void * _startFuncArg; +}; + + +#endif // YQUIThreadHandler_h -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org