diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb98c7..c8c5e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,18 @@ ## Squawk 0.1.4 (UNRELEASED) ### New features -- message line now is in the same window with roster (new window dialog is still able to opened on double click) -- several ways to manage your account password: +- message line now is in the same window with roster (new window dialog is still able to opened on context menu) +- several new ways to manage your account password: - store it in plain text with the config (like it always was) - store it in config jammed (local hashing with the constant seed, not secure at all but might look like it is) - ask the account password on each program launch - store it in KWallet which is dynamically loaded ### Bug fixes -- never updating MUC avatars now update +- never updating MUC avatars now get updated - going offline related segfault fix +- statuses now behave better: they wrap if they don't fit, you can select them, you can follow links from there +- messages and statuses don't loose content if you use < ore > symbols ## Squawk 0.1.3 (Mar 31, 2020) diff --git a/shared/utils.cpp b/shared/utils.cpp index 776c052..06247f8 100644 --- a/shared/utils.cpp +++ b/shared/utils.cpp @@ -27,3 +27,22 @@ QString Shared::generateUUID() uuid_unparse_lower(uuid, uuid_str); return uuid_str; } + + +static const QRegularExpression urlReg("(?\\1"); + return "

" + processed + "

"; +} diff --git a/shared/utils.h b/shared/utils.h index 218b53a..e9e3d29 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -28,6 +29,7 @@ namespace Shared { QString generateUUID(); +QString processMessageBody(const QString& msg); static const std::vector colorPalette = { QColor(244, 27, 63), diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 120123a..3e1eb9e 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -33,7 +33,8 @@ Squawk::Squawk(QWidget *parent) : vCards(), requestedAccountsForPasswords(), prompt(0), - currentConversation(0) + currentConversation(0), + restoreSelection() { m_ui->setupUi(this); m_ui->roster->setModel(&rosterModel); @@ -53,12 +54,13 @@ Squawk::Squawk(QWidget *parent) : connect(m_ui->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact); connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference); connect(m_ui->comboBox, qOverload(&QComboBox::activated), this, &Squawk::onComboboxActivated); - connect(m_ui->roster, &QTreeView::doubleClicked, this, &Squawk::onRosterItemDoubleClicked); + //connect(m_ui->roster, &QTreeView::doubleClicked, this, &Squawk::onRosterItemDoubleClicked); connect(m_ui->roster, &QTreeView::customContextMenuRequested, this, &Squawk::onRosterContextMenu); connect(m_ui->roster, &QTreeView::collapsed, this, &Squawk::onItemCollepsed); connect(m_ui->roster->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Squawk::onRosterSelectionChanged); connect(rosterModel.accountsModel, &Models::Accounts::sizeChanged, this, &Squawk::onAccountsSizeChanged); + connect(contextMenu, &QMenu::aboutToHide, this, &Squawk::onContextAboutToHide); //m_ui->mainToolBar->addWidget(m_ui->comboBox); setWindowTitle(tr("Contact list")); @@ -1094,13 +1096,19 @@ void Squawk::subscribeConversation(Conversation* conv) } void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIndex& previous) -{ +{ + if (restoreSelection.isValid() && restoreSelection == current) { + restoreSelection = QModelIndex(); + return; + } + if (current.isValid()) { Models::Item* node = static_cast(current.internalPointer()); Models::Contact* contact = 0; Models::Room* room = 0; QString res; Models::Roster::ElId* id = 0; + bool hasContext = true; switch (node->type) { case Models::Item::contact: contact = static_cast(node); @@ -1110,21 +1118,38 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn contact = static_cast(node->parentItem()); id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid()); res = node->getName(); + hasContext = false; break; case Models::Item::room: room = static_cast(node); id = new Models::Roster::ElId(room->getAccountName(), room->getJid()); break; + case Models::Item::participant: + room = static_cast(node->parentItem()); + id = new Models::Roster::ElId(room->getAccountName(), room->getJid()); + hasContext = false; + break; + case Models::Item::group: + hasContext = false; default: break; } + if (hasContext && QGuiApplication::mouseButtons() & Qt::RightButton) { + if (id != 0) { + delete id; + } + restoreSelection = previous; + return; + } + if (id != 0) { if (currentConversation != 0) { - if (currentConversation->getJid() == id->name) { + if (currentConversation->getId() == *id) { if (contact != 0) { currentConversation->setPalResource(res); } + return; } else { currentConversation->deleteLater(); } @@ -1168,5 +1193,16 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn m_ui->filler->show(); } } + } else { + if (currentConversation != 0) { + currentConversation->deleteLater(); + currentConversation = 0; + m_ui->filler->show(); + } } } + +void Squawk::onContextAboutToHide() +{ + m_ui->roster->selectionModel()->setCurrentIndex(restoreSelection, QItemSelectionModel::ClearAndSelect); +} diff --git a/ui/squawk.h b/ui/squawk.h index 5b3d7cd..28a2f17 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -125,6 +125,7 @@ private: std::deque requestedAccountsForPasswords; QInputDialog* prompt; Conversation* currentConversation; + QModelIndex restoreSelection; protected: void closeEvent(QCloseEvent * event) override; @@ -155,6 +156,7 @@ private slots: void onPasswordPromptAccepted(); void onPasswordPromptRejected(); void onRosterSelectionChanged(const QModelIndex& current, const QModelIndex& previous); + void onContextAboutToHide(); private: void checkNextAccountForPassword(); diff --git a/ui/squawk.ui b/ui/squawk.ui index 6c50024..19fdc4f 100644 --- a/ui/squawk.ui +++ b/ui/squawk.ui @@ -81,6 +81,12 @@ QFrame::Sunken + + QAbstractItemView::NoEditTriggers + + + false + true diff --git a/ui/utils/message.cpp b/ui/utils/message.cpp index c5149ef..7a004bb 100644 --- a/ui/utils/message.cpp +++ b/ui/utils/message.cpp @@ -23,18 +23,6 @@ #include #include -const QRegularExpression urlReg("(?setBackgroundRole(QPalette::AlternateBase); body->setAutoFillBackground(true); - QString bd = msg.getBody(); - //bd.replace(imgReg, ""); - bd.replace(urlReg, "\\1"); - //bd.replace("\n", "
"); + QString bd = Shared::processMessageBody(msg.getBody()); text->setTextFormat(Qt::RichText); - text->setText("

" + bd + "

");; + text->setText(bd);; text->setTextInteractionFlags(text->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); text->setWordWrap(true); text->setOpenExternalLinks(true); @@ -308,13 +293,13 @@ bool Message::change(const QMap& data) { bool idChanged = msg.change(data); - QString bd = msg.getBody(); - //bd.replace(imgReg, ""); - bd.replace(urlReg, "\\1"); - text->setText(bd); - if (bd.size() > 0) { + QString body = msg.getBody(); + QString bd = Shared::processMessageBody(body); + if (body.size() > 0) { + text->setText(bd); text->show(); } else { + text->setText(body); text->hide(); } if (msg.getEdited()) { diff --git a/ui/utils/message.h b/ui/utils/message.h index fc3f178..eef93a1 100644 --- a/ui/utils/message.h +++ b/ui/utils/message.h @@ -34,6 +34,7 @@ #include "shared/message.h" #include "shared/icons.h" #include "shared/global.h" +#include "shared/utils.h" #include "resizer.h" #include "image.h" diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index d413506..50f7dcf 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -19,7 +19,6 @@ #include "conversation.h" #include "ui_conversation.h" #include "ui/utils/dropshadoweffect.h" -#include "shared/icons.h" #include #include @@ -308,7 +307,7 @@ void Conversation::onFileSelected() void Conversation::setStatus(const QString& status) { - statusLabel->setText(status); + statusLabel->setText(Shared::processMessageBody(status)); } void Conversation::onScrollResize() diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 075bc31..f64ae54 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -31,6 +31,8 @@ #include "ui/utils/resizer.h" #include "ui/utils/flowlayout.h" #include "ui/utils/badge.h" +#include "shared/icons.h" +#include "shared/utils.h" namespace Ui { diff --git a/ui/widgets/conversation.ui b/ui/widgets/conversation.ui index 9b1321e..d73875d 100644 --- a/ui/widgets/conversation.ui +++ b/ui/widgets/conversation.ui @@ -122,9 +122,24 @@ + + + 0 + 0 + + + + true + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + @@ -134,9 +149,12 @@ Qt::Horizontal + + QSizePolicy::Preferred + - 40 + 0 20