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>
|
|
|
|
#include <QInputDialog>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QLabel>
|
2018-09-15 23:52:14 +03:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMessageBox>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QPushButton>
|
2018-01-14 16:57:58 +03:00
|
|
|
#include <QScrollArea>
|
2017-11-02 01:41:13 +03:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
#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();
|
|
|
|
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
2018-03-11 18:56:40 +03:00
|
|
|
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
2018-01-14 16:57:58 +03:00
|
|
|
theme_ = settings.value("user/theme", "light").toString();
|
2019-01-19 19:20:41 +03:00
|
|
|
font_ = settings.value("user/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();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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_);
|
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_);
|
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_);
|
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
|
|
|
{
|
|
|
|
topLayout_ = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
QIcon icon;
|
|
|
|
icon.addFile(":/icons/icons/ui/angle-pointing-to-left.png");
|
|
|
|
|
|
|
|
auto backBtn_ = new FlatButton(this);
|
|
|
|
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);
|
|
|
|
|
|
|
|
auto trayOptionLayout_ = new QHBoxLayout;
|
|
|
|
trayOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto trayLabel = new QLabel(tr("Minimize to tray"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
trayLabel->setFont(font);
|
|
|
|
trayToggle_ = new Toggle(this);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
|
|
|
trayOptionLayout_->addWidget(trayLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignRight);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2018-05-08 23:53:40 +03:00
|
|
|
auto startInTrayOptionLayout_ = new QHBoxLayout;
|
|
|
|
startInTrayOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto startInTrayLabel = new QLabel(tr("Start in tray"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
startInTrayLabel->setFont(font);
|
|
|
|
startInTrayToggle_ = new Toggle(this);
|
2018-05-08 23:53:40 +03:00
|
|
|
if (!settings_->isTrayEnabled())
|
|
|
|
startInTrayToggle_->setDisabled(true);
|
|
|
|
|
|
|
|
startInTrayOptionLayout_->addWidget(startInTrayLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
startInTrayOptionLayout_->addWidget(startInTrayToggle_, 0, Qt::AlignRight);
|
2018-05-08 23:53:40 +03:00
|
|
|
|
2018-01-09 22:57:41 +03:00
|
|
|
auto groupViewLayout = new QHBoxLayout;
|
|
|
|
groupViewLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto groupViewLabel = new QLabel(tr("Group's sidebar"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
groupViewLabel->setFont(font);
|
|
|
|
groupViewToggle_ = new Toggle(this);
|
2018-01-09 22:57:41 +03:00
|
|
|
|
|
|
|
groupViewLayout->addWidget(groupViewLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignRight);
|
2018-01-09 22:57:41 +03:00
|
|
|
|
2018-01-14 16:57:58 +03:00
|
|
|
auto typingLayout = new QHBoxLayout;
|
|
|
|
typingLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-07-22 18:03:12 +03:00
|
|
|
auto typingLabel = new QLabel(tr("Typing notifications"), this);
|
|
|
|
typingLabel->setFont(font);
|
2018-01-14 16:57:58 +03:00
|
|
|
typingNotifications_ = new Toggle(this);
|
|
|
|
|
|
|
|
typingLayout->addWidget(typingLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
typingLayout->addWidget(typingNotifications_, 0, Qt::AlignRight);
|
2018-01-14 16:57:58 +03:00
|
|
|
|
2018-03-11 18:56:40 +03:00
|
|
|
auto receiptsLayout = new QHBoxLayout;
|
|
|
|
receiptsLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto receiptsLabel = new QLabel(tr("Read receipts"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
receiptsLabel->setFont(font);
|
|
|
|
readReceipts_ = new Toggle(this);
|
2018-03-11 18:56:40 +03:00
|
|
|
|
|
|
|
receiptsLayout->addWidget(receiptsLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignRight);
|
2018-03-11 18:56:40 +03:00
|
|
|
|
2018-08-11 18:26:17 +03:00
|
|
|
auto desktopLayout = new QHBoxLayout;
|
|
|
|
desktopLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto desktopLabel = new QLabel(tr("Desktop notifications"), this);
|
|
|
|
desktopLabel->setFont(font);
|
|
|
|
desktopNotifications_ = new Toggle(this);
|
|
|
|
|
|
|
|
desktopLayout->addWidget(desktopLabel);
|
2018-09-19 22:42:26 +03:00
|
|
|
desktopLayout->addWidget(desktopNotifications_, 0, Qt::AlignRight);
|
2018-08-11 18:26:17 +03:00
|
|
|
|
2018-07-22 19:48:58 +03:00
|
|
|
auto scaleFactorOptionLayout = new QHBoxLayout;
|
|
|
|
scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-10-07 12:58:38 +03:00
|
|
|
auto scaleFactorLabel = new QLabel(tr("Scale factor"), this);
|
2018-07-22 19:48:58 +03:00
|
|
|
scaleFactorLabel->setFont(font);
|
|
|
|
scaleFactorCombo_ = new QComboBox(this);
|
2018-10-07 12:58:38 +03:00
|
|
|
for (double option = 1; option <= 3; option += 0.25)
|
|
|
|
scaleFactorCombo_->addItem(QString::number(option));
|
|
|
|
|
|
|
|
scaleFactorOptionLayout->addWidget(scaleFactorLabel);
|
|
|
|
scaleFactorOptionLayout->addWidget(scaleFactorCombo_, 0, Qt::AlignRight);
|
2018-07-22 19:48:58 +03:00
|
|
|
|
2018-10-01 17:56:46 +03:00
|
|
|
auto fontSizeOptionLayout = new QHBoxLayout;
|
|
|
|
fontSizeOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto fontSizeLabel = new QLabel(tr("Font size"), this);
|
|
|
|
fontSizeLabel->setFont(font);
|
|
|
|
fontSizeCombo_ = new QComboBox(this);
|
|
|
|
for (double option = 10; option < 17; option += 0.5)
|
|
|
|
fontSizeCombo_->addItem(QString("%1 ").arg(QString::number(option)));
|
|
|
|
|
|
|
|
fontSizeOptionLayout->addWidget(fontSizeLabel);
|
|
|
|
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
2018-07-22 19:48:58 +03:00
|
|
|
|
2019-01-19 19:20:41 +03:00
|
|
|
auto fontFamilyOptionLayout = new QHBoxLayout;
|
|
|
|
fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto fontFamilyLabel = new QLabel(tr("Font Family"), this);
|
|
|
|
fontFamilyLabel->setFont(font);
|
|
|
|
fontSelectionCombo_ = new QComboBox(this);
|
|
|
|
QFontDatabase fontDb;
|
|
|
|
auto fontFamilies = fontDb.families();
|
|
|
|
for (const auto &family : fontFamilies) {
|
|
|
|
fontSelectionCombo_->addItem(family);
|
|
|
|
}
|
|
|
|
|
2019-01-19 20:31:17 +03:00
|
|
|
int fontIndex = fontSelectionCombo_->findText(settings_->font());
|
|
|
|
fontSelectionCombo_->setCurrentIndex(fontIndex);
|
|
|
|
|
2019-01-19 19:20:41 +03:00
|
|
|
fontFamilyOptionLayout->addWidget(fontFamilyLabel);
|
|
|
|
fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight);
|
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
auto themeOptionLayout_ = new QHBoxLayout;
|
|
|
|
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-01-14 16:57:58 +03:00
|
|
|
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
themeLabel_->setFont(font);
|
|
|
|
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);
|
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
themeOptionLayout_->addWidget(themeLabel_);
|
2018-09-19 22:42:26 +03:00
|
|
|
themeOptionLayout_->addWidget(themeCombo_, 0, Qt::AlignRight);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2018-08-21 09:22:51 +03:00
|
|
|
auto encryptionLayout_ = new QVBoxLayout;
|
|
|
|
encryptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-09-19 22:42:26 +03:00
|
|
|
encryptionLayout_->setAlignment(Qt::AlignVCenter);
|
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
|
|
|
auto deviceIdLayout = new QHBoxLayout;
|
|
|
|
deviceIdLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
|
|
|
auto deviceIdLabel = new QLabel(tr("Device ID"), this);
|
|
|
|
deviceIdLabel->setFont(font);
|
2018-09-19 22:42:26 +03:00
|
|
|
deviceIdLabel->setMargin(0);
|
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
|
|
|
deviceIdLayout->addWidget(deviceIdLabel, 1);
|
|
|
|
deviceIdLayout->addWidget(deviceIdValue_);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2018-09-15 23:52:14 +03:00
|
|
|
auto deviceFingerprintLayout = new QHBoxLayout;
|
|
|
|
deviceFingerprintLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
|
|
|
auto deviceFingerprintLabel = new QLabel(tr("Device Fingerprint"), this);
|
|
|
|
deviceFingerprintLabel->setFont(font);
|
2018-09-19 22:42:26 +03:00
|
|
|
deviceFingerprintLabel->setMargin(0);
|
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
|
|
|
deviceFingerprintLayout->addWidget(deviceFingerprintLabel, 1);
|
|
|
|
deviceFingerprintLayout->addWidget(deviceFingerprintValue_);
|
|
|
|
|
|
|
|
auto sessionKeysLayout = new QHBoxLayout;
|
|
|
|
sessionKeysLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
|
|
|
auto sessionKeysLabel = new QLabel(tr("Session Keys"), this);
|
|
|
|
sessionKeysLabel->setFont(font);
|
|
|
|
sessionKeysLayout->addWidget(sessionKeysLabel, 1);
|
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
auto sessionKeysImportBtn = new QPushButton{tr("IMPORT"), this};
|
2018-09-15 23:52:14 +03:00
|
|
|
connect(
|
|
|
|
sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys);
|
2018-09-19 22:42:26 +03:00
|
|
|
auto sessionKeysExportBtn = new QPushButton{tr("EXPORT"), this};
|
2018-09-15 23:52:14 +03:00
|
|
|
connect(
|
|
|
|
sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys);
|
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
|
|
|
|
|
|
|
encryptionLayout_->addLayout(deviceIdLayout);
|
|
|
|
encryptionLayout_->addLayout(deviceFingerprintLayout);
|
2018-09-19 22:42:26 +03:00
|
|
|
encryptionLayout_->addWidget(new HorizontalLine{this});
|
2018-09-15 23:52:14 +03:00
|
|
|
encryptionLayout_->addLayout(sessionKeysLayout);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
font.setWeight(QFont::Medium);
|
2018-08-21 09:22:51 +03:00
|
|
|
|
|
|
|
auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this);
|
|
|
|
encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
|
|
|
encryptionLabel_->setFont(font);
|
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
auto general_ = new QLabel(tr("GENERAL"), this);
|
2018-08-01 21:26:34 +03:00
|
|
|
general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
2018-07-22 18:03:12 +03:00
|
|
|
general_->setFont(font);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2017-11-09 23:04:40 +03:00
|
|
|
mainLayout_ = new QVBoxLayout;
|
2018-08-01 21:26:34 +03:00
|
|
|
mainLayout_->setAlignment(Qt::AlignTop);
|
2017-11-02 01:41:13 +03:00
|
|
|
mainLayout_->setSpacing(7);
|
|
|
|
mainLayout_->setContentsMargins(
|
2017-11-09 23:04:40 +03:00
|
|
|
sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin);
|
2018-08-01 21:26:34 +03:00
|
|
|
mainLayout_->addWidget(general_, 1, Qt::AlignLeft | Qt::AlignBottom);
|
2017-11-02 01:41:13 +03:00
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
|
|
|
mainLayout_->addLayout(trayOptionLayout_);
|
2018-05-08 23:53:40 +03:00
|
|
|
mainLayout_->addLayout(startInTrayOptionLayout_);
|
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
2018-01-09 22:57:41 +03:00
|
|
|
mainLayout_->addLayout(groupViewLayout);
|
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
2018-01-14 16:57:58 +03:00
|
|
|
mainLayout_->addLayout(typingLayout);
|
2018-03-11 18:56:40 +03:00
|
|
|
mainLayout_->addLayout(receiptsLayout);
|
2018-08-11 18:26:17 +03:00
|
|
|
mainLayout_->addLayout(desktopLayout);
|
2018-01-14 16:57:58 +03:00
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
2018-07-22 19:48:58 +03:00
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
scaleFactorLabel->hide();
|
|
|
|
scaleFactorCombo_->hide();
|
|
|
|
#endif
|
|
|
|
|
2018-10-07 12:58:38 +03:00
|
|
|
mainLayout_->addLayout(scaleFactorOptionLayout);
|
2018-10-01 17:56:46 +03:00
|
|
|
mainLayout_->addLayout(fontSizeOptionLayout);
|
2019-01-19 19:20:41 +03:00
|
|
|
mainLayout_->addLayout(fontFamilyOptionLayout);
|
2018-10-01 17:56:46 +03:00
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
2017-11-02 01:41:13 +03:00
|
|
|
mainLayout_->addLayout(themeOptionLayout_);
|
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
2018-08-21 09:22:51 +03:00
|
|
|
|
|
|
|
mainLayout_->addSpacing(50);
|
|
|
|
|
|
|
|
mainLayout_->addWidget(encryptionLabel_, 1, Qt::AlignLeft | Qt::AlignBottom);
|
|
|
|
mainLayout_->addWidget(new HorizontalLine(this));
|
|
|
|
mainLayout_->addLayout(encryptionLayout_);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
2018-05-09 01:00:10 +03:00
|
|
|
auto scrollArea_ = new QScrollArea(this);
|
|
|
|
scrollArea_->setFrameShape(QFrame::NoFrame);
|
|
|
|
scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
|
|
scrollArea_->setWidgetResizable(true);
|
|
|
|
scrollArea_->setAlignment(Qt::AlignTop | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
auto scrollAreaContents_ = new QWidget(this);
|
|
|
|
scrollAreaContents_->setObjectName("UserSettingScrollWidget");
|
|
|
|
scrollAreaContents_->setLayout(mainLayout_);
|
|
|
|
|
|
|
|
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()); });
|
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);
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
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());
|
2018-01-14 16:57:58 +03:00
|
|
|
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
|
2018-03-11 18:56:40 +03:00
|
|
|
readReceipts_->setState(!settings_->isReadReceiptsEnabled());
|
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
|
|
|
|
UserSettingsPage::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
sideMargin_ = width() * 0.2;
|
|
|
|
mainLayout_->setContentsMargins(
|
|
|
|
sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin);
|
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
}
|
2017-11-22 20:52:38 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sessions File"), "", "");
|
|
|
|
|
|
|
|
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 {
|
|
|
|
auto sessions = mtx::crypto::decrypt_exported_sessions(
|
|
|
|
mtx::crypto::base642bin(payload), password.toStdString());
|
|
|
|
cache::client()->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.
|
|
|
|
auto fileName =
|
|
|
|
QFileDialog::getSaveFileName(this, tr("File to save the exported session keys"), "", "");
|
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), file.errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export sessions & save to file.
|
|
|
|
try {
|
|
|
|
auto encrypted_blob = mtx::crypto::encrypt_exported_sessions(
|
|
|
|
cache::client()->exportSessionKeys(), password.toStdString());
|
|
|
|
|
|
|
|
auto b64 = mtx::crypto::bin2base64(encrypted_blob);
|
|
|
|
|
|
|
|
file.write(b64.data(), b64.size());
|
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());
|
|
|
|
}
|
|
|
|
}
|