From 8d212bbea23c36cb72eb30fa54a74344bbafa68d Mon Sep 17 00:00:00 2001 From: kateleet Date: Thu, 25 Nov 2021 17:04:09 +0800 Subject: [PATCH] Add notifications page and complete do not disturb mode --- CMakeLists.txt | 1 + src/application.cpp | 2 + src/images/sidebar/dark/notifications.svg | 16 ++++++ src/notifications.cpp | 50 +++++++++++++++++++ src/notifications.h | 43 ++++++++++++++++ src/qml/DateTime/Main.qml | 2 +- src/qml/Notification/Main.qml | 61 +++++++++++++++++++++++ src/qml/SideBar.qml | 9 ++++ src/resources.qrc | 2 + translations/en_US.ts | 34 +++++++++---- translations/zh_CN.ts | 34 +++++++++---- 11 files changed, 235 insertions(+), 19 deletions(-) create mode 100644 src/images/sidebar/dark/notifications.svg create mode 100644 src/notifications.cpp create mode 100644 src/notifications.h create mode 100644 src/qml/Notification/Main.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index d0567b1..e642a79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ set(SRCS src/language.cpp src/about.cpp src/background.cpp + src/notifications.cpp src/password.cpp src/batteryhistorymodel.cpp src/cicontheme.cpp diff --git a/src/application.cpp b/src/application.cpp index 12b82b8..1c4e73e 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -19,6 +19,7 @@ #include "powermanager.h" #include "touchpad.h" #include "networkproxy.h" +#include "notifications.h" #include "cursor/cursorthememodel.h" #include "cursor/mouse.h" @@ -79,6 +80,7 @@ Application::Application(int &argc, char **argv) qmlRegisterType(uri, 1, 0, "TimeZoneMap"); qmlRegisterType(uri, 1, 0, "Touchpad"); qmlRegisterType(uri, 1, 0, "NetworkProxy"); + qmlRegisterType(uri, 1, 0, "Notifications"); qmlRegisterSingletonType(uri, 1, 0, "Password", passwordSingleton); diff --git a/src/images/sidebar/dark/notifications.svg b/src/images/sidebar/dark/notifications.svg new file mode 100644 index 0000000..8e9abc9 --- /dev/null +++ b/src/images/sidebar/dark/notifications.svg @@ -0,0 +1,16 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/notifications.cpp b/src/notifications.cpp new file mode 100644 index 0000000..d8602ff --- /dev/null +++ b/src/notifications.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 + * 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 . + */ + +#include "notifications.h" +#include +#include +#include + +Notifications::Notifications(QObject *parent) + : QObject(parent) +{ + QSettings settings(QSettings::UserScope, "cutefishos", "notification"); + m_doNotDisturb = settings.value("DoNotDisturb", false).toBool(); +} + +bool Notifications::doNotDisturb() const +{ + return m_doNotDisturb; +} + +void Notifications::setDoNotDisturb(bool enabled) +{ + m_doNotDisturb = enabled; + + QDBusInterface iface("com.cutefish.Notification", + "/Notification", + "com.cutefish.Notification", QDBusConnection::sessionBus()); + + if (iface.isValid()) { + iface.asyncCall("setDoNotDisturb", enabled); + } + + emit doNotDisturbChanged(); +} diff --git a/src/notifications.h b/src/notifications.h new file mode 100644 index 0000000..c564354 --- /dev/null +++ b/src/notifications.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 + * 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 . + */ + +#ifndef NOTIFICATIONS_H +#define NOTIFICATIONS_H + +#include + +class Notifications : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged) + +public: + explicit Notifications(QObject *parent = nullptr); + + bool doNotDisturb() const; + void setDoNotDisturb(bool enabled); + +signals: + void doNotDisturbChanged(); + +private: + bool m_doNotDisturb; +}; + +#endif // NOTIFICATIONS_H diff --git a/src/qml/DateTime/Main.qml b/src/qml/DateTime/Main.qml index 3575ea5..7b68062 100644 --- a/src/qml/DateTime/Main.qml +++ b/src/qml/DateTime/Main.qml @@ -46,7 +46,7 @@ ItemPage { ColumnLayout { id: layout anchors.fill: parent - spacing: FishUI.Units.largeSpacing + spacing: FishUI.Units.largeSpacing * 2 RoundedItem { spacing: FishUI.Units.largeSpacing * 1.5 diff --git a/src/qml/Notification/Main.qml b/src/qml/Notification/Main.qml new file mode 100644 index 0000000..471b20f --- /dev/null +++ b/src/qml/Notification/Main.qml @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 + * 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 . + */ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import FishUI 1.0 as FishUI +import Cutefish.Settings 1.0 +import "../" + +ItemPage { + headerTitle: qsTr("Notifications") + + Notifications { + id: notifications + } + + Scrollable { + anchors.fill: parent + contentHeight: layout.implicitHeight + + ColumnLayout { + id: layout + anchors.fill: parent + + RoundedItem { + RowLayout { + Label { + text: qsTr("Do Not Disturb") + } + + Item { + Layout.fillWidth: true + } + + Switch { + checked: notifications.doNotDisturb + Layout.fillHeight: true + onClicked: notifications.doNotDisturb = checked + } + } + } + } + } +} diff --git a/src/qml/SideBar.qml b/src/qml/SideBar.qml index ca0e22d..9020d55 100644 --- a/src/qml/SideBar.qml +++ b/src/qml/SideBar.qml @@ -159,6 +159,15 @@ Item { category: qsTr("System") } + ListElement { + title: qsTr("Notifications") + name: "notifications" + page: "qrc:/qml/Notification/Main.qml" + iconSource: "notifications.svg" + iconColor: "#F16884" + category: qsTr("System") + } + ListElement { title: qsTr("Sound") name: "sound" diff --git a/src/resources.qrc b/src/resources.qrc index 8dc9623..0c71438 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -141,5 +141,7 @@ images/dark/audio-input-microphone-medium-symbolic.svg qml/DefaultApp/Main.qml images/sidebar/dark/defaultapps.svg + qml/Notification/Main.qml + images/sidebar/dark/notifications.svg diff --git a/translations/en_US.ts b/translations/en_US.ts index 0eab786..438025d 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -774,6 +774,16 @@ Terminal + + + Notifications + + + + + Do Not Disturb + + PairDialog @@ -871,12 +881,12 @@ Appearance - + Mouse - + Default Applications @@ -905,47 +915,53 @@ - + + System + Notifications + + + + Sound - + Touchpad - + Date & Time - + Language Language - + Battery - + Power - + About About diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index d4b527f..88f99c2 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -774,6 +774,16 @@ Terminal 终端 + + + Notifications + 通知 + + + + Do Not Disturb + 勿扰模式 + PairDialog @@ -861,7 +871,7 @@ 外观 - + Mouse 鼠标 @@ -900,52 +910,58 @@ - + + System 系统 + Notifications + 通知 + + + Sound 声音 - + Touchpad 触摸版 - + Date & Time 日期和时间 - + Default Applications 默认应用 - + Language 语言 - + Battery 电池 - + Power 电源 - + About 关于