Browse Source

Merge pull request #10076 from Chocobo1/pr_9756

Prevent flickering preview dialog
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
3772968f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/gui/previewselectdialog.cpp
  2. 5
      src/gui/previewselectdialog.h
  3. 18
      src/gui/transferlistwidget.cpp

5
src/gui/previewselectdialog.cpp

@ -35,6 +35,7 @@
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QTableView> #include <QTableView>
#include "base/bittorrent/torrenthandle.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
@ -93,10 +94,6 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
} }
} }
if (m_previewListModel->rowCount() == 0) {
QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close();
}
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString))); connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString)));
m_previewListModel->sort(NAME); m_previewListModel->sort(NAME);
previewList->header()->setSortIndicator(0, Qt::AscendingOrder); previewList->header()->setSortIndicator(0, Qt::AscendingOrder);

5
src/gui/previewselectdialog.h

@ -31,12 +31,15 @@
#include <QDialog> #include <QDialog>
#include "base/bittorrent/torrenthandle.h"
#include "base/settingvalue.h" #include "base/settingvalue.h"
#include "ui_previewselectdialog.h" #include "ui_previewselectdialog.h"
class QStandardItemModel; class QStandardItemModel;
namespace BitTorrent
{
class TorrentHandle;
}
class PreviewListDelegate; class PreviewListDelegate;
class PreviewSelectDialog : public QDialog, private Ui::preview class PreviewSelectDialog : public QDialog, private Ui::preview

18
src/gui/transferlistwidget.cpp

@ -48,6 +48,7 @@
#include "base/preferences.h" #include "base/preferences.h"
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#include "deletionconfirmationdialog.h" #include "deletionconfirmationdialog.h"
@ -198,6 +199,19 @@ namespace
setDefaultWidget(new MenuCheckBox(text, onToggle, initialState)); setDefaultWidget(new MenuCheckBox(text, onToggle, initialState));
} }
}; };
bool torrentContainsPreviewableFiles(const BitTorrent::TorrentHandle *const torrent)
{
if (!torrent->hasMetadata())
return false;
for (int i = 0; i < torrent->filesCount(); ++i) {
if (Utils::Misc::isPreviewable(Utils::Fs::fileExtension(torrent->fileName(i))))
return true;
}
return false;
}
} }
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
@ -589,8 +603,10 @@ void TransferListWidget::openSelectedTorrentsFolder() const
void TransferListWidget::previewSelectedTorrents() void TransferListWidget::previewSelectedTorrents()
{ {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) { for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->hasMetadata()) if (torrentContainsPreviewableFiles(torrent))
new PreviewSelectDialog(this, torrent); new PreviewSelectDialog(this, torrent);
else
QMessageBox::critical(this, tr("Unable to preview"), tr("The selected torrent does not contain previewable files"));
} }
} }

Loading…
Cancel
Save