From 90207020f23cc878ad00799e42156bbf1d80ac50 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 27 Nov 2009 11:38:42 +0000 Subject: [PATCH] - Fix for media file preview --- src/GUI.cpp | 4 - src/GUI.h | 1 - src/filterparserthread.h | 2 +- src/previewselect.h | 154 +++++++++++++++++++------------------ src/transferlistwidget.cpp | 4 + src/transferlistwidget.h | 1 + 6 files changed, 84 insertions(+), 82 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index 4b029b892..a82b77905 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -424,10 +424,6 @@ void GUI::on_actionExit_triggered() { close(); } -void GUI::previewFile(QString filePath) { - QDesktopServices::openUrl(QString("file://")+filePath); -} - int GUI::getCurrentTabIndex() const { if(isMinimized() || !isVisible()) return -1; diff --git a/src/GUI.h b/src/GUI.h index de03d7912..86b1fe212 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -105,7 +105,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void on_actionShow_console_triggered(); void readParamsOnSocket(); void acceptConnection(); - void previewFile(QString filePath); void balloonClicked(); void writeSettings(); void readSettings(); diff --git a/src/filterparserthread.h b/src/filterparserthread.h index 9080834ab..aafcbb32f 100644 --- a/src/filterparserthread.h +++ b/src/filterparserthread.h @@ -72,7 +72,7 @@ class FilterParserThread : public QThread { parseP2PFilterFile(filePath); } else { if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) { - // PeerGuardian p2p file + // PeerGuardian p2b file parseP2BFilterFile(filePath); } else { // Default: eMule DAT format diff --git a/src/previewselect.h b/src/previewselect.h index 0dc8f6fff..ba8f8f5d6 100644 --- a/src/previewselect.h +++ b/src/previewselect.h @@ -50,90 +50,92 @@ using namespace libtorrent; class previewSelect: public QDialog, private Ui::preview { Q_OBJECT - private: - QStandardItemModel *previewListModel; - PreviewListDelegate *listDelegate; - QTorrentHandle h; - QList indexes; +private: + QStandardItemModel *previewListModel; + PreviewListDelegate *listDelegate; + QTorrentHandle h; + QList 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()); + 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(); + } + +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 fp; + h.file_progress(fp); + unsigned int nbFiles = h.num_files(); + for(unsigned int i=0; irowCount(); + 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(); } - - void on_cancelButton_clicked(){ - 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(); } + } - 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 fp; - h.file_progress(fp); - unsigned int nbFiles = h.num_files(); - for(unsigned int i=0; irowCount(); - 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(); - } - } - - ~previewSelect(){ - delete previewListModel; - delete listDelegate; - } + ~previewSelect(){ + delete previewListModel; + delete listDelegate; + } }; #endif diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index c11166acc..675b1c8c6 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -251,6 +251,10 @@ void TransferListWidget::updateMetadata(QTorrentHandle &h) { } } +void TransferListWidget::previewFile(QString filePath) { + QDesktopServices::openUrl(QString("file://")+filePath); +} + int TransferListWidget::updateTorrent(int row) { TorrentState s = STATE_INVALID; QString hash = getHashFromRow(row); diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 9442dfd42..c876d9b51 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -108,6 +108,7 @@ public slots: void hidePriorityColumn(bool hide); void displayDLHoSMenu(const QPoint&); void applyFilter(int f); + void previewFile(QString filePath); signals: void currentTorrentChanged(QTorrentHandle &h);