Use QString literals

The plan is to define `QT_NO_CAST_FROM_ASCII` eventually.
PR #16561.
This commit is contained in:
Chocobo1
2022-03-04 13:25:22 +08:00
committed by GitHub
parent 2c8447853b
commit ab64ee872b
23 changed files with 104 additions and 108 deletions

View File

@@ -30,6 +30,7 @@
#include <QFile>
#include "base/global.h"
#include "base/path.h"
#include "base/unicodestrings.h"
#include "base/utils/misc.h"
@@ -71,7 +72,7 @@ AboutDialog::AboutDialog(QWidget *parent)
, tr("Bug Tracker:"));
m_ui->labelAbout->setText(aboutText);
m_ui->labelMascot->setPixmap(Utils::Gui::scaledPixmap(Path(":/icons/mascot.png"), this));
m_ui->labelMascot->setPixmap(Utils::Gui::scaledPixmap(Path(u":/icons/mascot.png"_qs), this));
// Thanks
QFile thanksfile(":/thanks.html");

View File

@@ -567,23 +567,21 @@ void AddNewTorrentDialog::saveTorrentFile()
{
Q_ASSERT(hasMetadata());
const QString torrentFileExtension {C_TORRENT_FILE_EXTENSION};
const QString filter {tr("Torrent file (*%1)").arg(torrentFileExtension)};
const QString filter {tr("Torrent file (*%1)").arg(TORRENT_FILE_EXTENSION)};
QString path = QFileDialog::getSaveFileName(
this, tr("Save as torrent file")
, QDir::home().absoluteFilePath(m_torrentInfo.name() + torrentFileExtension)
, filter);
Path path {QFileDialog::getSaveFileName(this, tr("Save as torrent file")
, QDir::home().absoluteFilePath(m_torrentInfo.name() + TORRENT_FILE_EXTENSION)
, filter)};
if (path.isEmpty()) return;
if (!path.endsWith(torrentFileExtension, Qt::CaseInsensitive))
path += torrentFileExtension;
if (!path.hasExtension(TORRENT_FILE_EXTENSION))
path += TORRENT_FILE_EXTENSION;
const nonstd::expected<void, QString> result = m_torrentInfo.saveToFile(Path(path));
const nonstd::expected<void, QString> result = m_torrentInfo.saveToFile(path);
if (!result)
{
QMessageBox::critical(this, tr("I/O Error")
, tr("Couldn't export torrent metadata file '%1'. Reason: %2.").arg(path, result.error()));
, tr("Couldn't export torrent metadata file '%1'. Reason: %2.").arg(path.toString(), result.error()));
}
}

View File

@@ -116,7 +116,7 @@ namespace
bool isTorrentLink(const QString &str)
{
return str.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)
|| str.endsWith(QLatin1String(C_TORRENT_FILE_EXTENSION), Qt::CaseInsensitive)
|| str.endsWith(TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)
|| (!str.startsWith(QLatin1String("file:"), Qt::CaseInsensitive)
&& Net::DownloadManager::hasSupportedScheme(str));
}
@@ -1421,7 +1421,7 @@ void MainWindow::on_actionOpen_triggered()
// Note: it is possible to select more than one file
const QStringList pathsList =
QFileDialog::getOpenFileNames(this, tr("Open Torrent Files"), pref->getMainLastDir().data(),
tr("Torrent Files") + " (*" + C_TORRENT_FILE_EXTENSION + ')');
tr("Torrent Files") + u" (*" + TORRENT_FILE_EXTENSION + u')');
if (pathsList.isEmpty())
return;

View File

@@ -37,6 +37,7 @@
#include <QScrollBar>
#include <QStyle>
#include "base/global.h"
#include "base/path.h"
#include "base/profile.h"
@@ -45,7 +46,7 @@ HtmlBrowser::HtmlBrowser(QWidget *parent)
{
m_netManager = new QNetworkAccessManager(this);
m_diskCache = new QNetworkDiskCache(this);
m_diskCache->setCacheDirectory((specialFolderLocation(SpecialFolder::Cache) / Path("rss")).data());
m_diskCache->setCacheDirectory((specialFolderLocation(SpecialFolder::Cache) / Path(u"rss"_qs)).data());
m_diskCache->setMaximumCacheSize(50 * 1024 * 1024);
qDebug() << "HtmlBrowser cache path:" << m_diskCache->cacheDirectory() << " max size:" << m_diskCache->maximumCacheSize() / 1024 / 1024 << "MB";
m_netManager->setCache(m_diskCache);

View File

@@ -188,8 +188,8 @@ void TorrentCreatorDialog::onCreateButtonClicked()
Path destPath {QFileDialog::getSaveFileName(this, tr("Select where to save the new torrent"), savePath.data(), tr("Torrent Files (*.torrent)"))};
if (destPath.isEmpty())
return;
if (!destPath.hasExtension(C_TORRENT_FILE_EXTENSION))
destPath += C_TORRENT_FILE_EXTENSION;
if (!destPath.hasExtension(TORRENT_FILE_EXTENSION))
destPath += TORRENT_FILE_EXTENSION;
m_storeLastSavePath = destPath.parentPath();
// Disable dialog & set busy cursor

View File

@@ -37,6 +37,7 @@
#include <QPalette>
#include <QResource>
#include "base/global.h"
#include "base/logger.h"
#include "base/path.h"
#include "base/preferences.h"
@@ -44,7 +45,7 @@
namespace
{
const Path DEFAULT_ICONS_DIR {":icons"};
const Path DEFAULT_ICONS_DIR {u":icons"_qs};
const QString CONFIG_FILE_NAME {QStringLiteral("config.json")};
const QString STYLESHEET_FILE_NAME {QStringLiteral("stylesheet.qss")};
@@ -53,7 +54,7 @@ namespace
// point to a file `file.svg` in root directory of CONFIG_FILE_NAME
const QString STYLESHEET_RESOURCES_DIR {QStringLiteral(":/uitheme")};
const Path THEME_ICONS_DIR {"icons"};
const Path THEME_ICONS_DIR {u"icons"_qs};
Path findIcon(const QString &iconId, const Path &dir)
{
@@ -101,7 +102,7 @@ namespace
}
private:
const Path m_qrcThemeDir {":/uitheme"};
const Path m_qrcThemeDir {u":/uitheme"_qs};
const Path m_qrcIconsDir = m_qrcThemeDir / THEME_ICONS_DIR;
};