[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/kdewin-installer/shared
From: Christian Ehrlicher <Ch.Ehrlicher () gmx ! de>
Date: 2008-01-28 19:43:39
Message-ID: 1201549419.168806.20670.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 767788 by chehrlic:
fix threads to not use 100% cpu during wait
M +21 -19 downloader.cpp
M +1 -1 downloader.h
M +4 -3 downloader_p.h
M +1 -0 installerprogress.cpp
M +20 -14 uninstaller.cpp
M +2 -2 uninstaller.h
M +2 -1 uninstaller_p.h
M +22 -18 unpacker.cpp
M +2 -2 unpacker.h
M +2 -1 unpacker_p.h
--- trunk/kdesupport/kdewin-installer/shared/downloader.cpp #767787:767788
@@ -45,7 +45,7 @@
MyThread::MyThread ( CURL *handle, QObject *parent )
- : QThread ( parent ), curlHandle ( handle ), bCancel ( false )
+ : QThread ( parent ), curlHandle ( handle ), m_bCancel ( false ), m_ret( \
CURLE_OK ) {
curl_easy_setopt ( curlHandle, CURLOPT_PROGRESSFUNCTION, \
MyThread::curlProgressCallback ); curl_easy_setopt ( curlHandle, \
CURLOPT_PROGRESSDATA, this ); @@ -53,22 +53,26 @@
void MyThread::run()
{
- bCancel = false;
- CURLcode ret = curl_easy_perform ( curlHandle );
- emit done ( ret );
+ m_bCancel = false;
+ m_ret = curl_easy_perform ( curlHandle );
}
void MyThread::cancel()
{
- bCancel = true;
+ m_bCancel = true;
}
+CURLcode MyThread::retCode() const
+{
+ return m_ret;
+}
+
int MyThread::progressCallback ( double dltotal, double dlnow )
{
- if ( bCancel )
+ if ( m_bCancel )
return 1;
emit progress ( dltotal, dlnow );
- return bCancel;
+ return 0;
}
int MyThread::curlProgressCallback ( void *clientp, double dltotal, double dlnow,
@@ -93,7 +97,7 @@
{
public:
Private ()
- : curlHandle ( 0 ), thread ( NULL ), cancel ( false ), finished ( false ), ret \
( CURLE_OK ), + : curlHandle ( 0 ), thread ( NULL ), cancel ( false ), ret ( \
CURLE_OK ), progress ( 0 ), ioDevice ( NULL ) {}
~Private() {
if ( thread )
@@ -104,7 +108,6 @@
CURL *curlHandle;
MyThread *thread;
bool cancel;
- bool finished;
CURLcode ret;
DownloaderProgress *progress;
QIODevice *ioDevice;
@@ -177,7 +180,7 @@
bool Downloader::startInternal ( const QUrl &url )
{
- qDebug() << __FUNCTION__ << "url: " << url.toString();
+ qDebug() << this << __FUNCTION__ << "url: " << url.toString();
m_usedURL = url;
m_result = Undefined;
@@ -210,7 +213,7 @@
}
if ( !d->thread ) {
d->thread = new MyThread ( d->curlHandle, this );
- connect ( d->thread, SIGNAL ( done ( int ) ), this, SLOT ( threadFinished ( int \
) ) ); + connect ( d->thread, SIGNAL ( finished () ), this, SLOT ( threadFinished \
() ) );
connect ( d->thread, SIGNAL ( progress ( double, double ) ), this, SLOT ( \
progressCallback ( double, double ) ) ); }
if ( d->progress ) {
@@ -218,23 +221,23 @@
d->progress->show();
d->progress->setTitle ( tr ( "Downloading %1" ).arg ( m_usedURL.toString() ) );
}
- d->finished = false;
d->thread->start();
QEventLoop *loop = new QEventLoop ( this );
do {
- loop->processEvents ( QEventLoop::AllEvents, 50 );
- } while ( !d->finished );
+ loop->processEvents ( QEventLoop::WaitForMoreEvents );
+ } while ( !d->thread->isFinished() || m_result == Undefined );
+ delete loop;
+
if ( d->progress )
d->progress->hide();
- delete loop;
qDebug() << __FUNCTION__ << "ret: " << (d->ret == 0);
return ( d->ret == 0 );
}
-void Downloader::threadFinished ( int _ret )
+void Downloader::threadFinished ()
{
- d->ret = static_cast<CURLcode> ( _ret );
- d->finished = true;
+ qDebug() << this << __FUNCTION__;
+ d->ret = d->thread->retCode();
bool bRet = ( d->ret == CURLE_OK );
m_result = d->cancel ? Aborted : bRet ? Finished : Failed;
@@ -297,7 +300,6 @@
d->cancel = true;
if ( d->thread )
d->thread->cancel();
- setError( tr( "Canceled by user" ) );
}
void Downloader::setError ( const QString &errStr )
--- trunk/kdesupport/kdewin-installer/shared/downloader.h #767787:767788
@@ -64,7 +64,7 @@
void done ( bool error );
void error ( const QString &error );
protected Q_SLOTS:
- void threadFinished ( int ret ); // ret == CURLcode (enum)
+ void threadFinished ();
int progressCallback ( double ultotal, double ulnow );
protected:
void setError ( const QString &errStr );
--- trunk/kdesupport/kdewin-installer/shared/downloader_p.h #767787:767788
@@ -10,8 +10,8 @@
public:
MyThread(CURL *handle, QObject *parent = 0);
void cancel();
+ CURLcode retCode() const;
Q_SIGNALS:
- void done(int curlRetCode);
void progress(double dltotal, double dlnow);
protected:
virtual void run();
@@ -20,8 +20,9 @@
static int curlProgressCallback(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow);
protected:
- CURL *curlHandle;
- bool bCancel;
+ CURL *curlHandle;
+ bool m_bCancel;
+ CURLcode m_ret;
};
#endif // DOWNLOADER_P_H
--- trunk/kdesupport/kdewin-installer/shared/installerprogress.cpp #767787:767788
@@ -37,6 +37,7 @@
QVBoxLayout *mainLayout = new QVBoxLayout;
m_titleLabel = new QLabel;
+ m_titleLabel->setTextFormat( Qt::PlainText );
mainLayout->addWidget(m_titleLabel);
QHBoxLayout *statusLayout = new QHBoxLayout;
--- trunk/kdesupport/kdewin-installer/shared/uninstaller.cpp #767787:767788
@@ -37,7 +37,7 @@
#include "installerprogress.h"
UIThread::UIThread ( QObject *parent )
- : QThread ( parent ), m_bCancel( false )
+ : QThread ( parent ), m_bCancel( false ), m_bRet( false )
{}
UIThread::~UIThread()
@@ -45,6 +45,7 @@
void UIThread::uninstallPackage(const QString &manifest, const QString &root)
{
+ m_bRet = false;
m_bCancel = false;
m_manifest = manifest;
m_root = root;
@@ -56,6 +57,12 @@
m_bCancel = true;
}
+
+bool UIThread::retCode() const
+{
+ return m_bRet;
+}
+
void UIThread::run()
{
QList<FileItem> files;
@@ -63,13 +70,13 @@
QFile f;
if(!readManifestFile(files)) {
- emit done(false);
+ m_bRet = false;
return;
}
Q_FOREACH( const FileItem &fileItem, files) {
if(m_bCancel) {
- emit done(false);
+ m_bRet = false;
return;
}
@@ -101,7 +108,7 @@
continue;
}
}
- emit done(true);
+ m_bRet = true;
}
bool isHash(const QByteArray &str)
@@ -185,7 +192,7 @@
Q_GLOBAL_STATIC(UninstallerSingleton, sUninstaller);
Uninstaller::Uninstaller()
- : m_thread(NULL), m_bFinished(true), m_bRet(false)
+ : m_thread(NULL), m_bRet(false)
{}
Uninstaller::~Uninstaller()
@@ -205,31 +212,30 @@
bool Uninstaller::uninstallPackage(const QString &pathToManifest, const QString \
&root) {
qDebug() << __FUNCTION__ << "path: " << pathToManifest << "root: " << root;
- m_bFinished = true;
m_bRet = false;
+ m_bFinished = false;
if ( !QFile::exists ( pathToManifest ) ) {
setError ( tr ( "Manifest %1 not found - can't uninstall package!" ).arg ( \
pathToManifest ) ); return false;
}
- m_bFinished = false;
if ( !m_thread ) {
m_thread = new UIThread ( this );
- connect ( m_thread, SIGNAL ( done ( bool ) ), this, SLOT ( threadFinished ( \
bool ) ) ); + connect ( m_thread, SIGNAL ( finished () ), this, SLOT ( \
threadFinished () ) );
connect ( m_thread, SIGNAL ( progress ( QString ) ), this, SLOT ( \
progressCallback ( QString ) ) );
connect ( m_thread, SIGNAL ( error ( QString ) ), this, SLOT ( setError ( \
QString ) ) );
connect ( m_thread, SIGNAL ( warning ( QString ) ), this, SLOT ( setWarning \
( QString ) ) ); }
if ( m_progress ) {
m_progress->show();
- m_progress->setTitle ( tr ( "Uninstalling %1" ).arg ( pathToManifest ) );
+ m_progress->setTitle ( tr ( "Uninstalling %1" ).arg ( \
QDir::toNativeSeparators ( pathToManifest ) ) ); }
m_thread->uninstallPackage(pathToManifest, root);
QEventLoop *loop = new QEventLoop ( this );
do {
- loop->processEvents ( QEventLoop::AllEvents, 50 );
- } while ( !m_bFinished );
+ loop->processEvents ( QEventLoop::WaitForMoreEvents );
+ } while ( !m_thread->isFinished() || !m_bFinished );
delete loop;
if ( m_progress )
m_progress->hide();
@@ -244,11 +250,11 @@
m_thread->cancel();
}
-void Uninstaller::threadFinished ( bool bOk )
+void Uninstaller::threadFinished ()
{
+ m_bRet = m_thread->retCode();
m_bFinished = true;
- m_bRet = bOk;
- emit done ( bOk );
+ emit done ( m_bRet );
}
void Uninstaller::progressCallback ( const QString &file )
--- trunk/kdesupport/kdewin-installer/shared/uninstaller.h #767787:767788
@@ -50,13 +50,13 @@
protected Q_SLOTS:
void setError ( const QString &error );
void setWarning ( const QString &warning );
- void threadFinished ( bool bOk );
+ void threadFinished ();
void progressCallback ( const QString &s );
protected:
InstallerProgress *m_progress;
UIThread *m_thread;
+ bool m_bRet;
bool m_bFinished;
- bool m_bRet;
private:
Uninstaller();
--- trunk/kdesupport/kdewin-installer/shared/uninstaller_p.h #767787:767788
@@ -35,8 +35,8 @@
void uninstallPackage(const QString &manifest, const QString &root);
void cancel();
+ bool retCode() const;
Q_SIGNALS:
- void done ( bool bOk );
void progress ( const QString &filename );
void warning ( const QString &warning );
void error ( const QString &error );
@@ -54,6 +54,7 @@
QString m_manifest;
QString m_root;
bool m_bCancel;
+ bool m_bRet;
private:
void start ( Priority priority = InheritPriority );
};
--- trunk/kdesupport/kdewin-installer/shared/unpacker.cpp #767787:767788
@@ -49,7 +49,7 @@
#include "misc.h"
UPThread::UPThread ( QObject *parent )
- : QThread ( parent ), m_bCancel( false )
+ : QThread ( parent ), m_bCancel( false ), m_bRet( false )
{}
UPThread::~UPThread()
@@ -57,25 +57,25 @@
void UPThread::run()
{
- bool bOk = false;
+ m_bRet = false;
+ m_bCancel = false;
if ( m_filename.endsWith ( ".zip" ) ) {
- bOk = unzipFile();
+ m_bRet = unzipFile();
} else
if ( m_filename.endsWith ( ".tar.bz2" ) || m_filename.endsWith ( ".tbz" ) ) {
- bOk = unbz2File();
+ m_bRet = unbz2File();
} else
if ( m_filename.endsWith ( ".7z" ) ) {
- bOk = un7zipFile();
+ m_bRet = un7zipFile();
} else
if ( m_filename.endsWith ( ".exe" ) ) {
- bOk = unpackExe();
+ m_bRet = unpackExe();
} else
if ( m_filename.endsWith ( ".msi" ) ) {
- bOk = unpackMsi();
+ m_bRet = unpackMsi();
} else {
emit error ( tr ( "Don't know what to do with %1" ).arg ( m_filename ) );
}
- emit done( bOk );
}
void UPThread::unpackFile ( const QString &fn, const QString &destdir, const \
StringHash &pathRelocations ) @@ -93,6 +93,11 @@
m_bCancel = true;
}
+bool UPThread::retCode() const
+{
+ return m_bRet;
+}
+
QStringList UPThread::getUnpackedFiles() const
{
return m_unpackedFiles;
@@ -427,7 +432,7 @@
Q_GLOBAL_STATIC(UnpackerSingleton, sUnpacker);
Unpacker::Unpacker ()
- : m_progress ( NULL ), m_thread ( NULL ), m_bFinished ( true ), m_bRet ( \
false ) + : m_progress ( NULL ), m_thread ( NULL ), m_bRet ( false ), \
m_bFinished ( false ) {}
Unpacker::~Unpacker()
@@ -446,8 +451,8 @@
bool Unpacker::unpackFile ( const QString &fn, const QString &destpath, const \
StringHash &pathRelocations ) {
qDebug() << __FUNCTION__ << "filename: " << fn << "root: " << destpath;
- m_bFinished = true;
m_bRet = false;
+ m_bFinished = false;
QDir path ( destpath );
if ( !path.exists() ) {
@@ -459,22 +464,21 @@
return false;
}
- m_bFinished = false;
if ( !m_thread ) {
m_thread = new UPThread ( this );
- connect ( m_thread, SIGNAL ( done ( bool ) ), this, SLOT ( threadFinished ( \
bool ) ) ); + connect ( m_thread, SIGNAL ( finished () ), this, SLOT ( \
threadFinished () ) );
connect ( m_thread, SIGNAL ( progress ( QString ) ), this, SLOT ( \
progressCallback ( QString ) ) );
connect ( m_thread, SIGNAL ( error ( QString ) ), this, SLOT ( setError ( \
QString ) ) ); }
if ( m_progress ) {
m_progress->show();
- m_progress->setTitle ( tr ( "Unpacking %1" ).arg ( fn ) );
+ m_progress->setTitle ( tr ( "Unpacking %1" ).arg ( QDir::toNativeSeparators \
( fn ) ) ); }
m_thread->unpackFile ( fn, destpath, pathRelocations );
QEventLoop *loop = new QEventLoop ( this );
do {
- loop->processEvents ( QEventLoop::AllEvents, 50 );
- } while ( !m_bFinished );
+ loop->processEvents ( QEventLoop::WaitForMoreEvents );
+ } while ( !m_thread->isFinished() || !m_bFinished );
delete loop;
if ( m_progress )
m_progress->hide();
@@ -494,11 +498,11 @@
return m_thread ? m_thread->getUnpackedFiles() : QStringList();
}
-void Unpacker::threadFinished ( bool bOk )
+void Unpacker::threadFinished ()
{
+ m_bRet = m_thread->retCode();
m_bFinished = true;
- m_bRet = bOk;
- emit done ( bOk );
+ emit done ( m_bRet );
}
void Unpacker::progressCallback ( const QString &file )
--- trunk/kdesupport/kdewin-installer/shared/unpacker.h #767787:767788
@@ -51,13 +51,13 @@
void error ( const QString &error );
protected Q_SLOTS:
void setError ( const QString &error );
- void threadFinished ( bool bOk );
+ void threadFinished ();
void progressCallback ( const QString &s );
protected:
InstallerProgress *m_progress;
UPThread *m_thread;
+ bool m_bRet;
bool m_bFinished;
- bool m_bRet;
private:
Unpacker ();
--- trunk/kdesupport/kdewin-installer/shared/unpacker_p.h #767787:767788
@@ -41,9 +41,9 @@
void unpackFile ( const QString &fn, const QString &destdir, const StringHash \
&pathRelocations ); void cancel();
+ bool retCode() const;
QStringList getUnpackedFiles() const;
Q_SIGNALS:
- void done ( bool bOk );
void progress ( const QString &filename );
void error ( const QString &error );
protected:
@@ -62,6 +62,7 @@
StringHash m_pathRelocations;
QStringList m_unpackedFiles;
bool m_bCancel;
+ bool m_bRet;
private:
void start ( Priority priority = InheritPriority );
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic