mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
feat(NetworkJobFailedDialog): implement URL copying
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
7bb746dfab
commit
3a48d13c07
3 changed files with 42 additions and 7 deletions
|
|
@ -18,11 +18,14 @@
|
|||
|
||||
#include "NetworkJobFailedDialog.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QPushButton>
|
||||
#include <QShortcut>
|
||||
#include <utility>
|
||||
|
||||
#include "ui_NetworkJobFailedDialog.h"
|
||||
|
||||
#include <QTableWidgetItem>
|
||||
|
||||
NetworkJobFailedDialog::NetworkJobFailedDialog(QString jobName, int attempts, int requests, int failed, QWidget* parent)
|
||||
NetworkJobFailedDialog::NetworkJobFailedDialog(const QString& jobName, const int attempts, const int requests, const int failed, QWidget* parent)
|
||||
: QDialog(parent), m_ui(new Ui::NetworkJobFailedDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
|
@ -40,6 +43,12 @@ NetworkJobFailedDialog::NetworkJobFailedDialog(QString jobName, int attempts, in
|
|||
m_ui->detailsTable->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
m_ui->detailsTable->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
|
||||
const auto* copyShortcut = new QShortcut(QKeySequence::Copy, m_ui->detailsTable);
|
||||
connect(copyShortcut, &QShortcut::activated, this, &NetworkJobFailedDialog::copyUrl);
|
||||
|
||||
const auto* copyButton = m_ui->dialogButtonBox->addButton(tr("Copy URL"), QDialogButtonBox::ActionRole);
|
||||
connect(copyButton, &QPushButton::clicked, this, &NetworkJobFailedDialog::copyUrl);
|
||||
|
||||
connect(m_ui->dialogButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(m_ui->dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
|
@ -49,8 +58,22 @@ NetworkJobFailedDialog::~NetworkJobFailedDialog()
|
|||
delete m_ui;
|
||||
}
|
||||
|
||||
void NetworkJobFailedDialog::addFailedRequest(QUrl url, QString error) const
|
||||
void NetworkJobFailedDialog::addFailedRequest(const QUrl& url, QString error) const
|
||||
{
|
||||
auto item = new QTreeWidgetItem(m_ui->detailsTable, { url.toString(), error });
|
||||
auto* item = new QTreeWidgetItem(m_ui->detailsTable, { url.toString(), std::move(error) });
|
||||
m_ui->detailsTable->addTopLevelItem(item);
|
||||
if (m_ui->detailsTable->selectedItems().isEmpty()) {
|
||||
m_ui->detailsTable->setCurrentItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkJobFailedDialog::copyUrl() const
|
||||
{
|
||||
auto items = m_ui->detailsTable->selectedItems();
|
||||
if (items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(items.first()->text(0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,13 @@ class NetworkJobFailedDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NetworkJobFailedDialog(QString jobName, int attempts, int requests, int failed, QWidget* parent = nullptr);
|
||||
explicit NetworkJobFailedDialog(const QString& jobName, int attempts, int requests, int failed, QWidget* parent = nullptr);
|
||||
~NetworkJobFailedDialog() override;
|
||||
|
||||
void addFailedRequest(QUrl url, QString error) const;
|
||||
void addFailedRequest(const QUrl& url, QString error) const;
|
||||
|
||||
private slots:
|
||||
void copyUrl() const;
|
||||
|
||||
private:
|
||||
Ui::NetworkJobFailedDialog* m_ui;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,15 @@
|
|||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollMode::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue