增加根据全局设置查询当前是否处于勿扰模式的接口

Signed-off-by: iaom <zhangpengfei@kylinos.cn>
This commit is contained in:
iaom 2023-04-17 16:52:16 +08:00
parent 02352b0fc3
commit 188a895ca9
6 changed files with 53 additions and 76 deletions

View File

@ -20,6 +20,8 @@
#include "notification-global-settings.h"
#include <QJsonObject>
#include <QQmlEngine>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug>
#include "settings-manager.h"
#include "settings-properties.h"
@ -31,6 +33,8 @@ class NotificationGlobalSettingsPrivate
friend class NotificationGlobalSettings;
private:
QJsonObject m_settings;
QDBusInterface *m_usdInterface = nullptr;
int m_currentScreenMode = 0; //0-仅主屏1-镜像2-扩展3-仅副屏
};
}
@ -41,6 +45,20 @@ NotificationGlobalSettings::NotificationGlobalSettings(QObject *parent) : QObjec
qmlRegisterUncreatableType<UkuiNotification::NotificationGlobalSettings>("org.ukui.notification.client", 1, 0, "NotificationGlobalSettings", "");
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &NotificationGlobalSettings::settingsDataChanged);
d->m_settings = SettingsManager::self()->getGlobalSettings();
d->m_usdInterface = new QDBusInterface("org.ukui.SettingsDaemon",
"/org/ukui/SettingsDaemon/xrandr",
"org.ukui.SettingsDaemon.xrandr");
if(!d->m_usdInterface->isValid()) {
qWarning() << "NotificationGlobalSettings: Fail to creat org.ukui.SettingsDaemon dbus interface!";
return;
}
QDBusReply<int> reply = d->m_usdInterface->call("getScreenMode", "ukui-notification-server");
if (reply.isValid()) {
d->m_currentScreenMode = reply.value();
} else {
qWarning()<<"NotificationGlobalSettings: Call getScreenMode failed!";
}
connect(d->m_usdInterface, SIGNAL(screenModeChanged(int)), this, SLOT(screenModeChanged(int)));
}
NotificationGlobalSettings::~NotificationGlobalSettings()
@ -158,3 +176,30 @@ void NotificationGlobalSettings::setReceiveNotificationsFromApps(bool enable)
SettingsManager::self()->setGlobalSettings(SettingsProperty::ReceiveNotificationsFromApps, enable);
}
bool NotificationGlobalSettings::isDND() {
bool dnd = false;
if(scheduleTurnOnDND()) {
QTime currentTime = QTime::currentTime();
if( currentTime >= scheduleTurnOnDNDTime() && currentTime < scheduleTurnOffDNDTime()) {
dnd = true;
}
}
if(!dnd) {
if(DNDWhileMultiScreen()) {
if(d->m_currentScreenMode == 1 || d->m_currentScreenMode == 2) {
dnd = true;
}
}
}
if(!dnd) {
if(DNDWhileFullScreen()) {
//todo
}
}
return dnd;
}
void NotificationGlobalSettings::screenModeChanged(int mode) {
d->m_currentScreenMode = mode;
}

View File

@ -34,6 +34,7 @@ class NotificationGlobalSettings : public QObject
Q_PROPERTY(bool DNDWhileFullScreen READ DNDWhileFullScreen WRITE setDNDWhileFullScreen NOTIFY DNDWhileFullScreenChanged)
Q_PROPERTY(bool notifyAlarmWhileDND READ notifyAlarmWhileDND WRITE setNotifyAlarmWhileDND NOTIFY notifyAlarmWhileDNDChanged)
Q_PROPERTY(bool receiveNotificationsFromApps READ receiveNotificationsFromApps WRITE setReceiveNotificationsFromApps NOTIFY receiveNotificationsFromAppsChanged)
Q_PROPERTY(bool isDND READ isDND)
public:
NotificationGlobalSettings(QObject *parent = nullptr);
@ -80,6 +81,12 @@ public:
*/
bool receiveNotificationsFromApps();
void setReceiveNotificationsFromApps(bool enable);
/**
*
* @return
*/
bool isDND();
Q_SIGNALS:
void scheduleTurnOnDNDChanged(bool);
void scheduleTurnOnDNDTimeChanged(QTime);
@ -91,6 +98,7 @@ Q_SIGNALS:
private Q_SLOTS:
void settingsDataChanged();
void screenModeChanged(int mode);
private:
NotificationGlobalSettingsPrivate *d = nullptr;
};

View File

@ -1,22 +1,3 @@
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*/
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">

View File

@ -1,22 +1,3 @@
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*/
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="bo_CN" sourcelanguage="en">

View File

@ -1,22 +1,3 @@
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*/
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en" sourcelanguage="en">

View File

@ -1,22 +1,3 @@
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*/
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN" sourcelanguage="en">