make the thread working
This commit is contained in:
parent
f2bc16c6b3
commit
084b7a1226
@ -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()) {
|
||||
|
@ -51,6 +51,8 @@ private:
|
||||
};
|
||||
//End StorageJob
|
||||
|
||||
Q_DECLARE_METATYPE(StorageJob *)
|
||||
|
||||
class Storage : public Plasma::Service
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -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 ¶ms)
|
||||
void StorageThread::save(StorageJob* caller, const QVariantMap ¶ms)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
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;
|
||||
emit newResult(caller, success);
|
||||
}
|
||||
|
||||
void StorageThread::deleteEntry(ServiceJob* caller, const QVariantMap ¶ms)
|
||||
void StorageThread::deleteEntry(StorageJob* caller, const QVariantMap ¶ms)
|
||||
{
|
||||
|
||||
const bool success = true;
|
||||
emit newResult(caller, success);
|
||||
}
|
||||
|
||||
void StorageThread::expire(ServiceJob* caller, const QVariantMap ¶ms)
|
||||
void StorageThread::expire(StorageJob* caller, const QVariantMap ¶ms)
|
||||
{
|
||||
|
||||
bool success = true;
|
||||
@ -83,7 +84,7 @@ void StorageThread::expire(ServiceJob* caller, const QVariantMap ¶ms)
|
||||
|
||||
void StorageThread::run()
|
||||
{
|
||||
|
||||
exec();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 ¶meters);
|
||||
void retrieve(ServiceJob* caller, const QVariantMap ¶meters);
|
||||
void deleteEntry(ServiceJob* caller, const QVariantMap ¶meters);
|
||||
void expire(ServiceJob* caller, const QVariantMap ¶meters);
|
||||
void save(StorageJob* caller, const QVariantMap ¶meters);
|
||||
void retrieve(StorageJob* caller, const QVariantMap ¶meters);
|
||||
void deleteEntry(StorageJob* caller, const QVariantMap ¶meters);
|
||||
void expire(StorageJob* caller, const QVariantMap ¶meters);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newResult(ServiceJob* caller, bool result);
|
||||
void newResult(StorageJob* caller, bool result);
|
||||
|
||||
private:
|
||||
QSqlDatabase m_db;
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user