Browse Source

- BUGFIX: Fixed file preview and improved previewable files detection

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
229927bbe9
  1. 1
      TODO
  2. 8
      src/bittorrent.cpp
  3. 1
      src/bittorrent.h
  4. 45
      src/misc.h
  5. 36
      src/previewSelect.h
  6. 6
      src/qtorrenthandle.cpp
  7. 4
      src/qtorrenthandle.h

1
TODO

@ -89,4 +89,5 @@ beta5->beta6 changelog:
- BUGFIX: Improved ETA calculation - BUGFIX: Improved ETA calculation
- BUGFIX: ETA was wrong for torrents with filtered files - BUGFIX: ETA was wrong for torrents with filtered files
- BUGFIX: Display the torrent that are being checked as 'checking' in seeding list - 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 - I18N: Removed no longer maintained Traditional chinese translation

8
src/bittorrent.cpp

@ -46,9 +46,6 @@
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false){ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false){
// To avoid some exceptions // To avoid some exceptions
fs::path::default_name_check(fs::no_check); 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 // Creating bittorrent session
s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0)); s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0));
// Set severity level of libtorrent session // Set severity level of libtorrent session
@ -782,10 +779,9 @@ bool bittorrent::isFilePreviewPossible(QString hash) const{
unsigned int nbFiles = h.num_files(); unsigned int nbFiles = h.num_files();
for(unsigned int i=0; i<nbFiles; ++i) { for(unsigned int i=0; i<nbFiles; ++i) {
QString fileName = h.file_at(i); QString fileName = h.file_at(i);
QString extension = fileName.split('.').last().toUpper(); QString extension = fileName.split('.').last();
if(supported_preview_extensions.indexOf(extension) >= 0) { if(misc::isPreviewable(extension))
return true; return true;
}
} }
return false; return false;
} }

1
src/bittorrent.h

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

45
src/misc.h

@ -120,6 +120,51 @@ class misc : public QObject{
return QString(QByteArray::number(val, 'f', 1)) + tr("TiB", "tebibytes (1024 gibibytes)"); 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 // return qBittorrent config path
static QString qBittorrentPath() { static QString qBittorrentPath() {
QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator(); QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();

36
src/previewSelect.h

@ -44,7 +44,6 @@ class previewSelect: public QDialog, private Ui::preview {
private: private:
QStandardItemModel *previewListModel; QStandardItemModel *previewListModel;
PreviewListDelegate *listDelegate; PreviewListDelegate *listDelegate;
QStringList supported_preview_extensions;
QTorrentHandle h; QTorrentHandle h;
signals: signals:
@ -53,36 +52,22 @@ class previewSelect: public QDialog, private Ui::preview {
protected slots: protected slots:
void on_previewButton_clicked(){ void on_previewButton_clicked(){
QModelIndex index; QModelIndex index;
bool found = false;
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = previewList->selectionModel()->selectedIndexes();
if(selectedIndexes.size() == 0) return;
QString path;
foreach(index, selectedIndexes){ foreach(index, selectedIndexes){
if(index.column() == NAME){ if(index.column() == NAME){
QString root_path = h.save_path(); path = h.files_path().at(index.row());
if(root_path.at(root_path.length()-1) != QDir::separator()){
root_path += QString::fromUtf8("/");
}
// Get the file name
QString fileName = index.data().toString();
// File // File
if(QFile::exists(root_path+fileName)){ if(QFile::exists(path)){
emit readyToPreviewFile(root_path+fileName); emit readyToPreviewFile(path);
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;
}
} }
break; close();
return;
} }
} }
if(!found){ qDebug("Cannot find file: %s", path.toUtf8().data());
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();
} }
@ -102,7 +87,6 @@ class previewSelect: public QDialog, private Ui::preview {
previewList->setModel(previewListModel); previewList->setModel(previewListModel);
listDelegate = new PreviewListDelegate(this); listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate); 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); previewList->header()->resizeSection(0, 200);
// Fill list in // Fill list in
std::vector<float> fp; std::vector<float> fp;
@ -111,7 +95,7 @@ class previewSelect: public QDialog, private Ui::preview {
for(unsigned int i=0; i<nbFiles; ++i){ for(unsigned int i=0; i<nbFiles; ++i){
QString fileName = h.file_at(i); QString fileName = h.file_at(i);
QString extension = fileName.split(QString::fromUtf8(".")).last().toUpper(); QString extension = fileName.split(QString::fromUtf8(".")).last().toUpper();
if(supported_preview_extensions.indexOf(extension) >= 0){ if(misc::isPreviewable(extension)) {
int row = previewListModel->rowCount(); int row = previewListModel->rowCount();
previewListModel->insertRow(row); previewListModel->insertRow(row);
previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName)); previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName));

6
src/qtorrenthandle.cpp

@ -173,13 +173,15 @@ entry QTorrentHandle::write_resume_data() const {
return h.write_resume_data(); 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(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()); 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(h.is_valid());
Q_ASSERT(index < (unsigned int)h.get_torrent_info().num_files());
return h.get_torrent_info().file_at(index).size; return h.get_torrent_info().file_at(index).size;
} }

4
src/qtorrenthandle.h

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

Loading…
Cancel
Save