|
|
@ -863,7 +863,7 @@ void GUI::saveColWidthDLList() const{ |
|
|
|
width_list << QString(misc::toString(downloadList->columnWidth(i)).c_str()); |
|
|
|
width_list << QString(misc::toString(downloadList->columnWidth(i)).c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(lastDLListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ |
|
|
|
if(lastDLListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ |
|
|
|
lastDLListWidth.write(QByteArray(width_list.join(" ").toStdString().c_str())); |
|
|
|
lastDLListWidth.write(width_list.join(" ").toAscii()); |
|
|
|
lastDLListWidth.close(); |
|
|
|
lastDLListWidth.close(); |
|
|
|
qDebug("Columns width saved"); |
|
|
|
qDebug("Columns width saved"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -910,7 +910,7 @@ void GUI::saveColWidthSearchList() const{ |
|
|
|
width_list << QString(misc::toString(resultsBrowser->columnWidth(i)).c_str()); |
|
|
|
width_list << QString(misc::toString(resultsBrowser->columnWidth(i)).c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(lastSearchListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ |
|
|
|
if(lastSearchListWidth.open(QIODevice::WriteOnly | QIODevice::Text)){ |
|
|
|
lastSearchListWidth.write(QByteArray(width_list.join(" ").toStdString().c_str())); |
|
|
|
lastSearchListWidth.write(width_list.join(" ").toAscii()); |
|
|
|
lastSearchListWidth.close(); |
|
|
|
lastSearchListWidth.close(); |
|
|
|
qDebug("Columns width saved in search list"); |
|
|
|
qDebug("Columns width saved in search list"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -1017,7 +1017,7 @@ void GUI::closeEvent(QCloseEvent *e){ |
|
|
|
if(DHTEnabled){ |
|
|
|
if(DHTEnabled){ |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
entry dht_state = s->dht_state(); |
|
|
|
entry dht_state = s->dht_state(); |
|
|
|
boost::filesystem::ofstream out(misc::qBittorrentPath().toStdString()+"dht_state", std::ios_base::binary); |
|
|
|
boost::filesystem::ofstream out((const char*)(misc::qBittorrentPath()+QString("dht_state")).toUtf8(), 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); |
|
|
|
}catch (std::exception& e){ |
|
|
|
}catch (std::exception& e){ |
|
|
@ -1114,7 +1114,7 @@ void GUI::askForTorrents(){ |
|
|
|
lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text); |
|
|
|
lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text); |
|
|
|
QStringList top_dir = pathsList.at(0).split(QDir::separator()); |
|
|
|
QStringList top_dir = pathsList.at(0).split(QDir::separator()); |
|
|
|
top_dir.removeLast(); |
|
|
|
top_dir.removeLast(); |
|
|
|
lastDirFile.write(QByteArray(top_dir.join(QDir::separator()).toStdString().c_str())); |
|
|
|
lastDirFile.write(top_dir.join(QDir::separator()).toUtf8()); |
|
|
|
lastDirFile.close(); |
|
|
|
lastDirFile.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1150,7 +1150,7 @@ void GUI::scanDirectory(){ |
|
|
|
|
|
|
|
|
|
|
|
void GUI::saveFastResumeData() const{ |
|
|
|
void GUI::saveFastResumeData() const{ |
|
|
|
qDebug("Saving fast resume data"); |
|
|
|
qDebug("Saving fast resume data"); |
|
|
|
std::string file; |
|
|
|
QString file; |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
// Checking if torrentBackup Dir exists
|
|
|
|
// Checking if torrentBackup Dir exists
|
|
|
|
// create it if it is not
|
|
|
|
// create it if it is not
|
|
|
@ -1163,14 +1163,14 @@ void GUI::saveFastResumeData() const{ |
|
|
|
h.pause(); |
|
|
|
h.pause(); |
|
|
|
// Extracting resume data
|
|
|
|
// Extracting resume data
|
|
|
|
if (h.has_metadata()){ |
|
|
|
if (h.has_metadata()){ |
|
|
|
QString filename = QString(h.get_torrent_info().name().c_str()); |
|
|
|
QString fileName = QString(h.get_torrent_info().name().c_str()); |
|
|
|
if(QFile::exists(torrentBackup.path()+QDir::separator()+filename+".torrent")){ |
|
|
|
if(QFile::exists(torrentBackup.path()+QDir::separator()+fileName+".torrent")){ |
|
|
|
// Remove old .fastresume data in case it exists
|
|
|
|
// Remove old .fastresume data in case it exists
|
|
|
|
QFile::remove(filename + ".fastresume"); |
|
|
|
QFile::remove(fileName + ".fastresume"); |
|
|
|
// Write fast resume data
|
|
|
|
// Write fast resume data
|
|
|
|
entry resumeData = h.write_resume_data(); |
|
|
|
entry resumeData = h.write_resume_data(); |
|
|
|
file = filename.toStdString() + ".fastresume"; |
|
|
|
file = fileName + ".fastresume"; |
|
|
|
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toStdString()) / file, std::ios_base::binary); |
|
|
|
boost::filesystem::ofstream out(fs::path((const char*)torrentBackup.path().toUtf8()) / (const char*)file.toUtf8(), std::ios_base::binary); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
bencode(std::ostream_iterator<char>(out), resumeData); |
|
|
|
bencode(std::ostream_iterator<char>(out), resumeData); |
|
|
|
} |
|
|
|
} |
|
|
@ -1334,8 +1334,8 @@ void GUI::addTorrent(const QString& path, bool fromScanDir, const QString& from_ |
|
|
|
if(file.isEmpty()){ |
|
|
|
if(file.isEmpty()){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
qDebug("Adding %s to download list", file.toStdString().c_str()); |
|
|
|
qDebug("Adding %s to download list", (const char*)file.toUtf8()); |
|
|
|
std::ifstream in(file.toStdString().c_str(), std::ios_base::binary); |
|
|
|
std::ifstream in((const char*)file.toUtf8(), std::ios_base::binary); |
|
|
|
in.unsetf(std::ios_base::skipws); |
|
|
|
in.unsetf(std::ios_base::skipws); |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
// Decode torrent file
|
|
|
|
// Decode torrent file
|
|
|
@ -1363,7 +1363,7 @@ void GUI::addTorrent(const QString& path, bool fromScanDir, const QString& from_ |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
std::stringstream strStream; |
|
|
|
std::stringstream strStream; |
|
|
|
strStream << t.name() << ".fastresume"; |
|
|
|
strStream << t.name() << ".fastresume"; |
|
|
|
boost::filesystem::ifstream resume_file(fs::path(torrentBackup.path().toStdString()) / strStream.str(), std::ios_base::binary); |
|
|
|
boost::filesystem::ifstream resume_file(fs::path((const char*)torrentBackup.path().toUtf8()) / strStream.str(), std::ios_base::binary); |
|
|
|
resume_file.unsetf(std::ios_base::skipws); |
|
|
|
resume_file.unsetf(std::ios_base::skipws); |
|
|
|
resume_data = bdecode(std::istream_iterator<char>(resume_file), std::istream_iterator<char>()); |
|
|
|
resume_data = bdecode(std::istream_iterator<char>(resume_file), std::istream_iterator<char>()); |
|
|
|
fastResume=true; |
|
|
|
fastResume=true; |
|
|
@ -1371,15 +1371,15 @@ void GUI::addTorrent(const QString& path, bool fromScanDir, const QString& from_ |
|
|
|
catch (fs::filesystem_error&) {} |
|
|
|
catch (fs::filesystem_error&) {} |
|
|
|
//qDebug("Got fast resume data");
|
|
|
|
//qDebug("Got fast resume data");
|
|
|
|
} |
|
|
|
} |
|
|
|
//Get Save Path TODO: finish
|
|
|
|
|
|
|
|
QString savePath = getSavePath(QString(t.name().c_str())); |
|
|
|
QString savePath = getSavePath(QString(t.name().c_str())); |
|
|
|
int row = DLListModel->rowCount(); |
|
|
|
int row = DLListModel->rowCount(); |
|
|
|
// Adding files to bittorrent session
|
|
|
|
// Adding files to bittorrent session
|
|
|
|
|
|
|
|
std::cout << "save path: " << (const char*)savePath.toUtf8() << "\n"; |
|
|
|
if(hasFilteredFiles(QString(t.name().c_str()))){ |
|
|
|
if(hasFilteredFiles(QString(t.name().c_str()))){ |
|
|
|
h = s->add_torrent(t, fs::path(savePath.toStdString()), resume_data, false); |
|
|
|
h = s->add_torrent(t, fs::path((const char*)savePath.toUtf8()), resume_data, false); |
|
|
|
qDebug("Full allocation mode"); |
|
|
|
qDebug("Full allocation mode"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
h = s->add_torrent(t, fs::path(savePath.toStdString()), resume_data, true); |
|
|
|
h = s->add_torrent(t, fs::path((const char*)savePath.toUtf8()), resume_data, true); |
|
|
|
qDebug("Compact allocation mode"); |
|
|
|
qDebug("Compact allocation mode"); |
|
|
|
} |
|
|
|
} |
|
|
|
h.set_max_connections(60); |
|
|
|
h.set_max_connections(60); |
|
|
@ -1496,7 +1496,7 @@ QString GUI::getSavePath(QString fileName){ |
|
|
|
line = savepath_file.readAll(); |
|
|
|
line = savepath_file.readAll(); |
|
|
|
savepath_file.close(); |
|
|
|
savepath_file.close(); |
|
|
|
qDebug("Save path: %s", line.data()); |
|
|
|
qDebug("Save path: %s", line.data()); |
|
|
|
savePath = QString(line.data()); |
|
|
|
savePath = QString::fromUtf8(line.data()); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
savePath = options->getSavePath(); |
|
|
|
savePath = options->getSavePath(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1505,7 +1505,7 @@ QString GUI::getSavePath(QString fileName){ |
|
|
|
QDir saveDir(savePath); |
|
|
|
QDir saveDir(savePath); |
|
|
|
if(!saveDir.exists()){ |
|
|
|
if(!saveDir.exists()){ |
|
|
|
if(!saveDir.mkpath(saveDir.path())){ |
|
|
|
if(!saveDir.mkpath(saveDir.path())){ |
|
|
|
std::cerr << "Couldn't create the save directory: " << saveDir.path().toStdString() +"\n"; |
|
|
|
std::cerr << "Couldn't create the save directory: " << (const char*)saveDir.path().toUtf8() << "\n"; |
|
|
|
// TODO: handle this better
|
|
|
|
// TODO: handle this better
|
|
|
|
return QDir::homePath(); |
|
|
|
return QDir::homePath(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1516,7 +1516,7 @@ QString GUI::getSavePath(QString fileName){ |
|
|
|
void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ |
|
|
|
void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ |
|
|
|
QDir saveDir(options->getSavePath()), torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir saveDir(options->getSavePath()), torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QString fileName = QString(h.get_torrent_info().name().c_str()); |
|
|
|
QString fileName = QString(h.get_torrent_info().name().c_str()); |
|
|
|
qDebug("Reloading torrent: %s", fileName.toStdString().c_str()); |
|
|
|
qDebug("Reloading torrent: %s", (const char*)fileName.toUtf8()); |
|
|
|
torrent_handle new_h; |
|
|
|
torrent_handle new_h; |
|
|
|
entry resumeData; |
|
|
|
entry resumeData; |
|
|
|
torrent_info t = h.get_torrent_info(); |
|
|
|
torrent_info t = h.get_torrent_info(); |
|
|
@ -1556,7 +1556,7 @@ void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ |
|
|
|
std::cerr << "Error: Couldn't reload the torrent\n"; |
|
|
|
std::cerr << "Error: Couldn't reload the torrent\n"; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
new_h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resumeData, compact_mode); |
|
|
|
new_h = s->add_torrent(t, fs::path((const char*)saveDir.path().toUtf8()), resumeData, compact_mode); |
|
|
|
if(compact_mode){ |
|
|
|
if(compact_mode){ |
|
|
|
qDebug("Using compact allocation mode"); |
|
|
|
qDebug("Using compact allocation mode"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -1590,7 +1590,7 @@ void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ |
|
|
|
} |
|
|
|
} |
|
|
|
// Incremental download
|
|
|
|
// Incremental download
|
|
|
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental")){ |
|
|
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental")){ |
|
|
|
qDebug("Incremental download enabled for %s", fileName.toStdString().c_str()); |
|
|
|
qDebug("Incremental download enabled for %s", (const char*)fileName.toUtf8()); |
|
|
|
new_h.set_sequenced_download_threshold(15); |
|
|
|
new_h.set_sequenced_download_threshold(15); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1686,7 +1686,7 @@ void GUI::configureSession(){ |
|
|
|
setGlobalRatio(options->getRatio()); |
|
|
|
setGlobalRatio(options->getRatio()); |
|
|
|
// DHT (Trackerless)
|
|
|
|
// DHT (Trackerless)
|
|
|
|
if(options->isDHTEnabled() && !DHTEnabled){ |
|
|
|
if(options->isDHTEnabled() && !DHTEnabled){ |
|
|
|
boost::filesystem::ifstream dht_state_file(misc::qBittorrentPath().toStdString()+"dht_state", std::ios_base::binary); |
|
|
|
boost::filesystem::ifstream dht_state_file((const char*)(misc::qBittorrentPath()+QString("dht_state")).toUtf8(), std::ios_base::binary); |
|
|
|
dht_state_file.unsetf(std::ios_base::skipws); |
|
|
|
dht_state_file.unsetf(std::ios_base::skipws); |
|
|
|
entry dht_state; |
|
|
|
entry dht_state; |
|
|
|
try{ |
|
|
|
try{ |
|
|
@ -2156,15 +2156,15 @@ void GUI::updateNova() const{ |
|
|
|
// ask user for action.
|
|
|
|
// ask user for action.
|
|
|
|
void GUI::on_update_nova_button_clicked(){ |
|
|
|
void GUI::on_update_nova_button_clicked(){ |
|
|
|
CURL *curl; |
|
|
|
CURL *curl; |
|
|
|
std::string filePath; |
|
|
|
QString filePath; |
|
|
|
qDebug("Checking for search plugin updates on qbittorrent.org"); |
|
|
|
qDebug("Checking for search plugin updates on qbittorrent.org"); |
|
|
|
// XXX: Trick to get a unique filename
|
|
|
|
// XXX: Trick to get a unique filename
|
|
|
|
QTemporaryFile *tmpfile = new QTemporaryFile; |
|
|
|
QTemporaryFile *tmpfile = new QTemporaryFile; |
|
|
|
if (tmpfile->open()) { |
|
|
|
if (tmpfile->open()) { |
|
|
|
filePath = tmpfile->fileName().toStdString(); |
|
|
|
filePath = tmpfile->fileName(); |
|
|
|
} |
|
|
|
} |
|
|
|
delete tmpfile; |
|
|
|
delete tmpfile; |
|
|
|
FILE *file = fopen(filePath.c_str(), "w"); |
|
|
|
FILE *file = fopen((const char*)filePath.toUtf8(), "w"); |
|
|
|
if(!file){ |
|
|
|
if(!file){ |
|
|
|
std::cerr << "Error: could not open temporary file...\n"; |
|
|
|
std::cerr << "Error: could not open temporary file...\n"; |
|
|
|
} |
|
|
|
} |
|
|
@ -2190,12 +2190,12 @@ void GUI::on_update_nova_button_clicked(){ |
|
|
|
curl_easy_cleanup(curl); |
|
|
|
curl_easy_cleanup(curl); |
|
|
|
// Close tmp file
|
|
|
|
// Close tmp file
|
|
|
|
fclose(file); |
|
|
|
fclose(file); |
|
|
|
qDebug("Version on qbittorrent.org: %f", getNovaVersion(QString(filePath.c_str()))); |
|
|
|
qDebug("Version on qbittorrent.org: %f", getNovaVersion(filePath)); |
|
|
|
float version_on_server = getNovaVersion(QString(filePath.c_str())); |
|
|
|
float version_on_server = getNovaVersion(filePath); |
|
|
|
if(version_on_server == 0.0){ |
|
|
|
if(version_on_server == 0.0){ |
|
|
|
//First server is down, try mirror
|
|
|
|
//First server is down, try mirror
|
|
|
|
QFile::remove(filePath.c_str()); |
|
|
|
QFile::remove(filePath); |
|
|
|
FILE *file = fopen(filePath.c_str(), "w"); |
|
|
|
FILE *file = fopen((const char*)filePath.toUtf8(), "w"); |
|
|
|
if(!file){ |
|
|
|
if(!file){ |
|
|
|
std::cerr << "Error: could not open temporary file...\n"; |
|
|
|
std::cerr << "Error: could not open temporary file...\n"; |
|
|
|
} |
|
|
|
} |
|
|
@ -2214,19 +2214,19 @@ void GUI::on_update_nova_button_clicked(){ |
|
|
|
curl_easy_cleanup(curl); |
|
|
|
curl_easy_cleanup(curl); |
|
|
|
// Close tmp file
|
|
|
|
// Close tmp file
|
|
|
|
fclose(file); |
|
|
|
fclose(file); |
|
|
|
version_on_server = getNovaVersion(QString(filePath.c_str())); |
|
|
|
version_on_server = getNovaVersion(filePath); |
|
|
|
} |
|
|
|
} |
|
|
|
if(version_on_server > getNovaVersion(misc::qBittorrentPath()+"nova.py")){ |
|
|
|
if(version_on_server > getNovaVersion(misc::qBittorrentPath()+"nova.py")){ |
|
|
|
if(QMessageBox::question(this, |
|
|
|
if(QMessageBox::question(this, |
|
|
|
tr("Search plugin update -- qBittorrent"), |
|
|
|
tr("Search plugin update -- qBittorrent"), |
|
|
|
tr("Search plugin can be updated, do you want to update it?\n\nChangelog:\n")+QString(getNovaChangelog(QString(filePath.c_str())).data()), |
|
|
|
tr("Search plugin can be updated, do you want to update it?\n\nChangelog:\n")+getNovaChangelog(filePath), |
|
|
|
tr("&Yes"), tr("&No"), |
|
|
|
tr("&Yes"), tr("&No"), |
|
|
|
QString(), 0, 1)){ |
|
|
|
QString(), 0, 1)){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
qDebug("Updating search plugin from qbittorrent.org"); |
|
|
|
qDebug("Updating search plugin from qbittorrent.org"); |
|
|
|
QFile::remove(misc::qBittorrentPath()+"nova.py"); |
|
|
|
QFile::remove(misc::qBittorrentPath()+"nova.py"); |
|
|
|
QFile::copy(QString(filePath.c_str()), misc::qBittorrentPath()+"nova.py"); |
|
|
|
QFile::copy(filePath, misc::qBittorrentPath()+"nova.py"); |
|
|
|
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()+"nova.py").setPermissions(perm); |
|
|
|
QFile(misc::qBittorrentPath()+"nova.py").setPermissions(perm); |
|
|
|
} |
|
|
|
} |
|
|
@ -2240,7 +2240,7 @@ void GUI::on_update_nova_button_clicked(){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Delete tmp file
|
|
|
|
// Delete tmp file
|
|
|
|
QFile::remove(filePath.c_str()); |
|
|
|
QFile::remove(filePath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Slot called when search is Finished
|
|
|
|
// Slot called when search is Finished
|
|
|
|