Browse Source

Hide unwanted files that have to be partly downloaded

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
fb443bb6e7
  1. 1
      Changelog
  2. 7
      src/misc.cpp
  3. 93
      src/qtlibtorrent/qtorrenthandle.cpp
  4. 4
      src/qtlibtorrent/qtorrenthandle.h
  5. 1
      src/torrentfilesmodel.h

1
Changelog

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
- FEATURE: Added a search engine plugin to extratorrent.com
- FEATURE: Added a search engine plugin for kickasstorrents.com
- FEATURE: Added auto-suspend upon downloads completion feature
- BUGFIX: Hide unwanted files that have to be partly downloaded
- I18N: Added Galician translation
- COSMETIC: Same deletion confirmation dialog in the GUI and Web UI
- COSMETIC: Simplified the top toolbar

7
src/misc.cpp

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include <QFileInfo>
#include <QDateTime>
#include <QByteArray>
#include <QDebug>
#ifdef DISABLE_GUI
#include <QCoreApplication>
@ -772,7 +773,13 @@ QString misc::branchPath(QString file_path, bool uses_slashes) @@ -772,7 +773,13 @@ QString misc::branchPath(QString file_path, bool uses_slashes)
{
if(!uses_slashes)
file_path.replace("\\", "/");
Q_ASSERT(!file_path.contains("\\"));
if(file_path.endsWith("/"))
file_path.chop(1); // Remove trailing slash
qDebug() << Q_FUNC_INFO << "before:" << file_path;
if(file_path.contains("/"))
return file_path.left(file_path.lastIndexOf('/'));
return "";
}
bool misc::isUrl(const QString &s)

93
src/qtlibtorrent/qtorrenthandle.cpp

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
#include <boost/filesystem/fstream.hpp>
using namespace libtorrent;
using namespace std;
QTorrentHandle::QTorrentHandle(torrent_handle h): torrent_handle(h) {}
@ -456,45 +457,6 @@ void QTorrentHandle::add_url_seed(QString seed) const { @@ -456,45 +457,6 @@ void QTorrentHandle::add_url_seed(QString seed) const {
torrent_handle::add_url_seed(str_seed);
}
void QTorrentHandle::prioritize_files(const std::vector<int> &v) const {
// Does not do anything for seeding torrents
if(v.size() != (unsigned int)torrent_handle::get_torrent_info().num_files())
return;
bool was_seed = is_seed();
torrent_handle::prioritize_files(v);
if(was_seed && !is_seed()) {
// Reset seed status
TorrentPersistentData::saveSeedStatus(*this);
// Move to temp folder if necessary
const Preferences pref;
if(pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
QString root_folder = TorrentPersistentData::getRootFolder(hash());
if(!root_folder.isEmpty())
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
move_storage(tmp_path);
}
}
}
void QTorrentHandle::file_priority(int index, int priority) const {
bool was_seed = is_seed();
torrent_handle::file_priority(index, priority);
if(was_seed && !is_seed()) {
// Save seed status
TorrentPersistentData::saveSeedStatus(*this);
// Move to temp folder if necessary
const Preferences pref;
if(pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
QString root_folder = TorrentPersistentData::getRootFolder(hash());
if(!root_folder.isEmpty())
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
move_storage(tmp_path);
}
}
}
void QTorrentHandle::set_tracker_login(QString username, QString password) const {
torrent_handle::set_tracker_login(std::string(username.toLocal8Bit().constData()), std::string(password.toLocal8Bit().constData()));
}
@ -526,6 +488,59 @@ bool QTorrentHandle::save_torrent_file(QString path) const { @@ -526,6 +488,59 @@ bool QTorrentHandle::save_torrent_file(QString path) const {
return false;
}
void QTorrentHandle::file_priority(int index, int priority) const {
vector<int> priorities = torrent_handle::file_priorities();
if(priorities[index] != priority) {
priorities[index] = priority;
prioritize_files(priorities);
}
}
// TODO: Also hide the folder on Windows
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
if((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
const vector<int> prev_priorities = torrent_handle::file_priorities();
bool was_seed = is_seed();
torrent_handle::prioritize_files(files);
for(uint i=0; i<files.size(); ++i) {
// Move unwanted files to a .unwanted subfolder
if(prev_priorities[i] > 0 && files[i] == 0) {
QString old_path = filepath_at(i);
QString old_name = filename_at(i);
QDir parent_path(misc::branchPath(old_path));
if(parent_path.dirName() != ".unwanted") {
parent_path.mkdir(".unwanted");
rename_file(i, parent_path.filePath(".unwanted/"+old_name));
}
}
// Move wanted files back to their original folder
if(prev_priorities[i] == 0 && files[i] > 0) {
QString old_path = filepath_at(i);
QString old_name = filename_at(i);
QDir parent_path(misc::branchPath(old_path));
if(parent_path.dirName() == ".unwanted") {
QDir new_path(misc::branchPath(parent_path.path()));
rename_file(i, new_path.filePath(old_name));
// Remove .unwanted directory if empty
new_path.rmdir(".unwanted");
}
}
}
if(was_seed && !is_seed()) {
// Save seed status
TorrentPersistentData::saveSeedStatus(*this);
// Move to temp folder if necessary
const Preferences pref;
if(pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
QString root_folder = TorrentPersistentData::getRootFolder(hash());
if(!root_folder.isEmpty())
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
move_storage(tmp_path);
}
}
}
void QTorrentHandle::add_tracker(const announce_entry& url) const {
#if LIBTORRENT_VERSION_MINOR > 14
torrent_handle::add_tracker(url);

4
src/qtlibtorrent/qtorrenthandle.h

@ -122,14 +122,14 @@ public: @@ -122,14 +122,14 @@ public:
void resume() const;
void remove_url_seed(QString seed) const;
void add_url_seed(QString seed) const;
void prioritize_files(const std::vector<int> &v) const;
void file_priority(int index, int priority) const;
void set_tracker_login(QString username, QString password) const;
void move_storage(QString path) const;
void add_tracker(const libtorrent::announce_entry& url) const;
void prioritize_first_last_piece(bool b) const;
void rename_file(int index, QString name) const;
bool save_torrent_file(QString path) const;
void prioritize_files(const std::vector<int> &files) const;
void file_priority(int index, int priority) const;
//
// Operators

1
src/torrentfilesmodel.h

@ -546,6 +546,7 @@ public: @@ -546,6 +546,7 @@ public:
#endif
// Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split("/");
pathFolders.removeAll(".unwanted");
pathFolders.takeLast();
foreach(const QString &pathPart, pathFolders) {
TreeItem *new_parent = current_parent->childWithName(pathPart);

Loading…
Cancel
Save