mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-10 04:11:16 +00:00
Add progress indicator for metadata retrieval
This commit is contained in:
parent
8ca7603f38
commit
c8cc727aea
@ -63,6 +63,11 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|||||||
m_hasRenamedFile(false)
|
m_hasRenamedFile(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
m_progress = new QProgressBar(this);
|
||||||
|
m_progress->setMinimum(0);
|
||||||
|
m_progress->setMaximum(0);
|
||||||
|
ui->lblMetaLoading->setVisible(false);
|
||||||
|
ui->buttonsHLayout->insertWidget(ui->buttonsHLayout->indexOf(ui->lblMetaLoading), m_progress);
|
||||||
|
|
||||||
QIniSettings settings;
|
QIniSettings settings;
|
||||||
Preferences pref;
|
Preferences pref;
|
||||||
@ -91,6 +96,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|||||||
AddNewTorrentDialog::~AddNewTorrentDialog()
|
AddNewTorrentDialog::~AddNewTorrentDialog()
|
||||||
{
|
{
|
||||||
saveState();
|
saveState();
|
||||||
|
delete m_progress;
|
||||||
delete ui;
|
delete ui;
|
||||||
if (m_contentModel)
|
if (m_contentModel)
|
||||||
delete m_contentModel;
|
delete m_contentModel;
|
||||||
@ -254,6 +260,13 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent showing the dialog if download is already present
|
||||||
|
if (QBtSession::instance()->getTorrentHandle(m_hash).is_valid()) {
|
||||||
|
QMessageBox::information(0, tr("Already in download list"), tr("Magnet link is already in download list."), QMessageBox::Ok);
|
||||||
|
QBtSession::instance()->addMagnetUri(m_url, false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set dialog title
|
// Set dialog title
|
||||||
QString torrent_name = misc::magnetUriToName(m_url);
|
QString torrent_name = misc::magnetUriToName(m_url);
|
||||||
setWindowTitle(torrent_name.isEmpty() ? tr("Magnet link") : torrent_name);
|
setWindowTitle(torrent_name.isEmpty() ? tr("Magnet link") : torrent_name);
|
||||||
@ -274,6 +287,7 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri)
|
|||||||
|
|
||||||
QBtSession::instance()->addMagnetUri(m_url, false);
|
QBtSession::instance()->addMagnetUri(m_url, false);
|
||||||
QBtSession::instance()->resumeTorrent(m_hash);
|
QBtSession::instance()->resumeTorrent(m_hash);
|
||||||
|
setMetadataProgressIndicator(true, tr("Retrieving metadata..."));
|
||||||
|
|
||||||
// Restore addInPause setting
|
// Restore addInPause setting
|
||||||
pref.addTorrentsInPause(old_addInPause);
|
pref.addTorrentsInPause(old_addInPause);
|
||||||
@ -645,6 +659,8 @@ void AddNewTorrentDialog::reject() {
|
|||||||
if (!m_convertingMagnet)
|
if (!m_convertingMagnet)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
setMetadataProgressIndicator(false);
|
||||||
|
QBtSession::instance()->deleteTorrent(m_hash, true);
|
||||||
}
|
}
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
}
|
}
|
||||||
@ -664,6 +680,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
|||||||
if (!QFile::exists(m_filePath)) {
|
if (!QFile::exists(m_filePath)) {
|
||||||
QMessageBox::warning(0, tr("I/O Error"), tr("Failed to save metadata.\nFile list will be unavailable."));
|
QMessageBox::warning(0, tr("I/O Error"), tr("Failed to save metadata.\nFile list will be unavailable."));
|
||||||
m_convertingMagnet = false;
|
m_convertingMagnet = false;
|
||||||
|
setMetadataProgressIndicator(false, tr("Failed to save metadata"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,11 +690,13 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
|||||||
} catch(const std::exception&) {
|
} catch(const std::exception&) {
|
||||||
QMessageBox::critical(0, tr("Invalid metadata"), tr("Metadata corrupted.\nFile list will be unavailable."));
|
QMessageBox::critical(0, tr("Invalid metadata"), tr("Metadata corrupted.\nFile list will be unavailable."));
|
||||||
m_convertingMagnet = false;
|
m_convertingMagnet = false;
|
||||||
|
setMetadataProgressIndicator(false, tr("Invalid metadata"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QBtSession::instance()->deleteTorrent(m_hash, true);
|
QBtSession::instance()->deleteTorrent(m_hash, true);
|
||||||
// Good to go
|
// Good to go
|
||||||
m_hasMetadata = true;
|
m_hasMetadata = true;
|
||||||
|
setMetadataProgressIndicator(true, tr("Parsing metadata..."));
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
// Set dialog title
|
// Set dialog title
|
||||||
@ -736,8 +755,23 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
|||||||
// Set dialog position
|
// Set dialog position
|
||||||
setdialogPosition();
|
setdialogPosition();
|
||||||
m_convertingMagnet = false;
|
m_convertingMagnet = false;
|
||||||
|
setMetadataProgressIndicator(false, tr("Metadata retrieval complete"));
|
||||||
} catch (invalid_handle&) {
|
} catch (invalid_handle&) {
|
||||||
QMessageBox::critical(0, tr("I/O Error"), ("Unknown error."));
|
QMessageBox::critical(0, tr("I/O Error"), ("Unknown error."));
|
||||||
|
setMetadataProgressIndicator(false, tr("Unknown error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddNewTorrentDialog::setMetadataProgressIndicator(bool enabled, const QString &labelText) {
|
||||||
|
// Always show info label when waiting for metadata
|
||||||
|
ui->lblMetaLoading->setVisible(true);
|
||||||
|
ui->lblMetaLoading->setText(labelText);
|
||||||
|
if (enabled)
|
||||||
|
m_progress->setEnabled(enabled);
|
||||||
|
else {
|
||||||
|
m_progress->setMaximum(1);
|
||||||
|
m_progress->setValue(1);
|
||||||
|
m_progress->setTextVisible(false); // Don't display %% completed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
#include "qtorrenthandle.h"
|
#include "qtorrenthandle.h"
|
||||||
|
#include <QProgressBar>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -80,6 +81,7 @@ private:
|
|||||||
void updateFileNameInSavePaths(const QString& new_filename);
|
void updateFileNameInSavePaths(const QString& new_filename);
|
||||||
void loadState();
|
void loadState();
|
||||||
void saveState();
|
void saveState();
|
||||||
|
void setMetadataProgressIndicator(bool enabled, const QString &labelText = QString());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AddNewTorrentDialog *ui;
|
Ui::AddNewTorrentDialog *ui;
|
||||||
@ -95,6 +97,7 @@ private:
|
|||||||
QStringList m_filesPath;
|
QStringList m_filesPath;
|
||||||
bool m_hasRenamedFile;
|
bool m_hasRenamedFile;
|
||||||
QShortcut *editHotkey;
|
QShortcut *editHotkey;
|
||||||
|
QProgressBar *m_progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADDNEWTORRENTDIALOG_H
|
#endif // ADDNEWTORRENTDIALOG_H
|
||||||
|
@ -186,6 +186,16 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="buttonsHLayout">
|
<layout class="QHBoxLayout" name="buttonsHLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lblMetaLoading">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user