diff --git a/private/storage.cpp b/private/storage.cpp index 069a90d47..f6675f8c0 100644 --- a/private/storage.cpp +++ b/private/storage.cpp @@ -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 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() @@ -129,6 +133,7 @@ void StorageJob::start() return; } + //FIXME: QHASH QMap 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()) { diff --git a/private/storage_p.h b/private/storage_p.h index 1a88418a6..707e5abcb 100644 --- a/private/storage_p.h +++ b/private/storage_p.h @@ -51,6 +51,8 @@ private: }; //End StorageJob +Q_DECLARE_METATYPE(StorageJob *) + class Storage : public Plasma::Service { Q_OBJECT diff --git a/private/storagethread.cpp b/private/storagethread.cpp index 02f8845fa..30b1648ab 100644 --- a/private/storagethread.cpp +++ b/private/storagethread.cpp @@ -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(); } } diff --git a/private/storagethread_p.h b/private/storagethread_p.h index 9df2bb4d8..9c7eea2ce 100644 --- a/private/storagethread_p.h +++ b/private/storagethread_p.h @@ -24,7 +24,7 @@ #include #include -#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; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8f78ebb56..79729b09f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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})