Use XDG folders (.cache, .local) instead of .qbittorrent

old .qbittorrent is imported and moved to XDG folder by qBittorrent so that the user does not loose anything
This commit is contained in:
Christophe Dumez 2010-01-02 11:22:44 +00:00
parent 55d8e3d76b
commit a5d8766a9e
7 changed files with 136 additions and 66 deletions

View file

@ -9,6 +9,7 @@
- FEATURE: Better proxy support and preferences remodeling - FEATURE: Better proxy support and preferences remodeling
- FEATURE: qBittorrent can identify itself as uTorrent, Vuze or KTorrent (Any stable version) - FEATURE: qBittorrent can identify itself as uTorrent, Vuze or KTorrent (Any stable version)
- FEATURE: Torrents can be renamed in transfer list - FEATURE: Torrents can be renamed in transfer list
- BUGFIX: Use XDG folders (.cache, .local) instead of .qbittorrent
- COSMETIC: Use checkboxes to filter torrent content instead of comboboxes - COSMETIC: Use checkboxes to filter torrent content instead of comboboxes
- COSMETIC: Use alternating row colors in transfer list (set in program preferences) - COSMETIC: Use alternating row colors in transfer list (set in program preferences)
- COSMETIC: Added a spin box to speed limiting dialog for manual input - COSMETIC: Added a spin box to speed limiting dialog for manual input

View file

