From fa2128cbae6cf4dbc5f33251eb96a00d5ef00133 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 7 Mar 2017 19:41:38 +0800 Subject: [PATCH] Replace Utils::String::fromStdString() by QString::fromStdString() --- src/base/bittorrent/magneturi.cpp | 4 +-- src/base/bittorrent/peerinfo.cpp | 2 +- src/base/bittorrent/session.cpp | 26 +++++++++--------- src/base/bittorrent/torrentcreatorthread.cpp | 4 +-- src/base/bittorrent/torrenthandle.cpp | 28 ++++++++++---------- src/base/bittorrent/torrentinfo.cpp | 10 +++---- src/base/bittorrent/trackerentry.cpp | 2 +- src/base/utils/string.cpp | 5 ---- src/base/utils/string.h | 1 - 9 files changed, 38 insertions(+), 44 deletions(-) diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index cad119c77..a3a7c8325 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -80,10 +80,10 @@ MagnetUri::MagnetUri(const QString &source) m_valid = true; m_hash = m_addTorrentParams.info_hash; - m_name = Utils::String::fromStdString(m_addTorrentParams.name); + m_name = QString::fromStdString(m_addTorrentParams.name); foreach (const std::string &tracker, m_addTorrentParams.trackers) - m_trackers.append(Utils::String::fromStdString(tracker)); + m_trackers.append(QString::fromStdString(tracker)); foreach (const std::string &urlSeed, m_addTorrentParams.url_seeds) m_urlSeeds.append(QUrl(urlSeed.c_str())); diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 4ea3f9f10..29c7686e7 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -198,7 +198,7 @@ PeerAddress PeerInfo::address() const QString PeerInfo::client() const { - return Utils::String::fromStdString(m_nativeInfo.client); + return QString::fromStdString(m_nativeInfo.client); } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 43dc66fe5..4e2756d8a 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -367,7 +367,7 @@ Session::Session(QObject *parent) m_nativeSession->add_extension(&libt::create_ut_pex_plugin); m_nativeSession->add_extension(&libt::create_smart_ban_plugin); - logger->addMessage(tr("Peer ID: ") + Utils::String::fromStdString(peerId)); + logger->addMessage(tr("Peer ID: ") + QString::fromStdString(peerId)); logger->addMessage(tr("HTTP User-Agent is '%1'").arg(USER_AGENT)); logger->addMessage(tr("DHT support [%1]").arg(isDHTEnabled() ? tr("ON") : tr("OFF")), Log::INFO); logger->addMessage(tr("Local Peer Discovery support [%1]").arg(isLSDEnabled() ? tr("ON") : tr("OFF")), Log::INFO); @@ -3265,7 +3265,7 @@ void Session::handleAlert(libt::alert *a) } } catch (std::exception &exc) { - qWarning() << "Caught exception in " << Q_FUNC_INFO << ": " << Utils::String::fromStdString(exc.what()); + qWarning() << "Caught exception in " << Q_FUNC_INFO << ": " << QString::fromStdString(exc.what()); } } @@ -3347,7 +3347,7 @@ void Session::handleAddTorrentAlert(libt::add_torrent_alert *p) { if (p->error) { qDebug("/!\\ Error: Failed to add torrent!"); - QString msg = Utils::String::fromStdString(p->message()); + QString msg = QString::fromStdString(p->message()); Logger::instance()->addMessage(tr("Couldn't add torrent. Reason: %1").arg(msg), Log::WARNING); emit addTorrentFailed(msg); } @@ -3395,7 +3395,7 @@ void Session::handleFileErrorAlert(libt::file_error_alert *p) // NOTE: Check this function! TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash()); if (torrent) { - QString msg = Utils::String::fromStdString(p->message()); + QString msg = QString::fromStdString(p->message()); Logger::instance()->addMessage(tr("An I/O error occurred, '%1' paused. %2") .arg(torrent->name()).arg(msg)); emit fullDiskError(torrent, msg); @@ -3404,13 +3404,13 @@ void Session::handleFileErrorAlert(libt::file_error_alert *p) void Session::handlePortmapWarningAlert(libt::portmap_error_alert *p) { - Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(Utils::String::fromStdString(p->message())), Log::CRITICAL); + Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString::fromStdString(p->message())), Log::CRITICAL); } void Session::handlePortmapAlert(libt::portmap_alert *p) { qDebug("UPnP Success, msg: %s", p->message().c_str()); - Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(Utils::String::fromStdString(p->message())), Log::INFO); + Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(QString::fromStdString(p->message())), Log::INFO); } void Session::handlePeerBlockedAlert(libt::peer_blocked_alert *p) @@ -3453,7 +3453,7 @@ void Session::handlePeerBanAlert(libt::peer_ban_alert *p) void Session::handleUrlSeedAlert(libt::url_seed_alert *p) { - Logger::instance()->addMessage(tr("URL seed lookup failed for URL: '%1', message: %2").arg(Utils::String::fromStdString(p->url)).arg(Utils::String::fromStdString(p->message())), Log::CRITICAL); + Logger::instance()->addMessage(tr("URL seed lookup failed for URL: '%1', message: %2").arg(QString::fromStdString(p->url)).arg(QString::fromStdString(p->message())), Log::CRITICAL); } void Session::handleListenSucceededAlert(libt::listen_succeeded_alert *p) @@ -3567,20 +3567,20 @@ namespace if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false; #endif - torrentData.savePath = Utils::Fs::fromNativePath(Utils::String::fromStdString(fast.dict_find_string_value("qBt-savePath"))); - torrentData.ratioLimit = Utils::String::fromStdString(fast.dict_find_string_value("qBt-ratioLimit")).toDouble(); + torrentData.savePath = Utils::Fs::fromNativePath(QString::fromStdString(fast.dict_find_string_value("qBt-savePath"))); + torrentData.ratioLimit = QString::fromStdString(fast.dict_find_string_value("qBt-ratioLimit")).toDouble(); // ************************************************************************************** // Workaround to convert legacy label to category // TODO: Should be removed in future - torrentData.category = Utils::String::fromStdString(fast.dict_find_string_value("qBt-label")); + torrentData.category = QString::fromStdString(fast.dict_find_string_value("qBt-label")); if (torrentData.category.isEmpty()) // ************************************************************************************** - torrentData.category = Utils::String::fromStdString(fast.dict_find_string_value("qBt-category")); - torrentData.name = Utils::String::fromStdString(fast.dict_find_string_value("qBt-name")); + torrentData.category = QString::fromStdString(fast.dict_find_string_value("qBt-category")); + torrentData.name = QString::fromStdString(fast.dict_find_string_value("qBt-name")); torrentData.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); torrentData.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); - magnetUri = MagnetUri(Utils::String::fromStdString(fast.dict_find_string_value("qBt-magnetUri"))); + magnetUri = MagnetUri(QString::fromStdString(fast.dict_find_string_value("qBt-magnetUri"))); torrentData.addPaused = fast.dict_find_int_value("qBt-paused"); torrentData.addForced = fast.dict_find_int_value("qBt-forced"); diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index 271f533ca..1d9e35660 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -55,7 +55,7 @@ using namespace BitTorrent; // name starts with a . bool fileFilter(const std::string &f) { - return !Utils::Fs::fileName(Utils::String::fromStdString(f)).startsWith('.'); + return !Utils::Fs::fileName(QString::fromStdString(f)).startsWith('.'); } TorrentCreatorThread::TorrentCreatorThread(QObject *parent) @@ -163,6 +163,6 @@ void TorrentCreatorThread::run() emit creationSuccess(m_savePath, parentPath); } catch (std::exception& e) { - emit creationFailure(Utils::String::fromStdString(e.what())); + emit creationFailure(QString::fromStdString(e.what())); } } diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index d953cf268..1ffc84c86 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -263,7 +263,7 @@ QString TorrentHandle::name() const { QString name = m_name; if (name.isEmpty()) - name = Utils::String::fromStdString(m_nativeStatus.name); + name = QString::fromStdString(m_nativeStatus.name); if (name.isEmpty()) name = m_hash; @@ -324,7 +324,7 @@ qlonglong TorrentHandle::wastedSize() const QString TorrentHandle::currentTracker() const { - return Utils::String::fromStdString(m_nativeStatus.current_tracker); + return QString::fromStdString(m_nativeStatus.current_tracker); } QString TorrentHandle::savePath(bool actual) const @@ -371,7 +371,7 @@ void TorrentHandle::setAutoTMMEnabled(bool enabled) QString TorrentHandle::nativeActualSavePath() const { - return Utils::String::fromStdString(m_nativeStatus.save_path); + return QString::fromStdString(m_nativeStatus.save_path); } QList TorrentHandle::trackers() const @@ -858,7 +858,7 @@ int TorrentHandle::queuePosition() const QString TorrentHandle::error() const { - return Utils::String::fromStdString(m_nativeStatus.error); + return QString::fromStdString(m_nativeStatus.error); } qlonglong TorrentHandle::totalDownload() const @@ -1380,7 +1380,7 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p) return; } - const QString newPath = Utils::String::fromStdString(p->path); + const QString newPath = QString::fromStdString(p->path); if (newPath != m_newPath) { qWarning() << Q_FUNC_INFO << ": New path doesn't match a path in a queue."; return; @@ -1412,7 +1412,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail } Logger::instance()->addMessage(tr("Could not move torrent: '%1'. Reason: %2") - .arg(name()).arg(Utils::String::fromStdString(p->message())), Log::CRITICAL); + .arg(name()).arg(QString::fromStdString(p->message())), Log::CRITICAL); m_newPath.clear(); if (!m_queuedPath.isEmpty()) { @@ -1426,7 +1426,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p) { - QString trackerUrl = Utils::String::fromStdString(p->url); + QString trackerUrl = QString::fromStdString(p->url); qDebug("Received a tracker reply from %s (Num_peers = %d)", qPrintable(trackerUrl), p->num_peers); // Connection was successful now. Remove possible old errors m_trackerInfos[trackerUrl].lastMessage.clear(); // Reset error/warning message @@ -1437,8 +1437,8 @@ void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p) void TorrentHandle::handleTrackerWarningAlert(libtorrent::tracker_warning_alert *p) { - QString trackerUrl = Utils::String::fromStdString(p->url); - QString message = Utils::String::fromStdString(p->msg); + QString trackerUrl = QString::fromStdString(p->url); + QString message = QString::fromStdString(p->msg); qDebug("Received a tracker warning for %s: %s", qPrintable(trackerUrl), qPrintable(message)); // Connection was successful now but there is a warning message m_trackerInfos[trackerUrl].lastMessage = message; // Store warning message @@ -1448,8 +1448,8 @@ void TorrentHandle::handleTrackerWarningAlert(libtorrent::tracker_warning_alert void TorrentHandle::handleTrackerErrorAlert(libtorrent::tracker_error_alert *p) { - QString trackerUrl = Utils::String::fromStdString(p->url); - QString message = Utils::String::fromStdString(p->msg); + QString trackerUrl = QString::fromStdString(p->url); + QString message = QString::fromStdString(p->msg); qDebug("Received a tracker error for %s: %s", qPrintable(trackerUrl), qPrintable(message)); m_trackerInfos[trackerUrl].lastMessage = message; @@ -1570,13 +1570,13 @@ void TorrentHandle::handleFastResumeRejectedAlert(libtorrent::fastresume_rejecte } else { logger->addMessage(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...") - .arg(name()).arg(Utils::String::fromStdString(p->message())), Log::CRITICAL); + .arg(name()).arg(QString::fromStdString(p->message())), Log::CRITICAL); } } void TorrentHandle::handleFileRenamedAlert(libtorrent::file_renamed_alert *p) { - QString newName = Utils::Fs::fromNativePath(Utils::String::fromStdString(p->name)); + QString newName = Utils::Fs::fromNativePath(QString::fromStdString(p->name)); // TODO: Check this! if (filesCount() > 1) { @@ -1857,7 +1857,7 @@ void TorrentHandle::flushCache() QString TorrentHandle::toMagnetUri() const { - return Utils::String::fromStdString(libt::make_magnet_uri(m_nativeHandle)); + return QString::fromStdString(libt::make_magnet_uri(m_nativeHandle)); } void TorrentHandle::prioritizeFiles(const QVector &priorities) diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index a73fb9abb..6cf53124f 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -93,7 +93,7 @@ InfoHash TorrentInfo::hash() const QString TorrentInfo::name() const { if (!isValid()) return QString(); - return Utils::String::fromStdString(m_nativeInfo->name()); + return QString::fromStdString(m_nativeInfo->name()); } QDateTime TorrentInfo::creationDate() const @@ -106,13 +106,13 @@ QDateTime TorrentInfo::creationDate() const QString TorrentInfo::creator() const { if (!isValid()) return QString(); - return Utils::String::fromStdString(m_nativeInfo->creator()); + return QString::fromStdString(m_nativeInfo->creator()); } QString TorrentInfo::comment() const { if (!isValid()) return QString(); - return Utils::String::fromStdString(m_nativeInfo->comment()); + return QString::fromStdString(m_nativeInfo->comment()); } bool TorrentInfo::isPrivate() const @@ -154,7 +154,7 @@ int TorrentInfo::piecesCount() const QString TorrentInfo::filePath(int index) const { if (!isValid()) return QString(); - return Utils::Fs::fromNativePath(Utils::String::fromStdString(m_nativeInfo->files().file_path(index))); + return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->files().file_path(index))); } QStringList TorrentInfo::filePaths() const @@ -174,7 +174,7 @@ QString TorrentInfo::fileName(int index) const QString TorrentInfo::origFilePath(int index) const { if (!isValid()) return QString(); - return Utils::Fs::fromNativePath(Utils::String::fromStdString(m_nativeInfo->orig_files().file_path(index))); + return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->orig_files().file_path(index))); } qlonglong TorrentInfo::fileSize(int index) const diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index 6d0c71a6e..14f98e738 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -51,7 +51,7 @@ TrackerEntry::TrackerEntry(const TrackerEntry &other) QString TrackerEntry::url() const { - return Utils::String::fromStdString(m_nativeEntry.url); + return QString::fromStdString(m_nativeEntry.url); } int TrackerEntry::tier() const diff --git a/src/base/utils/string.cpp b/src/base/utils/string.cpp index 52eaafd20..3a6cef7c9 100644 --- a/src/base/utils/string.cpp +++ b/src/base/utils/string.cpp @@ -152,11 +152,6 @@ bool Utils::String::naturalCompareCaseInsensitive(const QString &left, const QSt #endif } -QString Utils::String::fromStdString(const std::string &str) -{ - return QString::fromUtf8(str.c_str()); -} - // to send numbers instead of strings with suffixes QString Utils::String::fromDouble(double n, int precision) { diff --git a/src/base/utils/string.h b/src/base/utils/string.h index c9a2b5795..c2c05ed6b 100644 --- a/src/base/utils/string.h +++ b/src/base/utils/string.h @@ -39,7 +39,6 @@ namespace Utils { namespace String { - QString fromStdString(const std::string &str); QString fromDouble(double n, int precision); // Implements constant-time comparison to protect against timing attacks