- Fixing indentation

- Stop catching SIGINT and SIGTERM once the application has exiting
This commit is contained in:
Christophe Dumez 2010-01-02 23:03:46 +00:00
parent 78ba99778a
commit 99459dc55d
4 changed files with 952 additions and 940 deletions

View file

@ -42,7 +42,7 @@
#include "filterparserthread.h" #include "filterparserthread.h"
#include "preferences.h" #include "preferences.h"
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include "geoip.h" #include "geoip.h"
#endif #endif
#include "torrentpersistentdata.h" #include "torrentpersistentdata.h"
#include "httpserver.h" #include "httpserver.h"
@ -1268,16 +1268,16 @@ QStringList Bittorrent::getPeerBanMessages() const {
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
void Bittorrent::addConsoleMessage(QString msg, QString) { void Bittorrent::addConsoleMessage(QString msg, QString) {
#else #else
void Bittorrent::addConsoleMessage(QString msg, QColor color) { void Bittorrent::addConsoleMessage(QString msg, QColor color) {
if(consoleMessages.size() > 100) { if(consoleMessages.size() > 100) {
consoleMessages.removeFirst(); consoleMessages.removeFirst();
} }
consoleMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + msg + QString::fromUtf8("</i></font>")); consoleMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + msg + QString::fromUtf8("</i></font>"));
#endif #endif
emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg); emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg);
} }
void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) { void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) {
if(peerBanMessages.size() > 100) { if(peerBanMessages.size() > 100) {
peerBanMessages.removeFirst(); peerBanMessages.removeFirst();
} }
@ -1285,9 +1285,9 @@ void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) {
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was blocked due to your IP filter</i>", "x.y.z.w was blocked").arg(ip)); peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was blocked due to your IP filter</i>", "x.y.z.w was blocked").arg(ip));
else else
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip)); peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip));
} }
bool Bittorrent::isFilePreviewPossible(QString hash) const{ bool Bittorrent::isFilePreviewPossible(QString hash) const{
// See if there are supported files in the torrent // See if there are supported files in the torrent
QTorrentHandle h = getTorrentHandle(hash); QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_valid()) { if(!h.is_valid()) {
@ -1302,9 +1302,9 @@ bool Bittorrent::isFilePreviewPossible(QString hash) const{
return true; return true;
} }
return false; return false;
} }
void Bittorrent::addTorrentsFromScanFolder(QStringList &pathList) { void Bittorrent::addTorrentsFromScanFolder(QStringList &pathList) {
QString dir_path = FSWatcher->directories().first(); QString dir_path = FSWatcher->directories().first();
foreach(const QString &file, pathList) { foreach(const QString &file, pathList) {
QString fullPath = dir_path+QDir::separator()+file; QString fullPath = dir_path+QDir::separator()+file;
@ -1315,17 +1315,17 @@ void Bittorrent::addTorrentsFromScanFolder(QStringList &pathList) {
qDebug("Ignoring incomplete torrent file: %s", fullPath.toLocal8Bit().data()); qDebug("Ignoring incomplete torrent file: %s", fullPath.toLocal8Bit().data());
} }
} }
} }
QString Bittorrent::getDefaultSavePath() const { QString Bittorrent::getDefaultSavePath() const {
return defaultSavePath; return defaultSavePath;
} }
bool Bittorrent::useTemporaryFolder() const { bool Bittorrent::useTemporaryFolder() const {
return !defaultTempPath.isEmpty(); return !defaultTempPath.isEmpty();
} }
void Bittorrent::setDefaultTempPath(QString temppath) { void Bittorrent::setDefaultTempPath(QString temppath) {
if(defaultTempPath == temppath) if(defaultTempPath == temppath)
return; return;
if(temppath.isEmpty()) { if(temppath.isEmpty()) {
@ -1350,10 +1350,10 @@ void Bittorrent::setDefaultTempPath(QString temppath) {
} }
} }
defaultTempPath = temppath; defaultTempPath = temppath;
} }
#ifdef LIBTORRENT_0_15 #ifdef LIBTORRENT_0_15
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) { void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) {
if(!h.is_valid() || !h.has_metadata()) return; if(!h.is_valid() || !h.has_metadata()) return;
std::vector<size_type> fp; std::vector<size_type> fp;
h.file_progress(fp); h.file_progress(fp);
@ -1376,10 +1376,10 @@ void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) {
} }
} }
} }
} }
#endif #endif
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) { void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) {
if(!h.is_valid()) return; if(!h.is_valid()) return;
if(!appendLabelToSavePath) return; if(!appendLabelToSavePath) return;
QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
@ -1406,9 +1406,9 @@ void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_labe
h.move_storage(new_save_path); h.move_storage(new_save_path);
} }
emit savePathChanged(h); emit savePathChanged(h);
} }
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) { void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) {
if(!h.is_valid()) return; if(!h.is_valid()) return;
QString label = TorrentPersistentData::getLabel(h.hash()); QString label = TorrentPersistentData::getLabel(h.hash());
if(label.isEmpty()) return; if(label.isEmpty()) return;
@ -1424,9 +1424,9 @@ void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) {
} }
emit savePathChanged(h); emit savePathChanged(h);
} }
} }
void Bittorrent::setAppendLabelToSavePath(bool append) { void Bittorrent::setAppendLabelToSavePath(bool append) {
if(appendLabelToSavePath != append) { if(appendLabelToSavePath != append) {
appendLabelToSavePath = !appendLabelToSavePath; appendLabelToSavePath = !appendLabelToSavePath;
if(appendLabelToSavePath) { if(appendLabelToSavePath) {
@ -1439,10 +1439,10 @@ void Bittorrent::setAppendLabelToSavePath(bool append) {
} }
} }
} }
} }
#ifdef LIBTORRENT_0_15 #ifdef LIBTORRENT_0_15
void Bittorrent::setAppendqBExtension(bool append) { void Bittorrent::setAppendqBExtension(bool append) {
if(appendqBExtension != append) { if(appendqBExtension != append) {
appendqBExtension = !appendqBExtension; appendqBExtension = !appendqBExtension;
// append or remove .!qB extension for incomplete files // append or remove .!qB extension for incomplete files
@ -1453,11 +1453,11 @@ void Bittorrent::setAppendqBExtension(bool append) {
appendqBextensionToTorrent(h, appendqBExtension); appendqBextensionToTorrent(h, appendqBExtension);
} }
} }
} }
#endif #endif
// Enable directory scanning // Enable directory scanning
void Bittorrent::enableDirectoryScanning(QString scan_dir) { void Bittorrent::enableDirectoryScanning(QString scan_dir) {
if(!scan_dir.isEmpty()) { if(!scan_dir.isEmpty()) {
QDir newDir(scan_dir); QDir newDir(scan_dir);
if(!newDir.exists()) { if(!newDir.exists()) {
@ -1480,43 +1480,43 @@ void Bittorrent::enableDirectoryScanning(QString scan_dir) {
} }
} }
} }
} }
// Disable directory scanning // Disable directory scanning
void Bittorrent::disableDirectoryScanning() { void Bittorrent::disableDirectoryScanning() {
if(FSWatcher) { if(FSWatcher) {
delete FSWatcher; delete FSWatcher;
} }
} }
// Set the ports range in which is chosen the port the Bittorrent // Set the ports range in which is chosen the port the Bittorrent
// session will listen to // session will listen to
void Bittorrent::setListeningPort(int port) { void Bittorrent::setListeningPort(int port) {
std::pair<int,int> ports(port, port); std::pair<int,int> ports(port, port);
s->listen_on(ports); s->listen_on(ports);
} }
// Set download rate limit // Set download rate limit
// -1 to disable // -1 to disable
void Bittorrent::setDownloadRateLimit(long rate) { void Bittorrent::setDownloadRateLimit(long rate) {
qDebug("Setting a global download rate limit at %ld", rate); qDebug("Setting a global download rate limit at %ld", rate);
s->set_download_rate_limit(rate); s->set_download_rate_limit(rate);
} }
session* Bittorrent::getSession() const{ session* Bittorrent::getSession() const{
return s; return s;
} }
// Set upload rate limit // Set upload rate limit
// -1 to disable // -1 to disable
void Bittorrent::setUploadRateLimit(long rate) { void Bittorrent::setUploadRateLimit(long rate) {
qDebug("set upload_limit to %fkb/s", rate/1024.); qDebug("set upload_limit to %fkb/s", rate/1024.);
s->set_upload_rate_limit(rate); s->set_upload_rate_limit(rate);
} }
// libtorrent allow to adjust ratio for each torrent // libtorrent allow to adjust ratio for each torrent
// This function will apply to same ratio to all torrents // This function will apply to same ratio to all torrents
void Bittorrent::setGlobalRatio(float ratio) { void Bittorrent::setGlobalRatio(float ratio) {
if(ratio != -1 && ratio < 1.) ratio = 1.; if(ratio != -1 && ratio < 1.) ratio = 1.;
if(ratio == -1) { if(ratio == -1) {
// 0 means unlimited for libtorrent // 0 means unlimited for libtorrent
@ -1532,11 +1532,11 @@ void Bittorrent::setGlobalRatio(float ratio) {
} }
h.set_ratio(ratio); h.set_ratio(ratio);
} }
} }
// Torrents will a ratio superior to the given value will // Torrents will a ratio superior to the given value will
// be automatically deleted // be automatically deleted
void Bittorrent::setDeleteRatio(float ratio) { void Bittorrent::setDeleteRatio(float ratio) {
if(ratio != -1 && ratio < 1.) ratio = 1.; if(ratio != -1 && ratio < 1.) ratio = 1.;
if(ratio_limit == -1 && ratio != -1) { if(ratio_limit == -1 && ratio != -1) {
Q_ASSERT(!BigRatioTimer); Q_ASSERT(!BigRatioTimer);
@ -1553,10 +1553,10 @@ void Bittorrent::setDeleteRatio(float ratio) {
qDebug("* Set deleteRatio to %.1f", ratio_limit); qDebug("* Set deleteRatio to %.1f", ratio_limit);
deleteBigRatios(); deleteBigRatios();
} }
} }
// Set DHT port (>= 1000 or 0 if same as BT) // Set DHT port (>= 1000 or 0 if same as BT)
void Bittorrent::setDHTPort(int dht_port) { void Bittorrent::setDHTPort(int dht_port) {
if(dht_port == 0 || dht_port >= 1000) { if(dht_port == 0 || dht_port >= 1000) {
if(dht_port == current_dht_port) return; if(dht_port == current_dht_port) return;
struct dht_settings DHTSettings; struct dht_settings DHTSettings;
@ -1565,10 +1565,10 @@ void Bittorrent::setDHTPort(int dht_port) {
current_dht_port = dht_port; current_dht_port = dht_port;
qDebug("Set DHT Port to %d", dht_port); qDebug("Set DHT Port to %d", dht_port);
} }
} }
// Enable IP Filtering // Enable IP Filtering
void Bittorrent::enableIPFilter(QString filter) { void Bittorrent::enableIPFilter(QString filter) {
qDebug("Enabling IPFiler"); qDebug("Enabling IPFiler");
if(!filterParser) { if(!filterParser) {
filterParser = new FilterParserThread(this, s); filterParser = new FilterParserThread(this, s);
@ -1577,32 +1577,32 @@ void Bittorrent::enableIPFilter(QString filter) {
filterPath = filter; filterPath = filter;
filterParser->processFilterFile(filter); filterParser->processFilterFile(filter);
} }
} }
// Disable IP Filtering // Disable IP Filtering
void Bittorrent::disableIPFilter() { void Bittorrent::disableIPFilter() {
qDebug("Disabling IPFilter"); qDebug("Disabling IPFilter");
s->set_ip_filter(ip_filter()); s->set_ip_filter(ip_filter());
if(filterParser) { if(filterParser) {
delete filterParser; delete filterParser;
} }
filterPath = ""; filterPath = "";
} }
// Set BT session settings (user_agent) // Set BT session settings (user_agent)
void Bittorrent::setSessionSettings(session_settings sessionSettings) { void Bittorrent::setSessionSettings(session_settings sessionSettings) {
qDebug("Set session settings"); qDebug("Set session settings");
s->set_settings(sessionSettings); s->set_settings(sessionSettings);
} }
// Set Proxy // Set Proxy
void Bittorrent::setPeerProxySettings(proxy_settings proxySettings) { void Bittorrent::setPeerProxySettings(proxy_settings proxySettings) {
qDebug("Set Peer Proxy settings"); qDebug("Set Peer Proxy settings");
s->set_peer_proxy(proxySettings); s->set_peer_proxy(proxySettings);
s->set_dht_proxy(proxySettings); s->set_dht_proxy(proxySettings);
} }
void Bittorrent::setHTTPProxySettings(proxy_settings proxySettings) { void Bittorrent::setHTTPProxySettings(proxy_settings proxySettings) {
s->set_tracker_proxy(proxySettings); s->set_tracker_proxy(proxySettings);
s->set_web_seed_proxy(proxySettings); s->set_web_seed_proxy(proxySettings);
QString proxy_str; QString proxy_str;
@ -1629,10 +1629,10 @@ void Bittorrent::setHTTPProxySettings(proxy_settings proxySettings) {
qDebug("HTTP: proxy string: %s", proxy_str.toLocal8Bit().data()); qDebug("HTTP: proxy string: %s", proxy_str.toLocal8Bit().data());
setenv("http_proxy", proxy_str.toLocal8Bit().data(), 1); setenv("http_proxy", proxy_str.toLocal8Bit().data(), 1);
#endif #endif
} }
// Read alerts sent by the Bittorrent session // Read alerts sent by the Bittorrent session
void Bittorrent::readAlerts() { void Bittorrent::readAlerts() {
// look at session alerts and display some infos // look at session alerts and display some infos
std::auto_ptr<alert> a = s->pop_alert(); std::auto_ptr<alert> a = s->pop_alert();
while (a.get()) { while (a.get()) {
@ -1846,22 +1846,22 @@ void Bittorrent::readAlerts() {
} }
a = s->pop_alert(); a = s->pop_alert();
} }
} }
QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{ QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{
return trackersInfos.value(hash, QHash<QString, TrackerInfos>()); return trackersInfos.value(hash, QHash<QString, TrackerInfos>());
} }
int Bittorrent::getListenPort() const{ int Bittorrent::getListenPort() const{
qDebug("LISTEN PORT: %d", s->listen_port()); qDebug("LISTEN PORT: %d", s->listen_port());
return s->listen_port(); return s->listen_port();
} }
session_status Bittorrent::getSessionStatus() const{ session_status Bittorrent::getSessionStatus() const{
return s->status(); return s->status();
} }
QString Bittorrent::getSavePath(QString hash) { QString Bittorrent::getSavePath(QString hash) {
QString savePath; QString savePath;
if(TorrentTempData::hasTempData(hash)) { if(TorrentTempData::hasTempData(hash)) {
savePath = TorrentTempData::getSavePath(hash); savePath = TorrentTempData::getSavePath(hash);
@ -1905,12 +1905,12 @@ QString Bittorrent::getSavePath(QString hash) {
} }
} }
return savePath; return savePath;
} }
// Take an url string to a torrent file, // Take an url string to a torrent file,
// download the torrent file to a tmp location, then // download the torrent file to a tmp location, then
// add it to download list // add it to download list
void Bittorrent::downloadFromUrl(QString url) { void Bittorrent::downloadFromUrl(QString url) {
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url) addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, QPalette::WindowText , QPalette::WindowText
@ -1919,19 +1919,19 @@ void Bittorrent::downloadFromUrl(QString url) {
//emit aboutToDownloadFromUrl(url); //emit aboutToDownloadFromUrl(url);
// Launch downloader thread // Launch downloader thread
downloader->downloadUrl(url); downloader->downloadUrl(url);
} }
void Bittorrent::downloadFromURLList(const QStringList& urls) { void Bittorrent::downloadFromURLList(const QStringList& urls) {
foreach(const QString &url, urls) { foreach(const QString &url, urls) {
downloadFromUrl(url); downloadFromUrl(url);
} }
} }
void Bittorrent::addMagnetSkipAddDlg(QString uri) { void Bittorrent::addMagnetSkipAddDlg(QString uri) {
addMagnetUri(uri, false); addMagnetUri(uri, false);
} }
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) { void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
//emit aboutToDownloadFromUrl(url); //emit aboutToDownloadFromUrl(url);
QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit()); QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
if(!save_path.isEmpty()) if(!save_path.isEmpty())
@ -1939,10 +1939,10 @@ void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
url_skippingDlg << qurl; url_skippingDlg << qurl;
// Launch downloader thread // Launch downloader thread
downloader->downloadUrl(url); downloader->downloadUrl(url);
} }
// Add to Bittorrent session the downloaded torrent file // Add to Bittorrent session the downloaded torrent file
void Bittorrent::processDownloadedFile(QString url, QString file_path) { void Bittorrent::processDownloadedFile(QString url, QString file_path) {
int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit())); int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
if(index < 0) { if(index < 0) {
// Add file to torrent download list // Add file to torrent download list
@ -1951,26 +1951,26 @@ void Bittorrent::processDownloadedFile(QString url, QString file_path) {
url_skippingDlg.removeAt(index); url_skippingDlg.removeAt(index);
addTorrent(file_path, false, url, false); addTorrent(file_path, false, url, false);
} }
} }
// Return current download rate for the BT // Return current download rate for the BT
// session. Payload means that it only take into // session. Payload means that it only take into
// account "useful" part of the rate // account "useful" part of the rate
float Bittorrent::getPayloadDownloadRate() const{ float Bittorrent::getPayloadDownloadRate() const{
session_status sessionStatus = s->status(); session_status sessionStatus = s->status();
return sessionStatus.payload_download_rate; return sessionStatus.payload_download_rate;
} }
// Return current upload rate for the BT // Return current upload rate for the BT
// session. Payload means that it only take into // session. Payload means that it only take into
// account "useful" part of the rate // account "useful" part of the rate
float Bittorrent::getPayloadUploadRate() const{ float Bittorrent::getPayloadUploadRate() const{
session_status sessionStatus = s->status(); session_status sessionStatus = s->status();
return sessionStatus.payload_upload_rate; return sessionStatus.payload_upload_rate;
} }
// Save DHT entry to hard drive // Save DHT entry to hard drive
void Bittorrent::saveDHTEntry() { void Bittorrent::saveDHTEntry() {
// Save DHT entry // Save DHT entry
if(DHTEnabled) { if(DHTEnabled) {
try{ try{
@ -1983,16 +1983,16 @@ void Bittorrent::saveDHTEntry() {
std::cerr << e.what() << "\n"; std::cerr << e.what() << "\n";
} }
} }
} }
void Bittorrent::applyEncryptionSettings(pe_settings se) { void Bittorrent::applyEncryptionSettings(pe_settings se) {
qDebug("Applying encryption settings"); qDebug("Applying encryption settings");
s->set_pe_settings(se); s->set_pe_settings(se);
} }
// Will fast resume torrents in // Will fast resume torrents in
// backup directory // backup directory
void Bittorrent::startUpTorrents() { void Bittorrent::startUpTorrents() {
qDebug("Resuming unfinished torrents"); qDebug("Resuming unfinished torrents");
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QDir torrentBackup(misc::BTBackupLocation()); QDir torrentBackup(misc::BTBackupLocation());
@ -2053,11 +2053,11 @@ void Bittorrent::startUpTorrents() {
} }
} }
qDebug("Unfinished torrents resumed"); qDebug("Unfinished torrents resumed");
} }
// Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces // Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces
// TODO: Remove in qBittorrent v2.2.0 // TODO: Remove in qBittorrent v2.2.0
void Bittorrent::importOldTempData(QString torrent_path) { void Bittorrent::importOldTempData(QString torrent_path) {
// Create torrent hash // Create torrent hash
boost::intrusive_ptr<torrent_info> t; boost::intrusive_ptr<torrent_info> t;
try { try {
@ -2103,11 +2103,11 @@ void Bittorrent::importOldTempData(QString torrent_path) {
} }
} catch(std::exception&) { } catch(std::exception&) {
} }
} }
// Trackers, web seeds, speed limits // Trackers, web seeds, speed limits
// TODO: Remove in qBittorrent v2.2.0 // TODO: Remove in qBittorrent v2.2.0
void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
// Load trackers // Load trackers
QDir torrentBackup(misc::BTBackupLocation()); QDir torrentBackup(misc::BTBackupLocation());
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers"); QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers");
@ -2172,11 +2172,11 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
h.set_upload_limit(speeds.at(1).toInt()); h.set_upload_limit(speeds.at(1).toInt());
} }
} }
} }
// Import torrents from v1.4.0 or earlier // Import torrents from v1.4.0 or earlier
// TODO: Remove in qBittorrent v2.2.0 // TODO: Remove in qBittorrent v2.2.0
void Bittorrent::importOldTorrents() { void Bittorrent::importOldTorrents() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool()); Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool());
// Import old torrent // Import old torrent
@ -2252,4 +2252,4 @@ void Bittorrent::importOldTorrents() {
} }
settings.setValue("v1_4_x_torrent_imported", true); settings.setValue("v1_4_x_torrent_imported", true);
std::cout << "Successfully imported torrents from v1.4.x (or previous) instance" << std::endl; std::cout << "Successfully imported torrents from v1.4.x (or previous) instance" << std::endl;
} }

