Skip to content

Commit

Permalink
Save the value of 'Launch on system startup' in the config files.
Browse files Browse the repository at this point in the history
Make sure to migrate older configs to have the value set to true.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Jan 19, 2024
1 parent 5990b6c commit 2c3738b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ bool Application::configVersionMigration()
return true;
}

// 'Launch on system startup' defaults to true > 3.11.x
const auto theme = Theme::instance();
configFile.setLaunchOnSystemStartup(configFile.launchOnSystemStartup());
Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), configFile.launchOnSystemStartup());

// back up all old config files
QStringList backupFilesList;
QDir configDir(configFile.configPath());
Expand Down
11 changes: 8 additions & 3 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ GeneralSettings::GeneralSettings(QWidget *parent)
_ui->autostartCheckBox->setChecked(hasSystemAutoStart);
_ui->autostartCheckBox->setDisabled(hasSystemAutoStart);
_ui->autostartCheckBox->setToolTip(tr("You cannot disable autostart because system-wide autostart is enabled."));
} else {
const auto hasAutoStart = Utility::hasLaunchOnStartup(Theme::instance()->appName());
} else {
connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup);
_ui->autostartCheckBox->setChecked(hasAutoStart);
_ui->autostartCheckBox->setChecked(ConfigFile().launchOnSystemStartup());
}

// setup about section
Expand Down Expand Up @@ -454,7 +453,13 @@ void GeneralSettings::saveMiscSettings()

void GeneralSettings::slotToggleLaunchOnStartup(bool enable)
{
ConfigFile configFile;

Check warning on line 456 in src/gui/generalsettings.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/generalsettings.cpp:456:16 [cppcoreguidelines-init-variables]

variable 'configFile' is not initialized
if (enable == Utility::hasLaunchOnStartup(Theme::instance()->appName())) {
return;
}

const auto theme = Theme::instance();
configFile.setLaunchOnSystemStartup(enable);
Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), enable);
}

Expand Down
13 changes: 13 additions & 0 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static constexpr char logExpireC[] = "logExpire";
static constexpr char logFlushC[] = "logFlush";
static constexpr char showExperimentalOptionsC[] = "showExperimentalOptions";
static constexpr char clientVersionC[] = "clientVersion";
static constexpr char launchOnSystemStartupC[] = "launchOnSystemStartup";

Check warning on line 87 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:87:23 [readability-static-definition-in-anonymous-namespace]

'launchOnSystemStartupC' is a static definition in anonymous namespace; static is redundant here

static constexpr char proxyHostC[] = "Proxy/host";
static constexpr char proxyTypeC[] = "Proxy/type";
Expand Down Expand Up @@ -1152,6 +1153,18 @@ void ConfigFile::setClientVersionString(const QString &version)
settings.setValue(QLatin1String(clientVersionC), version);
}

bool ConfigFile::launchOnSystemStartup() const
{
QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(launchOnSystemStartupC), true).toBool();
}

void ConfigFile::setLaunchOnSystemStartup(const bool autostart)
{
QSettings settings(configFile(), QSettings::IniFormat);
settings.setValue(QLatin1String(launchOnSystemStartupC), autostart);
}

Q_GLOBAL_STATIC(QString, g_configFileName)

std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, QObject *parent)
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
[[nodiscard]] QString clientVersionString() const;
void setClientVersionString(const QString &version);

/** If the option 'Launch on system startup' is set
Updated by configVersionMigration() at client startup. */
[[nodiscard]] bool launchOnSystemStartup() const;
void setLaunchOnSystemStartup(const bool autostart);

/** Returns a new settings pre-set in a specific group. The Settings will be created
with the given parent. If no parent is specified, the caller must destroy the settings */
static std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = nullptr);
Expand Down

0 comments on commit 2c3738b

Please sign in to comment.