- BUGFIX: Fixed file preview and improved previewable files detection

This commit is contained in:
Christophe Dumez 2007-08-29 16:07:37 +00:00
parent 495d6f2bab
commit 229927bbe9
7 changed files with 64 additions and 37 deletions

1
TODO
View File

@ -89,4 +89,5 @@ beta5->beta6 changelog:
- BUGFIX: Improved ETA calculation
- BUGFIX: ETA was wrong for torrents with filtered files
- BUGFIX: Display the torrent that are being checked as 'checking' in seeding list
- BUGFIX: Fixed file preview and improved previewable files detection
- I18N: Removed no longer maintained Traditional chinese translation

View File

@ -46,9 +46,6 @@
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false){
// To avoid some exceptions
fs::path::default_name_check(fs::no_check);
// Supported preview extensions
// XXX: A bit dirty to do it this way (use mime types?)
supported_preview_extensions << "AVI" << "DIVX" << "MPG" << "MPEG" << "MPE" << "MP3" << "OGG" << "WMV" << "WMA" << "RMV" << "RMVB" << "ASF" << "MOV" << "WAV" << "MP2" << "SWF" << "AC3" << "OGM" << "MP4" << "FLV" << "VOB" << "QT" << "MKV" << "AIF" << "AIFF" << "AIFC" << "MID" << "MPG" << "RA" << "RAM" << "AU" << "M4A" << "FLAC" << "M4P" << "3GP" << "AAC" << "RM" << "SWA" << "MPC" << "MPP";
// Creating bittorrent session
s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0));
// Set severity level of libtorrent session
@ -782,10 +779,9 @@ bool bittorrent::isFilePreviewPossible(QString hash) const{
unsigned int nbFiles = h.num_files();
for(unsigned int i=0; i<nbFiles; ++i) {
QString fileName = h.file_at(i);
QString extension = fileName.split('.').last().toUpper();
if(supported_preview_extensions.indexOf(extension) >= 0) {
QString extension = fileName.split('.').last();
if(misc::isPreviewable(extension))
return true;
}
}
return false;
}

View File

