From bd5880843f1323042c965c49651e1ba8a5af518b Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 9 Jan 2010 21:39:17 +0000 Subject: [PATCH] - flush cache before file preview (libtorrent >= 0.15 only) --- src/previewselect.h | 4 ++++ src/propertieswidget.cpp | 10 ++++++++-- src/qtorrenthandle.cpp | 5 +++++ src/qtorrenthandle.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/previewselect.h b/src/previewselect.h index ba8f8f5d6..861460f1f 100644 --- a/src/previewselect.h +++ b/src/previewselect.h @@ -64,6 +64,10 @@ protected slots: QModelIndex index; QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME); if(selectedIndexes.size() == 0) return; +#ifdef LIBTORRENT_0_15 + // Flush data + h.flush_cache(); +#endif QString path; foreach(index, selectedIndexes){ path = h.files_path().at(indexes.at(index.row())); diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index e60d8868f..c0f60c937 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -478,7 +478,10 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { QString filename = misc::toQString(h.get_torrent_info().file_at(i).path.string()); QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); qDebug("Trying to open file at %s", file_path.toLocal8Bit().data()); - // TODO: Flush data (when libtorrent supports it) +#ifdef LIBTORRENT_0_15 + // Flush data + h.flush_cache(); +#endif if(QFile::exists(file_path)) QDesktopServices::openUrl("file://"+file_path); else @@ -496,7 +499,10 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { QString filename = path_items.join(QDir::separator()); QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); qDebug("Trying to open folder at %s", file_path.toLocal8Bit().data()); - // TODO: Flush data (when libtorrent supports it) +#ifdef LIBTORRENT_0_15 + // Flush data + h.flush_cache(); +#endif if(QFile::exists(file_path)) QDesktopServices::openUrl("file://"+file_path); else diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 00a33971f..4ab23a0d0 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -547,6 +547,11 @@ void QTorrentHandle::super_seeding(bool on) const { Q_ASSERT(h.is_valid()); h.super_seeding(on); } + +void QTorrentHandle::flush_cache() const { + Q_ASSERT(h.is_valid()); + h.flush_cache(); +} #endif #ifndef DISABLE_GUI diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 02b52741a..5c1d0aa41 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -153,6 +153,7 @@ class QTorrentHandle { void move_storage(QString path) const; #ifdef LIBTORRENT_0_15 void super_seeding(bool on) const; + void flush_cache() const; #endif #ifndef DISABLE_GUI void resolve_countries(bool r);