Merge pull request #10220 from thalieht/const

Add const to many vars and arguments
This commit is contained in:
Mike Tzou
2019-02-13 12:11:00 +08:00
committed by GitHub
34 changed files with 299 additions and 301 deletions

View File

@@ -127,7 +127,7 @@ Application::Application(const QString &id, int &argc, char **argv)
setApplicationName("qBittorrent");
validateCommandLineParameters();
QString profileDir = m_commandLineArgs.portableMode
const QString profileDir = m_commandLineArgs.portableMode
? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR)
: m_commandLineArgs.profileDir;
@@ -185,7 +185,7 @@ bool Application::isFileLoggerEnabled() const
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool();
}
void Application::setFileLoggerEnabled(bool value)
void Application::setFileLoggerEnabled(const bool value)
{
if (value && !m_fileLogger)
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
@@ -212,7 +212,7 @@ bool Application::isFileLoggerBackup() const
return settings()->loadValue(KEY_FILELOGGER_BACKUP, true).toBool();
}
void Application::setFileLoggerBackup(bool value)
void Application::setFileLoggerBackup(const bool value)
{
if (m_fileLogger)
m_fileLogger->setBackup(value);
@@ -224,7 +224,7 @@ bool Application::isFileLoggerDeleteOld() const
return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true).toBool();
}
void Application::setFileLoggerDeleteOld(bool value)
void Application::setFileLoggerDeleteOld(const bool value)
{
if (value && m_fileLogger)
m_fileLogger->deleteOld(fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
@@ -233,13 +233,13 @@ void Application::setFileLoggerDeleteOld(bool value)
int Application::fileLoggerMaxSize() const
{
int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE).toInt();
const int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE).toInt();
return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
}
void Application::setFileLoggerMaxSize(const int bytes)
{
int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
const int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
if (m_fileLogger)
m_fileLogger->setMaxSize(clampedValue);
settings()->storeValue(KEY_FILELOGGER_MAXSIZEBYTES, clampedValue);
@@ -247,7 +247,7 @@ void Application::setFileLoggerMaxSize(const int bytes)
int Application::fileLoggerAge() const
{
int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1).toInt();
const int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1).toInt();
return std::min(std::max(val, 1), 365);
}
@@ -258,7 +258,7 @@ void Application::setFileLoggerAge(const int value)
int Application::fileLoggerAgeType() const
{
int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt();
const int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt();
return ((val < 0) || (val > 2)) ? 1 : val;
}
@@ -269,7 +269,7 @@ void Application::setFileLoggerAgeType(const int value)
void Application::processMessage(const QString &message)
{
QStringList params = message.split(PARAMS_SEPARATOR, QString::SkipEmptyParts);
const QStringList params = message.split(PARAMS_SEPARATOR, QString::SkipEmptyParts);
// If Application is not running (i.e., other
// components are not ready) store params
if (m_running)
@@ -572,7 +572,7 @@ int Application::exec(const QStringList &params)
#ifdef Q_OS_WIN
bool Application::isRunning()
{
bool running = BaseApplication::isRunning();
const bool running = BaseApplication::isRunning();
QSharedMemory *sharedMem = new QSharedMemory(id() + QLatin1String("-shared-memory-key"), this);
if (!running) {
// First instance creates shared memory and store PID
@@ -622,7 +622,7 @@ void Application::initializeTranslation()
{
Preferences *const pref = Preferences::instance();
// Load translation
QString localeStr = pref->getLocale();
const QString localeStr = pref->getLocale();
if (m_qtTranslator.load(QLatin1String("qtbase_") + localeStr, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) ||
m_qtTranslator.load(QLatin1String("qt_") + localeStr, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))

View File

@@ -99,11 +99,11 @@ public:
bool isFileLoggerDeleteOld() const;
void setFileLoggerDeleteOld(bool value);
int fileLoggerMaxSize() const;
void setFileLoggerMaxSize(const int bytes);
void setFileLoggerMaxSize(int bytes);
int fileLoggerAge() const;
void setFileLoggerAge(const int value);
void setFileLoggerAge(int value);
int fileLoggerAgeType() const;
void setFileLoggerAgeType(const int value);
void setFileLoggerAgeType(int value);
protected:
#ifndef DISABLE_GUI

View File

@@ -276,7 +276,7 @@ namespace
TriStateBool value(const QProcessEnvironment &env) const
{
QString val = env.value(envVarName(), "-1");
const QString val = env.value(envVarName(), "-1");
if (val.isEmpty()) {
return TriStateBool(m_defaultValue);

View File

@@ -85,8 +85,8 @@ void FileLogger::changePath(const QString &newPath)
void FileLogger::deleteOld(const int age, const FileLogAgeType ageType)
{
QDateTime date = QDateTime::currentDateTime();
QDir dir(Utils::Fs::branchPath(m_path));
const QDateTime date = QDateTime::currentDateTime();
const QDir dir(Utils::Fs::branchPath(m_path));
for (const QFileInfo &file : asConst(dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed))) {
QDateTime modificationDate = file.lastModified();
@@ -111,7 +111,7 @@ void FileLogger::setBackup(bool value)
m_backup = value;
}
void FileLogger::setMaxSize(int value)
void FileLogger::setMaxSize(const int value)
{
m_maxSize = value;
}

View File

@@ -52,11 +52,11 @@ public:
YEARS
};
FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType);
FileLogger(const QString &path, bool backup, int maxSize, bool deleteOld, int age, FileLogAgeType ageType);
~FileLogger();
void changePath(const QString &newPath);
void deleteOld(const int age, const FileLogAgeType ageType);
void deleteOld(int age, FileLogAgeType ageType);
void setBackup(bool value);
void setMaxSize(int value);

View File

@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
try {
// Create Application
QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString();
const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString();
QScopedPointer<Application> app(new Application(appId, argc, argv));
const QBtCommandLineParameters params = app->commandLineArgs();
@@ -255,7 +255,7 @@ void reportToUser(const char *str)
{
const size_t strLen = strlen(str);
if (write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) {
auto dummy = write(STDOUT_FILENO, str, strLen);
const auto dummy = write(STDOUT_FILENO, str, strLen);
Q_UNUSED(dummy);
}
}
@@ -305,7 +305,7 @@ void showSplashScreen()
{
QPixmap splashImg(":/icons/skin/splash.png");
QPainter painter(&splashImg);
QString version = QBT_VERSION;
const QString version = QBT_VERSION;
painter.setPen(QPen(Qt::white));
painter.setFont(QFont("Arial", 22, QFont::Black));
painter.drawText(224 - painter.fontMetrics().width(version), 270, version);
@@ -323,7 +323,7 @@ void displayVersion()
void displayBadArgMessage(const QString &message)
{
QString help = QObject::tr("Run application with -h option to read about command line parameters.");
const QString help = QObject::tr("Run application with -h option to read about command line parameters.");
#ifdef Q_OS_WIN
QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"),
message + QLatin1Char('\n') + help, QMessageBox::Ok);
@@ -351,7 +351,7 @@ bool userAgreesWithLegalNotice()
+ QObject::tr("Press %1 key to accept and continue...").arg("'y'") + '\n';
printf("%s", qUtf8Printable(eula));
char ret = getchar(); // Read pressed key
const char ret = getchar(); // Read pressed key
if ((ret == 'y') || (ret == 'Y')) {
// Save the answer
pref->setAcceptedLegal(true);
@@ -362,7 +362,7 @@ bool userAgreesWithLegalNotice()
msgBox.setText(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\nNo further notices will be issued."));
msgBox.setWindowTitle(QObject::tr("Legal notice"));
msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole);
QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole);
const QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole);
msgBox.show(); // Need to be shown or to moveToCenter does not work
msgBox.move(Utils::Misc::screenCenter(&msgBox));
msgBox.exec();