View file

@ -35,10 +35,10 @@
#include <QUrl> #include <QUrl>
#include <QStringList> #include <QStringList>
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
#include <QCoreApplication> #include <QCoreApplication>
#else #else
#include <QApplication> #include <QApplication>
#include <QPalette> #include <QPalette>
#endif #endif
#include <QPointer> #include <QPointer>

View file

@ -33,23 +33,23 @@
#include <QFile> #include <QFile>
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include <QApplication> #include <QApplication>
#include <QSplashScreen> #include <QSplashScreen>
#include <QPlastiqueStyle> #include <QPlastiqueStyle>
#include "qgnomelook.h" #include "qgnomelook.h"
#include <QMotifStyle> #include <QMotifStyle>
#include <QCDEStyle> #include <QCDEStyle>
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#include <QWindowsXPStyle> #include <QWindowsXPStyle>
#endif #endif
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
#include <QMacStyle> #include <QMacStyle>
#endif #endif
#include "GUI.h" #include "GUI.h"
#include "ico.h" #include "ico.h"
#else #else
#include <QCoreApplication> #include <QCoreApplication>
#include "headlessloader.h" #include "headlessloader.h"
#endif #endif
#include <QSettings> #include <QSettings>
@ -67,12 +67,17 @@
#include "preferences.h" #include "preferences.h"
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
QCoreApplication *app; QCoreApplication *app;
#else #else
QApplication *app; QApplication *app;
#endif #endif
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
void sigintHandler(int) {
qDebug("Catching SIGINT, exiting cleanly");
app->exit();
}
void sigtermHandler(int) { void sigtermHandler(int) {
qDebug("Catching SIGTERM, exiting cleanly"); qDebug("Catching SIGTERM, exiting cleanly");
app->exit(); app->exit();
@ -246,7 +251,7 @@ int main(int argc, char *argv[]){
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
signal(SIGABRT, sigabrtHandler); signal(SIGABRT, sigabrtHandler);
signal(SIGTERM, sigtermHandler); signal(SIGTERM, sigtermHandler);
signal(SIGINT, sigtermHandler); signal(SIGINT, sigintHandler);
signal(SIGSEGV, sigsegvHandler); signal(SIGSEGV, sigsegvHandler);
#endif #endif
// Read torrents given on command line // Read torrents given on command line
@ -264,6 +269,13 @@ int main(int argc, char *argv[]){
HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine); HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine);
#endif #endif
int ret = app->exec(); int ret = app->exec();
#ifndef Q_WS_WIN
// Application has exited, stop catching SIGINT and SIGTERM
signal(SIGINT, 0);
signal(SIGTERM, 0);
#endif
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
delete window; delete window;
qDebug("GUI was deleted!"); qDebug("GUI was deleted!");

View file

@ -47,9 +47,9 @@
#include <boost/date_time/posix_time/conversion.hpp> #include <boost/date_time/posix_time/conversion.hpp>
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
#include <QCoreApplication> #include <QCoreApplication>
#else #else
#include <QApplication> #include <QApplication>
#endif #endif
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
@ -183,16 +183,16 @@ public:
} }
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
static QString getFullPath(const FSRef &ref) static QString getFullPath(const FSRef &ref)
{ {
QByteArray ba(2048, 0); QByteArray ba(2048, 0);
if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr) if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr)
return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C); return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C);
return QString(); return QString();
} }
#endif #endif
static QString QDesktopServicesDataLocation() { static QString QDesktopServicesDataLocation() {
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#if defined Q_WS_WINCE #if defined Q_WS_WINCE
if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE)) if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE))
@ -221,9 +221,9 @@ static QString QDesktopServicesDataLocation() {
return xdgDataHome; return xdgDataHome;
#endif #endif
#endif #endif
} }
static QString QDesktopServicesCacheLocation() { static QString QDesktopServicesCacheLocation() {
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
return QDesktopServicesDataLocation() + QLatin1String("\\cache"); return QDesktopServicesDataLocation() + QLatin1String("\\cache");
#else #else
@ -244,7 +244,7 @@ static QString QDesktopServicesCacheLocation() {
return xdgCacheHome; return xdgCacheHome;
#endif #endif
#endif #endif
} }
static QString searchEngineLocation() { static QString searchEngineLocation() {
QString location = QDir::cleanPath(QDesktopServicesDataLocation() QString location = QDir::cleanPath(QDesktopServicesDataLocation()