first ideas for notifications

This commit is contained in:
Blue 2022-04-18 19:54:42 +03:00
parent 4c20a314f0
commit 18859cb960
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 55 additions and 38 deletions

View file

@ -19,6 +19,7 @@
#include "global.h"
#include "enums.h"
#include "ui/models/roster.h"
Shared::Global* Shared::Global::instance = 0;
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
@ -94,6 +95,8 @@ Shared::Global::Global():
}),
defaultSystemStyle(QApplication::style()->objectName()),
defaultSystemPalette(QApplication::palette()),
rosterModel(new Models::Roster()),
dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()),
pluginSupport({
{"KWallet", false},
{"openFileManagerWindowJob", false},
@ -349,6 +352,38 @@ void Shared::Global::setStyle(const QString& style)
}
}
void Shared::Global::notify(const QString& account, const Shared::Message& msg)
{
QString name = QString(instance->rosterModel->getContactName(account, msg.getPenPalJid()));
QString path = QString(instance->rosterModel->getContactIconPath(account, msg.getPenPalJid(), msg.getPenPalResource()));
QVariantList args;
args << QString(QCoreApplication::applicationName());
args << QVariant(QVariant::UInt); //TODO some normal id
if (path.size() > 0) {
args << path;
} else {
args << QString("mail-message"); //TODO should here better be unknown user icon?
}
if (msg.getType() == Shared::Message::groupChat) {
args << msg.getFromResource() + " from " + name;
} else {
args << name;
}
QString body(msg.getBody());
QString oob(msg.getOutOfBandUrl());
if (body == oob) {
body = tr("Attached file");
}
args << body;
args << QStringList();
args << QVariantMap();
args << 3000;
instance->dbus.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
}
#define FROM_INT_INPL(Enum) \
template<> \
Enum Shared::Global::fromInt(int src) \