2017-11-02 01:41:13 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-11-25 23:47:06 +03:00
|
|
|
#include <QApplication>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QComboBox>
|
2018-09-15 23:52:14 +03:00
|
|
|
#include <QFileDialog>
|
2020-02-18 18:08:19 +03:00
|
|
|
#include <QFormLayout>
|
2018-09-15 23:52:14 +03:00
|
|
|
#include <QInputDialog>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QLabel>
|
2018-09-15 23:52:14 +03:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMessageBox>
|
2020-01-31 08:12:02 +03:00
|
|
|
#include <QPainter>
|
2019-08-10 20:14:37 +03:00
|
|
|
#include <QProcessEnvironment>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QPushButton>
|
2020-02-15 05:37:54 +03:00
|
|
|
#include <QResizeEvent>
|
2018-01-14 16:57:58 +03:00
|
|
|
#include <QScrollArea>
|
2020-02-15 05:47:58 +03:00
|
|
|
#include <QScroller>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QSettings>
|
2020-02-15 04:35:26 +03:00
|
|
|
#include <QStandardPaths>
|
2019-08-10 20:14:37 +03:00
|
|
|
#include <QString>
|
2019-03-28 02:13:38 +03:00
|
|
|
#include <QTextStream>
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2019-12-15 05:34:17 +03:00
|
|
|
#include "Cache.h"
|
2017-11-02 01:41:13 +03:00
|
|
|
#include "Config.h"
|
2018-08-21 09:22:51 +03:00
|
|
|
#include "MatrixClient.h"
|
|
|
|
#include "Olm.h"
|
2017-11-02 01:41:13 +03:00
|
|
|
#include "UserSettingsPage.h"
|
2018-07-22 19:48:58 +03:00
|
|
|
#include "Utils.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "ui/FlatButton.h"
|
|
|
|
#include "ui/ToggleButton.h"
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2018-09-30 14:33:54 +03:00
|
|
|
#include "config/nheko.h"
|
2018-03-22 17:20:22 +03:00
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
UserSettings::UserSettings() { load(); }
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettings::load()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2018-09-26 19:22:52 +03:00
|
|
|
isTrayEnabled_ = settings.value("user/window/tray", false).toBool();
|
2018-08-11 18:26:17 +03:00
|
|
|
hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool();
|
2018-05-08 23:53:40 +03:00
|
|
|
isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool();
|
2018-01-14 16:57:58 +03:00
|
|
|
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
|
2020-03-10 02:30:45 +03:00
|
|
|
isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool();
|
2020-01-27 17:59:25 +03:00
|
|
|
isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool();
|
2018-01-14 16:57:58 +03:00
|
|
|
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
2020-03-15 18:19:22 +03:00
|
|
|
ignoreMinorEvents_ = settings.value("user/minor_events", false).toBool();
|
2018-03-11 18:56:40 +03:00
|
|
|
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
2019-08-10 20:14:37 +03:00
|
|
|
theme_ = settings.value("user/theme", defaultTheme_).toString();
|
2019-01-19 19:20:41 +03:00
|
|
|
font_ = settings.value("user/font_family", "default").toString();
|
2019-09-07 23:22:07 +03:00
|
|
|
avatarCircles_ = settings.value("user/avatar_circles", true).toBool();
|
2019-07-27 00:31:59 +03:00
|
|
|
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
|
2018-10-01 17:56:46 +03:00
|
|
|
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
|
|
|
|
2017-11-25 23:47:06 +03:00
|
|
|
applyTheme();
|
|
|
|
}
|
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
void
|
|
|
|
UserSettings::setFontSize(double size)
|
|
|
|
{
|
|
|
|
baseFontSize_ = size;
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2019-01-19 19:20:41 +03:00
|
|
|
void
|
|
|
|
UserSettings::setFontFamily(QString family)
|
|
|
|
{
|
|
|
|
font_ = family;
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2019-07-27 00:31:59 +03:00
|
|
|
void
|
|
|
|
UserSettings::setEmojiFontFamily(QString family)
|
|
|
|
{
|
|
|
|
emojiFont_ = family;
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2017-11-25 23:47:06 +03:00
|
|
|
void
|
|
|
|
UserSettings::setTheme(QString theme)
|
|
|
|
{
|
|
|
|
theme_ = theme;
|
|
|
|
save();
|
|
|
|
applyTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettings::applyTheme()
|
|
|
|
{
|
|
|
|
QFile stylefile;
|
|
|
|
|
|
|
|
if (theme() == "light") {
|
|
|
|
stylefile.setFileName(":/styles/styles/nheko.qss");
|
|
|
|
} else if (theme() == "dark") {
|
|
|
|
stylefile.setFileName(":/styles/styles/nheko-dark.qss");
|
|
|
|
} else {
|
|
|
|
stylefile.setFileName(":/styles/styles/system.qss");
|
|
|
|
}
|
|
|
|
|
|
|
|
stylefile.open(QFile::ReadOnly);
|
|
|
|
QString stylesheet = QString(stylefile.readAll());
|
|
|
|
|
|
|
|
qobject_cast<QApplication *>(QApplication::instance())->setStyleSheet(stylesheet);
|
2017-11-02 01:41:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettings::save()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("user");
|
2017-11-02 23:00:43 +03:00
|
|
|
|
|
|
|
settings.beginGroup("window");
|
2017-11-02 01:41:13 +03:00
|
|
|
settings.setValue("tray", isTrayEnabled_);
|
2018-05-08 23:53:40 +03:00
|
|
|
settings.setValue("start_in_tray", isStartInTrayEnabled_);
|
2017-11-02 23:00:43 +03:00
|
|
|
settings.endGroup();
|
|
|
|
|
2020-03-10 02:30:45 +03:00
|
|
|
settings.beginGroup("timeline");
|
|
|
|
settings.setValue("buttons", isButtonsInTimelineEnabled_);
|
|
|
|
settings.endGroup();
|
|
|
|
|
2019-09-07 23:22:07 +03:00
|
|
|
settings.setValue("avatar_circles", avatarCircles_);
|
2019-08-29 07:36:28 +03:00
|
|
|
|
2018-10-01 17:56:46 +03:00
|
|
|
settings.setValue("font_size", baseFontSize_);
|
2018-01-14 16:57:58 +03:00
|
|
|
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
|
2020-03-15 18:19:22 +03:00
|
|
|
settings.setValue("minor_events", ignoreMinorEvents_);
|
2018-03-11 18:56:40 +03:00
|
|
|
settings.setValue("read_receipts", isReadReceiptsEnabled_);
|
2018-01-09 22:57:41 +03:00
|
|
|
settings.setValue("group_view", isGroupViewEnabled_);
|
2020-01-27 17:59:25 +03:00
|
|
|
settings.setValue("markdown_enabled", isMarkdownEnabled_);
|
2018-08-11 18:26:17 +03:00
|
|
|
settings.setValue("desktop_notifications", hasDesktopNotifications_);
|
2017-11-02 01:41:13 +03:00
|
|
|
settings.setValue("theme", theme());
|
2019-01-19 19:20:41 +03:00
|
|
|
settings.setValue("font_family", font_);
|
2019-07-27 00:31:59 +03:00
|
|
|
settings.setValue("emoji_font_family", emojiFont_);
|
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
HorizontalLine::HorizontalLine(QWidget *parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
: QFrame{parent}
|
2017-11-02 01:41:13 +03:00
|
|
|
{
|
|
|
|
setFrameShape(QFrame::HLine);
|
|
|
|
setFrameShadow(QFrame::Sunken);
|
|
|
|
}
|
|
|
|
|
|
|
|
UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidget *parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
: QWidget{parent}
|
|
|
|
, settings_{settings}
|
2017-11-02 01:41:13 +03:00
|
|
|
{
|
2020-02-19 00:16:07 +03:00
|
|
|
topLayout_ = new QVBoxLayout{this};
|
2017-11-02 01:41:13 +03:00
|
|
|
|
|
|
|
QIcon icon;
|
|
|
|
icon.addFile(":/icons/icons/ui/angle-pointing-to-left.png");
|
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto backBtn_ = new FlatButton{this};
|
2017-11-02 01:41:13 +03:00
|
|
|
backBtn_->setMinimumSize(QSize(24, 24));
|
|
|
|
backBtn_->setIcon(icon);
|
|
|
|
backBtn_->setIconSize(QSize(24, 24));
|
|
|
|
|
2018-07-22 18:03:12 +03:00
|
|
|
QFont font;
|
|
|
|
font.setPointSizeF(font.pointSizeF() * 1.1);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2018-06-23 01:46:18 +03:00
|
|
|
auto versionInfo = new QLabel(QString("%1 | %2").arg(nheko::version).arg(nheko::build_os));
|
|
|
|
versionInfo->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
2018-03-22 17:20:22 +03:00
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
topBarLayout_ = new QHBoxLayout;
|
|
|
|
topBarLayout_->setSpacing(0);
|
|
|
|
topBarLayout_->setMargin(0);
|
|
|
|
topBarLayout_->addWidget(backBtn_, 1, Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
topBarLayout_->addStretch(1);
|
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_ = new QFormLayout;
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->setLabelAlignment(Qt::AlignLeft);
|
|
|
|
formLayout_->setFormAlignment(Qt::AlignRight);
|
|
|
|
formLayout_->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
|
|
|
formLayout_->setRowWrapPolicy(QFormLayout::WrapLongRows);
|
|
|
|
formLayout_->setHorizontalSpacing(0);
|
2018-05-08 23:53:40 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto general_ = new QLabel{tr("GENERAL"), this};
|
2020-02-18 18:08:19 +03:00
|
|
|
general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
|
|
|
general_->setFont(font);
|
2018-01-09 22:57:41 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
trayToggle_ = new Toggle{this};
|
|
|
|
startInTrayToggle_ = new Toggle{this};
|
|
|
|
avatarCircles_ = new Toggle{this};
|
|
|
|
groupViewToggle_ = new Toggle{this};
|
2020-03-10 02:30:45 +03:00
|
|
|
timelineButtonsToggle_ = new Toggle{this};
|
2020-02-19 00:16:07 +03:00
|
|
|
typingNotifications_ = new Toggle{this};
|
2020-03-15 18:19:22 +03:00
|
|
|
ignoreMinorEvents_ = new Toggle{this};
|
2020-02-19 00:16:07 +03:00
|
|
|
readReceipts_ = new Toggle{this};
|
|
|
|
markdownEnabled_ = new Toggle{this};
|
|
|
|
desktopNotifications_ = new Toggle{this};
|
|
|
|
scaleFactorCombo_ = new QComboBox{this};
|
|
|
|
fontSizeCombo_ = new QComboBox{this};
|
|
|
|
fontSelectionCombo_ = new QComboBox{this};
|
|
|
|
emojiFontSelectionCombo_ = new QComboBox{this};
|
2018-01-09 22:57:41 +03:00
|
|
|
|
2020-01-27 17:59:25 +03:00
|
|
|
if (!settings_->isTrayEnabled())
|
|
|
|
startInTrayToggle_->setDisabled(true);
|
2019-08-29 07:36:28 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
avatarCircles_->setFixedSize(64, 48);
|
|
|
|
|
|
|
|
auto uiLabel_ = new QLabel{tr("INTERFACE"), this};
|
2020-02-19 22:23:57 +03:00
|
|
|
uiLabel_->setFixedHeight(uiLabel_->minimumHeight() + LayoutTopMargin);
|
|
|
|
uiLabel_->setAlignment(Qt::AlignBottom);
|
2020-02-19 00:16:07 +03:00
|
|
|
uiLabel_->setFont(font);
|
|
|
|
|
2018-10-07 12:58:38 +03:00
|
|
|
for (double option = 1; option <= 3; option += 0.25)
|
|
|
|
scaleFactorCombo_->addItem(QString::number(option));
|
2018-10-01 17:56:46 +03:00
|
|
|
for (double option = 10; option < 17; option += 0.5)
|
|
|
|
fontSizeCombo_->addItem(QString("%1 ").arg(QString::number(option)));
|
|
|
|
|
2019-01-19 19:20:41 +03:00
|
|
|
QFontDatabase fontDb;
|
|
|
|
auto fontFamilies = fontDb.families();
|
|
|
|
for (const auto &family : fontFamilies) {
|
|
|
|
fontSelectionCombo_->addItem(family);
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
// TODO: Is there a way to limit to just emojis, rather than
|
|
|
|
// all emoji fonts?
|
|
|
|
auto emojiFamilies = fontDb.families(QFontDatabase::Symbol);
|
2019-07-27 00:31:59 +03:00
|
|
|
for (const auto &family : emojiFamilies) {
|
|
|
|
emojiFontSelectionCombo_->addItem(family);
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
fontSelectionCombo_->setCurrentIndex(fontSelectionCombo_->findText(settings_->font()));
|
2019-01-19 20:31:17 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
emojiFontSelectionCombo_->setCurrentIndex(
|
|
|
|
emojiFontSelectionCombo_->findText(settings_->emojiFont()));
|
2019-07-27 00:31:59 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
themeCombo_ = new QComboBox{this};
|
2017-11-25 19:19:58 +03:00
|
|
|
themeCombo_->addItem("Light");
|
|
|
|
themeCombo_->addItem("Dark");
|
2017-11-02 01:41:13 +03:00
|
|
|
themeCombo_->addItem("System");
|
|
|
|
|
2019-01-19 20:31:17 +03:00
|
|
|
QString themeStr = settings_->theme();
|
|
|
|
themeStr.replace(0, 1, themeStr[0].toUpper());
|
|
|
|
int themeIndex = themeCombo_->findText(themeStr);
|
|
|
|
themeCombo_->setCurrentIndex(themeIndex);
|
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto encryptionLabel_ = new QLabel{tr("ENCRYPTION"), this};
|
2020-02-19 22:23:57 +03:00
|
|
|
encryptionLabel_->setFixedHeight(encryptionLabel_->minimumHeight() + LayoutTopMargin);
|
|
|
|
encryptionLabel_->setAlignment(Qt::AlignBottom);
|
2020-02-18 18:08:19 +03:00
|
|
|
encryptionLabel_->setFont(font);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
QFont monospaceFont;
|
|
|
|
monospaceFont.setFamily("Monospace");
|
|
|
|
monospaceFont.setStyleHint(QFont::Monospace);
|
2018-08-21 09:22:51 +03:00
|
|
|
monospaceFont.setPointSizeF(monospaceFont.pointSizeF() * 0.9);
|
|
|
|
|
2018-09-15 23:52:14 +03:00
|
|
|
deviceIdValue_ = new QLabel{this};
|
2018-08-21 09:22:51 +03:00
|
|
|
deviceIdValue_->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
deviceIdValue_->setFont(monospaceFont);
|
|
|
|
|
2018-09-15 23:52:14 +03:00
|
|
|
deviceFingerprintValue_ = new QLabel{this};
|
2018-08-21 09:22:51 +03:00
|
|
|
deviceFingerprintValue_->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
deviceFingerprintValue_->setFont(monospaceFont);
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2020-02-19 22:00:49 +03:00
|
|
|
deviceFingerprintValue_->setText(utils::humanReadableFingerprint(QString(44, 'X')));
|
2020-02-19 00:16:07 +03:00
|
|
|
|
|
|
|
auto sessionKeysLabel = new QLabel{tr("Session Keys"), this};
|
2018-09-15 23:52:14 +03:00
|
|
|
sessionKeysLabel->setFont(font);
|
2020-02-18 18:08:19 +03:00
|
|
|
sessionKeysLabel->setMargin(OptionMargin);
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
auto sessionKeysImportBtn = new QPushButton{tr("IMPORT"), this};
|
|
|
|
auto sessionKeysExportBtn = new QPushButton{tr("EXPORT"), this};
|
2020-02-18 18:08:19 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto sessionKeysLayout = new QHBoxLayout;
|
|
|
|
sessionKeysLayout->addWidget(new QLabel{"", this}, 1, Qt::AlignRight);
|
2018-09-19 22:42:26 +03:00
|
|
|
sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight);
|
|
|
|
sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight);
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
auto boxWrap = [this, &font](QString labelText, QWidget *field) {
|
2020-02-19 00:16:07 +03:00
|
|
|
auto label = new QLabel{labelText, this};
|
2020-02-18 18:08:19 +03:00
|
|
|
label->setFont(font);
|
|
|
|
label->setMargin(OptionMargin);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto layout = new QHBoxLayout;
|
2020-02-18 18:08:19 +03:00
|
|
|
layout->addWidget(field, 0, Qt::AlignRight);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->addRow(label, layout);
|
|
|
|
};
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->addRow(general_);
|
2020-02-19 00:16:07 +03:00
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Minimize to tray"), trayToggle_);
|
|
|
|
boxWrap(tr("Start in tray"), startInTrayToggle_);
|
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
|
|
|
boxWrap(tr("Circular Avatars"), avatarCircles_);
|
|
|
|
boxWrap(tr("Group's sidebar"), groupViewToggle_);
|
2020-03-10 02:30:45 +03:00
|
|
|
boxWrap(tr("Show buttons in timeline"), timelineButtonsToggle_);
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Typing notifications"), typingNotifications_);
|
2020-03-15 18:19:22 +03:00
|
|
|
boxWrap(tr("Ignore minor events in room list"), ignoreMinorEvents_);
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
|
|
|
boxWrap(tr("Read receipts"), readReceipts_);
|
|
|
|
boxWrap(tr("Send messages as Markdown"), markdownEnabled_);
|
|
|
|
boxWrap(tr("Desktop notifications"), desktopNotifications_);
|
2020-02-19 00:16:07 +03:00
|
|
|
formLayout_->addRow(uiLabel_);
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
2020-02-19 00:16:07 +03:00
|
|
|
|
|
|
|
#if !defined(Q_OS_MAC)
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Scale factor"), scaleFactorCombo_);
|
2020-02-19 00:16:07 +03:00
|
|
|
#else
|
|
|
|
scaleFactorCombo_->hide();
|
|
|
|
#endif
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Font size"), fontSizeCombo_);
|
|
|
|
boxWrap(tr("Font Family"), fontSelectionCombo_);
|
2020-02-19 00:16:07 +03:00
|
|
|
|
|
|
|
#if !defined(Q_OS_MAC)
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Emoji Font Family"), emojiFontSelectionCombo_);
|
2020-02-19 00:16:07 +03:00
|
|
|
#else
|
|
|
|
emojiFontSelectionCombo_->hide();
|
|
|
|
#endif
|
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Theme"), themeCombo_);
|
|
|
|
formLayout_->addRow(encryptionLabel_);
|
2020-02-19 00:16:07 +03:00
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
2020-02-18 18:08:19 +03:00
|
|
|
boxWrap(tr("Device ID"), deviceIdValue_);
|
|
|
|
boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_);
|
2020-02-19 00:16:07 +03:00
|
|
|
formLayout_->addRow(new HorizontalLine{this});
|
2020-02-18 18:08:19 +03:00
|
|
|
formLayout_->addRow(sessionKeysLabel, sessionKeysLayout);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto scrollArea_ = new QScrollArea{this};
|
2018-05-09 01:00:10 +03:00
|
|
|
scrollArea_->setFrameShape(QFrame::NoFrame);
|
|
|
|
scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
|
|
scrollArea_->setWidgetResizable(true);
|
|
|
|
scrollArea_->setAlignment(Qt::AlignTop | Qt::AlignVCenter);
|
|
|
|
|
2020-02-15 05:47:58 +03:00
|
|
|
QScroller::grabGesture(scrollArea_, QScroller::TouchGesture);
|
|
|
|
|
2020-02-20 20:11:30 +03:00
|
|
|
auto spacingAroundForm = new QHBoxLayout;
|
|
|
|
spacingAroundForm->addStretch(1);
|
|
|
|
spacingAroundForm->addLayout(formLayout_, 0);
|
|
|
|
spacingAroundForm->addStretch(1);
|
|
|
|
|
2020-02-19 00:16:07 +03:00
|
|
|
auto scrollAreaContents_ = new QWidget{this};
|
2018-05-09 01:00:10 +03:00
|
|
|
scrollAreaContents_->setObjectName("UserSettingScrollWidget");
|
2020-02-20 20:11:30 +03:00
|
|
|
scrollAreaContents_->setLayout(spacingAroundForm);
|
2018-05-09 01:00:10 +03:00
|
|
|
|
|
|
|
scrollArea_->setWidget(scrollAreaContents_);
|
2017-11-02 01:41:13 +03:00
|
|
|
topLayout_->addLayout(topBarLayout_);
|
2018-08-01 21:26:34 +03:00
|
|
|
topLayout_->addWidget(scrollArea_, Qt::AlignTop);
|
|
|
|
topLayout_->addStretch(1);
|
2018-03-22 17:20:22 +03:00
|
|
|
topLayout_->addWidget(versionInfo);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
|
|
|
connect(themeCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
2019-01-20 07:43:48 +03:00
|
|
|
[this](const QString &text) {
|
|
|
|
settings_->setTheme(text.toLower());
|
|
|
|
emit themeChanged();
|
|
|
|
});
|
2018-07-22 19:48:58 +03:00
|
|
|
connect(scaleFactorCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
2018-07-22 20:26:50 +03:00
|
|
|
[](const QString &factor) { utils::setScaleFactor(factor.toFloat()); });
|
2018-10-01 17:56:46 +03:00
|
|
|
connect(fontSizeCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
|
|
|
[this](const QString &size) { settings_->setFontSize(size.trimmed().toDouble()); });
|
2019-01-19 19:20:41 +03:00
|
|
|
connect(fontSelectionCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
|
|
|
[this](const QString &family) { settings_->setFontFamily(family.trimmed()); });
|
2019-07-27 00:31:59 +03:00
|
|
|
connect(emojiFontSelectionCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
|
|
|
[this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); });
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
2017-11-02 23:00:43 +03:00
|
|
|
settings_->setTray(!isDisabled);
|
2018-05-08 23:53:40 +03:00
|
|
|
if (isDisabled) {
|
|
|
|
startInTrayToggle_->setDisabled(true);
|
|
|
|
} else {
|
|
|
|
startInTrayToggle_->setEnabled(true);
|
|
|
|
}
|
2017-11-02 23:00:43 +03:00
|
|
|
emit trayOptionChanged(!isDisabled);
|
2017-11-02 01:41:13 +03:00
|
|
|
});
|
|
|
|
|
2018-05-08 23:53:40 +03:00
|
|
|
connect(startInTrayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setStartInTray(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(groupViewToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
2018-01-09 22:57:41 +03:00
|
|
|
settings_->setGroupView(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2019-09-02 02:10:11 +03:00
|
|
|
connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) {
|
2019-09-02 00:41:23 +03:00
|
|
|
settings_->setAvatarCircles(!isDisabled);
|
2019-08-29 07:36:28 +03:00
|
|
|
});
|
|
|
|
|
2020-01-27 17:59:25 +03:00
|
|
|
connect(markdownEnabled_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setMarkdownEnabled(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
|
2018-01-14 16:57:58 +03:00
|
|
|
settings_->setTypingNotifications(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2020-03-15 18:19:22 +03:00
|
|
|
connect(ignoreMinorEvents_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setIgnoreMinorEvents(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2020-03-10 02:30:45 +03:00
|
|
|
connect(timelineButtonsToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setButtonsInTimeline(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2018-03-11 18:56:40 +03:00
|
|
|
connect(readReceipts_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setReadReceipts(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2018-08-11 18:26:17 +03:00
|
|
|
connect(desktopNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
|
|
|
|
settings_->setDesktopNotifications(!isDisabled);
|
|
|
|
});
|
|
|
|
|
2020-02-18 18:08:19 +03:00
|
|
|
connect(
|
|
|
|
sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys);
|
|
|
|
|
|
|
|
connect(
|
|
|
|
sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys);
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(backBtn_, &QPushButton::clicked, this, [this]() {
|
2017-11-02 01:41:13 +03:00
|
|
|
settings_->save();
|
|
|
|
emit moveBack();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsPage::showEvent(QShowEvent *)
|
|
|
|
{
|
2018-10-01 17:56:46 +03:00
|
|
|
// FIXME macOS doesn't show the full option unless a space is added.
|
|
|
|
utils::restoreCombobox(fontSizeCombo_, QString::number(settings_->fontSize()) + " ");
|
|
|
|
utils::restoreCombobox(scaleFactorCombo_, QString::number(utils::scaleFactor()));
|
|
|
|
utils::restoreCombobox(themeCombo_, settings_->theme());
|
2018-01-09 22:57:41 +03:00
|
|
|
|
|
|
|
// FIXME: Toggle treats true as "off"
|
|
|
|
trayToggle_->setState(!settings_->isTrayEnabled());
|
2018-05-08 23:53:40 +03:00
|
|
|
startInTrayToggle_->setState(!settings_->isStartInTrayEnabled());
|
2018-01-09 22:57:41 +03:00
|
|
|
groupViewToggle_->setState(!settings_->isGroupViewEnabled());
|
2020-01-27 17:59:25 +03:00
|
|
|
avatarCircles_->setState(!settings_->isAvatarCirclesEnabled());
|
2018-01-14 16:57:58 +03:00
|
|
|
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
|
2020-03-15 18:19:22 +03:00
|
|
|
ignoreMinorEvents_->setState(!settings_->isIgnoreMinorEventsEnabled());
|
2020-03-10 02:30:45 +03:00
|
|
|
timelineButtonsToggle_->setState(!settings_->isButtonsInTimelineEnabled());
|
2018-03-11 18:56:40 +03:00
|
|
|
readReceipts_->setState(!settings_->isReadReceiptsEnabled());
|
2020-01-27 17:59:25 +03:00
|
|
|
markdownEnabled_->setState(!settings_->isMarkdownEnabled());
|
2018-08-11 18:26:17 +03:00
|
|
|
desktopNotifications_->setState(!settings_->hasDesktopNotifications());
|
2018-08-21 09:22:51 +03:00
|
|
|
deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));
|
|
|
|
|
|
|
|
deviceFingerprintValue_->setText(
|
|
|
|
utils::humanReadableFingerprint(olm::client()->identity_keys().ed25519));
|
2017-11-02 01:41:13 +03:00
|
|
|
}
|
2017-11-09 23:04:40 +03:00
|
|
|
|
|
|
|
void
|
2017-11-22 20:52:38 +03:00
|
|
|
UserSettingsPage::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
}
|
2017-11-25 19:19:58 +03:00
|
|
|
|
2018-09-15 23:52:14 +03:00
|
|
|
void
|
|
|
|
UserSettingsPage::importSessionKeys()
|
|
|
|
{
|
2020-02-15 04:35:26 +03:00
|
|
|
const QString homeFolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
|
|
|
const QString fileName =
|
|
|
|
QFileDialog::getOpenFileName(this, tr("Open Sessions File"), homeFolder, "");
|
2018-09-15 23:52:14 +03:00
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), file.errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto bin = file.peek(file.size());
|
|
|
|
auto payload = std::string(bin.data(), bin.size());
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
auto password = QInputDialog::getText(this,
|
|
|
|
tr("File Password"),
|
|
|
|
tr("Enter the passphrase to decrypt the file:"),
|
|
|
|
QLineEdit::Password,
|
|
|
|
"",
|
|
|
|
&ok);
|
2018-09-19 22:42:26 +03:00
|
|
|
if (!ok)
|
|
|
|
return;
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
if (password.isEmpty()) {
|
2018-09-15 23:52:14 +03:00
|
|
|
QMessageBox::warning(this, tr("Error"), tr("The password cannot be empty"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-04-05 01:24:21 +03:00
|
|
|
auto sessions =
|
|
|
|
mtx::crypto::decrypt_exported_sessions(payload, password.toStdString());
|
2019-12-15 04:56:04 +03:00
|
|
|
cache::importSessionKeys(std::move(sessions));
|
2018-09-18 18:48:14 +03:00
|
|
|
} catch (const mtx::crypto::sodium_exception &e) {
|
2018-09-15 23:52:14 +03:00
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
} catch (const lmdb::error &e) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
} catch (const nlohmann::json::exception &e) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsPage::exportSessionKeys()
|
|
|
|
{
|
|
|
|
// Open password dialog.
|
|
|
|
bool ok;
|
|
|
|
auto password = QInputDialog::getText(this,
|
|
|
|
tr("File Password"),
|
|
|
|
tr("Enter passphrase to encrypt your session keys:"),
|
|
|
|
QLineEdit::Password,
|
|
|
|
"",
|
|
|
|
&ok);
|
2018-09-19 22:42:26 +03:00
|
|
|
if (!ok)
|
|
|
|
return;
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
if (password.isEmpty()) {
|
2018-09-15 23:52:14 +03:00
|
|
|
QMessageBox::warning(this, tr("Error"), tr("The password cannot be empty"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open file dialog to save the file.
|
2020-02-15 04:35:26 +03:00
|
|
|
const QString homeFolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
|
|
|
const QString fileName =
|
2018-09-15 23:52:14 +03:00
|
|
|
QFileDialog::getSaveFileName(this, tr("File to save the exported session keys"), "", "");
|
|
|
|
|
|
|
|
QFile file(fileName);
|
2019-03-28 02:13:38 +03:00
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
2018-09-15 23:52:14 +03:00
|
|
|
QMessageBox::warning(this, tr("Error"), file.errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export sessions & save to file.
|
|
|
|
try {
|
|
|
|
auto encrypted_blob = mtx::crypto::encrypt_exported_sessions(
|
2019-12-15 04:56:04 +03:00
|
|
|
cache::exportSessionKeys(), password.toStdString());
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2019-04-05 01:24:21 +03:00
|
|
|
QString b64 = QString::fromStdString(mtx::crypto::bin2base64(encrypted_blob));
|
2018-09-15 23:52:14 +03:00
|
|
|
|
2019-03-28 02:13:38 +03:00
|
|
|
QString prefix("-----BEGIN MEGOLM SESSION DATA-----");
|
|
|
|
QString suffix("-----END MEGOLM SESSION DATA-----");
|
|
|
|
QString newline("\n");
|
|
|
|
QTextStream out(&file);
|
|
|
|
out << prefix << newline << b64 << newline << suffix;
|
|
|
|
file.close();
|
2018-09-18 18:48:14 +03:00
|
|
|
} catch (const mtx::crypto::sodium_exception &e) {
|
2018-09-15 23:52:14 +03:00
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
} catch (const lmdb::error &e) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
} catch (const nlohmann::json::exception &e) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), e.what());
|
|
|
|
}
|
|
|
|
}
|