Merge pull request #6479 from Chocobo1/qt4

Remove remainings of Qt4
This commit is contained in:
sledgehammer999 2017-03-07 23:28:56 +02:00
commit 7a6da3d3ce
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
18 changed files with 79 additions and 148 deletions

View file

@ -66,7 +66,6 @@ endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(QBT_USE_GUI ${GUI}) set(QBT_USE_GUI ${GUI})
set(QBT_USE_WEBUI ${WEBUI}) set(QBT_USE_WEBUI ${WEBUI})
set(QBT_USES_QT5 ${QT5})
configure_file(config.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/config.h) configure_file(config.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/config.h)

View file

@ -119,7 +119,7 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent =
} }
else { else {
queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0); queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0);
fastNew["qBt-name"] = Utils::String::toStdString(oldTorrent.value("name").toString()); fastNew["qBt-name"] = oldTorrent.value("name").toString().toStdString();
fastNew["qBt-tempPathDisabled"] = false; fastNew["qBt-tempPathDisabled"] = false;
} }
@ -192,14 +192,14 @@ bool upgrade(bool ask = true)
QVariantHash oldTorrent = oldResumeData[hash].toHash(); QVariantHash oldTorrent = oldResumeData[hash].toHash();
if (oldTorrent.value("is_magnet", false).toBool()) { if (oldTorrent.value("is_magnet", false).toBool()) {
libtorrent::entry resumeData; libtorrent::entry resumeData;
resumeData["qBt-magnetUri"] = Utils::String::toStdString(oldTorrent.value("magnet_uri").toString()); resumeData["qBt-magnetUri"] = oldTorrent.value("magnet_uri").toString().toStdString();
resumeData["qBt-paused"] = false; resumeData["qBt-paused"] = false;
resumeData["qBt-forced"] = false; resumeData["qBt-forced"] = false;
resumeData["qBt-savePath"] = Utils::String::toStdString(oldTorrent.value("save_path").toString()); resumeData["qBt-savePath"] = oldTorrent.value("save_path").toString().toStdString();
resumeData["qBt-ratioLimit"] = Utils::String::toStdString(QString::number(oldTorrent.value("max_ratio", -2).toReal())); resumeData["qBt-ratioLimit"] = QString::number(oldTorrent.value("max_ratio", -2).toReal()).toStdString();
resumeData["qBt-label"] = Utils::String::toStdString(oldTorrent.value("label").toString()); resumeData["qBt-label"] = oldTorrent.value("label").toString().toStdString();
resumeData["qBt-name"] = Utils::String::toStdString(oldTorrent.value("name").toString()); resumeData["qBt-name"] = oldTorrent.value("name").toString().toStdString();
resumeData["qBt-seedStatus"] = oldTorrent.value("seed").toBool(); resumeData["qBt-seedStatus"] = oldTorrent.value("seed").toBool();
resumeData["qBt-tempPathDisabled"] = false; resumeData["qBt-tempPathDisabled"] = false;

View file

@ -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()));

View file

@ -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);
} }

View file

@ -375,7 +375,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);
@ -987,11 +987,11 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) { if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) {
if (proxyConfig.type != Net::ProxyType::None) { if (proxyConfig.type != Net::ProxyType::None) {
settingsPack.set_str(libt::settings_pack::proxy_hostname, Utils::String::toStdString(proxyConfig.ip)); settingsPack.set_str(libt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString());
settingsPack.set_int(libt::settings_pack::proxy_port, proxyConfig.port); settingsPack.set_int(libt::settings_pack::proxy_port, proxyConfig.port);
if (proxyManager->isAuthenticationRequired()) { if (proxyManager->isAuthenticationRequired()) {
settingsPack.set_str(libt::settings_pack::proxy_username, Utils::String::toStdString(proxyConfig.username)); settingsPack.set_str(libt::settings_pack::proxy_username, proxyConfig.username.toStdString());
settingsPack.set_str(libt::settings_pack::proxy_password, Utils::String::toStdString(proxyConfig.password)); settingsPack.set_str(libt::settings_pack::proxy_password, proxyConfig.password.toStdString());
} }
settingsPack.set_bool(libt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled()); settingsPack.set_bool(libt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled());
} }
@ -1066,7 +1066,7 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
// Include overhead in transfer limits // Include overhead in transfer limits
settingsPack.set_bool(libt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); settingsPack.set_bool(libt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits());
// IP address to announce to trackers // IP address to announce to trackers
settingsPack.set_str(libt::settings_pack::announce_ip, Utils::String::toStdString(announceIP())); settingsPack.set_str(libt::settings_pack::announce_ip, announceIP().toStdString());
// Super seeding // Super seeding
settingsPack.set_bool(libt::settings_pack::strict_super_seeding, isSuperSeedingEnabled()); settingsPack.set_bool(libt::settings_pack::strict_super_seeding, isSuperSeedingEnabled());
// * Max Half-open connections // * Max Half-open connections
@ -1134,11 +1134,11 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) { if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) {
libt::proxy_settings proxySettings; libt::proxy_settings proxySettings;
if (proxyConfig.type != Net::ProxyType::None) { if (proxyConfig.type != Net::ProxyType::None) {
proxySettings.hostname = Utils::String::toStdString(proxyConfig.ip); proxySettings.hostname = proxyConfig.ip.toStdString();
proxySettings.port = proxyConfig.port; proxySettings.port = proxyConfig.port;
if (proxyManager->isAuthenticationRequired()) { if (proxyManager->isAuthenticationRequired()) {
proxySettings.username = Utils::String::toStdString(proxyConfig.username); proxySettings.username = proxyConfig.username.toStdString();
proxySettings.password = Utils::String::toStdString(proxyConfig.password); proxySettings.password = proxyConfig.password.toStdString();
} }
proxySettings.proxy_peer_connections = isProxyPeerConnectionsEnabled(); proxySettings.proxy_peer_connections = isProxyPeerConnectionsEnabled();
} }
@ -1211,7 +1211,7 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
// Include overhead in transfer limits // Include overhead in transfer limits
sessionSettings.rate_limit_ip_overhead = includeOverheadInLimits(); sessionSettings.rate_limit_ip_overhead = includeOverheadInLimits();
// IP address to announce to trackers // IP address to announce to trackers
sessionSettings.announce_ip = Utils::String::toStdString(announceIP()); sessionSettings.announce_ip = announceIP().toStdString();
// Super seeding // Super seeding
sessionSettings.strict_super_seeding = isSuperSeedingEnabled(); sessionSettings.strict_super_seeding = isSuperSeedingEnabled();
// * Max Half-open connections // * Max Half-open connections
@ -1711,7 +1711,7 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri
// Limits // Limits
p.max_connections = maxConnectionsPerTorrent(); p.max_connections = maxConnectionsPerTorrent();
p.max_uploads = maxUploadsPerTorrent(); p.max_uploads = maxUploadsPerTorrent();
p.save_path = Utils::String::toStdString(Utils::Fs::toNativePath(savePath)); p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
m_addingTorrents.insert(hash, addData); m_addingTorrents.insert(hash, addData);
// Adding torrent to BitTorrent session // Adding torrent to BitTorrent session
@ -1799,7 +1799,7 @@ bool Session::loadMetadata(const MagnetUri &magnetUri)
p.max_uploads = maxUploadsPerTorrent(); p.max_uploads = maxUploadsPerTorrent();
QString savePath = QString("%1/%2").arg(QDir::tempPath()).arg(hash); QString savePath = QString("%1/%2").arg(QDir::tempPath()).arg(hash);
p.save_path = Utils::String::toStdString(Utils::Fs::toNativePath(savePath)); p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
// Forced start // Forced start
p.flags &= ~libt::add_torrent_params::flag_paused; p.flags &= ~libt::add_torrent_params::flag_paused;
@ -3330,7 +3330,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());
} }
} }
@ -3412,7 +3412,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);
} }
@ -3460,7 +3460,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);
@ -3469,13 +3469,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)
@ -3518,7 +3518,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)
@ -3632,20 +3632,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");

View file

@ -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)
@ -107,14 +107,14 @@ void TorrentCreatorThread::run()
try { try {
libt::file_storage fs; libt::file_storage fs;
// Adding files to the torrent // Adding files to the torrent
libt::add_files(fs, Utils::String::toStdString(Utils::Fs::toNativePath(m_inputPath)), fileFilter); libt::add_files(fs, Utils::Fs::toNativePath(m_inputPath).toStdString(), fileFilter);
if (m_abort) return; if (m_abort) return;
libt::create_torrent t(fs, m_pieceSize); libt::create_torrent t(fs, m_pieceSize);
// Add url seeds // Add url seeds
foreach (const QString &seed, m_urlSeeds) foreach (const QString &seed, m_urlSeeds)
t.add_url_seed(Utils::String::toStdString(seed.trimmed())); t.add_url_seed(seed.trimmed().toStdString());
int tier = 0; int tier = 0;
bool newline = false; bool newline = false;
@ -126,14 +126,14 @@ void TorrentCreatorThread::run()
newline = true; newline = true;
continue; continue;
} }
t.add_tracker(Utils::String::toStdString(tracker.trimmed()), tier); t.add_tracker(tracker.trimmed().toStdString(), tier);
newline = false; newline = false;
} }
if (m_abort) return; if (m_abort) return;
// calculate the hash for all pieces // calculate the hash for all pieces
const QString parentPath = Utils::Fs::branchPath(m_inputPath) + "/"; const QString parentPath = Utils::Fs::branchPath(m_inputPath) + "/";
libt::set_piece_hashes(t, Utils::String::toStdString(Utils::Fs::toNativePath(parentPath)), boost::bind(&TorrentCreatorThread::sendProgressSignal, this, _1, t.num_pieces())); libt::set_piece_hashes(t, Utils::Fs::toNativePath(parentPath).toStdString(), boost::bind(&TorrentCreatorThread::sendProgressSignal, this, _1, t.num_pieces()));
// Set qBittorrent as creator and add user comment to // Set qBittorrent as creator and add user comment to
// torrent_info structure // torrent_info structure
t.set_creator(creator_str.toUtf8().constData()); t.set_creator(creator_str.toUtf8().constData());
@ -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()));
} }
} }

View file

