diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 41183e478..d52e75e06 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -108,9 +108,9 @@ Bittorrent::Bittorrent() } } // Construct session - s = new session(fingerprint(peer_id.toLocal8Bit().data(), version.at(0), version.at(1), version.at(2), version.at(3)), 0); - std::cout << "Peer ID: " << fingerprint(peer_id.toLocal8Bit().data(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string() << std::endl; - addConsoleMessage("Peer ID: "+misc::toQString(fingerprint(peer_id.toLocal8Bit().data(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string())); + s = new session(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)), 0); + std::cout << "Peer ID: " << fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string() << std::endl; + addConsoleMessage("Peer ID: "+misc::toQString(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string())); // Set severity level of libtorrent session s->set_alert_mask(alert::error_notification | alert::peer_notification | alert::port_mapping_notification | alert::storage_notification | alert::tracker_notification | alert::status_notification | alert::ip_block_notification); @@ -718,7 +718,7 @@ void Bittorrent::banIP(QString ip) { // Delete a torrent from the session, given its hash // 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", hash.toLocal8Bit().data()); + qDebug("Deleting torrent with hash: %s", qPrintable(hash)); const QTorrentHandle &h = getTorrentHandle(hash); if(!h.is_valid()) { qDebug("/!\\ Error: Invalid handle"); @@ -799,7 +799,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { } const QDir &torrentBackup(misc::BTBackupLocation()); if(resumed) { - qDebug("Resuming magnet URI: %s", hash.toLocal8Bit().data()); + qDebug("Resuming magnet URI: %s", qPrintable(hash)); // Load metadata if(QFile::exists(torrentBackup.path()+QDir::separator()+hash+QString(".torrent"))) return addTorrent(torrentBackup.path()+QDir::separator()+hash+QString(".torrent"), false, false, true); @@ -811,7 +811,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { Q_ASSERT(magnet_uri.startsWith("magnet:")); // 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().constData())).is_valid()) { qDebug("/!\\ Torrent is already in download list"); // Update info Bar addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri)); @@ -822,8 +822,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { //Getting fast resume data if existing std::vector buf; if(resumed) { - qDebug("Trying to load fastresume data: %s", (torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data()); - if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data(), buf) == 0) { + qDebug("Trying to load fastresume data: %s", qPrintable(torrentBackup.path()+QDir::separator()+hash+QString(".fastresume"))); + if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().constData(), buf) == 0) { fastResume = true; p.resume_data = &buf; qDebug("Successfuly loaded"); @@ -929,7 +929,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr // 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"; + std::cerr << "Couldn't create the directory: '" << qPrintable(torrentBackup.path()) << "'\n"; exit(1); } } @@ -1030,8 +1030,8 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr //Getting fast resume data if existing std::vector buf; if(resumed) { - qDebug("Trying to load fastresume data: %s", (torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data()); - if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data(), buf) == 0) { + qDebug("Trying to load fastresume data: %s", qPrintable(torrentBackup.path()+QDir::separator()+hash+QString(".fastresume"))); + if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().constData(), buf) == 0) { fastResume = true; p.resume_data = &buf; qDebug("Successfuly loaded"); @@ -1130,7 +1130,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr } // Save save_path if(!defaultTempPath.isEmpty()) { - qDebug("addTorrent: Saving save_path in persistent data: %s", savePath.toLocal8Bit().data()); + qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath)); TorrentPersistentData::saveSavePath(hash, savePath); } #ifdef LIBTORRENT_0_15 @@ -1315,7 +1315,7 @@ void Bittorrent::enableLSD(bool b) { } void Bittorrent::loadSessionState() { - boost::filesystem::ifstream ses_state_file((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data() + boost::filesystem::ifstream ses_state_file((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().constData() , std::ios_base::binary); ses_state_file.unsetf(std::ios_base::skipws); s->load_state(bdecode( @@ -1326,7 +1326,7 @@ void Bittorrent::loadSessionState() { void Bittorrent::saveSessionState() { qDebug("Saving session state to disk..."); entry session_state = s->state(); - boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data() + boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().constData() , std::ios_base::binary); out.unsetf(std::ios_base::skipws); bencode(std::ostream_iterator(out), session_state); @@ -1339,7 +1339,7 @@ bool Bittorrent::enableDHT(bool b) { entry dht_state; const QString &dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); 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().constData(), std::ios_base::binary); dht_state_file.unsetf(std::ios_base::skipws); try{ dht_state = bdecode(std::istream_iterator(dht_state_file), std::istream_iterator()); @@ -1498,7 +1498,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { foreach(const QString &file, pathList) { qDebug("File %s added", qPrintable(file)); try { - torrent_info t(file.toLocal8Bit().data()); + torrent_info t(file.toLocal8Bit().constData()); if(t.is_valid()) addTorrent(file, true); } catch(std::exception&) { @@ -1954,7 +1954,6 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { #endif /*else if (torrent_paused_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - qDebug("Received a torrent_paused_alert for %s", h.hash().toLocal8Bit().data()); if(h.is_valid()) { emit torrentPaused(h); } diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index 3275c5cc2..f65593f26 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -59,7 +59,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) { QVariant redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if(redirection.isValid()) { // We should redirect - qDebug("Redirecting from %s to %s", url.toLocal8Bit().data(), redirection.toUrl().toString().toLocal8Bit().data()); + qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(redirection.toUrl().toString())); redirect_mapping.insert(redirection.toUrl().toString(), url); downloadUrl(redirection.toUrl().toString()); return; @@ -74,7 +74,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) { tmpfile.setAutoRemove(false); if (tmpfile.open()) { filePath = tmpfile.fileName(); - qDebug("Temporary filename is: %s", filePath.toLocal8Bit().data()); + qDebug("Temporary filename is: %s", qPrintable(filePath)); if(reply->open(QIODevice::ReadOnly)) { // TODO: Support GZIP compression tmpfile.write(reply->readAll()); @@ -104,7 +104,7 @@ void downloadThread::downloadUrl(QString url){ // Spoof Firefox 3.5 user agent to avoid // Web server banning request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"); - qDebug("Downloading %s...", request.url().toString().toLocal8Bit().data()); + qDebug("Downloading %s...", qPrintable(request.url().toString())); networkManager->get(request); } @@ -117,7 +117,7 @@ void downloadThread::applyProxySettings() { QString IP = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), "0.0.0.0").toString(); proxy.setHostName(IP); QString port = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), 8080).toString(); - qDebug("Using proxy: %s", (IP+QString(":")+port).toLocal8Bit().data()); + qDebug("Using proxy: %s", qPrintable(IP+QString(":")+port)); proxy.setPort(port.toUShort()); // Default proxy type is HTTP, we must change if it is SOCKS5 if(intValue == SOCKS5 || intValue == SOCKS5_PW) { diff --git a/src/engineselectdlg.cpp b/src/engineselectdlg.cpp index 0cc734c4c..e0a30ae85 100644 --- a/src/engineselectdlg.cpp +++ b/src/engineselectdlg.cpp @@ -81,7 +81,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) { QStringList files=event->mimeData()->text().split(QString::fromUtf8("\n")); QString file; foreach(file, files) { - qDebug("dropped %s", file.toLocal8Bit().data()); + qDebug("dropped %s", qPrintable(file)); file = file.replace("file://", ""); if(file.startsWith("http://", Qt::CaseInsensitive) || file.startsWith("https://", Qt::CaseInsensitive) || file.startsWith("ftp://", Qt::CaseInsensitive)) { downloader->downloadUrl(file); @@ -99,7 +99,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) { void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) { QString mime; foreach(mime, event->mimeData()->formats()){ - qDebug("mimeData: %s", mime.toLocal8Bit().data()); + qDebug("mimeData: %s", qPrintable(mime)); } if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) { event->acceptProposedAction(); @@ -251,12 +251,12 @@ bool engineSelectDlg::isUpdateNeeded(QString plugin_name, float new_version) con } void engineSelectDlg::installPlugin(QString path, QString plugin_name) { - qDebug("Asked to install plugin at %s", path.toLocal8Bit().data()); + qDebug("Asked to install plugin at %s", qPrintable(path)); float new_version = SearchEngine::getPluginVersion(path); qDebug("Version to be installed: %.2f", new_version); if(!isUpdateNeeded(plugin_name, new_version)) { qDebug("Apparently update is not needed, we have a more recent version"); - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("A more recent version of %1 search engine plugin is already installed.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("A more recent version of %1 search engine plugin is already installed.", "%1 is the name of the search engine").arg(plugin_name)); return; } // Process with install @@ -280,12 +280,12 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) { // restore backup QFile::copy(dest_path+".bak", dest_path); QFile::remove(dest_path+".bak"); - QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name)); return; } else { // Remove broken file QFile::remove(dest_path); - QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name)); return; } } @@ -294,10 +294,10 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) { QFile::remove(dest_path+".bak"); } if(update) { - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name)); return; } else { - QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name)); return; } } @@ -390,17 +390,17 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) { plugin_name.chop(1); // remove trailing ':' bool ok; float version = list.last().toFloat(&ok); - qDebug("read line %s: %.2f", plugin_name.toLocal8Bit().data(), version); + qDebug("read line %s: %.2f", qPrintable(plugin_name), version); if(!ok) continue; file_correct = true; if(isUpdateNeeded(plugin_name, version)) { - qDebug("Plugin: %s is outdated", plugin_name.toLocal8Bit().data()); + qDebug("Plugin: %s is outdated", qPrintable(plugin_name)); // Downloading update downloader->downloadUrl(UPDATE_URL+plugin_name+".py"); //downloader->downloadUrl(UPDATE_URL+plugin_name+".png"); updated = true; }else { - qDebug("Plugin: %s is up to date", plugin_name.toLocal8Bit().data()); + qDebug("Plugin: %s is up to date", qPrintable(plugin_name)); } } // Close file @@ -414,7 +414,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) { } void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { - qDebug("engineSelectDlg received %s", url.toLocal8Bit().data()); + qDebug("engineSelectDlg received %s", qPrintable(url)); if(url.endsWith("favicon.ico", Qt::CaseInsensitive)){ // Icon downloaded QImage fileIcon; @@ -456,7 +456,7 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { void engineSelectDlg::handleDownloadFailure(QString url, QString reason) { if(url.endsWith("favicon.ico", Qt::CaseInsensitive)){ - qDebug("Could not download favicon: %s, reason: %s", url.toLocal8Bit().data(), reason.toLocal8Bit().data()); + qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason)); return; } if(url.endsWith("versions.txt")) { @@ -467,6 +467,6 @@ void engineSelectDlg::handleDownloadFailure(QString url, QString reason) { // a plugin update download has been failed QString plugin_name = url.split('/').last(); plugin_name.replace(".py", "", Qt::CaseInsensitive); - QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, %1 search plugin install failed.", "%1 is the name of the search engine").arg(plugin_name.toLocal8Bit().data())); + QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, %1 search plugin install failed.", "%1 is the name of the search engine").arg(plugin_name)); } } diff --git a/src/feeddownloader.h b/src/feeddownloader.h index c179f6a90..9d0d132ee 100644 --- a/src/feeddownloader.h +++ b/src/feeddownloader.h @@ -64,11 +64,9 @@ public: bool matches(QString s) { QStringList match_tokens = getMatchingTokens(); - //qDebug("Checking matching tokens: \"%s\"", getMatchingTokens_str().toLocal8Bit().data()); foreach(const QString& token, match_tokens) { if(token.isEmpty() || token == "") continue; - //qDebug("Token: %s", token.toLocal8Bit().data()); QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard); //reg.setMinimal(false); if(reg.indexIn(s) < 0) return false; @@ -226,7 +224,7 @@ public: void save() { QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QHash all_feeds_filters = qBTRSS.value("feed_filters", QHash()).toHash(); - qDebug("Saving filters for feed: %s (%d filters)", feed_url.toLocal8Bit().data(), (*this).size()); + qDebug("Saving filters for feed: %s (%d filters)", qPrintable(feed_url), (*this).size()); all_feeds_filters[feed_url] = *this; qBTRSS.setValue("feed_filters", all_feeds_filters); } diff --git a/src/filesystemwatcher.h b/src/filesystemwatcher.h index 8257b4aca..21e004b45 100644 --- a/src/filesystemwatcher.h +++ b/src/filesystemwatcher.h @@ -49,10 +49,10 @@ protected: file += QDir::separator(); file += "."; struct statfs buf; - if(!statfs(file.toLocal8Bit().data(), &buf)) { + if(!statfs(file.toLocal8Bit().constData(), &buf)) { return (buf.f_type == (long)CIFS_MAGIC_NUMBER || buf.f_type == (long)NFS_SUPER_MAGIC); } else { - std::cerr << "Error: statfs() call failed for " << file.toLocal8Bit().data() << ". Supposing it is a local folder..." << std::endl; + std::cerr << "Error: statfs() call failed for " << qPrintable(file) << ". Supposing it is a local folder..." << std::endl; switch(errno) { case EACCES: std::cerr << "Search permission is denied for a component of the path prefix of the path" << std::endl; @@ -148,7 +148,7 @@ public: } else { #endif // Normal mode - qDebug("FS Watching is watching %s in normal mode", path.toLocal8Bit().data()); + qDebug("FS Watching is watching %s in normal mode", qPrintable(path)); QFileSystemWatcher::addPath(path); scanLocalFolder(path); #ifndef Q_WS_WIN @@ -190,7 +190,7 @@ protected slots: QStringList torrents; // Network folders scan foreach (const QDir &dir, watched_folders) { - qDebug("FSWatcher: Polling manually folder %s", qPrintable(dir.path())); + //qDebug("FSWatcher: Polling manually folder %s", qPrintable(dir.path())); addTorrentsFromDir(dir, torrents); } // Report detected torrent files diff --git a/src/geoip.h b/src/geoip.h index 1f94c75d3..da2e3e65f 100644 --- a/src/geoip.h +++ b/src/geoip.h @@ -86,9 +86,9 @@ public: exportEmbeddedDb(); #endif if(QFile::exists(geoipDBpath(false))) { - qDebug("Loading GeoIP database from %s...", geoipDBpath(false).toLocal8Bit().data()); - if(!s->load_country_db(geoipDBpath(false).toLocal8Bit().data())) { - std::cerr << "Failed to load Geoip Database at " << geoipDBpath(false).toLocal8Bit().data() << std::endl; + qDebug("Loading GeoIP database from %s...", qPrintable(geoipDBpath(false))); + if(!s->load_country_db(geoipDBpath(false).toLocal8Bit().constData())) { + std::cerr << "Failed to load Geoip Database at " << qPrintable(geoipDBpath(false)) << std::endl; } } else { qDebug("ERROR: Impossible to find local Geoip Database"); diff --git a/src/headlessloader.h b/src/headlessloader.h index 7c83d2b56..29101998c 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -41,97 +41,98 @@ class HeadlessLoader: QObject { Q_OBJECT - private: - QLocalServer *localServer; - Bittorrent *BTSession; - - public: - HeadlessLoader(QStringList torrentCmdLine) { - // Enable Web UI - Preferences::setWebUiEnabled(true); - // Instanciate Bittorrent Object - BTSession = new Bittorrent(); - connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); - // Resume unfinished torrents - BTSession->startUpTorrents(); - // Process command line parameters - processParams(torrentCmdLine); - // Use a tcp server to allow only one instance of qBittorrent - localServer = new QLocalServer(); - QString uid = QString::number(getuid()); +public: + HeadlessLoader(QStringList torrentCmdLine) { + // Enable Web UI + Preferences::setWebUiEnabled(true); + // Instanciate Bittorrent Object + BTSession = new Bittorrent(); + connect(BTSession, SIGNAL(newConsoleMessage(QString)), this, SLOT(displayConsoleMessage(QString))); + // Resume unfinished torrents + BTSession->startUpTorrents(); + // Process command line parameters + processParams(torrentCmdLine); + // Use a tcp server to allow only one instance of qBittorrent + localServer = new QLocalServer(); + const QString &uid = QString::number(getuid()); #ifdef Q_WS_X11 - if(QFile::exists(QDir::tempPath()+QDir::separator()+QString("qBittorrent-")+uid)) { - // Socket was not closed cleanly - std::cerr << "Warning: Local domain socket was not closed cleanly, deleting file...\n"; - QFile::remove(QDir::tempPath()+QDir::separator()+QString("qBittorrent-")+uid); - } + if(QFile::exists(QDir::tempPath()+QDir::separator()+QString("qBittorrent-")+uid)) { + // Socket was not closed cleanly + std::cerr << "Warning: Local domain socket was not closed cleanly, deleting file..." << std::endl; + QFile::remove(QDir::tempPath()+QDir::separator()+QString("qBittorrent-")+uid); + } #endif - if (!localServer->listen("qBittorrent-"+uid)) { - std::cerr << "Couldn't create socket, single instance mode won't work...\n"; - } - connect(localServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); - // Display some information to the user - std::cout << std::endl << "******** " << tr("Information").toLocal8Bit().data() << " ********" << std::endl; - std::cout << tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(Preferences::getWebUiPort())).toLocal8Bit().data() << std::endl; - std::cout << tr("The Web UI administrator user name is: %1").arg(Preferences::getWebUiUsername()).toLocal8Bit().data() << std::endl; - if(Preferences::getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { - std::cout << tr("The Web UI administrator password is still the default one: %1").arg("adminadmin").toLocal8Bit().data() << std::endl; - std::cout << tr("This is a security risk, please consider changing your password from program preferences.").toLocal8Bit().data() << std::endl; - } + if (!localServer->listen("qBittorrent-"+uid)) { + std::cerr << "Couldn't create socket, single instance mode won't work..." << std::endl; } - - ~HeadlessLoader() { - delete BTSession; + connect(localServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); + // Display some information to the user + std::cout << std::endl << "******** " << qPrintable(tr("Information")) << " ********" << std::endl; + std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(Preferences::getWebUiPort()))) << std::endl; + std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(Preferences::getWebUiUsername())) << std::endl; + if(Preferences::getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { + std::cout << qPrintable(tr("The Web UI administrator password is still the default one: %1").arg("adminadmin")) << std::endl; + std::cout << qPrintable(tr("This is a security risk, please consider changing your password from program preferences.")) << std::endl; } + } - public slots: - // Call this function to exit qBittorrent headless loader - // and return to prompt (object will be deleted by main) - void exit() { - qApp->quit(); - } + ~HeadlessLoader() { + delete localServer; + delete BTSession; + } - void displayConsoleMessage(QString msg) { - std::cout << msg.toLocal8Bit().data() << std::endl; - } +public slots: + // Call this function to exit qBittorrent headless loader + // and return to prompt (object will be deleted by main) + void exit() { + qApp->quit(); + } + + void displayConsoleMessage(QString msg) { + std::cout << qPrintable(msg) << std::endl; + } - // As program parameters, we can get paths or urls. - // This function parse the parameters and call - // the right addTorrent function, considering - // the parameter type. - void processParams(const QStringList& params) { - foreach(QString param, params) { - param = param.trimmed(); - if(param.startsWith("--")) continue; - if(param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) { - BTSession->downloadFromUrl(param); - }else{ - if(param.startsWith("magnet:", Qt::CaseInsensitive)) { - BTSession->addMagnetUri(param); - } else { - BTSession->addTorrent(param); - } + // As program parameters, we can get paths or urls. + // This function parse the parameters and call + // the right addTorrent function, considering + // the parameter type. + void processParams(const QStringList& params) { + foreach(QString param, params) { + param = param.trimmed(); + if(param.startsWith("--")) continue; + if(param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) { + BTSession->downloadFromUrl(param); + }else{ + if(param.startsWith("magnet:", Qt::CaseInsensitive)) { + BTSession->addMagnetUri(param); + } else { + BTSession->addTorrent(param); } } } + } - void acceptConnection() { - QLocalSocket *clientConnection = localServer->nextPendingConnection(); - connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket())); - qDebug("accepted connection from another instance"); - } + void acceptConnection() { + QLocalSocket *clientConnection = localServer->nextPendingConnection(); + connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket())); + qDebug("accepted connection from another instance"); + } - void readParamsOnSocket() { - QLocalSocket *clientConnection = static_cast(sender()); - if(clientConnection) { - QByteArray params = clientConnection->readAll(); - if(!params.isEmpty()) { - processParams(QString::fromUtf8(params.data()).split(QString::fromUtf8("\n"))); - qDebug("Received parameters from another instance"); - } - clientConnection->deleteLater(); + void readParamsOnSocket() { + QLocalSocket *clientConnection = static_cast(sender()); + if(clientConnection) { + const QByteArray ¶ms = clientConnection->readAll(); + if(!params.isEmpty()) { + processParams(QString(params).split("\n")); + qDebug("Received parameters from another instance"); } + clientConnection->deleteLater(); } + } + +private: + QLocalServer *localServer; + Bittorrent *BTSession; }; diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index 4a69244de..8d37d419e 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -117,7 +117,7 @@ QString HttpConnection::translateDocument(QString data) { QString translation = word; int context_index= 0; do { - translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1); + translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1); ++context_index; }while(translation == word && context_index < 12); //qDebug("Translation is %s", translation.toUtf8().data()); @@ -139,11 +139,11 @@ void HttpConnection::respond() { return; } QString auth = parser.value("Authorization"); - qDebug("Auth: %s", auth.split(" ").first().toLocal8Bit().data()); + qDebug("Auth: %s", qPrintable(auth.split(" ").first())); if (QString::compare(auth.split(" ").first(), "Digest", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth.toLocal8Bit(), parser.method())) { // Update failed attempt counter parent->client_failed_attempts.insert(socket->peerAddress().toString(), nb_fail+1); - qDebug("client IP: %s (%d failed attempts)", socket->peerAddress().toString().toLocal8Bit().data(), nb_fail); + qDebug("client IP: %s (%d failed attempts)", qPrintable(socket->peerAddress().toString()), nb_fail); // Return unauthorized header generator.setStatusLine(401, "Unauthorized"); generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", algorithm=\"MD5\", qop=\"auth\""); @@ -225,7 +225,6 @@ void HttpConnection::respond() { else list.prepend("webui"); url = ":/" + list.join("/"); - //qDebug("Resource URL: %s", url.toLocal8Bit().data()); QFile file(url); if(!file.open(QIODevice::ReadOnly)) { @@ -261,7 +260,6 @@ void HttpConnection::respondJson() QString string = json::toJson(manager->getEventList()); generator.setStatusLine(200, "OK"); generator.setContentTypeByExt("js"); - //qDebug("JSON: %s", string.toLocal8Bit().data()); generator.setMessage(string); write(); } @@ -290,7 +288,6 @@ void HttpConnection::respondFilesPropertiesJson(QString hash) { generator.setStatusLine(200, "OK"); generator.setContentTypeByExt("js"); generator.setMessage(string); - //qDebug("JSON: %s", string.toLocal8Bit().data()); write(); } @@ -391,7 +388,6 @@ void HttpConnection::respondCommand(QString command) } if(command == "setPreferences") { QString json_str = parser.post("json"); - //qDebug("setPreferences, json: %s", json_str.toLocal8Bit().data()); EventManager* manager = parent->eventManager(); manager->setGlobalPreferences(json::fromJson(json_str)); } diff --git a/src/main.cpp b/src/main.cpp index 2f0f064e1..dc2dc1ca3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,7 +73,7 @@ class UsageDisplay: public QObject { public: static void displayUsage(char* prg_name) { - std::cout << tr("Usage:").toLocal8Bit().data() << std::endl; + std::cout << qPrintable(tr("Usage:")) << std::endl; std::cout << '\t' << prg_name << " --version: " << qPrintable(tr("displays program version")) << std::endl; #ifndef DISABLE_GUI std::cout << '\t' << prg_name << " --no-splash: " << qPrintable(tr("disable splash screen")) << std::endl; diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 9dde6edd5..3509333a7 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -548,7 +548,7 @@ void QTorrentHandle::set_sequential_download(bool b) { void QTorrentHandle::set_tracker_login(QString username, QString password) { Q_ASSERT(h.is_valid()); - h.set_tracker_login(std::string(username.toLocal8Bit().data()), std::string(password.toLocal8Bit().data())); + h.set_tracker_login(std::string(username.toLocal8Bit().constData()), std::string(password.toLocal8Bit().constData())); } void QTorrentHandle::force_recheck() const { @@ -558,7 +558,7 @@ void QTorrentHandle::force_recheck() const { void QTorrentHandle::move_storage(QString new_path) const { Q_ASSERT(h.is_valid()); - h.move_storage(new_path.toLocal8Bit().data()); + h.move_storage(new_path.toLocal8Bit().constData()); } void QTorrentHandle::file_priority(int index, int priority) const { @@ -606,7 +606,7 @@ bool QTorrentHandle::save_torrent_file(QString path) { torrent_file["info"] = meta; if(!h.trackers().empty()) torrent_file["announce"] = h.trackers().front().url; - boost::filesystem::ofstream out(path.toLocal8Bit().data(), std::ios_base::binary); + boost::filesystem::ofstream out(path.toLocal8Bit().constData(), std::ios_base::binary); out.unsetf(std::ios_base::skipws); bencode(std::ostream_iterator(out), torrent_file); return true; @@ -676,7 +676,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) { } void QTorrentHandle::rename_file(int index, QString name) { - h.rename_file(index, std::string(name.toLocal8Bit().data())); + h.rename_file(index, std::string(name.toLocal8Bit().constData())); } // diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index fe830654a..00d2be2a0 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -90,8 +90,8 @@ void RSSImp::displayItemsListMenu(const QPoint&){ if(selectedItems.size() > 0) { bool has_attachment = false; foreach(QTreeWidgetItem *item, selectedItems) { - qDebug("text(3) URL: %s", item->text(NEWS_URL_COL).toLocal8Bit().data()); - qDebug("text(2) TITLE: %s", item->text(NEWS_TITLE_COL).toLocal8Bit().data()); + qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL))); + qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL))); if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_TITLE_COL))->has_attachment()) { has_attachment = true; break; @@ -254,7 +254,7 @@ void RSSImp::loadFoldersOpenState() { if(listStreams->getRSSItem(child)->getID() == name) { parent = child; parent->setExpanded(true); - qDebug("expanding folder %s", name.toLocal8Bit().data()); + qDebug("expanding folder %s", qPrintable(name)); break; } } @@ -267,7 +267,7 @@ void RSSImp::saveFoldersOpenState() { QList items = listStreams->getAllOpenFolders(); foreach(QTreeWidgetItem* item, items) { QString path = listStreams->getItemPath(item).join("\\"); - qDebug("saving open folder: %s", path.toLocal8Bit().data()); + qDebug("saving open folder: %s", qPrintable(path)); open_folders << path; } QSettings settings("qBittorrent", "qBittorrent"); diff --git a/src/searchengine.cpp b/src/searchengine.cpp index 650b3cc96..47470f965 100644 --- a/src/searchengine.cpp +++ b/src/searchengine.cpp @@ -96,7 +96,7 @@ void SearchEngine::fillCatCombobox() { comboCategory->addItem(full_cat_names["all"], QVariant("all")); QStringList supported_cat = supported_engines->supportedCategories(); foreach(QString cat, supported_cat) { - qDebug("Supported category: %s", cat.toLocal8Bit().data()); + qDebug("Supported category: %s", qPrintable(cat)); comboCategory->addItem(full_cat_names[cat], QVariant(cat)); } } @@ -254,7 +254,7 @@ void SearchEngine::on_search_button_clicked(){ search_stopped = false; params << misc::searchEngineLocation()+QDir::separator()+"nova2.py"; params << supported_engines->enginesEnabled().join(","); - qDebug("Search with category: %s", selectedCategory().toLocal8Bit().data()); + qDebug("Search with category: %s", qPrintable(selectedCategory())); params << selectedCategory(); params << pattern.split(" "); // Update SearchEngine widgets @@ -433,12 +433,12 @@ void SearchEngine::updateNova() { // Copy python classes if(file.endsWith(".py")) { if(getPluginVersion(shipped_file) > getPluginVersion(destDir+file) ) { - qDebug("shippped %s is more recent then local plugin, updating", file.toLocal8Bit().data()); + qDebug("shippped %s is more recent then local plugin, updating", qPrintable(file)); if(QFile::exists(destDir+file)) { - qDebug("Removing old %s", (destDir+file).toLocal8Bit().data()); + qDebug("Removing old %s", qPrintable(destDir+file)); QFile::remove(destDir+file); } - qDebug("%s copied to %s", shipped_file.toLocal8Bit().data(), (destDir+file).toLocal8Bit().data()); + qDebug("%s copied to %s", qPrintable(shipped_file), qPrintable(destDir+file)); QFile::copy(shipped_file, destDir+file); } } else { diff --git a/src/searchengine.h b/src/searchengine.h index 9da9d8bcc..c8343e5b4 100644 --- a/src/searchengine.h +++ b/src/searchengine.h @@ -79,7 +79,7 @@ public: static float getPluginVersion(QString filePath) { QFile plugin(filePath); if(!plugin.exists()){ - qDebug("%s plugin does not exist, returning 0.0", filePath.toLocal8Bit().data()); + qDebug("%s plugin does not exist, returning 0.0", qPrintable(filePath)); return 0.0; } if(!plugin.open(QIODevice::ReadOnly | QIODevice::Text)){ @@ -91,7 +91,7 @@ public: if(line.startsWith("#VERSION: ")){ line = line.split(' ').last().trimmed(); version = line.toFloat(); - qDebug("plugin %s version: %.2f", filePath.toLocal8Bit().data(), version); + qDebug("plugin %s version: %.2f", qPrintable(filePath), version); break; } } diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index fd7f04e08..bf56bb942 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -114,7 +114,7 @@ public: resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize()); move(settings.value(QString::fromUtf8("TorrentAdditionDlg/pos"), misc::screenCenter(this)).toPoint()); // Restore column width - QVariantList contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariantList()).toList(); + const QVariantList &contentColsWidths = settings.value(QString::fromUtf8("TorrentAdditionDlg/filesColsWidth"), QVariantList()).toList(); if(contentColsWidths.empty()) { torrentContentList->header()->resizeSection(0, 200); } else { @@ -175,7 +175,7 @@ public: resize(width(), height()-hidden_height); } - void showLoad(QString filePath, QString from_url=QString::null){ + void showLoad(QString filePath, QString from_url=QString::null) { is_magnet = false; if(!QFile::exists(filePath)) { close(); @@ -222,7 +222,7 @@ public: // Load custom labels QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.beginGroup(QString::fromUtf8("TransferListFilters")); - 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); @@ -239,7 +239,7 @@ public slots: void displayContentListMenu(const QPoint&) { QMenu myFilesLlistMenu; - QModelIndexList selectedRows = torrentContentList->selectionModel()->selectedRows(0); + const QModelIndexList &selectedRows = torrentContentList->selectionModel()->selectedRows(0); QAction *actRename = 0; if(selectedRows.size() == 1) { actRename = myFilesLlistMenu.addAction(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename...")); @@ -266,7 +266,7 @@ public slots: } } qDebug("Setting files priority"); - foreach(QModelIndex index, selectedRows) { + foreach(const QModelIndex &index, selectedRows) { qDebug("Setting priority(%d) for file at row %d", prio, index.row()); PropListModel->setData(PropListModel->index(index.row(), PRIORITY, index.parent()), prio); } @@ -275,12 +275,12 @@ public slots: } void renameSelectedFile() { - QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedRows(0); + const QModelIndexList &selectedIndexes = torrentContentList->selectionModel()->selectedRows(0); Q_ASSERT(selectedIndexes.size() == 1); - 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"), + 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()) { @@ -292,12 +292,12 @@ public slots: } if(PropListModel->getType(index)==TFILE) { // File renaming - uint file_index = PropListModel->getFileIndex(index); - QString old_name = files_path.at(file_index); + const uint file_index = PropListModel->getFileIndex(index); + const QString &old_name = files_path.at(file_index); QStringList path_items = old_name.split(QDir::separator()); path_items.removeLast(); path_items << new_name_last; - QString new_name = path_items.join(QDir::separator()); + const QString &new_name = path_items.join(QDir::separator()); if(old_name == new_name) { qDebug("Name did not change"); return; @@ -317,7 +317,7 @@ public slots: return; } } - qDebug("Renaming %s to %s", old_name.toLocal8Bit().data(), new_name.toLocal8Bit().data()); + qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name)); // Rename file in files_path files_path.replace(file_index, new_name); // Rename in torrent files model too @@ -331,14 +331,14 @@ public slots: path_items.prepend(parent.data().toString()); parent = PropListModel->parent(parent); } - QString old_path = path_items.join(QDir::separator()); + const QString &old_path = path_items.join(QDir::separator()); path_items.removeLast(); path_items << new_name_last; QString new_path = path_items.join(QDir::separator()); if(!new_path.endsWith(QDir::separator())) new_path += QDir::separator(); // Check for overwriting for(uint i=0; itext())); + const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->text())); lbl_disk_space->setText(misc::friendlyUnit(available)); if(!is_magnet) { // Determine torrent size qulonglong torrent_size = 0; - unsigned int nbFiles = t->num_files(); - std::vector priorities = PropListModel->getFilesPriorities(nbFiles); + const unsigned int nbFiles = t->num_files(); + const std::vector &priorities = PropListModel->getFilesPriorities(nbFiles); for(unsigned int i=0; i 0) @@ -400,8 +400,8 @@ public slots: void on_browseButton_clicked(){ QString dir; - QString save_path = misc::expandPath(savePathTxt->text()); - QDir saveDir(save_path); + const QString &save_path = misc::expandPath(savePathTxt->text()); + const QDir &saveDir(save_path); if(!save_path.isEmpty() && saveDir.exists()){ dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath()); }else{ @@ -422,7 +422,7 @@ public slots: void savePiecesPriorities(){ qDebug("Saving pieces priorities"); - std::vector priorities = PropListModel->getFilesPriorities(t->num_files()); + const std::vector &priorities = PropListModel->getFilesPriorities(t->num_files()); TorrentTempData::setFilesPriority(hash, priorities); } @@ -439,14 +439,14 @@ public slots: return; } } - QString current_label = comboLabel->currentText().trimmed(); + const QString ¤t_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; } // Save savepath TorrentTempData::setSavePath(hash, savePath.path()); - qDebug("Torrent label is: %s", comboLabel->currentText().trimmed().toLocal8Bit().data()); + qDebug("Torrent label is: %s", qPrintable(comboLabel->currentText().trimmed())); if(!current_label.isEmpty()) TorrentTempData::setLabel(hash, current_label); // Is download sequential? diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index b4ce5084a..7ce238333 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -65,8 +65,8 @@ public: if(name.endsWith(".!qB")) name.chop(4); itemData << name; - qDebug("Created a TreeItem file with name %s", getName().toLocal8Bit().data()); - qDebug("parent is %s", parent->getName().toLocal8Bit().data()); + qDebug("Created a TreeItem file with name %s", qPrintable(getName())); + qDebug("parent is %s", qPrintable(parent->getName())); itemData << QVariant((qulonglong)f.size); total_done = 0; itemData << 0.; // Progress; @@ -102,7 +102,7 @@ public: } ~TreeItem() { - qDebug("Deleting item: %s", getName().toLocal8Bit().data()); + qDebug("Deleting item: %s", qPrintable(getName())); qDeleteAll(childItems); } @@ -168,7 +168,6 @@ public: else progress = 1.; Q_ASSERT(progress >= 0. && progress <= 1.); - //qDebug("setProgress(%s): %f", getName().toLocal8Bit().data(), progress); itemData.replace(2, progress); if(parentItem) parentItem->updateProgress(); @@ -189,7 +188,6 @@ public: if(type == ROOT) return; Q_ASSERT(type == FOLDER); total_done = 0; - //qDebug("Folder %s is updating its progress", getName().toLocal8Bit().data()); foreach(TreeItem* child, childItems) { if(child->getPriority() > 0) total_done += child->getTotalDone(); diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index f6f5e1bbf..b3e4cd194 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -63,11 +63,11 @@ public: } } - static void setFilesPriority(QString hash, std::vector pp) { + static void setFilesPriority(QString hash, const std::vector &pp) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents-tmp", QHash()).toHash(); QHash data = all_data[hash].toHash(); - std::vector::iterator pp_it = pp.begin(); + std::vector::const_iterator pp_it = pp.begin(); QVariantList pieces_priority; while(pp_it != pp.end()) { pieces_priority << *pp_it; @@ -78,7 +78,7 @@ public: settings.setValue("torrents-tmp", all_data); } - static void setFilesPath(QString hash, QStringList path_list) { + static void setFilesPath(QString hash, const QStringList &path_list) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents-tmp", QHash()).toHash(); QHash data = all_data[hash].toHash(); @@ -225,7 +225,7 @@ public: return dt; } - static void saveSeedDate(QTorrentHandle h) { + static void saveSeedDate(const QTorrentHandle &h) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); QHash data = all_data[h.hash()].toHash(); @@ -253,7 +253,7 @@ public: } } - static void saveTorrentPersistentData(QTorrentHandle h, bool is_magnet = false) { + static void saveTorrentPersistentData(const QTorrentHandle &h, bool is_magnet = false) { Q_ASSERT(h.is_valid()); qDebug("Saving persistent data for %s", h.hash().toLocal8Bit().data()); // First, remove temp data @@ -311,7 +311,7 @@ public: settings.setValue("torrents", all_data); } - static void savePriority(QTorrentHandle h) { + static void savePriority(const QTorrentHandle &h) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); QHash data = all_data[h.hash()].toHash(); @@ -320,7 +320,7 @@ public: settings.setValue("torrents", all_data); } - static void saveSeedStatus(QTorrentHandle h) { + static void saveSeedStatus(const QTorrentHandle &h) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); QHash data = all_data[h.hash()].toHash(); diff --git a/src/transferlistfilterswidget.h b/src/transferlistfilterswidget.h index bfa66eaf3..978230513 100644 --- a/src/transferlistfilterswidget.h +++ b/src/transferlistfilterswidget.h @@ -73,7 +73,7 @@ public: QString labelFromRow(int row) const { Q_ASSERT(row > 1); - QString label = item(row)->text(); + const QString &label = item(row)->text(); QStringList parts = label.split(" "); Q_ASSERT(parts.size() >= 2); parts.removeLast(); // Remove trailing number @@ -93,9 +93,7 @@ signals: protected: void dragMoveEvent(QDragMoveEvent *event) { - //qDebug("filters, dragmoveevent"); if(itemAt(event->pos()) && row(itemAt(event->pos())) > 0) { - //qDebug("Name: %s", itemAt(event->pos())->text().toLocal8Bit().data()); if(itemHover) { if(itemHover != itemAt(event->pos())) { setItemHover(false); @@ -249,7 +247,7 @@ public: QStringList label_list = settings.value("customLabels", QStringList()).toStringList(); foreach(const QString &label, label_list) { customLabels.insert(label, 0); - qDebug("Creating label QListWidgetItem: %s", label.toLocal8Bit().data()); + qDebug("Creating label QListWidgetItem: %s", qPrintable(label)); QListWidgetItem *newLabel = new QListWidgetItem(); newLabel->setText(label + " (0)"); newLabel->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder.png")); @@ -321,9 +319,9 @@ protected slots: } void removeSelectedLabel() { - int row = labelFilters->row(labelFilters->selectedItems().first()); + const int row = labelFilters->row(labelFilters->selectedItems().first()); Q_ASSERT(row > 1); - QString label = labelFilters->labelFromRow(row); + const QString &label = labelFilters->labelFromRow(row); Q_ASSERT(customLabels.contains(label)); customLabels.remove(label); transferList->removeLabelFromRows(label); @@ -351,13 +349,13 @@ protected slots: } void torrentChangedLabel(QString old_label, QString new_label) { - qDebug("Torrent label changed from %s to %s", old_label.toLocal8Bit().data(), new_label.toLocal8Bit().data()); + qDebug("Torrent label changed from %s to %s", qPrintable(old_label), qPrintable(new_label)); if(!old_label.isEmpty()) { if(customLabels.contains(old_label)) { - int new_count = customLabels.value(old_label, 0) - 1; + const int new_count = customLabels.value(old_label, 0) - 1; Q_ASSERT(new_count >= 0); customLabels.insert(old_label, new_count); - int row = labelFilters->rowFromLabel(old_label); + const int row = labelFilters->rowFromLabel(old_label); Q_ASSERT(row >= 2); labelFilters->item(row)->setText(old_label + " ("+ QString::number(new_count) +")"); } @@ -366,10 +364,10 @@ protected slots: if(!new_label.isEmpty()) { if(!customLabels.contains(new_label)) addLabel(new_label); - int new_count = customLabels.value(new_label, 0) + 1; + const int new_count = customLabels.value(new_label, 0) + 1; Q_ASSERT(new_count >= 1); customLabels.insert(new_label, new_count); - int row = labelFilters->rowFromLabel(new_label); + const int row = labelFilters->rowFromLabel(new_label); Q_ASSERT(row >= 2); labelFilters->item(row)->setText(new_label + " ("+ QString::number(new_count) +")"); ++nb_labeled; @@ -380,17 +378,17 @@ protected slots: void torrentAdded(QModelIndex index) { Q_ASSERT(index.isValid()); if(!index.isValid()) return; - QString label = transferList->getSourceModel()->index(index.row(), TR_LABEL).data(Qt::DisplayRole).toString().trimmed(); - qDebug("New torrent was added with label: %s", label.toLocal8Bit().data()); + const QString &label = transferList->getSourceModel()->index(index.row(), TR_LABEL).data(Qt::DisplayRole).toString().trimmed(); + qDebug("New torrent was added with label: %s", qPrintable(label)); if(!label.isEmpty()) { if(!customLabels.contains(label)) { addLabel(label); } // Update label counter Q_ASSERT(customLabels.contains(label)); - int new_count = customLabels.value(label, 0) + 1; + const int new_count = customLabels.value(label, 0) + 1; customLabels.insert(label, new_count); - int row = labelFilters->rowFromLabel(label); + const int row = labelFilters->rowFromLabel(label); qDebug("torrentAdded, Row: %d", row); Q_ASSERT(row >= 2); Q_ASSERT(labelFilters->item(row)); @@ -410,9 +408,9 @@ protected slots: QString label = transferList->getSourceModel()->index(index.row(), TR_LABEL).data(Qt::DisplayRole).toString().trimmed(); if(!label.isEmpty()) { // Update label counter - int new_count = customLabels.value(label, 0) - 1; + const int new_count = customLabels.value(label, 0) - 1; customLabels.insert(label, new_count); - int row = labelFilters->rowFromLabel(label); + const int row = labelFilters->rowFromLabel(label); Q_ASSERT(row >= 2); labelFilters->item(row)->setText(label + " ("+ QString::number(new_count) +")"); --nb_labeled; diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index da0491c72..bb1fcff31 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -765,7 +765,7 @@ void TransferListWidget::setDlLimitSelectedTorrents() { const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::getGlobalDownloadLimit()*1024.); if(ok) { foreach(const QTorrentHandle &h, selected_torrents) { - qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().constData()); + qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash())); BTSession->setDownloadLimit(h.hash(), new_limit); } } @@ -798,7 +798,7 @@ void TransferListWidget::setUpLimitSelectedTorrents() { const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::getGlobalUploadLimit()*1024.); if(ok) { foreach(const QTorrentHandle &h, selected_torrents) { - qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().constData()); + qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash())); BTSession->setUploadLimit(h.hash(), new_limit); } } @@ -1296,7 +1296,7 @@ void TransferListWidget::applyLabelFilter(QString label) { labelFilterModel->setFilterRegExp(QRegExp("^$")); return; } - qDebug("Applying Label filter: %s", label.toLocal8Bit().data()); + qDebug("Applying Label filter: %s", qPrintable(label)); labelFilterModel->setFilterRegExp(QRegExp("^"+label+"$", Qt::CaseSensitive)); }