@ -78,6 +78,8 @@ using namespace libtorrent;
// Constructor // Constructor
GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), displaySpeedInTitle(false), force_exit(false) { GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), displaySpeedInTitle(false), force_exit(false) {
setupUi(this); setupUi(this);
qDebug("Data Location: %s", QDesktopServices::storageLocation(QDesktopServices::CacheLocation).toLocal8Bit().data());
qDebug("Data Location: %s", QDesktopServices::storageLocation(QDesktopServices::DataLocation).toLocal8Bit().data());
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
// Setting icons // Setting icons
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png"))); this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));

View file

@ -69,6 +69,10 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit
resolve_countries = false; resolve_countries = false;
// To avoid some exceptions // To avoid some exceptions
fs::path::default_name_check(fs::no_check); fs::path::default_name_check(fs::no_check);
// For backward compatibility
// Move .qBittorrent content to XDG folder
// TODO: Remove after some releases (introduced in v2.1.0)
misc::moveToXDGFolders();
// Creating Bittorrent session // Creating Bittorrent session
// Check if we should spoof utorrent // Check if we should spoof utorrent
QList<int> version; QList<int> version;
@ -656,7 +660,7 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) {
else else
s->remove_torrent(h.get_torrent_handle()); s->remove_torrent(h.get_torrent_handle());
// Remove it from torrent backup directory // Remove it from torrent backup directory
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QStringList filters; QStringList filters;
filters << hash+".*"; filters << hash+".*";
QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
@ -730,15 +734,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
bool fastResume=false; bool fastResume=false;
Q_ASSERT(magnet_uri.startsWith("magnet:")); Q_ASSERT(magnet_uri.startsWith("magnet:"));
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
// Checking if BT_backup Dir exists
// create it if it is not
if(! torrentBackup.exists()) {
if(! torrentBackup.mkpath(torrentBackup.path())) {
std::cerr << "Couldn't create the directory: '" << torrentBackup.path().toLocal8Bit().data() << "'\n";
exit(1);
}
}
// Check if torrent is already in download list // Check if torrent is already in download list
if(s->find_torrent(sha1_hash(hash.toLocal8Bit().data())).is_valid()) { if(s->find_torrent(sha1_hash(hash.toLocal8Bit().data())).is_valid()) {
@ -829,8 +825,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) { QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) {
QTorrentHandle h; QTorrentHandle h;
bool fastResume=false; bool fastResume=false;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QString file, dest_file, hash; QString file, hash;
boost::intrusive_ptr<torrent_info> t; boost::intrusive_ptr<torrent_info> t;
// Checking if BT_backup Dir exists // Checking if BT_backup Dir exists
@ -926,9 +922,9 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
} }
#endif #endif
// TODO: Remove in v1.6.0: For backward compatibility only // TODO: Remove in v1.6.0: For backward compatibility only
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) { if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".finished")) {
p.save_path = savePath.toLocal8Bit().data(); p.save_path = savePath.toLocal8Bit().data();
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished"); QFile::remove(misc::BTBackupLocation()+QDir::separator()+hash+".finished");
} }
p.ti = t; p.ti = t;
// Preallocate all? // Preallocate all?
@ -1120,7 +1116,7 @@ void Bittorrent::enableLSD(bool b) {
} }
void Bittorrent::loadSessionState() { void Bittorrent::loadSessionState() {
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data() boost::filesystem::ifstream ses_state_file((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary); , std::ios_base::binary);
ses_state_file.unsetf(std::ios_base::skipws); ses_state_file.unsetf(std::ios_base::skipws);
s->load_state(bdecode( s->load_state(bdecode(
@ -1131,7 +1127,7 @@ void Bittorrent::loadSessionState() {
void Bittorrent::saveSessionState() { void Bittorrent::saveSessionState() {
qDebug("Saving session state to disk..."); qDebug("Saving session state to disk...");
entry session_state = s->state(); entry session_state = s->state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data() boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary); , std::ios_base::binary);
out.unsetf(std::ios_base::skipws); out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), session_state); bencode(std::ostream_iterator<char>(out), session_state);
@ -1142,7 +1138,7 @@ bool Bittorrent::enableDHT(bool b) {
if(b) { if(b) {
if(!DHTEnabled) { if(!DHTEnabled) {
entry dht_state; entry dht_state;
QString dht_state_path = misc::qBittorrentPath()+QString::fromUtf8("dht_state"); QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
if(QFile::exists(dht_state_path)) { if(QFile::exists(dht_state_path)) {
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary); boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary);
dht_state_file.unsetf(std::ios_base::skipws); dht_state_file.unsetf(std::ios_base::skipws);
@ -1235,7 +1231,7 @@ void Bittorrent::saveFastResumeData() {
// Saving fast resume data was successful // Saving fast resume data was successful
--num_resume_data; --num_resume_data;
if (!rd->resume_data) continue; if (!rd->resume_data) continue;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QTorrentHandle h(rd->handle); QTorrentHandle h(rd->handle);
if(!h.is_valid()) continue; if(!h.is_valid()) continue;
// Remove old fastresume file if it exists // Remove old fastresume file if it exists
@ -1664,7 +1660,7 @@ void Bittorrent::readAlerts() {
} }
} }
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) { else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) {
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if(h.is_valid()) { if(h.is_valid()) {
QString file = h.hash()+".fastresume"; QString file = h.hash()+".fastresume";
@ -1959,7 +1955,7 @@ void Bittorrent::saveDHTEntry() {
if(DHTEnabled) { if(DHTEnabled) {
try{ try{
entry dht_state = s->dht_state(); entry dht_state = s->dht_state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary); boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws); out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), dht_state); bencode(std::ostream_iterator<char>(out), dht_state);
qDebug("DHT entry saved"); qDebug("DHT entry saved");
@ -1979,8 +1975,7 @@ void Bittorrent::applyEncryptionSettings(pe_settings se) {
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::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QStringList fileNames;
QStringList known_torrents = TorrentPersistentData::knownTorrents(); QStringList known_torrents = TorrentPersistentData::knownTorrents();
if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) { if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) {
@ -2041,7 +2036,7 @@ void Bittorrent::startUpTorrents() {
} }
// 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 v1.6.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;
@ -2049,7 +2044,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
t = new torrent_info(torrent_path.toLocal8Bit().data()); t = new torrent_info(torrent_path.toLocal8Bit().data());
QString hash = misc::toQString(t->info_hash()); QString hash = misc::toQString(t->info_hash());
// Load save path // Load save path
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath"); QFile savepath_file(misc::BTBackupLocation()+QDir::separator()+hash+".savepath");
QByteArray line; QByteArray line;
QString savePath; QString savePath;
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) { if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2061,7 +2056,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
TorrentTempData::setSavePath(hash, savePath); TorrentTempData::setSavePath(hash, savePath);
} }
// Load pieces priority // Load pieces priority
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities"); QFile pieces_file(misc::BTBackupLocation()+QDir::separator()+hash+".priorities");
if(pieces_file.exists()){ if(pieces_file.exists()){
// Read saved file // Read saved file
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) { if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2082,7 +2077,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
} }
} }
// Load sequential // Load sequential
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) { if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".incremental")) {
qDebug("Imported torrent was sequential"); qDebug("Imported torrent was sequential");
TorrentTempData::setSequential(hash, true); TorrentTempData::setSequential(hash, true);
} }
@ -2091,10 +2086,10 @@ void Bittorrent::importOldTempData(QString torrent_path) {
} }
// Trackers, web seeds, speed limits // Trackers, web seeds, speed limits
// TODO: Remove in qBittorrent v1.6.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::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers"); QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers");
if(tracker_file.exists()) { if(tracker_file.exists()) {
if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) { if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2114,7 +2109,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
} }
} }
// Load Web seeds // Load Web seeds
QFile urlseeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".urlseeds"); QFile urlseeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".urlseeds");
if(urlseeds_file.exists()) { if(urlseeds_file.exists()) {
if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QByteArray urlseeds_lines = urlseeds_file.readAll(); QByteArray urlseeds_lines = urlseeds_file.readAll();
@ -2143,7 +2138,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
} }
} }
// Load speed limits // Load speed limits
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".speedLimits"); QFile speeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".speedLimits");
if(speeds_file.exists()) { if(speeds_file.exists()) {
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QByteArray speed_limits = speeds_file.readAll(); QByteArray speed_limits = speeds_file.readAll();
@ -2160,12 +2155,12 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
} }
// Import torrents from v1.4.0 or earlier // Import torrents from v1.4.0 or earlier
// TODO: Remove in qBittorrent v1.6.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
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::BTBackupLocation());
QStringList fileNames; QStringList fileNames;
QStringList filters; QStringList filters;
filters << "*.torrent"; filters << "*.torrent";

