save
This commit is contained in:
parent
5e4ae7657b
commit
48469bb635
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.2" date="2021-06-15"/>
|
||||
<release version="3.9.2" date="2021-06-17"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -7,7 +7,6 @@
|
||||
<file>text/COPYING_GNU_GPL_HTML</file>
|
||||
|
||||
<file>sounds/boing.wav</file>
|
||||
<file>sounds/doorbell.wav</file>
|
||||
<file>sounds/rooster.wav</file>
|
||||
<file>sounds/sheep.wav</file>
|
||||
|
||||
|
Binary file not shown.
@ -3,6 +3,7 @@
|
||||
#include "gui/notifications/notificationseditor.h"
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/notifications/singlenotificationeditor.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
@ -24,14 +25,15 @@ void NotificationsEditor::loadNotifications(const QList<Notification>& notificat
|
||||
return n.event() == ev;
|
||||
}), this);
|
||||
|
||||
notif_editor->setNotificationEnabled(true);
|
||||
connect(notif_editor, &SingleNotificationEditor::notificationChanged, this, &NotificationsEditor::someNotificationChanged);
|
||||
|
||||
m_layout->addWidget(notif_editor);
|
||||
}
|
||||
else {
|
||||
auto* notif_editor = new SingleNotificationEditor(Notification(ev, {}), this);
|
||||
auto* notif_editor = new SingleNotificationEditor(Notification(ev), this);
|
||||
|
||||
connect(notif_editor, &SingleNotificationEditor::notificationChanged, this, &NotificationsEditor::someNotificationChanged);
|
||||
|
||||
notif_editor->setNotificationEnabled(false);
|
||||
m_layout->addWidget(notif_editor);
|
||||
|
||||
}
|
||||
@ -39,3 +41,11 @@ void NotificationsEditor::loadNotifications(const QList<Notification>& notificat
|
||||
|
||||
m_layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
}
|
||||
|
||||
QList<Notification> NotificationsEditor::allNotifications() const {
|
||||
auto lst = boolinq::from(findChildren<SingleNotificationEditor*>()).select([](const SingleNotificationEditor* ed) {
|
||||
return ed->notification();
|
||||
}).toStdList();
|
||||
|
||||
return FROM_STD_LIST(QList<Notification>, lst);
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ class NotificationsEditor : public QScrollArea {
|
||||
|
||||
void loadNotifications(const QList<Notification>& notifications);
|
||||
|
||||
QList<Notification> allNotifications() const;
|
||||
|
||||
signals:
|
||||
void someNotificationChanged();
|
||||
|
||||
private:
|
||||
Ui::NotificationsEditor m_ui;
|
||||
QVBoxLayout* m_layout;
|
||||
|
@ -6,35 +6,30 @@
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
SingleNotificationEditor::SingleNotificationEditor(const Notification& notification, QWidget* parent)
|
||||
: QWidget(parent), m_notificationEvent(Notification::Event::UnknownEvent) {
|
||||
: QWidget(parent), m_notificationEvent(Notification::Event::NoEvent) {
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.m_btnBrowseSound->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
|
||||
m_ui.m_btnPlaySound->setIcon(qApp->icons()->fromTheme(QSL("media-playback-start")));
|
||||
|
||||
connect(m_ui.m_btnPlaySound, &QPushButton::clicked, this, &SingleNotificationEditor::playSound);
|
||||
|
||||
loadNotification(notification);
|
||||
|
||||
connect(m_ui.m_btnPlaySound, &QPushButton::clicked, this, &SingleNotificationEditor::playSound);
|
||||
connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged);
|
||||
connect(m_ui.m_cbBalloon, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged);
|
||||
}
|
||||
|
||||
Notification SingleNotificationEditor::notification() const {
|
||||
return Notification(m_notificationEvent, m_ui.m_txtSound->text());
|
||||
}
|
||||
|
||||
bool SingleNotificationEditor::notificationEnabled() const {
|
||||
return m_ui.m_gbNotification->isChecked();
|
||||
}
|
||||
|
||||
void SingleNotificationEditor::setNotificationEnabled(bool enabled) {
|
||||
m_ui.m_gbNotification->setChecked(enabled);
|
||||
return Notification(m_notificationEvent, m_ui.m_cbBalloon->isChecked(), m_ui.m_txtSound->text());
|
||||
}
|
||||
|
||||
void SingleNotificationEditor::playSound() {
|
||||
Notification({}, m_ui.m_txtSound->text()).playSound(qApp);
|
||||
Notification({}, {}, m_ui.m_txtSound->text()).playSound(qApp);
|
||||
}
|
||||
|
||||
void SingleNotificationEditor::loadNotification(const Notification& notification) {
|
||||
m_ui.m_txtSound->setText(notification.soundPath());
|
||||
m_ui.m_cbBalloon->setChecked(notification.balloonEnabled());
|
||||
m_ui.m_gbNotification->setTitle(Notification::nameForEvent(notification.event()));
|
||||
|
||||
m_notificationEvent = notification.event();
|
||||
|
@ -17,8 +17,8 @@ class SingleNotificationEditor : public QWidget {
|
||||
|
||||
Notification notification() const;
|
||||
|
||||
bool notificationEnabled() const;
|
||||
void setNotificationEnabled(bool enabled);
|
||||
signals:
|
||||
void notificationChanged();
|
||||
|
||||
private slots:
|
||||
void playSound();
|
||||
|
@ -40,18 +40,18 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Sound</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>m_txtSound</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_txtSound">
|
||||
@ -76,11 +76,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="m_cbBalloon">
|
||||
<property name="text">
|
||||
<string>Balloon notification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>m_cbBalloon</tabstop>
|
||||
<tabstop>m_txtSound</tabstop>
|
||||
<tabstop>m_btnBrowseSound</tabstop>
|
||||
<tabstop>m_btnPlaySound</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -116,7 +116,7 @@
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_tabNotifications">
|
||||
<attribute name="title">
|
||||
<string>Tray area && notifications</string>
|
||||
<string>Tray area</string>
|
||||
</attribute>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<item row="0" column="0">
|
||||
|
@ -15,8 +15,10 @@ SettingsNotifications::SettingsNotifications(Settings* settings, QWidget* parent
|
||||
m_ui.setupUi(this);
|
||||
|
||||
GuiUtilities::setLabelAsNotice(*m_ui.m_lblAvailableSounds, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui.m_lblInfo, true);
|
||||
|
||||
connect(m_ui.m_checkEnableNotifications, &QCheckBox::toggled, this, &SettingsNotifications::dirtifySettings);
|
||||
connect(m_ui.m_editor, &NotificationsEditor::someNotificationChanged, this, &SettingsNotifications::dirtifySettings);
|
||||
}
|
||||
|
||||
void SettingsNotifications::loadSettings() {
|
||||
@ -43,6 +45,7 @@ void SettingsNotifications::saveSettings() {
|
||||
|
||||
// Save notifications.
|
||||
settings()->setValue(GROUP(Notifications), Notifications::EnableNotifications, m_ui.m_checkEnableNotifications->isChecked());
|
||||
qApp->notifications()->save(m_ui.m_editor->allNotifications(), settings());
|
||||
|
||||
onEndSaveSettings();
|
||||
}
|
||||
|
@ -26,14 +26,14 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="m_checkEnableNotifications">
|
||||
<property name="text">
|
||||
<string>Enable notifications</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="NotificationsEditor" name="m_editor" native="true">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
@ -46,9 +46,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QLabel" name="m_lblAvailableSounds"/>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="m_lblInfo">
|
||||
<property name="text">
|
||||
<string>You must have "tray icon" activated to have notifications working.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -90,6 +90,7 @@ Application::Application(const QString& id, int& argc, char** argv)
|
||||
if (isFirstRun()) {
|
||||
m_notifications->save({
|
||||
Notification(Notification::Event::NewArticlesFetched,
|
||||
true,
|
||||
QSL("%1/rooster.wav").arg(SOUNDS_BUILTIN_DIRECTORY))
|
||||
}, settings());
|
||||
}
|
||||
|
@ -7,9 +7,8 @@
|
||||
#include <QDir>
|
||||
#include <QSound>
|
||||
|
||||
Notification::Notification() {}
|
||||
|
||||
Notification::Notification(Notification::Event event, const QString& sound_path) : m_event(event), m_soundPath(sound_path) {}
|
||||
Notification::Notification(Notification::Event event, bool balloon, const QString& sound_path)
|
||||
: m_event(event), m_balloonEnabled(balloon), m_soundPath(sound_path) {}
|
||||
|
||||
Notification::Event Notification::event() const {
|
||||
return m_event;
|
||||
@ -54,3 +53,8 @@ QString Notification::nameForEvent(Notification::Event event) {
|
||||
return QObject::tr("Unknown event");
|
||||
}
|
||||
}
|
||||
|
||||
bool Notification::balloonEnabled() const
|
||||
{
|
||||
return m_balloonEnabled;
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ class Application;
|
||||
class Notification {
|
||||
public:
|
||||
enum class Event {
|
||||
UnknownEvent = 0,
|
||||
// Is here to provide "empty" events - events which should
|
||||
// not trigger any notifications.
|
||||
NoEvent = 0,
|
||||
|
||||
// New (unread) messages were downloaded for some feed.
|
||||
NewArticlesFetched = 1,
|
||||
@ -26,8 +28,9 @@ class Notification {
|
||||
// TODO: app update is available
|
||||
};
|
||||
|
||||
explicit Notification();
|
||||
explicit Notification(Event event, const QString& sound_path);
|
||||
explicit Notification(Event event = Event::NoEvent, bool balloon = {}, const QString& sound_path = {});
|
||||
|
||||
bool balloonEnabled() const;
|
||||
|
||||
Event event() const;
|
||||
void setEvent(const Event& event);
|
||||
@ -45,6 +48,7 @@ class Notification {
|
||||
|
||||
private:
|
||||
Event m_event;
|
||||
bool m_balloonEnabled;
|
||||
QString m_soundPath;
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
@ -16,12 +17,21 @@ QList<Notification> NotificationFactory::allNotifications() const {
|
||||
}
|
||||
|
||||
Notification NotificationFactory::notificationForEvent(Notification::Event event) const {
|
||||
if (!qApp->settings()->value(GROUP(Notifications), SETTING(Notifications::EnableNotifications)).toBool()) {
|
||||
return Notification();
|
||||
}
|
||||
|
||||
auto good_n = boolinq::from(m_notifications).where([event](const Notification& n) {
|
||||
return n.event() == event;
|
||||
});
|
||||
|
||||
if (good_n.count() <= 0) {
|
||||
throw ApplicationException(QSL("notification for event %1 was not found").arg(QString::number(int(event))));
|
||||
qCriticalNN << LOGSEC_CORE
|
||||
<< "Notification for event"
|
||||
<< QUOTE_W_SPACE(int(event))
|
||||
<< "not found";
|
||||
|
||||
return Notification();
|
||||
}
|
||||
else {
|
||||
return good_n.first();
|
||||
@ -35,9 +45,11 @@ void NotificationFactory::load(Settings* settings) {
|
||||
|
||||
for (const auto& key : notif_keys) {
|
||||
auto event = Notification::Event(key.toInt());
|
||||
auto sound = settings->value(GROUP(Notifications), key).toString();
|
||||
auto data = settings->value(GROUP(Notifications), key).toStringList();
|
||||
auto enabled = data.at(0).toInt() != 0;
|
||||
auto sound = data.at(1);
|
||||
|
||||
m_notifications.append(Notification(event, sound));
|
||||
m_notifications.append(Notification(event, enabled, sound));
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +58,9 @@ void NotificationFactory::save(const QList<Notification>& new_notifications, Set
|
||||
m_notifications = new_notifications;
|
||||
|
||||
for (const auto& n : qAsConst(m_notifications)) {
|
||||
settings->setValue(GROUP(Notifications), QString::number(int(n.event())), n.soundPath());
|
||||
settings->setValue(GROUP(Notifications), QString::number(int(n.event())), QStringList {
|
||||
n.balloonEnabled() ? QSL("1") : QSL("0"),
|
||||
n.soundPath()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user