kitchensync

clientthread.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2003 Mathias Froehlich <Mathias.Froehlich@web.de>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <qobject.h>
00023 #include <qapplication.h>
00024 #include <qthread.h>
00025 
00026 #include <kdebug.h>
00027 
00028 #include <error.h>
00029 #include <progress.h>
00030 
00031 #include "clientthread.h"
00032 
00033 using namespace Threaded;
00034 
00038 ClientThread::ClientThread( QObject* reciver )
00039   : QObject( 0, "Threaded test konnector" )
00040 {
00041   mReciver = reciver;
00042   mCancel = false;
00043 }
00044 
00048 ClientThread::~ClientThread()
00049 {
00050 }
00051 
00056 void ClientThread::run()
00057 {
00058   // Do the work here. No further communication here.
00059   for (;;) {
00060     mWait.wait( &mLock );
00061     mCancel = false;
00062     switch ( mCommand ) {
00063     case Connect:
00064       kdDebug() << "################################### Connect" << endl;
00065       finished();
00066       break;
00067     case Disconnect:
00068       kdDebug() << "################################### Disconnect" << endl;
00069       finished();
00070       break;
00071     case ReadSyncees:
00072       kdDebug() << "################################### ReadSyncee" << endl;
00073       finished();
00074       break;
00075     case WriteSyncees:
00076       kdDebug() << "################################### WriteSyncee" << endl;
00077       finished();
00078       break;
00079     default:
00080       // Signal that we are finished ...
00081       QApplication::postEvent( mReciver, new QCustomEvent( TerminatedEvent ) );
00082       return;
00083     }
00084   }
00085 }
00086 
00090 void ClientThread::finished()
00091 {
00092   // Signal an error
00093   QApplication::postEvent( mReciver, new QCustomEvent( FinishedEvent ) );
00094 }
00095 
00099 void ClientThread::error( const KSync::Error* e )
00100 {
00101   // Signal an error
00102   QCustomEvent* ce = new QCustomEvent( ErrorEvent );
00103   ce->setData( (void *)e );
00104   QApplication::postEvent( mReciver, ce );
00105 }
00106 
00110 void ClientThread::progress( const KSync::Progress* p )
00111 {
00112   // Signal progress
00113   QCustomEvent* ce = new QCustomEvent( ProgressEvent );
00114   ce->setData( (void *)p );
00115   QApplication::postEvent( mReciver, ce );
00116 }
00117 #include "clientthread.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys