2006-09-30 20:02:39 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
2006-09-30 20:02:39 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PREVIEWSELECT_H
|
|
|
|
#define PREVIEWSELECT_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMessageBox>
|
2010-03-20 22:09:27 +03:00
|
|
|
#include <QFile>
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2006-09-30 20:02:39 +04:00
|
|
|
#include <libtorrent/session.hpp>
|
|
|
|
#include "ui_preview.h"
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "previewlistdelegate.h"
|
2006-09-30 20:02:39 +04:00
|
|
|
#include "misc.h"
|
2007-08-20 10:29:18 +04:00
|
|
|
#include "qtorrenthandle.h"
|
2006-09-30 20:02:39 +04:00
|
|
|
|
|
|
|
#define NAME 0
|
|
|
|
#define SIZE 1
|
|
|
|
#define PROGRESS 2
|
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
|
|
|
class previewSelect: public QDialog, private Ui::preview {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
private:
|
|
|
|
QStandardItemModel *previewListModel;
|
|
|
|
PreviewListDelegate *listDelegate;
|
|
|
|
QTorrentHandle h;
|
|
|
|
QList<int> indexes;
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
signals:
|
|
|
|
void readyToPreviewFile(QString) const;
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
protected slots:
|
|
|
|
void on_previewButton_clicked(){
|
|
|
|
QModelIndex index;
|
|
|
|
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME);
|
|
|
|
if(selectedIndexes.size() == 0) return;
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-01-10 00:39:17 +03:00
|
|
|
// Flush data
|
|
|
|
h.flush_cache();
|
|
|
|
#endif
|
2009-11-27 14:38:42 +03:00
|
|
|
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"));
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
close();
|
2009-11-27 14:38:42 +03:00
|
|
|
return;
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
2009-11-27 14:38:42 +03:00
|
|
|
qDebug("Cannot find file: %s", path.toLocal8Bit().data());
|
|
|
|
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
|
|
|
|
close();
|
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
void on_cancelButton_clicked(){
|
|
|
|
close();
|
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
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){
|
2010-10-23 20:21:56 +04:00
|
|
|
QString fileName = h.filename_at(i);
|
2009-11-27 14:38:42 +03:00
|
|
|
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;
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
|
|
|
}
|
2009-11-27 14:38:42 +03:00
|
|
|
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();
|
2006-09-30 20:02:39 +04:00
|
|
|
}
|
2009-11-27 14:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~previewSelect(){
|
|
|
|
delete previewListModel;
|
|
|
|
delete listDelegate;
|
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|