Show notifications
This commit is contained in:
33
imports/NeoChat/Page/SettingsPage.qml
Normal file
33
imports/NeoChat/Page/SettingsPage.qml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick 2.14
|
||||||
|
import QtQuick.Controls 2.14 as QQC2
|
||||||
|
import QtQuick.Layouts 1.14
|
||||||
|
|
||||||
|
import org.kde.kirigami 2.12 as Kirigami
|
||||||
|
|
||||||
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
|
Kirigami.ScrollablePage {
|
||||||
|
title: i18n("Settings")
|
||||||
|
|
||||||
|
Kirigami.FormLayout {
|
||||||
|
QQC2.CheckBox {
|
||||||
|
id: showNotifications
|
||||||
|
Kirigami.FormData.label: i18n("Show Notifications:")
|
||||||
|
checked: Config.showNotifications
|
||||||
|
}
|
||||||
|
|
||||||
|
QQC2.Button {
|
||||||
|
text: i18n("Save")
|
||||||
|
onClicked: {
|
||||||
|
Config.showNotifications = showNotifications.checked;
|
||||||
|
Config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,4 +5,5 @@ RoomListPage 1.0 RoomListPage.qml
|
|||||||
RoomPage 1.0 RoomPage.qml
|
RoomPage 1.0 RoomPage.qml
|
||||||
JoinRoomPage 1.0 JoinRoomPage.qml
|
JoinRoomPage 1.0 JoinRoomPage.qml
|
||||||
InviteUserPage 1.0 InviteUserPage.qml
|
InviteUserPage 1.0 InviteUserPage.qml
|
||||||
|
SettingsPage 1.0 SettingsPage.qml
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ Kirigami.ApplicationWindow {
|
|||||||
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/AccountsPage.qml")
|
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/AccountsPage.qml")
|
||||||
enabled: pageStack.layers.currentItem.title !== i18n("Accounts")
|
enabled: pageStack.layers.currentItem.title !== i18n("Accounts")
|
||||||
},
|
},
|
||||||
|
Kirigami.Action {
|
||||||
|
text: i18n("Settings")
|
||||||
|
iconName: "settings-configure"
|
||||||
|
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/SettingsPage.qml")
|
||||||
|
enabled: pageStack.layers.currentItem.title !== i18n("Settings")
|
||||||
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: i18n("About Neochat")
|
text: i18n("About Neochat")
|
||||||
iconName: "help-about"
|
iconName: "help-about"
|
||||||
|
|||||||
1
res.qrc
1
res.qrc
@@ -11,6 +11,7 @@
|
|||||||
<file>imports/NeoChat/Page/AccountsPage.qml</file>
|
<file>imports/NeoChat/Page/AccountsPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/JoinRoomPage.qml</file>
|
<file>imports/NeoChat/Page/JoinRoomPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/InviteUserPage.qml</file>
|
<file>imports/NeoChat/Page/InviteUserPage.qml</file>
|
||||||
|
<file>imports/NeoChat/Page/SettingsPage.qml</file>
|
||||||
<file>imports/NeoChat/Component/qmldir</file>
|
<file>imports/NeoChat/Component/qmldir</file>
|
||||||
<file>imports/NeoChat/Component/ChatTextInput.qml</file>
|
<file>imports/NeoChat/Component/ChatTextInput.qml</file>
|
||||||
<file>imports/NeoChat/Component/AutoMouseArea.qml</file>
|
<file>imports/NeoChat/Component/AutoMouseArea.qml</file>
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ if(ANDROID)
|
|||||||
"go-down"
|
"go-down"
|
||||||
"list-add"
|
"list-add"
|
||||||
"irc-join-channel"
|
"irc-join-channel"
|
||||||
|
"settings-configure"
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(neochat PRIVATE Qt5::Widgets ${QTKEYCHAIN_LIBRARIES})
|
target_link_libraries(neochat PRIVATE Qt5::Widgets ${QTKEYCHAIN_LIBRARIES})
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterType<PublicRoomListModel>("org.kde.neochat", 1, 0, "PublicRoomListModel");
|
qmlRegisterType<PublicRoomListModel>("org.kde.neochat", 1, 0, "PublicRoomListModel");
|
||||||
qmlRegisterType<UserDirectoryListModel>("org.kde.neochat", 1, 0, "UserDirectoryListModel");
|
qmlRegisterType<UserDirectoryListModel>("org.kde.neochat", 1, 0, "UserDirectoryListModel");
|
||||||
qmlRegisterType<EmojiModel>("org.kde.neochat", 1, 0, "EmojiModel");
|
qmlRegisterType<EmojiModel>("org.kde.neochat", 1, 0, "EmojiModel");
|
||||||
qmlRegisterType<NotificationsManager>("org.kde.neochat", 1, 0, "NotificationsManager");
|
|
||||||
qmlRegisterType<TrayIcon>("org.kde.neochat", 1, 0, "TrayIcon");
|
qmlRegisterType<TrayIcon>("org.kde.neochat", 1, 0, "TrayIcon");
|
||||||
qmlRegisterType<SortFilterRoomListModel>("org.kde.neochat", 1, 0, "SortFilterRoomListModel");
|
qmlRegisterType<SortFilterRoomListModel>("org.kde.neochat", 1, 0, "SortFilterRoomListModel");
|
||||||
qmlRegisterUncreatableType<RoomMessageEvent>("org.kde.neochat", 1, 0, "RoomMessageEvent", "ENUM");
|
qmlRegisterUncreatableType<RoomMessageEvent>("org.kde.neochat", 1, 0, "RoomMessageEvent", "ENUM");
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
<entry name="OpenRoom" type="String">
|
<entry name="OpenRoom" type="String">
|
||||||
<label>Latest opened room</label>
|
<label>Latest opened room</label>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="ShowNotifications" type="bool">
|
||||||
|
<label>Show notifications</label>
|
||||||
|
<default>true</default>
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
</kcfg>
|
</kcfg>
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "jobs/downloadfilejob.h"
|
#include "jobs/downloadfilejob.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "notificationsmanager.h"
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
@@ -43,6 +44,18 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
|||||||
setFileUploadingProgress(0);
|
setFileUploadingProgress(0);
|
||||||
setHasFileUploading(false);
|
setHasFileUploading(false);
|
||||||
});
|
});
|
||||||
|
connect(this, &NeoChatRoom::notificationCountChanged, this, [this]() {
|
||||||
|
if(messageEvents().size() == 0)
|
||||||
|
return;
|
||||||
|
const RoomEvent *lastEvent = messageEvents().rbegin()->get();
|
||||||
|
if (lastEvent->isStateEvent())
|
||||||
|
return;
|
||||||
|
User *sender = user(lastEvent->senderId());
|
||||||
|
if (sender == localUser())
|
||||||
|
return;
|
||||||
|
|
||||||
|
NotificationsManager::instance().postNotification(id(), lastEvent->id(), displayName(), sender->displayname(this), eventToString(*lastEvent), avatar(128));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
|
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
|
||||||
|
|||||||
@@ -11,6 +11,15 @@
|
|||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
|
|
||||||
|
#include "neochatconfig.h"
|
||||||
|
|
||||||
|
NotificationsManager &NotificationsManager::instance()
|
||||||
|
{
|
||||||
|
static NotificationsManager _instance;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
@@ -18,6 +27,10 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
|||||||
|
|
||||||
void NotificationsManager::postNotification(const QString &roomid, const QString &eventid, const QString &roomname, const QString &sender, const QString &text, const QImage &icon)
|
void NotificationsManager::postNotification(const QString &roomid, const QString &eventid, const QString &roomname, const QString &sender, const QString &text, const QImage &icon)
|
||||||
{
|
{
|
||||||
|
if(!NeoChatConfig::self()->showNotifications()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap img;
|
QPixmap img;
|
||||||
img.convertFromImage(icon);
|
img.convertFromImage(icon);
|
||||||
KNotification *notification = new KNotification("message");
|
KNotification *notification = new KNotification("message");
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ class NotificationsManager : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NotificationsManager(QObject *parent = nullptr);
|
static NotificationsManager &instance();
|
||||||
|
|
||||||
Q_INVOKABLE void postNotification(const QString &roomId, const QString &eventId, const QString &roomName, const QString &senderName, const QString &text, const QImage &icon);
|
Q_INVOKABLE void postNotification(const QString &roomId, const QString &eventId, const QString &roomName, const QString &senderName, const QString &text, const QImage &icon);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
NotificationsManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
QMultiMap<QString, KNotification *> m_notifications;
|
QMultiMap<QString, KNotification *> m_notifications;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user