This commit is contained in:
craig
2012-02-29 18:11:06 +00:00
committed by craig
parent aba0617a96
commit 6a11f80f72
6 changed files with 33 additions and 34 deletions

View File

@@ -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()

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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;
}
}