mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
FEATURE: Search engine results can now be opened in a Web browser (plugins will be progressively ported, only btjunkie is working atm)
This commit is contained in:
parent
35ea06214a
commit
c14deec893
14 changed files with 224 additions and 177 deletions
|
@ -32,114 +32,36 @@
|
|||
#define PREVIEWSELECT_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStandardItemModel>
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
#include <libtorrent/version.hpp>
|
||||
#include <libtorrent/session.hpp>
|
||||
#include <QList>
|
||||
#include "ui_preview.h"
|
||||
#include "previewlistdelegate.h"
|
||||
#include "misc.h"
|
||||
#include "qtorrenthandle.h"
|
||||
|
||||
#define NAME 0
|
||||
#define SIZE 1
|
||||
#define PROGRESS 2
|
||||
class QStandardItemModel;
|
||||
class PreviewListDelegate;
|
||||
|
||||
class previewSelect: public QDialog, private Ui::preview {
|
||||
class PreviewSelect: public QDialog, private Ui::preview {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum PreviewColumn { NAME, SIZE, PROGRESS };
|
||||
|
||||
public:
|
||||
PreviewSelect(QWidget* parent, QTorrentHandle h);
|
||||
~PreviewSelect();
|
||||
|
||||
signals:
|
||||
void readyToPreviewFile(QString) const;
|
||||
|
||||
protected slots:
|
||||
void on_previewButton_clicked();
|
||||
void on_cancelButton_clicked();
|
||||
|
||||
private:
|
||||
QStandardItemModel *previewListModel;
|
||||
PreviewListDelegate *listDelegate;
|
||||
QTorrentHandle h;
|
||||
QList<int> indexes;
|
||||
|
||||
signals:
|
||||
void readyToPreviewFile(QString) const;
|
||||
|
||||
protected slots:
|
||||
void on_previewButton_clicked(){
|
||||
QModelIndex index;
|
||||
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME);
|
||||
if(selectedIndexes.size() == 0) return;
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Flush data
|
||||
h.flush_cache();
|
||||
#endif
|
||||
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"));
|
||||
}
|
||||
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<libtorrent::size_type> fp;
|
||||
h.file_progress(fp);
|
||||
unsigned int nbFiles = h.num_files();
|
||||
for(unsigned int i=0; i<nbFiles; ++i){
|
||||
QString fileName = h.filename_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){
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue