diff --git a/core/networkaccess.cpp b/core/networkaccess.cpp index a27ab8f..3e9d2c0 100644 --- a/core/networkaccess.cpp +++ b/core/networkaccess.cpp @@ -291,15 +291,17 @@ void Core::NetworkAccess::onDownloadFinished() QStringList parts = fileName.split("."); path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/"; QString suffix(""); - QString realName = parts.front(); - for (QStringList::const_iterator sItr = (parts.begin()++), sEnd = parts.end(); sItr != sEnd; ++sItr) { + QStringList::const_iterator sItr = parts.begin(); + QString realName = *sItr; + ++sItr; + for (QStringList::const_iterator sEnd = parts.end(); sItr != sEnd; ++sItr) { suffix += "." + (*sItr); } QString postfix(""); QFileInfo proposedName(path + realName + postfix + suffix); int counter = 0; while (proposedName.exists()) { - suffix = QString("(") + std::to_string(++counter).c_str() + ")"; + postfix = QString("(") + std::to_string(++counter).c_str() + ")"; proposedName = QFileInfo(path + realName + postfix + suffix); } diff --git a/global.cpp b/global.cpp index d054150..5756bb0 100644 --- a/global.cpp +++ b/global.cpp @@ -622,9 +622,24 @@ QIcon Shared::icon(const QString& name, bool big) const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? big ? db : ds: big ? lb : ls; - return QIcon::fromTheme(itr->second.first, QIcon(prefix + itr->second.second)); + return QIcon::fromTheme(itr->second.first, QIcon(prefix + itr->second.second + ".svg")); } else { qDebug() << "Icon" << name << "not found"; return QIcon::fromTheme(name); } } + + +QString Shared::iconPath(const QString& name, bool big) +{ + QString result = ""; + std::map>::const_iterator itr = icons.find(name); + if (itr != icons.end()) { + const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? db : ds: + big ? lb : ls; + result = prefix + itr->second.second + ".svg"; + } + + return result; +} diff --git a/global.h b/global.h index d5d206e..521cd26 100644 --- a/global.h +++ b/global.h @@ -438,6 +438,7 @@ QIcon availabilityIcon(Availability av, bool big = false); QIcon subscriptionStateIcon(SubscriptionState ss, bool big = false); QIcon connectionStateIcon(ConnectionState cs, bool big = false); QIcon icon(const QString& name, bool big = false); +QString iconPath(const QString& name, bool big = false); static const std::map> icons = { {"user-online", {"user-online", "online"}}, diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index 8e006a9..903a3a8 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -961,3 +961,8 @@ QString Models::Roster::getContactIconPath(const QString& account, const QString } return path; } + +Models::Account * Models::Roster::getAccount(const QString& name) +{ + return accounts.find(name)->second; +} diff --git a/ui/models/roster.h b/ui/models/roster.h index 40c978d..07ab495 100644 --- a/ui/models/roster.h +++ b/ui/models/roster.h @@ -74,6 +74,7 @@ public: std::deque groupList(const QString& account) const; bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const; QString getContactIconPath(const QString& account, const QString& jid); + Account* getAccount(const QString& name); Accounts* accountsModel; diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 095f639..167b8ed 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -276,6 +276,7 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item) if (id != 0) { Conversations::const_iterator itr = conversations.find(*id); + Models::Account* acc = rosterModel.getAccount(id->account); Conversation* conv = 0; bool created = false; Models::Contact::Messages deque; @@ -283,11 +284,11 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item) conv = itr->second; } else if (contact != 0) { created = true; - conv = new Chat(contact); + conv = new Chat(acc, contact); contact->getMessages(deque); } else if (room != 0) { created = true; - conv = new Room(room); + conv = new Room(acc, room); room->getMessages(deque); if (!room->getJoined()) { diff --git a/ui/utils/image.cpp b/ui/utils/image.cpp index 1d09709..13ac400 100644 --- a/ui/utils/image.cpp +++ b/ui/utils/image.cpp @@ -19,12 +19,17 @@ #include #include "image.h" -Image::Image(const QString& path, quint16 p_minWidth, QWidget* parent): +Image::Image(const QString& p_path, quint16 p_minWidth, QWidget* parent): QLabel(parent), - pixmap(path), + pixmap(p_path), + path(p_path), aspectRatio(0), - minWidth(p_minWidth) + minWidth(p_minWidth), + svgMode(false) { + if (path.contains(".svg")) { + svgMode = true; + } setScaledContents(true); recalculateAspectRatio(); } @@ -55,7 +60,9 @@ void Image::recalculateAspectRatio() qreal height = pixmap.height(); qreal width = pixmap.width(); aspectRatio = width / height; - setPixmap(pixmap); + if (!svgMode) { + setPixmap(pixmap); + } setMinimumHeight(minWidth / aspectRatio); setMinimumWidth(minWidth); } @@ -68,8 +75,27 @@ void Image::setMinWidth(quint16 p_minWidth) } } -void Image::setPath(const QString& path) +void Image::setPath(const QString& p_path) { - pixmap = QPixmap(path); - recalculateAspectRatio(); + if (path != p_path) { + path = p_path; + if (path.contains(".svg")) { + svgMode = true; + } + pixmap = QPixmap(path); + recalculateAspectRatio(); + } } + +void Image::resizeEvent(QResizeEvent* event) +{ + if (svgMode) { + QIcon ico; + QSize size = event->size(); + ico.addFile(path, size); + setPixmap(ico.pixmap(size)); + } + + QLabel::resizeEvent(event); +} + diff --git a/ui/utils/image.h b/ui/utils/image.h index 883ddf4..4f524bb 100644 --- a/ui/utils/image.h +++ b/ui/utils/image.h @@ -21,6 +21,8 @@ #include #include +#include +#include /** * @todo write docs @@ -29,7 +31,6 @@ class Image : public QLabel { public: Image(const QString& path, quint16 minWidth = 50, QWidget* parent = nullptr); - ~Image(); int heightForWidth(int width) const override; @@ -40,11 +41,14 @@ public: private: QPixmap pixmap; + QString path; qreal aspectRatio; quint16 minWidth; + bool svgMode; private: void recalculateAspectRatio(); + void resizeEvent(QResizeEvent * event) override; }; #endif // IMAGE_H diff --git a/ui/utils/message.cpp b/ui/utils/message.cpp index 1dc35b7..d3d9f77 100644 --- a/ui/utils/message.cpp +++ b/ui/utils/message.cpp @@ -26,7 +26,7 @@ const QRegularExpression urlReg("(?setYOffset(1); shadow->setColor(Qt::black); body->setGraphicsEffect(shadow); + avatar->setMaximumHeight(60); + avatar->setMaximumWidth(60); + QVBoxLayout* aLay = new QVBoxLayout(); + aLay->addWidget(avatar); + aLay->addStretch(); + if (outgoing) { sender->setAlignment(Qt::AlignRight); date->setAlignment(Qt::AlignRight); addStretch(); addWidget(body); + addItem(aLay); } else { + addItem(aLay); addWidget(body); addStretch(); } @@ -95,6 +104,7 @@ Message::~Message() delete fileComment; } delete body; + delete avatar; } QString Message::getId() const @@ -243,3 +253,7 @@ const Shared::Message & Message::getMessage() const return msg; } +void Message::setAvatarPath(const QString& p_path) +{ + avatar->setPath(p_path); +} diff --git a/ui/utils/message.h b/ui/utils/message.h index 6bea433..537f40b 100644 --- a/ui/utils/message.h +++ b/ui/utils/message.h @@ -41,7 +41,7 @@ class Message : public QHBoxLayout { Q_OBJECT public: - Message(const Shared::Message& source, bool outgoing, const QString& sender, QWidget* parent = nullptr); + Message(const Shared::Message& source, bool outgoing, const QString& sender, const QString& avatarPath = "", QWidget* parent = nullptr); ~Message(); void setSender(const QString& sender); @@ -54,6 +54,7 @@ public: void hideComment(); void showFile(const QString& path); void setProgress(qreal value); + void setAvatarPath(const QString& p_path); signals: void buttonClicked(); @@ -70,6 +71,7 @@ private: QLabel* file; QProgressBar* progress; QLabel* fileComment; + Image* avatar; bool hasButton; bool hasProgress; bool hasFile; diff --git a/ui/utils/messageline.cpp b/ui/utils/messageline.cpp index 6f2cb8d..e7d190d 100644 --- a/ui/utils/messageline.cpp +++ b/ui/utils/messageline.cpp @@ -29,6 +29,7 @@ MessageLine::MessageLine(bool p_room, QWidget* parent): uploadPaths(), layout(new QVBoxLayout(this)), myName(), + myAvatarPath(), palNames(), uploading(), downloading(), @@ -57,15 +58,18 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc } QString sender; + QString aPath; bool outgoing; if (forceOutgoing) { sender = myName; + aPath = myAvatarPath; outgoing = true; } else { if (room) { if (msg.getFromResource() == myName) { sender = myName; + aPath = myAvatarPath; outgoing = true; } else { sender = msg.getFromResource(); @@ -74,6 +78,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc } else { if (msg.getOutgoing()) { sender = myName; + aPath = myAvatarPath; outgoing = true; } else { QString jid = msg.getFromJid(); @@ -88,7 +93,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc } } - Message* message = new Message(msg, outgoing, sender); + Message* message = new Message(msg, outgoing, sender, aPath); std::pair result = messageOrder.insert(std::make_pair(msg.getTime(), message)); if (!result.second) { @@ -348,3 +353,13 @@ void MessageLine::onUpload() { //TODO retry } + +void MessageLine::setMyAvatarPath(const QString& p_path) +{ + if (myAvatarPath != p_path) { + myAvatarPath = p_path; + for (std::pair pair : myMessages) { + pair.second->setAvatarPath(myAvatarPath); + } + } +} diff --git a/ui/utils/messageline.h b/ui/utils/messageline.h index 56f0a5e..4ef226c 100644 --- a/ui/utils/messageline.h +++ b/ui/utils/messageline.h @@ -54,6 +54,7 @@ public: void fileProgress(const QString& messageId, qreal progress); void appendMessageWithUpload(const Shared::Message& msg, const QString& path); void removeMessage(const QString& messageId); + void setMyAvatarPath(const QString& p_path); signals: void resize(int amount); @@ -87,6 +88,7 @@ private: QVBoxLayout* layout; QString myName; + QString myAvatarPath; std::map palNames; Index uploading; Index downloading; diff --git a/ui/widgets/chat.cpp b/ui/widgets/chat.cpp index c876679..43a4144 100644 --- a/ui/widgets/chat.cpp +++ b/ui/widgets/chat.cpp @@ -18,8 +18,8 @@ #include "chat.h" -Chat::Chat(Models::Contact* p_contact, QWidget* parent): - Conversation(false, p_contact->getAccountJid(), p_contact->getAccountResource(), p_contact->getJid(), "", p_contact->getAccountName(), parent), +Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent): + Conversation(false, acc, p_contact->getJid(), "", parent), contact(p_contact) { setName(p_contact->getContactName()); @@ -27,8 +27,6 @@ Chat::Chat(Models::Contact* p_contact, QWidget* parent): setStatus(p_contact->getStatus()); connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged); - - line->setMyName(p_contact->getAccountName()); } Chat::~Chat() @@ -62,8 +60,7 @@ void Chat::updateState() void Chat::handleSendMessage(const QString& text) { Shared::Message msg(Shared::Message::chat); - msg.setFromJid(myJid); - msg.setFromResource(myResource); + msg.setFrom(account->getFullJid()); msg.setToJid(palJid); msg.setToResource(activePalResource); msg.setBody(text); diff --git a/ui/widgets/chat.h b/ui/widgets/chat.h index 174bdf3..d36cbbf 100644 --- a/ui/widgets/chat.h +++ b/ui/widgets/chat.h @@ -30,7 +30,7 @@ class Chat : public Conversation { Q_OBJECT public: - Chat(Models::Contact* p_contact, QWidget* parent = 0); + Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent = 0); ~Chat(); void addMessage(const Shared::Message & data) override; diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index d9e1039..52e4b4c 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -26,14 +26,12 @@ #include #include -Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent): +Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, const QString pRes, QWidget* parent): QWidget(parent), isMuc(muc), - myJid(mJid), - myResource(mRes), + account(acc), palJid(pJid), activePalResource(pRes), - account(acc), line(new MessageLine(muc)), m_ui(new Ui::Conversation()), ker(), @@ -85,6 +83,9 @@ Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, co m_ui->scrollArea->installEventFilter(&scrollResizeCatcher); m_ui->filesPanel->installEventFilter(&attachResizeCatcher); + line->setMyAvatarPath(acc->getAvatarPath()); + line->setMyName(acc->getName()); + applyVisualEffects(); } @@ -124,7 +125,7 @@ void Conversation::setName(const QString& name) QString Conversation::getAccount() const { - return account; + return account->getName(); } QString Conversation::getJid() const @@ -199,8 +200,7 @@ void Conversation::onEnterPressed() msg.setType(Shared::Message::chat); msg.setToResource(activePalResource); } - msg.setFromJid(myJid); - msg.setFromResource(myResource); + msg.setFrom(account->getFullJid()); msg.setToJid(palJid); msg.setOutgoing(true); msg.generateRandomId(); diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index cf9585b..594801a 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -21,8 +21,9 @@ #include #include -#include "../../global.h" -#include "../../order.h" +#include "global.h" +#include "order.h" +#include "../models/account.h" #include "../utils/messageline.h" #include "../utils/resizer.h" #include "../utils/flowlayout.h" @@ -63,7 +64,7 @@ class Conversation : public QWidget { Q_OBJECT public: - Conversation(bool muc, const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent = 0); + Conversation(bool muc, Models::Account* acc, const QString pJid, const QString pRes, QWidget* parent = 0); ~Conversation(); QString getJid() const; @@ -115,11 +116,9 @@ protected: keep, down }; - QString myJid; - QString myResource; + Models::Account* account; QString palJid; QString activePalResource; - QString account; MessageLine* line; QScopedPointer m_ui; KeyEnterReceiver ker; diff --git a/ui/widgets/room.cpp b/ui/widgets/room.cpp index 98fc97d..0e0ecc6 100644 --- a/ui/widgets/room.cpp +++ b/ui/widgets/room.cpp @@ -18,8 +18,8 @@ #include "room.h" -Room::Room(Models::Room* p_room, QWidget* parent): - Conversation(true, p_room->getAccountJid(), p_room->getAccountResource(), p_room->getJid(), "", p_room->getAccountName(), parent), +Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent): + Conversation(true, acc, p_room->getJid(), "", parent), room(p_room) { setName(p_room->getName()); @@ -36,8 +36,7 @@ Room::~Room() void Room::handleSendMessage(const QString& text) { Shared::Message msg(Shared::Message::groupChat); - msg.setFromJid(myJid); - msg.setFromResource(myResource); + msg.setFrom(account->getFullJid()); msg.setToJid(palJid); //msg.setToResource(activePalResource); msg.setBody(text); diff --git a/ui/widgets/room.h b/ui/widgets/room.h index 52d19c6..bf08615 100644 --- a/ui/widgets/room.h +++ b/ui/widgets/room.h @@ -29,7 +29,7 @@ class Room : public Conversation { Q_OBJECT public: - Room(Models::Room* p_room, QWidget* parent = 0); + Room(Models::Account* acc, Models::Room* p_room, QWidget* parent = 0); ~Room(); bool autoJoined() const;