Browse Source

Merge pull request #11847 from glassez/legacy-defaults

Keep legacy defaults for existing users
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
1e63dcb400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      src/app/main.cpp
  2. 20
      src/app/upgrade.cpp
  3. 7
      src/app/upgrade.h

48
src/app/main.cpp

@ -168,22 +168,25 @@ int main(int argc, char *argv[]) @@ -168,22 +168,25 @@ int main(int argc, char *argv[])
if (!qputenv("QBITTORRENT", QBT_VERSION))
fprintf(stderr, "Couldn't set environment variable...\n");
const bool firstTimeUser = !Preferences::instance()->getAcceptedLegal();
if (firstTimeUser) {
#ifndef DISABLE_GUI
if (!userAgreesWithLegalNotice())
return EXIT_SUCCESS;
if (!userAgreesWithLegalNotice())
return EXIT_SUCCESS;
#elif defined(Q_OS_WIN)
if (_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout))
&& !userAgreesWithLegalNotice())
return EXIT_SUCCESS;
if (_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout))
&& !userAgreesWithLegalNotice())
return EXIT_SUCCESS;
#else
if (!params.shouldDaemonize
&& isatty(fileno(stdin))
&& isatty(fileno(stdout))
&& !userAgreesWithLegalNotice())
return EXIT_SUCCESS;
if (!params.shouldDaemonize
&& isatty(fileno(stdin))
&& isatty(fileno(stdout))
&& !userAgreesWithLegalNotice())
return EXIT_SUCCESS;
#endif
}
// Check if qBittorrent is already running for this user
if (app->isRunning()) {
@ -233,16 +236,24 @@ int main(int argc, char *argv[]) @@ -233,16 +236,24 @@ int main(int argc, char *argv[])
app->setAttribute(Qt::AA_DontShowIconsInMenus);
#endif
if (!firstTimeUser) {
handleChangedDefaults(DefaultPreferencesMode::Legacy);
#ifndef DISABLE_GUI
if (!upgrade()) return EXIT_FAILURE;
if (!upgrade()) return EXIT_FAILURE;
#elif defined(Q_OS_WIN)
if (!upgrade(_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout)))) return EXIT_FAILURE;
if (!upgrade(_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout)))) return EXIT_FAILURE;
#else
if (!upgrade(!params.shouldDaemonize
&& isatty(fileno(stdin))
&& isatty(fileno(stdout)))) return EXIT_FAILURE;
if (!upgrade(!params.shouldDaemonize
&& isatty(fileno(stdin))
&& isatty(fileno(stdout)))) return EXIT_FAILURE;
#endif
}
else {
handleChangedDefaults(DefaultPreferencesMode::Current);
}
#if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
if (params.shouldDaemonize) {
app.reset(); // Destroy current application
@ -378,8 +389,7 @@ void displayBadArgMessage(const QString &message) @@ -378,8 +389,7 @@ void displayBadArgMessage(const QString &message)
bool userAgreesWithLegalNotice()
{
Preferences *const pref = Preferences::instance();
if (pref->getAcceptedLegal()) // Already accepted once
return true;
Q_ASSERT(!pref->getAcceptedLegal());
#ifdef DISABLE_GUI
const QString eula = QString("\n*** %1 ***\n").arg(QObject::tr("Legal Notice"))

20
src/app/upgrade.cpp

@ -82,3 +82,23 @@ bool upgrade(const bool /*ask*/) @@ -82,3 +82,23 @@ bool upgrade(const bool /*ask*/)
exportWebUIHttpsFiles();
return true;
}
void handleChangedDefaults(const DefaultPreferencesMode mode)
{
struct DefaultValue
{
QString name;
QVariant legacy;
QVariant current;
};
const QVector<DefaultValue> changedDefaults {
{QLatin1String {"BitTorrent/Session/QueueingSystemEnabled"}, true, false}
};
SettingsStorage *settingsStorage {SettingsStorage::instance()};
for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it) {
if (settingsStorage->loadValue(it->name).isNull())
settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current));
}
}

7
src/app/upgrade.h

@ -28,4 +28,11 @@ @@ -28,4 +28,11 @@
#pragma once
enum class DefaultPreferencesMode
{
Legacy,
Current
};
void handleChangedDefaults(DefaultPreferencesMode mode);
bool upgrade(bool ask = true);

Loading…
Cancel
Save