Add reddit frontend setting

This commit is contained in:
tobtoht 2020-12-30 03:48:10 +01:00
parent 94a53abb00
commit 5cf37918e7
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
8 changed files with 50 additions and 10 deletions

View file

@ -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<RedditPost> r = QSharedPointer<RedditPost>(redditPost);
l.append(r);

View file

@ -45,6 +45,7 @@ Settings::Settings(QWidget *parent) :
connect(ui->comboBox_skin, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_skinChanged);
connect(ui->comboBox_blockExplorer, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_blockExplorerChanged);
connect(ui->comboBox_redditFrontend, QOverload<int>::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();
}

View file

@ -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"};

View file

@ -161,20 +161,46 @@
</item>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox_externalLink">
<property name="text">
<string>Warn before opening external link</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox_hideBalance">
<property name="text">
<string>Hide balance</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Reddit frontend:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBox_redditFrontend">
<item>
<property name="text">
<string>old.reddit.com</string>
</property>
</item>
<item>
<property name="text">
<string>reddit.com</string>
</property>
</item>
<item>
<property name="text">
<string>teddit.net</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_node">

View file

@ -43,7 +43,8 @@ static const QHash<Config::ConfigKey, ConfigDirective> 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"}}
};

View file

@ -45,7 +45,8 @@ public:
geometry,
windowState,
firstRun,
hideBalance
hideBalance,
redditFrontend
};
~Config() override;

View file

@ -7,11 +7,12 @@
#include <QString>
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;
};

View file

@ -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);
}
}