mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 21:38:51 +03:00
Keep on cleaning up
This commit is contained in:
parent
7d0581a7a5
commit
a9be841d2d
3 changed files with 135 additions and 133 deletions
|
@ -2020,7 +2020,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) {
|
||||
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->message().c_str())), "red");
|
||||
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(misc::toQString(p->message())), "red");
|
||||
//emit UPnPError(QString(p->msg().c_str()));
|
||||
}
|
||||
else if (portmap_alert* p = dynamic_cast<portmap_alert*>(a.get())) {
|
||||
|
@ -2112,15 +2112,15 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
if(appendLabelToSavePath) {
|
||||
qDebug("appendLabelToSavePath is true");
|
||||
QString label = TorrentTempData::getLabel(hash);
|
||||
const QString &label = TorrentTempData::getLabel(hash);
|
||||
if(!label.isEmpty()) {
|
||||
QDir save_dir(savePath);
|
||||
const QDir &save_dir(savePath);
|
||||
if(save_dir.dirName() != label) {
|
||||
savePath = save_dir.absoluteFilePath(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug("getSavePath, got save_path from temp data: %s", savePath.toLocal8Bit().data());
|
||||
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
|
||||
} else {
|
||||
savePath = TorrentPersistentData::getSavePath(hash);
|
||||
if(savePath.isEmpty()) {
|
||||
|
@ -2130,7 +2130,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
savePath = defaultSavePath;
|
||||
}
|
||||
if(!fromScanDir && appendLabelToSavePath) {
|
||||
QString label = TorrentPersistentData::getLabel(hash);
|
||||
const QString &label = TorrentPersistentData::getLabel(hash);
|
||||
if(!label.isEmpty()) {
|
||||
QDir save_dir(savePath);
|
||||
if(save_dir.dirName() != label) {
|
||||
|
@ -2138,7 +2138,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
}
|
||||
qDebug("getSavePath, got save_path from persistent data: %s", savePath.toLocal8Bit().data());
|
||||
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath));
|
||||
}
|
||||
// Clean path
|
||||
savePath = misc::expandPath(savePath);
|
||||
|
@ -2147,7 +2147,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QDir saveDir(savePath);
|
||||
if(!saveDir.exists()) {
|
||||
if(!saveDir.mkpath(saveDir.absolutePath())) {
|
||||
std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n";
|
||||
std::cerr << "Couldn't create the save directory: " << qPrintable(saveDir.path()) << "\n";
|
||||
// XXX: Do something else?
|
||||
}
|
||||
}
|
||||
|
@ -2180,7 +2180,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
|
||||
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
||||
//emit aboutToDownloadFromUrl(url);
|
||||
QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
const QUrl &qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
if(!save_path.isEmpty())
|
||||
savepath_fromurl[qurl] = save_path;
|
||||
url_skippingDlg << qurl;
|
||||
|
@ -2190,7 +2190,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
|
||||
// Add to Bittorrent session the downloaded torrent file
|
||||
void Bittorrent::processDownloadedFile(QString url, QString file_path) {
|
||||
int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
|
||||
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
|
||||
if(index < 0) {
|
||||
// Add file to torrent download list
|
||||
emit newDownloadedTorrent(file_path, url);
|
||||
|
@ -2204,7 +2204,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
float Bittorrent::getPayloadDownloadRate() const{
|
||||
session_status sessionStatus = s->status();
|
||||
const session_status &sessionStatus = s->status();
|
||||
return sessionStatus.payload_download_rate;
|
||||
}
|
||||
|
||||
|
@ -2212,7 +2212,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
float Bittorrent::getPayloadUploadRate() const{
|
||||
session_status sessionStatus = s->status();
|
||||
const session_status &sessionStatus = s->status();
|
||||
return sessionStatus.payload_upload_rate;
|
||||
}
|
||||
|
||||
|
@ -2222,7 +2222,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(DHTEnabled) {
|
||||
try{
|
||||
entry dht_state = s->dht_state();
|
||||
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary);
|
||||
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state")).toLocal8Bit().constData(), std::ios_base::binary);
|
||||
out.unsetf(std::ios_base::skipws);
|
||||
bencode(std::ostream_iterator<char>(out), dht_state);
|
||||
qDebug("DHT entry saved");
|
||||
|
@ -2242,8 +2242,8 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
void Bittorrent::startUpTorrents() {
|
||||
qDebug("Resuming unfinished torrents");
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
QDir torrentBackup(misc::BTBackupLocation());
|
||||
QStringList known_torrents = TorrentPersistentData::knownTorrents();
|
||||
const QDir &torrentBackup(misc::BTBackupLocation());
|
||||
const QStringList &known_torrents = TorrentPersistentData::knownTorrents();
|
||||
|
||||
if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) {
|
||||
qDebug("No known torrent, importing old torrents");
|
||||
|
@ -2255,11 +2255,11 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// we switch the v1.5 way of resuming torrents on startup
|
||||
QStringList filters;
|
||||
filters << "*.torrent";
|
||||
QStringList torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
const QStringList &torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
foreach(QString hash, torrents_on_hd) {
|
||||
hash.chop(8); // remove trailing .torrent
|
||||
if(!known_torrents.contains(hash)) {
|
||||
std::cerr << "ERROR Detected!!! Adding back torrent " << hash.toLocal8Bit().data() << " which got lost for some reason." << std::endl;
|
||||
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl;
|
||||
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
||||
}
|
||||
}
|
||||
|
@ -2275,14 +2275,14 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
} else {
|
||||
filePath = torrentBackup.path()+QDir::separator()+hash+".torrent";
|
||||
}
|
||||
int prio = TorrentPersistentData::getPriority(hash);
|
||||
const int prio = TorrentPersistentData::getPriority(hash);
|
||||
misc::insertSort2<QString>(hashes, qMakePair(prio, hash));
|
||||
}
|
||||
// Resume downloads
|
||||
QPair<int, QString> couple;
|
||||
foreach(couple, hashes) {
|
||||
QString hash = couple.second;
|
||||
qDebug("Starting up torrent %s", hash.toLocal8Bit().data());
|
||||
const QString &hash = couple.second;
|
||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||
if(TorrentPersistentData::isMagnet(hash)) {
|
||||
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
||||
} else {
|
||||
|
@ -2292,7 +2292,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
} else {
|
||||
// Resume downloads
|
||||
foreach(const QString &hash, known_torrents) {
|
||||
qDebug("Starting up torrent %s", hash.toLocal8Bit().data());
|
||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||
if(TorrentPersistentData::isMagnet(hash))
|
||||
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
||||
else
|
||||
|
@ -2306,10 +2306,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// TODO: Remove in qBittorrent v2.2.0
|
||||
void Bittorrent::importOldTempData(QString torrent_path) {
|
||||
// Create torrent hash
|
||||
boost::intrusive_ptr<torrent_info> t;
|
||||
try {
|
||||
t = new torrent_info(torrent_path.toLocal8Bit().data());
|
||||
QString hash = misc::toQString(t->info_hash());
|
||||
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_path.toLocal8Bit().data());
|
||||
const QString &hash = misc::toQString(t->info_hash());
|
||||
// Load save path
|
||||
QFile savepath_file(misc::BTBackupLocation()+QDir::separator()+hash+".savepath");
|
||||
QByteArray line;
|
||||
|
@ -2317,9 +2316,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
line = savepath_file.readAll();
|
||||
savepath_file.close();
|
||||
qDebug(" -> Save path: %s", line.data());
|
||||
qDebug(" -> Save path: %s", line.constData());
|
||||
savePath = QString::fromUtf8(line.data());
|
||||
qDebug("Imported the following save path: %s", savePath.toLocal8Bit().data());
|
||||
qDebug("Imported the following save path: %s", qPrintable(savePath));
|
||||
TorrentTempData::setSavePath(hash, savePath);
|
||||
}
|
||||
// Load pieces priority
|
||||
|
@ -2327,9 +2326,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(pieces_file.exists()){
|
||||
// Read saved file
|
||||
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QByteArray pieces_priorities = pieces_file.readAll();
|
||||
const QByteArray &pieces_priorities = pieces_file.readAll();
|
||||
pieces_file.close();
|
||||
QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
|
||||
const QList<QByteArray> &pieces_priorities_list = pieces_priorities.split('\n');
|
||||
std::vector<int> pp;
|
||||
for(int i=0; i<t->num_files(); ++i) {
|
||||
int priority = pieces_priorities_list.at(i).toInt();
|
||||
|
@ -2356,14 +2355,14 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// TODO: Remove in qBittorrent v2.2.0
|
||||
void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
|
||||
// Load trackers
|
||||
QDir torrentBackup(misc::BTBackupLocation());
|
||||
const QDir &torrentBackup(misc::BTBackupLocation());
|
||||
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers");
|
||||
if(tracker_file.exists()) {
|
||||
if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QStringList lines = QString::fromUtf8(tracker_file.readAll().data()).split("\n");
|
||||
const QStringList &lines = QString::fromUtf8(tracker_file.readAll().data()).split("\n");
|
||||
std::vector<announce_entry> trackers;
|
||||
foreach(const QString &line, lines) {
|
||||
QStringList parts = line.split("|");
|
||||
const QStringList &parts = line.split("|");
|
||||
if(parts.size() != 2) continue;
|
||||
announce_entry t(parts[0].toStdString());
|
||||
t.tier = parts[1].toInt();
|
||||
|
@ -2379,13 +2378,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QFile urlseeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".urlseeds");
|
||||
if(urlseeds_file.exists()) {
|
||||
if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QByteArray urlseeds_lines = urlseeds_file.readAll();
|
||||
const QByteArray &urlseeds_lines = urlseeds_file.readAll();
|
||||
urlseeds_file.close();
|
||||
QList<QByteArray> url_seeds = urlseeds_lines.split('\n');
|
||||
const QList<QByteArray> &url_seeds = urlseeds_lines.split('\n');
|
||||
// First remove from the torrent the url seeds that were deleted
|
||||
// in a previous session
|
||||
QStringList seeds_to_delete;
|
||||
QStringList existing_seeds = h.url_seeds();
|
||||
const QStringList &existing_seeds = h.url_seeds();
|
||||
foreach(const QString &existing_seed, existing_seeds) {
|
||||
if(!url_seeds.contains(existing_seed.toLocal8Bit())) {
|
||||
seeds_to_delete << existing_seed;
|
||||
|
@ -2408,11 +2407,11 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QFile speeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".speedLimits");
|
||||
if(speeds_file.exists()) {
|
||||
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QByteArray speed_limits = speeds_file.readAll();
|
||||
const QByteArray &speed_limits = speeds_file.readAll();
|
||||
speeds_file.close();
|
||||
QList<QByteArray> speeds = speed_limits.split(' ');
|
||||
const QList<QByteArray> &speeds = speed_limits.split(' ');
|
||||
if(speeds.size() != 2) {
|
||||
std::cerr << "Invalid .speedLimits file for " << h.hash().toStdString() << '\n';
|
||||
std::cerr << "Invalid .speedLimits file for " << qPrintable(h.hash()) << '\n';
|
||||
return;
|
||||
}
|
||||
h.set_download_limit(speeds.at(0).toInt());
|
||||
|
@ -2427,19 +2426,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool());
|
||||
// Import old torrent
|
||||
QDir torrentBackup(misc::BTBackupLocation());
|
||||
QStringList fileNames;
|
||||
const QDir &torrentBackup(misc::BTBackupLocation());
|
||||
QStringList filters;
|
||||
filters << "*.torrent";
|
||||
fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
const QStringList &fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
if(isQueueingEnabled()) {
|
||||
QList<QPair<int, QString> > filePaths;
|
||||
foreach(const QString &fileName, fileNames) {
|
||||
QString filePath = torrentBackup.path()+QDir::separator()+fileName;
|
||||
int prio = 99999;
|
||||
// Get priority
|
||||
QString prioPath = filePath;
|
||||
prioPath.replace(".torrent", ".prio");
|
||||
const QString &prioPath = filePath.replace(".torrent", ".prio");
|
||||
if(QFile::exists(prioPath)) {
|
||||
QFile prio_file(prioPath);
|
||||
if(prio_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
|
@ -2463,12 +2460,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
h.set_sequential_download(TorrentTempData::isSequential(h.hash()));
|
||||
}
|
||||
applyFormerAttributeFiles(h);
|
||||
QString savePath = TorrentTempData::getSavePath(h.hash());
|
||||
const QString &savePath = TorrentTempData::getSavePath(h.hash());
|
||||
// Save persistent data for new torrent
|
||||
TorrentPersistentData::saveTorrentPersistentData(h);
|
||||
// Save save_path
|
||||
if(!defaultTempPath.isEmpty() && !savePath.isNull()) {
|
||||
qDebug("addTorrent: Saving save_path in persistent data: %s", savePath.toLocal8Bit().data());
|
||||
qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath));
|
||||
TorrentPersistentData::saveSavePath(h.hash(), savePath);
|
||||
}
|
||||
}
|
||||
|
@ -2487,12 +2484,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
h.set_sequential_download(TorrentTempData::isSequential(h.hash()));
|
||||
}
|
||||
applyFormerAttributeFiles(h);
|
||||
QString savePath = TorrentTempData::getSavePath(h.hash());
|
||||
const QString &savePath = TorrentTempData::getSavePath(h.hash());
|
||||
// Save persistent data for new torrent
|
||||
TorrentPersistentData::saveTorrentPersistentData(h);
|
||||
// Save save_path
|
||||
if(!defaultTempPath.isEmpty() && !savePath.isNull()) {
|
||||
qDebug("addTorrent: Saving save_path in persistent data: %s", savePath.toLocal8Bit().data());
|
||||
qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath));
|
||||
TorrentPersistentData::saveSavePath(h.hash(), savePath);
|
||||
}
|
||||
}
|
||||
|
|
113
src/bittorrent.h
113
src/bittorrent.h
|
@ -89,62 +89,6 @@ public:
|
|||
class Bittorrent : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
// Bittorrent
|
||||
session *s;
|
||||
QPointer<QTimer> timerAlerts;
|
||||
QPointer<BandwidthScheduler> bd_scheduler;
|
||||
QMap<QUrl, QString> savepath_fromurl;
|
||||
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
|
||||
QStringList torrentsToPausedAfterChecking;
|
||||
// Ratio
|
||||
QPointer<QTimer> BigRatioTimer;
|
||||
// HTTP
|
||||
QPointer<downloadThread> downloader;
|
||||
// File System
|
||||
ScanFoldersModel *m_scanFolders;
|
||||
// Console / Log
|
||||
QStringList consoleMessages;
|
||||
QStringList peerBanMessages;
|
||||
// Settings
|
||||
bool preAllocateAll;
|
||||
bool addInPause;
|
||||
float ratio_limit;
|
||||
bool UPnPEnabled;
|
||||
bool NATPMPEnabled;
|
||||
bool LSDEnabled;
|
||||
bool DHTEnabled;
|
||||
int current_dht_port;
|
||||
bool PeXEnabled;
|
||||
bool queueingEnabled;
|
||||
bool appendLabelToSavePath;
|
||||
bool torrentExport;
|
||||
#ifdef LIBTORRENT_0_15
|
||||
bool appendqBExtension;
|
||||
#endif
|
||||
QString defaultSavePath;
|
||||
QString defaultTempPath;
|
||||
// ETA Computation
|
||||
QPointer<QTimer> timerETA;
|
||||
QHash<QString, QList<int> > ETA_samples;
|
||||
// IP filtering
|
||||
QPointer<FilterParserThread> filterParser;
|
||||
QString filterPath;
|
||||
// Web UI
|
||||
QPointer<HttpServer> httpServer;
|
||||
QList<QUrl> url_skippingDlg;
|
||||
// Fast exit (async)
|
||||
bool exiting;
|
||||
// GeoIP
|
||||
#ifndef DISABLE_GUI
|
||||
bool geoipDBLoaded;
|
||||
bool resolve_countries;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
QString getSavePath(QString hash, bool fromScanDir = false, QString filePath = QString());
|
||||
bool initWebUi(QString username, QString password, int port);
|
||||
|
||||
public:
|
||||
// Constructor / Destructor
|
||||
Bittorrent();
|
||||
|
@ -241,6 +185,10 @@ public slots:
|
|||
void configureSession();
|
||||
void banIP(QString ip);
|
||||
|
||||
protected:
|
||||
QString getSavePath(QString hash, bool fromScanDir = false, QString filePath = QString());
|
||||
bool initWebUi(QString username, QString password, int port);
|
||||
|
||||
protected slots:
|
||||
void addTorrentsFromScanFolder(QStringList&);
|
||||
void readAlerts();
|
||||
|
@ -265,6 +213,59 @@ signals:
|
|||
void savePathChanged(QTorrentHandle &h);
|
||||
void newConsoleMessage(QString msg);
|
||||
void alternativeSpeedsModeChanged(bool alternative);
|
||||
|
||||
private:
|
||||
// Bittorrent
|
||||
session *s;
|
||||
QPointer<QTimer> timerAlerts;
|
||||
QPointer<BandwidthScheduler> bd_scheduler;
|
||||
QMap<QUrl, QString> savepath_fromurl;
|
||||
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
|
||||
QStringList torrentsToPausedAfterChecking;
|
||||
// Ratio
|
||||
QPointer<QTimer> BigRatioTimer;
|
||||
// HTTP
|
||||
QPointer<downloadThread> downloader;
|
||||
// File System
|
||||
ScanFoldersModel *m_scanFolders;
|
||||
// Console / Log
|
||||
QStringList consoleMessages;
|
||||
QStringList peerBanMessages;
|
||||
// Settings
|
||||
bool preAllocateAll;
|
||||
bool addInPause;
|
||||
float ratio_limit;
|
||||
bool UPnPEnabled;
|
||||
bool NATPMPEnabled;
|
||||
bool LSDEnabled;
|
||||
bool DHTEnabled;
|
||||
int current_dht_port;
|
||||
bool PeXEnabled;
|
||||
bool queueingEnabled;
|
||||
bool appendLabelToSavePath;
|
||||
bool torrentExport;
|
||||
#ifdef LIBTORRENT_0_15
|
||||
bool appendqBExtension;
|
||||
#endif
|
||||
QString defaultSavePath;
|
||||
QString defaultTempPath;
|
||||
// ETA Computation
|
||||
QPointer<QTimer> timerETA;
|
||||
QHash<QString, QList<int> > ETA_samples;
|
||||
// IP filtering
|
||||
QPointer<FilterParserThread> filterParser;
|
||||
QString filterPath;
|
||||
// Web UI
|
||||
QPointer<HttpServer> httpServer;
|
||||
QList<QUrl> url_skippingDlg;
|
||||
// Fast exit (async)
|
||||
bool exiting;
|
||||
// GeoIP
|
||||
#ifndef DISABLE_GUI
|
||||
bool geoipDBLoaded;
|
||||
bool resolve_countries;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
68
src/misc.h
68
src/misc.h
|
@ -138,22 +138,22 @@ public:
|
|||
if(!destDir.mkpath(destDir.absolutePath())) return;
|
||||
}
|
||||
// List source directory
|
||||
QFileInfoList content = sourceDir.entryInfoList();
|
||||
const QFileInfoList &content = sourceDir.entryInfoList();
|
||||
foreach(const QFileInfo& child, content) {
|
||||
if(child.fileName()[0] == '.') continue;
|
||||
if(child.isDir()) {
|
||||
copyDir(child.absoluteFilePath(), dst_path+QDir::separator()+QDir(child.absoluteFilePath()).dirName());
|
||||
continue;
|
||||
}
|
||||
QString src_child_path = child.absoluteFilePath();
|
||||
QString dest_child_path = destDir.absoluteFilePath(child.fileName());
|
||||
const QString &src_child_path = child.absoluteFilePath();
|
||||
const QString &dest_child_path = destDir.absoluteFilePath(child.fileName());
|
||||
// Copy the file from src to dest
|
||||
QFile::copy(src_child_path, dest_child_path);
|
||||
// Remove source file
|
||||
QFile::remove(src_child_path);
|
||||
}
|
||||
// Remove source folder
|
||||
QString dir_name = sourceDir.dirName();
|
||||
const QString &dir_name = sourceDir.dirName();
|
||||
if(sourceDir.cdUp()) {
|
||||
sourceDir.rmdir(dir_name);
|
||||
}
|
||||
|
@ -163,15 +163,15 @@ public:
|
|||
// For backward compatibility
|
||||
// Remove after some releases
|
||||
static void moveToXDGFolders() {
|
||||
QString old_qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
|
||||
const QString &old_qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
|
||||
if(QDir(old_qBtPath).exists()) {
|
||||
// Copy BT_backup folder
|
||||
QString old_BTBackupPath = old_qBtPath + "BT_backup";
|
||||
const QString &old_BTBackupPath = old_qBtPath + "BT_backup";
|
||||
if(QDir(old_BTBackupPath).exists()) {
|
||||
copyDir(old_BTBackupPath, BTBackupLocation());
|
||||
}
|
||||
// Copy search engine folder
|
||||
QString old_searchPath = old_qBtPath + "search_engine";
|
||||
const QString &old_searchPath = old_qBtPath + "search_engine";
|
||||
if(QDir(old_searchPath).exists()) {
|
||||
copyDir(old_searchPath, searchEngineLocation());
|
||||
}
|
||||
|
@ -190,23 +190,25 @@ public:
|
|||
}
|
||||
|
||||
static QString toValidFileSystemName(QString filename) {
|
||||
qDebug("toValidFSName: %s", filename.toLocal8Bit().data());
|
||||
qDebug("toValidFSName: %s", qPrintable(filename));
|
||||
filename = filename.replace("\\", "/").trimmed();
|
||||
QRegExp regex("[/:?\"*<>|]");
|
||||
const QRegExp regex("[/:?\"*<>|]");
|
||||
filename = filename.replace(regex, " ").trimmed();
|
||||
qDebug("toValidFSName, result: %s", filename.toLocal8Bit().data());
|
||||
qDebug("toValidFSName, result: %s", qPrintable(filename));
|
||||
return filename;
|
||||
}
|
||||
|
||||
static bool isValidFileSystemName(QString filename) {
|
||||
filename = filename.replace("\\", "/").trimmed();
|
||||
if(filename.isEmpty()) return false;
|
||||
QRegExp regex("[/:?\"*<>|]");
|
||||
const QRegExp regex("[/:?\"*<>|]");
|
||||
if(filename.contains(regex))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Ported from Qt4 to drop dependency on QtGui */
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
static QString getFullPath(const FSRef &ref)
|
||||
{
|
||||
|
@ -271,11 +273,13 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
/* End of Qt4 code */
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
// Get screen center
|
||||
static QPoint screenCenter(QWidget *win) {
|
||||
int scrn = 0;
|
||||
QWidget *w = win->window();
|
||||
const QWidget *w = win->window();
|
||||
|
||||
if(w)
|
||||
scrn = QApplication::desktop()->screenNumber(w);
|
||||
|
@ -290,7 +294,7 @@ public:
|
|||
#endif
|
||||
|
||||
static QString searchEngineLocation() {
|
||||
QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
const QString &location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
+ QDir::separator() + "search_engine");
|
||||
QDir locationDir(location);
|
||||
if(!locationDir.exists())
|
||||
|
@ -299,7 +303,7 @@ public:
|
|||
}
|
||||
|
||||
static QString BTBackupLocation() {
|
||||
QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
const QString &location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
+ QDir::separator() + "BT_backup");
|
||||
QDir locationDir(location);
|
||||
if(!locationDir.exists())
|
||||
|
@ -308,7 +312,7 @@ public:
|
|||
}
|
||||
|
||||
static QString cacheLocation() {
|
||||
QString location = QDir::cleanPath(QDesktopServicesCacheLocation());
|
||||
const QString &location = QDir::cleanPath(QDesktopServicesCacheLocation());
|
||||
QDir locationDir(location);
|
||||
if(!locationDir.exists())
|
||||
locationDir.mkpath(locationDir.absolutePath());
|
||||
|
@ -325,7 +329,7 @@ public:
|
|||
#ifndef Q_WS_WIN
|
||||
unsigned long long available;
|
||||
struct statfs stats;
|
||||
int ret = statfs ((dir_path.path()+"/.").toLocal8Bit().data(), &stats) ;
|
||||
const int ret = statfs ((dir_path.path()+"/.").toLocal8Bit().data(), &stats) ;
|
||||
if(ret == 0) {
|
||||
available = ((unsigned long long)stats.f_bavail) *
|
||||
((unsigned long long)stats.f_bsize) ;
|
||||
|
@ -371,7 +375,7 @@ public:
|
|||
char i = 0;
|
||||
while(val >= 1024. && i++<6)
|
||||
val /= 1024.;
|
||||
return QString(QByteArray::number(val, 'f', 1)) + " " + units[(int)i];
|
||||
return QString::number(val, 'f', 1) + " " + units[(int)i];
|
||||
}
|
||||
|
||||
static bool isPreviewable(QString extension){
|
||||
|
@ -451,7 +455,7 @@ public:
|
|||
|
||||
// Can't use template class for QString because >,< use unicode code for sorting
|
||||
// which is not what a human would expect when sorting strings.
|
||||
static void insertSortString(QList<QPair<int, QString> > &list, QPair<int, QString> value, Qt::SortOrder sortOrder) {
|
||||
static void insertSortString(QList<QPair<int, QString> > &list, const QPair<int, QString> &value, Qt::SortOrder sortOrder) {
|
||||
int i = 0;
|
||||
if(sortOrder == Qt::AscendingOrder) {
|
||||
while(i < list.size() and QString::localeAwareCompare(value.second, list.at(i).second) > 0) {
|
||||
|
@ -467,11 +471,11 @@ public:
|
|||
|
||||
static bool removeEmptyTree(QString path) {
|
||||
QDir dir(path);
|
||||
foreach(QString child, dir.entryList(QDir::AllDirs)) {
|
||||
foreach(const QString &child, dir.entryList(QDir::AllDirs)) {
|
||||
if(child == "." || child == "..") continue;
|
||||
return removeEmptyTree(dir.absoluteFilePath(child));
|
||||
}
|
||||
QString dir_name = dir.dirName();
|
||||
const QString &dir_name = dir.dirName();
|
||||
if(dir.cdUp()) {
|
||||
return dir.rmdir(dir_name);
|
||||
}
|
||||
|
@ -480,10 +484,10 @@ public:
|
|||
|
||||
static QString magnetUriToName(QString magnet_uri) {
|
||||
QString name = "";
|
||||
QRegExp regHex("dn=([^&]+)");
|
||||
int pos = regHex.indexIn(magnet_uri);
|
||||
const QRegExp regHex("dn=([^&]+)");
|
||||
const int pos = regHex.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
QString found = regHex.cap(1);
|
||||
const QString &found = regHex.cap(1);
|
||||
// URL decode
|
||||
name = QUrl::fromPercentEncoding(found.toLocal8Bit()).replace("+", " ");
|
||||
}
|
||||
|
@ -492,32 +496,32 @@ public:
|
|||
|
||||
static QString magnetUriToHash(QString magnet_uri) {
|
||||
QString hash = "";
|
||||
QRegExp regHex("urn:btih:([0-9A-Za-z]+)");
|
||||
const QRegExp regHex("urn:btih:([0-9A-Za-z]+)");
|
||||
// Hex
|
||||
int pos = regHex.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
QString found = regHex.cap(1);
|
||||
const QString &found = regHex.cap(1);
|
||||
if(found.length() == 40) {
|
||||
sha1_hash sha1(QString(QByteArray::fromHex(regHex.cap(1).toLocal8Bit())).toStdString());
|
||||
qDebug("magnetUriToHash (Hex): hash: %s", sha1.to_string().c_str());
|
||||
const sha1_hash sha1(QString(QByteArray::fromHex(regHex.cap(1).toLocal8Bit())).toStdString());
|
||||
qDebug("magnetUriToHash (Hex): hash: %s", qPrintable(misc::toQString(sha1)));
|
||||
return misc::toQString(sha1);
|
||||
}
|
||||
}
|
||||
// Base 32
|
||||
QRegExp regBase32("urn:btih:([A-Za-z2-7=]+)");
|
||||
const QRegExp regBase32("urn:btih:([A-Za-z2-7=]+)");
|
||||
pos = regBase32.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
QString found = regBase32.cap(1);
|
||||
const QString &found = regBase32.cap(1);
|
||||
if(found.length() > 20 && (found.length()*5)%40 == 0) {
|
||||
sha1_hash sha1(base32decode(regBase32.cap(1).toStdString()));
|
||||
const sha1_hash sha1(base32decode(regBase32.cap(1).toStdString()));
|
||||
hash = misc::toQString(sha1);
|
||||
}
|
||||
}
|
||||
qDebug("magnetUriToHash (base32): hash: %s", hash.toLocal8Bit().data());
|
||||
qDebug("magnetUriToHash (base32): hash: %s", qPrintable(hash));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static QString boostTimeToQString(boost::optional<boost::posix_time::ptime> boostDate) {
|
||||
static QString boostTimeToQString(const boost::optional<boost::posix_time::ptime> boostDate) {
|
||||
if(!boostDate) return tr("Unknown");
|
||||
struct std::tm tm = boost::posix_time::to_tm(*boostDate);
|
||||
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
|
||||
|
|
Loading…
Reference in a new issue