@ -45,7 +45,6 @@ class bittorrent : public QObject{
QTimer *timerAlerts;
bool DHTEnabled;
downloadThread *downloader;
QStringList supported_preview_extensions;
QString defaultSavePath;
QStringList torrentsToPauseAfterChecking;
QStringList reloadingTorrents;

View File

@ -120,6 +120,51 @@ class misc : public QObject{
return QString(QByteArray::number(val, 'f', 1)) + tr("TiB", "tebibytes (1024 gibibytes)");
}
static bool isPreviewable(QString extension){
extension = extension.toUpper();
if(extension == "AVI") return true;
if(extension == "MP3") return true;
if(extension == "OGG") return true;
if(extension == "OGM") return true;
if(extension == "WMV") return true;
if(extension == "WMA") return true;
if(extension == "MPEG") return true;
if(extension == "MPG") return true;
if(extension == "ASF") return true;
if(extension == "QT") return true;
if(extension == "RM") return true;
if(extension == "RMVB") return true;
if(extension == "RMV") return true;
if(extension == "SWF") return true;
if(extension == "FLV") return true;
if(extension == "WAV") return true;
if(extension == "MOV") return true;
if(extension == "VOB") return true;
if(extension == "MID") return true;
if(extension == "AC3") return true;
if(extension == "MP4") return true;
if(extension == "MP2") return true;
if(extension == "AVI") return true;
if(extension == "FLAC") return true;
if(extension == "AU") return true;
if(extension == "MPE") return true;
if(extension == "MOV") return true;
if(extension == "MKV") return true;
if(extension == "AIF") return true;
if(extension == "AIFF") return true;
if(extension == "AIFC") return true;
if(extension == "RA") return true;
if(extension == "RAM") return true;
if(extension == "M4P") return true;
if(extension == "M4A") return true;
if(extension == "3GP") return true;
if(extension == "AAC") return true;
if(extension == "SWA") return true;
if(extension == "MPC") return true;
if(extension == "MPP") return true;
return false;
}
// return qBittorrent config path
static QString qBittorrentPath() {
QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();

View File

@ -44,7 +44,6 @@ class previewSelect: public QDialog, private Ui::preview {
private:
QStandardItemModel *previewListModel;
PreviewListDelegate *listDelegate;
QStringList supported_preview_extensions;
QTorrentHandle h;
signals:
@ -53,36 +52,22 @@ class previewSelect: public QDialog, private Ui::preview {
protected slots:
void on_previewButton_clicked(){
QModelIndex index;
bool found = false;
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedIndexes();
if(selectedIndexes.size() == 0) return;
QString path;
foreach(index, selectedIndexes){
if(index.column() == NAME){
QString root_path = h.save_path();
if(root_path.at(root_path.length()-1) != QDir::separator()){
root_path += QString::fromUtf8("/");
}
// Get the file name
QString fileName = index.data().toString();
path = h.files_path().at(index.row());
// File
if(QFile::exists(root_path+fileName)){
emit readyToPreviewFile(root_path+fileName);
found = true;
}else{
// Folder
QString folder_name = h.name();
// Will find the file even if it is in a sub directory
QString result = misc::findFileInDir(root_path+folder_name, fileName);
if(!result.isNull()){
emit readyToPreviewFile(result);
found = true;
}
if(QFile::exists(path)){
emit readyToPreviewFile(path);
}
break;
close();
return;
}
}
if(!found){
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
}
qDebug("Cannot find file: %s", path.toUtf8().data());
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close();
}
@ -102,7 +87,6 @@ class previewSelect: public QDialog, private Ui::preview {
previewList->setModel(previewListModel);
listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate);
supported_preview_extensions << QString::fromUtf8("AVI") << QString::fromUtf8("DIVX") << QString::fromUtf8("MPG") << QString::fromUtf8("MPEG") << QString::fromUtf8("MPE") << QString::fromUtf8("MP3") << QString::fromUtf8("OGG") << QString::fromUtf8("WMV") << QString::fromUtf8("WMA") << QString::fromUtf8("RMV") << QString::fromUtf8("RMVB") << QString::fromUtf8("ASF") << QString::fromUtf8("MOV") << QString::fromUtf8("WAV") << QString::fromUtf8("MP2") << QString::fromUtf8("SWF") << QString::fromUtf8("AC3") << QString::fromUtf8("OGM") << QString::fromUtf8("MP4") << QString::fromUtf8("FLV") << QString::fromUtf8("VOB") << QString::fromUtf8("QT") << QString::fromUtf8("MKV") << QString::fromUtf8("AIF") << QString::fromUtf8("AIFF") << QString::fromUtf8("AIFC") << QString::fromUtf8("MID") << QString::fromUtf8("MPG") << QString::fromUtf8("RA") << QString::fromUtf8("RAM") << QString::fromUtf8("AU") << QString::fromUtf8("M4A") << QString::fromUtf8("FLAC") << QString::fromUtf8("M4P") << QString::fromUtf8("3GP") << QString::fromUtf8("AAC") << QString::fromUtf8("RM") << QString::fromUtf8("SWA") << QString::fromUtf8("MPC") << QString::fromUtf8("MPP");
previewList->header()->resizeSection(0, 200);
// Fill list in
std::vector<float> fp;
@ -111,7 +95,7 @@ class previewSelect: public QDialog, private Ui::preview {
for(unsigned int i=0; i<nbFiles; ++i){
QString fileName = h.file_at(i);
QString extension = fileName.split(QString::fromUtf8(".")).last().toUpper();
if(supported_preview_extensions.indexOf(extension) >= 0){
if(misc::isPreviewable(extension)) {
int row = previewListModel->rowCount();
previewListModel->insertRow(row);
previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName));

View File

@ -173,13 +173,15 @@ entry QTorrentHandle::write_resume_data() const {
return h.write_resume_data();
}
QString QTorrentHandle::file_at(int index) const {
QString QTorrentHandle::file_at(unsigned int index) const {
Q_ASSERT(h.is_valid());
Q_ASSERT(index < (unsigned int)h.get_torrent_info().num_files());
return misc::toQString(h.get_torrent_info().file_at(index).path.leaf());
}
size_type QTorrentHandle::filesize_at(int index) const {
size_type QTorrentHandle::filesize_at(unsigned int index) const {
Q_ASSERT(h.is_valid());
Q_ASSERT(index < (unsigned int)h.get_torrent_info().num_files());
return h.get_torrent_info().file_at(index).size;
}

View File

@ -72,8 +72,8 @@ class QTorrentHandle {
int num_files() const;
bool has_metadata() const;
entry write_resume_data() const;
QString file_at(int index) const;
size_type filesize_at(int index) const;
QString file_at(unsigned int index) const;
size_type filesize_at(unsigned int index) const;
std::vector<announce_entry> const& trackers() const;
torrent_status::state_t state() const;
QString creator() const;