Coding style clean up

This commit is contained in:
Christophe Dumez
2012-02-20 19:30:53 +02:00
parent 9acac03f14
commit a8a7b61ea9
77 changed files with 2194 additions and 2194 deletions

View File

@@ -29,7 +29,7 @@ public slots:
QTime startAltSpeeds = pref.getSchedulerStartTime();
QTime endAltSpeeds = pref.getSchedulerEndTime();
if(startAltSpeeds == endAltSpeeds) {
if (startAltSpeeds == endAltSpeeds) {
std::cerr << "Error: bandwidth scheduler have the same start time and end time." << std::endl;
std::cerr << "The bandwidth scheduler will be disabled" << std::endl;
stop();
@@ -41,7 +41,7 @@ public slots:
QTime now = QTime::currentTime();
uint time_to_start = secsTo(now, startAltSpeeds);
uint time_to_end = secsTo(now, endAltSpeeds);
if(time_to_end < time_to_start) {
if (time_to_end < time_to_start) {
// We should be in alternative mode
in_alternative_mode = true;
// Start counting
@@ -61,9 +61,9 @@ public slots:
// Get the day this mode was started (either today or yesterday)
QDate current_date = QDateTime::currentDateTime().toLocalTime().date();
int day = current_date.dayOfWeek();
if(in_alternative_mode) {
if (in_alternative_mode) {
// It is possible that starttime was yesterday
if(QTime::currentTime().secsTo(pref.getSchedulerStartTime()) > 0) {
if (QTime::currentTime().secsTo(pref.getSchedulerStartTime()) > 0) {
current_date.addDays(-1); // Go to yesterday
day = current_date.day();
}
@@ -75,17 +75,17 @@ public slots:
emit switchToAlternativeMode(!in_alternative_mode);
break;
case WEEK_ENDS:
if(day == Qt::Saturday || day == Qt::Sunday)
if (day == Qt::Saturday || day == Qt::Sunday)
emit switchToAlternativeMode(!in_alternative_mode);
break;
case WEEK_DAYS:
if(day != Qt::Saturday && day != Qt::Sunday)
if (day != Qt::Saturday && day != Qt::Sunday)
emit switchToAlternativeMode(!in_alternative_mode);
break;
default:
// Convert our enum index to Qt enum index
int scheduler_day = ((int)pref.getSchedulerDays()) - 2;
if(day == scheduler_day)
if (day == scheduler_day)
emit switchToAlternativeMode(!in_alternative_mode);
break;
}
@@ -101,7 +101,7 @@ private:
// don't want that
uint secsTo(QTime now, QTime t) {
int diff = now.secsTo(t);
if(diff < 0) {
if (diff < 0) {
// 86400 seconds in a day
diff += 86400;
}

View File

@@ -69,7 +69,7 @@ public:
int ruleCount = 0;
QFile file(filePath);
if (file.exists()){
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
std::cerr << "I/O Error: Could not open ip filer file in read mode." << std::endl;
return ruleCount;
}
@@ -79,9 +79,9 @@ public:
QByteArray line = file.readLine();
// Ignoring empty lines
line = line.trimmed();
if(line.isEmpty()) continue;
if (line.isEmpty()) continue;
// Ignoring commented lines
if(line.startsWith('#') || line.startsWith("//")) continue;
if (line.startsWith('#') || line.startsWith("//")) continue;
// Line should be splitted by commas
QList<QByteArray> partsList = line.split(',');
@@ -89,7 +89,7 @@ public:
// IP Range should be splitted by a dash
QList<QByteArray> IPs = partsList.first().split('-');
if(IPs.size() != 2) {
if (IPs.size() != 2) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("Line was %s", line.constData());
continue;
@@ -97,30 +97,30 @@ public:
boost::system::error_code ec;
const QString strStartIP = cleanupIPAddress(IPs.at(0));
if(strStartIP.isEmpty()) {
if (strStartIP.isEmpty()) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("Start IP of the range is malformated: %s", qPrintable(strStartIP));
continue;
}
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
if(ec) {
if (ec) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("Start IP of the range is malformated: %s", qPrintable(strStartIP));
continue;
}
const QString strEndIP = cleanupIPAddress(IPs.at(1));
if(strEndIP.isEmpty()) {
if (strEndIP.isEmpty()) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("End IP of the range is malformated: %s", qPrintable(strEndIP));
continue;
}
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
if(ec) {
if (ec) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("End IP of the range is malformated: %s", qPrintable(strEndIP));
continue;
}
if(startAddr.is_v4() != endAddr.is_v4()) {
if (startAddr.is_v4() != endAddr.is_v4()) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("One IP is IPv4 and the other is IPv6!");
continue;
@@ -128,12 +128,12 @@ public:
// Check if there is an access value (apparently not mandatory)
int nbAccess = 0;
if(nbElem > 1) {
if (nbElem > 1) {
// There is possibly one
nbAccess = partsList.at(1).trimmed().toInt();
}
if(nbAccess > 127) {
if (nbAccess > 127) {
// Ignoring this rule because access value is too high
continue;
}
@@ -155,7 +155,7 @@ public:
int ruleCount = 0;
QFile file(filePath);
if (file.exists()){
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
std::cerr << "I/O Error: Could not open ip filer file in read mode." << std::endl;
return ruleCount;
}
@@ -163,48 +163,48 @@ public:
while (!file.atEnd() && !abort) {
++nbLine;
QByteArray line = file.readLine().trimmed();
if(line.isEmpty()) continue;
if (line.isEmpty()) continue;
// Ignoring commented lines
if(line.startsWith('#') || line.startsWith("//")) continue;
if (line.startsWith('#') || line.startsWith("//")) continue;
// Line is splitted by :
QList<QByteArray> partsList = line.split(':');
if(partsList.size() < 2){
if (partsList.size() < 2){
qDebug("p2p file: line %d is malformed.", nbLine);
continue;
}
// Get IP range
QList<QByteArray> IPs = partsList.last().split('-');
if(IPs.size() != 2) {
if (IPs.size() != 2) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("line was: %s", line.constData());
continue;
}
boost::system::error_code ec;
QString strStartIP = cleanupIPAddress(IPs.at(0));
if(strStartIP.isEmpty()) {
if (strStartIP.isEmpty()) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("Start IP is invalid: %s", qPrintable(strStartIP));
continue;
}
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
if(ec) {
if (ec) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("Start IP is invalid: %s", qPrintable(strStartIP));
continue;
}
QString strEndIP = cleanupIPAddress(IPs.at(1));
if(strEndIP.isEmpty()) {
if (strEndIP.isEmpty()) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("End IP is invalid: %s", qPrintable(strStartIP));
continue;
}
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
if(ec) {
if (ec) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("End IP is invalid: %s", qPrintable(strStartIP));
continue;
}
if(startAddr.is_v4() != endAddr.is_v4()) {
if (startAddr.is_v4() != endAddr.is_v4()) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("Line was: %s", line.constData());
continue;
@@ -230,8 +230,8 @@ public:
do {
read = stream.readRawData(&c, 1);
total_read += read;
if(read > 0) {
if(c != delim) {
if (read > 0) {
if (c != delim) {
name += c;
} else {
// Delim found
@@ -247,7 +247,7 @@ public:
int ruleCount = 0;
QFile file(filePath);
if (file.exists()){
if(!file.open(QIODevice::ReadOnly)){
if (!file.open(QIODevice::ReadOnly)){
std::cerr << "I/O Error: Could not open ip filer file in read mode." << std::endl;
return ruleCount;
}
@@ -255,7 +255,7 @@ public:
// Read header
char buf[7];
unsigned char version;
if(
if (
!stream.readRawData(buf, sizeof(buf)) ||
memcmp(buf, "\xFF\xFF\xFF\xFFP2B", 7) ||
!stream.readRawData((char*)&version, sizeof(version))
@@ -264,13 +264,13 @@ public:
return ruleCount;
}
if(version==1 || version==2) {
if (version==1 || version==2) {
qDebug ("p2b version 1 or 2");
unsigned int start, end;
string name;
while(getlineInStream(stream, name, '\0') && !abort) {
if(
if (
!stream.readRawData((char*)&start, sizeof(start)) ||
!stream.readRawData((char*)&end, sizeof(end))
) {
@@ -289,26 +289,26 @@ public:
} catch(std::exception&) {}
}
}
else if(version==3) {
else if (version==3) {
qDebug ("p2b version 3");
unsigned int namecount;
if(!stream.readRawData((char*)&namecount, sizeof(namecount))) {
if (!stream.readRawData((char*)&namecount, sizeof(namecount))) {
std::cerr << "Parsing Error: The filter file is not a valid PeerGuardian P2B file." << std::endl;
return ruleCount;
}
namecount=ntohl(namecount);
// Reading names although, we don't really care about them
for(unsigned int i=0; i<namecount; i++) {
for (unsigned int i=0; i<namecount; i++) {
string name;
if(!getlineInStream(stream, name, '\0')) {
if (!getlineInStream(stream, name, '\0')) {
std::cerr << "Parsing Error: The filter file is not a valid PeerGuardian P2B file." << std::endl;
return ruleCount;
}
if(abort) return ruleCount;
if (abort) return ruleCount;
}
// Reading the ranges
unsigned int rangecount;
if(!stream.readRawData((char*)&rangecount, sizeof(rangecount))) {
if (!stream.readRawData((char*)&rangecount, sizeof(rangecount))) {
std::cerr << "Parsing Error: The filter file is not a valid PeerGuardian P2B file." << std::endl;
return ruleCount;
}
@@ -316,8 +316,8 @@ public:
unsigned int name, start, end;
for(unsigned int i=0; i<rangecount; i++) {
if(
for (unsigned int i=0; i<rangecount; i++) {
if (
!stream.readRawData((char*)&name, sizeof(name)) ||
!stream.readRawData((char*)&start, sizeof(start)) ||
!stream.readRawData((char*)&end, sizeof(end))
@@ -335,7 +335,7 @@ public:
filter.add_rule(first, last, libtorrent::ip_filter::blocked);
++ruleCount;
} catch(std::exception&) {}
if(abort) return ruleCount;
if (abort) return ruleCount;
}
} else {
std::cerr << "Parsing Error: The filter file is not a valid PeerGuardian P2B file." << std::endl;
@@ -354,7 +354,7 @@ public:
void processFilterFile(QString _filePath){
// First, import current filter
filter = s->get_ip_filter();
if(isRunning()) {
if (isRunning()) {
// Already parsing a filter, abort first
abort = true;
wait();
@@ -368,12 +368,12 @@ public:
static void processFilterList(libtorrent::session *s, const QStringList& IPs) {
// First, import current filter
libtorrent::ip_filter filter = s->get_ip_filter();
foreach(const QString &ip, IPs) {
foreach (const QString &ip, IPs) {
qDebug("Manual ban of peer %s", ip.toLocal8Bit().constData());
boost::system::error_code ec;
libtorrent::address addr = libtorrent::address::from_string(ip.toLocal8Bit().constData(), ec);
Q_ASSERT(!ec);
if(!ec)
if (!ec)
filter.add_rule(addr, addr, libtorrent::ip_filter::blocked);
}
s->set_ip_filter(filter);
@@ -386,7 +386,7 @@ signals:
protected:
QString cleanupIPAddress(QString _ip) {
QHostAddress ip(_ip.trimmed());
if(ip.isNull()) {
if (ip.isNull()) {
return QString();
}
return ip.toString();
@@ -395,11 +395,11 @@ protected:
void run(){
qDebug("Processing filter file");
int ruleCount = 0;
if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
if (filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
// PeerGuardian p2p file
ruleCount = parseP2PFilterFile(filePath);
} else {
if(filePath.endsWith(".p2b", Qt::CaseInsensitive)) {
if (filePath.endsWith(".p2b", Qt::CaseInsensitive)) {
// PeerGuardian p2b file
ruleCount = parseP2BFilterFile(filePath);
} else {
@@ -407,7 +407,7 @@ protected:
ruleCount = parseDATFilterFile(filePath);
}
}
if(abort)
if (abort)
return;
try {
s->set_ip_filter(filter);

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ using namespace std;
#if LIBTORRENT_VERSION_MINOR < 16
static QString boostTimeToQString(const boost::posix_time::ptime &boostDate) {
if(boostDate.is_not_a_date_time()) return "";
if (boostDate.is_not_a_date_time()) return "";
struct std::tm tm;
try {
tm = boost::posix_time::to_tm(boostDate);
@@ -81,7 +81,7 @@ QString QTorrentHandle::hash() const {
QString QTorrentHandle::name() const {
QString name = TorrentPersistentData::getName(hash());
if(name.isEmpty()) {
if (name.isEmpty()) {
name = misc::toQStringU(torrent_handle::name());
}
return name;
@@ -124,7 +124,7 @@ qreal QTorrentHandle::progress() const {
#else
torrent_status st = torrent_handle::status();
#endif
if(!st.total_wanted)
if (!st.total_wanted)
return 0.;
if (st.total_wanted_done == st.total_wanted)
return 1.;
@@ -182,19 +182,19 @@ int QTorrentHandle::num_pieces() const {
bool QTorrentHandle::first_last_piece_first() const {
// Detect first media file
int index = 0;
for(index = 0; index < num_files(); ++index) {
for (index = 0; index < num_files(); ++index) {
#if LIBTORRENT_VERSION_MINOR > 15
QString path = misc::toQStringU(get_torrent_info().file_at(index).path);
#else
QString path = misc::toQStringU(get_torrent_info().file_at(index).path.string());
#endif
const QString ext = misc::file_extension(path);
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
if (misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
break;
}
++index;
}
if(index >= torrent_handle::get_torrent_info().num_files()) return false;
if (index >= torrent_handle::get_torrent_info().num_files()) return false;
file_entry media_file = torrent_handle::get_torrent_info().file_at(index);
int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0);
@@ -285,7 +285,7 @@ QStringList QTorrentHandle::url_seeds() const {
try {
const std::set<std::string> existing_seeds = torrent_handle::url_seeds();
std::set<std::string>::const_iterator it;
for(it = existing_seeds.begin(); it != existing_seeds.end(); it++) {
for (it = existing_seeds.begin(); it != existing_seeds.end(); it++) {
qDebug("URL Seed: %s", it->c_str());
res << misc::toQString(*it);
}
@@ -306,8 +306,8 @@ size_type QTorrentHandle::actual_size() const {
bool QTorrentHandle::has_filtered_pieces() const {
std::vector<int> piece_priorities = torrent_handle::piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(!piece_priorities[i]) return true;
for (unsigned int i = 0; i<piece_priorities.size(); ++i) {
if (!piece_priorities[i]) return true;
}
return false;
}
@@ -432,7 +432,7 @@ size_type QTorrentHandle::total_payload_upload() const {
QStringList QTorrentHandle::absolute_files_path() const {
QDir saveDir(save_path());
QStringList res;
for(int i = 0; i<num_files(); ++i) {
for (int i = 0; i<num_files(); ++i) {
res << QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
}
return res;
@@ -442,10 +442,10 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
QDir saveDir(save_path());
QStringList res;
std::vector<int> fp = torrent_handle::file_priorities();
for(uint i = 0; i < fp.size(); ++i) {
if(fp[i] == 0) {
for (uint i = 0; i < fp.size(); ++i) {
if (fp[i] == 0) {
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
if(file_path.contains(".unwanted"))
if (file_path.contains(".unwanted"))
res << file_path;
}
}
@@ -454,14 +454,14 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
bool QTorrentHandle::has_missing_files() const {
const QStringList paths = absolute_files_path();
foreach(const QString &path, paths) {
if(!QFile::exists(path)) return true;
foreach (const QString &path, paths) {
if (!QFile::exists(path)) return true;
}
return false;
}
int QTorrentHandle::queue_position() const {
if(torrent_handle::queue_position() < 0)
if (torrent_handle::queue_position() < 0)
return -1;
return torrent_handle::queue_position()+1;
}
@@ -540,14 +540,14 @@ bool QTorrentHandle::priv() const {
QString QTorrentHandle::firstFileSavePath() const {
Q_ASSERT(has_metadata());
QString fsave_path = TorrentPersistentData::getSavePath(hash());
if(fsave_path.isEmpty())
if (fsave_path.isEmpty())
fsave_path = save_path();
fsave_path.replace("\\", "/");
if(!fsave_path.endsWith("/"))
if (!fsave_path.endsWith("/"))
fsave_path += "/";
fsave_path += filepath_at(0);
// Remove .!qB extension
if(fsave_path.endsWith(".!qB", Qt::CaseInsensitive))
if (fsave_path.endsWith(".!qB", Qt::CaseInsensitive))
fsave_path.chop(4);
return fsave_path;
}
@@ -572,7 +572,7 @@ QString QTorrentHandle::error() const {
void QTorrentHandle::downloading_pieces(bitfield &bf) const {
std::vector<partial_piece_info> queue;
torrent_handle::get_download_queue(queue);
for(std::vector<partial_piece_info>::iterator it=queue.begin(); it!= queue.end(); it++) {
for (std::vector<partial_piece_info>::iterator it=queue.begin(); it!= queue.end(); it++) {
bf.set_bit(it->piece_index);
}
return;
@@ -609,22 +609,22 @@ void QTorrentHandle::pause() const {
}
void QTorrentHandle::resume() const {
if(has_error()) torrent_handle::clear_error();
if (has_error()) torrent_handle::clear_error();
const QString torrent_hash = hash();
bool has_persistant_error = TorrentPersistentData::hasError(torrent_hash);
TorrentPersistentData::setErrorState(torrent_hash, false);
bool temp_path_enabled = Preferences().isTempPathEnabled();
if(has_persistant_error && temp_path_enabled) {
if (has_persistant_error && temp_path_enabled) {
// Torrent was supposed to be seeding, checking again in final destination
qDebug("Resuming a torrent with error...");
const QString final_save_path = TorrentPersistentData::getSavePath(torrent_hash);
qDebug("Torrent final path is: %s", qPrintable(final_save_path));
if(!final_save_path.isEmpty())
if (!final_save_path.isEmpty())
move_storage(final_save_path);
}
torrent_handle::auto_managed(true);
torrent_handle::resume();
if(has_persistant_error && temp_path_enabled) {
if (has_persistant_error && temp_path_enabled) {
// Force recheck
torrent_handle::force_recheck();
}
@@ -645,7 +645,7 @@ void QTorrentHandle::set_tracker_login(QString username, QString password) const
}
void QTorrentHandle::move_storage(QString new_path) const {
if(QDir(save_path()) == QDir(new_path)) return;
if (QDir(save_path()) == QDir(new_path)) return;
TorrentPersistentData::setPreviousSavePath(hash(), save_path());
// Create destination directory if necessary
// or move_storage() will fail...
@@ -655,12 +655,12 @@ void QTorrentHandle::move_storage(QString new_path) const {
}
bool QTorrentHandle::save_torrent_file(QString path) const {
if(!has_metadata()) return false;
if (!has_metadata()) return false;
entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size());
entry torrent_entry(entry::dictionary_t);
torrent_entry["info"] = meta;
if(!torrent_handle::trackers().empty())
if (!torrent_handle::trackers().empty())
torrent_entry["announce"] = torrent_handle::trackers().front().url;
vector<char> out;
@@ -677,14 +677,14 @@ bool QTorrentHandle::save_torrent_file(QString path) const {
void QTorrentHandle::file_priority(int index, int priority) const {
vector<int> priorities = torrent_handle::file_priorities();
if(priorities[index] != priority) {
if (priorities[index] != priority) {
priorities[index] = priority;
prioritize_files(priorities);
}
}
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
if((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
if ((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
qDebug() << Q_FUNC_INFO;
bool was_seed = is_seed();
vector<size_type> progress;
@@ -692,25 +692,25 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
qDebug() << Q_FUNC_INFO << "Changing files priorities...";
torrent_handle::prioritize_files(files);
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder...";
for(uint i=0; i<files.size(); ++i) {
for (uint i=0; i<files.size(); ++i) {
// Move unwanted files to a .unwanted subfolder
if(files[i] == 0 && progress[i] < filesize_at(i)) {
if (files[i] == 0 && progress[i] < filesize_at(i)) {
QString old_path = filepath_at(i);
// Make sure the file does not already exists
if(QFile::exists(QDir(save_path()).absoluteFilePath(old_path))) {
if (QFile::exists(QDir(save_path()).absoluteFilePath(old_path))) {
qWarning() << "File" << old_path << "already exists at destination.";
qWarning() << "We do not move it to .unwanted folder";
continue;
}
QString old_name = filename_at(i);
QString parent_path = misc::branchPath(old_path);
if(parent_path.isEmpty() || QDir(parent_path).dirName() != ".unwanted") {
if (parent_path.isEmpty() || QDir(parent_path).dirName() != ".unwanted") {
QString unwanted_abspath = QDir::cleanPath(save_path()+"/"+parent_path+"/.unwanted");
qDebug() << "Unwanted path is" << unwanted_abspath;
bool created = QDir().mkpath(unwanted_abspath);
#ifdef Q_WS_WIN
qDebug() << "unwanted folder was created:" << created;
if(created) {
if (created) {
// Hide the folder on Windows
qDebug() << "Hiding folder (Windows)";
wstring win_path = unwanted_abspath.replace("/","\\").toStdWString();
@@ -721,16 +721,16 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
#else
Q_UNUSED(created);
#endif
if(!parent_path.isEmpty() && !parent_path.endsWith("/"))
if (!parent_path.isEmpty() && !parent_path.endsWith("/"))
parent_path += "/";
rename_file(i, parent_path+".unwanted/"+old_name);
}
}
// Move wanted files back to their original folder
qDebug() << Q_FUNC_INFO << "Moving wanted files back from .unwanted folder";
if(files[i] > 0) {
if (files[i] > 0) {
QString parent_relpath = misc::branchPath(filepath_at(i));
if(QDir(parent_relpath).dirName() == ".unwanted") {
if (QDir(parent_relpath).dirName() == ".unwanted") {
QString old_name = filename_at(i);
QString new_relpath = misc::branchPath(parent_relpath);
if (new_relpath.isEmpty())
@@ -744,16 +744,16 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
}
}
if(was_seed && !is_seed()) {
if (was_seed && !is_seed()) {
qDebug() << "Torrent is no longer SEEDING";
// Save seed status
TorrentPersistentData::saveSeedStatus(*this);
// Move to temp folder if necessary
const Preferences pref;
if(pref.isTempPathEnabled()) {
if (pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
QString root_folder = TorrentPersistentData::getRootFolder(hash());
if(!root_folder.isEmpty())
if (!root_folder.isEmpty())
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << save_path();
move_storage(tmp_path);
@@ -768,7 +768,7 @@ void QTorrentHandle::add_tracker(const announce_entry& url) const {
void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
// Determine the priority to set
int prio = 7; // MAX
if(!b) prio = torrent_handle::file_priority(file_index);
if (!b) prio = torrent_handle::file_priority(file_index);
file_entry file = get_torrent_info().file_at(file_index);
// Determine the first and last piece of the file
int piece_size = torrent_handle::get_torrent_info().piece_length();
@@ -785,13 +785,13 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
}
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
if(!has_metadata()) return;
if (!has_metadata()) return;
// Download first and last pieces first for all media files in the torrent
int index = 0;
for(index = 0; index < num_files(); ++index) {
for (index = 0; index < num_files(); ++index) {
const QString path = filepath_at(index);
const QString ext = misc::file_extension(path);
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
if (misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
qDebug() << "File" << path << "is previewable, toggle downloading of first/last pieces first";
prioritize_first_last_piece(index, b);
}

View File

@@ -41,7 +41,7 @@ TorrentModelItem::TorrentModelItem(const QTorrentHandle &h)
m_torrent = h;
m_hash = h.hash();
m_name = TorrentPersistentData::getName(h.hash());
if(m_name.isEmpty()) m_name = h.name();
if (m_name.isEmpty()) m_name = h.name();
m_addedTime = TorrentPersistentData::getAddedDate(h.hash());
m_seedTime = TorrentPersistentData::getSeedDate(h.hash());
m_label = TorrentPersistentData::getLabel(h.hash());
@@ -51,13 +51,13 @@ TorrentModelItem::State TorrentModelItem::state() const
{
try {
// Pause or Queued
if(m_torrent.is_paused()) {
if (m_torrent.is_paused()) {
m_icon = QIcon(":/Icons/skin/paused.png");
m_fgColor = QColor("red");
return m_torrent.is_seed() ? STATE_PAUSED_UP : STATE_PAUSED_DL;
}
if(m_torrent.is_queued()) {
if(m_torrent.state() != torrent_status::queued_for_checking
if (m_torrent.is_queued()) {
if (m_torrent.state() != torrent_status::queued_for_checking
&& m_torrent.state() != torrent_status::checking_resume_data
&& m_torrent.state() != torrent_status::checking_files) {
m_icon = QIcon(":/Icons/skin/queued.png");
@@ -70,7 +70,7 @@ TorrentModelItem::State TorrentModelItem::state() const
case torrent_status::allocating:
case torrent_status::downloading_metadata:
case torrent_status::downloading: {
if(m_torrent.download_payload_rate() > 0) {
if (m_torrent.download_payload_rate() > 0) {
m_icon = QIcon(":/Icons/skin/downloading.png");
m_fgColor = QColor("green");
return STATE_DOWNLOADING;
@@ -82,7 +82,7 @@ TorrentModelItem::State TorrentModelItem::state() const
}
case torrent_status::finished:
case torrent_status::seeding:
if(m_torrent.upload_payload_rate() > 0) {
if (m_torrent.upload_payload_rate() > 0) {
m_icon = QIcon(":/Icons/skin/uploading.png");
m_fgColor = QColor("orange");
return STATE_SEEDING;
@@ -112,7 +112,7 @@ TorrentModelItem::State TorrentModelItem::state() const
bool TorrentModelItem::setData(int column, const QVariant &value, int role)
{
qDebug() << Q_FUNC_INFO << column << value;
if(role != Qt::DisplayRole) return false;
if (role != Qt::DisplayRole) return false;
// Label and Name columns can be edited
switch(column) {
case TR_NAME:
@@ -121,7 +121,7 @@ bool TorrentModelItem::setData(int column, const QVariant &value, int role)
return true;
case TR_LABEL: {
QString new_label = value.toString();
if(m_label != new_label) {
if (m_label != new_label) {
QString old_label = m_label;
m_label = new_label;
TorrentPersistentData::saveLabel(m_torrent.hash(), new_label);
@@ -137,13 +137,13 @@ bool TorrentModelItem::setData(int column, const QVariant &value, int role)
QVariant TorrentModelItem::data(int column, int role) const
{
if(role == Qt::DecorationRole && column == TR_NAME) {
if (role == Qt::DecorationRole && column == TR_NAME) {
return m_icon;
}
if(role == Qt::ForegroundRole) {
if (role == Qt::ForegroundRole) {
return m_fgColor;
}
if(role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
if (role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
switch(column) {
case TR_NAME:
return m_name.isEmpty()? m_torrent.name() : m_name;
@@ -167,7 +167,7 @@ QVariant TorrentModelItem::data(int column, int role) const
return m_torrent.upload_payload_rate();
case TR_ETA: {
// XXX: Is this correct?
if(m_torrent.is_seed() || m_torrent.is_paused() || m_torrent.is_queued()) return MAX_ETA;
if (m_torrent.is_seed() || m_torrent.is_paused() || m_torrent.is_queued()) return MAX_ETA;
return QBtSession::instance()->getETA(m_torrent.hash());
}
case TR_RATIO:
@@ -206,7 +206,7 @@ void TorrentModel::populate() {
// Load the torrents
std::vector<torrent_handle> torrents = QBtSession::instance()->getSession()->get_torrents();
std::vector<torrent_handle>::const_iterator it;
for(it = torrents.begin(); it != torrents.end(); it++) {
for (it = torrents.begin(); it != torrents.end(); it++) {
addTorrent(QTorrentHandle(*it));
}
// Refresh timer
@@ -234,7 +234,7 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal) {
if(role == Qt::DisplayRole) {
if (role == Qt::DisplayRole) {
switch(section) {
case TorrentModelItem::TR_NAME: return tr("Name", "i.e: torrent name");
case TorrentModelItem::TR_PRIORITY: return "#";
@@ -260,7 +260,7 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation,
return QVariant();
}
}
if(role == Qt::TextAlignmentRole) {
if (role == Qt::TextAlignmentRole) {
switch(section) {
case TorrentModelItem::TR_PRIORITY:
case TorrentModelItem::TR_SIZE:
@@ -287,9 +287,9 @@ QVariant TorrentModel::headerData(int section, Qt::Orientation orientation,
QVariant TorrentModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid()) return QVariant();
if (!index.isValid()) return QVariant();
try {
if(index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount())
if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount())
return m_torrents[index.row()]->data(index.column(), role);
} catch(invalid_handle&) {}
return QVariant();
@@ -298,12 +298,12 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const
bool TorrentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
qDebug() << Q_FUNC_INFO << value;
if(!index.isValid() || role != Qt::DisplayRole) return false;
if (!index.isValid() || role != Qt::DisplayRole) return false;
qDebug("Index is valid and role is DisplayRole");
try {
if(index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount()) {
if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0 && index.column() < columnCount()) {
bool change = m_torrents[index.row()]->setData(index.column(), value, role);
if(change)
if (change)
notifyTorrentChanged(index.row());
return change;
}
@@ -315,8 +315,8 @@ int TorrentModel::torrentRow(const QString &hash) const
{
QList<TorrentModelItem*>::const_iterator it;
int row = 0;
for(it = m_torrents.constBegin(); it != m_torrents.constEnd(); it++) {
if((*it)->hash() == hash) return row;
for (it = m_torrents.constBegin(); it != m_torrents.constEnd(); it++) {
if ((*it)->hash() == hash) return row;
++row;
}
return -1;
@@ -324,7 +324,7 @@ int TorrentModel::torrentRow(const QString &hash) const
void TorrentModel::addTorrent(const QTorrentHandle &h)
{
if(torrentRow(h.hash()) < 0) {
if (torrentRow(h.hash()) < 0) {
beginInsertTorrent(m_torrents.size());
TorrentModelItem *item = new TorrentModelItem(h);
connect(item, SIGNAL(labelChanged(QString,QString)), SLOT(handleTorrentLabelChange(QString,QString)));
@@ -338,7 +338,7 @@ void TorrentModel::removeTorrent(const QString &hash)
{
const int row = torrentRow(hash);
qDebug() << Q_FUNC_INFO << hash << row;
if(row >= 0) {
if (row >= 0) {
beginRemoveTorrent(row);
m_torrents.removeAt(row);
endRemoveTorrent();
@@ -368,7 +368,7 @@ void TorrentModel::endRemoveTorrent()
void TorrentModel::handleTorrentUpdate(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if(row >= 0) {
if (row >= 0) {
notifyTorrentChanged(row);
}
}
@@ -380,7 +380,7 @@ void TorrentModel::notifyTorrentChanged(int row)
void TorrentModel::setRefreshInterval(int refreshInterval)
{
if(m_refreshInterval != refreshInterval) {
if (m_refreshInterval != refreshInterval) {
m_refreshInterval = refreshInterval;
m_refreshTimer.stop();
m_refreshTimer.start(m_refreshInterval);
@@ -396,7 +396,7 @@ TorrentStatusReport TorrentModel::getTorrentStatusReport() const
{
TorrentStatusReport report;
QList<TorrentModelItem*>::const_iterator it;
for(it = m_torrents.constBegin(); it != m_torrents.constEnd(); it++) {
for (it = m_torrents.constBegin(); it != m_torrents.constEnd(); it++) {
switch((*it)->data(TorrentModelItem::TR_STATUS).toInt()) {
case TorrentModelItem::STATE_DOWNLOADING:
++report.nb_active;
@@ -446,7 +446,7 @@ void TorrentModel::handleTorrentLabelChange(QString previous, QString current)
QString TorrentModel::torrentHash(int row) const
{
if(row >= 0 && row < rowCount())
if (row >= 0 && row < rowCount())
return m_torrents.at(row)->hash();
return QString();
}
@@ -454,7 +454,7 @@ QString TorrentModel::torrentHash(int row) const
void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if(row >= 0) {
if (row >= 0) {
emit torrentAboutToBeRemoved(m_torrents.at(row));
}
}

View File

@@ -79,13 +79,13 @@ void TorrentSpeedMonitor::run()
void SpeedSample::addSample(int s)
{
m_speedSamples << s;
if(m_speedSamples.size() > max_samples)
if (m_speedSamples.size() > max_samples)
m_speedSamples.removeFirst();
}
qreal SpeedSample::average() const
{
if(m_speedSamples.empty()) return 0;
if (m_speedSamples.empty()) return 0;
qlonglong sum = 0;
foreach (int s, m_speedSamples) {
sum += s;
@@ -113,9 +113,9 @@ qlonglong TorrentSpeedMonitor::getETA(const QString &hash) const
{
QMutexLocker locker(&m_mutex);
QTorrentHandle h = m_session->getTorrentHandle(hash);
if(h.is_paused() || !m_samples.contains(hash)) return -1;
if (h.is_paused() || !m_samples.contains(hash)) return -1;
const qreal speed_average = m_samples.value(hash).average();
if(speed_average == 0) return -1;
if (speed_average == 0) return -1;
return (h.total_wanted() - h.total_done()) / speed_average;
}
@@ -123,14 +123,14 @@ void TorrentSpeedMonitor::getSamples()
{
const std::vector<torrent_handle> torrents = m_session->getSession()->get_torrents();
std::vector<torrent_handle>::const_iterator it;
for(it = torrents.begin(); it != torrents.end(); it++) {
for (it = torrents.begin(); it != torrents.end(); it++) {
try {
#if LIBTORRENT_VERSION_MINOR > 15
torrent_status st = it->status(0x0);
if(!st.paused)
if (!st.paused)
m_samples[misc::toQString(it->info_hash())].addSample(st.download_payload_rate);
#else
if(!it->is_paused())
if (!it->is_paused())
m_samples[misc::toQString(it->info_hash())].addSample(it->status().download_payload_rate);
#endif
} catch(invalid_handle&){}