diff --git a/panels/notification/common/dbaccessor.cpp b/panels/notification/common/dbaccessor.cpp index 6ef958e36..2a5b2fc76 100644 --- a/panels/notification/common/dbaccessor.cpp +++ b/panels/notification/common/dbaccessor.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -173,6 +174,7 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString columns = QStringList{ @@ -224,6 +226,7 @@ void DBAccessor::updateEntityProcessedType(qint64 id, int processedType) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd = QString("UPDATE %1 SET ProcessedType = :processed WHERE ID = :id").arg(TableName_v2); @@ -240,6 +243,7 @@ NotifyEntity DBAccessor::fetchEntity(qint64 id) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd = QString("SELECT %1 FROM notifications2 WHERE ID = :id").arg(EntityFields.join(",")); query.prepare(cmd); @@ -260,6 +264,7 @@ int DBAccessor::fetchEntityCount(const QString &appName, int processedType) cons { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); if (appName == DataAccessor::AllApp()) { QString cmd = QString("SELECT COUNT(*) FROM notifications2 WHERE (ProcessedType = :processedType OR ProcessedType IS NULL)"); @@ -287,6 +292,7 @@ NotifyEntity DBAccessor::fetchLastEntity(const QString &appName, int processedTy { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd = QString( @@ -314,6 +320,7 @@ QList DBAccessor::fetchEntities(const QString &appName, int proces { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); if (appName == DataAccessor::AllApp()) { if (maxCount >= 0) { @@ -360,6 +367,7 @@ NotifyEntity DBAccessor::fetchLastEntity(uint notifyId) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd = QString("SELECT %1 FROM notifications2 WHERE notifyId = :notifyId ORDER BY CTime DESC LIMIT 1").arg(EntityFields.join(",")); query.prepare(cmd); @@ -383,6 +391,7 @@ QList DBAccessor::fetchApps(int maxCount) const { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); if (maxCount >= 0) { QString cmd("SELECT DISTINCT AppName FROM notifications2 ORDER BY CTime DESC LIMIT :limit"); @@ -413,6 +422,7 @@ void DBAccessor::removeEntity(qint64 id) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd("DELETE FROM notifications2 WHERE ID = :id"); @@ -431,6 +441,7 @@ void DBAccessor::removeEntityByApp(const QString &appName) { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd("DELETE FROM notifications2 WHERE AppName = :appName"); @@ -449,6 +460,7 @@ void DBAccessor::clear() { BENCHMARK(); + QMutexLocker locker(&m_mutex); QSqlQuery query(m_connection); QString cmd("DELETE FROM notifications2"); diff --git a/panels/notification/common/dbaccessor.h b/panels/notification/common/dbaccessor.h index da7db81b2..7535fa040 100644 --- a/panels/notification/common/dbaccessor.h +++ b/panels/notification/common/dbaccessor.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -50,6 +51,7 @@ class DBAccessor : public DataAccessor NotifyEntity parseEntity(const QSqlQuery &query); private: + mutable QMutex m_mutex; QSqlDatabase m_connection; QString m_key; }; diff --git a/panels/notification/server/notificationmanager.h b/panels/notification/server/notificationmanager.h index bdbe1354c..51c091731 100644 --- a/panels/notification/server/notificationmanager.h +++ b/panels/notification/server/notificationmanager.h @@ -30,9 +30,9 @@ class NotificationManager : public QObject, public QDBusContext bool registerDbusService(); uint recordCount() const; - void actionInvoked(qint64 id, uint bubbleId, const QString &actionKey); - void notificationClosed(qint64 id, uint bubbleId, uint reason); - void notificationReplaced(qint64 id); + Q_INVOKABLE void actionInvoked(qint64 id, uint bubbleId, const QString &actionKey); + Q_INVOKABLE void notificationClosed(qint64 id, uint bubbleId, uint reason); + Q_INVOKABLE void notificationReplaced(qint64 id); void removeNotification(qint64 id); void removeNotifications(const QString &appName); diff --git a/panels/notification/server/notifyserverapplet.cpp b/panels/notification/server/notifyserverapplet.cpp index 43c6b58f8..4c9857ea6 100644 --- a/panels/notification/server/notifyserverapplet.cpp +++ b/panels/notification/server/notifyserverapplet.cpp @@ -61,17 +61,17 @@ bool NotifyServerApplet::init() void NotifyServerApplet::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey) { - m_manager->actionInvoked(id, bubbleId, actionKey); + QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::AutoConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(QString, actionKey)); } void NotifyServerApplet::notificationClosed(qint64 id, uint bubbleId, uint reason) { - m_manager->notificationClosed(id, bubbleId, reason); + QMetaObject::invokeMethod(m_manager, "notificationClosed", Qt::AutoConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, reason)); } void NotifyServerApplet::notificationReplaced(qint64 id) { - m_manager->notificationReplaced(id); + QMetaObject::invokeMethod(m_manager, "notificationReplaced", Qt::AutoConnection, Q_ARG(qint64, id)); } QVariant NotifyServerApplet::appValue(const QString &appId, int configItem)