@ -227,7 +227,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;
@ -288,7 +288,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
@ -335,7 +335,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
@ -442,7 +442,7 @@ bool TorrentHandle::addUrlSeed(const QUrl &urlSeed)
QList<QUrl> seeds = urlSeeds(); QList<QUrl> seeds = urlSeeds();
if (seeds.contains(urlSeed)) return false; if (seeds.contains(urlSeed)) return false;
m_nativeHandle.add_url_seed(Utils::String::toStdString(urlSeed.toString())); m_nativeHandle.add_url_seed(urlSeed.toString().toStdString());
return true; return true;
} }
@ -451,14 +451,14 @@ bool TorrentHandle::removeUrlSeed(const QUrl &urlSeed)
QList<QUrl> seeds = urlSeeds(); QList<QUrl> seeds = urlSeeds();
if (!seeds.contains(urlSeed)) return false; if (!seeds.contains(urlSeed)) return false;
m_nativeHandle.remove_url_seed(Utils::String::toStdString(urlSeed.toString())); m_nativeHandle.remove_url_seed(urlSeed.toString().toStdString());
return true; return true;
} }
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress) bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
{ {
libt::error_code ec; libt::error_code ec;
libt::address addr = libt::address::from_string(Utils::String::toStdString(peerAddress.ip.toString()), ec); libt::address addr = libt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
if (ec) return false; if (ec) return false;
boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port); boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
@ -818,7 +818,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
@ -1282,7 +1282,7 @@ void TorrentHandle::renameFile(int index, const QString &name)
{ {
++m_renameCount; ++m_renameCount;
qDebug() << Q_FUNC_INFO << index << name; qDebug() << Q_FUNC_INFO << index << name;
m_nativeHandle.rename_file(index, Utils::String::toStdString(Utils::Fs::toNativePath(name))); m_nativeHandle.rename_file(index, Utils::Fs::toNativePath(name).toStdString());
} }
bool TorrentHandle::saveTorrentFile(const QString &path) bool TorrentHandle::saveTorrentFile(const QString &path)
@ -1323,7 +1323,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;
@ -1355,7 +1355,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()) {
@ -1369,7 +1369,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
@ -1380,8 +1380,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
@ -1391,8 +1391,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;
@ -1473,14 +1473,14 @@ void TorrentHandle::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert
libtorrent::entry &resumeData = useDummyResumeData ? dummyEntry : *(p->resume_data); libtorrent::entry &resumeData = useDummyResumeData ? dummyEntry : *(p->resume_data);
if (useDummyResumeData) { if (useDummyResumeData) {
resumeData["qBt-magnetUri"] = Utils::String::toStdString(toMagnetUri()); resumeData["qBt-magnetUri"] = toMagnetUri().toStdString();
resumeData["qBt-paused"] = isPaused(); resumeData["qBt-paused"] = isPaused();
resumeData["qBt-forced"] = isForced(); resumeData["qBt-forced"] = isForced();
} }
resumeData["qBt-savePath"] = m_useAutoTMM ? "" : Utils::String::toStdString(m_savePath); resumeData["qBt-savePath"] = m_useAutoTMM ? "" : m_savePath.toStdString();
resumeData["qBt-ratioLimit"] = Utils::String::toStdString(QString::number(m_ratioLimit)); resumeData["qBt-ratioLimit"] = QString::number(m_ratioLimit).toStdString();
resumeData["qBt-category"] = Utils::String::toStdString(m_category); resumeData["qBt-category"] = m_category.toStdString();
resumeData["qBt-name"] = Utils::String::toStdString(m_name); resumeData["qBt-name"] = m_name.toStdString();
resumeData["qBt-seedStatus"] = m_hasSeedStatus; resumeData["qBt-seedStatus"] = m_hasSeedStatus;
resumeData["qBt-tempPathDisabled"] = m_tempPathDisabled; resumeData["qBt-tempPathDisabled"] = m_tempPathDisabled;
resumeData["qBt-queuePosition"] = queuePosition(); resumeData["qBt-queuePosition"] = queuePosition();
@ -1513,13 +1513,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) {
@ -1797,7 +1797,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)

View file

@ -64,7 +64,7 @@ TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString &error)
{ {
error.clear(); error.clear();
libt::error_code ec; libt::error_code ec;
TorrentInfo info(NativePtr(new libt::torrent_info(Utils::String::toStdString(Utils::Fs::toNativePath(path)), ec))); TorrentInfo info(NativePtr(new libt::torrent_info(Utils::Fs::toNativePath(path).toStdString(), ec)));
if (ec) { if (ec) {
error = QString::fromUtf8(ec.message().c_str()); error = QString::fromUtf8(ec.message().c_str());
qDebug("Cannot load .torrent file: %s", qPrintable(error)); qDebug("Cannot load .torrent file: %s", qPrintable(error));
@ -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
@ -279,7 +279,7 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(int fileIndex) const
void TorrentInfo::renameFile(uint index, const QString &newPath) void TorrentInfo::renameFile(uint index, const QString &newPath)
{ {
if (!isValid()) return; if (!isValid()) return;
nativeInfo()->rename_file(index, Utils::String::toStdString(newPath)); nativeInfo()->rename_file(index, newPath.toStdString());
} }
int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const

View file

@ -65,8 +65,8 @@ libtorrent::entry Peer::toEntry(bool noPeerId) const
{ {
libtorrent::entry::dictionary_type peerMap; libtorrent::entry::dictionary_type peerMap;
if (!noPeerId) if (!noPeerId)
peerMap["id"] = libtorrent::entry(Utils::String::toStdString(peerId)); peerMap["id"] = libtorrent::entry(peerId.toStdString());
peerMap["ip"] = libtorrent::entry(Utils::String::toStdString(ip)); peerMap["ip"] = libtorrent::entry(ip.toStdString());
peerMap["port"] = libtorrent::entry(port); peerMap["port"] = libtorrent::entry(port);
return libtorrent::entry(peerMap); return libtorrent::entry(peerMap);

View file

@ -35,7 +35,7 @@
using namespace BitTorrent; using namespace BitTorrent;
TrackerEntry::TrackerEntry(const QString &url) TrackerEntry::TrackerEntry(const QString &url)
: m_nativeEntry(libtorrent::announce_entry(Utils::String::toStdString(url))) : m_nativeEntry(libtorrent::announce_entry(url.toStdString()))
{ {
} }
@ -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

View file

@ -37,7 +37,7 @@ void Logger::addMessage(const QString &message, const Log::MsgType &type)
{ {
QWriteLocker locker(&lock); QWriteLocker locker(&lock);
Log::Msg temp = { msgCounter++, QDateTime::currentMSecsSinceEpoch(), type, Utils::String::toHtmlEscaped(message) }; Log::Msg temp = { msgCounter++, QDateTime::currentMSecsSinceEpoch(), type, message.toHtmlEscaped() };
m_messages.push_back(temp); m_messages.push_back(temp);
if (m_messages.size() >= MAX_LOG_MESSAGES) if (m_messages.size() >= MAX_LOG_MESSAGES)
@ -50,7 +50,7 @@ void Logger::addPeer(const QString &ip, bool blocked, const QString &reason)
{ {
QWriteLocker locker(&lock); QWriteLocker locker(&lock);
Log::Peer temp = { peerCounter++, QDateTime::currentMSecsSinceEpoch(), Utils::String::toHtmlEscaped(ip), blocked, Utils::String::toHtmlEscaped(reason) }; Log::Peer temp = { peerCounter++, QDateTime::currentMSecsSinceEpoch(), ip.toHtmlEscaped(), blocked, reason.toHtmlEscaped() };
m_peers.push_back(temp); m_peers.push_back(temp);
if (m_peers.size() >= MAX_LOG_MESSAGES) if (m_peers.size() >= MAX_LOG_MESSAGES)

View file

@ -1271,20 +1271,12 @@ void Preferences::setRssMainSplitterState(const QByteArray &state)
QByteArray Preferences::getSearchTabHeaderState() const QByteArray Preferences::getSearchTabHeaderState() const
{ {
#ifdef QBT_USES_QT5
return value("SearchTab/qt5/HeaderState").toByteArray(); return value("SearchTab/qt5/HeaderState").toByteArray();
#else
return value("SearchTab/HeaderState").toByteArray();
#endif
} }
void Preferences::setSearchTabHeaderState(const QByteArray &state) void Preferences::setSearchTabHeaderState(const QByteArray &state)
{ {
#ifdef QBT_USES_QT5
setValue("SearchTab/qt5/HeaderState", state); setValue("SearchTab/qt5/HeaderState", state);
#else
setValue("SearchTab/HeaderState", state);
#endif
} }
QStringList Preferences::getSearchEngDisabled() const QStringList Preferences::getSearchEngDisabled() const

View file

@ -152,21 +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());
}
std::string Utils::String::toStdString(const QString &str)
{
#ifdef QBT_USES_QT5
return str.toStdString();
#else
QByteArray utf8 = str.toUtf8();
return std::string(utf8.constData(), utf8.length());
#endif
}
// 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)
{ {
@ -193,29 +178,3 @@ bool Utils::String::slowEquals(const QByteArray &a, const QByteArray &b)
return (diff == 0); return (diff == 0);
} }
QString Utils::String::toHtmlEscaped(const QString &str)
{
#ifdef QBT_USES_QT5
return str.toHtmlEscaped();
#else
// code from Qt
QString rich;
const int len = str.length();
rich.reserve(int(len * 1.1));
for (int i = 0; i < len; ++i) {
if (str.at(i) == QLatin1Char('<'))
rich += QLatin1String("&lt;");
else if (str.at(i) == QLatin1Char('>'))
rich += QLatin1String("&gt;");
else if (str.at(i) == QLatin1Char('&'))
rich += QLatin1String("&amp;");
else if (str.at(i) == QLatin1Char('"'))
rich += QLatin1String("&quot;");
else
rich += str.at(i);
}
rich.squeeze();
return rich;
#endif
}

View file

@ -39,16 +39,12 @@ namespace Utils
{ {
namespace String namespace String
{ {
QString fromStdString(const std::string &str);
std::string toStdString(const QString &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
// Taken from https://crackstation.net/hashing-security.htm // Taken from https://crackstation.net/hashing-security.htm
bool slowEquals(const QByteArray &a, const QByteArray &b); bool slowEquals(const QByteArray &a, const QByteArray &b);
QString toHtmlEscaped(const QString &str);
bool naturalCompareCaseSensitive(const QString &left, const QString &right); bool naturalCompareCaseSensitive(const QString &left, const QString &right);
bool naturalCompareCaseInsensitive(const QString &left, const QString &right); bool naturalCompareCaseInsensitive(const QString &left, const QString &right);
} }

View file

@ -161,22 +161,7 @@ void CategoryFilterWidget::callUpdateGeometry()
QSize CategoryFilterWidget::sizeHint() const QSize CategoryFilterWidget::sizeHint() const
{ {
#ifdef QBT_USES_QT5
return viewportSizeHint(); return viewportSizeHint();
#else
int lastRow = model()->rowCount() - 1;
QModelIndex last = model()->index(lastRow, 0);
while ((lastRow >= 0) && isExpanded(last)) {
lastRow = model()->rowCount(last) - 1;
last = model()->index(lastRow, 0, last);
}
const QRect deepestRect = visualRect(last);
if (!deepestRect.isValid())
return viewport()->sizeHint();
return QSize(header()->length(), deepestRect.bottom() + 1);
#endif
} }
QSize CategoryFilterWidget::minimumSizeHint() const QSize CategoryFilterWidget::minimumSizeHint() const

View file

@ -46,7 +46,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) { DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) {
setupUi(this); setupUi(this);
if (size == 1) if (size == 1)
label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(Utils::String::toHtmlEscaped(name))); label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name.toHtmlEscaped()));
else else
label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size))); label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
// Icons // Icons

View file

@ -397,7 +397,7 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHan
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), peer.connectionType()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), peer.connectionType());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), Utils::String::toHtmlEscaped(peer.client())); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), peer.client().toHtmlEscaped());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed());
@ -428,7 +428,7 @@ void PeerListWidget::updatePeer(const QString &ip, BitTorrent::TorrentHandle *co
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), Utils::String::toHtmlEscaped(peer.client())); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), peer.client().toHtmlEscaped());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed());

View file

@ -307,12 +307,12 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
label_total_size_val->setText(Utils::Misc::friendlyUnit(m_torrent->totalSize())); label_total_size_val->setText(Utils::Misc::friendlyUnit(m_torrent->totalSize()));
// Comment // Comment
comment_text->setText(Utils::Misc::parseHtmlLinks(Utils::String::toHtmlEscaped(m_torrent->comment()))); comment_text->setText(Utils::Misc::parseHtmlLinks(m_torrent->comment().toHtmlEscaped()));
// URL seeds // URL seeds
loadUrlSeeds(); loadUrlSeeds();
label_created_by_val->setText(Utils::String::toHtmlEscaped(m_torrent->creator())); label_created_by_val->setText(m_torrent->creator().toHtmlEscaped());
// List files in torrent // List files in torrent
PropListModel->model()->setupModelData(m_torrent->info()); PropListModel->model()->setupModelData(m_torrent->info());