diff --git a/debian/control b/debian/control index d88d125..36aa903 100644 --- a/debian/control +++ b/debian/control @@ -56,7 +56,6 @@ Depends: accountsservice, qml-module-qtquick-shapes, appmenu-gtk2-module, appmenu-gtk3-module, - appmenu-gtk-module-common, ${misc:Depends}, ${shlibs:Depends} Description: CutefishOS System Components diff --git a/notificationd/CMakeLists.txt b/notificationd/CMakeLists.txt index e6448a5..ac334d1 100644 --- a/notificationd/CMakeLists.txt +++ b/notificationd/CMakeLists.txt @@ -7,6 +7,7 @@ set(SRCS main.cpp notification.cpp notificationwindow.cpp historymodel.cpp + settings.cpp utils.cpp dbus/notificationsadaptor.cpp resources.qrc diff --git a/notificationd/application.cpp b/notificationd/application.cpp index c2e26c4..4507c70 100644 --- a/notificationd/application.cpp +++ b/notificationd/application.cpp @@ -43,6 +43,7 @@ Application::Application(int& argc, char** argv) , m_notificationServer(NotificationServer::self()) , m_model(NotificationsModel::self()) , m_window(nullptr) + , m_settings(Settings::self()) , m_instance(false) { if (QDBusConnection::sessionBus().registerService("com.cutefish.Notification")) { @@ -77,6 +78,11 @@ void Application::showWindow() m_window->open(); } +void Application::setDoNotDisturb(bool enabled) +{ + m_settings->setDoNotDisturb(enabled); +} + int Application::run() { if (!parseCommandLineArgs()) @@ -84,6 +90,7 @@ int Application::run() QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("notificationsModel", m_model); + engine.rootContext()->setContextProperty("Settings", m_settings); engine.load(QUrl("qrc:/qml/main.qml")); m_window = new NotificationWindow; diff --git a/notificationd/application.h b/notificationd/application.h index af2fc6e..0aa941b 100644 --- a/notificationd/application.h +++ b/notificationd/application.h @@ -22,6 +22,7 @@ #include #include "notificationwindow.h" +#include "settings.h" class NotificationServer; class NotificationsModel; @@ -33,6 +34,7 @@ public: explicit Application(int& argc, char** argv); void showWindow(); + void setDoNotDisturb(bool enabled); int run(); bool parseCommandLineArgs(); @@ -41,6 +43,7 @@ private: NotificationServer *m_notificationServer; NotificationsModel *m_model; NotificationWindow *m_window; + Settings *m_settings; bool m_instance; }; diff --git a/notificationd/com.cutefish.Notification.xml b/notificationd/com.cutefish.Notification.xml index 9dabaab..23581fd 100644 --- a/notificationd/com.cutefish.Notification.xml +++ b/notificationd/com.cutefish.Notification.xml @@ -2,5 +2,8 @@ + + + diff --git a/notificationd/notificationsmodel.cpp b/notificationd/notificationsmodel.cpp index c7597e5..979566d 100644 --- a/notificationd/notificationsmodel.cpp +++ b/notificationd/notificationsmodel.cpp @@ -7,6 +7,7 @@ #include "notificationsmodel.h" #include "historymodel.h" #include "notification.h" +#include "settings.h" #include #include @@ -207,6 +208,13 @@ void NotificationsModel::removeRows(const QVector &rows) void NotificationsModel::onNotificationAdded(const Notification ¬ification) { + // Do Not Disturb Mode: + // Add directly to the historical model. + if (Settings::self()->doNotDisturb()) { + HistoryModel::self()->add(notification); + return; + } + if (m_notifications.size() >= s_notificationsLimit) { const int cleanupCount = s_notificationsLimit / 2; beginRemoveRows(QModelIndex(), 0, cleanupCount - 1); diff --git a/notificationd/settings.cpp b/notificationd/settings.cpp new file mode 100644 index 0000000..c4804a5 --- /dev/null +++ b/notificationd/settings.cpp @@ -0,0 +1,49 @@ +/* + * 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 "settings.h" + +Settings *Settings::self() +{ + static Settings s; + return &s; +} + +Settings::Settings(QObject *parent) + : QObject(parent) + , m_settings(QSettings::UserScope, "cutefishos", "notification") +{ + m_doNotDisturb = m_settings.value("DoNotDisturb", false).toBool(); +} + +bool Settings::doNotDisturb() const +{ + return m_doNotDisturb; +} + +void Settings::setDoNotDisturb(bool doNotDisturb) +{ + if (m_doNotDisturb != doNotDisturb) { + m_doNotDisturb = doNotDisturb; + + m_settings.setValue("DoNotDisturb", m_doNotDisturb); + + emit doNotDisturbChanged(); + } +} diff --git a/notificationd/settings.h b/notificationd/settings.h new file mode 100644 index 0000000..18e7964 --- /dev/null +++ b/notificationd/settings.h @@ -0,0 +1,47 @@ +/* + * 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 SETTINGS_H +#define SETTINGS_H + +#include +#include + +class Settings : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged) + +public: + static Settings *self(); + + explicit Settings(QObject *parent = nullptr); + + bool doNotDisturb() const; + void setDoNotDisturb(bool doNotDisturb); + +signals: + void doNotDisturbChanged(); + +private: + QSettings m_settings; + bool m_doNotDisturb; +}; + +#endif // SETTINGS_H