Browse Source

Preview now correctly uses the selected file. Closes #1222 #1182.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
5512576022
  1. 26
      src/previewselect.cpp
  2. 3
      src/previewselect.h

26
src/previewselect.cpp

@ -52,6 +52,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent) @@ -52,6 +52,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
previewList->setModel(previewListModel);
previewList->hideColumn(FILE_INDEX);
listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate);
previewList->header()->resizeSection(0, 200);
@ -71,7 +72,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent) @@ -71,7 +72,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName));
previewListModel->setData(previewListModel->index(row, SIZE), QVariant((qlonglong)h.filesize_at(i)));
previewListModel->setData(previewListModel->index(row, PROGRESS), QVariant((double)fp[i]/h.filesize_at(i)));
indexes << i;
previewListModel->setData(previewListModel->index(row, FILE_INDEX), QVariant(i));
}
}
@ -104,26 +105,19 @@ PreviewSelect::~PreviewSelect() { @@ -104,26 +105,19 @@ PreviewSelect::~PreviewSelect() {
void PreviewSelect::on_previewButton_clicked() {
QModelIndex index;
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME);
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.size() == 0) return;
// Flush data
h.flush_cache();
QStringList absolute_paths(h.absolute_files_path());
QString path;
foreach (index, selectedIndexes) {
path = absolute_paths.at(indexes.at(index.row()));
// File
if (QFile::exists(path)) {
emit readyToPreviewFile(path);
} else {
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
}
close();
return;
}
qDebug("Cannot find file: %s", path.toLocal8Bit().data());
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
//only one file should be selected
QString path = absolute_paths.at(selectedIndexes.at(0).data().toInt());
// File
if (QFile::exists(path))
emit readyToPreviewFile(path);
else
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close();
}

3
src/previewselect.h

@ -46,7 +46,7 @@ class PreviewSelect: public QDialog, private Ui::preview { @@ -46,7 +46,7 @@ class PreviewSelect: public QDialog, private Ui::preview {
Q_OBJECT
public:
enum PreviewColumn { NAME, SIZE, PROGRESS, NB_COLUMNS };
enum PreviewColumn { NAME, SIZE, PROGRESS, FILE_INDEX, NB_COLUMNS };
public:
PreviewSelect(QWidget* parent, QTorrentHandle h);
@ -63,7 +63,6 @@ private: @@ -63,7 +63,6 @@ private:
QStandardItemModel *previewListModel;
PreviewListDelegate *listDelegate;
QTorrentHandle h;
QList<int> indexes;
};

Loading…
Cancel
Save