From 00c7d0a4c31ba83db5cabe941da610ed35318bdf Mon Sep 17 00:00:00 2001 From: Matt Traudt Date: Thu, 18 Feb 2016 23:27:47 -0600 Subject: [PATCH 1/2] Limit nick length and whitespaces in ContactUser and UserIdentity --- src/core/ContactUser.cpp | 4 +++- src/core/UserIdentity.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/ContactUser.cpp b/src/core/ContactUser.cpp index 422caf76..51abae88 100644 --- a/src/core/ContactUser.cpp +++ b/src/core/ContactUser.cpp @@ -288,7 +288,9 @@ QString ContactUser::nickname() const void ContactUser::setNickname(const QString &nickname) { - m_settings->write("nickname", nickname); + QString newNick = nickname.simplified(); + newNick.truncate(24); + m_settings->write("nickname", newNick); } QString ContactUser::hostname() const diff --git a/src/core/UserIdentity.cpp b/src/core/UserIdentity.cpp index e04e8cec..403fe5e7 100644 --- a/src/core/UserIdentity.cpp +++ b/src/core/UserIdentity.cpp @@ -128,7 +128,9 @@ QString UserIdentity::nickname() const void UserIdentity::setNickname(const QString &nick) { - m_settings->write("nickname", nick); + QString newNick = nick.simplified(); + newNick.truncate(24); + m_settings->write("nickname", newNick); } void UserIdentity::onSettingsModified(const QString &key, const QJsonValue &value) From 7646d661ca49e11ee88a5cd515ed927ec6e485d4 Mon Sep 17 00:00:00 2001 From: Matt Traudt Date: Mon, 21 Mar 2016 22:58:40 -0500 Subject: [PATCH 2/2] Limit nick length at the UI instead --- src/core/ContactUser.cpp | 4 +--- src/core/UserIdentity.cpp | 4 +--- src/ui/qml/ChatPage.qml | 2 +- src/ui/qml/ContactListDelegate.qml | 1 + src/ui/qml/MessageDelegate.qml | 8 ++++++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/ContactUser.cpp b/src/core/ContactUser.cpp index 51abae88..422caf76 100644 --- a/src/core/ContactUser.cpp +++ b/src/core/ContactUser.cpp @@ -288,9 +288,7 @@ QString ContactUser::nickname() const void ContactUser::setNickname(const QString &nickname) { - QString newNick = nickname.simplified(); - newNick.truncate(24); - m_settings->write("nickname", newNick); + m_settings->write("nickname", nickname); } QString ContactUser::hostname() const diff --git a/src/core/UserIdentity.cpp b/src/core/UserIdentity.cpp index 403fe5e7..e04e8cec 100644 --- a/src/core/UserIdentity.cpp +++ b/src/core/UserIdentity.cpp @@ -128,9 +128,7 @@ QString UserIdentity::nickname() const void UserIdentity::setNickname(const QString &nick) { - QString newNick = nick.simplified(); - newNick.truncate(24); - m_settings->write("nickname", newNick); + m_settings->write("nickname", nick); } void UserIdentity::onSettingsModified(const QString &key, const QJsonValue &value) diff --git a/src/ui/qml/ChatPage.qml b/src/ui/qml/ChatPage.qml index e24a3a96..4de4b6f6 100644 --- a/src/ui/qml/ChatPage.qml +++ b/src/ui/qml/ChatPage.qml @@ -44,7 +44,7 @@ FocusScope { } Label { - text: contact.nickname + text: contact.nickname.replace(/\s/gm, " ").trim().substr(0,80); textFormat: Text.PlainText font.pointSize: styleHelper.pointSize } diff --git a/src/ui/qml/ContactListDelegate.qml b/src/ui/qml/ContactListDelegate.qml index 15f7c274..0383cfca 100644 --- a/src/ui/qml/ContactListDelegate.qml +++ b/src/ui/qml/ContactListDelegate.qml @@ -36,6 +36,7 @@ Rectangle { text: model.name textFormat: Text.PlainText elide: Text.ElideRight + maximumLineCount: 1 font.pointSize: styleHelper.pointSize color: "black" opacity: model.status === ContactUser.Online ? 1 : 0.8 diff --git a/src/ui/qml/MessageDelegate.qml b/src/ui/qml/MessageDelegate.qml index d328a110..f684f0b4 100644 --- a/src/ui/qml/MessageDelegate.qml +++ b/src/ui/qml/MessageDelegate.qml @@ -22,14 +22,18 @@ Column { sourceComponent: Label { //: %1 nickname text: { - if (model.section === "offline") - return qsTr("%1 is offline").arg(contact !== null ? contact.nickname : "") + if (model.section === "offline"){ + var nick = (contact ? contact.nickname.replace(/\s/gm, ' ').trim().substr(0,80) : ""); + return qsTr("%1 is offline").arg(nick) + } + else return Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleShortDate) } textFormat: Text.PlainText width: background.parent.width elide: Text.ElideRight + maximumLineCount: 1 horizontalAlignment: Qt.AlignHCenter color: palette.mid