Browse Source

Replace Utils::String::fromStdString() by QString::fromStdString()

adaptive-webui-19844
Chocobo1 8 years ago
parent
commit
fa2128cbae
  1. 4
      src/base/bittorrent/magneturi.cpp
  2. 2
      src/base/bittorrent/peerinfo.cpp
  3. 26
      src/base/bittorrent/session.cpp
  4. 4
      src/base/bittorrent/torrentcreatorthread.cpp
  5. 28
      src/base/bittorrent/torrenthandle.cpp
  6. 10
      src/base/bittorrent/torrentinfo.cpp
  7. 2
      src/base/bittorrent/trackerentry.cpp
  8. 5
      src/base/utils/string.cpp
  9. 1
      src/base/utils/string.h

4
src/base/bittorrent/magneturi.cpp

@ -80,10 +80,10 @@ MagnetUri::MagnetUri(const QString &source)
m_valid = true; m_valid = true;
m_hash = m_addTorrentParams.info_hash; 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) 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) foreach (const std::string &urlSeed, m_addTorrentParams.url_seeds)
m_urlSeeds.append(QUrl(urlSeed.c_str())); m_urlSeeds.append(QUrl(urlSeed.c_str()));

2
src/base/bittorrent/peerinfo.cpp

@ -198,7 +198,7 @@ PeerAddress PeerInfo::address() const
QString PeerInfo::client() const QString PeerInfo::client() const
{ {
return Utils::String::fromStdString(m_nativeInfo.client); return QString::fromStdString(m_nativeInfo.client);
} }

26
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_ut_pex_plugin);
m_nativeSession->add_extension(&libt::create_smart_ban_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("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("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); 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) { 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) { if (p->error) {
qDebug("/!\\ Error: Failed to add torrent!"); 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); Logger::instance()->addMessage(tr("Couldn't add torrent. Reason: %1").arg(msg), Log::WARNING);
emit addTorrentFailed(msg); emit addTorrentFailed(msg);
} }
@ -3395,7 +3395,7 @@ void Session::handleFileErrorAlert(libt::file_error_alert *p)
// NOTE: Check this function! // NOTE: Check this function!
TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash()); TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash());
if (torrent) { 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") Logger::instance()->addMessage(tr("An I/O error occurred, '%1' paused. %2")
.arg(torrent->name()).arg(msg)); .arg(torrent->name()).arg(msg));
emit fullDiskError(torrent, 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) 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) void Session::handlePortmapAlert(libt::portmap_alert *p)
{ {
qDebug("UPnP Success, msg: %s", p->message().c_str()); 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) 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) 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) void Session::handleListenSucceededAlert(libt::listen_succeeded_alert *p)
@ -3567,20 +3567,20 @@ namespace
if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false; if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false;
#endif #endif
torrentData.savePath = Utils::Fs::fromNativePath(Utils::String::fromStdString(fast.dict_find_string_value("qBt-savePath"))); torrentData.savePath = Utils::Fs::fromNativePath(QString::fromStdString(fast.dict_find_string_value("qBt-savePath")));
torrentData.ratioLimit = Utils::String::fromStdString(fast.dict_find_string_value("qBt-ratioLimit")).toDouble(); torrentData.ratioLimit = QString::fromStdString(fast.dict_find_string_value("qBt-ratioLimit")).toDouble();
// ************************************************************************************** // **************************************************************************************
// Workaround to convert legacy label to category // Workaround to convert legacy label to category
// TODO: Should be removed in future // 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()) if (torrentData.category.isEmpty())
// ************************************************************************************** // **************************************************************************************
torrentData.category = Utils::String::fromStdString(fast.dict_find_string_value("qBt-category")); torrentData.category = QString::fromStdString(fast.dict_find_string_value("qBt-category"));
torrentData.name = Utils::String::fromStdString(fast.dict_find_string_value("qBt-name")); torrentData.name = QString::fromStdString(fast.dict_find_string_value("qBt-name"));
torrentData.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); torrentData.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus");
torrentData.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); 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.addPaused = fast.dict_find_int_value("qBt-paused");
torrentData.addForced = fast.dict_find_int_value("qBt-forced"); torrentData.addForced = fast.dict_find_int_value("qBt-forced");

