From 36d3f1057f7c2432a293da8bb1703c16b2f06bd0 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 10 Jul 2015 17:52:47 -0700 Subject: [PATCH] Adding an Away Status to Contacts --- src/core/ContactUser.cpp | 5 +++++ src/core/ContactUser.h | 4 +++- src/core/ConversationModel.cpp | 16 ++++++++++++++-- src/ui/qml/MessageDelegate.qml | 18 ++++++++++++++++-- src/ui/qml/PresenceIcon.qml | 2 ++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/core/ContactUser.cpp b/src/core/ContactUser.cpp index c33947ce..898b2435 100644 --- a/src/core/ContactUser.cpp +++ b/src/core/ContactUser.cpp @@ -347,6 +347,11 @@ void ContactUser::requestRemoved() } } +void ContactUser::setAway() { + m_status = Away; + emit statusChanged(); +} + void ContactUser::assignConnection(Protocol::Connection *connection) { if (connection == m_connection) { diff --git a/src/core/ContactUser.h b/src/core/ContactUser.h index e276a76d..7989ec69 100644 --- a/src/core/ContactUser.h +++ b/src/core/ContactUser.h @@ -80,7 +80,8 @@ class ContactUser : public QObject Offline, RequestPending, RequestRejected, - Outdated + Outdated, + Away }; UserIdentity * const identity; @@ -131,6 +132,7 @@ public slots: void setHostname(const QString &hostname); void updateStatus(); + void setAway(); signals: void statusChanged(); diff --git a/src/core/ConversationModel.cpp b/src/core/ConversationModel.cpp index 6fcd96ac..7900631f 100644 --- a/src/core/ConversationModel.cpp +++ b/src/core/ConversationModel.cpp @@ -277,14 +277,26 @@ QVariant ConversationModel::data(const QModelIndex &index, int role) const const MessageData &message = messages[index.row()]; switch (role) { - case Qt::DisplayRole: return message.text; + case Qt::DisplayRole: + if(message.status == Received) { + if (message.text.startsWith(QLatin1String("/away"))) { + m_contact->setAway(); + } else if (message.text.startsWith(QLatin1String("/back"))) { + m_contact->updateStatus(); + } + } + return message.text; case TimestampRole: return message.time; case IsOutgoingRole: return message.status != Received; case StatusRole: return message.status; case SectionRole: { - if (m_contact->status() == ContactUser::Online) + if (m_contact->status() == ContactUser::Online) { return QString(); + } + if (m_contact->status() == ContactUser::Away) { + return QStringLiteral("away"); + } if (index.row() < messages.size() - 1) { const MessageData &next = messages[index.row()+1]; if (next.status != Received && next.status != Delivered) diff --git a/src/ui/qml/MessageDelegate.qml b/src/ui/qml/MessageDelegate.qml index dcdd2299..d9baff94 100644 --- a/src/ui/qml/MessageDelegate.qml +++ b/src/ui/qml/MessageDelegate.qml @@ -24,6 +24,8 @@ Column { text: { if (model.section === "offline") return qsTr("%1 is offline").arg(contact !== null ? contact.nickname : "") + else if (model.section === "away") + return qsTr("%1 is away").arg(contact !== null ? contact.nickname : "") else return Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleShortDate) } @@ -103,8 +105,20 @@ Column { wrapMode: TextEdit.Wrap readOnly: true selectByMouse: true - text: LinkedText.parsed(model.text) - + text: { + if(model.isOutgoing) { + if(model.text === "/away") + return qsTr("You are now Away to %1").arg(contact !== null ? contact.nickname : ""); + else if(model.text === "/back") + return qsTr("You are now Online to %1").arg(contact !== null ? contact.nickname : ""); + } else { + if(model.text === "/away") + return qsTr("%1 is away").arg(contact !== null ? contact.nickname : ""); + else if(model.text === "/back") + return qsTr("%1 has returned").arg(contact !== null ? contact.nickname : ""); + } + return LinkedText.parsed(model.text) + } onLinkActivated: { textField.deselect() delegate.showContextMenu(link) diff --git a/src/ui/qml/PresenceIcon.qml b/src/ui/qml/PresenceIcon.qml index f42bddbe..64673a96 100644 --- a/src/ui/qml/PresenceIcon.qml +++ b/src/ui/qml/PresenceIcon.qml @@ -12,6 +12,8 @@ Rectangle { onStatusChanged: { if (status === ContactUser.Online) color = "#3EBB4F" + else if (status === ContactUser.Away) + color = "#EEEE44" else color = "#999999" }