View file

@ -170,7 +170,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
}else { }else {
// Proceed with uninstall // Proceed with uninstall
// remove it from hard drive // remove it from hard drive
QDir enginesFolder(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"); QDir enginesFolder(misc::searchEngineLocation()+QDir::separator()+"engines");
QStringList filters; QStringList filters;
filters << id+".*"; filters << id+".*";
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted); QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
@ -245,7 +245,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id){
} }
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, float new_version) const { bool engineSelectDlg::isUpdateNeeded(QString plugin_name, float new_version) const {
float old_version = SearchEngine::getPluginVersion(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"); float old_version = SearchEngine::getPluginVersion(misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py");
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version); qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version);
return (new_version > old_version); return (new_version > old_version);
} }
@ -260,7 +260,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
return; return;
} }
// Process with install // Process with install
QString dest_path = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"; QString dest_path = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py";
bool update = false; bool update = false;
if(QFile::exists(dest_path)) { if(QFile::exists(dest_path)) {
// Backup in case install fails // Backup in case install fails
@ -324,12 +324,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
} }
// Handle icon // Handle icon
QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png"; QString iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png";
if(QFile::exists(iconPath)) { if(QFile::exists(iconPath)) {
// Good, we already have the icon // Good, we already have the icon
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else { } else {
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico"; iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico";
if(QFile::exists(iconPath)) { // ICO support if(QFile::exists(iconPath)) { // ICO support
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else { } else {
@ -427,9 +427,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
QFile icon(filePath); QFile icon(filePath);
icon.open(QIODevice::ReadOnly); icon.open(QIODevice::ReadOnly);
if(ICOHandler::canRead(&icon)) if(ICOHandler::canRead(&icon))
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".ico"; iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".ico";
else else
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".png"; iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".png";
QFile::copy(filePath, iconPath); QFile::copy(filePath, iconPath);
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} }

View file

@ -43,6 +43,7 @@
#include <QThread> #include <QThread>
#include <ctime> #include <ctime>
#include <QDateTime> #include <QDateTime>
#include <QDesktopServices>
#include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/conversion.hpp> #include <boost/date_time/posix_time/conversion.hpp>
@ -107,6 +108,91 @@ public:
return x; return x;
} }
static void copyDir(QString src_path, QString dst_path) {
QDir sourceDir(src_path);
if(!sourceDir.exists()) return;
// Create destination directory
QDir destDir(dst_path);
if(!destDir.exists()) {
if(!destDir.mkpath(destDir.absolutePath())) return;
}
// List source directory
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());
// 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();
if(sourceDir.cdUp()) {
sourceDir.rmdir(dir_name);
}
}
// Introduced in v2.1.0
// For backward compatibility
// Remove after some releases
static void moveToXDGFolders() {
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";
if(QDir(old_BTBackupPath).exists()) {
copyDir(old_BTBackupPath, BTBackupLocation());
}
// Copy search engine folder
QString old_searchPath = old_qBtPath + "search_engine";
if(QDir(old_searchPath).exists()) {
copyDir(old_searchPath, searchEngineLocation());
}
// Copy *_state files
if(QFile::exists(old_qBtPath+"dht_state")) {
QFile::copy(old_qBtPath+"dht_state", cacheLocation()+QDir::separator()+"dht_state");
QFile::remove(old_qBtPath+"dht_state");
}
if(QFile::exists(old_qBtPath+"ses_state")) {
QFile::copy(old_qBtPath+"ses_state", cacheLocation()+QDir::separator()+"ses_state");
QFile::remove(old_qBtPath+"ses_state");
}
// Remove .qbittorrent folder if empty
QDir::home().rmdir(".qbittorrent");
}
}
static QString searchEngineLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
+ QDir::separator() + "search_engine");
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static QString BTBackupLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
+ QDir::separator() + "BT_backup");
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static QString cacheLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static long long freeDiskSpaceOnPath(QString path) { static long long freeDiskSpaceOnPath(QString path) {
if(path.isEmpty()) return -1; if(path.isEmpty()) return -1;
@ -212,17 +298,6 @@ public:
return false; return false;
} }
// return qBittorrent config path
static QString qBittorrentPath() {
QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
// Create dir if it does not exist
if(!QFile::exists(qBtPath)){
QDir dir(qBtPath);
dir.mkpath(qBtPath);
}
return qBtPath;
}
// Insertion sort, used instead of bubble sort because it is // Insertion sort, used instead of bubble sort because it is
// approx. 5 times faster. // approx. 5 times faster.
template <class T> static void insertSort(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder) { template <class T> static void insertSort(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder) {

View file

@ -240,7 +240,7 @@ void SearchEngine::on_search_button_clicked(){
QStringList params; QStringList params;
QStringList engineNames; QStringList engineNames;
search_stopped = false; search_stopped = false;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py"; params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
params << supported_engines->enginesEnabled().join(","); params << supported_engines->enginesEnabled().join(",");
qDebug("Search with category: %s", selectedCategory().toLocal8Bit().data()); qDebug("Search with category: %s", selectedCategory().toLocal8Bit().data());
params << selectedCategory(); params << selectedCategory();
@ -305,7 +305,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) {
connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus))); connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus)));
downloaders << downloadProcess; downloaders << downloadProcess;
QStringList params; QStringList params;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py"; params << misc::searchEngineLocation()+QDir::separator()+"nova2dl.py";
params << engine_url; params << engine_url;
params << torrent_url; params << torrent_url;
// Launch search // Launch search
@ -358,10 +358,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
void SearchEngine::updateNova() { void SearchEngine::updateNova() {
qDebug("Updating nova"); qDebug("Updating nova");
// create search_engine directory if necessary // create search_engine directory if necessary
QDir search_dir(misc::qBittorrentPath()+"search_engine"); QDir search_dir(misc::searchEngineLocation());
if(!search_dir.exists()){
search_dir.mkdir(misc::qBittorrentPath()+"search_engine");
}
QFile package_file(search_dir.path()+QDir::separator()+"__init__.py"); QFile package_file(search_dir.path()+QDir::separator()+"__init__.py");
package_file.open(QIODevice::WriteOnly | QIODevice::Text); package_file.open(QIODevice::WriteOnly | QIODevice::Text);
package_file.close(); package_file.close();
@ -372,7 +369,7 @@ void SearchEngine::updateNova() {
package_file2.open(QIODevice::WriteOnly | QIODevice::Text); package_file2.open(QIODevice::WriteOnly | QIODevice::Text);
package_file2.close(); package_file2.close();
// Copy search plugin files (if necessary) // Copy search plugin files (if necessary)
QString filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py"; QString filePath = misc::searchEngineLocation()+QDir::separator()+"nova2.py";
if(getPluginVersion(":/search_engine/nova2.py") > getPluginVersion(filePath)) { if(getPluginVersion(":/search_engine/nova2.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)) if(QFile::exists(filePath))
QFile::remove(filePath); QFile::remove(filePath);
@ -380,33 +377,33 @@ void SearchEngine::updateNova() {
} }
// Set permissions // Set permissions
QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup; QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup;
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py").setPermissions(perm); QFile(misc::searchEngineLocation()+QDir::separator()+"nova2.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py"; filePath = misc::searchEngineLocation()+QDir::separator()+"nova2dl.py";
if(getPluginVersion(":/search_engine/nova2dl.py") > getPluginVersion(filePath)) { if(getPluginVersion(":/search_engine/nova2dl.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){ if(QFile::exists(filePath)){
QFile::remove(filePath); QFile::remove(filePath);
} }
QFile::copy(":/search_engine/nova2dl.py", filePath); QFile::copy(":/search_engine/nova2dl.py", filePath);
} }
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py").setPermissions(perm); QFile(misc::searchEngineLocation()+QDir::separator()+"nova2dl.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"novaprinter.py"; filePath = misc::searchEngineLocation()+QDir::separator()+"novaprinter.py";
if(getPluginVersion(":/search_engine/novaprinter.py") > getPluginVersion(filePath)) { if(getPluginVersion(":/search_engine/novaprinter.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){ if(QFile::exists(filePath)){
QFile::remove(filePath); QFile::remove(filePath);
} }
QFile::copy(":/search_engine/novaprinter.py", filePath); QFile::copy(":/search_engine/novaprinter.py", filePath);
} }
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"novaprinter.py").setPermissions(perm); QFile(misc::searchEngineLocation()+QDir::separator()+"novaprinter.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"helpers.py"; filePath = misc::searchEngineLocation()+QDir::separator()+"helpers.py";
if(getPluginVersion(":/search_engine/helpers.py") > getPluginVersion(filePath)) { if(getPluginVersion(":/search_engine/helpers.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){ if(QFile::exists(filePath)){
QFile::remove(filePath); QFile::remove(filePath);
} }
QFile::copy(":/search_engine/helpers.py", filePath); QFile::copy(":/search_engine/helpers.py", filePath);
} }
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"helpers.py").setPermissions(perm); QFile(misc::searchEngineLocation()+QDir::separator()+"helpers.py").setPermissions(perm);
QString destDir = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator(); QString destDir = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator();
QDir shipped_subDir(":/search_engine/engines/"); QDir shipped_subDir(":/search_engine/engines/");
QStringList files = shipped_subDir.entryList(); QStringList files = shipped_subDir.entryList();
foreach(const QString &file, files){ foreach(const QString &file, files){

View file

@ -139,7 +139,7 @@ public slots:
void update() { void update() {
QProcess nova; QProcess nova;
QStringList params; QStringList params;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py"; params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
params << "--capabilities"; params << "--capabilities";
nova.start("python", params, QIODevice::ReadOnly); nova.start("python", params, QIODevice::ReadOnly);
nova.waitForStarted(); nova.waitForStarted();