|
|
|
@ -50,90 +50,92 @@ using namespace libtorrent;
@@ -50,90 +50,92 @@ using namespace libtorrent;
|
|
|
|
|
class previewSelect: public QDialog, private Ui::preview { |
|
|
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
QStandardItemModel *previewListModel; |
|
|
|
|
PreviewListDelegate *listDelegate; |
|
|
|
|
QTorrentHandle h; |
|
|
|
|
QList<int> indexes; |
|
|
|
|
private: |
|
|
|
|
QStandardItemModel *previewListModel; |
|
|
|
|
PreviewListDelegate *listDelegate; |
|
|
|
|
QTorrentHandle h; |
|
|
|
|
QList<int> indexes; |
|
|
|
|
|
|
|
|
|
signals: |
|
|
|
|
void readyToPreviewFile(QString) const; |
|
|
|
|
signals: |
|
|
|
|
void readyToPreviewFile(QString) const; |
|
|
|
|
|
|
|
|
|
protected slots: |
|
|
|
|
void on_previewButton_clicked(){ |
|
|
|
|
QModelIndex index; |
|
|
|
|
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedIndexes(); |
|
|
|
|
if(selectedIndexes.size() == 0) return; |
|
|
|
|
QString path; |
|
|
|
|
foreach(index, selectedIndexes){ |
|
|
|
|
if(index.column() == NAME){ |
|
|
|
|
path = h.files_path().at(indexes.at(index.row())); |
|
|
|
|
// File
|
|
|
|
|
if(QFile::exists(path)){ |
|
|
|
|
emit readyToPreviewFile(path); |
|
|
|
|
} |
|
|
|
|
close(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
protected slots: |
|
|
|
|
void on_previewButton_clicked(){ |
|
|
|
|
QModelIndex index; |
|
|
|
|
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME); |
|
|
|
|
if(selectedIndexes.size() == 0) return; |
|
|
|
|
QString path; |
|
|
|
|
foreach(index, selectedIndexes){ |
|
|
|
|
path = h.files_path().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")); |
|
|
|
|
} |
|
|
|
|
qDebug("Cannot find file: %s", path.toLocal8Bit().data()); |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_cancelButton_clicked(){ |
|
|
|
|
close(); |
|
|
|
|
} |
|
|
|
|
void on_cancelButton_clicked(){ |
|
|
|
|
close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h){ |
|
|
|
|
setupUi(this); |
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
|
// Preview list
|
|
|
|
|
previewListModel = new QStandardItemModel(0, 3); |
|
|
|
|
previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); |
|
|
|
|
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); |
|
|
|
|
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); |
|
|
|
|
previewList->setModel(previewListModel); |
|
|
|
|
listDelegate = new PreviewListDelegate(this); |
|
|
|
|
previewList->setItemDelegate(listDelegate); |
|
|
|
|
previewList->header()->resizeSection(0, 200); |
|
|
|
|
// Fill list in
|
|
|
|
|
std::vector<size_type> fp; |
|
|
|
|
h.file_progress(fp); |
|
|
|
|
unsigned int nbFiles = h.num_files(); |
|
|
|
|
for(unsigned int i=0; i<nbFiles; ++i){ |
|
|
|
|
QString fileName = h.file_at(i); |
|
|
|
|
QString extension = fileName.split(QString::fromUtf8(".")).last().toUpper(); |
|
|
|
|
if(misc::isPreviewable(extension)) { |
|
|
|
|
int row = previewListModel->rowCount(); |
|
|
|
|
previewListModel->insertRow(row); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, NAME), QItemSelectionModel::Select); |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, SIZE), QItemSelectionModel::Select); |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, PROGRESS), QItemSelectionModel::Select); |
|
|
|
|
if(!previewListModel->rowCount()){ |
|
|
|
|
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file")); |
|
|
|
|
close(); |
|
|
|
|
} |
|
|
|
|
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString))); |
|
|
|
|
if(previewListModel->rowCount() == 1){ |
|
|
|
|
// Only one file : no choice
|
|
|
|
|
on_previewButton_clicked(); |
|
|
|
|
}else{ |
|
|
|
|
show(); |
|
|
|
|
public: |
|
|
|
|
previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h){ |
|
|
|
|
setupUi(this); |
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
|
// Preview list
|
|
|
|
|
previewListModel = new QStandardItemModel(0, 3); |
|
|
|
|
previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); |
|
|
|
|
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); |
|
|
|
|
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); |
|
|
|
|
previewList->setModel(previewListModel); |
|
|
|
|
listDelegate = new PreviewListDelegate(this); |
|
|
|
|
previewList->setItemDelegate(listDelegate); |
|
|
|
|
previewList->header()->resizeSection(0, 200); |
|
|
|
|
// Fill list in
|
|
|
|
|
std::vector<size_type> fp; |
|
|
|
|
h.file_progress(fp); |
|
|
|
|
unsigned int nbFiles = h.num_files(); |
|
|
|
|
for(unsigned int i=0; i<nbFiles; ++i){ |
|
|
|
|
QString fileName = h.file_at(i); |
|
|
|
|
QString extension = fileName.split(QString::fromUtf8(".")).last().toUpper(); |
|
|
|
|
if(misc::isPreviewable(extension)) { |
|
|
|
|
int row = previewListModel->rowCount(); |
|
|
|
|
previewListModel->insertRow(row); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~previewSelect(){ |
|
|
|
|
delete previewListModel; |
|
|
|
|
delete listDelegate; |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, NAME), QItemSelectionModel::Select); |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, SIZE), QItemSelectionModel::Select); |
|
|
|
|
previewList->selectionModel()->select(previewListModel->index(0, PROGRESS), QItemSelectionModel::Select); |
|
|
|
|
if(!previewListModel->rowCount()){ |
|
|
|
|
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file")); |
|
|
|
|
close(); |
|
|
|
|
} |
|
|
|
|
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString))); |
|
|
|
|
if(previewListModel->rowCount() == 1){ |
|
|
|
|
qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); |
|
|
|
|
// Only one file : no choice
|
|
|
|
|
on_previewButton_clicked(); |
|
|
|
|
}else{ |
|
|
|
|
qDebug("Displaying media file selection dialog for preview"); |
|
|
|
|
show(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~previewSelect(){ |
|
|
|
|
delete previewListModel; |
|
|
|
|
delete listDelegate; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|