diff --git a/src/dialogs/PreviewUploadOverlay.cc b/src/dialogs/PreviewUploadOverlay.cc
index 3c44e911..e01d2b17 100644
--- a/src/dialogs/PreviewUploadOverlay.cc
+++ b/src/dialogs/PreviewUploadOverlay.cc
@@ -17,7 +17,6 @@
#include <QApplication>
#include <QBuffer>
-#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QHBoxLayout>
@@ -25,14 +24,15 @@
#include <QVBoxLayout>
#include "Config.h"
+#include "Logging.hpp"
#include "Utils.h"
#include "dialogs/PreviewUploadOverlay.h"
using namespace dialogs;
-static constexpr const char *DEFAULT = "Upload %1?";
-static constexpr const char *ERROR = "Failed to load image type '%1'. Continue upload?";
+constexpr const char *DEFAULT = "Upload %1?";
+constexpr const char *ERR_MSG = "Failed to load image type '%1'. Continue upload?";
PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent)
: QWidget{parent}
@@ -105,7 +105,7 @@ PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64
{
if (mediaType_ == "image") {
if (!image_.loadFromData(data_)) {
- titleLabel_.setText(QString{tr(ERROR)}.arg(type));
+ titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type));
} else {
titleLabel_.setText(QString{tr(DEFAULT)}.arg(mediaType_));
}
@@ -142,8 +142,9 @@ PreviewUploadOverlay::setPreview(const QString &path)
QFile file{path};
if (!file.open(QIODevice::ReadOnly)) {
- qWarning() << "Failed to open file from:" << path;
- qWarning() << "Reason:" << file.errorString();
+ nhlog::ui()->warn("Failed to open file ({}): {}",
+ path.toStdString(),
+ file.errorString().toStdString());
close();
return;
}
@@ -152,7 +153,7 @@ PreviewUploadOverlay::setPreview(const QString &path)
auto mime = db.mimeTypeForFileNameAndData(path, &file);
if ((data_ = file.readAll()).isEmpty()) {
- qWarning() << "Failed to read media:" << file.errorString();
+ nhlog::ui()->warn("Failed to read media: {}", file.errorString().toStdString());
close();
return;
}
diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp
index ba487cea..6b1143b5 100644
--- a/src/dialogs/ReCaptcha.cpp
+++ b/src/dialogs/ReCaptcha.cpp
@@ -6,6 +6,7 @@
#include "Config.h"
#include "FlatButton.h"
+#include "MatrixClient.h"
#include "RaisedButton.h"
#include "Theme.h"
@@ -13,7 +14,7 @@
using namespace dialogs;
-ReCaptcha::ReCaptcha(const QString &server, const QString &session, QWidget *parent)
+ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
: QWidget(parent)
{
setAutoFillBackground(true);
@@ -51,12 +52,12 @@ ReCaptcha::ReCaptcha(const QString &server, const QString &session, QWidget *par
layout->addWidget(label);
layout->addLayout(buttonLayout);
- connect(openCaptchaBtn_, &QPushButton::clicked, [server, session]() {
- const auto url =
- QString(
- "https://%1/_matrix/client/r0/auth/m.login.recaptcha/fallback/web?session=%2")
- .arg(server)
- .arg(session);
+ connect(openCaptchaBtn_, &QPushButton::clicked, [session]() {
+ const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/"
+ "fallback/web?session=%3")
+ .arg(QString::fromStdString(http::v2::client()->server()))
+ .arg(http::v2::client()->port())
+ .arg(session);
QDesktopServices::openUrl(url);
});
diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp
index 4d2f304b..74d08478 100644
--- a/src/dialogs/RoomSettings.cpp
+++ b/src/dialogs/RoomSettings.cpp
@@ -1,16 +1,20 @@
#include "Avatar.h"
+#include "ChatPage.h"
#include "Config.h"
#include "FlatButton.h"
+#include "Logging.hpp"
#include "MatrixClient.h"
#include "Painter.h"
#include "TextField.h"
#include "Theme.h"
#include "Utils.h"
#include "dialogs/RoomSettings.hpp"
+#include "ui/ToggleButton.h"
#include <QApplication>
#include <QComboBox>
#include <QLabel>
+#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
#include <QSettings>
@@ -67,6 +71,20 @@ EditModal::EditModal(const QString &roomId, QWidget *parent)
labelLayout->addWidget(errorField_);
layout->addLayout(labelLayout);
+ connect(this, &EditModal::stateEventErrorCb, this, [this](const QString &msg) {
+ errorField_->setText(msg);
+ errorField_->show();
+ });
+ connect(this, &EditModal::nameEventSentCb, this, [this](const QString &newName) {
+ errorField_->hide();
+ emit nameChanged(newName);
+ close();
+ });
+ connect(this, &EditModal::topicEventSentCb, this, [this]() {
+ errorField_->hide();
+ close();
+ });
+
connect(applyBtn_, &QPushButton::clicked, [this]() {
// Check if the values are changed from the originals.
auto newName = nameInput_->text().trimmed();
@@ -85,53 +103,37 @@ EditModal::EditModal(const QString &roomId, QWidget *parent)
state::Name body;
body.name = newName.toStdString();
- auto proxy =
- http::client()->sendStateEvent<state::Name, EventType::RoomName>(body,
- roomId_);
- connect(proxy.get(),
- &StateEventProxy::stateEventSent,
- this,
- [this, proxy, newName]() {
- Q_UNUSED(proxy);
- errorField_->hide();
- emit nameChanged(newName);
- close();
- });
+ http::v2::client()->send_state_event<state::Name, EventType::RoomName>(
+ roomId_.toStdString(),
+ body,
+ [this, newName](const mtx::responses::EventId &,
+ mtx::http::RequestErr err) {
+ if (err) {
+ emit stateEventErrorCb(
+ QString::fromStdString(err->matrix_error.error));
+ return;
+ }
- connect(proxy.get(),
- &StateEventProxy::stateEventError,
- this,
- [this, proxy, newName](const QString &msg) {
- Q_UNUSED(proxy);
- errorField_->setText(msg);
- errorField_->show();
- });
+ emit nameEventSentCb(newName);
+ });
}
if (newTopic != initialTopic_ && !newTopic.isEmpty()) {
state::Topic body;
body.topic = newTopic.toStdString();
- auto proxy =
- http::client()->sendStateEvent<state::Topic, EventType::RoomTopic>(
- body, roomId_);
- connect(proxy.get(),
- &StateEventProxy::stateEventSent,
- this,
- [this, proxy, newTopic]() {
- Q_UNUSED(proxy);
- errorField_->hide();
- close();
- });
+ http::v2::client()->send_state_event<state::Topic, EventType::RoomTopic>(
+ roomId_.toStdString(),
+ body,
+ [this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
+ if (err) {
+ emit stateEventErrorCb(
+ QString::fromStdString(err->matrix_error.error));
+ return;
+ }
- connect(proxy.get(),
- &StateEventProxy::stateEventError,
- this,
- [this, proxy, newTopic](const QString &msg) {
- Q_UNUSED(proxy);
- errorField_->setText(msg);
- errorField_->show();
- });
+ emit topicEventSentCb();
+ });
}
});
connect(cancelBtn_, &QPushButton::clicked, this, &EditModal::close);
@@ -190,8 +192,8 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
layout->setSpacing(15);
layout->setMargin(20);
- saveBtn_ = new FlatButton("SAVE", this);
- saveBtn_->setFontSize(conf::btn::fontSize);
+ okBtn_ = new FlatButton(tr("OK"), this);
+ okBtn_->setFontSize(conf::btn::fontSize);
cancelBtn_ = new FlatButton(tr("CANCEL"), this);
cancelBtn_->setFontSize(conf::btn::fontSize);
@@ -199,7 +201,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
btnLayout->setSpacing(0);
btnLayout->setMargin(0);
btnLayout->addStretch(1);
- btnLayout->addWidget(saveBtn_);
+ btnLayout->addWidget(okBtn_);
btnLayout->addWidget(cancelBtn_);
auto notifOptionLayout_ = new QHBoxLayout;
@@ -238,6 +240,61 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
accessOptionLayout->addWidget(accessLabel);
accessOptionLayout->addWidget(accessCombo);
+ auto encryptionOptionLayout = new QHBoxLayout;
+ encryptionOptionLayout->setMargin(SettingsMargin);
+ auto encryptionLabel = new QLabel(tr("Encryption"), this);
+ encryptionLabel->setStyleSheet("font-size: 15px;");
+ encryptionToggle_ = new Toggle(this);
+ connect(encryptionToggle_, &Toggle::toggled, this, [this](bool isOn) {
+ if (isOn)
+ return;
+
+ QFont font;
+ font.setPixelSize(conf::fontSize);
+
+ QMessageBox msgBox;
+ msgBox.setIcon(QMessageBox::Question);
+ msgBox.setFont(font);
+ msgBox.setWindowTitle(tr("End-to-End Encryption"));
+ msgBox.setText(tr(
+ "Encryption is currently experimental and things might break unexpectedly. <br>"
+ "Please take note that it can't be disabled afterwards."));
+ msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ msgBox.setDefaultButton(QMessageBox::Save);
+ int ret = msgBox.exec();
+
+ switch (ret) {
+ case QMessageBox::Ok: {
+ encryptionToggle_->setState(false);
+ encryptionToggle_->setEnabled(false);
+ enableEncryption();
+ break;
+ }
+ default: {
+ encryptionToggle_->setState(true);
+ encryptionToggle_->setEnabled(true);
+ break;
+ }
+ }
+ });
+
+ encryptionOptionLayout->addWidget(encryptionLabel);
+ encryptionOptionLayout->addWidget(encryptionToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
+
+ // Disable encryption button.
+ if (usesEncryption_) {
+ encryptionToggle_->setState(false);
+ encryptionToggle_->setEnabled(false);
+ } else {
+ encryptionToggle_->setState(true);
+ }
+
+ // Hide encryption option for public rooms.
+ if (!usesEncryption_ && (info_.join_rule == JoinRule::Public)) {
+ encryptionToggle_->hide();
+ encryptionLabel->hide();
+ }
+
QFont font;
font.setPixelSize(18);
font.setWeight(70);
@@ -257,10 +314,18 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
layout->addLayout(editLayout_);
layout->addLayout(notifOptionLayout_);
layout->addLayout(accessOptionLayout);
+ layout->addLayout(encryptionOptionLayout);
layout->addLayout(btnLayout);
connect(cancelBtn_, &QPushButton::clicked, this, &RoomSettings::closing);
- connect(saveBtn_, &QPushButton::clicked, this, &RoomSettings::saveSettings);
+ connect(okBtn_, &QPushButton::clicked, this, &RoomSettings::saveSettings);
+
+ connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) {
+ encryptionToggle_->setState(true);
+ encryptionToggle_->setEnabled(true);
+
+ emit ChatPage::instance()->showNotification(msg);
+ });
}
void
@@ -273,7 +338,7 @@ RoomSettings::setupEditButton()
hasEditRights_ = cache::client()->hasEnoughPowerLevel(
{EventType::RoomName, EventType::RoomTopic}, room_id_.toStdString(), userId);
} catch (const lmdb::error &e) {
- qWarning() << "lmdb error" << e.what();
+ nhlog::db()->warn("lmdb error: {}", e.what());
}
constexpr int buttonSize = 36;
@@ -310,10 +375,12 @@ void
RoomSettings::retrieveRoomInfo()
{
try {
- info_ = cache::client()->singleRoomInfo(room_id_.toStdString());
+ usesEncryption_ = cache::client()->isRoomEncrypted(room_id_.toStdString());
+ info_ = cache::client()->singleRoomInfo(room_id_.toStdString());
setAvatar(QImage::fromData(cache::client()->image(info_.avatar_url)));
} catch (const lmdb::error &e) {
- qWarning() << "failed to retrieve room info from cache" << room_id_;
+ nhlog::db()->warn("failed to retrieve room info from cache: {}",
+ room_id_.toStdString());
}
}
@@ -342,6 +409,28 @@ RoomSettings::saveSettings()
}
void
+RoomSettings::enableEncryption()
+{
+ const auto room_id = room_id_.toStdString();
+ http::v2::client()->enable_encryption(
+ room_id, [room_id, this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
+ if (err) {
+ int status_code = static_cast<int>(err->status_code);
+ nhlog::net()->warn("failed to enable encryption in room ({}): {} {}",
+ room_id,
+ err->matrix_error.error,
+ status_code);
+ emit enableEncryptionError(
+ tr("Failed to enable encryption: %1")
+ .arg(QString::fromStdString(err->matrix_error.error)));
+ return;
+ }
+
+ nhlog::net()->info("enabled encryption on room ({})", room_id);
+ });
+}
+
+void
RoomSettings::paintEvent(QPaintEvent *)
{
QStyleOption opt;
|