Skip to content

Commit

Permalink
Disable autostartCheckBox if autostart is configured system wide
Browse files Browse the repository at this point in the history
  • Loading branch information
dschmidt committed Oct 17, 2018
1 parent 9c7bc80 commit ab360e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ QByteArray Utility::userAgentString()
return re.toLatin1();
}

bool Utility::hasSystemLaunchOnStartup(const QString &appName)
{
#if defined(Q_OS_WIN)
return hasSystemLaunchOnStartup_private(appName);
#else
return false;
#endif
}

bool Utility::hasLaunchOnStartup(const QString &appName)
{
return hasLaunchOnStartup_private(appName);
Expand Down
9 changes: 9 additions & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ namespace Utility {
OCSYNC_EXPORT bool writeRandomFile(const QString &fname, int size = -1);
OCSYNC_EXPORT QString octetsToString(qint64 octets);
OCSYNC_EXPORT QByteArray userAgentString();
/**
* @brief Return whether launch on startup is enabled system wide.
*
* If this returns true, the checkbox for user specific launch
* on startup will be hidden.
*
* Currently only implemented on Windows.
*/
OCSYNC_EXPORT bool hasSystemLaunchOnStartup(const QString &appName);
OCSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
OCSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString &guiName, bool launch);

Expand Down
7 changes: 7 additions & 0 deletions src/common/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <QLibrary>

static const char systemRunPathC[] = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";

namespace OCC {
Expand Down Expand Up @@ -67,6 +68,12 @@ static void setupFavLink_private(const QString &folder)
qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
}

bool hasSystemLaunchOnStartup_private(const QString &appName)
{
QString runPath = QLatin1String(systemRunPathC);
QSettings settings(runPath, QSettings::NativeFormat);
return settings.contains(appName);
}

bool hasLaunchOnStartup_private(const QString &appName)
{
Expand Down
11 changes: 8 additions & 3 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ GeneralSettings::GeneralSettings(QWidget *parent)
this, &GeneralSettings::slotToggleOptionalDesktopNotifications);
connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane);

_ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName()));
connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup);

if(Utility::hasSystemLaunchOnStartup(Theme::instance()->appName())) {
_ui->autostartCheckBox->setChecked(true);
_ui->autostartCheckBox->setDisabled(true);
_ui->autostartCheckBox->setToolTip(tr("You cannot disable autostart because system-wide autostart is enabled."));
} else {
_ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName()));
connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup);
}
loadMiscSettings();
slotUpdateInfo();

Expand Down

0 comments on commit ab360e1

Please sign in to comment.