mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-24 21:44:25 +00:00
- Fix for media file preview
This commit is contained in:
parent
d22d6468c7
commit
90207020f2
@ -424,10 +424,6 @@ void GUI::on_actionExit_triggered() {
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::previewFile(QString filePath) {
|
|
||||||
QDesktopServices::openUrl(QString("file://")+filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GUI::getCurrentTabIndex() const {
|
int GUI::getCurrentTabIndex() const {
|
||||||
if(isMinimized() || !isVisible())
|
if(isMinimized() || !isVisible())
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -105,7 +105,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
|||||||
void on_actionShow_console_triggered();
|
void on_actionShow_console_triggered();
|
||||||
void readParamsOnSocket();
|
void readParamsOnSocket();
|
||||||
void acceptConnection();
|
void acceptConnection();
|
||||||
void previewFile(QString filePath);
|
|
||||||
void balloonClicked();
|
void balloonClicked();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
|
@ -72,7 +72,7 @@ class FilterParserThread : public QThread {
|
|||||||
parseP2PFilterFile(filePath);
|
parseP2PFilterFile(filePath);
|
||||||
} else {
|
} else {
|
||||||
if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
|
if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
|
||||||
// PeerGuardian p2p file
|
// PeerGuardian p2b file
|
||||||
parseP2BFilterFile(filePath);
|
parseP2BFilterFile(filePath);
|
||||||
} else {
|
} else {
|
||||||
// Default: eMule DAT format
|
// Default: eMule DAT format
|
||||||
|
@ -50,90 +50,92 @@ using namespace libtorrent;
|
|||||||
class previewSelect: public QDialog, private Ui::preview {
|
class previewSelect: public QDialog, private Ui::preview {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStandardItemModel *previewListModel;
|
QStandardItemModel *previewListModel;
|
||||||
PreviewListDelegate *listDelegate;
|
PreviewListDelegate *listDelegate;
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
QList<int> indexes;
|
QList<int> indexes;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void readyToPreviewFile(QString) const;
|
void readyToPreviewFile(QString) const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_previewButton_clicked(){
|
void on_previewButton_clicked(){
|
||||||
QModelIndex index;
|
QModelIndex index;
|
||||||
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedIndexes();
|
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME);
|
||||||
if(selectedIndexes.size() == 0) return;
|
if(selectedIndexes.size() == 0) return;
|
||||||
QString path;
|
QString path;
|
||||||
foreach(index, selectedIndexes){
|
foreach(index, selectedIndexes){
|
||||||
if(index.column() == NAME){
|
path = h.files_path().at(indexes.at(index.row()));
|
||||||
path = h.files_path().at(indexes.at(index.row()));
|
// File
|
||||||
// File
|
if(QFile::exists(path)){
|
||||||
if(QFile::exists(path)){
|
emit readyToPreviewFile(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());
|
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<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"));
|
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString)));
|
||||||
void on_cancelButton_clicked(){
|
if(previewListModel->rowCount() == 1){
|
||||||
close();
|
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(){
|
||||||
previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h){
|
delete previewListModel;
|
||||||
setupUi(this);
|
delete listDelegate;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~previewSelect(){
|
|
||||||
delete previewListModel;
|
|
||||||
delete listDelegate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -251,6 +251,10 @@ void TransferListWidget::updateMetadata(QTorrentHandle &h) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransferListWidget::previewFile(QString filePath) {
|
||||||
|
QDesktopServices::openUrl(QString("file://")+filePath);
|
||||||
|
}
|
||||||
|
|
||||||
int TransferListWidget::updateTorrent(int row) {
|
int TransferListWidget::updateTorrent(int row) {
|
||||||
TorrentState s = STATE_INVALID;
|
TorrentState s = STATE_INVALID;
|
||||||
QString hash = getHashFromRow(row);
|
QString hash = getHashFromRow(row);
|
||||||
|
@ -108,6 +108,7 @@ public slots:
|
|||||||
void hidePriorityColumn(bool hide);
|
void hidePriorityColumn(bool hide);
|
||||||
void displayDLHoSMenu(const QPoint&);
|
void displayDLHoSMenu(const QPoint&);
|
||||||
void applyFilter(int f);
|
void applyFilter(int f);
|
||||||
|
void previewFile(QString filePath);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentTorrentChanged(QTorrentHandle &h);
|
void currentTorrentChanged(QTorrentHandle &h);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user