4
src/base/bittorrent/torrentcreatorthread.cpp

@ -55,7 +55,7 @@ using namespace BitTorrent;
// name starts with a . // name starts with a .
bool fileFilter(const std::string &f) 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) TorrentCreatorThread::TorrentCreatorThread(QObject *parent)
@ -163,6 +163,6 @@ void TorrentCreatorThread::run()
emit creationSuccess(m_savePath, parentPath); emit creationSuccess(m_savePath, parentPath);
} }
catch (std::exception& e) { catch (std::exception& e) {
emit creationFailure(Utils::String::fromStdString(e.what())); emit creationFailure(QString::fromStdString(e.what()));
} }
} }

28
src/base/bittorrent/torrenthandle.cpp

@ -263,7 +263,7 @@ QString TorrentHandle::name() const
{ {
QString name = m_name; QString name = m_name;
if (name.isEmpty()) if (name.isEmpty())
name = Utils::String::fromStdString(m_nativeStatus.name); name = QString::fromStdString(m_nativeStatus.name);
if (name.isEmpty()) if (name.isEmpty())
name = m_hash; name = m_hash;
@ -324,7 +324,7 @@ qlonglong TorrentHandle::wastedSize() const
QString TorrentHandle::currentTracker() 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 QString TorrentHandle::savePath(bool actual) const
@ -371,7 +371,7 @@ void TorrentHandle::setAutoTMMEnabled(bool enabled)
QString TorrentHandle::nativeActualSavePath() const QString TorrentHandle::nativeActualSavePath() const
{ {
return Utils::String::fromStdString(m_nativeStatus.save_path); return QString::fromStdString(m_nativeStatus.save_path);
} }
QList<TrackerEntry> TorrentHandle::trackers() const QList<TrackerEntry> TorrentHandle::trackers() const
@ -858,7 +858,7 @@ int TorrentHandle::queuePosition() const
QString TorrentHandle::error() const QString TorrentHandle::error() const
{ {
return Utils::String::fromStdString(m_nativeStatus.error); return QString::fromStdString(m_nativeStatus.error);
} }
qlonglong TorrentHandle::totalDownload() const qlonglong TorrentHandle::totalDownload() const
@ -1380,7 +1380,7 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p)
return; return;
} }
const QString newPath = Utils::String::fromStdString(p->path); const QString newPath = QString::fromStdString(p->path);
if (newPath != m_newPath) { if (newPath != m_newPath) {
qWarning() << Q_FUNC_INFO << ": New path doesn't match a path in a queue."; qWarning() << Q_FUNC_INFO << ": New path doesn't match a path in a queue.";
return; return;
@ -1412,7 +1412,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail
} }
Logger::instance()->addMessage(tr("Could not move torrent: '%1'. Reason: %2") 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(); m_newPath.clear();
if (!m_queuedPath.isEmpty()) { if (!m_queuedPath.isEmpty()) {
@ -1426,7 +1426,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail
void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p) 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); qDebug("Received a tracker reply from %s (Num_peers = %d)", qPrintable(trackerUrl), p->num_peers);
// Connection was successful now. Remove possible old errors // Connection was successful now. Remove possible old errors
m_trackerInfos[trackerUrl].lastMessage.clear(); // Reset error/warning message 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) void TorrentHandle::handleTrackerWarningAlert(libtorrent::tracker_warning_alert *p)
{ {
QString trackerUrl = Utils::String::fromStdString(p->url); QString trackerUrl = QString::fromStdString(p->url);
QString message = Utils::String::fromStdString(p->msg); QString message = QString::fromStdString(p->msg);
qDebug("Received a tracker warning for %s: %s", qPrintable(trackerUrl), qPrintable(message)); qDebug("Received a tracker warning for %s: %s", qPrintable(trackerUrl), qPrintable(message));
// Connection was successful now but there is a warning message // Connection was successful now but there is a warning message
m_trackerInfos[trackerUrl].lastMessage = message; // Store 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) void TorrentHandle::handleTrackerErrorAlert(libtorrent::tracker_error_alert *p)
{ {
QString trackerUrl = Utils::String::fromStdString(p->url); QString trackerUrl = QString::fromStdString(p->url);
QString message = Utils::String::fromStdString(p->msg); QString message = QString::fromStdString(p->msg);
qDebug("Received a tracker error for %s: %s", qPrintable(trackerUrl), qPrintable(message)); qDebug("Received a tracker error for %s: %s", qPrintable(trackerUrl), qPrintable(message));
m_trackerInfos[trackerUrl].lastMessage = message; m_trackerInfos[trackerUrl].lastMessage = message;
@ -1570,13 +1570,13 @@ void TorrentHandle::handleFastResumeRejectedAlert(libtorrent::fastresume_rejecte
} }
else { else {
logger->addMessage(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...") 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) 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! // TODO: Check this!
if (filesCount() > 1) { if (filesCount() > 1) {
@ -1857,7 +1857,7 @@ void TorrentHandle::flushCache()
QString TorrentHandle::toMagnetUri() const 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<int> &priorities) void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)

10
src/base/bittorrent/torrentinfo.cpp

@ -93,7 +93,7 @@ InfoHash TorrentInfo::hash() const
QString TorrentInfo::name() const QString TorrentInfo::name() const
{ {
if (!isValid()) return QString(); if (!isValid()) return QString();
return Utils::String::fromStdString(m_nativeInfo->name()); return QString::fromStdString(m_nativeInfo->name());
} }
QDateTime TorrentInfo::creationDate() const QDateTime TorrentInfo::creationDate() const
@ -106,13 +106,13 @@ QDateTime TorrentInfo::creationDate() const
QString TorrentInfo::creator() const QString TorrentInfo::creator() const
{ {
if (!isValid()) return QString(); if (!isValid()) return QString();
return Utils::String::fromStdString(m_nativeInfo->creator()); return QString::fromStdString(m_nativeInfo->creator());
} }
QString TorrentInfo::comment() const QString TorrentInfo::comment() const
{ {
if (!isValid()) return QString(); if (!isValid()) return QString();
return Utils::String::fromStdString(m_nativeInfo->comment()); return QString::fromStdString(m_nativeInfo->comment());
} }
bool TorrentInfo::isPrivate() const bool TorrentInfo::isPrivate() const
@ -154,7 +154,7 @@ int TorrentInfo::piecesCount() const
QString TorrentInfo::filePath(int index) const QString TorrentInfo::filePath(int index) const
{ {
if (!isValid()) return QString(); 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 QStringList TorrentInfo::filePaths() const
@ -174,7 +174,7 @@ QString TorrentInfo::fileName(int index) const
QString TorrentInfo::origFilePath(int index) const QString TorrentInfo::origFilePath(int index) const
{ {
if (!isValid()) return QString(); 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 qlonglong TorrentInfo::fileSize(int index) const

2
src/base/bittorrent/trackerentry.cpp

@ -51,7 +51,7 @@ TrackerEntry::TrackerEntry(const TrackerEntry &other)
QString TrackerEntry::url() const QString TrackerEntry::url() const
{ {
return Utils::String::fromStdString(m_nativeEntry.url); return QString::fromStdString(m_nativeEntry.url);
} }
int TrackerEntry::tier() const int TrackerEntry::tier() const

5
src/base/utils/string.cpp

@ -152,11 +152,6 @@ bool Utils::String::naturalCompareCaseInsensitive(const QString &left, const QSt
#endif #endif
} }
QString Utils::String::fromStdString(const std::string &str)
{
return QString::fromUtf8(str.c_str());
}
// to send numbers instead of strings with suffixes // to send numbers instead of strings with suffixes
QString Utils::String::fromDouble(double n, int precision) QString Utils::String::fromDouble(double n, int precision)
{ {

1
src/base/utils/string.h

@ -39,7 +39,6 @@ namespace Utils
{ {
namespace String namespace String
{ {
QString fromStdString(const std::string &str);
QString fromDouble(double n, int precision); QString fromDouble(double n, int precision);
// Implements constant-time comparison to protect against timing attacks // Implements constant-time comparison to protect against timing attacks

Loading…
Cancel
Save