Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QString literals #16669

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/Modules/MacroQbtCommonConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ macro(qbt_common_config)

target_compile_definitions(qbt_common_cfg INTERFACE
QT_DISABLE_DEPRECATED_BEFORE=0x050f02
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_CAST_FROM_BYTEARRAY
QT_USE_QSTRINGBUILDER
Expand Down
11 changes: 6 additions & 5 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#endif

#include <QAtomicInt>
#include <QByteArray>
#include <QDebug>
#include <QLibraryInfo>
#include <QProcess>
Expand Down Expand Up @@ -326,7 +327,7 @@ void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const
#if defined(Q_OS_WIN)
const auto chopPathSep = [](const QString &str) -> QString
{
if (str.endsWith('\\'))
if (str.endsWith(u'\\'))
return str.mid(0, (str.length() -1));
return str;
};
Expand Down Expand Up @@ -677,11 +678,11 @@ int Application::exec(const QStringList &params)
+ tr("To control qBittorrent, access the WebUI at: %1").arg(url);
printf("%s\n", qUtf8Printable(mesg));

if (pref->getWebUIPassword() == "ARQ77eY1NUZaQsuDHbIMCA==:0WMRkYTUWVT9wVvdDtHAjU9b3b7uB8NR1Gur2hmQCvCDpm39Q+PsJRJPaCU51dEiz+dTzh8qbPsL8WkFljQYFQ==")
if (pref->getWebUIPassword() == QByteArrayLiteral("ARQ77eY1NUZaQsuDHbIMCA==:0WMRkYTUWVT9wVvdDtHAjU9b3b7uB8NR1Gur2hmQCvCDpm39Q+PsJRJPaCU51dEiz+dTzh8qbPsL8WkFljQYFQ=="))
{
const QString warning = tr("The Web UI administrator username is: %1").arg(pref->getWebUiUsername()) + '\n'
+ tr("The Web UI administrator password has not been changed from the default: %1").arg("adminadmin") + '\n'
+ tr("This is a security risk, please change your password in program preferences.") + '\n';
const QString warning = tr("The Web UI administrator username is: %1").arg(pref->getWebUiUsername()) + u'\n'
+ tr("The Web UI administrator password has not been changed from the default: %1").arg(u"adminadmin"_qs) + u'\n'
+ tr("This is a security risk, please change your password in program preferences.") + u'\n';
printf("%s", qUtf8Printable(warning));
}
#endif // DISABLE_WEBUI
Expand Down
10 changes: 3 additions & 7 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ int main(int argc, char *argv[])
.arg(QLatin1String("-h (or --help)")));
}

// Set environment variable
if (!qputenv("QBITTORRENT", QBT_VERSION))
fprintf(stderr, "Couldn't set environment variable...\n");

