Notification: Support do not disturb mode

pull/21/head
kateleet 4 years ago
parent f9375635b0
commit 202ade7e8f

1
debian/control vendored

@ -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

@ -7,6 +7,7 @@ set(SRCS main.cpp
notification.cpp
notificationwindow.cpp
historymodel.cpp
settings.cpp
utils.cpp
dbus/notificationsadaptor.cpp
resources.qrc

@ -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;

@ -22,6 +22,7 @@
#include <QApplication>
#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;
};

@ -2,5 +2,8 @@
<node>
<interface name="com.cutefish.Notification">
<method name="showWindow"></method>
<method name="setDoNotDisturb">
<arg name="enabled" type="b" direction="in"/>
</method>
</interface>
</node>

@ -7,6 +7,7 @@
#include "notificationsmodel.h"
#include "historymodel.h"
#include "notification.h"
#include "settings.h"
#include <QMetaEnum>
#include <QDebug>
@ -207,6 +208,13 @@ void NotificationsModel::removeRows(const QVector<int> &rows)
void NotificationsModel::onNotificationAdded(const Notification &notification)
{
// 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);

@ -0,0 +1,49 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Kate Leet <kateleet@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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();
}
}

@ -0,0 +1,47 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Kate Leet <kateleet@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QSettings>
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
Loading…
Cancel
Save