Sleep
This commit is contained in:
@@ -50,11 +50,6 @@
|
||||
|
||||
static const QLatin1String constCantataCacheFile("/.cache.xml");
|
||||
|
||||
struct Thread : public QThread
|
||||
{
|
||||
static void sleep() { QThread::msleep(100); }
|
||||
};
|
||||
|
||||
MusicScanner::MusicScanner(const QString &f)
|
||||
: QThread(0)
|
||||
, folder(f)
|
||||
@@ -78,9 +73,7 @@ void MusicScanner::run()
|
||||
void MusicScanner::stop()
|
||||
{
|
||||
stopRequested=true;
|
||||
quit();
|
||||
for(int i=0; i<10 && isRunning(); ++i)
|
||||
Thread::sleep();
|
||||
Utils::stopThread(this);
|
||||
}
|
||||
|
||||
MusicLibraryItemRoot * MusicScanner::takeLibrary()
|
||||
|
||||
@@ -525,16 +525,9 @@ MtpDevice::MtpDevice(DevicesModel *m, Solid::Device &dev)
|
||||
QTimer::singleShot(0, this, SLOT(rescan()));
|
||||
}
|
||||
|
||||
struct Thread : public QThread
|
||||
{
|
||||
static void sleep() { QThread::msleep(100); }
|
||||
};
|
||||
|
||||
MtpDevice::~MtpDevice()
|
||||
{
|
||||
thread->quit();
|
||||
for(int i=0; i<10 && thread->isRunning(); ++i)
|
||||
Thread::sleep();
|
||||
Utils::stopThread(thread);
|
||||
thread->deleteLater();
|
||||
thread=0;
|
||||
deleteTemp();
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QThread>
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
#include <KDE/KStandardDirs>
|
||||
#endif
|
||||
@@ -192,3 +193,22 @@ bool Utils::createDir(const QString &dir, const QString &base)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
struct Thread : public QThread
|
||||
{
|
||||
static void sleep(int msecs) { QThread::msleep(msecs); }
|
||||
};
|
||||
|
||||
void Utils::msleep(int msecs)
|
||||
{
|
||||
Thread::sleep(msecs);
|
||||
}
|
||||
|
||||
void Utils::stopThread(QThread *thread)
|
||||
{
|
||||
thread->quit();
|
||||
for(int i=0; i<10 && thread->isRunning(); ++i) {
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <math.h>
|
||||
|
||||
class QString;
|
||||
class QThread;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
@@ -39,6 +40,9 @@ namespace Utils
|
||||
extern void cleanDir(const QString &dir, const QString &base, const QString &coverFile, int level=0);
|
||||
extern void setFilePerms(const QString &file);
|
||||
extern bool createDir(const QString &dir, const QString &base);
|
||||
extern void msleep(int msecs);
|
||||
inline void sleep() { msleep(100); }
|
||||
extern void stopThread(QThread *thread);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
#include "mpdparseutils.h"
|
||||
#include "settings.h"
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "musiclibrarymodel.h"
|
||||
#include "musiclibraryitemalbum.h"
|
||||
#include "librarypage.h"
|
||||
@@ -920,11 +921,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
}
|
||||
|
||||
struct Thread : public QThread
|
||||
{
|
||||
static void sleep() { QThread::msleep(100); }
|
||||
};
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
if (dock) {
|
||||
@@ -959,11 +955,9 @@ MainWindow::~MainWindow()
|
||||
disconnect(MPDConnection::self(), 0, 0, 0);
|
||||
if (Settings::self()->stopOnExit()) {
|
||||
emit stop();
|
||||
Thread::sleep();
|
||||
Utils::sleep();
|
||||
}
|
||||
mpdThread->quit();
|
||||
for(int i=0; i<10 && mpdThread->isRunning(); ++i)
|
||||
Thread::sleep();
|
||||
Utils::stopThread(mpdThread);
|
||||
}
|
||||
|
||||
void MainWindow::load(const QList<QUrl> &urls)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "httpserver.h"
|
||||
#include "httpsocket.h"
|
||||
#include "utils.h"
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QThread>
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
@@ -30,11 +31,6 @@
|
||||
K_GLOBAL_STATIC(HttpServer, instance)
|
||||
#endif
|
||||
|
||||
struct Thread : public QThread
|
||||
{
|
||||
static void sleep() { QThread::msleep(100); }
|
||||
};
|
||||
|
||||
HttpServer * HttpServer::self()
|
||||
{
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
@@ -56,10 +52,9 @@ void HttpServer::stop()
|
||||
}
|
||||
|
||||
if (thread) {
|
||||
thread->quit();
|
||||
for(int i=0; i<10 && thread->isRunning(); ++i) {
|
||||
Thread::sleep();
|
||||
}
|
||||
Utils::stopThread(thread);
|
||||
thread->deleteLater();
|
||||
thread=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user