diff --git a/panels/notification/bubble/bubblemodel.cpp b/panels/notification/bubble/bubblemodel.cpp index 4126efdd6..6eb323716 100644 --- a/panels/notification/bubble/bubblemodel.cpp +++ b/panels/notification/bubble/bubblemodel.cpp @@ -236,7 +236,7 @@ int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const if (bubble->replacesId() != NoReplaceId) { for (int i = 0; i < m_bubbles.size(); i++) { auto item = m_bubbles[i]; - if (item->appName() != item->appName()) + if (item->appName() != bubble->appName()) continue; const bool firstItem = item->replacesId() == NoReplaceId && item->bubbleId() == bubble->replacesId(); diff --git a/panels/notification/bubble/bubblemodel.h b/panels/notification/bubble/bubblemodel.h index 0fdbbfe08..d6cbc1927 100644 --- a/panels/notification/bubble/bubblemodel.h +++ b/panels/notification/bubble/bubblemodel.h @@ -38,7 +38,7 @@ class BubbleModel : public QAbstractListModel } BubbleRole; explicit BubbleModel(QObject *parent = nullptr); - ~BubbleModel(); + ~BubbleModel() override; public: void push(BubbleItem *bubble); diff --git a/panels/notification/common/dbaccessor.cpp b/panels/notification/common/dbaccessor.cpp index 061407aae..7415388b4 100644 --- a/panels/notification/common/dbaccessor.cpp +++ b/panels/notification/common/dbaccessor.cpp @@ -62,8 +62,8 @@ static QString notificationDBPath() if (dataPaths.isEmpty()) { const QString dataDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QDir dir(dataDir); - const auto dbSubfix = QString("%1/%2/data.db").arg(qApp->organizationName()).arg(qApp->applicationName()); - const auto appPath = dir.absoluteFilePath(dbSubfix); + const auto dbSubFix = QString("%1/%2/data.db").arg(qApp->organizationName()).arg(qApp->applicationName()); + const auto appPath = dir.absoluteFilePath(dbSubFix); dataPaths << appPath; QString path = dir.absoluteFilePath("deepin/dde-osd/data.db"); dataPaths << path; @@ -75,7 +75,7 @@ static QString notificationDBPath() QDir().mkpath(QFileInfo(file.fileName()).path()); } if (!file.open(QIODevice::ReadWrite)) { - qDebug(notifyLog) << "Falied on open the data path:" << path << ", error:" << file.errorString(); + qDebug(notifyLog) << "Failed on open the data path:" << path << ", error:" << file.errorString(); continue; } if (QFileInfo::exists(path)) { @@ -83,7 +83,7 @@ static QString notificationDBPath() } } qWarning(notifyLog) << "Doesn't exist the data path" << dataPaths; - return QString(); + return {}; } class Benchmark @@ -147,19 +147,24 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity) QSqlQuery query(m_connection); - QString sqlCmd = QString("INSERT INTO %1 (").arg(TableName_v2); - sqlCmd += ColumnIcon + ","; - sqlCmd += ColumnSummary + ","; - sqlCmd += ColumnBody + ","; - sqlCmd += ColumnAppName + ","; - sqlCmd += ColumnAppId + ","; - sqlCmd += ColumnCTime + ","; - sqlCmd += ColumnAction + ","; - sqlCmd += ColumnHint + ","; - sqlCmd += ColumnReplacesId + ","; - sqlCmd += ColumnNotifyId + ","; - sqlCmd += ColumnProcessedType + ")"; - sqlCmd += "VALUES (:icon, :summary, :body, :appName, :appId, :ctime, :action, :hint, :replacesId, :notifyId, :processedType)"; + QString columns = QStringList{ + ColumnIcon, + ColumnSummary, + ColumnBody, + ColumnAppName, + ColumnAppId, + ColumnCTime, + ColumnAction, + ColumnHint, + ColumnReplacesId, + ColumnNotifyId, + ColumnProcessedType + }.join(", "); + + QString sqlCmd = QString("INSERT INTO %1 (%2) VALUES (%3)") + .arg(TableName_v2) + .arg(columns) + .arg(":icon, :summary, :body, :appName, :appId, :ctime, :action, :hint, :replacesId, :notifyId, :processedType"); query.prepare(sqlCmd); query.bindValue(":icon", entity.appIcon()); @@ -180,7 +185,7 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity) } // to get entity's id in database - int storageId = query.lastInsertId().toLongLong(); + qint64 storageId = query.lastInsertId().toLongLong(); qDebug(notifyDBLog) << "Insert entity bubbleId:" << entity.bubbleId() << ", id:" << storageId; @@ -433,20 +438,25 @@ void DBAccessor::tryToCreateTable() { QSqlQuery query(m_connection); - QString sql = QString("CREATE TABLE IF NOT EXISTS %1(" - "%2 INTEGER PRIMARY KEY AUTOINCREMENT,").arg(TableName_v2, ColumnId); - sql += ColumnIcon + " TEXT,"; - sql += ColumnSummary + " TEXT,"; - sql += ColumnBody + " TEXT,"; - sql += ColumnAppName + " TEXT,"; - sql += ColumnAppId + " TEXT,"; - sql += ColumnCTime + " TEXT,"; - sql += ColumnAction + " TEXT,"; - sql += ColumnHint + " TEXT,"; - sql += ColumnReplacesId + " TEXT,"; - sql += ColumnNotifyId + " TEXT,"; - sql += ColumnTimeout + " TEXT,"; - sql += ColumnProcessedType + " INTEGER)"; + QStringList columns = { + QString("%1 INTEGER PRIMARY KEY AUTOINCREMENT").arg(ColumnId), + QString("%1 TEXT").arg(ColumnIcon), + QString("%1 TEXT").arg(ColumnSummary), + QString("%1 TEXT").arg(ColumnBody), + QString("%1 TEXT").arg(ColumnAppName), + QString("%1 TEXT").arg(ColumnAppId), + QString("%1 TEXT").arg(ColumnCTime), + QString("%1 TEXT").arg(ColumnAction), + QString("%1 TEXT").arg(ColumnHint), + QString("%1 TEXT").arg(ColumnReplacesId), + QString("%1 TEXT").arg(ColumnNotifyId), + QString("%1 TEXT").arg(ColumnTimeout), + QString("%1 INTEGER").arg(ColumnProcessedType) + }; + + QString sql = QString("CREATE TABLE IF NOT EXISTS %1(%2)") + .arg(TableName_v2) + .arg(columns.join(", ")); query.prepare(sql); @@ -476,7 +486,7 @@ void DBAccessor::tryToCreateTable() } } -bool DBAccessor::isAttributeValid(const QString &tableName, const QString &attributeName) +bool DBAccessor::isAttributeValid(const QString &tableName, const QString &attributeName) const { QSqlQuery query(m_connection); @@ -487,25 +497,20 @@ bool DBAccessor::isAttributeValid(const QString &tableName, const QString &attri if (query.exec(sqlCmd)) { QSqlRecord record = query.record(); int index = record.indexOf(attributeName); - if (index == -1) { - return false; - } else { - return true; - } - } else { - qDebug(notifyDBLog) << sqlCmd << ",lastError:" << query.lastError().text(); - return false; + return index != -1; } - } else { // table not exist + qDebug(notifyDBLog) << sqlCmd << ",lastError:" << query.lastError().text(); return false; } - } else { // sql error - qDebug(notifyDBLog) << sqlCmd << ",lastError:" << query.lastError().text(); + // table not exist return false; } + // sql error + qDebug(notifyDBLog) << sqlCmd << ",lastError:" << query.lastError().text(); + return false; } -bool DBAccessor::addAttributeToTable(const QString &tableName, const QString &attributeName, const QString &type) +bool DBAccessor::addAttributeToTable(const QString &tableName, const QString &attributeName, const QString &type) const { QSqlQuery query(m_connection); diff --git a/panels/notification/common/dbaccessor.h b/panels/notification/common/dbaccessor.h index 4b2adf719..3ff59b9ae 100644 --- a/panels/notification/common/dbaccessor.h +++ b/panels/notification/common/dbaccessor.h @@ -41,8 +41,8 @@ class DBAccessor : public DataAccessor private: void tryToCreateTable(); - bool isAttributeValid(const QString &tableName, const QString &attributeName); - bool addAttributeToTable(const QString &tableName, const QString &attributeName, const QString &type); + bool isAttributeValid(const QString &tableName, const QString &attributeName) const; + bool addAttributeToTable(const QString &tableName, const QString &attributeName, const QString &type) const; void updateProcessTypeValue(); private: diff --git a/panels/notification/server/configs/org.deepin.dde.shell.notification.json b/panels/notification/server/configs/org.deepin.dde.shell.notification.json index 83948ce16..b9a2002aa 100644 --- a/panels/notification/server/configs/org.deepin.dde.shell.notification.json +++ b/panels/notification/server/configs/org.deepin.dde.shell.notification.json @@ -6,7 +6,7 @@ "value": true, "serial": 0, "flags": [], - "name": "dndode", + "name": "dndMode", "name[zh_CN]": "勿扰模式", "description": "System notification do not disturb mode", "description[zh_CN]": "系统通知勿扰模式", diff --git a/panels/notification/server/notificationmanager.cpp b/panels/notification/server/notificationmanager.cpp index f86efb82b..a951482f1 100644 --- a/panels/notification/server/notificationmanager.cpp +++ b/panels/notification/server/notificationmanager.cpp @@ -322,20 +322,14 @@ bool NotificationManager::isDoNotDisturb() const QTime startTime = QTime::fromString(m_setting->systemValue(NotificationSetting::StartTime).toString()); QTime endTime = QTime::fromString(m_setting->systemValue(NotificationSetting::EndTime).toString()); - bool dndMode = false; + bool dndMode = true; if (startTime < endTime) { dndMode = startTime <= currentTime && endTime >= currentTime; } else if (startTime > endTime) { dndMode = startTime <= currentTime || endTime >= currentTime; - } else { - dndMode = true; } - if (dndMode && m_setting->systemValue(NotificationSetting::OpenByTimeInterval).toBool()) { - return dndMode; - } else { - return false; - } + return dndMode && m_setting->systemValue(NotificationSetting::OpenByTimeInterval).toBool(); } void NotificationManager::tryPlayNotificationSound(const NotifyEntity &entity, const QString &appId, bool dndMode) const @@ -437,8 +431,7 @@ void NotificationManager::doActionInvoked(const NotifyEntity &entity, const QStr while (i != hints.constEnd()) { QStringList args = i.value().toString().split(","); if (!args.isEmpty()) { - QString cmd = args.first(); //命令 - args.removeFirst(); + QString cmd = args.takeFirst(); //命令 if (i.key() == "x-deepin-action-" + actionId) { QProcess::startDetached(cmd, args); //执行相关命令 } @@ -478,7 +471,7 @@ void NotificationManager::onHandingPendingEntities() m_lastTimeoutPoint = std::numeric_limits::max(); } - for (const auto item : timeoutEntities) { + for (const auto &item : timeoutEntities) { qDebug(notifyLog) << "Expired for the notification " << item.id() << item.appName(); notificationClosed(item.id(), item.bubbleId(), NotifyEntity::Expired); } diff --git a/panels/notification/server/notificationsetting.cpp b/panels/notification/server/notificationsetting.cpp index 58c668e29..9a7ada8bb 100644 --- a/panels/notification/server/notificationsetting.cpp +++ b/panels/notification/server/notificationsetting.cpp @@ -37,7 +37,7 @@ enum Roles { NotificationSetting::NotificationSetting(QObject *parent) : QObject(parent) - , m_impl(Dtk::Core::DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification")) + , m_impl(Dtk::Core::DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification", QString(), this)) { invalidAppItemCached(); connect(m_impl, &Dtk::Core::DConfig::valueChanged, this, [this] (const QString &key) {