mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-26 14:34:30 +00:00
Merge pull request #11317 from Chocobo1/preview
Fix "preview file" action not working
This commit is contained in:
commit
2fb1182700
@ -2205,7 +2205,7 @@ void TorrentHandle::setSuperSeeding(const bool enable)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::flushCache()
|
void TorrentHandle::flushCache() const
|
||||||
{
|
{
|
||||||
m_nativeHandle.flush_cache();
|
m_nativeHandle.flush_cache();
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ namespace BitTorrent
|
|||||||
void setUploadLimit(int limit);
|
void setUploadLimit(int limit);
|
||||||
void setDownloadLimit(int limit);
|
void setDownloadLimit(int limit);
|
||||||
void setSuperSeeding(bool enable);
|
void setSuperSeeding(bool enable);
|
||||||
void flushCache();
|
void flushCache() const;
|
||||||
void addTrackers(const QVector<TrackerEntry> &trackers);
|
void addTrackers(const QVector<TrackerEntry> &trackers);
|
||||||
void replaceTrackers(const QVector<TrackerEntry> &trackers);
|
void replaceTrackers(const QVector<TrackerEntry> &trackers);
|
||||||
void addUrlSeeds(const QVector<QUrl> &urlSeeds);
|
void addUrlSeeds(const QVector<QUrl> &urlSeeds);
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
#define SETTINGS_KEY(name) "PreviewSelectDialog/" name
|
#define SETTINGS_KEY(name) "PreviewSelectDialog/" name
|
||||||
|
|
||||||
PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent)
|
PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::TorrentHandle *torrent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::PreviewSelectDialog)
|
, m_ui(new Ui::PreviewSelectDialog)
|
||||||
, m_torrent(torrent)
|
, m_torrent(torrent)
|
||||||
@ -53,13 +53,15 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
|
|||||||
, m_storeTreeHeaderState(SETTINGS_KEY("HeaderState"))
|
, m_storeTreeHeaderState(SETTINGS_KEY("HeaderState"))
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
|
m_ui->label->setText(tr("The following files from torrent \"%1\" support previewing, please select one of them:")
|
||||||
|
.arg(m_torrent->name()));
|
||||||
|
|
||||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview"));
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview"));
|
||||||
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked);
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked);
|
||||||
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
Preferences *const pref = Preferences::instance();
|
const Preferences *pref = Preferences::instance();
|
||||||
// Preview list
|
// Preview list
|
||||||
m_previewListModel = new QStandardItemModel(0, NB_COLUMNS, this);
|
m_previewListModel = new QStandardItemModel(0, NB_COLUMNS, this);
|
||||||
m_previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name"));
|
m_previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name"));
|
||||||
@ -102,16 +104,6 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
|
|||||||
|
|
||||||
// Restore dialog state
|
// Restore dialog state
|
||||||
loadWindowState();
|
loadWindowState();
|
||||||
|
|
||||||
if (m_previewListModel->rowCount() == 1) {
|
|
||||||
qDebug("Torrent file only contains one file, no need to display selection dialog before preview");
|
|
||||||
// Only one file : no choice
|
|
||||||
previewButtonClicked();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("Displaying media file selection dialog for preview");
|
|
||||||
show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewSelectDialog::~PreviewSelectDialog()
|
PreviewSelectDialog::~PreviewSelectDialog()
|
||||||
@ -123,21 +115,27 @@ PreviewSelectDialog::~PreviewSelectDialog()
|
|||||||
|
|
||||||
void PreviewSelectDialog::previewButtonClicked()
|
void PreviewSelectDialog::previewButtonClicked()
|
||||||
{
|
{
|
||||||
QModelIndexList selectedIndexes = m_ui->previewList->selectionModel()->selectedRows(FILE_INDEX);
|
const QModelIndexList selectedIndexes = m_ui->previewList->selectionModel()->selectedRows(FILE_INDEX);
|
||||||
if (selectedIndexes.isEmpty()) return;
|
if (selectedIndexes.isEmpty()) return;
|
||||||
|
|
||||||
// Flush data
|
// Flush data
|
||||||
m_torrent->flushCache();
|
m_torrent->flushCache();
|
||||||
|
|
||||||
QStringList absolutePaths(m_torrent->absoluteFilePaths());
|
const QStringList absolutePaths = m_torrent->absoluteFilePaths();
|
||||||
// Only one file should be selected
|
// Only one file should be selected
|
||||||
QString path = absolutePaths.at(selectedIndexes.at(0).data().toInt());
|
const QString path = absolutePaths.at(selectedIndexes.at(0).data().toInt());
|
||||||
// File
|
// File
|
||||||
if (QFile::exists(path))
|
if (!QFile::exists(path)) {
|
||||||
emit readyToPreviewFile(path);
|
const bool isSingleFile = (m_previewListModel->rowCount() == 1);
|
||||||
else
|
QWidget *parent = isSingleFile ? this->parentWidget() : this;
|
||||||
QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file"));
|
QMessageBox::critical(parent, tr("Preview impossible")
|
||||||
|
, tr("Sorry, we can't preview this file: \"%1\".").arg(Utils::Fs::toNativePath(path)));
|
||||||
|
if (isSingleFile)
|
||||||
|
reject();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit readyToPreviewFile(path);
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,13 +160,21 @@ void PreviewSelectDialog::loadWindowState()
|
|||||||
|
|
||||||
void PreviewSelectDialog::showEvent(QShowEvent *event)
|
void PreviewSelectDialog::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
// event originated from system
|
||||||
|
if (event->spontaneous()) {
|
||||||
|
QDialog::showEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Default size, have to be called after show(), because width is needed
|
// Default size, have to be called after show(), because width is needed
|
||||||
// Set Name column width to 60% of TreeView
|
// Set Name column width to 60% of TreeView
|
||||||
if (!m_headerStateInitialized) {
|
if (!m_headerStateInitialized) {
|
||||||
int nameSize = (m_ui->previewList->size().width() * 0.6);
|
const int nameSize = (m_ui->previewList->size().width() * 0.6);
|
||||||
m_ui->previewList->header()->resizeSection(0, nameSize);
|
m_ui->previewList->header()->resizeSection(0, nameSize);
|
||||||
m_headerStateInitialized = true;
|
m_headerStateInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only one file, no choice
|
||||||
|
if (m_previewListModel->rowCount() <= 1)
|
||||||
|
previewButtonClicked();
|
||||||
}
|
}
|
||||||
|
@ -60,26 +60,25 @@ public:
|
|||||||
NB_COLUMNS
|
NB_COLUMNS
|
||||||
};
|
};
|
||||||
|
|
||||||
PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent);
|
PreviewSelectDialog(QWidget *parent, const BitTorrent::TorrentHandle *torrent);
|
||||||
~PreviewSelectDialog();
|
~PreviewSelectDialog();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void readyToPreviewFile(QString) const;
|
void readyToPreviewFile(QString) const;
|
||||||
|
|
||||||
protected:
|
|
||||||
void showEvent(QShowEvent *event) override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void previewButtonClicked();
|
void previewButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
void loadWindowState();
|
void loadWindowState();
|
||||||
void saveWindowState();
|
void saveWindowState();
|
||||||
|
|
||||||
Ui::PreviewSelectDialog *m_ui;
|
Ui::PreviewSelectDialog *m_ui;
|
||||||
QStandardItemModel *m_previewListModel;
|
QStandardItemModel *m_previewListModel;
|
||||||
PreviewListDelegate *m_listDelegate;
|
PreviewListDelegate *m_listDelegate;
|
||||||
BitTorrent::TorrentHandle *const m_torrent;
|
const BitTorrent::TorrentHandle *m_torrent;
|
||||||
bool m_headerStateInitialized = false;
|
bool m_headerStateInitialized = false;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
@ -16,9 +16,6 @@
|
|||||||
<layout class="QVBoxLayout">
|
<layout class="QVBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
|
||||||
<string>The following files support previewing, please select one of them:</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -504,13 +504,16 @@ void TransferListWidget::openSelectedTorrentsFolder() const
|
|||||||
|
|
||||||
void TransferListWidget::previewSelectedTorrents()
|
void TransferListWidget::previewSelectedTorrents()
|
||||||
{
|
{
|
||||||
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
|
for (const BitTorrent::TorrentHandle *torrent : asConst(getSelectedTorrents())) {
|
||||||
if (torrentContainsPreviewableFiles(torrent)) {
|
if (torrentContainsPreviewableFiles(torrent)) {
|
||||||
const auto *dialog = new PreviewSelectDialog(this, torrent);
|
auto *dialog = new PreviewSelectDialog(this, torrent);
|
||||||
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile);
|
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile);
|
||||||
|
dialog->show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::critical(this, tr("Unable to preview"), tr("The selected torrent does not contain previewable files"));
|
QMessageBox::critical(this, tr("Unable to preview"), tr("The selected torrent \"%1\" does not contain previewable files")
|
||||||
|
.arg(torrent->name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user