forked from blue/squawk
Now notifications have actions! Some more usefull functions to roster model
This commit is contained in:
parent
3916aec358
commit
e58213b294
15 changed files with 205 additions and 30 deletions
|
@ -26,7 +26,8 @@ Application::Application(Core::Squawk* p_core):
|
|||
conversations(),
|
||||
dialogueQueue(roster),
|
||||
nowQuitting(false),
|
||||
destroyingSquawk(false)
|
||||
destroyingSquawk(false),
|
||||
storage()
|
||||
{
|
||||
connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify);
|
||||
connect(&roster, &Models::Roster::unreadMessagesCountChanged, this, &Application::unreadMessagesCountChanged);
|
||||
|
@ -90,6 +91,23 @@ Application::Application(Core::Squawk* p_core):
|
|||
connect(core, &Core::Squawk::requestPassword, this, &Application::requestPassword);
|
||||
connect(core, &Core::Squawk::ready, this, &Application::readSettings);
|
||||
|
||||
QDBusConnection sys = QDBusConnection::sessionBus();
|
||||
sys.connect(
|
||||
"org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"NotificationClosed",
|
||||
this,
|
||||
SLOT(onNotificationClosed(quint32, quint32))
|
||||
);
|
||||
sys.connect(
|
||||
"org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"ActionInvoked",
|
||||
this,
|
||||
SLOT(onNotificationInvoked(quint32, const QString&))
|
||||
);
|
||||
}
|
||||
|
||||
Application::~Application() {}
|
||||
|
@ -188,12 +206,14 @@ void Application::onSquawkDestroyed() {
|
|||
|
||||
void Application::notify(const QString& account, const Shared::Message& msg)
|
||||
{
|
||||
QString name = QString(roster.getContactName(account, msg.getPenPalJid()));
|
||||
QString path = QString(roster.getContactIconPath(account, msg.getPenPalJid(), msg.getPenPalResource()));
|
||||
QString jid = msg.getPenPalJid();
|
||||
QString name = QString(roster.getContactName(account, jid));
|
||||
QString path = QString(roster.getContactIconPath(account, jid, msg.getPenPalResource()));
|
||||
QVariantList args;
|
||||
args << QString();
|
||||
|
||||
args << qHash(msg.getId());
|
||||
uint32_t notificationId = qHash(msg.getId());
|
||||
args << notificationId;
|
||||
if (path.size() > 0) {
|
||||
args << path;
|
||||
} else {
|
||||
|
@ -212,7 +232,10 @@ void Application::notify(const QString& account, const Shared::Message& msg)
|
|||
}
|
||||
|
||||
args << body;
|
||||
args << QStringList();
|
||||
args << QStringList({
|
||||
"markAsRead", tr("Mark as Read"),
|
||||
"openConversation", tr("Open conversation")
|
||||
});
|
||||
args << QVariantMap({
|
||||
{"desktop-entry", qApp->desktopFileName()},
|
||||
{"category", QString("message")},
|
||||
|
@ -222,11 +245,40 @@ void Application::notify(const QString& account, const Shared::Message& msg)
|
|||
args << -1;
|
||||
notifications.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
|
||||
storage.insert(std::make_pair(notificationId, std::make_pair(Models::Roster::ElId(account, name), msg.getId())));
|
||||
|
||||
if (squawk != nullptr) {
|
||||
QApplication::alert(squawk);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onNotificationClosed(quint32 id, quint32 reason)
|
||||
{
|
||||
Notifications::const_iterator itr = storage.find(id);
|
||||
if (itr != storage.end()) {
|
||||
if (reason == 2) { //dissmissed by user (https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html)
|
||||
//TODO may ba also mark as read?
|
||||
}
|
||||
if (reason != 1) { //just expired, can be activated again from history, so no removing for now
|
||||
storage.erase(id);
|
||||
qDebug() << "Notification" << id << "was closed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onNotificationInvoked(quint32 id, const QString& action)
|
||||
{
|
||||
qDebug() << "Notification" << id << action << "request";
|
||||
Notifications::const_iterator itr = storage.find(id);
|
||||
if (itr != storage.end()) {
|
||||
if (action == "markAsRead") {
|
||||
roster.markMessageAsRead(itr->second.first, itr->second.second);
|
||||
} else if (action == "openConversation") {
|
||||
focusConversation(itr->second.first, "", itr->second.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::unreadMessagesCountChanged(int count)
|
||||
{
|
||||
QDBusMessage signal = QDBusMessage::createSignal("/", "com.canonical.Unity.LauncherEntry", "Update");
|
||||
|
@ -238,6 +290,27 @@ void Application::unreadMessagesCountChanged(int count)
|
|||
QDBusConnection::sessionBus().send(signal);
|
||||
}
|
||||
|
||||
void Application::focusConversation(const Models::Roster::ElId& id, const QString& resource, const QString& messageId)
|
||||
{
|
||||
if (squawk != nullptr) {
|
||||
if (squawk->currentConversationId() != id) {
|
||||
QModelIndex index = roster.getContactIndex(id.account, id.name, resource);
|
||||
squawk->select(index);
|
||||
}
|
||||
|
||||
if (squawk->isMinimized()) {
|
||||
squawk->showNormal();
|
||||
} else {
|
||||
squawk->show();
|
||||
}
|
||||
squawk->raise();
|
||||
squawk->activateWindow();
|
||||
} else {
|
||||
openConversation(id, resource);
|
||||
}
|
||||
|
||||
//TODO focus messageId;
|
||||
}
|
||||
|
||||
void Application::setState(Shared::Availability p_availability)
|
||||
{
|
||||
|
@ -343,7 +416,7 @@ void Application::openConversation(const Models::Roster::ElId& id, const QString
|
|||
conv = itr->second;
|
||||
} else {
|
||||
Models::Element* el = roster.getElement(id);
|
||||
if (el != NULL) {
|
||||
if (el != nullptr) {
|
||||
if (el->type == Models::Item::room) {
|
||||
created = true;
|
||||
Models::Room* room = static_cast<Models::Room*>(el);
|
||||
|
@ -409,7 +482,7 @@ void Application::onSquawkOpenedConversation() {
|
|||
Models::Roster::ElId id = squawk->currentConversationId();
|
||||
|
||||
const Models::Element* el = roster.getElementConst(id);
|
||||
if (el != NULL && el->isRoom() && !static_cast<const Models::Room*>(el)->getJoined()) {
|
||||
if (el != nullptr && el->isRoom() && !static_cast<const Models::Room*>(el)->getJoined()) {
|
||||
emit setRoomJoined(id.account, id.name, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,14 +89,19 @@ private slots:
|
|||
void stateChanged(Shared::Availability state);
|
||||
void onSquawkClosing();
|
||||
void onSquawkDestroyed();
|
||||
void onNotificationClosed(quint32 id, quint32 reason);
|
||||
void onNotificationInvoked(quint32 id, const QString& action);
|
||||
|
||||
|
||||
private:
|
||||
void createMainWindow();
|
||||
void subscribeConversation(Conversation* conv);
|
||||
void checkForTheLastWindow();
|
||||
void focusConversation(const Models::Roster::ElId& id, const QString& resource = "", const QString& messageId = "");
|
||||
|
||||
private:
|
||||
typedef std::map<Models::Roster::ElId, Conversation*> Conversations;
|
||||
typedef std::map<uint32_t, std::pair<Models::Roster::ElId, QString>> Notifications;
|
||||
|
||||
Shared::Availability availability;
|
||||
Core::Squawk* core;
|
||||
|
@ -107,6 +112,7 @@ private:
|
|||
DialogQueue dialogueQueue;
|
||||
bool nowQuitting;
|
||||
bool destroyingSquawk;
|
||||
Notifications storage;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue