From c2701c00dd17b4e2fe01ad51c56e5c68d609f494 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 7 May 2024 21:45:57 +0200 Subject: [PATCH] plugins: remove reddit --- CMakeLists.txt | 1 - src/SettingsDialog.cpp | 7 -- src/SettingsDialog.ui | 42 --------- src/dialog/AboutDialog.ui | 4 +- src/plugins/reddit/RedditModel.cpp | 108 ------------------------ src/plugins/reddit/RedditModel.h | 41 --------- src/plugins/reddit/RedditPlugin.cpp | 59 ------------- src/plugins/reddit/RedditPlugin.h | 39 --------- src/plugins/reddit/RedditPost.h | 19 ----- src/plugins/reddit/RedditProxyModel.cpp | 10 --- src/plugins/reddit/RedditProxyModel.h | 17 ---- src/plugins/reddit/RedditWidget.cpp | 99 ---------------------- src/plugins/reddit/RedditWidget.h | 44 ---------- src/plugins/reddit/RedditWidget.ui | 61 ------------- src/utils/config.cpp | 3 +- src/utils/config.h | 1 - 16 files changed, 3 insertions(+), 552 deletions(-) delete mode 100644 src/plugins/reddit/RedditModel.cpp delete mode 100644 src/plugins/reddit/RedditModel.h delete mode 100644 src/plugins/reddit/RedditPlugin.cpp delete mode 100644 src/plugins/reddit/RedditPlugin.h delete mode 100644 src/plugins/reddit/RedditPost.h delete mode 100644 src/plugins/reddit/RedditProxyModel.cpp delete mode 100644 src/plugins/reddit/RedditProxyModel.h delete mode 100644 src/plugins/reddit/RedditWidget.cpp delete mode 100644 src/plugins/reddit/RedditWidget.h delete mode 100644 src/plugins/reddit/RedditWidget.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 7418190..6023cfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ option(WITH_PLUGIN_HOME "Include Home tab plugin" ON) option(WITH_PLUGIN_TICKERS "Include Tickers Home plugin" ON) option(WITH_PLUGIN_CROWDFUNDING "Include Crowdfunding Home plugin" ON) option(WITH_PLUGIN_BOUNTIES "Include Bounties Home plugin" ON) -option(WITH_PLUGIN_REDDIT "Include Reddit Home plugin" ON) option(WITH_PLUGIN_REVUO "Include Revuo Home plugin" ON) option(WITH_PLUGIN_CALC "Include Calc tab plugin" ON) option(WITH_PLUGIN_XMRIG "Include XMRig plugin" ON) diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 03248bd..cbdd3d3 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -352,13 +352,6 @@ void Settings::setupPluginsTab() { void Settings::setupMiscTab() { // [Block explorer] ui->blockExplorerConfigureWidget->setup("Block explorers", Config::blockExplorers, Config::blockExplorer, {"%txid%"}); - - // [Reddit frontend] - ui->comboBox_redditFrontend->setCurrentIndex(ui->comboBox_redditFrontend->findText(conf()->get(Config::redditFrontend).toString())); - connect(ui->comboBox_redditFrontend, QOverload::of(&QComboBox::currentIndexChanged), [this]{ - QString redditFrontend = ui->comboBox_redditFrontend->currentText(); - conf()->set(Config::redditFrontend, redditFrontend); - }); } void Settings::onProxySettingsChanged() { diff --git a/src/SettingsDialog.ui b/src/SettingsDialog.ui index 71dece5..578dfa7 100644 --- a/src/SettingsDialog.ui +++ b/src/SettingsDialog.ui @@ -1067,48 +1067,6 @@ - - - - - 0 - 0 - - - - Reddit frontend: - - - - - - - - old.reddit.com - - - - - old.reddittorjg6rue252oqsxryoxengawnmo46qy4kyii5wtqnwfj4ooad.onion - - - - - reddit.com - - - - - reddittorjg6rue252oqsxryoxengawnmo46qy4kyii5wtqnwfj4ooad.onion - - - - - teddit.net - - - - diff --git a/src/dialog/AboutDialog.ui b/src/dialog/AboutDialog.ui index 35e6e31..d5a7162 100644 --- a/src/dialog/AboutDialog.ui +++ b/src/dialog/AboutDialog.ui @@ -100,7 +100,7 @@ - Reddit: + Lemmy: @@ -158,7 +158,7 @@ - /r/FeatherWallet + monero.town/c/featherwallet Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse diff --git a/src/plugins/reddit/RedditModel.cpp b/src/plugins/reddit/RedditModel.cpp deleted file mode 100644 index 85e6b44..0000000 --- a/src/plugins/reddit/RedditModel.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#include "RedditModel.h" - -RedditModel::RedditModel(QObject *parent) - : QAbstractTableModel(parent) -{ - -} - -void RedditModel::clear() { - beginResetModel(); - - m_posts.clear(); - - endResetModel(); -} - -void RedditModel::updatePosts(const QList>& posts) { - beginResetModel(); - - m_posts.clear(); - for (const auto& post : posts) { - m_posts.push_back(post); - } - - endResetModel(); -} - -int RedditModel::rowCount(const QModelIndex &parent) const{ - if (parent.isValid()) { - return 0; - } - return m_posts.count(); -} - -int RedditModel::columnCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - return ModelColumn::COUNT; -} - -QVariant RedditModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() < 0 || index.row() >= m_posts.count()) - return QVariant(); - - QSharedPointer post = m_posts.at(index.row()); - - if(role == Qt::DisplayRole || role == Qt::UserRole) { - switch(index.column()) { - case Title: - return post->title; - case Author: - return post->author; - case Comments: { - if (role == Qt::UserRole) { - return post->comments; - } - return QString::number(post->comments); - } - default: - return QVariant(); - } - } - else if (role == Qt::TextAlignmentRole) { - switch(index.column()) { - case Comments: - return Qt::AlignRight; - default: - return QVariant(); - } - } - return QVariant(); -} - -QVariant RedditModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole) { - return QVariant(); - } - if (orientation == Qt::Horizontal) - { - switch(section) { - case Title: - return QString("Reddit Post"); - case Author: - return QString("Author"); - case Comments: - return QString(" Comments "); - default: - return QVariant(); - } - } - return QVariant(); -} - -QSharedPointer RedditModel::post(int row) { - if (row < 0 || row >= m_posts.size()) { - qCritical("%s: no reddit post for index %d", __FUNCTION__, row); - return QSharedPointer(); - } - - return m_posts.at(row); -} \ No newline at end of file diff --git a/src/plugins/reddit/RedditModel.h b/src/plugins/reddit/RedditModel.h deleted file mode 100644 index c4db675..0000000 --- a/src/plugins/reddit/RedditModel.h +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#ifndef FEATHER_REDDITMODEL_H -#define FEATHER_REDDITMODEL_H - -#include -#include - -#include "RedditPost.h" - -class RedditModel : public QAbstractTableModel -{ -Q_OBJECT - -public: - enum ModelColumn - { - Title = 0, - Author, - Comments, - COUNT - }; - - explicit RedditModel(QObject *parent); - - int rowCount(const QModelIndex &parent) const override; - int columnCount(const QModelIndex &parent) const override; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - void clear(); - void updatePosts(const QList>& posts); - - QSharedPointer post(int row); - -private: - QList> m_posts; -}; - -#endif //FEATHER_REDDITMODEL_H diff --git a/src/plugins/reddit/RedditPlugin.cpp b/src/plugins/reddit/RedditPlugin.cpp deleted file mode 100644 index 7556a85..0000000 --- a/src/plugins/reddit/RedditPlugin.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#include "RedditPlugin.h" - -#include "plugins/PluginRegistry.h" -#include "RedditWidget.h" - -RedditPlugin::RedditPlugin() -{ -} - -void RedditPlugin::initialize(Wallet *wallet, QObject *parent) { - this->setParent(parent); - m_redditWidget = new RedditWidget(nullptr); - connect(m_redditWidget, &RedditWidget::setStatusText, this, &Plugin::setStatusText); -} - -QString RedditPlugin::id() { - return "reddit"; -} - -int RedditPlugin::idx() const { - return 30; -} - -QString RedditPlugin::parent() { - return "home"; -} - -QString RedditPlugin::displayName() { - return "Reddit"; -} - -QString RedditPlugin::description() { - return {}; -} - -QString RedditPlugin::icon() { - return {}; -} - -QStringList RedditPlugin::socketData() { - return {"reddit"}; -} - -Plugin::PluginType RedditPlugin::type() { - return Plugin::PluginType::TAB; -} - -QWidget* RedditPlugin::tab() { - return m_redditWidget; -} - -const bool RedditPlugin::registered = [] { - PluginRegistry::registerPlugin(RedditPlugin::create()); - PluginRegistry::getInstance().registerPluginCreator(&RedditPlugin::create); - return true; -}(); diff --git a/src/plugins/reddit/RedditPlugin.h b/src/plugins/reddit/RedditPlugin.h deleted file mode 100644 index 0b138eb..0000000 --- a/src/plugins/reddit/RedditPlugin.h +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#ifndef REDDITPLUGIN_H -#define REDDITPLUGIN_H - -#include "plugins/Plugin.h" -#include "RedditWidget.h" -#include "plugins/PluginRegistry.h" - -class RedditPlugin : public Plugin { - Q_OBJECT - -public: - explicit RedditPlugin(); - - QString id() override; - int idx() const override; - QString parent() override; - QString displayName() override; - QString description() override; - QString icon() override; - QStringList socketData() override; - PluginType type() override; - QWidget* tab() override; - - void initialize(Wallet *wallet, QObject *parent) override; - - static RedditPlugin* create() { return new RedditPlugin(); } - -private: - RedditWidget* m_redditWidget = nullptr; - static const bool registered; -}; - - - - -#endif //REDDITPLUGIN_H diff --git a/src/plugins/reddit/RedditPost.h b/src/plugins/reddit/RedditPost.h deleted file mode 100644 index 030c9ea..0000000 --- a/src/plugins/reddit/RedditPost.h +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#ifndef FEATHER_REDDITPOST_H -#define FEATHER_REDDITPOST_H - -#include - -struct RedditPost { - 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 permalink; - int comments; -}; - -#endif //FEATHER_REDDITPOST_H diff --git a/src/plugins/reddit/RedditProxyModel.cpp b/src/plugins/reddit/RedditProxyModel.cpp deleted file mode 100644 index bbd9c98..0000000 --- a/src/plugins/reddit/RedditProxyModel.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#include "RedditProxyModel.h" - -RedditProxyModel::RedditProxyModel(QObject *parent) - : QSortFilterProxyModel(parent) -{ - setSortRole(Qt::UserRole); -} diff --git a/src/plugins/reddit/RedditProxyModel.h b/src/plugins/reddit/RedditProxyModel.h deleted file mode 100644 index 4526a9d..0000000 --- a/src/plugins/reddit/RedditProxyModel.h +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#ifndef REDDITPROXYMODEL_H -#define REDDITPROXYMODEL_H - -#include - -class RedditProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - -public: - explicit RedditProxyModel(QObject* parent = nullptr); -}; - -#endif //REDDITPROXYMODEL_H diff --git a/src/plugins/reddit/RedditWidget.cpp b/src/plugins/reddit/RedditWidget.cpp deleted file mode 100644 index 8067de7..0000000 --- a/src/plugins/reddit/RedditWidget.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#include "RedditWidget.h" -#include "ui_RedditWidget.h" - -#include - -#include "RedditModel.h" -#include "utils/Utils.h" -#include "utils/config.h" -#include "utils/WebsocketNotifier.h" - -RedditWidget::RedditWidget(QWidget *parent) - : QWidget(parent) - , ui(new Ui::RedditWidget) - , m_model(new RedditModel(this)) - , m_contextMenu(new QMenu(this)) -{ - ui->setupUi(this); - - m_proxyModel = new RedditProxyModel(this); - m_proxyModel->setSourceModel(m_model); - - ui->tableView->setModel(m_proxyModel); - ui->tableView->setSortingEnabled(true); - ui->tableView->sortByColumn(2, Qt::DescendingOrder); - this->setupTable(); - - m_contextMenu->addAction("View thread", this, &RedditWidget::linkClicked); - m_contextMenu->addAction("Copy link", this, &RedditWidget::copyUrl); - connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &RedditWidget::showContextMenu); - - connect(ui->tableView, &QTableView::doubleClicked, this, &RedditWidget::linkClicked); - - ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - - connect(websocketNotifier(), &WebsocketNotifier::dataReceived, this, [this](const QString& type, const QJsonValue& json) { - if (type == "reddit") { - QJsonArray reddit_data = json.toArray(); - QList> l; - - for (auto &&entry: reddit_data) { - auto obj = entry.toObject(); - auto redditPost = new RedditPost( - obj.value("title").toString(), - obj.value("author").toString(), - obj.value("permalink").toString(), - obj.value("comments").toInt()); - QSharedPointer r = QSharedPointer(redditPost); - l.append(r); - } - - m_model->updatePosts(l); - } - }); -} - -void RedditWidget::linkClicked() { - QModelIndex index = m_proxyModel->mapToSource(ui->tableView->currentIndex()); - auto post = m_model->post(index.row()); - - if (post) - Utils::externalLinkWarning(this, this->getLink(post->permalink)); -} - -void RedditWidget::copyUrl() { - QModelIndex index = m_proxyModel->mapToSource(ui->tableView->currentIndex()); - auto post = m_model->post(index.row()); - - if (post) { - Utils::copyToClipboard(this->getLink(post->permalink)); - emit setStatusText("Link copied to clipboard", true, 1000); - } -} - -void RedditWidget::setupTable() { - ui->tableView->verticalHeader()->setVisible(false); - ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - - ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->tableView->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch); -} - -void RedditWidget::showContextMenu(const QPoint &pos) { - QModelIndex index = ui->tableView->indexAt(pos); - if (!index.isValid()) { - return; - } - - m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos)); -} - -QString RedditWidget::getLink(const QString &permaLink) { - QString redditFrontend = conf()->get(Config::redditFrontend).toString(); - return QString("https://%1%2").arg(redditFrontend, permaLink); -} - -RedditWidget::~RedditWidget() = default; \ No newline at end of file diff --git a/src/plugins/reddit/RedditWidget.h b/src/plugins/reddit/RedditWidget.h deleted file mode 100644 index 98515a2..0000000 --- a/src/plugins/reddit/RedditWidget.h +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: 2020-2024 The Monero Project - -#ifndef FEATHER_REDDITWIDGET_H -#define FEATHER_REDDITWIDGET_H - -#include -#include -#include - -#include "RedditModel.h" -#include "RedditProxyModel.h" - -namespace Ui { - class RedditWidget; -} - -class RedditWidget : public QWidget -{ - Q_OBJECT - -public: - explicit RedditWidget(QWidget *parent = nullptr); - ~RedditWidget(); - -public slots: - void linkClicked(); - -signals: - void setStatusText(const QString &msg, bool override, int timeout); - -private: - void setupTable(); - void showContextMenu(const QPoint &pos); - void copyUrl(); - QString getLink(const QString &permaLink); - - QScopedPointer ui; - RedditModel* const m_model; - RedditProxyModel* m_proxyModel; - QMenu *m_contextMenu; -}; - -#endif // FEATHER_REDDITWIDGET_H diff --git a/src/plugins/reddit/RedditWidget.ui b/src/plugins/reddit/RedditWidget.ui deleted file mode 100644 index ef63a43..0000000 --- a/src/plugins/reddit/RedditWidget.ui +++ /dev/null @@ -1,61 +0,0 @@ - - - RedditWidget - - - - 0 - 0 - 492 - 409 - - - - Form - - - - 4 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - false - - - - - - - - - linkClicked() - - diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 9e6cc6d..722eb55 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -104,7 +104,6 @@ static const QHash configStrings = { "http://blkchairbknpn73cfjhevhla7rkp4ed5gg2knctvv7it4lioy22defid.onion/monero/transaction/%txid%", "http://127.0.0.1:31312/tx?id=%txid%"}}}, {Config::blockExplorer,{QS("blockExplorer"), "https://xmrchain.net/tx/%txid%"}}, - {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}}, {Config::bountiesFrontend, {QS("bountiesFrontend"), "https://bounties.monero.social"}}, {Config::lastPath, {QS("lastPath"), QDir::homePath()}}, @@ -130,7 +129,7 @@ static const QHash configStrings = { {Config::useLocalTor, {QS("useLocalTor"), false}}, {Config::initSyncThreshold, {QS("initSyncThreshold"), 360}}, - {Config::enabledPlugins, {QS("enabledPlugins"), QStringList{"tickers", "crowdfunding", "bounties", "reddit", "revuo", "calc", "xmrig"}}}, + {Config::enabledPlugins, {QS("enabledPlugins"), QStringList{"tickers", "crowdfunding", "bounties", "revuo", "calc", "xmrig"}}}, {Config::restartRequired, {QS("restartRequired"), false}}, {Config::tickers, {QS("tickers"), QStringList{"XMR", "BTC", "XMR/BTC"}}}, diff --git a/src/utils/config.h b/src/utils/config.h index c76e946..215ec6b 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -127,7 +127,6 @@ public: // Misc blockExplorers, blockExplorer, - redditFrontend, bountiesFrontend, // unused lastPath,