mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-24 02:06:07 +03:00
Code cleanup
This commit is contained in:
parent
bbb5ad31c4
commit
b483f09d11
16 changed files with 136 additions and 144 deletions
|
@ -425,7 +425,7 @@ void GUI::readSettings() {
|
|||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
settings.beginGroup(QString::fromUtf8("MainWindow"));
|
||||
restoreGeometry(settings.value("geometry").toByteArray());
|
||||
const QStringList &sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList();
|
||||
const QStringList sizes_str = settings.value("vSplitterSizes", QStringList()).toStringList();
|
||||
// Splitter size
|
||||
QList<int> sizes;
|
||||
if(sizes_str.size() == 2) {
|
||||
|
@ -664,7 +664,7 @@ void GUI::dropEvent(QDropEvent *event) {
|
|||
event->acceptProposedAction();
|
||||
QStringList files;
|
||||
if(event->mimeData()->hasUrls()) {
|
||||
const QList<QUrl> &urls = event->mimeData()->urls();
|
||||
const QList<QUrl> urls = event->mimeData()->urls();
|
||||
foreach(const QUrl &url, urls) {
|
||||
const QString tmp = url.toString().trimmed();
|
||||
if(!tmp.isEmpty())
|
||||
|
@ -723,7 +723,7 @@ void GUI::on_actionOpen_triggered() {
|
|||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
// Open File Open Dialog
|
||||
// Note: it is possible to select more than one file
|
||||
const QStringList &pathsList = QFileDialog::getOpenFileNames(0,
|
||||
const QStringList pathsList = QFileDialog::getOpenFileNames(0,
|
||||
tr("Open Torrent Files"), settings.value(QString::fromUtf8("MainWindowLastDir"), QDir::homePath()).toString(),
|
||||
tr("Torrent Files")+QString::fromUtf8(" (*.torrent)"));
|
||||
if(!pathsList.empty()) {
|
||||
|
|
|
@ -178,7 +178,7 @@ protected slots:
|
|||
setItem(NETWORK_IFACE, PROPERTY, new QTableWidgetItem(tr("Network Interface (requires restart)")));
|
||||
combo_iface = new QComboBox;
|
||||
combo_iface->addItem(tr("Any interface", "i.e. Any network interface"));
|
||||
const QString ¤t_iface = Preferences::getNetworkInterface();
|
||||
const QString current_iface = Preferences::getNetworkInterface();
|
||||
int i = 1;
|
||||
foreach(const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||||
if(iface.name() == "lo") continue;
|
||||
|
|
|
@ -267,7 +267,7 @@ void Bittorrent::setUploadLimit(QString hash, long val) {
|
|||
void Bittorrent::handleDownloadFailure(QString url, QString reason) {
|
||||
emit downloadFromUrlFailure(url, reason);
|
||||
// Clean up
|
||||
const QUrl &qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
const int index = url_skippingDlg.indexOf(qurl);
|
||||
if(index >= 0)
|
||||
url_skippingDlg.removeAt(index);
|
||||
|
@ -304,7 +304,7 @@ void Bittorrent::configureSession() {
|
|||
preAllocateAllFiles(Preferences::preAllocateAllFiles());
|
||||
startTorrentsInPause(Preferences::addTorrentsInPause());
|
||||
// * Scan dirs
|
||||
const QStringList &scan_dirs = Preferences::getScanDirs();
|
||||
const QStringList scan_dirs = Preferences::getScanDirs();
|
||||
QList<bool> downloadInDirList = Preferences::getDownloadInScanDirs();
|
||||
while(scan_dirs.size() > downloadInDirList.size()) {
|
||||
downloadInDirList << false;
|
||||
|
@ -678,7 +678,7 @@ void Bittorrent::useAlternativeSpeedsLimit(bool alternative) {
|
|||
void Bittorrent::takeETASamples() {
|
||||
bool change = false;;
|
||||
foreach(const QString &hash, ETA_samples.keys()) {
|
||||
const QTorrentHandle &h = getTorrentHandle(hash);
|
||||
const QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(h.is_valid() && !h.is_paused() && !h.is_seed()) {
|
||||
QList<int> samples = ETA_samples.value(h.hash(), QList<int>());
|
||||
if(samples.size() >= MAX_SAMPLES)
|
||||
|
@ -701,7 +701,7 @@ void Bittorrent::takeETASamples() {
|
|||
// CSA: Current Speed Algorithm
|
||||
// WINX: Window of X Algorithm
|
||||
qlonglong Bittorrent::getETA(QString hash) {
|
||||
const QTorrentHandle &h = getTorrentHandle(hash);
|
||||
const QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(!h.is_valid() || h.state() != torrent_status::downloading || !h.active_time())
|
||||
return -1;
|
||||
// See if the torrent is going to be completed soon
|
||||
|
@ -717,7 +717,7 @@ qlonglong Bittorrent::getETA(QString hash) {
|
|||
connect(timerETA, SIGNAL(timeout()), this, SLOT(takeETASamples()));
|
||||
timerETA->start();
|
||||
} else {
|
||||
const QList<int> &samples = ETA_samples.value(h.hash(), QList<int>());
|
||||
const QList<int> samples = ETA_samples.value(h.hash(), QList<int>());
|
||||
const int nb_samples = samples.size();
|
||||
if(nb_samples > 3) {
|
||||
long sum_samples = 0;
|
||||
|
@ -764,12 +764,12 @@ void Bittorrent::banIP(QString ip) {
|
|||
// permanent = true means that the torrent will be removed from the hard-drive too
|
||||
void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) {
|
||||
qDebug("Deleting torrent with hash: %s", qPrintable(hash));
|
||||
const QTorrentHandle &h = getTorrentHandle(hash);
|
||||
const QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(!h.is_valid()) {
|
||||
qDebug("/!\\ Error: Invalid handle");
|
||||
return;
|
||||
}
|
||||
const QString &fileName = h.name();
|
||||
const QString fileName(h.name());
|
||||
// Remove it from session
|
||||
if(delete_local_files) {
|
||||
QDir save_dir(h.save_path());
|
||||
|
@ -783,7 +783,7 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) {
|
|||
QDir torrentBackup(misc::BTBackupLocation());
|
||||
QStringList filters;
|
||||
filters << hash+".*";
|
||||
const QStringList &files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
const QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
foreach(const QString &file, files) {
|
||||
torrentBackup.remove(file);
|
||||
}
|
||||
|
@ -841,7 +841,7 @@ void Bittorrent::resumeTorrent(QString hash) {
|
|||
|
||||
QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
||||
QTorrentHandle h;
|
||||
const QString &hash = misc::magnetUriToHash(magnet_uri);
|
||||
const QString hash(misc::magnetUriToHash(magnet_uri));
|
||||
if(hash.isEmpty()) {
|
||||
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
|
||||
return h;
|
||||
|
@ -880,7 +880,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
|||
}
|
||||
}
|
||||
QString torrent_name = misc::magnetUriToName(magnet_uri);
|
||||
const QString &savePath = getSavePath(hash, false, QString::null, torrent_name);
|
||||
const QString savePath(getSavePath(hash, false, QString::null, torrent_name));
|
||||
if(!defaultTempPath.isEmpty() && resumed && !TorrentPersistentData::isSeed(hash)) {
|
||||
qDebug("addMagnetURI: Temp folder is enabled.");
|
||||
qDebug("addTorrent::Temp folder is enabled.");
|
||||
|
@ -950,7 +950,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
|||
qDebug("addMagnetURI Setting download as sequential (from tmp data)");
|
||||
h.set_sequential_download(TorrentTempData::isSequential(hash));
|
||||
}
|
||||
const QString &label = TorrentTempData::getLabel(hash);
|
||||
const QString label(TorrentTempData::getLabel(hash));
|
||||
// Save persistent data for new torrent
|
||||
TorrentPersistentData::saveTorrentPersistentData(h, true);
|
||||
// Save Label
|
||||
|
@ -1074,10 +1074,10 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
addConsoleMessage(tr("Note: new trackers were added to the existing torrent."));
|
||||
}
|
||||
bool urlseeds_added = false;
|
||||
const QStringList &old_urlseeds = h_ex.url_seeds();
|
||||
const QStringList old_urlseeds = h_ex.url_seeds();
|
||||
std::vector<std::string> new_urlseeds = t->url_seeds();
|
||||
for(std::vector<std::string>::iterator it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
|
||||
const QString &new_url = misc::toQString(it->c_str());
|
||||
const QString new_url = misc::toQString(it->c_str());
|
||||
if(!old_urlseeds.contains(new_url)) {
|
||||
urlseeds_added = true;
|
||||
h_ex.add_url_seed(new_url);
|
||||
|
@ -1212,7 +1212,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
qDebug("addTorrent: Setting download as sequential (from tmp data)");
|
||||
h.set_sequential_download(TorrentTempData::isSequential(hash));
|
||||
// Import Files names from torrent addition dialog
|
||||
const QStringList &files_path = TorrentTempData::getFilesPath(hash);
|
||||
const QStringList files_path = TorrentTempData::getFilesPath(hash);
|
||||
bool force_recheck = false;
|
||||
if(files_path.size() == h.num_files()) {
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
|
@ -1236,7 +1236,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
if(force_recheck) h.force_recheck();
|
||||
}
|
||||
}
|
||||
const QString &label = TorrentTempData::getLabel(hash);
|
||||
const QString label(TorrentTempData::getLabel(hash));
|
||||
// Save persistent data for new torrent
|
||||
TorrentPersistentData::saveTorrentPersistentData(h);
|
||||
// Save Label
|
||||
|
@ -1254,7 +1254,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
appendqBextensionToTorrent(h, true);
|
||||
#endif
|
||||
// Backup torrent file
|
||||
const QString &newFile = torrentBackup.absoluteFilePath(hash + ".torrent");
|
||||
const QString newFile = torrentBackup.absoluteFilePath(hash + ".torrent");
|
||||
if(file != newFile) {
|
||||
// Delete file from torrentBackup directory in case it exists because
|
||||
// QFile::copy() do not overwrite
|
||||
|
@ -1320,7 +1320,7 @@ void Bittorrent::exportTorrentFiles(QString path) {
|
|||
std::cerr << "Torrent Export: torrent is invalid, skipping..." << std::endl;
|
||||
continue;
|
||||
}
|
||||
const QString &src_path = torrentBackup.absoluteFilePath(h.hash()+".torrent");
|
||||
const QString src_path(torrentBackup.absoluteFilePath(h.hash()+".torrent"));
|
||||
if(QFile::exists(src_path)) {
|
||||
QString dst_path = exportDir.absoluteFilePath(h.name()+".torrent");
|
||||
if(QFile::exists(dst_path)) {
|
||||
|
@ -1651,7 +1651,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
|
||||
bool Bittorrent::isFilePreviewPossible(QString hash) const{
|
||||
// See if there are supported files in the torrent
|
||||
const QTorrentHandle &h = getTorrentHandle(hash);
|
||||
const QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(!h.is_valid() || !h.has_metadata()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1730,7 +1730,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(append) {
|
||||
const qulonglong file_size = h.filesize_at(i);
|
||||
if(file_size > 0 && (fp[i]/(double)file_size) < 1.) {
|
||||
const QString &name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
if(!name.endsWith(".!qB")) {
|
||||
const QString new_name = name+".!qB";
|
||||
qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name));
|
||||
|
@ -1766,7 +1766,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
|
||||
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle& h) {
|
||||
if(!h.is_valid()) return;
|
||||
const QString &label = TorrentPersistentData::getLabel(h.hash());
|
||||
const QString label = TorrentPersistentData::getLabel(h.hash());
|
||||
if(label.isEmpty()) return;
|
||||
// Current save path
|
||||
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
|
||||
|
@ -1966,13 +1966,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) {
|
||||
torrent_info::file_iterator it;
|
||||
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
|
||||
const QString &torrent_relpath = misc::toQStringU(it->path.string());
|
||||
const QString torrent_relpath = misc::toQStringU(it->path.string());
|
||||
if(torrent_relpath.endsWith(".torrent")) {
|
||||
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name()));
|
||||
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
|
||||
try {
|
||||
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
|
||||
const QString &sub_hash = misc::toQString(t->info_hash());
|
||||
const QString sub_hash = misc::toQString(t->info_hash());
|
||||
// Passing the save path along to the sub torrent file
|
||||
TorrentTempData::setSavePath(sub_hash, h.save_path());
|
||||
addTorrent(torrent_fullpath);
|
||||
|
@ -1993,7 +1993,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QTorrentHandle h(p->handle);
|
||||
if(h.is_valid()) {
|
||||
emit finishedTorrent(h);
|
||||
const QString &hash = h.hash();
|
||||
const QString hash = h.hash();
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Remove .!qB extension if necessary
|
||||
if(appendqBExtension)
|
||||
|
@ -2015,7 +2015,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// Check if there are torrent files inside
|
||||
torrent_info::file_iterator it;
|
||||
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
|
||||
const QString &torrent_relpath = misc::toQStringU(it->path.string());
|
||||
const QString torrent_relpath = misc::toQStringU(it->path.string());
|
||||
if(torrent_relpath.endsWith(".torrent")) {
|
||||
qDebug("Found possible recursive torrent download.");
|
||||
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
|
||||
|
@ -2172,7 +2172,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
appendqBextensionToTorrent(h, true);
|
||||
#endif
|
||||
// Truncate root folder
|
||||
const QString &root_folder = misc::truncateRootFolder(p->handle);
|
||||
const QString root_folder = misc::truncateRootFolder(p->handle);
|
||||
TorrentPersistentData::setRootFolder(h.hash(), root_folder);
|
||||
|
||||
// Move to a subfolder corresponding to the torrent root folder if necessary
|
||||
|
@ -2240,7 +2240,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// Authentication
|
||||
if(p->status_code != 401) {
|
||||
qDebug("Received a tracker error for %s: %s", p->url.c_str(), p->msg.c_str());
|
||||
const QString &tracker_url = misc::toQString(p->url);
|
||||
const QString tracker_url = misc::toQString(p->url);
|
||||
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = misc::toQString(p->msg);
|
||||
|
@ -2261,7 +2261,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
qDebug("Received a tracker reply from %s (Num_peers=%d)", p->url.c_str(), p->num_peers);
|
||||
// Connection was successful now. Remove possible old errors
|
||||
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
|
||||
const QString &tracker_url = misc::toQString(p->url);
|
||||
const QString tracker_url = misc::toQString(p->url);
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = ""; // Reset error/warning message
|
||||
data.num_peers = p->num_peers;
|
||||
|
@ -2277,7 +2277,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(h.is_valid()){
|
||||
// Connection was successful now but there is a warning message
|
||||
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
|
||||
const QString &tracker_url = misc::toQString(p->url);
|
||||
const QString tracker_url = misc::toQString(p->url);
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = misc::toQString(p->msg); // Store warning message
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
|
@ -2332,7 +2332,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(h.is_valid()){
|
||||
const QString &hash = h.hash();
|
||||
const QString hash = h.hash();
|
||||
qDebug("%s have just finished checking", qPrintable(hash));
|
||||
// Save seed status
|
||||
TorrentPersistentData::saveSeedStatus(h);
|
||||
|
@ -2398,7 +2398,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
if(appendLabelToSavePath) {
|
||||
qDebug("appendLabelToSavePath is true");
|
||||
const QString &label = TorrentTempData::getLabel(hash);
|
||||
const QString label = TorrentTempData::getLabel(hash);
|
||||
if(!label.isEmpty()) {
|
||||
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
||||
}
|
||||
|
@ -2422,7 +2422,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
if(!fromScanDir && appendLabelToSavePath) {
|
||||
const QString &label = TorrentPersistentData::getLabel(hash);
|
||||
const QString label = TorrentPersistentData::getLabel(hash);
|
||||
if(!label.isEmpty()) {
|
||||
qDebug("Torrent label is %s", qPrintable(label));
|
||||
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
||||
|
@ -2469,7 +2469,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
|
||||
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
||||
//emit aboutToDownloadFromUrl(url);
|
||||
const 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;
|
||||
|
@ -2506,16 +2506,14 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
float Bittorrent::getPayloadDownloadRate() const{
|
||||
const session_status &sessionStatus = s->status();
|
||||
return sessionStatus.payload_download_rate;
|
||||
return s->status().payload_download_rate;
|
||||
}
|
||||
|
||||
// Return current upload rate for the BT
|
||||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
float Bittorrent::getPayloadUploadRate() const{
|
||||
const session_status &sessionStatus = s->status();
|
||||
return sessionStatus.payload_upload_rate;
|
||||
return s->status().payload_upload_rate;
|
||||
}
|
||||
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
|
@ -2549,13 +2547,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
void Bittorrent::startUpTorrents() {
|
||||
qDebug("Resuming unfinished torrents");
|
||||
const QDir torrentBackup(misc::BTBackupLocation());
|
||||
const QStringList &known_torrents = TorrentPersistentData::knownTorrents();
|
||||
const QStringList known_torrents = TorrentPersistentData::knownTorrents();
|
||||
|
||||
// Safety measure because some people reported torrent loss since
|
||||
// we switch the v1.5 way of resuming torrents on startup
|
||||
QStringList filters;
|
||||
filters << "*.torrent";
|
||||
const 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) {
|
||||
qDebug("found torrent with hash: %s on hard disk", qPrintable(hash));
|
||||
hash.chop(8); // remove trailing .torrent
|
||||
|
|
|
@ -101,7 +101,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
|
|||
}
|
||||
|
||||
void downloadThread::loadCookies(const QString &host_name, QString url) {
|
||||
const QList<QByteArray> &raw_cookies = Preferences::getHostNameCookies(host_name);
|
||||
const QList<QByteArray> raw_cookies = Preferences::getHostNameCookies(host_name);
|
||||
QNetworkCookieJar *cookie_jar = networkManager.cookieJar();
|
||||
QList<QNetworkCookie> cookies;
|
||||
qDebug("Loading cookies for host name: %s", qPrintable(host_name));
|
||||
|
@ -135,7 +135,7 @@ QNetworkReply* downloadThread::downloadUrl(QString url){
|
|||
loadCookies(host_name, url);
|
||||
// Process download request
|
||||
qDebug("url is %s", qPrintable(url));
|
||||
const QUrl &qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||
QNetworkRequest request(qurl);
|
||||
// Spoof Firefox 3.5 user agent to avoid
|
||||
// Web server banning
|
||||
|
|
|
@ -201,7 +201,7 @@ signals:
|
|||
|
||||
private:
|
||||
void addTorrentsFromDir(const QDir &dir, QStringList &torrents) {
|
||||
const QStringList &files = dir.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
const QStringList files = dir.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
foreach(const QString &file, files)
|
||||
torrents << dir.canonicalPath() + '/' + file;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ QString HttpConnection::translateDocument(QString data) {
|
|||
|
||||
void HttpConnection::respond() {
|
||||
//qDebug("Respond called");
|
||||
const QString &peer_ip = socket->peerAddress().toString();
|
||||
const QString peer_ip = socket->peerAddress().toString();
|
||||
const int nb_fail = parent->NbFailedAttemptsForIp(peer_ip);
|
||||
if(nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
generator.setStatusLine(403, "Forbidden");
|
||||
|
|
28
src/misc.cpp
28
src/misc.cpp
|
@ -148,7 +148,7 @@ long long misc::freeDiskSpaceOnPath(QString path) {
|
|||
#ifndef Q_WS_WIN
|
||||
unsigned long long available;
|
||||
struct statfs stats;
|
||||
const QString &statfs_path = dir_path.path()+"/.";
|
||||
const QString statfs_path = dir_path.path()+"/.";
|
||||
const int ret = statfs (qPrintable(statfs_path), &stats) ;
|
||||
if(ret == 0) {
|
||||
available = ((unsigned long long)stats.f_bavail) *
|
||||
|
@ -261,22 +261,22 @@ void misc::copyDir(QString src_path, QString dst_path) {
|
|||
if(!destDir.mkpath(destDir.absolutePath())) return;
|
||||
}
|
||||
// List source directory
|
||||
const 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;
|
||||
}
|
||||
const QString &src_child_path = child.absoluteFilePath();
|
||||
const 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
|
||||
const QString &dir_name = sourceDir.dirName();
|
||||
const QString dir_name = sourceDir.dirName();
|
||||
if(sourceDir.cdUp()) {
|
||||
sourceDir.rmdir(dir_name);
|
||||
}
|
||||
|
@ -312,15 +312,15 @@ QString misc::updateLabelInSavePath(const QString& defaultSavePath, QString save
|
|||
}
|
||||
|
||||
void misc::moveToXDGFolders() {
|
||||
const 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
|
||||
const 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
|
||||
const QString &old_searchPath = old_qBtPath + "search_engine";
|
||||
const QString old_searchPath = old_qBtPath + "search_engine";
|
||||
if(QDir(old_searchPath).exists()) {
|
||||
copyDir(old_searchPath, searchEngineLocation());
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ QPoint misc::screenCenter(QWidget *win) {
|
|||
#endif
|
||||
|
||||
QString misc::searchEngineLocation() {
|
||||
const QString &location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
+ QDir::separator() + "search_engine");
|
||||
QDir locationDir(location);
|
||||
if(!locationDir.exists())
|
||||
|
@ -384,7 +384,7 @@ QString misc::searchEngineLocation() {
|
|||
}
|
||||
|
||||
QString misc::BTBackupLocation() {
|
||||
const QString &location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
|
||||
+ QDir::separator() + "BT_backup");
|
||||
QDir locationDir(location);
|
||||
if(!locationDir.exists())
|
||||
|
@ -468,7 +468,7 @@ bool misc::removeEmptyTree(QString path) {
|
|||
if(child == "." || child == "..") continue;
|
||||
return removeEmptyTree(dir.absoluteFilePath(child));
|
||||
}
|
||||
const QString &dir_name = dir.dirName();
|
||||
const QString dir_name = dir.dirName();
|
||||
if(dir.cdUp()) {
|
||||
return dir.rmdir(dir_name);
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ QString misc::magnetUriToName(QString magnet_uri) {
|
|||
QRegExp regHex("dn=([^&]+)");
|
||||
const int pos = regHex.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
const QString &found = regHex.cap(1);
|
||||
const QString found = regHex.cap(1);
|
||||
// URL decode
|
||||
name = QUrl::fromPercentEncoding(found.toLocal8Bit()).replace("+", " ");
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ QString misc::magnetUriToHash(QString magnet_uri) {
|
|||
// Hex
|
||||
int pos = regHex.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
const QString &found = regHex.cap(1);
|
||||
const QString found = regHex.cap(1);
|
||||
if(found.length() == 40) {
|
||||
const sha1_hash sha1(QString(QByteArray::fromHex(regHex.cap(1).toLocal8Bit())).toStdString());
|
||||
qDebug("magnetUriToHash (Hex): hash: %s", qPrintable(misc::toQString(sha1)));
|
||||
|
@ -518,7 +518,7 @@ QString misc::magnetUriToHash(QString magnet_uri) {
|
|||
QRegExp regBase32("urn:btih:([A-Za-z2-7=]+)");
|
||||
pos = regBase32.indexIn(magnet_uri);
|
||||
if(pos > -1) {
|
||||
const QString &found = regBase32.cap(1);
|
||||
const QString found = regBase32.cap(1);
|
||||
if(found.length() > 20 && (found.length()*5)%40 == 0) {
|
||||
const sha1_hash sha1(base32decode(regBase32.cap(1).toStdString()));
|
||||
hash = misc::toQString(sha1);
|
||||
|
|
|
@ -302,7 +302,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
|
|||
if(!p.isNull())
|
||||
move(p);
|
||||
// Load slider size
|
||||
const QStringList &sizes_str = settings.value("Preferences/State/hSplitterSizes", QStringList()).toStringList();
|
||||
const QStringList sizes_str = settings.value("Preferences/State/hSplitterSizes", QStringList()).toStringList();
|
||||
// Splitter size
|
||||
QList<int> sizes;
|
||||
if(sizes_str.size() == 2) {
|
||||
|
@ -1285,7 +1285,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
|
|||
}
|
||||
|
||||
void options_imp::on_removeScanFolderButton_clicked() {
|
||||
const QModelIndexList &selected
|
||||
const QModelIndexList selected
|
||||
= scanFoldersView->selectionModel()->selectedIndexes();
|
||||
if (selected.isEmpty())
|
||||
return;
|
||||
|
|
|
@ -107,7 +107,7 @@ void PeerListWidget::updatePeerCountryResolutionState() {
|
|||
if(Preferences::resolvePeerCountries() != display_flags) {
|
||||
display_flags = !display_flags;
|
||||
if(display_flags) {
|
||||
const QTorrentHandle &h = properties->getCurrentTorrent();
|
||||
const QTorrentHandle h = properties->getCurrentTorrent();
|
||||
if(!h.is_valid()) return;
|
||||
loadPeers(h);
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
|
|||
resolver->resolve(peer.ip);
|
||||
if(display_flags) {
|
||||
QString country_name;
|
||||
const QIcon &ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
|
||||
const QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
|
||||
if(!ico.isNull()) {
|
||||
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
|
||||
Q_ASSERT(!country_name.isEmpty());
|
||||
|
@ -362,7 +362,7 @@ void PeerListWidget::updatePeer(QString ip, peer_info peer) {
|
|||
int row = item->row();
|
||||
if(display_flags) {
|
||||
QString country_name;
|
||||
const QIcon &ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
|
||||
const QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
|
||||
if(!ico.isNull()) {
|
||||
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
|
||||
Q_ASSERT(!country_name.isEmpty());
|
||||
|
|
|
@ -407,7 +407,7 @@ void PropertiesWidget::loadDynamicData() {
|
|||
void PropertiesWidget::loadUrlSeeds(){
|
||||
listWebSeeds->clear();
|
||||
qDebug("Loading URL seeds");
|
||||
const QStringList &hc_seeds = h.url_seeds();
|
||||
const QStringList hc_seeds = h.url_seeds();
|
||||
// Add url seeds
|
||||
foreach(const QString &hc_seed, hc_seeds){
|
||||
qDebug("Loading URL seed: %s", qPrintable(hc_seed));
|
||||
|
@ -491,9 +491,9 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
|
|||
if(!h.is_valid() || !h.has_metadata()) return;
|
||||
if(PropListModel->getType(index) == TFILE) {
|
||||
int i = PropListModel->getFileIndex(index);
|
||||
const QDir &saveDir(h.save_path());
|
||||
const QString &filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString &file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
||||
const QDir saveDir(h.save_path());
|
||||
const QString filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
||||
qDebug("Trying to open file at %s", qPrintable(file_path));
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Flush data
|
||||
|
@ -517,9 +517,9 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
|
|||
path_items.prepend(parent.data().toString());
|
||||
parent = PropListModel->parent(parent);
|
||||
}
|
||||
const QDir &saveDir(h.save_path());
|
||||
const QString &filename = path_items.join(QDir::separator());
|
||||
const QString &file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
||||
const QDir saveDir(h.save_path());
|
||||
const QString filename = path_items.join(QDir::separator());
|
||||
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
||||
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Flush data
|
||||
|
@ -582,9 +582,9 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){
|
|||
}
|
||||
|
||||
void PropertiesWidget::renameSelectedFile() {
|
||||
const QModelIndexList &selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
||||
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
||||
Q_ASSERT(selectedIndexes.size() == 1);
|
||||
const QModelIndex &index = selectedIndexes.first();
|
||||
const QModelIndex index = selectedIndexes.first();
|
||||
// Ask for new name
|
||||
bool ok;
|
||||
QString new_name_last = QInputDialog::getText(this, tr("Rename the file"),
|
||||
|
@ -648,7 +648,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
path_items.prepend(parent.data().toString());
|
||||
parent = PropListModel->parent(parent);
|
||||
}
|
||||
const QString &old_path = path_items.join("/");
|
||||
const QString old_path = path_items.join("/");
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_path = path_items.join("/");
|
||||
|
@ -671,7 +671,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
bool force_recheck = false;
|
||||
// Replace path in all files
|
||||
for(int i=0; i<num_files; ++i) {
|
||||
const QString ¤t_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
if(current_name.startsWith(old_path)) {
|
||||
QString new_name = current_name;
|
||||
new_name.replace(0, old_path.length(), new_path);
|
||||
|
@ -700,7 +700,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
void PropertiesWidget::askWebSeed(){
|
||||
bool ok;
|
||||
// Ask user for a new url seed
|
||||
const QString &url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
||||
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
||||
tr("New url seed:"), QLineEdit::Normal,
|
||||
QString::fromUtf8("http://www."), &ok);
|
||||
if(!ok) return;
|
||||
|
@ -717,7 +717,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
}
|
||||
|
||||
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
||||
const QList<QListWidgetItem *> &selectedItems = listWebSeeds->selectedItems();
|
||||
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
||||
bool change = false;
|
||||
foreach(const QListWidgetItem *item, selectedItems){
|
||||
QString url_seed = item->text();
|
||||
|
@ -732,7 +732,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
|
||||
bool PropertiesWidget::applyPriorities() {
|
||||
qDebug("Saving pieces priorities");
|
||||
const std::vector<int> &priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
||||
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
||||
bool first_last_piece_first = false;
|
||||
// Save first/last piece first option state
|
||||
if(h.first_last_piece_first())
|
||||
|
|
|
@ -69,7 +69,7 @@ RssFile::FileType RssFolder::getType() const {
|
|||
|
||||
void RssFolder::refreshAll(){
|
||||
qDebug("Refreshing all rss feeds");
|
||||
const QList<RssFile*> &items = this->values();
|
||||
const QList<RssFile*> items = this->values();
|
||||
for(int i=0; i<items.size(); ++i) {
|
||||
//foreach(RssFile *item, *this){
|
||||
RssFile *item = items.at(i);
|
||||
|
@ -361,7 +361,7 @@ void RssManager::moveFile(RssFile* file, RssFolder* dest_folder) {
|
|||
void RssManager::saveStreamList(){
|
||||
QStringList streamsUrl;
|
||||
QStringList aliases;
|
||||
const QList<RssStream*> &streams = getAllFeeds();
|
||||
const QList<RssStream*> streams = getAllFeeds();
|
||||
foreach(const RssStream *stream, streams) {
|
||||
QString stream_path = stream->getPath().join("\\");
|
||||
if(stream_path.isNull()) {
|
||||
|
|
|
@ -159,7 +159,7 @@ ScanFoldersModel::PathStatus ScanFoldersModel::setDownloadAtPath(int row, bool d
|
|||
return CannotWrite;
|
||||
}
|
||||
oldValue = downloadAtPath;
|
||||
const QModelIndex &changedIndex = index(row, DownloadAtTorrentColumn);
|
||||
const QModelIndex changedIndex = index(row, DownloadAtTorrentColumn);
|
||||
emit dataChanged(changedIndex, changedIndex);
|
||||
}
|
||||
return Ok;
|
||||
|
|
|
@ -12,9 +12,9 @@ CONFIG += qt \
|
|||
|
||||
# Update this VERSION for each release
|
||||
os2 {
|
||||
DEFINES += VERSION=\'\"v2.3.0rc7\"\'
|
||||
DEFINES += VERSION=\'\"v2.3.0rc8\"\'
|
||||
} else {
|
||||
DEFINES += VERSION=\\\"v2.3.0rc7\\\"
|
||||
DEFINES += VERSION=\\\"v2.3.0rc8\\\"
|
||||
}
|
||||
DEFINES += VERSION_MAJOR=2
|
||||
DEFINES += VERSION_MINOR=3
|
||||
|
|
|
@ -69,7 +69,7 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||
// Load custom labels
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
settings.beginGroup(QString::fromUtf8("TransferListFilters"));
|
||||
const QStringList &customLabels = settings.value("customLabels", QStringList()).toStringList();
|
||||
const QStringList customLabels = settings.value("customLabels", QStringList()).toStringList();
|
||||
comboLabel->addItem("");
|
||||
foreach(const QString& label, customLabels) {
|
||||
comboLabel->addItem(label);
|
||||
|
@ -94,7 +94,7 @@ void torrentAdditionDialog::readSettings() {
|
|||
resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize());
|
||||
move(settings.value(QString::fromUtf8("TorrentAdditionDlg/pos"), misc::screenCenter(this)).toPoint());
|
||||
// Restore column width
|
||||
const QList<int> &contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth")).toStringList());
|
||||
const QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth")).toStringList());
|
||||
if(contentColsWidths.empty()) {
|
||||
torrentContentList->header()->resizeSection(0, 200);
|
||||
} else {
|
||||
|
@ -265,7 +265,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
|
||||
Q_ASSERT(!is_magnet && t->num_files() > 1);
|
||||
QMenu myFilesLlistMenu;
|
||||
const QModelIndexList &selectedRows = torrentContentList->selectionModel()->selectedRows(0);
|
||||
const QModelIndexList selectedRows = torrentContentList->selectionModel()->selectedRows(0);
|
||||
QAction *actRename = 0;
|
||||
if(selectedRows.size() == 1 && t->num_files() > 1) {
|
||||
actRename = myFilesLlistMenu.addAction(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename..."));
|
||||
|
@ -307,12 +307,12 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
|
|||
|
||||
void torrentAdditionDialog::renameSelectedFile() {
|
||||
Q_ASSERT(!is_magnet && t->num_files() > 1);
|
||||
const QModelIndexList &selectedIndexes = torrentContentList->selectionModel()->selectedRows(0);
|
||||
const QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedRows(0);
|
||||
Q_ASSERT(selectedIndexes.size() == 1);
|
||||
const QModelIndex &index = selectedIndexes.first();
|
||||
// Ask for new name
|
||||
bool ok;
|
||||
const QString &new_name_last = QInputDialog::getText(this, tr("Rename the file"),
|
||||
const QString new_name_last = QInputDialog::getText(this, tr("Rename the file"),
|
||||
tr("New name:"), QLineEdit::Normal,
|
||||
index.data().toString(), &ok);
|
||||
if (ok && !new_name_last.isEmpty()) {
|
||||
|
@ -368,7 +368,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
path_items.prepend(parent.data().toString());
|
||||
parent = PropListModel->parent(parent);
|
||||
}
|
||||
const QString &old_path = path_items.join("/");
|
||||
const QString old_path = path_items.join("/");
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_path = path_items.join("/");
|
||||
|
@ -414,7 +414,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
qulonglong torrent_size = 0;
|
||||
if(t->num_files() > 1) {
|
||||
const unsigned int nbFiles = t->num_files();
|
||||
const std::vector<int> &priorities = PropListModel->getFilesPriorities(nbFiles);
|
||||
const std::vector<int> priorities = PropListModel->getFilesPriorities(nbFiles);
|
||||
|
||||
for(unsigned int i=0; i<nbFiles; ++i) {
|
||||
if(priorities[i] > 0)
|
||||
|
@ -459,7 +459,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
if(path_parts.last().isEmpty())
|
||||
path_parts.removeLast();
|
||||
// Append label
|
||||
const QString &label_name = comboLabel->currentText();
|
||||
const QString label_name = comboLabel->currentText();
|
||||
if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty())
|
||||
path_parts << label_name;
|
||||
// Append root folder
|
||||
|
@ -499,7 +499,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
void torrentAdditionDialog::savePiecesPriorities(){
|
||||
qDebug("Saving pieces priorities");
|
||||
Q_ASSERT(!is_magnet);
|
||||
const std::vector<int> &priorities = PropListModel->getFilesPriorities(t->num_files());
|
||||
const std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files());
|
||||
TorrentTempData::setFilesPriority(hash, priorities);
|
||||
}
|
||||
|
||||
|
@ -522,7 +522,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
save_path = parts.join("/");
|
||||
}
|
||||
QDir savePath(save_path);
|
||||
const QString ¤t_label = comboLabel->currentText().trimmed();
|
||||
const QString current_label = comboLabel->currentText().trimmed();
|
||||
if (!current_label.isEmpty() && !misc::isValidFileSystemName(current_label)) {
|
||||
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
||||
return;
|
||||
|
|
|
@ -535,24 +535,19 @@ public:
|
|||
torrent_info::file_iterator fi = t.begin_files();
|
||||
while(fi != t.end_files()) {
|
||||
current_parent = root_folder;
|
||||
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string()));
|
||||
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())).replace("\\", "/");
|
||||
// Iterate of parts of the path to create necessary folders
|
||||
QStringList pathFolders = path.split("/");
|
||||
//Q_ASSERT(pathFolders.size() >= 2);
|
||||
QString fileName = pathFolders.takeLast();
|
||||
//QString currentFolderName = pathFolders.takeFirst();
|
||||
//Q_ASSERT(currentFolderName == current_parent->getName());
|
||||
pathFolders.takeLast();
|
||||
foreach(const QString &pathPart, pathFolders) {
|
||||
TreeItem *new_parent = current_parent->childWithName(pathPart);
|
||||
if(!new_parent) {
|
||||
new_parent = new TreeItem(pathPart, current_parent);
|
||||
//current_parent->appendChild(new_parent);
|
||||
}
|
||||
current_parent = new_parent;
|
||||
}
|
||||
// Actually create the file
|
||||
TreeItem *f = new TreeItem(*fi, current_parent, i);
|
||||
//current_parent->appendChild(f);
|
||||
files_index[i] = f;
|
||||
fi++;
|
||||
++i;
|
||||
|
|
|
@ -178,7 +178,7 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
|
|||
listModel->setData(listModel->index(row, TR_UPLIMIT), QVariant(h.upload_limit()));
|
||||
listModel->setData(listModel->index(row, TR_DLLIMIT), QVariant(h.download_limit()));
|
||||
listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(h.hash())));
|
||||
const QString &label = TorrentPersistentData::getLabel(h.hash());
|
||||
const QString label = TorrentPersistentData::getLabel(h.hash());
|
||||
listModel->setData(listModel->index(row, TR_LABEL), QVariant(label));
|
||||
if(BTSession->isQueueingEnabled())
|
||||
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)h.queue_position()));
|
||||
|
@ -230,7 +230,7 @@ void TransferListWidget::setRowColor(int row, QColor color) {
|
|||
|
||||
void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
|
||||
Q_ASSERT(row >= 0);
|
||||
const QModelIndex &index = listModel->index(row, 0);
|
||||
const QModelIndex index = listModel->index(row, 0);
|
||||
Q_ASSERT(index.isValid());
|
||||
if(!index.isValid()) return;
|
||||
emit torrentAboutToBeRemoved(index);
|
||||
|
@ -245,7 +245,7 @@ void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
|
|||
}
|
||||
|
||||
void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||||
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)0.0));
|
||||
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)0.0));
|
||||
if(h.is_seed()) {
|
||||
|
@ -284,7 +284,7 @@ void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
|
|||
}
|
||||
|
||||
void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||||
if(!h.is_valid()) return;
|
||||
if(h.is_seed()) {
|
||||
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/stalledUP.png")), Qt::DecorationRole);
|
||||
|
@ -300,7 +300,7 @@ void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
|
|||
}
|
||||
|
||||
void TransferListWidget::updateMetadata(QTorrentHandle &h) {
|
||||
const QString &hash = h.hash();
|
||||
const QString hash = h.hash();
|
||||
const int row = getRowFromHash(hash);
|
||||
if(row != -1) {
|
||||
qDebug("Updating torrent metadata in download list");
|
||||
|
@ -316,8 +316,8 @@ void TransferListWidget::previewFile(QString filePath) {
|
|||
|
||||
int TransferListWidget::updateTorrent(int row) {
|
||||
TorrentState s = STATE_INVALID;
|
||||
const QString &hash = getHashFromRow(row);
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QString hash = getHashFromRow(row);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(!h.is_valid()) {
|
||||
// Torrent will be deleted from list by caller
|
||||
return s;
|
||||
|
@ -554,7 +554,7 @@ void TransferListWidget::refreshList(bool force) {
|
|||
}
|
||||
|
||||
int TransferListWidget::getRowFromHash(QString hash) const{
|
||||
const QList<QStandardItem *> &items = listModel->findItems(hash, Qt::MatchExactly, TR_HASH);
|
||||
const QList<QStandardItem *> items = listModel->findItems(hash, Qt::MatchExactly, TR_HASH);
|
||||
if(items.empty()) return -1;
|
||||
Q_ASSERT(items.size() == 1);
|
||||
return items.first()->row();
|
||||
|
@ -580,7 +580,7 @@ QStringList TransferListWidget::getCustomLabels() const {
|
|||
|
||||
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
||||
const int row = mapToSource(index).row();
|
||||
const QString &hash = getHashFromRow(row);
|
||||
const QString hash = getHashFromRow(row);
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(!h.is_valid()) return;
|
||||
int action;
|
||||
|
@ -612,7 +612,7 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
|||
|
||||
QStringList TransferListWidget::getSelectedTorrentsHashes() const {
|
||||
QStringList hashes;
|
||||
const QModelIndexList &selectedIndexes = selectionModel()->selectedRows();
|
||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
foreach(const QModelIndex &index, selectedIndexes) {
|
||||
hashes << getHashFromRow(mapToSource(index).row());
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ QStringList TransferListWidget::getSelectedTorrentsHashes() const {
|
|||
}
|
||||
|
||||
void TransferListWidget::setSelectedTorrentsLocation() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
if(hashes.isEmpty()) return;
|
||||
QString dir;
|
||||
const QDir saveDir(BTSession->getTorrentHandle(hashes.first()).save_path());
|
||||
|
@ -648,7 +648,7 @@ void TransferListWidget::setSelectedTorrentsLocation() {
|
|||
}
|
||||
|
||||
void TransferListWidget::startSelectedTorrents() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.is_paused()) {
|
||||
|
@ -672,7 +672,7 @@ void TransferListWidget::startAllTorrents() {
|
|||
}
|
||||
|
||||
void TransferListWidget::pauseSelectedTorrents() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && !h.is_paused()) {
|
||||
|
@ -713,7 +713,7 @@ void TransferListWidget::deleteSelectedTorrents() {
|
|||
|
||||
// FIXME: Should work only if the tab is displayed
|
||||
void TransferListWidget::increasePrioSelectedTorrents() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && !h.is_seed()) {
|
||||
|
@ -725,7 +725,7 @@ void TransferListWidget::increasePrioSelectedTorrents() {
|
|||
|
||||
// FIXME: Should work only if the tab is displayed
|
||||
void TransferListWidget::decreasePrioSelectedTorrents() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && !h.is_seed()) {
|
||||
|
@ -736,9 +736,9 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
|
|||
}
|
||||
|
||||
void TransferListWidget::buySelectedTorrents() const {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid())
|
||||
QDesktopServices::openUrl(QUrl("http://match.sharemonkey.com/?info_hash="+h.hash()+"&n="+h.name()+"&cid=33"));
|
||||
}
|
||||
|
@ -746,9 +746,9 @@ void TransferListWidget::buySelectedTorrents() const {
|
|||
|
||||
void TransferListWidget::copySelectedMagnetURIs() const {
|
||||
QStringList magnet_uris;
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata())
|
||||
magnet_uris << misc::toQString(make_magnet_uri(h.get_torrent_info()));
|
||||
}
|
||||
|
@ -761,11 +761,11 @@ void TransferListWidget::hidePriorityColumn(bool hide) {
|
|||
|
||||
void TransferListWidget::openSelectedTorrentsFolder() const {
|
||||
QStringList pathsList;
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
const QString &savePath = h.save_path();
|
||||
const QString savePath = h.save_path();
|
||||
qDebug("Opening path at %s", qPrintable(savePath));
|
||||
if(!pathsList.contains(savePath)) {
|
||||
pathsList.append(savePath);
|
||||
|
@ -780,10 +780,9 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
|
|||
}
|
||||
|
||||
void TransferListWidget::previewSelectedTorrents() {
|
||||
QStringList pathsList;
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
new previewSelect(this, h);
|
||||
}
|
||||
|
@ -794,9 +793,9 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
|
|||
QList<QTorrentHandle> selected_torrents;
|
||||
bool first = true;
|
||||
bool all_same_limit = true;
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && !h.is_seed()) {
|
||||
selected_torrents << h;
|
||||
// Determine current limit for selected torrents
|
||||
|
@ -827,9 +826,9 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
|
|||
QList<QTorrentHandle> selected_torrents;
|
||||
bool first = true;
|
||||
bool all_same_limit = true;
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
selected_torrents << h;
|
||||
// Determine current limit for selected torrents
|
||||
|
@ -857,7 +856,7 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
|
|||
}
|
||||
|
||||
void TransferListWidget::recheckSelectedTorrents() {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
BTSession->recheckTorrent(hash);
|
||||
}
|
||||
|
@ -883,9 +882,9 @@ void TransferListWidget::saveHiddenColumns() const {
|
|||
// load the previous settings, and hide the columns
|
||||
bool TransferListWidget::loadHiddenColumns() {
|
||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
||||
const QString &line = settings.value("TransferListColsHoS", "").toString();
|
||||
const QString line = settings.value("TransferListColsHoS", "").toString();
|
||||
bool loaded = false;
|
||||
const QStringList &ishidden_list = line.split(' ');
|
||||
const QStringList ishidden_list = line.split(' ');
|
||||
const unsigned int nbCol = ishidden_list.size();
|
||||
if(nbCol == (unsigned int)listModel->columnCount()-1) {
|
||||
for(unsigned int i=0; i<nbCol; ++i){
|
||||
|
@ -934,7 +933,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&){
|
|||
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
|
@ -945,7 +944,7 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
|
|||
#endif
|
||||
|
||||
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
||||
const QStringList &hashes = getSelectedTorrentsHashes();
|
||||
const QStringList hashes = getSelectedTorrentsHashes();
|
||||
foreach(const QString &hash, hashes) {
|
||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
|
@ -970,7 +969,7 @@ void TransferListWidget::askNewLabelForSelection() {
|
|||
bool invalid;
|
||||
do {
|
||||
invalid = false;
|
||||
const QString &label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
|
||||
const QString label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
|
||||
if (ok && !label.isEmpty()) {
|
||||
if(misc::isValidFileSystemName(label)) {
|
||||
setSelectionLabel(label);
|
||||
|
@ -983,15 +982,15 @@ void TransferListWidget::askNewLabelForSelection() {
|
|||
}
|
||||
|
||||
void TransferListWidget::renameSelectedTorrent() {
|
||||
const QModelIndexList &selectedIndexes = selectionModel()->selectedRows();
|
||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
if(selectedIndexes.size() != 1) return;
|
||||
if(!selectedIndexes.first().isValid()) return;
|
||||
const QString &hash = getHashFromRow(mapToSource(selectedIndexes.first()).row());
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
const QString hash = getHashFromRow(mapToSource(selectedIndexes.first()).row());
|
||||
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||
if(!h.is_valid()) return;
|
||||
// Ask for a new Name
|
||||
bool ok;
|
||||
const QString &name = QInputDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, h.name(), &ok);
|
||||
const QString name = QInputDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, h.name(), &ok);
|
||||
if (ok && !name.isEmpty()) {
|
||||
// Remember the name
|
||||
TorrentPersistentData::saveName(hash, name);
|
||||
|
@ -1005,7 +1004,7 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
|||
foreach(const QString &hash, hashes) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
const int row = getRowFromHash(hash);
|
||||
const QString &old_label = listModel->data(listModel->index(row, TR_LABEL)).toString();
|
||||
const QString old_label = listModel->data(listModel->index(row, TR_LABEL)).toString();
|
||||
listModel->setData(listModel->index(row, TR_LABEL), QVariant(label));
|
||||
TorrentPersistentData::saveLabel(hash, label);
|
||||
emit torrentChangedLabel(old_label, label);
|
||||
|
@ -1018,7 +1017,7 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
|||
void TransferListWidget::removeLabelFromRows(QString label) {
|
||||
for(int i=0; i<listModel->rowCount(); ++i) {
|
||||
if(listModel->data(listModel->index(i, TR_LABEL)) == label) {
|
||||
const QString &hash = getHashFromRow(i);
|
||||
const QString hash = getHashFromRow(i);
|
||||
listModel->setData(listModel->index(i, TR_LABEL), "", Qt::DisplayRole);
|
||||
TorrentPersistentData::saveLabel(hash, "");
|
||||
emit torrentChangedLabel(label, "");
|
||||
|
@ -1230,7 +1229,7 @@ void TransferListWidget::saveColWidthList() {
|
|||
QStringList new_width_list;
|
||||
const short nbColumns = listModel->columnCount()-1; // HASH is hidden
|
||||
if(nbColumns <= 0) return;
|
||||
const QString &line = settings.value("TransferListColsWidth", QString()).toString();
|
||||
const QString line = settings.value("TransferListColsWidth", QString()).toString();
|
||||
if(!line.isEmpty()) {
|
||||
width_list = line.split(' ');
|
||||
}
|
||||
|
@ -1295,7 +1294,7 @@ bool TransferListWidget::loadColWidthList() {
|
|||
|
||||
void TransferListWidget::saveLastSortedColumn() {
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
const Qt::SortOrder &sortOrder = header()->sortIndicatorOrder();
|
||||
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
|
||||
QString sortOrderLetter;
|
||||
if(sortOrder == Qt::AscendingOrder)
|
||||
sortOrderLetter = QString::fromUtf8("a");
|
||||
|
|
Loading…
Reference in a new issue