make the thread working

This commit is contained in:
Marco Martin 2011-04-28 18:40:02 +02:00
parent f2bc16c6b3
commit 084b7a1226
5 changed files with 26 additions and 16 deletions

View File

@ -38,6 +38,7 @@
#include "applet.h"
#include "dataengine.h"
#include "abstractrunner.h"
#include "storagethread_p.h"
class RefCountedDatabase
@ -78,6 +79,7 @@ private:
static QThreadStorage<RefCountedDatabase *> s_databasePool;
//Storage Job implentation
StorageJob::StorageJob(const QString& destination,
const QString& operation,
@ -104,6 +106,8 @@ StorageJob::StorageJob(const QString& destination,
m_rdb->database()->close();
}
}
Plasma::StorageThread::self()->start();
qRegisterMetaType<StorageJob *>();
}
StorageJob::~StorageJob()
@ -129,6 +133,7 @@ void StorageJob::start()
return;
}
//FIXME: QHASH
QMap<QString, QVariant> params = parameters();
QString valueGroup = params["group"].toString();
@ -220,6 +225,8 @@ void StorageJob::start()
setResult(true);
} else if (operationName() == "retrieve") {
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
if (params["key"].toString().isEmpty()) {

View File

@ -51,6 +51,8 @@ private:
};
//End StorageJob
Q_DECLARE_METATYPE(StorageJob *)
class Storage : public Plasma::Service
{
Q_OBJECT

View File

@ -19,6 +19,8 @@
#include "storagethread_p.h"
#include "kdebug.h"
namespace Plasma
{
@ -38,7 +40,6 @@ K_GLOBAL_STATIC(StorageThreadSingleton, privateStorageThreadSelf)
StorageThread::StorageThread(QObject *parent)
: QThread(parent)
{
}
StorageThread::~StorageThread()
@ -47,33 +48,33 @@ StorageThread::~StorageThread()
QSqlDatabase::removeDatabase(name);
}
Plasma::StorageThread *self()
Plasma::StorageThread *StorageThread::self()
{
return &privateStorageThreadSelf->self;
}
void StorageThread::save(ServiceJob* caller, const QVariantMap &params)
void StorageThread::save(StorageJob* caller, const QVariantMap &params)
{
bool success = true;
emit newResult(caller, success);
}
void StorageThread::retrieve(ServiceJob* caller, const QVariantMap &params)
void StorageThread::retrieve(StorageJob* caller, const QVariantMap &params)
{
kWarning()<<"RETRIEVE";
bool success = true;
emit newResult(caller, success);
}
void StorageThread::deleteEntry(ServiceJob* caller, const QVariantMap &params)
void StorageThread::deleteEntry(StorageJob* caller, const QVariantMap &params)
{
const bool success = true;
emit newResult(caller, success);
}
void StorageThread::expire(ServiceJob* caller, const QVariantMap &params)
void StorageThread::expire(StorageJob* caller, const QVariantMap &params)
{
bool success = true;
@ -83,7 +84,7 @@ void StorageThread::expire(ServiceJob* caller, const QVariantMap &params)
void StorageThread::run()
{
exec();
}
}

View File

@ -24,7 +24,7 @@
#include <QThread>
#include <QSqlDatabase>
#include "servicejob_p.h"
#include "storage_p.h"
namespace Plasma
{
@ -38,16 +38,16 @@ public:
void run();
static StorageThread *self();
static Plasma::StorageThread *self();
public Q_SLOTS:
void save(ServiceJob* caller, const QVariantMap &parameters);
void retrieve(ServiceJob* caller, const QVariantMap &parameters);
void deleteEntry(ServiceJob* caller, const QVariantMap &parameters);
void expire(ServiceJob* caller, const QVariantMap &parameters);
void save(StorageJob* caller, const QVariantMap &parameters);
void retrieve(StorageJob* caller, const QVariantMap &parameters);
void deleteEntry(StorageJob* caller, const QVariantMap &parameters);
void expire(StorageJob* caller, const QVariantMap &parameters);
Q_SIGNALS:
void newResult(ServiceJob* caller, bool result);
void newResult(StorageJob* caller, bool result);
private:
QSqlDatabase m_db;

View File

@ -19,7 +19,7 @@ PLASMA_UNIT_TESTS(
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)
if(QT_QTOPENGL_FOUND)
target_link_libraries(storagetest ${QT_QTOPENGL_LIBRARY})