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)
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
previewList->setModel(previewListModel); previewList->setModel(previewListModel);
previewList->hideColumn(FILE_INDEX);
listDelegate = new PreviewListDelegate(this); listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate); previewList->setItemDelegate(listDelegate);
previewList->header()->resizeSection(0, 200); previewList->header()->resizeSection(0, 200);
@ -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, NAME), QVariant(fileName));
previewListModel->setData(previewListModel->index(row, SIZE), QVariant((qlonglong)h.filesize_at(i))); 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))); 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() {
void PreviewSelect::on_previewButton_clicked() { void PreviewSelect::on_previewButton_clicked() {
QModelIndex index; QModelIndex index;
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME); QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.size() == 0) return; if (selectedIndexes.size() == 0) return;
// Flush data // Flush data
h.flush_cache(); h.flush_cache();
QStringList absolute_paths(h.absolute_files_path()); QStringList absolute_paths(h.absolute_files_path());
QString path; //only one file should be selected
foreach (index, selectedIndexes) { QString path = absolute_paths.at(selectedIndexes.at(0).data().toInt());
path = absolute_paths.at(indexes.at(index.row())); // File
// File if (QFile::exists(path))
if (QFile::exists(path)) { emit readyToPreviewFile(path);
emit readyToPreviewFile(path); else
} else { QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
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"));
close(); close();
} }

3
src/previewselect.h

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

Loading…
Cancel
Save