From 0a530bfa935ebda733a9c9d4cd965f44e365e26c Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 6 Nov 2023 20:57:08 -0300 Subject: [PATCH] encrypted messages now are displayed in the feed --- CMakeLists.txt | 4 +- core/handlers/messagehandler.cpp | 9 +- main/main.cpp | 3 +- resources/images/fallback/dark/big/lock.svg | 13 ++ resources/images/fallback/dark/big/shield.svg | 13 ++ resources/images/fallback/dark/big/unlock.svg | 14 ++ resources/images/fallback/dark/small/lock.svg | 13 ++ .../images/fallback/dark/small/shield.svg | 13 ++ .../images/fallback/dark/small/unlock.svg | 13 ++ resources/images/fallback/light/big/lock.svg | 13 ++ .../images/fallback/light/big/shield.svg | 13 ++ .../images/fallback/light/big/unlock.svg | 14 ++ .../images/fallback/light/small/lock.svg | 13 ++ .../images/fallback/light/small/shield.svg | 13 ++ .../images/fallback/light/small/unlock.svg | 13 ++ resources/resources.qrc | 12 + shared/enums.h | 4 +- shared/exception.h | 5 +- shared/global.cpp | 104 +++++---- shared/global.h | 10 +- shared/icons.h | 10 +- shared/message.cpp | 9 +- shared/message.h | 5 +- shared/pathcheck.h | 5 +- shared/utils.h | 5 +- ui/widgets/chat.h | 7 +- ui/widgets/conversation.cpp | 1 + ui/widgets/conversation.h | 3 +- ui/widgets/messageline/CMakeLists.txt | 1 - ui/widgets/messageline/messagedelegate.cpp | 212 ++++++++++-------- ui/widgets/messageline/messagedelegate.h | 50 ++--- ui/widgets/messageline/messagefeed.cpp | 54 +++-- ui/widgets/messageline/messagefeed.h | 8 +- ui/widgets/messageline/preview.h | 5 +- 34 files changed, 439 insertions(+), 245 deletions(-) create mode 100644 resources/images/fallback/dark/big/lock.svg create mode 100644 resources/images/fallback/dark/big/shield.svg create mode 100644 resources/images/fallback/dark/big/unlock.svg create mode 100644 resources/images/fallback/dark/small/lock.svg create mode 100644 resources/images/fallback/dark/small/shield.svg create mode 100644 resources/images/fallback/dark/small/unlock.svg create mode 100644 resources/images/fallback/light/big/lock.svg create mode 100644 resources/images/fallback/light/big/shield.svg create mode 100644 resources/images/fallback/light/big/unlock.svg create mode 100644 resources/images/fallback/light/small/lock.svg create mode 100644 resources/images/fallback/light/small/shield.svg create mode 100644 resources/images/fallback/light/small/unlock.svg diff --git a/CMakeLists.txt b/CMakeLists.txt index 1151cc1..552cba9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,9 @@ option(WITH_OMEMO "Build OMEMO support module" ON) # Dependencies ## Qt if (NOT DEFINED QT_VERSION_MAJOR) - find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core) + find_package(QT NAMES Qt6 Qt5 CONFIG REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core) else () - find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core) + find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core) endif() find_package(Boost COMPONENTS) diff --git a/core/handlers/messagehandler.cpp b/core/handlers/messagehandler.cpp index f939b9e..2a546e9 100644 --- a/core/handlers/messagehandler.cpp +++ b/core/handlers/messagehandler.cpp @@ -117,9 +117,8 @@ bool Core::MessageHandler::handleChatMessage(const QXmppMessage& msg, bool outgo qDebug() << "appending message" << sMsg.getId() << "to an out of roster contact"; } if (sMsg.getOutgoing()) { - if (sMsg.getForwarded()) { + if (sMsg.getForwarded()) sMsg.setState(Shared::Message::State::sent); - } } else { sMsg.setState(Shared::Message::State::delivered); } @@ -208,6 +207,12 @@ void Core::MessageHandler::initializeMessage(Shared::Message& target, const QXmp target.setTo(source.to()); target.setBody(source.body()); target.setForwarded(forwarded); +#ifdef WITH_OMEMO + #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) + if (source.encryptionMethod() == QXmpp::EncryptionMethod::Omemo2) + target.setEncryption(Shared::EncryptionProtocol::omemo2); + #endif +#endif if (guessing) outgoing = target.getFromJid() == acc->getBareJid(); diff --git a/main/main.cpp b/main/main.cpp index c8e962f..06c2c95 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -27,8 +27,7 @@ #include #endif -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { qRegisterMetaType("Shared::Message"); qRegisterMetaType("Shared::MessageInfo"); qRegisterMetaType("Shared::VCard"); diff --git a/resources/images/fallback/dark/big/lock.svg b/resources/images/fallback/dark/big/lock.svg new file mode 100644 index 0000000..d7835b3 --- /dev/null +++ b/resources/images/fallback/dark/big/lock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/dark/big/shield.svg b/resources/images/fallback/dark/big/shield.svg new file mode 100644 index 0000000..c63b275 --- /dev/null +++ b/resources/images/fallback/dark/big/shield.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/dark/big/unlock.svg b/resources/images/fallback/dark/big/unlock.svg new file mode 100644 index 0000000..a5e4a4c --- /dev/null +++ b/resources/images/fallback/dark/big/unlock.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/resources/images/fallback/dark/small/lock.svg b/resources/images/fallback/dark/small/lock.svg new file mode 100644 index 0000000..6d36522 --- /dev/null +++ b/resources/images/fallback/dark/small/lock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/dark/small/shield.svg b/resources/images/fallback/dark/small/shield.svg new file mode 100644 index 0000000..c63b275 --- /dev/null +++ b/resources/images/fallback/dark/small/shield.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/dark/small/unlock.svg b/resources/images/fallback/dark/small/unlock.svg new file mode 100644 index 0000000..9f2f121 --- /dev/null +++ b/resources/images/fallback/dark/small/unlock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/light/big/lock.svg b/resources/images/fallback/light/big/lock.svg new file mode 100644 index 0000000..5c7f4e1 --- /dev/null +++ b/resources/images/fallback/light/big/lock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/light/big/shield.svg b/resources/images/fallback/light/big/shield.svg new file mode 100644 index 0000000..52f9c34 --- /dev/null +++ b/resources/images/fallback/light/big/shield.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/light/big/unlock.svg b/resources/images/fallback/light/big/unlock.svg new file mode 100644 index 0000000..0548efc --- /dev/null +++ b/resources/images/fallback/light/big/unlock.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/resources/images/fallback/light/small/lock.svg b/resources/images/fallback/light/small/lock.svg new file mode 100644 index 0000000..a566da0 --- /dev/null +++ b/resources/images/fallback/light/small/lock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/light/small/shield.svg b/resources/images/fallback/light/small/shield.svg new file mode 100644 index 0000000..52f9c34 --- /dev/null +++ b/resources/images/fallback/light/small/shield.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/images/fallback/light/small/unlock.svg b/resources/images/fallback/light/small/unlock.svg new file mode 100644 index 0000000..ff91b8e --- /dev/null +++ b/resources/images/fallback/light/small/unlock.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/resources/resources.qrc b/resources/resources.qrc index 58565fc..993255b 100644 --- a/resources/resources.qrc +++ b/resources/resources.qrc @@ -42,6 +42,9 @@ images/fallback/dark/big/add.svg images/fallback/dark/big/folder.svg images/fallback/dark/big/document-preview.svg + images/fallback/dark/big/shield.svg + images/fallback/dark/big/lock.svg + images/fallback/dark/big/unlock.svg images/fallback/dark/small/absent.svg @@ -84,6 +87,9 @@ images/fallback/dark/small/add.svg images/fallback/dark/small/folder.svg images/fallback/dark/small/document-preview.svg + images/fallback/dark/small/shield.svg + images/fallback/dark/small/lock.svg + images/fallback/dark/small/unlock.svg images/fallback/light/big/absent.svg @@ -126,6 +132,9 @@ images/fallback/light/big/add.svg images/fallback/light/big/folder.svg images/fallback/light/big/document-preview.svg + images/fallback/light/big/shield.svg + images/fallback/light/big/lock.svg + images/fallback/light/big/unlock.svg images/fallback/light/small/absent.svg @@ -168,5 +177,8 @@ images/fallback/light/small/add.svg images/fallback/light/small/folder.svg images/fallback/light/small/document-preview.svg + images/fallback/light/small/shield.svg + images/fallback/light/small/lock.svg + images/fallback/light/small/unlock.svg diff --git a/shared/enums.h b/shared/enums.h index c959883..6b668d6 100644 --- a/shared/enums.h +++ b/shared/enums.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef SHARED_ENUMS_H -#define SHARED_ENUMS_H +#pragma once #include @@ -170,4 +169,3 @@ static const EncryptionProtocol EncryptionProtocolHighest = EncryptionProtocol:: static const EncryptionProtocol EncryptionProtocolLowest = EncryptionProtocol::omemo2; } -#endif // SHARED_ENUMS_H diff --git a/shared/exception.h b/shared/exception.h index 4c66c2d..48d7eda 100644 --- a/shared/exception.h +++ b/shared/exception.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef EXCEPTION_H -#define EXCEPTION_H +#pragma once #include #include @@ -36,5 +35,3 @@ namespace Utils const char* what() const noexcept( true ); }; } - -#endif // EXCEPTION_H diff --git a/shared/global.cpp b/shared/global.cpp index 95168b2..97f3263 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -62,70 +62,78 @@ Shared::Global::ColorSchemeName Shared::Global::colorSchemeName = 0; Shared::Global::CreatePalette Shared::Global::createPalette = 0; #endif + + Shared::Global::Global(): availability({ - tr("Online", "Availability"), - tr("Away", "Availability"), - tr("Absent", "Availability"), - tr("Busy", "Availability"), - tr("Chatty", "Availability"), - tr("Invisible", "Availability"), - tr("Offline", "Availability") + QCoreApplication::translate("Global", "Online", "Availability"), + QCoreApplication::translate("Global", "Away", "Availability"), + QCoreApplication::translate("Global", "Absent", "Availability"), + QCoreApplication::translate("Global", "Busy", "Availability"), + QCoreApplication::translate("Global", "Chatty", "Availability"), + QCoreApplication::translate("Global", "Invisible", "Availability"), + QCoreApplication::translate("Global", "Offline", "Availability") }), connectionState({ - tr("Disconnected", "ConnectionState"), - tr("Scheduled", "ConnectionState"), - tr("Connecting", "ConnectionState"), - tr("Connected", "ConnectionState"), - tr("Error", "ConnectionState") + QCoreApplication::translate("Global", "Disconnected", "ConnectionState"), + QCoreApplication::translate("Global", "Scheduled", "ConnectionState"), + QCoreApplication::translate("Global", "Connecting", "ConnectionState"), + QCoreApplication::translate("Global", "Connected", "ConnectionState"), + QCoreApplication::translate("Global", "Error", "ConnectionState") }), subscriptionState({ - tr("None", "SubscriptionState"), - tr("From", "SubscriptionState"), - tr("To", "SubscriptionState"), - tr("Both", "SubscriptionState"), - tr("Unknown", "SubscriptionState") + QCoreApplication::translate("Global", "None", "SubscriptionState"), + QCoreApplication::translate("Global", "From", "SubscriptionState"), + QCoreApplication::translate("Global", "To", "SubscriptionState"), + QCoreApplication::translate("Global", "Both", "SubscriptionState"), + QCoreApplication::translate("Global", "Unknown", "SubscriptionState") }), affiliation({ - tr("Unspecified", "Affiliation"), - tr("Outcast", "Affiliation"), - tr("Nobody", "Affiliation"), - tr("Member", "Affiliation"), - tr("Admin", "Affiliation"), - tr("Owner", "Affiliation") + QCoreApplication::translate("Global", "Unspecified", "Affiliation"), + QCoreApplication::translate("Global", "Outcast", "Affiliation"), + QCoreApplication::translate("Global", "Nobody", "Affiliation"), + QCoreApplication::translate("Global", "Member", "Affiliation"), + QCoreApplication::translate("Global", "Admin", "Affiliation"), + QCoreApplication::translate("Global", "Owner", "Affiliation") }), role({ - tr("Unspecified", "Role"), - tr("Nobody", "Role"), - tr("Visitor", "Role"), - tr("Participant", "Role"), - tr("Moderator", "Role") + QCoreApplication::translate("Global", "Unspecified", "Role"), + QCoreApplication::translate("Global", "Nobody", "Role"), + QCoreApplication::translate("Global", "Visitor", "Role"), + QCoreApplication::translate("Global", "Participant", "Role"), + QCoreApplication::translate("Global", "Moderator", "Role") }), messageState({ - tr("Pending", "MessageState"), - tr("Sent", "MessageState"), - tr("Delivered", "MessageState"), - tr("Error", "MessageState") + QCoreApplication::translate("Global", "Pending", "MessageState"), + QCoreApplication::translate("Global", "Sent", "MessageState"), + QCoreApplication::translate("Global", "Delivered", "MessageState"), + QCoreApplication::translate("Global", "Error", "MessageState") }), accountPassword({ - tr("Plain", "AccountPassword"), - tr("Jammed", "AccountPassword"), - tr("Always Ask", "AccountPassword"), - tr("KWallet", "AccountPassword") + QCoreApplication::translate("Global", "Plain", "AccountPassword"), + QCoreApplication::translate("Global", "Jammed", "AccountPassword"), + QCoreApplication::translate("Global", "Always Ask", "AccountPassword"), + QCoreApplication::translate("Global", "KWallet", "AccountPassword") }), trustLevel({ - tr("Undecided", "TrustLevel"), - tr("Automatically distrusted", "TrustLevel"), - tr("Manually distrusted", "TrustLevel"), - tr("Automatically trusted", "TrustLevel"), - tr("Manually trusted", "TrustLevel"), - tr("Authenticated", "TrustLevel") + QCoreApplication::translate("Global", "Undecided", "TrustLevel"), + QCoreApplication::translate("Global", "Automatically distrusted", "TrustLevel"), + QCoreApplication::translate("Global", "Manually distrusted", "TrustLevel"), + QCoreApplication::translate("Global", "Automatically trusted", "TrustLevel"), + QCoreApplication::translate("Global", "Manually trusted", "TrustLevel"), + QCoreApplication::translate("Global", "Authenticated", "TrustLevel") + }), + encryptionProtocols({ + QCoreApplication::translate("Global", "None", "EncryptionProtocol"), + QCoreApplication::translate("Global", "OMEMO 0", "EncryptionProtocol"), + QCoreApplication::translate("Global", "OMEMO 1", "EncryptionProtocol"), + QCoreApplication::translate("Global", "OMEMO 2", "EncryptionProtocol") }), accountPasswordDescription({ - tr("Your password is going to be stored in config file in plain text", "AccountPasswordDescription"), - tr("Your password is going to be stored in config file but jammed with constant encryption key you can find in program source code. It might look like encryption but it's not", "AccountPasswordDescription"), - tr("Squawk is going to query you for the password on every start of the program", "AccountPasswordDescription"), - tr("Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription") + QCoreApplication::translate("Global", "Your password is going to be stored in config file in plain text", "AccountPasswordDescription"), + QCoreApplication::translate("Global", "Your password is going to be stored in config file but jammed with constant encryption key you can find in program source code. It might look like encryption but it's not", "AccountPasswordDescription"), + QCoreApplication::translate("Global", "Squawk is going to query you for the password on every start of the program", "AccountPasswordDescription"), + QCoreApplication::translate("Global", "Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription") }), defaultSystemStyle(QApplication::style()->objectName()), defaultSystemPalette(QApplication::palette()), @@ -262,6 +270,10 @@ QString Shared::Global::getName(Shared::TrustLevel tl) { return instance->trustLevel[static_cast(tl)]; } +QString Shared::Global::getName(EncryptionProtocol ep) { + return instance->encryptionProtocols[static_cast(ep)]; +} + void Shared::Global::setSupported(const QString& pluginName, bool support) { std::map::iterator itr = instance->pluginSupport.find(pluginName); if (itr != instance->pluginSupport.end()) { diff --git a/shared/global.h b/shared/global.h index 578fc42..6d23c2f 100644 --- a/shared/global.h +++ b/shared/global.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef SHARED_GLOBAL_H -#define SHARED_GLOBAL_H +#pragma once #include "enums.h" #include "message.h" @@ -48,7 +47,6 @@ namespace Shared { class Global { - Q_DECLARE_TR_FUNCTIONS(Global) public: struct FileInfo { enum class Preview { @@ -75,6 +73,7 @@ namespace Shared { static QString getName(Message::State rl); static QString getName(AccountPassword ap); static QString getName(TrustLevel tl); + static QString getName(EncryptionProtocol ep); static QString getDescription(AccountPassword ap); @@ -86,6 +85,7 @@ namespace Shared { const std::deque messageState; const std::deque accountPassword; const std::deque trustLevel; + const std::deque encryptionProtocols; const std::deque accountPasswordDescription; @@ -124,7 +124,7 @@ namespace Shared { class EnumOutOfRange: public Utils::Exception { public: EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {} - + std::string getMessage() const{ return "An attempt to get enum " + name + " from integer out of range of that enum"; } @@ -161,5 +161,3 @@ namespace Shared { #endif }; } - -#endif // SHARED_GLOBAL_H diff --git a/shared/icons.h b/shared/icons.h index cf31b3b..dadb87e 100644 --- a/shared/icons.h +++ b/shared/icons.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef SHARED_ICONS_H -#define SHARED_ICONS_H +#pragma once #include @@ -175,8 +174,9 @@ static const std::map> icons = { {"unfavorite", {"draw-star", "unfavorite"}}, {"list-add", {"list-add", "add"}}, {"folder", {"folder", "folder"}}, - {"document-preview", {"document-preview", "document-preview"}} + {"document-preview", {"document-preview", "document-preview"}}, + {"secure", {"security-high", "shield"}}, + {"lock", {"lock", "lock"}}, + {"unlock", {"unlock", "unlock"}} }; } - -#endif // SHARED_ICONS_H diff --git a/shared/message.cpp b/shared/message.cpp index 5b535c1..caf8a97 100644 --- a/shared/message.cpp +++ b/shared/message.cpp @@ -37,7 +37,8 @@ Shared::Message::Message(Shared::Message::Type p_type): originalMessage(), lastModified(), stanzaId(), - attachPath() + attachPath(), + encryption(EncryptionProtocol::none) {} Shared::Message::Message(): @@ -58,7 +59,8 @@ Shared::Message::Message(): originalMessage(), lastModified(), stanzaId(), - attachPath() + attachPath(), + encryption(EncryptionProtocol::none) {} QString Shared::Message::getBody() const { @@ -234,9 +236,8 @@ void Shared::Message::setType(Shared::Message::Type t) { void Shared::Message::setState(Shared::Message::State p_state) { state = p_state; - if (state != State::error) { + if (state != State::error) errorText = ""; - } } bool Shared::Message::serverStored() const { diff --git a/shared/message.h b/shared/message.h index d7df9f3..b81881b 100644 --- a/shared/message.h +++ b/shared/message.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef SHAPER_MESSAGE_H -#define SHAPER_MESSAGE_H +#pragma once #include #include @@ -154,5 +153,3 @@ private: }; } - -#endif // SHAPER_MESSAGE_H diff --git a/shared/pathcheck.h b/shared/pathcheck.h index 3ca612b..1608241 100644 --- a/shared/pathcheck.h +++ b/shared/pathcheck.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef PATHCHECK_H -#define PATHCHECK_H +#pragma once #include #include @@ -40,5 +39,3 @@ QString squawkifyPath(QString path); bool isSubdirectoryOfSettings(const QString& path); } - -#endif // PATHCHECK_H diff --git a/shared/utils.h b/shared/utils.h index 0329cee..019f611 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef SHARED_UTILS_H -#define SHARED_UTILS_H +#pragma once #include #include @@ -76,5 +75,3 @@ enum class Hover { anchor }; } - -#endif // SHARED_UTILS_H diff --git a/ui/widgets/chat.h b/ui/widgets/chat.h index cf7ecd3..912299e 100644 --- a/ui/widgets/chat.h +++ b/ui/widgets/chat.h @@ -24,12 +24,11 @@ #include "shared/icons.h" #include "shared/global.h" -namespace Ui -{ +namespace Ui { class Chat; } -class Chat : public Conversation -{ + +class Chat : public Conversation { Q_OBJECT public: Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent = 0); diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 8336d5e..32c38a8 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -120,6 +120,7 @@ Conversation::~Conversation() { delete contextMenu; element->feed->decrementObservers(); + delete m_ui; } void Conversation::onAccountChanged(Models::Item* item, int row, int col) { diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 4db5029..73e6536 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -20,6 +20,7 @@ #define CONVERSATION_H #include +#include #include #include #include @@ -134,7 +135,7 @@ protected: Models::Element* element; QString palJid; QString activePalResource; - QScopedPointer m_ui; + Ui::Conversation* m_ui; KeyEnterReceiver ker; QString thread; QLabel* statusIcon; diff --git a/ui/widgets/messageline/CMakeLists.txt b/ui/widgets/messageline/CMakeLists.txt index 7ded76b..1524509 100644 --- a/ui/widgets/messageline/CMakeLists.txt +++ b/ui/widgets/messageline/CMakeLists.txt @@ -14,5 +14,4 @@ set(HEADER_FILES target_sources(squawk PRIVATE ${SOURCE_FILES} - ${HEADER_FILES} ) diff --git a/ui/widgets/messageline/messagedelegate.cpp b/ui/widgets/messageline/messagedelegate.cpp index 35a73c2..b89b438 100644 --- a/ui/widgets/messageline/messagedelegate.cpp +++ b/ui/widgets/messageline/messagedelegate.cpp @@ -47,22 +47,23 @@ MessageDelegate::MessageDelegate(QObject* parent): dateFont(Shared::Global::getInstance()->smallFont), nickMetrics(Shared::Global::getInstance()->headerFontMetrics), dateMetrics(Shared::Global::getInstance()->smallFontMetrics), - bodyRenderer(new QTextDocument()), + bodyRenderer(), buttonHeight(0), buttonWidth(0), barHeight(0), - buttons(new std::map()), - bars(new std::map()), - statusIcons(new std::map()), - pencilIcons(new std::map()), - previews(new std::map()), - idsToKeep(new std::set()), + buttons(), + bars(), + statusIcons(), + pencilIcons(), + encryptionIcons(), + previews(), + idsToKeep(), clearingWidgets(false), currentId(""), selection(0, 0) { - bodyRenderer->setDocumentMargin(0); - bodyRenderer->setDefaultFont(bodyFont); + bodyRenderer.setDocumentMargin(0); + bodyRenderer.setDefaultFont(bodyFont); QPushButton btn(QCoreApplication::translate("MessageLine", "Download")); buttonHeight = btn.sizeHint().height(); @@ -73,28 +74,23 @@ MessageDelegate::MessageDelegate(QObject* parent): } MessageDelegate::~MessageDelegate() { - for (const std::pair& pair: *buttons) + for (const std::pair& pair: buttons) delete pair.second; - for (const std::pair& pair: *bars) + for (const std::pair& pair: bars) delete pair.second; - for (const std::pair& pair: *statusIcons) + for (const std::pair& pair: statusIcons) delete pair.second; - for (const std::pair& pair: *pencilIcons) + for (const std::pair& pair: pencilIcons) + delete pair.second; + + for (const std::pair& pair: encryptionIcons) delete pair.second; - for (const std::pair& pair: *previews) + for (const std::pair& pair: previews) delete pair.second; - - delete statusIcons; - delete pencilIcons; - delete idsToKeep; - delete buttons; - delete bars; - delete previews; - delete bodyRenderer; } void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { @@ -168,6 +164,7 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio painter->setPen(q); painter->drawText(opt.rect, opt.displayAlignment, dateString, &rect); int currentY = opt.rect.y(); + int statusOffset = statusIconSize; if (data.sentByMe) { QLabel* statusIcon = getStatusIcon(data); @@ -176,30 +173,43 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio statusIcon->show(); opt.rect.adjust(0, statusIconSize + textMargin, 0, 0); + statusOffset = statusIconSize + margin; } if (data.correction.corrected) { QLabel* pencilIcon = getPencilIcon(data); - pencilIcon->setParent(vp); if (data.sentByMe) - pencilIcon->move(opt.rect.left() + statusIconSize + margin, currentY); + pencilIcon->move(opt.rect.left() + statusOffset, currentY); else - pencilIcon->move(opt.rect.right() - statusIconSize - margin, currentY); + pencilIcon->move(opt.rect.right() - statusOffset, currentY); pencilIcon->show(); + statusOffset += statusIconSize + margin; } else { - std::map::const_iterator itr = pencilIcons->find(data.id); - if (itr != pencilIcons->end()) { + std::map::const_iterator itr = pencilIcons.find(data.id); + if (itr != pencilIcons.end()) { delete itr->second; - pencilIcons->erase(itr); + pencilIcons.erase(itr); } } + + if (data.encryption != Shared::EncryptionProtocol::none) { + QLabel* shieldIcon = getEncryptionIcon(data); + shieldIcon->setParent(vp); + if (data.sentByMe) + shieldIcon->move(opt.rect.left() + statusOffset, currentY); + else + shieldIcon->move(opt.rect.right() - statusOffset, currentY); + + shieldIcon->show(); + statusOffset += statusIconSize + margin; + } painter->restore(); if (clearingWidgets) - idsToKeep->insert(data.id); + idsToKeep.insert(data.id); } void MessageDelegate::paintBubble(const Models::FeedItem& data, QPainter* painter, const QStyleOptionViewItem& option) const { @@ -281,11 +291,11 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel Models::FeedItem data = qvariant_cast(vi); QSize messageSize(0, 0); if (data.text.size() > 0) { - bodyRenderer->setPlainText(data.text); - bodyRenderer->setTextWidth(messageRect.size().width()); + bodyRenderer.setPlainText(data.text); + bodyRenderer.setTextWidth(messageRect.size().width()); - QSizeF size = bodyRenderer->size(); - size.setWidth(bodyRenderer->idealWidth()); + QSizeF size = bodyRenderer.size(); + size.setWidth(bodyRenderer.idealWidth()); messageSize = QSize(std::ceil(size.width()), std::ceil(size.height())); messageSize.rheight() += textMargin; } @@ -338,9 +348,12 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel messageSize.rheight() += dateSize.height() > statusIconSize ? dateSize.height() : statusIconSize; int statusWidth = dateSize.width() + statusIconSize + margin; - if (data.correction.corrected) { + if (data.correction.corrected) statusWidth += statusIconSize + margin; - } + + if (data.encryption != Shared::EncryptionProtocol::none) + statusWidth += statusIconSize + margin; + messageSize.setWidth(std::max(statusWidth, messageSize.width())); messageSize.rwidth() += 2 * bubbleMargin; @@ -399,10 +412,10 @@ QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index if (localHint.contains(point)) { QPoint translated = point - localHint.topLeft(); - bodyRenderer->setHtml(Shared::processMessageBody(data.text)); - bodyRenderer->setTextWidth(localHint.size().width()); + bodyRenderer.setHtml(Shared::processMessageBody(data.text)); + bodyRenderer.setTextWidth(localHint.size().width()); - return bodyRenderer->documentLayout()->anchorAt(translated); + return bodyRenderer.documentLayout()->anchorAt(translated); } } @@ -424,13 +437,13 @@ QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& if (localHint.contains(point)) { QPoint translated = point - localHint.topLeft(); - bodyRenderer->setHtml(Shared::processMessageBody(data.text)); - bodyRenderer->setTextWidth(localHint.size().width()); + bodyRenderer.setHtml(Shared::processMessageBody(data.text)); + bodyRenderer.setTextWidth(localHint.size().width()); - QAbstractTextDocumentLayout* lay = bodyRenderer->documentLayout(); + QAbstractTextDocumentLayout* lay = bodyRenderer.documentLayout(); int position = lay->hitTest(translated, Qt::HitTestAccuracy::FuzzyHit); - QTextCursor cursor(bodyRenderer); + QTextCursor cursor(&bodyRenderer); cursor.setPosition(position, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); @@ -456,10 +469,10 @@ Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& if (localHint.contains(point)) { QPoint translated = point - localHint.topLeft(); - bodyRenderer->setHtml(Shared::processMessageBody(data.text)); - bodyRenderer->setTextWidth(localHint.size().width()); + bodyRenderer.setHtml(Shared::processMessageBody(data.text)); + bodyRenderer.setTextWidth(localHint.size().width()); - QAbstractTextDocumentLayout* lay = bodyRenderer->documentLayout(); + QAbstractTextDocumentLayout* lay = bodyRenderer.documentLayout(); QString anchor = lay->anchorAt(translated); if (anchor.size() > 0) { @@ -489,15 +502,15 @@ QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const last.setY(std::max(last.y(), 0)); last.setY(std::min(last.y(), localHint.height())); - bodyRenderer->setHtml(Shared::processMessageBody(data.text)); - bodyRenderer->setTextWidth(localHint.size().width()); - selection.first = bodyRenderer->documentLayout()->hitTest(first, Qt::HitTestAccuracy::FuzzyHit); - selection.second = bodyRenderer->documentLayout()->hitTest(last, Qt::HitTestAccuracy::FuzzyHit); + bodyRenderer.setHtml(Shared::processMessageBody(data.text)); + bodyRenderer.setTextWidth(localHint.size().width()); + selection.first = bodyRenderer.documentLayout()->hitTest(first, Qt::HitTestAccuracy::FuzzyHit); + selection.second = bodyRenderer.documentLayout()->hitTest(last, Qt::HitTestAccuracy::FuzzyHit); currentId = data.id; if (selection.first != selection.second) { - QTextCursor cursor(bodyRenderer); + QTextCursor cursor(&bodyRenderer); cursor.setPosition(selection.first, QTextCursor::MoveAnchor); cursor.setPosition(selection.second, QTextCursor::KeepAnchor); return cursor.selectedText(); @@ -562,17 +575,17 @@ int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByM int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const { Preview* preview = 0; - std::map::iterator itr = previews->find(data.id); + std::map::iterator itr = previews.find(data.id); QSize size = option.rect.size(); QString path = Shared::resolvePath(data.attach.localPath); - if (itr != previews->end()) { + if (itr != previews.end()) { preview = itr->second; preview->actualize(path, size, option.rect.topLeft()); } else { QWidget* vp = static_cast(painter->device()); preview = new Preview(path, size, option.rect.topLeft(), vp); - previews->insert(std::make_pair(data.id, preview)); + previews.insert(std::make_pair(data.id, preview)); } if (!preview->isFileReachable()) //this is the situation when the file preview couldn't be painted because the file was moved @@ -585,15 +598,15 @@ int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painte } QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const { - std::map::const_iterator itr = buttons->find(data.id); + std::map::const_iterator itr = buttons.find(data.id); FeedButton* result = 0; - if (itr != buttons->end()) { + if (itr != buttons.end()) { result = itr->second; } else { - std::map::const_iterator barItr = bars->find(data.id); - if (barItr != bars->end()) { + std::map::const_iterator barItr = bars.find(data.id); + if (barItr != bars.end()) { delete barItr->second; - bars->erase(barItr); + bars.erase(barItr); } } @@ -601,7 +614,7 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const { result = new FeedButton(); result->messageId = data.id; result->setText(QCoreApplication::translate("MessageLine", "Download")); - buttons->insert(std::make_pair(data.id, result)); + buttons.insert(std::make_pair(data.id, result)); connect(result, &QPushButton::clicked, this, &MessageDelegate::onButtonPushed); } @@ -609,22 +622,22 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const { } QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const { - std::map::const_iterator barItr = bars->find(data.id); + std::map::const_iterator barItr = bars.find(data.id); QProgressBar* result = 0; - if (barItr != bars->end()) { + if (barItr != bars.end()) { result = barItr->second; } else { - std::map::const_iterator itr = buttons->find(data.id); - if (itr != buttons->end()) { + std::map::const_iterator itr = buttons.find(data.id); + if (itr != buttons.end()) { delete itr->second; - buttons->erase(itr); + buttons.erase(itr); } } if (result == 0) { result = new QProgressBar(); result->setRange(0, 100); - bars->insert(std::make_pair(data.id, result)); + bars.insert(std::make_pair(data.id, result)); } result->setValue(data.attach.progress * 100); @@ -633,14 +646,14 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const { } QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const { - std::map::const_iterator itr = statusIcons->find(data.id); + std::map::const_iterator itr = statusIcons.find(data.id); QLabel* result = 0; - if (itr != statusIcons->end()) { + if (itr != statusIcons.end()) { result = itr->second; } else { result = new QLabel(); - statusIcons->insert(std::make_pair(data.id, result)); + statusIcons.insert(std::make_pair(data.id, result)); } QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast(data.state)])); @@ -657,17 +670,17 @@ QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const { return result; } -QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const { - std::map::const_iterator itr = pencilIcons->find(data.id); +QLabel* MessageDelegate::getPencilIcon(const Models::FeedItem& data) const { + std::map::const_iterator itr = pencilIcons.find(data.id); QLabel* result = 0; - if (itr != pencilIcons->end()) { + if (itr != pencilIcons.end()) { result = itr->second; } else { result = new QLabel(); QIcon icon = Shared::icon("edit-rename"); result->setPixmap(icon.pixmap(statusIconSize)); - pencilIcons->insert(std::make_pair(data.id, result)); + pencilIcons.insert(std::make_pair(data.id, result)); } result->setToolTip("Last time edited: " + data.correction.lastCorrection.toLocalTime().toString() @@ -676,30 +689,46 @@ QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const { return result; } +QLabel* MessageDelegate::getEncryptionIcon(const Models::FeedItem& data) const { + std::map::const_iterator itr = encryptionIcons.find(data.id); + QLabel* result = 0; + + if (itr != encryptionIcons.end()) { + result = itr->second; + } else { + result = new QLabel(); + QIcon icon = Shared::icon("secure"); + result->setPixmap(icon.pixmap(statusIconSize)); + encryptionIcons.insert(std::make_pair(data.id, result)); + result->setToolTip("Encrypted: " + Shared::Global::getName(data.encryption)); + } + + return result; +} + template -void removeElements(std::map* elements, std::set* idsToKeep) { +void removeElements(std::map& elements, std::set& idsToKeep) { std::set toRemove; - for (const std::pair& pair: *elements) { - if (idsToKeep->find(pair.first) == idsToKeep->end()) { + for (const std::pair& pair: elements) { + if (idsToKeep.find(pair.first) == idsToKeep.end()) { delete pair.second; toRemove.insert(pair.first); } } - for (const QString& key : toRemove) { - elements->erase(key); - } + for (const QString& key : toRemove) + elements.erase(key); } int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const { if (data.text.size() > 0) { - bodyRenderer->setHtml(Shared::processMessageBody(data.text)); - bodyRenderer->setTextWidth(option.rect.size().width()); + bodyRenderer.setHtml(Shared::processMessageBody(data.text)); + bodyRenderer.setTextWidth(option.rect.size().width()); painter->save(); painter->translate(option.rect.topLeft()); if (data.id == currentId) { - QTextCursor cursor(bodyRenderer); + QTextCursor cursor(&bodyRenderer); cursor.setPosition(selection.first, QTextCursor::MoveAnchor); cursor.setPosition(selection.second, QTextCursor::KeepAnchor); QTextCharFormat format = cursor.charFormat(); @@ -708,10 +737,10 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter, cursor.setCharFormat(format); } - bodyRenderer->drawContents(painter); + bodyRenderer.drawContents(painter); painter->restore(); - QSize bodySize(std::ceil(bodyRenderer->idealWidth()), std::ceil(bodyRenderer->size().height())); + QSize bodySize(std::ceil(bodyRenderer.idealWidth()), std::ceil(bodyRenderer.size().height())); option.rect.adjust(0, bodySize.height() + textMargin, 0, 0); return bodySize.width(); @@ -720,7 +749,7 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter, } void MessageDelegate::beginClearWidgets() { - idsToKeep->clear(); + idsToKeep.clear(); clearingWidgets = true; } @@ -730,9 +759,10 @@ void MessageDelegate::endClearWidgets() { removeElements(bars, idsToKeep); removeElements(statusIcons, idsToKeep); removeElements(pencilIcons, idsToKeep); + removeElements(encryptionIcons, idsToKeep); removeElements(previews, idsToKeep); - idsToKeep->clear(); + idsToKeep.clear(); clearingWidgets = false; } } @@ -743,15 +773,15 @@ void MessageDelegate::onButtonPushed() const { } void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const { - std::map::const_iterator itr = buttons->find(data.id); - if (itr != buttons->end()) { + std::map::const_iterator itr = buttons.find(data.id); + if (itr != buttons.end()) { delete itr->second; - buttons->erase(itr); + buttons.erase(itr); } else { - std::map::const_iterator barItr = bars->find(data.id); - if (barItr != bars->end()) { + std::map::const_iterator barItr = bars.find(data.id); + if (barItr != bars.end()) { delete barItr->second; - bars->erase(barItr); + bars.erase(barItr); } } } diff --git a/ui/widgets/messageline/messagedelegate.h b/ui/widgets/messageline/messagedelegate.h index 16e39ff..90ef819 100644 --- a/ui/widgets/messageline/messagedelegate.h +++ b/ui/widgets/messageline/messagedelegate.h @@ -1,23 +1,22 @@ /* - * Squawk messenger. + * Squawk messenger. * Copyright (C) 2019 Yury Gubich - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef MESSAGEDELEGATE_H -#define MESSAGEDELEGATE_H +#pragma once #include #include @@ -44,17 +43,16 @@ namespace Models { struct FeedItem; }; -class MessageDelegate : public QStyledItemDelegate -{ +class MessageDelegate : public QStyledItemDelegate { Q_OBJECT public: MessageDelegate(QObject *parent = nullptr); ~MessageDelegate(); - + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; //void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; - + bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index) override; void endClearWidgets(); void beginClearWidgets(); @@ -66,12 +64,12 @@ public: static int avatarHeight; static int margin; - + signals: void buttonPushed(const QString& messageId) const; void invalidPath(const QString& messageId) const; void openLink(const QString& href) const; - + protected: int paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const; int paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const; @@ -85,6 +83,7 @@ protected: QProgressBar* getBar(const Models::FeedItem& data) const; QLabel* getStatusIcon(const Models::FeedItem& data) const; QLabel* getPencilIcon(const Models::FeedItem& data) const; + QLabel* getEncryptionIcon(const Models::FeedItem& data) const; void clearHelperWidget(const Models::FeedItem& data) const; bool needToDrawAvatar(const QModelIndex& index, const Models::FeedItem& data, const QStyleOptionViewItem& option) const; @@ -92,36 +91,35 @@ protected: QRect getHoveredMessageBodyRect(const QModelIndex& index, const Models::FeedItem& data, const QRect& sizeHint) const; QString getAnchor(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const; - + protected slots: void onButtonPushed() const; - + private: class FeedButton : public QPushButton { public: QString messageId; }; - + const QFont& bodyFont; const QFont& nickFont; const QFont& dateFont; const QFontMetrics& nickMetrics; const QFontMetrics& dateMetrics; - QTextDocument* bodyRenderer; - + mutable QTextDocument bodyRenderer; + int buttonHeight; int buttonWidth; int barHeight; - - std::map* buttons; - std::map* bars; - std::map* statusIcons; - std::map* pencilIcons; - std::map* previews; - std::set* idsToKeep; + + mutable std::map buttons; + mutable std::map bars; + mutable std::map statusIcons; + mutable std::map pencilIcons; + mutable std::map encryptionIcons; + mutable std::map previews; + mutable std::set idsToKeep; bool clearingWidgets; QString currentId; std::pair selection; }; - -#endif // MESSAGEDELEGATE_H diff --git a/ui/widgets/messageline/messagefeed.cpp b/ui/widgets/messageline/messagefeed.cpp index 29f51d2..370af36 100644 --- a/ui/widgets/messageline/messagefeed.cpp +++ b/ui/widgets/messageline/messagefeed.cpp @@ -29,6 +29,7 @@ const QHash Models::MessageFeed::roles = { {Sender, "sender"}, {Date, "date"}, {DeliveryState, "deliveryState"}, + {Encryption, "encryption"}, {Correction, "correction"}, {SentByMe,"sentByMe"}, {Avatar, "avatar"}, @@ -51,20 +52,16 @@ Models::MessageFeed::MessageFeed(const Element* ri, QObject* parent): failedUploads(), unreadMessages(new std::set()), observersAmount(0) -{ -} +{} -Models::MessageFeed::~MessageFeed() -{ +Models::MessageFeed::~MessageFeed() { delete unreadMessages; - for (Shared::Message* message : storage) { + for (Shared::Message* message : storage) delete message; - } } -void Models::MessageFeed::addMessage(const Shared::Message& msg) -{ +void Models::MessageFeed::addMessage(const Shared::Message& msg) { QString id = msg.getId(); StorageById::const_iterator itr = indexById.find(id); if (itr != indexById.end()) { @@ -75,11 +72,11 @@ void Models::MessageFeed::addMessage(const Shared::Message& msg) Shared::Message* copy = new Shared::Message(msg); StorageByTime::const_iterator tItr = indexByTime.upper_bound(msg.getTime()); int position; - if (tItr == indexByTime.end()) { + if (tItr == indexByTime.end()) position = storage.size(); - } else { + else position = indexByTime.rank(tItr); - } + beginInsertRows(QModelIndex(), position, position); storage.insert(copy); endInsertRows(); @@ -93,8 +90,7 @@ void Models::MessageFeed::addMessage(const Shared::Message& msg) } } -void Models::MessageFeed::changeMessage(const QString& id, const QMap& data) -{ +void Models::MessageFeed::changeMessage(const QString& id, const QMap& data) { StorageById::iterator itr = indexById.find(id); if (itr == indexById.end()) { qDebug() << "received a command to change a message, but the message couldn't be found, skipping"; @@ -159,9 +155,8 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap cr; - for (MessageRoles role : changeRoles) { + for (MessageRoles role : changeRoles) cr.push_back(role); - } emit dataChanged(index, index, cr); @@ -173,14 +168,15 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap& data) const -{ +std::set Models::MessageFeed::detectChanges( + const Shared::Message& msg, + const QMap& data +) const { std::set roles; Shared::Message::State state = msg.getState(); QMap::const_iterator itr = data.find("state"); - if (itr != data.end() && static_cast(itr.value().toUInt()) != state) { + if (itr != data.end() && static_cast(itr.value().toUInt()) != state) roles.insert(MessageRoles::DeliveryState); - } itr = data.find("outOfBandUrl"); bool att = false; @@ -255,9 +251,8 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const { case Qt::DisplayRole: case Text: { QString body = msg->getBody(); - if (body != msg->getOutOfBandUrl()) { + if (body != msg->getOutOfBandUrl()) answer = body; - } } break; case Sender: @@ -276,6 +271,9 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const { case DeliveryState: answer = static_cast(msg->getState()); break; + case Encryption: + answer = QVariant::fromValue(msg->getEncryption()); + break; case Correction: answer.setValue(fillCorrection(*msg));; break; @@ -318,13 +316,13 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const { item.sentByMe = sentByMe(*msg); item.date = msg->getTime(); item.state = msg->getState(); + item.encryption = msg->getEncryption(); item.error = msg->getErrorText(); item.correction = fillCorrection(*msg); QString body = msg->getBody(); - if (body != msg->getOutOfBandUrl()) { + if (body != msg->getOutOfBandUrl()) item.text = body; - } item.avatar.clear(); if (item.sentByMe) { @@ -419,13 +417,11 @@ QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& p return QModelIndex(); StorageByTime::iterator itr = indexByTime.nth(row); - if (itr != indexByTime.end()) { - Shared::Message* msg = *itr; - - return createIndex(row, column, msg); - } else { + if (itr == indexByTime.end()) return QModelIndex(); - } + + Shared::Message* msg = *itr; + return createIndex(row, column, msg); } QHash Models::MessageFeed::roleNames() const {return roles;} diff --git a/ui/widgets/messageline/messagefeed.h b/ui/widgets/messageline/messagefeed.h index db174d2..5cceae9 100644 --- a/ui/widgets/messageline/messagefeed.h +++ b/ui/widgets/messageline/messagefeed.h @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -#ifndef MESSAGEFEED_H -#define MESSAGEFEED_H +#pragma once #include #include #include +#include #include @@ -100,6 +100,7 @@ public: Sender, Date, DeliveryState, + Encryption, Correction, SentByMe, Avatar, @@ -216,6 +217,7 @@ struct FeedItem { Edition correction; QDateTime date; Shared::Message::State state; + Shared::EncryptionProtocol encryption; Attachment attach; }; }; @@ -224,4 +226,4 @@ Q_DECLARE_METATYPE(Models::Attachment); Q_DECLARE_METATYPE(Models::Edition); Q_DECLARE_METATYPE(Models::FeedItem); -#endif // MESSAGEFEED_H +#pragma once diff --git a/ui/widgets/messageline/preview.h b/ui/widgets/messageline/preview.h index 11a5d7d..96a6530 100644 --- a/ui/widgets/messageline/preview.h +++ b/ui/widgets/messageline/preview.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef PREVIEW_H -#define PREVIEW_H +#pragma once #include #include @@ -75,5 +74,3 @@ private: bool fileReachable; bool actualPreview; }; - -#endif // PREVIEW_H