const bool firstTimeUser = !Preferences::instance()->getAcceptedLegal();
if (firstTimeUser)
{
Expand Down Expand Up @@ -420,9 +416,9 @@ bool userAgreesWithLegalNotice()

#ifdef DISABLE_GUI
const QString eula = QString::fromLatin1("\n*** %1 ***\n").arg(QObject::tr("Legal Notice"))
+ QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.") + "\n\n"
+ QObject::tr("No further notices will be issued.") + "\n\n"
+ QObject::tr("Press %1 key to accept and continue...").arg("'y'") + '\n';
+ QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.") + u"\n\n"
+ QObject::tr("No further notices will be issued.") + u"\n\n"
+ QObject::tr("Press %1 key to accept and continue...").arg(u"'y'"_qs) + u'\n';
printf("%s", qUtf8Printable(eula));

const char ret = getchar(); // Read pressed key
Expand Down
36 changes: 19 additions & 17 deletions src/app/stacktrace_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <cxxabi.h>
#endif

#include "base/global.h"

namespace straceWin
{
void loadHelpStackFrame(IMAGEHLP_STACK_FRAME&, const STACKFRAME64&);
Expand All @@ -50,7 +52,7 @@ namespace straceWin
#ifdef __MINGW32__
void straceWin::demangle(QString& str)
{
char const* inStr = qPrintable("_" + str); // Really need that underline or demangling will fail
char const* inStr = qPrintable(u"_" + str); // Really need that underline or demangling will fail
int status = 0;
size_t outSz = 0;
char* demangled_name = abi::__cxa_demangle(inStr, 0, &outSz, &status);
Expand All @@ -75,7 +77,7 @@ BOOL CALLBACK straceWin::EnumSymbolsCB(PSYMBOL_INFO symInfo, ULONG size, PVOID u
Q_UNUSED(size)
auto params = static_cast<QStringList *>(user);
if (symInfo->Flags & SYMFLAG_PARAMETER)
params->append(symInfo->Name);
params->append(QString::fromUtf8(symInfo->Name));
return TRUE;
}

Expand All @@ -97,16 +99,16 @@ BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVO
{
QString moduleBase = QString::fromLatin1("0x%1").arg(BaseOfDll, 16, 16, QLatin1Char('0'));
QString line = QString::fromLatin1("%1 %2 Image: %3")
.arg(mod.ModuleName, -25)
.arg(QString::fromUtf8(mod.ModuleName), -25)
.arg(moduleBase, -13)
.arg(mod.LoadedImageName);
.arg(QString::fromUtf8(mod.LoadedImageName));
context->stream << line << '\n';

QString pdbName(mod.LoadedPdbName);
const auto pdbName = QString::fromUtf8(mod.LoadedPdbName);
if(!pdbName.isEmpty())
{
QString line2 = QString::fromLatin1("%1 %2")
.arg("", 35)
.arg(u""_qs, 35)
.arg(pdbName);
context->stream << line2 << '\n';
}
Expand All @@ -119,7 +121,7 @@ BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVO
* Cuts off leading 'dir' path from 'file' path, otherwise leaves it unchanged
* returns true if 'dir' is an ancestor of 'file', otherwise - false
*/
bool straceWin::makeRelativePath(const QString& dir, QString& file)
bool straceWin::makeRelativePath(const QString &dir, QString &file)
{
QString d = QDir::toNativeSeparators(QDir(dir).absolutePath());
QString f = QDir::toNativeSeparators(QFileInfo(file).absoluteFilePath());
Expand Down Expand Up @@ -148,7 +150,7 @@ QString straceWin::getSourcePathAndLineNumber(HANDLE hProcess, DWORD64 addr)

if (SymGetLineFromAddr64(hProcess, addr, &dwDisplacement, &line))
{
QString path(line.FileName);
auto path = QString::fromUtf8(line.FileName);

#if defined STACKTRACE_WIN_PROJECT_PATH || defined STACKTRACE_WIN_MAKEFILE_PATH

Expand All @@ -159,14 +161,14 @@ QString straceWin::getSourcePathAndLineNumber(HANDLE hProcess, DWORD64 addr)

bool success = false;
#ifdef STACKTRACE_WIN_PROJECT_PATH
QString projectPath(STACKTRACE_WIN_STRING(STACKTRACE_WIN_PROJECT_PATH));
const auto projectPath = QStringLiteral(STACKTRACE_WIN_STRING(STACKTRACE_WIN_PROJECT_PATH));
success = makeRelativePath(projectPath, path);
#endif

#ifdef STACKTRACE_WIN_MAKEFILE_PATH
if (!success)
{
QString targetPath(STACKTRACE_WIN_STRING(STACKTRACE_WIN_MAKEFILE_PATH));
const auto targetPath = QStringLiteral(STACKTRACE_WIN_STRING(STACKTRACE_WIN_MAKEFILE_PATH));
makeRelativePath(targetPath, path);
}
#endif
Expand Down Expand Up @@ -285,19 +287,19 @@ const QString straceWin::getBacktrace()
if(StackFrame.AddrPC.Offset != 0)
{ // Valid frame.

QString fileName("???");
auto fileName = u"???"_qs;
if(SymGetModuleInfo64(hProcess, ihsf.InstructionOffset, &mod))
{
fileName = QString(mod.ImageName);
int slashPos = fileName.lastIndexOf('\\');
fileName = QString::fromUtf8(mod.ImageName);
int slashPos = fileName.lastIndexOf(u'\\');
if(slashPos != -1)
fileName = fileName.mid(slashPos + 1);
}
QString funcName;
QString sourceFile;
if(SymFromAddr(hProcess, ihsf.InstructionOffset, &dwDisplacement, pSymbol))
{
funcName = QString(pSymbol->Name);
funcName = QString::fromUtf8(pSymbol->Name);
#ifdef __MINGW32__
demangle(funcName);
#endif
Expand All @@ -317,17 +319,17 @@ const QString straceWin::getBacktrace()
#endif

QString insOffset = QString::fromLatin1("0x%1").arg(ihsf.InstructionOffset, 16, 16, QLatin1Char('0'));
QString formatLine = "#%1 %2 %3 %4";
auto formatLine = u"#%1 %2 %3 %4"_qs;
#ifndef __MINGW32__
formatLine += "(%5)";
formatLine += u"(%5)"_qs;
#endif
QString debugLine = formatLine
.arg(i, 3, 10)
.arg(fileName, -20)
.arg(insOffset, -11)
.arg(funcName)
#ifndef __MINGW32__
.arg(params.join(", "));
.arg(params.join(u", "));

if (!sourceFile.isEmpty())
debugLine += QString::fromLatin1("[ %1 ]").arg(sourceFile);
Expand Down
2 changes: 1 addition & 1 deletion src/app/stacktracedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ StacktraceDialog::~StacktraceDialog()
void StacktraceDialog::setStacktraceString(const QString &sigName, const QString &trace)
{
// try to call Qt function as less as possible
const QString htmlStr = QString(
const QString htmlStr = QStringLiteral(
"<p align=center><b><font size=7 color=red>"
"qBittorrent has crashed"
"</font></b></p>"
Expand Down
2 changes: 1 addition & 1 deletion src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3170,7 +3170,7 @@ void Session::setOSMemoryPriority(const OSMemoryPriority priority)
void Session::applyOSMemoryPriority() const
{
using SETPROCESSINFORMATION = BOOL (WINAPI *)(HANDLE, PROCESS_INFORMATION_CLASS, LPVOID, DWORD);
const auto setProcessInformation = Utils::Misc::loadWinAPI<SETPROCESSINFORMATION>("Kernel32.dll", "SetProcessInformation");
const auto setProcessInformation = Utils::Misc::loadWinAPI<SETPROCESSINFORMATION>(u"Kernel32.dll"_qs, "SetProcessInformation");
if (!setProcessInformation) // only available on Windows >= 8
return;

Expand Down
16 changes: 8 additions & 8 deletions src/base/utils/foreignapps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace
bool found = false;
while (!found && !versions.empty())
{
const QString version = versions.takeLast() + "\\InstallPath";
const QString version = versions.takeLast() + u"\\InstallPath";
LPWSTR lpSubkey = new WCHAR[version.size() + 1];
version.toWCharArray(lpSubkey);
lpSubkey[version.size()] = 0;
Expand All @@ -205,15 +205,15 @@ namespace
{
const QDir baseDir {path};

if (baseDir.exists("python3.exe"))
if (baseDir.exists(u"python3.exe"_qs))
{
found = true;
path = baseDir.filePath("python3.exe");
path = baseDir.filePath(u"python3.exe"_qs);
}
else if (baseDir.exists("python.exe"))
else if (baseDir.exists(u"python.exe"_qs))
{
found = true;
path = baseDir.filePath("python.exe");
path = baseDir.filePath(u"python.exe"_qs);
}
}
}
Expand Down Expand Up @@ -243,14 +243,14 @@ namespace
return path;

// Fallback: Detect python from default locations
const QFileInfoList dirs = QDir("C:/").entryInfoList({"Python*"}, QDir::Dirs, (QDir::Name | QDir::Reversed));
const QFileInfoList dirs = QDir(u"C:/"_qs).entryInfoList({u"Python*"_qs}, QDir::Dirs, (QDir::Name | QDir::Reversed));
for (const QFileInfo &info : dirs)
{
const QString py3Path {info.absolutePath() + "/python3.exe"};
const QString py3Path {info.absolutePath() + u"/python3.exe"};
if (QFile::exists(py3Path))
return py3Path;

const QString pyPath {info.absolutePath() + "/python.exe"};
const QString pyPath {info.absolutePath() + u"/python.exe"};
if (QFile::exists(pyPath))
return pyPath;
}
Expand Down
4 changes: 2 additions & 2 deletions src/base/utils/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ namespace Utils::Misc
T loadWinAPI(const QString &source, const char *funcName)
{
QString path = windowsSystemPath();
if (!path.endsWith('\\'))
path += '\\';
if (!path.endsWith(u'\\'))
path += u'\\';

path += source;

Expand Down
5 changes: 3 additions & 2 deletions src/base/utils/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

#include <QString>

#include "misc.h"
#include "base/global.h"
#include "base/utils/misc.h"

namespace
{
Expand All @@ -55,7 +56,7 @@ namespace
using result_type = uint32_t;

RandomLayer()
: m_rtlGenRandom {Utils::Misc::loadWinAPI<PRTLGENRANDOM>("Advapi32.dll", "SystemFunction036")}
: m_rtlGenRandom {Utils::Misc::loadWinAPI<PRTLGENRANDOM>(u"Advapi32.dll"_qs, "SystemFunction036")}
{
if (!m_rtlGenRandom)
qFatal("Failed to load RtlGenRandom()");
Expand Down
12 changes: 6 additions & 6 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ void MainWindow::reloadSessionStats()
}
else if (!MacUtils::badgeLabelText().isEmpty())
{
MacUtils::setBadgeLabelText("");
MacUtils::setBadgeLabelText({});
}
#else
if (m_systrayIcon)
Expand Down Expand Up @@ -1905,8 +1905,8 @@ void MainWindow::handleUpdateCheckFinished(ProgramUpdater *updater, const bool i
const QString newVersion = updater->getNewVersion();
if (!newVersion.isEmpty())
{
const QString msg {tr("A new version is available.") + "<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + "<br/><br/>"
const QString msg {tr("A new version is available.") + u"<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + u"<br/><br/>"
+ QString::fromLatin1("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))};
auto *msgBox = new QMessageBox {QMessageBox::Question, tr("qBittorrent Update Available"), msg
, (QMessageBox::Yes | QMessageBox::No), this};
Expand Down Expand Up @@ -2082,9 +2082,9 @@ void MainWindow::installPython()
setCursor(QCursor(Qt::WaitCursor));
// Download python
#ifdef QBT_APP_64BIT
const QString installerURL = "https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe";
const auto installerURL = u"https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe"_qs;
#else
const QString installerURL = "https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe";
const auto installerURL = u"https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe"_qs;
#endif
Net::DownloadManager::instance()->download(
Net::DownloadRequest(installerURL).saveToFile(true)
Expand All @@ -2109,7 +2109,7 @@ void MainWindow::pythonDownloadFinished(const Net::DownloadResult &result)

const Path exePath = result.filePath + ".exe";
Utils::Fs::renameFile(result.filePath, exePath);
installer.start(exePath.toString(), {"/passive"});
installer.start(exePath.toString(), {u"/passive"_qs});

// Wait for setup to complete
installer.waitForFinished(10 * 60 * 1000);
Expand Down
11 changes: 6 additions & 5 deletions src/gui/programupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QSysInfo>
#endif

#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/utils/version.h"
#include "base/version.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ void ProgramUpdater::checkForUpdates() const
// Don't change this User-Agent. In case our updater goes haywire,
// the filehost can identify it and contact us.
Net::DownloadManager::instance()->download(
Net::DownloadRequest(RSS_URL).userAgent("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)")
Net::DownloadRequest(RSS_URL).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)"))
, this, &ProgramUpdater::rssDownloadFinished);
}

Expand Down Expand Up @@ -108,11 +109,11 @@ void ProgramUpdater::rssDownloadFinished(const Net::DownloadResult &result)
};

#ifdef Q_OS_MACOS
const QString OS_TYPE {"Mac OS X"};
const QString OS_TYPE = u"Mac OS X"_qs;
#elif defined(Q_OS_WIN)
const QString OS_TYPE {(::IsWindows7OrGreater()
&& QSysInfo::currentCpuArchitecture().endsWith("64"))
? "Windows x64" : "Windows"};
const QString OS_TYPE = (::IsWindows7OrGreater() && QSysInfo::currentCpuArchitecture().endsWith(u"64"))
? u"Windows x64"_qs
: u"Windows"_qs;
#endif

bool inItem = false;
Expand Down
4 changes: 3 additions & 1 deletion src/gui/progressbarpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
#include <QProxyStyle>
#endif

#include "base/global.h"

ProgressBarPainter::ProgressBarPainter()
{
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
auto *fusionStyle = new QProxyStyle {"fusion"};
auto *fusionStyle = new QProxyStyle {u"fusion"_qs};
fusionStyle->setParent(&m_dummyProgressBar);
m_dummyProgressBar.setStyle(fusionStyle);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/gui/transferlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
{
switch (section)
{
case TR_QUEUE_POSITION: return u'#';
case TR_QUEUE_POSITION: return QChar(u'#');
case TR_NAME: return tr("Name", "i.e: torrent name");
case TR_SIZE: return tr("Size", "i.e: torrent size");
case TR_PROGRESS: return tr("Progress", "% Done");
Expand Down
1 change: 1 addition & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ include(../version.pri)

# Qt defines
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050f02
DEFINES += QT_NO_CAST_FROM_ASCII
DEFINES += QT_NO_CAST_TO_ASCII
DEFINES += QT_NO_CAST_FROM_BYTEARRAY
DEFINES += QT_USE_QSTRINGBUILDER
Expand Down
Loading