mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Reddit: copy link
This commit is contained in:
		
							parent
							
								
									c399bc1068
								
							
						
					
					
						commit
						ac598bb801
					
				
					 4 changed files with 40 additions and 8 deletions
				
			
		| 
						 | 
					@ -177,6 +177,8 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
 | 
				
			||||||
    connect(m_ctx, &AppContext::ccsUpdated, ui->ccsWidget->model(), &CCSModel::updateEntries);
 | 
					    connect(m_ctx, &AppContext::ccsUpdated, ui->ccsWidget->model(), &CCSModel::updateEntries);
 | 
				
			||||||
    connect(m_ctx, &AppContext::redditUpdated, ui->redditWidget->model(), &RedditModel::updatePosts);
 | 
					    connect(m_ctx, &AppContext::redditUpdated, ui->redditWidget->model(), &RedditModel::updatePosts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    connect(ui->redditWidget, &RedditWidget::setStatusText, this, &MainWindow::setStatusText);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connect(ui->tabHomeWidget, &QTabWidget::currentChanged, [](int index){
 | 
					    connect(ui->tabHomeWidget, &QTabWidget::currentChanged, [](int index){
 | 
				
			||||||
        config()->set(Config::homeWidget, TabsHome(index));
 | 
					        config()->set(Config::homeWidget, TabsHome(index));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
| 
						 | 
					@ -675,10 +677,22 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
 | 
				
			||||||
    m_balanceWidget->setHidden(hide);
 | 
					    m_balanceWidget->setHidden(hide);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::setStatusText(const QString &text) {
 | 
					void MainWindow::setStatusText(const QString &text, bool override, int timeout) {
 | 
				
			||||||
    m_statusText = text;
 | 
					    if (override) {
 | 
				
			||||||
    if (!m_constructingTransaction)
 | 
					        m_statusOverrideActive = true;
 | 
				
			||||||
        m_statusLabelStatus->setText(text);
 | 
					        m_statusLabelStatus->setText(text);
 | 
				
			||||||
 | 
					        QTimer::singleShot(timeout, [this]{
 | 
				
			||||||
 | 
					            m_statusOverrideActive = false;
 | 
				
			||||||
 | 
					            this->setStatusText(m_statusText);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_statusText = text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!m_statusOverrideActive && !m_constructingTransaction) {
 | 
				
			||||||
 | 
					        m_statusLabelStatus->setText(text);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::onSynchronized() {
 | 
					void MainWindow::onSynchronized() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -169,7 +169,7 @@ private:
 | 
				
			||||||
    void updatePasswordIcon();
 | 
					    void updatePasswordIcon();
 | 
				
			||||||
    void updateNetStats();
 | 
					    void updateNetStats();
 | 
				
			||||||
    void rescanSpent();
 | 
					    void rescanSpent();
 | 
				
			||||||
    void setStatusText(const QString &text);
 | 
					    void setStatusText(const QString &text, bool override = false, int timeout = 1000);
 | 
				
			||||||
    void showBalanceDialog();
 | 
					    void showBalanceDialog();
 | 
				
			||||||
    QString statusDots();
 | 
					    QString statusDots();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -222,6 +222,7 @@ private:
 | 
				
			||||||
    QString m_statusText;
 | 
					    QString m_statusText;
 | 
				
			||||||
    int m_statusDots;
 | 
					    int m_statusDots;
 | 
				
			||||||
    bool m_constructingTransaction = false;
 | 
					    bool m_constructingTransaction = false;
 | 
				
			||||||
 | 
					    bool m_statusOverrideActive = false;
 | 
				
			||||||
    QTimer m_txTimer;
 | 
					    QTimer m_txTimer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ RedditWidget::RedditWidget(QWidget *parent) :
 | 
				
			||||||
    this->setupTable();
 | 
					    this->setupTable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_contextMenu->addAction("View thread", this, &RedditWidget::linkClicked);
 | 
					    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, &QHeaderView::customContextMenuRequested, this, &RedditWidget::showContextMenu);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connect(ui->tableView, &QTableView::doubleClicked, this, &RedditWidget::linkClicked);
 | 
					    connect(ui->tableView, &QTableView::doubleClicked, this, &RedditWidget::linkClicked);
 | 
				
			||||||
| 
						 | 
					@ -37,11 +38,17 @@ void RedditWidget::linkClicked() {
 | 
				
			||||||
    QModelIndex index = ui->tableView->currentIndex();
 | 
					    QModelIndex index = ui->tableView->currentIndex();
 | 
				
			||||||
    auto post = m_model->post(index.row());
 | 
					    auto post = m_model->post(index.row());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (post != nullptr) {
 | 
					    if (post)
 | 
				
			||||||
        QString redditFrontend = config()->get(Config::redditFrontend).toString();
 | 
					        Utils::externalLinkWarning(this, this->getLink(post->permalink));
 | 
				
			||||||
        QString link = QString("https://%1%2").arg(redditFrontend, post->permalink);
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Utils::externalLinkWarning(this, link);
 | 
					void RedditWidget::copyUrl() {
 | 
				
			||||||
 | 
					    QModelIndex index = 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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +69,11 @@ void RedditWidget::showContextMenu(const QPoint &pos) {
 | 
				
			||||||
    m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
 | 
					    m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString RedditWidget::getLink(const QString &permaLink) {
 | 
				
			||||||
 | 
					    QString redditFrontend = config()->get(Config::redditFrontend).toString();
 | 
				
			||||||
 | 
					    return QString("https://%1%2").arg(redditFrontend, permaLink);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RedditWidget::~RedditWidget() {
 | 
					RedditWidget::~RedditWidget() {
 | 
				
			||||||
    delete ui;
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,9 +26,14 @@ public:
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
    void linkClicked();
 | 
					    void linkClicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					signals:
 | 
				
			||||||
 | 
					    void setStatusText(const QString &msg, bool override, int timeout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void setupTable();
 | 
					    void setupTable();
 | 
				
			||||||
    void showContextMenu(const QPoint &pos);
 | 
					    void showContextMenu(const QPoint &pos);
 | 
				
			||||||
 | 
					    void copyUrl();
 | 
				
			||||||
 | 
					    QString getLink(const QString &permaLink);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ui::RedditWidget *ui;
 | 
					    Ui::RedditWidget *ui;
 | 
				
			||||||
    RedditModel* const m_model;
 | 
					    RedditModel* const m_model;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue