From 129beb57c9525439d04fc2bf74f4ccaed30369c9 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 13 Jun 2019 22:33:04 -0400 Subject: Further Improve Reply Functionality Quoted replies now include matrix.to links for the event and the user. UI Rendering has been (slightly) improved... still very WIP. Restructured the reply structure in the code for future usability improvements. --- src/Utils.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index f8fdfaf9..690a9a9a 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -314,6 +314,20 @@ utils::markdownToHtml(const QString &text) return result; } +QString +utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) +{ + return QString("
In reply " + "to%3
%4
") + .arg(QString::fromStdString(related.related_event), + related.quoted_user, + related.quoted_user, + related.quoted_body) + + html; +} + QString utils::linkColor() { -- cgit 1.5.1 From 40d9b5c5fcc29d58248f00b6c6437af252881e17 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 27 Jun 2019 14:11:02 +0200 Subject: Fix santizize=undefined warning (overflow) --- src/Utils.cpp | 6 +++--- src/Utils.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 690a9a9a..3d304e7d 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -342,10 +342,10 @@ utils::linkColor() return QPalette().color(QPalette::Link).name(); } -int +uint32_t utils::hashQString(const QString &input) { - auto hash = 0; + uint32_t hash = 0; for (int i = 0; i < input.length(); i++) { hash = input.at(i).digitValue() + ((hash << 5) - hash); @@ -363,7 +363,7 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou // Create a color for the input auto hash = hashQString(input); // create a hue value based on the hash of the input. - auto userHue = qAbs(hash % 360); + auto userHue = static_cast(qAbs(hash % 360)); // start with moderate saturation and lightness values. auto sat = 220; auto lightness = 125; diff --git a/src/Utils.h b/src/Utils.h index bf941c4c..0f022770 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -243,7 +243,7 @@ QString linkColor(); //! Returns the hash code of the input QString -int +uint32_t hashQString(const QString &input); //! Generate a color (matching #RRGGBB) that has an acceptable contrast to background that is based -- cgit 1.5.1 From c0a010acbb7f0045aa1ce33f82b0d537a715a886 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 4 Jul 2019 21:20:19 -0400 Subject: Fix deprecated function call issues with Qt 5.13 Update to mtxclient 0.3.0 --- CMakeLists.txt | 2 +- deps/CMakeLists.txt | 5 ++-- nheko-backtrace.dump | Bin 0 -> 288 bytes src/RoomInfoListItem.cpp | 4 ++-- src/TypingDisplay.cpp | 2 +- src/Utils.cpp | 47 +++++++++++++++++++++++++++++++------ src/Utils.h | 7 ++++++ src/dialogs/ImageOverlay.cpp | 5 +++- src/main.cpp | 5 +++- src/notifications/ManagerLinux.cpp | 2 +- src/timeline/TimelineItem.cpp | 6 ++++- src/timeline/TimelineItem.h | 8 +++++++ src/timeline/widgets/AudioItem.cpp | 2 +- src/timeline/widgets/FileItem.cpp | 2 +- src/timeline/widgets/ImageItem.cpp | 2 +- src/ui/DropShadow.h | 22 ++++++++++------- src/ui/InfoMessage.cpp | 4 ++-- src/ui/Painter.h | 6 +++-- 18 files changed, 97 insertions(+), 34 deletions(-) create mode 100644 nheko-backtrace.dump (limited to 'src/Utils.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d262f0..4a0bf50f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,7 @@ find_package(Boost 1.66 REQUIRED thread) find_package(ZLIB REQUIRED) find_package(OpenSSL REQUIRED) -find_package(MatrixClient 0.1.0 REQUIRED) +find_package(MatrixClient 0.3.0 REQUIRED) find_package(Olm 2 REQUIRED) find_package(spdlog 1.0.0 CONFIG REQUIRED) find_package(cmark REQUIRED) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 9a6fd433..1df09cc9 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -46,17 +46,16 @@ set(BOOST_SHA256 set( MTXCLIENT_URL - https://github.com/Nheko-Reborn/mtxclient/archive/32065798a2efa205052fcd2f470c52326a46d0b9.tar.gz + https://github.com/Nheko-Reborn/mtxclient/archive/35b596a98d516e044a6a25803ba6b93b6c0a538b.tar.gz ) set(MTXCLIENT_HASH - 3ddc6a482b5f388533bbaa69c44f1621d65a4e38fcb6cafaff83330975ea7e2b) + ea770f52afaad45706b8050aa3d860fa98780c60f2d3f061f2c89dfd3b3bf9be) set( TWEENY_URL https://github.com/mobius3/tweeny/archive/b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf.tar.gz ) set(TWEENY_HASH 9a632b9da84823fae002ad5d9ba02c8d77c0a3810479974c6b637c5504165475) - set( LMDBXX_HEADER_URL https://raw.githubusercontent.com/bendiken/lmdbxx/0b43ca87d8cfabba392dfe884eb1edb83874de02/lmdb%2B%2B.h diff --git a/nheko-backtrace.dump b/nheko-backtrace.dump new file mode 100644 index 00000000..11aeb9d2 Binary files /dev/null and b/nheko-backtrace.dump differ diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index f17b383c..d6a4f78f 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -182,7 +182,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) QFont tsFont; tsFont.setPointSizeF(tsFont.pointSizeF() * 0.9); - const int msgStampWidth = QFontMetrics(tsFont).width(lastMsgInfo_.timestamp) + 4; + const int msgStampWidth = QFontMetrics(tsFont).horizontalAdvance(lastMsgInfo_.timestamp) + 4; // We use the full width of the widget if there is no unread msg bubble. const int bottomLineWidthLimit = (unreadMsgCount_ > 0) ? msgStampWidth : 0; @@ -211,7 +211,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) p.setFont(QFont{}); p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), userName); - int nameWidth = QFontMetrics(QFont{}).width(userName); + int nameWidth = QFontMetrics(QFont{}).horizontalAdvance(userName); p.setFont(QFont{}); diff --git a/src/TypingDisplay.cpp b/src/TypingDisplay.cpp index 11313adc..97aeb268 100644 --- a/src/TypingDisplay.cpp +++ b/src/TypingDisplay.cpp @@ -69,7 +69,7 @@ TypingDisplay::paintEvent(QPaintEvent *) text_ = fm.elidedText(text_, Qt::ElideRight, (double)(width() * 0.75)); QPainterPath path; - path.addRoundedRect(QRectF(0, 0, fm.width(text_) + 2 * LEFT_PADDING, height()), 3, 3); + path.addRoundedRect(QRectF(0, 0, fm.horizontalAdvance(text_) + 2 * LEFT_PADDING, height()), 3, 3); p.fillPath(path, backgroundColor()); p.drawText(region, Qt::AlignVCenter, text_); diff --git a/src/Utils.cpp b/src/Utils.cpp index 3d304e7d..863de79e 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include @@ -229,8 +231,10 @@ utils::scaleImageToPixmap(const QImage &img, int size) if (img.isNull()) return QPixmap(); + // Deprecated in 5.13: const double sz = + // std::ceil(QApplication::desktop()->screen()->devicePixelRatioF() * (double)size); const double sz = - std::ceil(QApplication::desktop()->screen()->devicePixelRatioF() * (double)size); + std::ceil(QGuiApplication::primaryScreen()->devicePixelRatio() * (double)size); return QPixmap::fromImage( img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } @@ -318,16 +322,44 @@ QString utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) { return QString("
In reply " - "to%3
%4
") - .arg(QString::fromStdString(related.related_event), + "href=\"https://matrix.to/#/%1/%2\">In reply " + "to* %4
%5") + .arg(related.room, + QString::fromStdString(related.related_event), related.quoted_user, related.quoted_user, - related.quoted_body) + + getQuoteBody(related)) + html; } +QString +utils::getQuoteBody(const RelatedInfo &related) +{ + using MsgType = mtx::events::MessageType; + + switch (related.type) { + case MsgType::Text: { + return markdownToHtml(related.quoted_body); + } + case MsgType::File: { + return QString("sent a file."); + } + case MsgType::Image: { + return QString("sent an image."); + } + case MsgType::Audio: { + return QString("sent an audio file."); + } + case MsgType::Video: { + return QString("sent a video"); + } + default: { + return related.quoted_body; + } + } +} + QString utils::linkColor() { @@ -475,7 +507,8 @@ utils::centerWidget(QWidget *widget, QWidget *parent) return; } - widget->move(findCenter(QApplication::desktop()->screenGeometry())); + // Deprecated in 5.13: widget->move(findCenter(QApplication::desktop()->screenGeometry())); + widget->move(findCenter(QGuiApplication::primaryScreen()->geometry())); } void diff --git a/src/Utils.h b/src/Utils.h index 0f022770..a840a187 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -22,6 +22,9 @@ class QComboBox; // outgoing messages struct RelatedInfo { + using MsgType = mtx::events::MessageType; + MsgType type; + QString room; QString quoted_body; std::string related_event; QString quoted_user; @@ -238,6 +241,10 @@ markdownToHtml(const QString &text); QString getFormattedQuoteBody(const RelatedInfo &related, const QString &html); +//! Get the body for the quote, depending on the event type. +QString +getQuoteBody(const RelatedInfo &related); + //! Retrieve the color of the links based on the current theme. QString linkColor(); diff --git a/src/dialogs/ImageOverlay.cpp b/src/dialogs/ImageOverlay.cpp index dbf5bbe4..dd9cd03a 100644 --- a/src/dialogs/ImageOverlay.cpp +++ b/src/dialogs/ImageOverlay.cpp @@ -17,7 +17,9 @@ #include #include +#include #include +#include #include "dialogs/ImageOverlay.h" @@ -39,7 +41,8 @@ ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) setAttribute(Qt::WA_DeleteOnClose, true); setWindowState(Qt::WindowFullScreen); - screen_ = QApplication::desktop()->availableGeometry(); + // Deprecated in 5.13: screen_ = QApplication::desktop()->availableGeometry(); + screen_ = QGuiApplication::primaryScreen()->availableGeometry(); move(QApplication::desktop()->mapToGlobal(screen_.topLeft())); resize(screen_.size()); diff --git a/src/main.cpp b/src/main.cpp index 0c196a33..bd7560da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,10 +21,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -72,7 +74,8 @@ registerSignalHandlers() QPoint screenCenter(int width, int height) { - QRect screenGeometry = QApplication::desktop()->screenGeometry(); + // Deprecated in 5.13: QRect screenGeometry = QApplication::desktop()->screenGeometry(); + QRect screenGeometry = QGuiApplication::primaryScreen()->geometry(); int x = (screenGeometry.width() - width) / 2; int y = (screenGeometry.height() - height) / 2; diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp index d3901c52..1d9f97d9 100644 --- a/src/notifications/ManagerLinux.cpp +++ b/src/notifications/ManagerLinux.cpp @@ -142,7 +142,7 @@ operator<<(QDBusArgument &arg, const QImage &image) int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3); arg << i.depth() / channels; arg << channels; - arg << QByteArray(reinterpret_cast(i.bits()), i.byteCount()); + arg << QByteArray(reinterpret_cast(i.bits()), i.sizeInBytes()); arg.endStructure(); return arg; } diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index 1094bde5..80153026 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -731,7 +731,9 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam userName_->setToolTipDuration(1500); userName_->setAttribute(Qt::WA_Hover); userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop); - userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text())); + // width deprecated in 5.13: + // userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text())); + userName_->setFixedWidth(QFontMetrics(userName_->font()).horizontalAdvance(userName_->text())); // Set the user color asynchronously if it hasn't been generated yet, // otherwise this will just set it. @@ -877,9 +879,11 @@ TimelineItem::replyAction() return; RelatedInfo related; + related.type = message_type_; related.quoted_body = body_->toPlainText(); related.quoted_user = descriptionMsg_.userid; related.related_event = eventId().toStdString(); + related.room = room_id_; emit ChatPage::instance()->messageReply(related); } diff --git a/src/timeline/TimelineItem.h b/src/timeline/TimelineItem.h index 6fe4a6f2..4db36c07 100644 --- a/src/timeline/TimelineItem.h +++ b/src/timeline/TimelineItem.h @@ -28,6 +28,8 @@ #include +#include "mtx/events.hpp" + #include "AvatarProvider.h" #include "RoomInfoListItem.h" #include "Utils.h" @@ -276,6 +278,7 @@ private: QString replaceEmoji(const QString &body); QString event_id_; + mtx::events::MessageType message_type_; QString room_id_; DescInfo descriptionMsg_; @@ -349,6 +352,11 @@ TimelineItem::setupWidgetLayout(Widget *widget, const Event &event, bool withSen { init(); + //if (event.type == mtx::events::EventType::RoomMessage) { + // message_type_ = mtx::events::getMessageType(event.content.msgtype); + //} + // TODO: Fix this. + message_type_ = mtx::events::MessageType::Unknown; event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); diff --git a/src/timeline/widgets/AudioItem.cpp b/src/timeline/widgets/AudioItem.cpp index 72332174..8cc2ba8f 100644 --- a/src/timeline/widgets/AudioItem.cpp +++ b/src/timeline/widgets/AudioItem.cpp @@ -163,7 +163,7 @@ AudioItem::resizeEvent(QResizeEvent *event) QFontMetrics fm(font); const int computedWidth = std::min( - fm.width(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth); + fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth); resize(computedWidth, Height); diff --git a/src/timeline/widgets/FileItem.cpp b/src/timeline/widgets/FileItem.cpp index e97554e2..903fc4b2 100644 --- a/src/timeline/widgets/FileItem.cpp +++ b/src/timeline/widgets/FileItem.cpp @@ -154,7 +154,7 @@ FileItem::resizeEvent(QResizeEvent *event) QFontMetrics fm(font); const int computedWidth = std::min( - fm.width(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth); + fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth); resize(computedWidth, Height); diff --git a/src/timeline/widgets/ImageItem.cpp b/src/timeline/widgets/ImageItem.cpp index 4ee9e42a..79a66c4d 100644 --- a/src/timeline/widgets/ImageItem.cpp +++ b/src/timeline/widgets/ImageItem.cpp @@ -192,7 +192,7 @@ ImageItem::paintEvent(QPaintEvent *event) if (image_.isNull()) { QString elidedText = metrics.elidedText(text_, Qt::ElideRight, max_width_ - 10); - setFixedSize(metrics.width(elidedText), fontHeight); + setFixedSize(metrics.horizontalAdvance(elidedText), fontHeight); painter.setFont(font); painter.setPen(QPen(QColor(66, 133, 244))); diff --git a/src/ui/DropShadow.h b/src/ui/DropShadow.h index b7ba1985..d322fb42 100644 --- a/src/ui/DropShadow.h +++ b/src/ui/DropShadow.h @@ -30,7 +30,11 @@ public: gradient.setStart(right0); gradient.setFinalStop(right1); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect( + // Deprecated in 5.13: painter.drawRoundRect( + // QRectF(QPointF(width - margin * radius, margin), QPointF(width, height - margin)), + // 0.0, + // 0.0); + painter.drawRoundedRect( QRectF(QPointF(width - margin * radius, margin), QPointF(width, height - margin)), 0.0, 0.0); @@ -41,7 +45,7 @@ public: gradient.setStart(left0); gradient.setFinalStop(left1); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect( + painter.drawRoundedRect( QRectF(QPointF(margin * radius, margin), QPointF(0, height - margin)), 0.0, 0.0); // Top @@ -50,7 +54,7 @@ public: gradient.setStart(top0); gradient.setFinalStop(top1); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect( + painter.drawRoundedRect( QRectF(QPointF(width - margin, 0), QPointF(margin, margin)), 0.0, 0.0); // Bottom @@ -59,7 +63,7 @@ public: gradient.setStart(bottom0); gradient.setFinalStop(bottom1); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect( + painter.drawRoundedRect( QRectF(QPointF(margin, height - margin), QPointF(width - margin, height)), 0.0, 0.0); @@ -71,7 +75,7 @@ public: gradient.setFinalStop(bottomright1); gradient.setColorAt(endPosition1, end); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect(QRectF(bottomright0, bottomright1), 0.0, 0.0); + painter.drawRoundedRect(QRectF(bottomright0, bottomright1), 0.0, 0.0); // BottomLeft QPointF bottomleft0(margin, height - margin); @@ -80,7 +84,7 @@ public: gradient.setFinalStop(bottomleft1); gradient.setColorAt(endPosition1, end); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect(QRectF(bottomleft0, bottomleft1), 0.0, 0.0); + painter.drawRoundedRect(QRectF(bottomleft0, bottomleft1), 0.0, 0.0); // TopLeft QPointF topleft0(margin, margin); @@ -89,7 +93,7 @@ public: gradient.setFinalStop(topleft1); gradient.setColorAt(endPosition1, end); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect(QRectF(topleft0, topleft1), 0.0, 0.0); + painter.drawRoundedRect(QRectF(topleft0, topleft1), 0.0, 0.0); // TopRight QPointF topright0(width - margin, margin); @@ -98,12 +102,12 @@ public: gradient.setFinalStop(topright1); gradient.setColorAt(endPosition1, end); painter.setBrush(QBrush(gradient)); - painter.drawRoundRect(QRectF(topright0, topright1), 0.0, 0.0); + painter.drawRoundedRect(QRectF(topright0, topright1), 0.0, 0.0); // Widget painter.setBrush(QBrush("#FFFFFF")); painter.setRenderHint(QPainter::Antialiasing); - painter.drawRoundRect( + painter.drawRoundedRect( QRectF(QPointF(margin, margin), QPointF(width - margin, height - margin)), radius, radius); diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp index e9de20cc..b18a80c4 100644 --- a/src/ui/InfoMessage.cpp +++ b/src/ui/InfoMessage.cpp @@ -22,7 +22,7 @@ InfoMessage::InfoMessage(QString msg, QWidget *parent) initFont(); QFontMetrics fm{font()}; - width_ = fm.width(msg_) + HPadding * 2; + width_ = fm.horizontalAdvance(msg_) + HPadding * 2; height_ = fm.ascent() + 2 * VPadding; setFixedHeight(height_ + 2 * HMargin); @@ -64,7 +64,7 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent) msg_ = datetime.toString(fmt); QFontMetrics fm{font()}; - width_ = fm.width(msg_) + HPadding * 2; + width_ = fm.horizontalAdvance(msg_) + HPadding * 2; height_ = fm.ascent() + 2 * VPadding; setFixedHeight(height_ + 2 * HMargin); diff --git a/src/ui/Painter.h b/src/ui/Painter.h index 8de39651..8feed17b 100644 --- a/src/ui/Painter.h +++ b/src/ui/Painter.h @@ -20,8 +20,10 @@ public: void drawTextRight(int x, int y, int outerw, const QString &text, int textWidth = -1) { QFontMetrics m(fontMetrics()); - if (textWidth < 0) - textWidth = m.width(text); + if (textWidth < 0) { + // deprecated in 5.13: textWidth = m.width(text); + textWidth = m.horizontalAdvance(text); + } drawText((outerw - x - textWidth), y + m.ascent(), text); } -- cgit 1.5.1 From 86888ee71349cb416e79940e3b369e047cf7492a Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Fri, 26 Jul 2019 17:44:44 -0400 Subject: Fix bug with emoji font setting and clean linting --- src/ChatPage.cpp | 22 +++++++++++----------- src/ChatPage.h | 3 ++- src/UserSettingsPage.cpp | 2 +- src/UserSettingsPage.h | 2 -- src/Utils.cpp | 23 +++++++++++++++++++++++ src/Utils.h | 3 +++ src/timeline/TimelineItem.cpp | 27 ++------------------------- src/timeline/TimelineItem.h | 1 - 8 files changed, 42 insertions(+), 41 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index deefec14..18188429 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -90,13 +90,13 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(sidebarActions_, &SideBarActions::joinRoom, this, &ChatPage::joinRoom); connect(sidebarActions_, &SideBarActions::createRoom, this, &ChatPage::createRoom); - user_info_widget_ = new UserInfoWidget(sideBar_); - //user_mentions_widget_ = new UserMentionsWidget(sideBar_); - room_list_ = new RoomList(sideBar_); + user_info_widget_ = new UserInfoWidget(sideBar_); + // user_mentions_widget_ = new UserMentionsWidget(sideBar_); + room_list_ = new RoomList(sideBar_); connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom); sideBarLayout_->addWidget(user_info_widget_); - //sideBarLayout_->addWidget(user_mentions_widget_); + // sideBarLayout_->addWidget(user_mentions_widget_); sideBarLayout_->addWidget(room_list_); sideBarLayout_->addWidget(sidebarActions_); @@ -159,7 +159,8 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) 1000, "", "highlight", - [this, mentionsPos](const mtx::responses::Notifications &res, mtx::http::RequestErr err) { + [this, mentionsPos](const mtx::responses::Notifications &res, + mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to retrieve notifications: {} ({})", err->matrix_error.error, @@ -218,8 +219,6 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) } }); - - connect(room_list_, &RoomList::roomChanged, this, [this](const QString &roomid) { QStringList users; @@ -1007,10 +1006,11 @@ ChatPage::showNotificationsDialog(const mtx::responses::Notifications &res, cons nhlog::db()->warn("error while sending desktop notification: {}", e.what()); } } - notifDialog->setGeometry(widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2); - //notifDialog->move(widgetPos.x(), widgetPos.y()); - //notifDialog->setFixedWidth(width() / 10); - //notifDialog->setFixedHeight(height() / 2); + notifDialog->setGeometry( + widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2); + // notifDialog->move(widgetPos.x(), widgetPos.y()); + // notifDialog->setFixedWidth(width() / 10); + // notifDialog->setFixedHeight(height() / 2); notifDialog->raise(); notifDialog->show(); } diff --git a/src/ChatPage.h b/src/ChatPage.h index b2f04b02..3c97ba25 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -89,7 +89,8 @@ signals: void messageReply(const RelatedInfo &related); void notificationsRetrieved(const mtx::responses::Notifications &); - void highlightedNotifsRetrieved(const mtx::responses::Notifications &, const QPoint widgetPos); + void highlightedNotifsRetrieved(const mtx::responses::Notifications &, + const QPoint widgetPos); void uploadFailed(const QString &msg); void imageUploaded(const QString &roomid, diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 1ac3f738..49cb2c1f 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -239,7 +239,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge fontSizeOptionLayout->addWidget(fontSizeLabel); fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight); - auto fontFamilyOptionLayout = new QHBoxLayout; + auto fontFamilyOptionLayout = new QHBoxLayout; auto emojiFontFamilyOptionLayout = new QHBoxLayout; fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); emojiFontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 8b782213..ffff1e20 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -96,7 +96,6 @@ public: QString font() const { return font_; } QString emojiFont() const { return emojiFont_; } - signals: void groupViewStateChanged(bool state); @@ -111,7 +110,6 @@ private: double baseFontSize_; QString font_; QString emojiFont_; - }; class HorizontalLine : public QFrame diff --git a/src/Utils.cpp b/src/Utils.cpp index 863de79e..d6b092b1 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -26,6 +26,29 @@ utils::localUser() return settings.value("auth/user_id").toString(); } +QString +utils::replaceEmoji(const QString &body) +{ + QString fmtBody = ""; + + QVector utf32_string = body.toUcs4(); + + QSettings settings; + QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + + for (auto &code : utf32_string) { + // TODO: Be more precise here. + if (code > 9000) + fmtBody += + QString("") + + QString::fromUcs4(&code, 1) + ""; + else + fmtBody += QString::fromUcs4(&code, 1); + } + + return fmtBody; +} + void utils::setScaleFactor(float factor) { diff --git a/src/Utils.h b/src/Utils.h index a840a187..756dc1e3 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -34,6 +34,9 @@ namespace utils { using TimelineEvent = mtx::events::collections::TimelineEvents; +QString +replaceEmoji(const QString &body); + QString localUser(); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index cf5d68c6..54011279 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -650,7 +650,7 @@ TimelineItem::markReceived(bool isEncrypted) void TimelineItem::generateBody(const QString &body) { - body_ = new TextLabel(replaceEmoji(body), this); + body_ = new TextLabel(utils::replaceEmoji(body), this); body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction); connect(body_, &TextLabel::userProfileTriggered, this, [](const QString &user_id) { @@ -727,7 +727,7 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam userName_ = new QLabel(this); userName_->setFont(usernameFont); - userName_->setText(replaceEmoji(fm.elidedText(sender, Qt::ElideRight, 500))); + userName_->setText(utils::replaceEmoji(fm.elidedText(sender, Qt::ElideRight, 500))); userName_->setToolTip(user_id); userName_->setToolTipDuration(1500); userName_->setAttribute(Qt::WA_Hover); @@ -773,29 +773,6 @@ TimelineItem::generateTimestamp(const QDateTime &time) QString(" %1 ").arg(time.toString("HH:mm"))); } -QString -TimelineItem::replaceEmoji(const QString &body) -{ - QString fmtBody = ""; - - QVector utf32_string = body.toUcs4(); - - QSettings settings; - QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); - - for (auto &code : utf32_string) { - // TODO: Be more precise here. - if (code > 9000) - fmtBody += - QString("") + - QString::fromUcs4(&code, 1) + ""; - else - fmtBody += QString::fromUcs4(&code, 1); - } - - return fmtBody; -} - void TimelineItem::setupAvatarLayout(const QString &userName) { diff --git a/src/timeline/TimelineItem.h b/src/timeline/TimelineItem.h index e2b1cda4..c0dab6b8 100644 --- a/src/timeline/TimelineItem.h +++ b/src/timeline/TimelineItem.h @@ -276,7 +276,6 @@ private: QFutureWatcher *colorGenerating_; - QString replaceEmoji(const QString &body); QString event_id_; mtx::events::MessageType message_type_; QString room_id_; -- cgit 1.5.1 From 1c9cc33902d8242ec25b4416a1662ee6c9902583 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 28 Jul 2019 12:50:10 +0200 Subject: Try to localise timestamps I'm not sure, if that is the right way, but Qt doesn't really have a way to format custom localised dates, so I tried to find the closest approximations to what we currently have. Relates to #69 --- resources/langs/nheko_de.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_el.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_en.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_fr.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_nl.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_pl.ts | 101 +++++++++++++++++++++++++++++++--------- resources/langs/nheko_ru.ts | 103 ++++++++++++++++++++++++++++++++--------- resources/langs/nheko_zh_CN.ts | 101 +++++++++++++++++++++++++++++++--------- src/Utils.cpp | 20 ++++---- src/dialogs/MemberList.cpp | 4 +- src/dialogs/ReadReceipts.cpp | 12 +++-- src/timeline/TimelineItem.cpp | 2 +- src/ui/InfoMessage.cpp | 13 +++--- 13 files changed, 668 insertions(+), 193 deletions(-) (limited to 'src/Utils.cpp') diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index f592a4d8..8c92c084 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -4,7 +4,7 @@ AudioItem - + Save File In Datei speichern @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. Hochladen der Bilddatei fehlgeschlagen. Bitte versuche es erneut. @@ -32,7 +32,7 @@ Hochladen der Videodatei fehlgeschlagen. Bitte versuche es erneut. - + Failed to restore OLM account. Please login again. Wiederherstellung des OLM Accounts fehlgeschlagen. Bitte logge dich erneut ein. @@ -42,7 +42,7 @@ Nachrichten konnten nicht aus dem Cache geladen werden. Bitte melde dich erneut an. - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. Erstellung des Schlüsselmaterials fehlgeschlagen. Antwort des Servers: %1 %2. Bitte versuche es später erneut. @@ -118,7 +118,7 @@ FileItem - + Save File Datei speichern @@ -126,7 +126,7 @@ ImageItem - + Save image Bild speichern @@ -205,8 +205,8 @@ Teilnehmerliste - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Raum verlassen - + Accept Akzeptieren @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted @@ -354,13 +354,13 @@ TextInputWidget - + Send a file - + Write a message... Schreibe eine Nachricht... @@ -424,7 +424,12 @@ - + + Mentions + + + + Invite users Benutzer einladen @@ -460,7 +465,7 @@ TypingDisplay - + is typing tippt @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray Ins Benachrichtigungsfeld minimieren @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme Erscheinungsbild @@ -566,7 +576,7 @@ ALLGEMEINES - + Open Sessions File @@ -635,6 +645,14 @@ ANMELDEN + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -778,7 +796,7 @@ Medien-Größe: %2 dialogs::ReadReceipts - + Read receipts Lesebestätigungen @@ -793,6 +811,19 @@ Medien-Größe: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1003,4 +1034,32 @@ Medien-Größe: %2 Flaggen + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 5a6be4cb..74b14266 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Αποθήκευση @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. @@ -32,7 +32,7 @@ - + Failed to restore OLM account. Please login again. @@ -42,7 +42,7 @@ - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File Αποθήκευση @@ -126,7 +126,7 @@ ImageItem - + Save image Αποθήκευση Εικόνας @@ -205,8 +205,8 @@ Μέλη - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Βγές - + Accept Αποδοχή @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted @@ -354,13 +354,13 @@ TextInputWidget - + Send a file - + Write a message... Γράψε ένα μήνυμα... @@ -424,7 +424,12 @@ - + + Mentions + + + + Invite users Προσκάλεσε χρήστες @@ -460,7 +465,7 @@ TypingDisplay - + is typing πληκτρολογεί @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray Ελαχιστοποίηση @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme Φόντο @@ -566,7 +576,7 @@ ΓΕΝΙΚΑ - + Open Sessions File @@ -635,6 +645,14 @@ ΕΙΣΟΔΟΣ + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -776,7 +794,7 @@ Media size: %2 dialogs::ReadReceipts - + Read receipts @@ -791,6 +809,19 @@ Media size: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1001,4 +1032,32 @@ Media size: %2 Σημαίες + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index d8259dc5..5c4bad0e 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Save File @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. Failed to upload image. Please try again. @@ -32,7 +32,7 @@ Failed to upload video. Please try again. - + Failed to restore OLM account. Please login again. Failed to restore OLM account. Please login again. @@ -42,7 +42,7 @@ Failed to restore save data. Please login again. - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File Save File @@ -126,7 +126,7 @@ ImageItem - + Save image Save image @@ -205,8 +205,8 @@ Room members - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Leave room - + Accept Accept @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted @@ -354,13 +354,13 @@ TextInputWidget - + Send a file - + Write a message... @@ -424,7 +424,12 @@ - + + Mentions + + + + Invite users @@ -460,7 +465,7 @@ TypingDisplay - + is typing @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme @@ -566,7 +576,7 @@ - + Open Sessions File @@ -635,6 +645,14 @@ + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -776,7 +794,7 @@ Media size: %2 dialogs::ReadReceipts - + Read receipts @@ -791,6 +809,19 @@ Media size: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1001,4 +1032,32 @@ Media size: %2 Flags + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index beab8752..f8425e26 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Enregistrer le fichier @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. @@ -32,7 +32,7 @@ - + Failed to restore OLM account. Please login again. @@ -42,7 +42,7 @@ - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File Enregistrer le fichier @@ -126,7 +126,7 @@ ImageItem - + Save image Enregistrer l'image @@ -205,8 +205,8 @@ Membres du salon - - ESC + + OK @@ -278,7 +278,7 @@ RoomInfo - + no version stored @@ -286,12 +286,12 @@ RoomInfoListItem - + Leave room Quitter le salon - + Accept Accepter @@ -332,7 +332,7 @@ StatusIndicator - + Encrypted @@ -355,13 +355,13 @@ TextInputWidget - + Send a file - + Write a message... Écrivez un message... @@ -425,7 +425,12 @@ - + + Mentions + + + + Invite users Inviter des utilisateurs @@ -461,7 +466,7 @@ TypingDisplay - + is typing est en train d'écrire @@ -482,7 +487,7 @@ UserSettingsPage - + Minimize to tray Réduire à la barre des tâches @@ -522,12 +527,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme Thème @@ -567,7 +577,7 @@ GÉNÉRAL - + Open Sessions File @@ -636,6 +646,14 @@ CONNEXION + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -779,7 +797,7 @@ Taille du média : %2 dialogs::ReadReceipts - + Read receipts Accusés de lecture @@ -794,6 +812,19 @@ Taille du média : %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1004,4 +1035,32 @@ Taille du média : %2 Drapeaux + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index 4c81ec76..51ec18fe 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Bestand opslaan @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. @@ -32,7 +32,7 @@ - + Failed to restore OLM account. Please login again. @@ -42,7 +42,7 @@ - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File Bestand opslaan @@ -126,7 +126,7 @@ ImageItem - + Save image Afbeelding opslaan @@ -205,8 +205,8 @@ Kamerleden - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Kamer verlaten - + Accept Accepteren @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted @@ -354,13 +354,13 @@ TextInputWidget - + Send a file - + Write a message... Typ een bericht... @@ -424,7 +424,12 @@ - + + Mentions + + + + Invite users Gebruikers uitnodigen @@ -460,7 +465,7 @@ TypingDisplay - + is typing is aan het typen @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray Minimaliseren naar systeemvak @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme Thema @@ -566,7 +576,7 @@ ALGEMEEN - + Open Sessions File @@ -635,6 +645,14 @@ INLOGGEN + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -778,7 +796,7 @@ Mediagrootte: %2 dialogs::ReadReceipts - + Read receipts Leesbevestigingen @@ -793,6 +811,19 @@ Mediagrootte: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1003,4 +1034,32 @@ Mediagrootte: %2 Vlaggen + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index edea85b9..ca021554 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Zapisz plik @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. Nie udało się wysłać obrazu. Spróbuj ponownie. @@ -32,7 +32,7 @@ Nie udało się wysłać filmu. Spróbuj ponownie. - + Failed to restore OLM account. Please login again. Nie udało się przywrócić konta OLM. Spróbuj zalogować się ponownie. @@ -42,7 +42,7 @@ Nie udało się przywrócić zapisanych danych. Spróbuj zalogować się ponownie. - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File Zapisz plik @@ -126,7 +126,7 @@ ImageItem - + Save image Zapisz obraz @@ -205,8 +205,8 @@ Członkowie pokoju - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Opuść pokój - + Accept Akceptuj @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted Szyfrowana @@ -354,13 +354,13 @@ TextInputWidget - + Send a file Wyślij plik - + Write a message... Napisz wiadomość… @@ -424,7 +424,12 @@ Ustawienia pokoju - + + Mentions + + + + Invite users Zaproś użytkowników @@ -460,7 +465,7 @@ TypingDisplay - + is typing pisze @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray Zminimalizuj do paska zadań @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme Motyw @@ -566,7 +576,7 @@ OGÓLNE - + Open Sessions File @@ -635,6 +645,14 @@ ZALOGUJ SIĘ + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -778,7 +796,7 @@ Rozmiar multimediów: %2 dialogs::ReadReceipts - + Read receipts Potwierdzenia przeczytania @@ -793,6 +811,19 @@ Rozmiar multimediów: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1006,4 +1037,32 @@ Rozmiar multimediów: %2 Flagi + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 4c157884..39cf7b72 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -4,7 +4,7 @@ AudioItem - + Save File Сохранить файл @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. Не удалось загрузить изображение. Пожалуйста, попробуйте еще раз. @@ -32,7 +32,7 @@ Не удалось загрузить видео. Пожалуйста, попробуйте еще раз. - + Failed to restore OLM account. Please login again. Не удалось восстановить учетную запись OLM. Пожалуйста, войдите снова. @@ -42,7 +42,7 @@ Не удалось восстановить сохраненные данные. Пожалуйста, войдите снова. - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. Не удалось настроить ключи шифрования. Ответ сервера:%1 %2. Пожалуйста, попробуйте позже. @@ -118,7 +118,7 @@ FileItem - + Save File Сохранить файл @@ -126,7 +126,7 @@ ImageItem - + Save image Сохранить изображение @@ -205,9 +205,9 @@ Участники комнаты - - ESC - + + OK + @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room Покинуть комнату - + Accept Принять @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted Зашифровано @@ -354,13 +354,13 @@ TextInputWidget - + Send a file Отправить файл - + Write a message... Написать сообщение... @@ -424,7 +424,12 @@ Настройки комнаты - + + Mentions + + + + Invite users Пригласить пользователей @@ -460,7 +465,7 @@ TypingDisplay - + is typing печатает @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray Сворачивать в системную панель @@ -521,12 +526,17 @@ Размер шрифта - + Font Family - + + Emoji Font Famly + + + + Theme Тема @@ -566,7 +576,7 @@ ГЛАВНОЕ - + Open Sessions File Открыть файл сеансов @@ -636,6 +646,14 @@ ВХОД + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -779,7 +797,7 @@ Media size: %2 dialogs::ReadReceipts - + Read receipts Подтверждать прочтение @@ -794,6 +812,19 @@ Media size: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1005,4 +1036,32 @@ Media size: %2 + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index ca7c6e22..08463cd7 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -4,7 +4,7 @@ AudioItem - + Save File 保存文件 @@ -12,7 +12,7 @@ ChatPage - + Failed to upload image. Please try again. 上传图像失败。请重试。 @@ -32,7 +32,7 @@ 上传视频失败。请重试。 - + Failed to restore OLM account. Please login again. 恢复 OLM 账户失败。请重新登录。 @@ -42,7 +42,7 @@ 恢复保存的数据失败。请重新登录。 - + Failed to setup encryption keys. Server response: %1 %2. Please try again later. @@ -118,7 +118,7 @@ FileItem - + Save File 保存文件 @@ -126,7 +126,7 @@ ImageItem - + Save image 保存图像 @@ -205,8 +205,8 @@ 聊天室成员 - - ESC + + OK @@ -277,7 +277,7 @@ RoomInfo - + no version stored @@ -285,12 +285,12 @@ RoomInfoListItem - + Leave room 离开聊天室 - + Accept 接受 @@ -331,7 +331,7 @@ StatusIndicator - + Encrypted 加密的 @@ -354,13 +354,13 @@ TextInputWidget - + Send a file 发送一个文件 - + Write a message... 写一条消息... @@ -424,7 +424,12 @@ 聊天室选项 - + + Mentions + + + + Invite users 邀请用户 @@ -460,7 +465,7 @@ TypingDisplay - + is typing 正在打字 @@ -481,7 +486,7 @@ UserSettingsPage - + Minimize to tray 最小化至托盘 @@ -521,12 +526,17 @@ - + Font Family - + + Emoji Font Famly + + + + Theme 主题 @@ -566,7 +576,7 @@ 通用 - + Open Sessions File 打开会话文件 @@ -635,6 +645,14 @@ 登录 + + descriptiveTime + + + Yesterday + + + dialogs::CreateRoom @@ -778,7 +796,7 @@ Media size: %2 dialogs::ReadReceipts - + Read receipts 阅读回执 @@ -793,6 +811,19 @@ Media size: %2 + + dialogs::ReceiptItem + + + Today %1 + + + + + Yesterday %1 + + + dialogs::RoomSettings @@ -1012,4 +1043,32 @@ Media size: %2 Flags + + utils + + + You + + + + + sent a file. + + + + + sent an image. + + + + + sent an audio file. + + + + + sent a video + + + diff --git a/src/Utils.cpp b/src/Utils.cpp index d6b092b1..a3c15c96 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -99,13 +99,13 @@ utils::descriptiveTime(const QDateTime &then) const auto days = then.daysTo(now); if (days == 0) - return then.toString("HH:mm"); + return then.time().toString(Qt::DefaultLocaleShortDate); else if (days < 2) - return QString("Yesterday"); - else if (days < 365) - return then.toString("dd/MM"); + return QString(QCoreApplication::translate("descriptiveTime", "Yesterday")); + else if (days < 7) + return then.toString("dddd"); - return then.toString("dd/MM/yy"); + return then.date().toString(Qt::DefaultLocaleShortDate); } DescInfo @@ -147,7 +147,7 @@ utils::getMessageDescription(const TimelineEvent &event, DescInfo info; if (sender == localUser) - info.username = "You"; + info.username = QCoreApplication::translate("utils", "You"); else info.username = username; @@ -366,16 +366,16 @@ utils::getQuoteBody(const RelatedInfo &related) return markdownToHtml(related.quoted_body); } case MsgType::File: { - return QString("sent a file."); + return QString(QCoreApplication::translate("utils", "sent a file.")); } case MsgType::Image: { - return QString("sent an image."); + return QString(QCoreApplication::translate("utils", "sent an image.")); } case MsgType::Audio: { - return QString("sent an audio file."); + return QString(QCoreApplication::translate("utils", "sent an audio file.")); } case MsgType::Video: { - return QString("sent a video"); + return QString(QCoreApplication::translate("utils", "sent a video")); } default: { return related.quoted_body; diff --git a/src/dialogs/MemberList.cpp b/src/dialogs/MemberList.cpp index f4167143..3b957c15 100644 --- a/src/dialogs/MemberList.cpp +++ b/src/dialogs/MemberList.cpp @@ -97,7 +97,7 @@ MemberList::MemberList(const QString &room_id, QWidget *parent) topLabel_->setAlignment(Qt::AlignCenter); topLabel_->setFont(font); - auto okBtn = new QPushButton("OK", this); + auto okBtn = new QPushButton(tr("OK"), this); auto buttonLayout = new QHBoxLayout(); buttonLayout->setSpacing(15); @@ -126,7 +126,7 @@ MemberList::MemberList(const QString &room_id, QWidget *parent) qCritical() << e.what(); } - auto closeShortcut = new QShortcut(QKeySequence(tr("ESC")), this); + auto closeShortcut = new QShortcut(QKeySequence("ESC"), this); connect(closeShortcut, &QShortcut::activated, this, &MemberList::close); connect(okBtn, &QPushButton::clicked, this, &MemberList::close); } diff --git a/src/dialogs/ReadReceipts.cpp b/src/dialogs/ReadReceipts.cpp index dc4145db..03ce3068 100644 --- a/src/dialogs/ReadReceipts.cpp +++ b/src/dialogs/ReadReceipts.cpp @@ -78,13 +78,15 @@ ReceiptItem::dateFormat(const QDateTime &then) const auto days = then.daysTo(now); if (days == 0) - return QString("Today %1").arg(then.toString("HH:mm")); + return tr("Today %1").arg(then.time().toString(Qt::DefaultLocaleShortDate)); else if (days < 2) - return QString("Yesterday %1").arg(then.toString("HH:mm")); - else if (days < 365) - return then.toString("dd/MM HH:mm"); + return tr("Yesterday %1").arg(then.time().toString(Qt::DefaultLocaleShortDate)); + else if (days < 7) + return QString("%1 %2") + .arg(then.toString("dddd")) + .arg(then.time().toString(Qt::DefaultLocaleShortDate)); - return then.toString("dd/MM/yy"); + return then.toString(Qt::DefaultLocaleShortDate); } ReadReceipts::ReadReceipts(QWidget *parent) diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index e52dce7b..c0d7f97f 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -951,4 +951,4 @@ TimelineItem::openRawMessageViewer() const "failed to serialize event ({}, {})", room_id, event_id); } }); -} \ No newline at end of file +} diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp index fa575d76..27bc0a5f 100644 --- a/src/ui/InfoMessage.cpp +++ b/src/ui/InfoMessage.cpp @@ -2,6 +2,7 @@ #include "Config.h" #include +#include #include #include #include @@ -61,14 +62,14 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent) { auto now = QDateTime::currentDateTime(); - QString fmt; + QString fmt = QLocale::system().dateFormat(QLocale::LongFormat); - if (now.date().year() != datetime.date().year()) - fmt = QString("ddd d MMMM yy"); - else - fmt = QString("ddd d MMMM"); + if (now.date().year() == datetime.date().year()) { + QRegularExpression rx("[^a-zA-Z]*y+[^a-zA-Z]*"); + fmt = fmt.remove(rx); + } - msg_ = datetime.toString(fmt); + msg_ = datetime.date().toString(fmt); QFontMetrics fm{font()}; #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) -- cgit 1.5.1 From d5bb0936bf8b16dc4a8b505192077576dbe96149 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Sat, 10 Aug 2019 13:14:37 -0400 Subject: Use 'system' theme as default if QT_QPA_PLATFORMTHEME is set On first launch, before the user has configured any settings, check the value of the QT_QPA_PLATFORMTHEME environment var. If it is set, use the system theme as the default instead of the light theme. This fixes #72. --- src/UserSettingsPage.cpp | 4 +++- src/UserSettingsPage.h | 7 ++++++- src/Utils.cpp | 19 +++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 49cb2c1f..30e6ea96 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include "Config.h" @@ -49,7 +51,7 @@ UserSettings::load() isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); - theme_ = settings.value("user/theme", "light").toString(); + theme_ = settings.value("user/theme", defaultTheme_).toString(); font_ = settings.value("user/font_family", "default").toString(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index ffff1e20..dce12315 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -85,7 +85,7 @@ public: save(); } - QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } + QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } @@ -100,6 +100,11 @@ signals: void groupViewStateChanged(bool state); private: + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme_ = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; QString theme_; bool isTrayEnabled_; bool isStartInTrayEnabled_; diff --git a/src/Utils.cpp b/src/Utils.cpp index a3c15c96..5c664b7c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -387,14 +388,20 @@ QString utils::linkColor() { QSettings settings; - const auto theme = settings.value("user/theme", "light").toString(); - - if (theme == "light") + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; + const auto theme = settings.value("user/theme", defaultTheme).toString(); + + if (theme == "light") { return "#0077b5"; - else if (theme == "dark") + } else if (theme == "dark") { return "#38A3D8"; - - return QPalette().color(QPalette::Link).name(); + } else { + return QPalette().color(QPalette::Link).name(); + } } uint32_t -- cgit 1.5.1 From 1659176c0d49c51cb2e20e2a4c1e823ffb2c6446 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 21 Sep 2019 01:38:17 +0200 Subject: escape html before parsing commonmark --- src/Utils.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 5c664b7c..8c02b1c2 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -324,10 +324,25 @@ utils::linkifyMessage(const QString &body) return doc; } +QByteArray escapeRawHtml(const QByteArray &data) { + QByteArray buffer; + const size_t length = data.size(); + buffer.reserve(length); + for(size_t pos = 0; pos != length; ++pos) { + switch(data.at(pos)) { + case '&': buffer.append("&"); break; + case '<': buffer.append("<"); break; + case '>': buffer.append(">"); break; + default: buffer.append(data.at(pos)); break; + } + } + return buffer; +} + QString utils::markdownToHtml(const QString &text) { - const auto str = text.toUtf8(); + const auto str = escapeRawHtml(text.toUtf8()); const char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_DEFAULT); -- cgit 1.5.1 From 8727831de7308ee5cf202c9b20a7bbf916405b2a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 7 Sep 2019 02:01:44 +0200 Subject: Fix QML emojis --- resources/qml/TimelineView.qml | 3 ++- src/Utils.cpp | 5 ++--- src/timeline2/TimelineModel.cpp | 6 ++++++ src/timeline2/TimelineModel.h | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/Utils.cpp') diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index e97b560a..76e728c3 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -173,8 +173,9 @@ Rectangle { Text { id: userName - text: chat.model.displayName(section.split(" ")[0]) + text: chat.model.escapeEmoji(chat.model.displayName(section.split(" ")[0])) color: chat.model.userColor(section.split(" ")[0], colors.window) + textFormat: Text.RichText } } } diff --git a/src/Utils.cpp b/src/Utils.cpp index 8c02b1c2..d458dbcc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -40,9 +40,8 @@ utils::replaceEmoji(const QString &body) for (auto &code : utf32_string) { // TODO: Be more precise here. if (code > 9000) - fmtBody += - QString("") + - QString::fromUcs4(&code, 1) + ""; + fmtBody += QString("") + + QString::fromUcs4(&code, 1) + ""; else fmtBody += QString::fromUcs4(&code, 1); } diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index c1918d20..dff5e56e 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -336,3 +336,9 @@ TimelineModel::formatDateSeparator(QDate date) const return date.toString(fmt); } + +QString +TimelineModel::escapeEmoji(QString str) const +{ + return utils::replaceEmoji(str); +} diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 51cb9be3..e37c6542 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -91,6 +91,7 @@ public: Q_INVOKABLE QColor userColor(QString id, QColor background); Q_INVOKABLE QString displayName(QString id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; + Q_INVOKABLE QString escapeEmoji(QString str) const; void addEvents(const mtx::responses::Timeline &events); -- cgit 1.5.1 From cff46d97a8636f41dd5ac2ace9dc00ecb5f4c51c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 17 Oct 2019 09:36:16 +0200 Subject: Add native themeing to QML (where possible) --- resources/qml/TimelineView.qml | 5 ++-- resources/qml/delegates/TimelineRow.qml | 28 +++++++++++++++------ src/Utils.cpp | 36 +++++++++++++++++---------- src/timeline2/TimelineViewManager.cpp | 44 +++++++++++++++++++++++++++++++++ src/timeline2/TimelineViewManager.h | 1 + 5 files changed, 91 insertions(+), 23 deletions(-) (limited to 'src/Utils.cpp') diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index b0a8853e..d1ada3ea 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -12,8 +12,9 @@ import "./delegates" Rectangle { anchors.fill: parent - SystemPalette { id: colors; colorGroup: SystemPalette.Active } - SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Disabled } + property var colors: currentActivePalette + property var systemInactive: SystemPalette { colorGroup: SystemPalette.Disabled } + property var inactiveColors: currentInactivePalette ? currentInactivePalette : systemInactive property int avatarSize: 32 color: colors.window diff --git a/resources/qml/delegates/TimelineRow.qml b/resources/qml/delegates/TimelineRow.qml index 28a2ec8c..3019deb1 100644 --- a/resources/qml/delegates/TimelineRow.qml +++ b/resources/qml/delegates/TimelineRow.qml @@ -1,5 +1,5 @@ import QtQuick 2.6 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.3 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 import QtQuick.Window 2.2 @@ -48,8 +48,12 @@ RowLayout { id: replyButton flat: true Layout.preferredHeight: 16 - ToolTip.visible: hovered - ToolTip.text: qsTr("Reply") + + ToolTip { + visible: replyButton.hovered + text: qsTr("Reply") + palette: colors + } // disable background, because we don't want a border on hover background: Item { @@ -74,8 +78,12 @@ RowLayout { id: optionsButton flat: true Layout.preferredHeight: 16 - ToolTip.visible: hovered - ToolTip.text: qsTr("Options") + + ToolTip { + visible: optionsButton.hovered + text: qsTr("Options") + palette: colors + } // disable background, because we don't want a border on hover background: Item { @@ -98,6 +106,7 @@ RowLayout { Menu { y: optionsButton.height id: contextMenu + palette: colors MenuItem { text: qsTr("Read receipts") @@ -127,13 +136,16 @@ RowLayout { text: model.timestamp.toLocaleTimeString("HH:mm") color: inactiveColors.text - ToolTip.visible: ma.containsMouse - ToolTip.text: Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleLongDate) - MouseArea{ id: ma anchors.fill: parent hoverEnabled: true } + + ToolTip { + visible: ma.containsMouse + text: Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleLongDate) + palette: colors + } } } diff --git a/src/Utils.cpp b/src/Utils.cpp index d458dbcc..5a1447ac 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -323,19 +323,29 @@ utils::linkifyMessage(const QString &body) return doc; } -QByteArray escapeRawHtml(const QByteArray &data) { - QByteArray buffer; - const size_t length = data.size(); - buffer.reserve(length); - for(size_t pos = 0; pos != length; ++pos) { - switch(data.at(pos)) { - case '&': buffer.append("&"); break; - case '<': buffer.append("<"); break; - case '>': buffer.append(">"); break; - default: buffer.append(data.at(pos)); break; - } - } - return buffer; +QByteArray +escapeRawHtml(const QByteArray &data) +{ + QByteArray buffer; + const size_t length = data.size(); + buffer.reserve(length); + for (size_t pos = 0; pos != length; ++pos) { + switch (data.at(pos)) { + case '&': + buffer.append("&"); + break; + case '<': + buffer.append("<"); + break; + case '>': + buffer.append(">"); + break; + default: + buffer.append(data.at(pos)); + break; + } + } + return buffer; } QString diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp index 13025864..057f03de 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp @@ -3,13 +3,51 @@ #include #include #include +#include #include #include +#include "ChatPage.h" #include "Logging.h" #include "MxcImageProvider.h" +#include "UserSettingsPage.h" #include "dialogs/ImageOverlay.h" +void +TimelineViewManager::updateColorPalette() +{ + UserSettings settings; + if (settings.theme() == "light") { + QPalette lightActive(/*windowText*/ QColor("#333"), + /*button*/ QColor("#333"), + /*light*/ QColor(), + /*dark*/ QColor(220, 220, 220, 120), + /*mid*/ QColor(), + /*text*/ QColor("#333"), + /*bright_text*/ QColor(), + /*base*/ QColor("white"), + /*window*/ QColor("white")); + view->rootContext()->setContextProperty("currentActivePalette", lightActive); + view->rootContext()->setContextProperty("currentInactivePalette", lightActive); + } else if (settings.theme() == "dark") { + QPalette darkActive(/*windowText*/ QColor("#caccd1"), + /*button*/ QColor("#caccd1"), + /*light*/ QColor(), + /*dark*/ QColor(45, 49, 57, 120), + /*mid*/ QColor(), + /*text*/ QColor("#caccd1"), + /*bright_text*/ QColor(), + /*base*/ QColor("#202228"), + /*window*/ QColor("#202228")); + darkActive.setColor(QPalette::Highlight, QColor("#e7e7e9")); + view->rootContext()->setContextProperty("currentActivePalette", darkActive); + view->rootContext()->setContextProperty("currentInactivePalette", darkActive); + } else { + view->rootContext()->setContextProperty("currentActivePalette", QPalette()); + view->rootContext()->setContextProperty("currentInactivePalette", nullptr); + } +} + TimelineViewManager::TimelineViewManager(QWidget *parent) : imgProvider(new MxcImageProvider()) { @@ -23,8 +61,14 @@ TimelineViewManager::TimelineViewManager(QWidget *parent) container = QWidget::createWindowContainer(view, parent); container->setMinimumSize(200, 200); view->rootContext()->setContextProperty("timelineManager", this); + updateColorPalette(); view->engine()->addImageProvider("MxcImage", imgProvider); view->setSource(QUrl("qrc:///qml/TimelineView.qml")); + + connect(dynamic_cast(parent), + &ChatPage::themeChanged, + this, + &TimelineViewManager::updateColorPalette); } void diff --git a/src/timeline2/TimelineViewManager.h b/src/timeline2/TimelineViewManager.h index 6a6d3c6b..b14e78ff 100644 --- a/src/timeline2/TimelineViewManager.h +++ b/src/timeline2/TimelineViewManager.h @@ -71,6 +71,7 @@ public slots: void initWithMessages(const std::map &msgs); void setHistoryView(const QString &room_id); + void updateColorPalette(); void queueTextMessage(const QString &msg); void queueReplyMessage(const QString &reply, const RelatedInfo &related); -- cgit 1.5.1 From 2c37beba8dc5b32e843010ba117abb84951c820b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 2 Nov 2019 18:17:06 +0100 Subject: Fix translation of roomlist message preview This also makes long messages unreadable, because we don't shorten long usernames anymore. We may eventually want to do that again, but it is hard with translations and we probably want to shorten the displayname more, as before this change the message was only ever as long as the timestamp, which is usually just 5 characters... --- src/RoomInfoListItem.cpp | 30 ++------------- src/Utils.cpp | 5 --- src/Utils.h | 99 ++++++++++++++++++++++++++++++------------------ 3 files changed, 67 insertions(+), 67 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index f135451c..8bebb0f5 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -118,7 +118,7 @@ RoomInfoListItem::RoomInfoListItem(QString room_id, RoomInfo info, QWidget *pare // so we can't use them for sorting. if (roomType_ == RoomType::Invited) lastMsgInfo_ = { - emptyEventId, "-", "-", "-", "-", QDateTime::currentDateTime().addYears(10)}; + emptyEventId, "-", "-", "-", QDateTime::currentDateTime().addYears(10)}; } void @@ -210,33 +210,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) p.setFont(QFont{}); p.setPen(subtitlePen); - // The limit is the space between the end of the avatar and the start of the - // timestamp. - int usernameLimit = - std::max(0, width() - 3 * wm.padding - msgStampWidth - wm.iconSize - 20); - auto userName = - metrics.elidedText(lastMsgInfo_.username, Qt::ElideRight, usernameLimit); - - p.setFont(QFont{}); - p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), userName); - -#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) - int nameWidth = QFontMetrics(QFont{}).width(userName); -#else - int nameWidth = QFontMetrics(QFont{}).horizontalAdvance(userName); -#endif - p.setFont(QFont{}); - - // The limit is the space between the end of the username and the start of - // the timestamp. - int descriptionLimit = - std::max(0, - width() - 3 * wm.padding - bottomLineWidthLimit - wm.iconSize - - nameWidth - 5); + int descriptionLimit = std::max( + 0, width() - 3 * wm.padding - bottomLineWidthLimit - wm.iconSize); auto description = metrics.elidedText(lastMsgInfo_.body, Qt::ElideRight, descriptionLimit); - p.drawText(QPoint(2 * wm.padding + wm.iconSize + nameWidth, bottom_y), - description); + p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), description); // We show the last message timestamp. p.save(); diff --git a/src/Utils.cpp b/src/Utils.cpp index 5a1447ac..e27bc995 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -146,11 +146,6 @@ utils::getMessageDescription(const TimelineEvent &event, const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); DescInfo info; - if (sender == localUser) - info.username = QCoreApplication::translate("utils", "You"); - else - info.username = username; - info.userid = sender; info.body = QString(" %1").arg(messageDescription()); info.timestamp = utils::descriptiveTime(ts); diff --git a/src/Utils.h b/src/Utils.h index 225754be..8cb891cc 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -94,38 +94,72 @@ messageDescription(const QString &username = "", using Video = mtx::events::RoomEvent; using Encrypted = mtx::events::EncryptedEvent; - // Sometimes the verb form of sent changes in some languages depending on the actor. - auto remoteSent = QCoreApplication::translate( - "message-description: ", "sent", "For when you are the sender"); - auto localSent = QCoreApplication::translate( - "message-description:", "sent", "For when someone else is the sender"); - QString sentVerb = isLocal ? localSent : remoteSent; if (std::is_same::value || std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 an audio clip") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent an audio clip"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent an audio clip") + .arg(username); } else if (std::is_same::value || std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 an image") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent an image"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent an image") + .arg(username); } else if (std::is_same::value || std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 a file") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a file"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a file") + .arg(username); } else if (std::is_same::value || std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 a video clip") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a video"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a video") + .arg(username); } else if (std::is_same::value || std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 a sticker") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a sticker"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a sticker") + .arg(username); } else if (std::is_same::value) { - return QCoreApplication::translate("message-description sent:", "%1 a notification") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a notification"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a notification") + .arg(username); } else if (std::is_same::value) { - return QString(": %1").arg(body); + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You: %1") + .arg(body); + else + return QCoreApplication::translate("message-description sent:", "%1: %2") + .arg(username) + .arg(body); } else if (std::is_same::value) { return QString("* %1 %2").arg(username).arg(body); } else if (std::is_same::value) { - return QCoreApplication::translate("message-description sent:", - "%1 an encrypted message") - .arg(sentVerb); + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent an encrypted message"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent an encrypted message") + .arg(username); } else { return QCoreApplication::translate("utils", "Unknown Message Type"); } @@ -144,20 +178,13 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin const auto username = Cache::displayName(room_id, sender); const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); - bool isText = std::is_same::value; - bool isEmote = std::is_same::value; - - return DescInfo{ - QString::fromStdString(msg.event_id), - isEmote ? "" - : (sender == localUser ? QCoreApplication::translate("utils", "You") : username), - sender, - (isText || isEmote) - ? messageDescription( - username, QString::fromStdString(msg.content.body).trimmed(), sender == localUser) - : QString(" %1").arg(messageDescription()), - utils::descriptiveTime(ts), - ts}; + return DescInfo{QString::fromStdString(msg.event_id), + sender, + messageDescription(username, + QString::fromStdString(msg.content.body).trimmed(), + sender == localUser), + utils::descriptiveTime(ts), + ts}; } //! Scale down an image to fit to the given width & height limitations. -- cgit 1.5.1 From 1268e9f11c22e8cd22302342e80daef94b15001d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 5 Nov 2019 17:16:04 +0100 Subject: Make replies format nicer Also lays a bit of groundwork for better reply rendering --- resources/qml/TimelineRow.qml | 15 ++++++++++++-- src/Utils.cpp | 5 +---- src/timeline2/TimelineModel.cpp | 44 +++++++++++++++++++++++++++++++---------- src/timeline2/TimelineModel.h | 1 + 4 files changed, 49 insertions(+), 16 deletions(-) (limited to 'src/Utils.cpp') diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index c5c3fde0..8f9090e3 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -14,12 +14,23 @@ RowLayout { anchors.left: parent.left anchors.right: parent.right - implicitHeight: contentItem.childrenRect.height + implicitHeight: contentItem.height - MessageDelegate { + Column { Layout.fillWidth: true Layout.alignment: Qt.AlignTop id: contentItem + + //property var replyTo: model.replyTo + + //Text { + // property int idx: timelineManager.timeline.idToIndex(replyTo) + // text: "" + (idx != -1 ? timelineManager.timeline.data(timelineManager.timeline.index(idx, 0), 2) : "nothing") + //} + MessageDelegate { + width: parent.width + height: childrenRect.height + } } StatusIndicator { diff --git a/src/Utils.cpp b/src/Utils.cpp index e27bc995..8f9e0643 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -366,7 +366,7 @@ utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) { return QString("
In reply " - "to* %4
%4%5
") .arg(related.room, QString::fromStdString(related.related_event), @@ -382,9 +382,6 @@ utils::getQuoteBody(const RelatedInfo &related) using MsgType = mtx::events::MessageType; switch (related.type) { - case MsgType::Text: { - return markdownToHtml(related.quoted_body); - } case MsgType::File: { return QString(QCoreApplication::translate("utils", "sent a file.")); } diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index bdb3ea6f..b2b6f803 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -13,6 +13,8 @@ #include "Utils.h" #include "dialogs/RawMessage.h" +Q_DECLARE_METATYPE(QModelIndex) + namespace { template QString @@ -80,12 +82,6 @@ eventFormattedBody(const mtx::events::RoomEvent &e) { auto temp = e.content.formatted_body; if (!temp.empty()) { - auto pos = temp.find(""); - if (pos != std::string::npos) - temp.erase(pos, std::string("").size()); - pos = temp.find(""); - if (pos != std::string::npos) - temp.erase(pos, std::string("").size()); return QString::fromStdString(temp); } else { return QString::fromStdString(e.content.body).toHtmlEscaped().replace("\n", "
"); @@ -182,6 +178,21 @@ eventMimeType(const mtx::events::RoomEvent &e) return QString::fromStdString(e.content.info.mimetype); } +template +QString +eventRelatesTo(const mtx::events::Event &) +{ + return QString(); +} +template +auto +eventRelatesTo(const mtx::events::RoomEvent &e) -> std::enable_if_t< + std::is_same::value, + QString> +{ + return QString::fromStdString(e.content.relates_to.in_reply_to.event_id); +} + template qml_mtx_events::EventType toRoomEventType(const mtx::events::Event &e) @@ -383,6 +394,7 @@ TimelineModel::roleNames() const {Id, "id"}, {State, "state"}, {IsEncrypted, "isEncrypted"}, + {ReplyTo, "replyTo"}, }; } int @@ -450,8 +462,12 @@ TimelineModel::data(const QModelIndex &index, int role) const return QVariant(utils::replaceEmoji(boost::apply_visitor( [](const auto &e) -> QString { return eventBody(e); }, event))); case FormattedBody: - return QVariant(utils::replaceEmoji(boost::apply_visitor( - [](const auto &e) -> QString { return eventFormattedBody(e); }, event))); + return QVariant( + utils::replaceEmoji( + boost::apply_visitor( + [](const auto &e) -> QString { return eventFormattedBody(e); }, event)) + .remove("") + .remove("")); case Url: return QVariant(boost::apply_visitor( [](const auto &e) -> QString { return eventUrl(e); }, event)); @@ -501,6 +517,11 @@ TimelineModel::data(const QModelIndex &index, int role) const return boost::get>( &tempEvent) != nullptr; } + case ReplyTo: { + QString evId = boost::apply_visitor( + [](const auto &e) -> QString { return eventRelatesTo(e); }, event); + return QVariant(evId); + } default: return QVariant(); } @@ -825,8 +846,11 @@ TimelineModel::replyAction(QString id) event); related.type = mtx::events::getMessageType(boost::apply_visitor( [](const auto &e) -> std::string { return eventMsgType(e); }, event)); - related.quoted_body = - boost::apply_visitor([](const auto &e) -> QString { return eventBody(e); }, event); + related.quoted_body = boost::apply_visitor( + [](const auto &e) -> QString { return eventFormattedBody(e); }, event); + related.quoted_body.remove(QRegularExpression( + ".*", QRegularExpression::DotMatchesEverythingOption)); + nhlog::ui()->debug("after replacement: {}", related.quoted_body.toStdString()); related.room = room_id_; if (related.quoted_body.isEmpty()) diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 1ed6e72c..31e41315 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -139,6 +139,7 @@ public: Id, State, IsEncrypted, + ReplyTo, }; QHash roleNames() const override; -- cgit 1.5.1 From 659e36b113158ba9870e201dab7098888bf9d275 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 14 Dec 2019 17:08:36 +0100 Subject: Update to c++17 --- .ci/install.sh | 33 +------- .ci/linux/deploy.sh | 2 +- .ci/script.sh | 8 -- .travis.yml | 105 ++++++++++++++++------- CMakeLists.txt | 13 ++- deps/CMakeLists.txt | 4 +- deps/cmake/Json.cmake | 2 +- src/Cache.cpp | 30 ++++--- src/Cache.h | 85 ++++++++++--------- src/ChatPage.cpp | 10 +-- src/ChatPage.h | 12 +-- src/Olm.cpp | 7 +- src/Utils.cpp | 67 +++++++-------- src/Utils.h | 17 ++-- src/timeline/TimelineModel.cpp | 157 +++++++++++++++++------------------ src/timeline/TimelineViewManager.cpp | 8 +- src/timeline/TimelineViewManager.h | 8 +- 17 files changed, 284 insertions(+), 284 deletions(-) (limited to 'src/Utils.cpp') diff --git a/.ci/install.sh b/.ci/install.sh index 57e73e03..776d4d23 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -3,14 +3,6 @@ set -ex if [ "$TRAVIS_OS_NAME" = "osx" ]; then - brew update - - # uninstall packages, that would get upgraded by upgrading cmake (and we don't need) - brew uninstall --force cgal node sfcgal postgis - - brew install qt5 lmdb clang-format ninja libsodium cmark - brew upgrade boost cmake icu4c || true - brew tap nlohmann/json brew install --with-cmake nlohmann_json @@ -25,11 +17,11 @@ fi if [ "$TRAVIS_OS_NAME" = "linux" ]; then + sudo update-alternatives --install /usr/bin/gcc gcc "/usr/bin/${CC}" 10 + sudo update-alternatives --install /usr/bin/g++ g++ "/usr/bin/${CXX}" 10 - if [ -z "$QT_VERSION" ]; then - QT_VERSION="592" - QT_PKG="59" - fi + sudo update-alternatives --set gcc "/usr/bin/${CC}" + sudo update-alternatives --set g++ "/usr/bin/${CXX}" wget https://cmake.org/files/v3.15/cmake-3.15.5-Linux-x86_64.sh sudo sh cmake-3.15.5-Linux-x86_64.sh --skip-license --prefix=/usr/local @@ -40,21 +32,4 @@ if [ "$TRAVIS_OS_NAME" = "linux" ]; then tar xfz libsodium-1.0.17.tar.gz cd libsodium-1.0.17/ ./configure && make && sudo make install ) - - sudo add-apt-repository -y ppa:beineri/opt-qt${QT_VERSION}-trusty - # needed for git-lfs, otherwise the follow apt update fails. - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 6B05F25D762E3157 - - # needed for mongodb repository: https://github.com/travis-ci/travis-ci/issues/9037 - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 - - sudo apt update -qq - sudo apt install -qq -y \ - qt${QT_PKG}base \ - qt${QT_PKG}tools \ - qt${QT_PKG}svg \ - qt${QT_PKG}multimedia \ - qt${QT_PKG}quickcontrols2 \ - qt${QT_PKG}graphicaleffects \ - liblmdb-dev fi diff --git a/.ci/linux/deploy.sh b/.ci/linux/deploy.sh index 524d72d5..ff8ef6ca 100755 --- a/.ci/linux/deploy.sh +++ b/.ci/linux/deploy.sh @@ -36,7 +36,7 @@ unset LD_LIBRARY_PATH ARCH=$(uname -m) export ARCH -LD_LIBRARY_PATH=$(pwd)/.deps/usr/lib/:$LD_LIBRARY_PATH +LD_LIBRARY_PATH=$(pwd)/.deps/usr/lib/:/usr/local/lib/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH for res in ./linuxdeployqt*.AppImage diff --git a/.ci/script.sh b/.ci/script.sh index 06536278..7e9a8d81 100755 --- a/.ci/script.sh +++ b/.ci/script.sh @@ -3,17 +3,9 @@ set -ex if [ "$TRAVIS_OS_NAME" = "linux" ]; then - export CC=${C_COMPILER} - export CXX=${CXX_COMPILER} # make build use all available cores export CMAKE_BUILD_PARALLEL_LEVEL=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l) - sudo update-alternatives --install /usr/bin/gcc gcc "/usr/bin/${C_COMPILER}" 10 - sudo update-alternatives --install /usr/bin/g++ g++ "/usr/bin/${CXX_COMPILER}" 10 - - sudo update-alternatives --set gcc "/usr/bin/${C_COMPILER}" - sudo update-alternatives --set g++ "/usr/bin/${CXX_COMPILER}" - export PATH="/usr/local/bin/:${PATH}" cmake --version fi diff --git a/.travis.yml b/.travis.yml index 3abb8bfd..1e2bc5b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: cpp sudo: required -dist: trusty +dist: xenial notifications: webhooks: @@ -19,61 +19,108 @@ matrix: include: - os: osx compiler: clang - # Use the default osx image, because that one is actually tested to work with homebrew and probably the oldest supported version - # osx_image: xcode9 + # C++17 support + osx_image: xcode10.2 env: - - DEPLOYMENT=1 - - USE_BUNDLED_BOOST=0 - - USE_BUNDLED_CMARK=0 - - USE_BUNDLED_JSON=0 - - MTX_STATIC=1 + - DEPLOYMENT=1 + - USE_BUNDLED_BOOST=0 + - USE_BUNDLED_CMARK=0 + - USE_BUNDLED_JSON=0 + - MTX_STATIC=1 + addons: + homebrew: + taps: nlohmann/json + packages: + - boost + - clang-format + - cmake + - cmark + - icu4c + - libsodium + - lmdb + - ninja + - openssl + - qt5 - os: linux - compiler: gcc + compiler: gcc-7 env: - - CXX_COMPILER=g++-5 - - C_COMPILER=gcc-5 - - QT_VERSION="-5.10.1" - - QT_PKG=510 + - CXX=g++-7 + - CC=gcc-7 + - QT_PKG=512 - DEPLOYMENT=1 - USE_BUNDLED_BOOST=1 - USE_BUNDLED_CMARK=1 - USE_BUNDLED_JSON=1 addons: apt: - sources: ["ubuntu-toolchain-r-test"] - packages: ["g++-5", "ninja-build"] + sources: + - ubuntu-toolchain-r-test + - sourceline: 'ppa:beineri/opt-qt-5.12.6-xenial' + packages: + - g++-7 + - ninja-build + - qt512base + - qt512tools + - qt512svg + - qt512multimedia + - qt512quickcontrols2 + - qt512graphicaleffects + - liblmdb-dev + - libgl1-mesa-dev # needed for missing gl.h - os: linux - compiler: gcc + compiler: gcc-8 env: - - CXX_COMPILER=g++-8 - - C_COMPILER=gcc-8 - - QT_VERSION=592 + - CXX=g++-8 + - CC=gcc-8 - QT_PKG=59 - USE_BUNDLED_BOOST=1 - USE_BUNDLED_CMARK=1 - USE_BUNDLED_JSON=1 addons: apt: - sources: ["ubuntu-toolchain-r-test"] - packages: ["g++-8", "ninja-build"] + sources: + - ubuntu-toolchain-r-test + - sourceline: 'ppa:beineri/opt-qt597-xenial' + packages: + - g++-8 + - ninja-build + - qt59base + - qt59tools + - qt59svg + - qt59multimedia + - qt59quickcontrols2 + - qt59graphicaleffects + - liblmdb-dev + - libgl1-mesa-dev # needed for missing gl.h - os: linux - compiler: clang + compiler: clang-6 env: - - CXX_COMPILER=clang++-5.0 - - C_COMPILER=clang-5.0 - - QT_VERSION=592 + - CXX=clang++-6.0 + - CC=clang-6.0 - QT_PKG=59 - USE_BUNDLED_BOOST=1 - USE_BUNDLED_CMARK=1 - USE_BUNDLED_JSON=1 addons: apt: - sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-trusty-5.0"] - packages: ["clang-5.0", "g++-7", "ninja-build"] + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-xenial-6.0 + - sourceline: 'ppa:beineri/opt-qt597-xenial' + packages: + - clang++-6.0 + - g++-7 + - ninja-build + - qt59base + - qt59tools + - qt59svg + - qt59multimedia + - qt59quickcontrols2 + - qt59graphicaleffects + - liblmdb-dev + - libgl1-mesa-dev # needed for missing gl.h before_install: - - export CXX=${CXX_COMPILER} - - export CC=${C_COMPILER} # Use TRAVIS_TAG if defined, or the short commit SHA otherwise - export VERSION=${TRAVIS_TAG:-$(git rev-parse --short HEAD)} install: diff --git a/CMakeLists.txt b/CMakeLists.txt index 67a1dfb0..39dadc64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,6 @@ option(ASAN "Compile with address sanitizers" OFF) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -add_definitions(-DBOOST_MPL_LIMIT_LIST_SIZE=30) -add_definitions(-DBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) - include(GNUInstallDirs) # Include Qt basic functions @@ -15,8 +12,8 @@ include(QtCommon) project(nheko LANGUAGES C CXX) set(CPACK_PACKAGE_VERSION_MAJOR "0") -set(CPACK_PACKAGE_VERSION_MINOR "6") -set(CPACK_PACKAGE_VERSION_PATCH "4") +set(CPACK_PACKAGE_VERSION_MINOR "7") +set(CPACK_PACKAGE_VERSION_PATCH "0") set(PROJECT_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) set(PROJECT_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) set(PROJECT_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}) @@ -27,7 +24,7 @@ fix_project_version() # Set additional project information set(COMPANY "Nheko") -set(COPYRIGHT "Copyright (c) 2018 Nheko Contributors") +set(COPYRIGHT "Copyright (c) 2019 Nheko Contributors") set(IDENTIFIER "com.github.mujx.nheko") add_project_meta(META_FILES_TO_INCLUDE) @@ -91,7 +88,7 @@ if (NOT MSVC) set(CMAKE_C_COMPILER gcc) endif(NOT MSVC) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) if(NOT MSVC) @@ -106,7 +103,7 @@ if(NOT MSVC) -fsized-deallocation \ -fdiagnostics-color=always \ -Wunreachable-code \ - -std=c++14" + -std=c++17" ) if (NOT CMAKE_COMPILER_IS_GNUCXX) # -Wshadow is buggy and broken in GCC, so do not enable it. diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index fbe9275f..cf42b7b5 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -46,10 +46,10 @@ set(BOOST_SHA256 set( MTXCLIENT_URL - https://github.com/Nheko-Reborn/mtxclient/archive/1945952864ef87a6afeb57b0beb80756d0647381.zip + https://github.com/Nheko-Reborn/mtxclient/archive/fd5208d85ecc9e077fe0fde5424ba225849cccf7.zip ) set(MTXCLIENT_HASH - 727cd145c0c1e9c168aaeded3b7cc9801c63b4da5e8cd0a4782982d08770816e) + 24ef9d5562ed6d83d6c28f6c8de559487029f3bdc35d9fe8e5799283ff999513) set( TWEENY_URL https://github.com/mobius3/tweeny/archive/b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf.tar.gz diff --git a/deps/cmake/Json.cmake b/deps/cmake/Json.cmake index 3b63550e..c5e66cea 100644 --- a/deps/cmake/Json.cmake +++ b/deps/cmake/Json.cmake @@ -13,7 +13,7 @@ ExternalProject_Add( -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} BUILD_COMMAND ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR}/json - INSTALL_COMMAND make install + INSTALL_COMMAND ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR}/json --target install ) list(APPEND THIRD_PARTY_DEPS Json) diff --git a/src/Cache.cpp b/src/Cache.cpp index 083dbe89..d3aec9db 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -26,7 +27,6 @@ #include #include -#include #include #include "Cache.h" @@ -395,7 +395,7 @@ Cache::saveOlmSession(const std::string &curve25519, mtx::crypto::OlmSessionPtr txn.commit(); } -boost::optional +std::optional Cache::getOlmSession(const std::string &curve25519, const std::string &session_id) { using namespace mtx::crypto; @@ -413,7 +413,7 @@ Cache::getOlmSession(const std::string &curve25519, const std::string &session_i return unpickle(data, SECRET); } - return boost::none; + return std::nullopt; } std::vector @@ -967,8 +967,8 @@ Cache::saveState(const mtx::responses::Sync &res) bool has_new_tags = false; for (const auto &evt : room.second.account_data.events) { // for now only fetch tag events - if (evt.type() == typeid(Event)) { - auto tags_evt = boost::get>(evt); + if (std::holds_alternative>(evt)) { + auto tags_evt = std::get>(evt); has_new_tags = true; for (const auto &tag : tags_evt.content.tags) { updatedInfo.tags.push_back(tag.first); @@ -1049,19 +1049,17 @@ Cache::saveInvite(lmdb::txn &txn, using namespace mtx::events::state; for (const auto &e : room.invite_state) { - if (boost::get>(&e) != nullptr) { - auto msg = boost::get>(e); + if (auto msg = std::get_if>(&e)) { + auto display_name = msg->content.display_name.empty() + ? msg->state_key + : msg->content.display_name; - auto display_name = msg.content.display_name.empty() - ? msg.state_key - : msg.content.display_name; - - MemberInfo tmp{display_name, msg.content.avatar_url}; + MemberInfo tmp{display_name, msg->content.avatar_url}; lmdb::dbi_put( - txn, membersdb, lmdb::val(msg.state_key), lmdb::val(json(tmp).dump())); + txn, membersdb, lmdb::val(msg->state_key), lmdb::val(json(tmp).dump())); } else { - boost::apply_visitor( + std::visit( [&txn, &statesdb](auto msg) { bool res = lmdb::dbi_put(txn, statesdb, @@ -1122,7 +1120,7 @@ Cache::roomsWithTagUpdates(const mtx::responses::Sync &res) for (const auto &room : res.rooms.join) { bool hasUpdates = false; for (const auto &evt : room.second.account_data.events) { - if (evt.type() == typeid(Event)) { + if (std::holds_alternative>(evt)) { hasUpdates = true; } } @@ -1940,7 +1938,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn, if (isStateEvent(e)) continue; - if (boost::get>(&e) != nullptr) + if (std::holds_alternative>(e)) continue; json obj = json::object(); diff --git a/src/Cache.h b/src/Cache.h index f5e1cfa0..878ac9ce 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -17,7 +17,8 @@ #pragma once -#include +#include +#include #include #include @@ -25,11 +26,11 @@ #include #include +#include + #include #include #include -#include -#include #include "Logging.h" #include "MatrixClient.h" @@ -453,8 +454,8 @@ public: // void saveOlmSession(const std::string &curve25519, mtx::crypto::OlmSessionPtr session); std::vector getOlmSessions(const std::string &curve25519); - boost::optional getOlmSession(const std::string &curve25519, - const std::string &session_id); + std::optional getOlmSession(const std::string &curve25519, + const std::string &session_id); void saveOlmAccount(const std::string &pickled); std::string restoreOlmAccount(); @@ -517,52 +518,50 @@ private: using namespace mtx::events; using namespace mtx::events::state; - if (boost::get>(&event) != nullptr) { - const auto e = boost::get>(event); - - switch (e.content.membership) { + if (auto e = std::get_if>(&event); e != nullptr) { + switch (e->content.membership) { // // We only keep users with invite or join membership. // case Membership::Invite: case Membership::Join: { - auto display_name = e.content.display_name.empty() - ? e.state_key - : e.content.display_name; + auto display_name = e->content.display_name.empty() + ? e->state_key + : e->content.display_name; // Lightweight representation of a member. - MemberInfo tmp{display_name, e.content.avatar_url}; + MemberInfo tmp{display_name, e->content.avatar_url}; lmdb::dbi_put(txn, membersdb, - lmdb::val(e.state_key), + lmdb::val(e->state_key), lmdb::val(json(tmp).dump())); insertDisplayName(QString::fromStdString(room_id), - QString::fromStdString(e.state_key), + QString::fromStdString(e->state_key), QString::fromStdString(display_name)); insertAvatarUrl(QString::fromStdString(room_id), - QString::fromStdString(e.state_key), - QString::fromStdString(e.content.avatar_url)); + QString::fromStdString(e->state_key), + QString::fromStdString(e->content.avatar_url)); break; } default: { lmdb::dbi_del( - txn, membersdb, lmdb::val(e.state_key), lmdb::val("")); + txn, membersdb, lmdb::val(e->state_key), lmdb::val("")); removeDisplayName(QString::fromStdString(room_id), - QString::fromStdString(e.state_key)); + QString::fromStdString(e->state_key)); removeAvatarUrl(QString::fromStdString(room_id), - QString::fromStdString(e.state_key)); + QString::fromStdString(e->state_key)); break; } } return; - } else if (boost::get>(&event) != nullptr) { + } else if (std::holds_alternative>(event)) { setEncryptedRoom(txn, room_id); return; } @@ -570,7 +569,7 @@ private: if (!isStateEvent(event)) return; - boost::apply_visitor( + std::visit( [&txn, &statesdb](auto e) { lmdb::dbi_put( txn, statesdb, lmdb::val(to_string(e.type)), lmdb::val(json(e).dump())); @@ -584,17 +583,17 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr; + return std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e); } template @@ -603,11 +602,11 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr; + return std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e); } bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e) @@ -615,11 +614,11 @@ private: using namespace mtx::events; using namespace mtx::events::state; - return boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr || - boost::get>(&e) != nullptr; + return std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e) || + std::holds_alternative>(e); } void saveInvites(lmdb::txn &txn, diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 35d262ac..c496acab 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -54,7 +54,7 @@ constexpr int CHECK_CONNECTIVITY_INTERVAL = 15'000; constexpr int RETRY_TIMEOUT = 5'000; constexpr size_t MAX_ONETIME_KEYS = 50; -Q_DECLARE_METATYPE(boost::optional) +Q_DECLARE_METATYPE(std::optional) ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) : QWidget(parent) @@ -64,8 +64,8 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) { setObjectName("chatPage"); - qRegisterMetaType>( - "boost::optional"); + qRegisterMetaType>( + "std::optional"); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); @@ -318,7 +318,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) auto bin = dev->peek(dev->size()); auto payload = std::string(bin.data(), bin.size()); - boost::optional encryptedFile; + std::optional encryptedFile; if (cache::client()->isRoomEncrypted(current_room_.toStdString())) { mtx::crypto::BinaryBuf buf; std::tie(buf, encryptedFile) = mtx::crypto::encrypt_file(payload); @@ -371,7 +371,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) this, [this](QString roomid, QString filename, - boost::optional encryptedFile, + std::optional encryptedFile, QString url, QString mimeClass, QString mime, diff --git a/src/ChatPage.h b/src/ChatPage.h index 20e156af..6ca30b3d 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -18,8 +18,9 @@ #pragma once #include -#include -#include +#include +#include + #include #include @@ -98,7 +99,7 @@ signals: void uploadFailed(const QString &msg); void mediaUploaded(const QString &roomid, const QString &filename, - const boost::optional &file, + const std::optional &file, const QString &url, const QString &mimeClass, const QString &mime, @@ -252,9 +253,8 @@ ChatPage::getMemberships(const std::vector &collection) const using Member = mtx::events::StateEvent; for (const auto &event : collection) { - if (boost::get(event) != nullptr) { - auto member = boost::get(event); - memberships.emplace(member.state_key, member); + if (auto member = std::get_if(event)) { + memberships.emplace(member->state_key, *member); } } diff --git a/src/Olm.cpp b/src/Olm.cpp index c1598570..9c1a25df 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -1,4 +1,4 @@ -#include +#include #include "Olm.h" @@ -289,14 +289,13 @@ request_keys(const std::string &room_id, const std::string &event_id) return; } - if (boost::get>(&res) == nullptr) { + if (!std::holds_alternative>(res)) { nhlog::net()->info( "retrieved event is not encrypted: {} from {}", event_id, room_id); return; } - olm::send_key_request_for(room_id, - boost::get>(res)); + olm::send_key_request_for(room_id, std::get>(res)); }); } diff --git a/src/Utils.cpp b/src/Utils.cpp index 8f9e0643..3d69162f 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -9,9 +9,10 @@ #include #include #include + #include +#include -#include #include #include "Config.h" @@ -122,34 +123,33 @@ utils::getMessageDescription(const TimelineEvent &event, using Video = mtx::events::RoomEvent; using Encrypted = mtx::events::EncryptedEvent; - if (boost::get