make the thread working
This commit is contained in:
parent
f2bc16c6b3
commit
084b7a1226
@ -38,6 +38,7 @@
|
|||||||
#include "applet.h"
|
#include "applet.h"
|
||||||
#include "dataengine.h"
|
#include "dataengine.h"
|
||||||
#include "abstractrunner.h"
|
#include "abstractrunner.h"
|
||||||
|
#include "storagethread_p.h"
|
||||||
|
|
||||||
|
|
||||||
class RefCountedDatabase
|
class RefCountedDatabase
|
||||||
@ -78,6 +79,7 @@ private:
|
|||||||
|
|
||||||
static QThreadStorage<RefCountedDatabase *> s_databasePool;
|
static QThreadStorage<RefCountedDatabase *> s_databasePool;
|
||||||
|
|
||||||
|
|
||||||
//Storage Job implentation
|
//Storage Job implentation
|
||||||
StorageJob::StorageJob(const QString& destination,
|
StorageJob::StorageJob(const QString& destination,
|
||||||
const QString& operation,
|
const QString& operation,
|
||||||
@ -104,6 +106,8 @@ StorageJob::StorageJob(const QString& destination,
|
|||||||
m_rdb->database()->close();
|
m_rdb->database()->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Plasma::StorageThread::self()->start();
|
||||||
|
qRegisterMetaType<StorageJob *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageJob::~StorageJob()
|
StorageJob::~StorageJob()
|
||||||
@ -129,6 +133,7 @@ void StorageJob::start()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: QHASH
|
||||||
QMap<QString, QVariant> params = parameters();
|
QMap<QString, QVariant> params = parameters();
|
||||||
|
|
||||||
QString valueGroup = params["group"].toString();
|
QString valueGroup = params["group"].toString();
|
||||||
@ -221,6 +226,8 @@ void StorageJob::start()
|
|||||||
} else if (operationName() == "retrieve") {
|
} else if (operationName() == "retrieve") {
|
||||||
QSqlQuery query(*m_rdb->database());
|
QSqlQuery query(*m_rdb->database());
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(StorageJob *, this), Q_ARG(const QVariantMap&, params));
|
||||||
|
|
||||||
//a bit redundant but should be the faster way with less string concatenation as possible
|
//a bit redundant but should be the faster way with less string concatenation as possible
|
||||||
if (params["key"].toString().isEmpty()) {
|
if (params["key"].toString().isEmpty()) {
|
||||||
//update modification time
|
//update modification time
|
||||||
|
@ -51,6 +51,8 @@ private:
|
|||||||
};
|
};
|
||||||
//End StorageJob
|
//End StorageJob
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(StorageJob *)
|
||||||
|
|
||||||
class Storage : public Plasma::Service
|
class Storage : public Plasma::Service
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "storagethread_p.h"
|
#include "storagethread_p.h"
|
||||||
|
|
||||||
|
#include "kdebug.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -38,7 +40,6 @@ K_GLOBAL_STATIC(StorageThreadSingleton, privateStorageThreadSelf)
|
|||||||
StorageThread::StorageThread(QObject *parent)
|
StorageThread::StorageThread(QObject *parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageThread::~StorageThread()
|
StorageThread::~StorageThread()
|
||||||
@ -47,33 +48,33 @@ StorageThread::~StorageThread()
|
|||||||
QSqlDatabase::removeDatabase(name);
|
QSqlDatabase::removeDatabase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::StorageThread *self()
|
Plasma::StorageThread *StorageThread::self()
|
||||||
{
|
{
|
||||||
return &privateStorageThreadSelf->self;
|
return &privateStorageThreadSelf->self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageThread::save(ServiceJob* caller, const QVariantMap ¶ms)
|
void StorageThread::save(StorageJob* caller, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
emit newResult(caller, success);
|
emit newResult(caller, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageThread::retrieve(ServiceJob* caller, const QVariantMap ¶ms)
|
void StorageThread::retrieve(StorageJob* caller, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
kWarning()<<"RETRIEVE";
|
||||||
bool success = true;
|
bool success = true;
|
||||||
emit newResult(caller, success);
|
emit newResult(caller, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageThread::deleteEntry(ServiceJob* caller, const QVariantMap ¶ms)
|
void StorageThread::deleteEntry(StorageJob* caller, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
|
||||||
const bool success = true;
|
const bool success = true;
|
||||||
emit newResult(caller, success);
|
emit newResult(caller, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageThread::expire(ServiceJob* caller, const QVariantMap ¶ms)
|
void StorageThread::expire(StorageJob* caller, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@ -83,7 +84,7 @@ void StorageThread::expire(ServiceJob* caller, const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void StorageThread::run()
|
void StorageThread::run()
|
||||||
{
|
{
|
||||||
|
exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
|
|
||||||
#include "servicejob_p.h"
|
#include "storage_p.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -38,16 +38,16 @@ public:
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
static StorageThread *self();
|
static Plasma::StorageThread *self();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void save(ServiceJob* caller, const QVariantMap ¶meters);
|
void save(StorageJob* caller, const QVariantMap ¶meters);
|
||||||
void retrieve(ServiceJob* caller, const QVariantMap ¶meters);
|
void retrieve(StorageJob* caller, const QVariantMap ¶meters);
|
||||||
void deleteEntry(ServiceJob* caller, const QVariantMap ¶meters);
|
void deleteEntry(StorageJob* caller, const QVariantMap ¶meters);
|
||||||
void expire(ServiceJob* caller, const QVariantMap ¶meters);
|
void expire(StorageJob* caller, const QVariantMap ¶meters);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void newResult(ServiceJob* caller, bool result);
|
void newResult(StorageJob* caller, bool result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSqlDatabase m_db;
|
QSqlDatabase m_db;
|
||||||
|
@ -19,7 +19,7 @@ PLASMA_UNIT_TESTS(
|
|||||||
configloadertest
|
configloadertest
|
||||||
)
|
)
|
||||||
|
|
||||||
kde4_add_unit_test(storagetest TESTNAME plasma-storage storagetest.cpp ../private/storage.cpp)
|
kde4_add_unit_test(storagetest TESTNAME plasma-storage storagetest.cpp ../private/storage.cpp ../private/storagethread.cpp)
|
||||||
target_link_libraries(storagetest ${QT_QTTEST_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS} plasma)
|
target_link_libraries(storagetest ${QT_QTTEST_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS} plasma)
|
||||||
if(QT_QTOPENGL_FOUND)
|
if(QT_QTOPENGL_FOUND)
|
||||||
target_link_libraries(storagetest ${QT_QTOPENGL_LIBRARY})
|
target_link_libraries(storagetest ${QT_QTOPENGL_LIBRARY})
|
||||||
|
Loading…
Reference in New Issue
Block a user