first ideas for notifications
This commit is contained in:
parent
4c20a314f0
commit
18859cb960
@ -19,6 +19,7 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
#include "enums.h"
|
#include "enums.h"
|
||||||
|
#include "ui/models/roster.h"
|
||||||
|
|
||||||
Shared::Global* Shared::Global::instance = 0;
|
Shared::Global* Shared::Global::instance = 0;
|
||||||
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
|
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
|
||||||
@ -94,6 +95,8 @@ Shared::Global::Global():
|
|||||||
}),
|
}),
|
||||||
defaultSystemStyle(QApplication::style()->objectName()),
|
defaultSystemStyle(QApplication::style()->objectName()),
|
||||||
defaultSystemPalette(QApplication::palette()),
|
defaultSystemPalette(QApplication::palette()),
|
||||||
|
rosterModel(new Models::Roster()),
|
||||||
|
dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()),
|
||||||
pluginSupport({
|
pluginSupport({
|
||||||
{"KWallet", false},
|
{"KWallet", false},
|
||||||
{"openFileManagerWindowJob", 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) \
|
#define FROM_INT_INPL(Enum) \
|
||||||
template<> \
|
template<> \
|
||||||
Enum Shared::Global::fromInt(int src) \
|
Enum Shared::Global::fromInt(int src) \
|
||||||
|
@ -42,12 +42,18 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
|
||||||
|
class Squawk;
|
||||||
|
namespace Models {
|
||||||
|
class Roster;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Shared {
|
namespace Shared {
|
||||||
|
|
||||||
class Global {
|
class Global {
|
||||||
Q_DECLARE_TR_FUNCTIONS(Global)
|
Q_DECLARE_TR_FUNCTIONS(Global)
|
||||||
|
friend class ::Squawk;
|
||||||
public:
|
public:
|
||||||
struct FileInfo {
|
struct FileInfo {
|
||||||
enum class Preview {
|
enum class Preview {
|
||||||
@ -65,6 +71,8 @@ namespace Shared {
|
|||||||
|
|
||||||
Global();
|
Global();
|
||||||
|
|
||||||
|
static void notify(const QString& account, const Shared::Message& msg);
|
||||||
|
|
||||||
static Global* getInstance();
|
static Global* getInstance();
|
||||||
static QString getName(Availability av);
|
static QString getName(Availability av);
|
||||||
static QString getName(ConnectionState cs);
|
static QString getName(ConnectionState cs);
|
||||||
@ -122,6 +130,8 @@ namespace Shared {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static Global* instance;
|
static Global* instance;
|
||||||
|
Models::Roster* rosterModel;
|
||||||
|
QDBusInterface dbus;
|
||||||
|
|
||||||
std::map<QString, bool> pluginSupport;
|
std::map<QString, bool> pluginSupport;
|
||||||
std::map<QString, FileInfo> fileCache;
|
std::map<QString, FileInfo> fileCache;
|
||||||
|
@ -763,7 +763,7 @@ void Models::Roster::removeAccount(const QString& account)
|
|||||||
acc->deleteLater();
|
acc->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Models::Roster::getContactName(const QString& account, const QString& jid)
|
QString Models::Roster::getContactName(const QString& account, const QString& jid) const
|
||||||
{
|
{
|
||||||
ElId id(account, jid);
|
ElId id(account, jid);
|
||||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||||
@ -907,7 +907,7 @@ bool Models::Roster::groupHasContact(const QString& account, const QString& grou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Models::Roster::getContactIconPath(const QString& account, const QString& jid, const QString& resource)
|
QString Models::Roster::getContactIconPath(const QString& account, const QString& jid, const QString& resource) const
|
||||||
{
|
{
|
||||||
ElId id(account, jid);
|
ElId id(account, jid);
|
||||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||||
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||||
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
|
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
|
||||||
QString getContactName(const QString& account, const QString& jid);
|
QString getContactName(const QString& account, const QString& jid) const;
|
||||||
|
|
||||||
QVariant data ( const QModelIndex& index, int role ) const override;
|
QVariant data ( const QModelIndex& index, int role ) const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
|
|
||||||
std::deque<QString> groupList(const QString& account) const;
|
std::deque<QString> groupList(const QString& account) const;
|
||||||
bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const;
|
bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const;
|
||||||
QString getContactIconPath(const QString& account, const QString& jid, const QString& resource);
|
QString getContactIconPath(const QString& account, const QString& jid, const QString& resource) const;
|
||||||
Account* getAccount(const QString& name);
|
Account* getAccount(const QString& name);
|
||||||
QModelIndex getAccountIndex(const QString& name);
|
QModelIndex getAccountIndex(const QString& name);
|
||||||
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
||||||
|
@ -28,10 +28,9 @@ Squawk::Squawk(QWidget *parent) :
|
|||||||
preferences(nullptr),
|
preferences(nullptr),
|
||||||
about(nullptr),
|
about(nullptr),
|
||||||
dialogueQueue(this),
|
dialogueQueue(this),
|
||||||
rosterModel(),
|
rosterModel(*(Shared::Global::getInstance()->rosterModel)),
|
||||||
conversations(),
|
conversations(),
|
||||||
contextMenu(new QMenu()),
|
contextMenu(new QMenu()),
|
||||||
dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()),
|
|
||||||
vCards(),
|
vCards(),
|
||||||
currentConversation(nullptr),
|
currentConversation(nullptr),
|
||||||
restoreSelection(),
|
restoreSelection(),
|
||||||
@ -441,33 +440,7 @@ void Squawk::changeMessage(const QString& account, const QString& jid, const QSt
|
|||||||
|
|
||||||
void Squawk::notify(const QString& account, const Shared::Message& msg)
|
void Squawk::notify(const QString& account, const Shared::Message& msg)
|
||||||
{
|
{
|
||||||
QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid()));
|
Shared::Global::notify(account, msg);
|
||||||
QString path = QString(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;
|
|
||||||
dbus.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squawk::onConversationMessage(const Shared::Message& msg)
|
void Squawk::onConversationMessage(const Shared::Message& msg)
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QtDBus/QDBusInterface>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
|
||||||
@ -43,6 +42,7 @@
|
|||||||
#include "dialogqueue.h"
|
#include "dialogqueue.h"
|
||||||
|
|
||||||
#include "shared/shared.h"
|
#include "shared/shared.h"
|
||||||
|
#include "shared/global.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Squawk;
|
class Squawk;
|
||||||
@ -124,10 +124,9 @@ private:
|
|||||||
Settings* preferences;
|
Settings* preferences;
|
||||||
About* about;
|
About* about;
|
||||||
DialogQueue dialogueQueue;
|
DialogQueue dialogueQueue;
|
||||||
Models::Roster rosterModel;
|
Models::Roster& rosterModel;
|
||||||
Conversations conversations;
|
Conversations conversations;
|
||||||
QMenu* contextMenu;
|
QMenu* contextMenu;
|
||||||
QDBusInterface dbus;
|
|
||||||
std::map<QString, VCard*> vCards;
|
std::map<QString, VCard*> vCards;
|
||||||
Conversation* currentConversation;
|
Conversation* currentConversation;
|
||||||
QModelIndex restoreSelection;
|
QModelIndex restoreSelection;
|
||||||
|
Loading…
Reference in New Issue
Block a user