From 5cf37918e78d2d5e5c7c07de3c2e6bdc928f112a Mon Sep 17 00:00:00 2001 From: tobtoht Date: Wed, 30 Dec 2020 03:48:10 +0100 Subject: [PATCH] Add reddit frontend setting --- src/appcontext.cpp | 2 +- src/settings.cpp | 6 ++++++ src/settings.h | 3 ++- src/settings.ui | 30 ++++++++++++++++++++++++++++-- src/utils/config.cpp | 3 ++- src/utils/config.h | 3 ++- src/widgets/RedditPost.h | 5 +++-- src/widgets/redditwidget.cpp | 8 ++++++-- 8 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 8a02dba..67cca12 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -468,7 +468,7 @@ void AppContext::onWSReddit(const QJsonArray& reddit_data) { auto redditPost = new RedditPost( obj.value("title").toString(), obj.value("author").toString(), - obj.value("url").toString(), + obj.value("permalink").toString(), obj.value("comments").toInt()); QSharedPointer r = QSharedPointer(redditPost); l.append(r); diff --git a/src/settings.cpp b/src/settings.cpp index 6d86ae3..af314e5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -45,6 +45,7 @@ Settings::Settings(QWidget *parent) : connect(ui->comboBox_skin, QOverload::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_skinChanged); connect(ui->comboBox_blockExplorer, QOverload::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_blockExplorerChanged); + connect(ui->comboBox_redditFrontend, QOverload::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_redditFrontendChanged); // setup preferred fiat currency combobox QStringList fiatCurrencies; @@ -94,6 +95,11 @@ void Settings::comboBox_blockExplorerChanged(int pos) { emit blockExplorerChanged(blockExplorer); } +void Settings::comboBox_redditFrontendChanged(int pos) { + QString redditFrontend = ui->comboBox_redditFrontend->currentText(); + config()->set(Config::redditFrontend, redditFrontend); +} + void Settings::copyToClipboard() { ui->textLogs->copy(); } diff --git a/src/settings.h b/src/settings.h index e86b86d..86b8c5c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -36,7 +36,8 @@ public slots: void checkboxExternalLinkWarn(); void fiatCurrencySelected(int index); void comboBox_skinChanged(int pos); - void comboBox_blockExplorerChanged(int post); + void comboBox_blockExplorerChanged(int pos); + void comboBox_redditFrontendChanged(int pos); private: QStringList m_skins{"Native", "QDarkStyle", "Breeze/Dark", "Breeze/Light"}; diff --git a/src/settings.ui b/src/settings.ui index a3945ad..9f0fb4b 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -161,20 +161,46 @@ - + Warn before opening external link - + Hide balance + + + + Reddit frontend: + + + + + + + + old.reddit.com + + + + + reddit.com + + + + + teddit.net + + + + diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 7c6ad53..6938a46 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -43,7 +43,8 @@ static const QHash configStrings = { {Config::geometry, {QS("geometry"), {}}}, {Config::windowState, {QS("windowState"), {}}}, {Config::firstRun,{QS("firstRun"), false}}, - {Config::hideBalance, {QS("hideBalance"), false}} + {Config::hideBalance, {QS("hideBalance"), false}}, + {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}} }; diff --git a/src/utils/config.h b/src/utils/config.h index caa4e8b..eb8e9cb 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -45,7 +45,8 @@ public: geometry, windowState, firstRun, - hideBalance + hideBalance, + redditFrontend }; ~Config() override; diff --git a/src/widgets/RedditPost.h b/src/widgets/RedditPost.h index bde0d69..221db91 100644 --- a/src/widgets/RedditPost.h +++ b/src/widgets/RedditPost.h @@ -7,11 +7,12 @@ #include struct RedditPost { - RedditPost(const QString &title, const QString &author, const QString &url, int comments) : title(title), author(author), url(url), comments(comments){}; + RedditPost(const QString &title, const QString &author, const QString &permalink, int comments) + : title(title), author(author), permalink(permalink), comments(comments){}; QString title; QString author; - QString url; + QString permalink; int comments; }; diff --git a/src/widgets/redditwidget.cpp b/src/widgets/redditwidget.cpp index 778ad1a..a074ff5 100644 --- a/src/widgets/redditwidget.cpp +++ b/src/widgets/redditwidget.cpp @@ -9,6 +9,7 @@ #include "redditwidget.h" #include "ui_redditwidget.h" #include "utils/utils.h" +#include "utils/config.h" RedditWidget::RedditWidget(QWidget *parent) : QWidget(parent), @@ -36,8 +37,11 @@ void RedditWidget::linkClicked() { QModelIndex index = ui->tableView->currentIndex(); auto post = m_model->post(index.row()); - if (post) { - Utils::externalLinkWarning(this, post->url); + if (post != nullptr) { + QString redditFrontend = config()->get(Config::redditFrontend).toString(); + QString link = QString("https://%1%2").arg(redditFrontend, post->permalink); + + Utils::externalLinkWarning(this, link); } }