File indexing completed on 2024-06-16 07:42:27

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bsignalwaiter.h"
0007 #include "k3bjob.h"
0008 
0009 #include <QEventLoop>
0010 
0011 class K3b::SignalWaiter::Private
0012 {
0013 public:
0014     QEventLoop loop;
0015 };
0016 
0017 
0018 K3b::SignalWaiter::SignalWaiter()
0019     : QObject(),
0020       d( new Private() )
0021 {
0022 }
0023 
0024 
0025 K3b::SignalWaiter::~SignalWaiter()
0026 {
0027     delete d;
0028 }
0029 
0030 
0031 void K3b::SignalWaiter::waitForSignal( QObject* o, const char* signal )
0032 {
0033     K3b::SignalWaiter w;
0034     connect( o, signal,
0035              &w, SLOT(slotSignal()) );
0036 
0037     w.d->loop.exec();
0038 }
0039 
0040 
0041 void K3b::SignalWaiter::waitForJob( K3b::Job* job )
0042 {
0043     if( !job->active() )
0044         return;
0045 
0046     waitForSignal( job, SIGNAL(finished(bool)) );
0047 }
0048 
0049 
0050 void K3b::SignalWaiter::slotSignal()
0051 {
0052     if( d->loop.isRunning() ) {
0053         d->loop.exit();
0054     }
0055 }
0056 
0057 #include "moc_k3bsignalwaiter.cpp"