Make Utility::*Startup* testable

This commit is contained in:
Daniel Molkentin 2013-07-06 22:38:33 +02:00
parent c6219581f6
commit fff795146e
4 changed files with 13 additions and 11 deletions

View file

@ -259,7 +259,7 @@ void Application::slotownCloudWizardDone( int res )
int cnt = _folderMan->setupFolders();
qDebug() << "Set up " << cnt << " folders.";
// We have some sort of configuration. Enable autostart
Utility::setLaunchOnStartup(true);
Utility::setLaunchOnStartup(_theme->appName(), _theme->appNameGUI(), true);
// FIXME!
// _statusDialog->setFolderList( _folderMan->map() );
}

View file

@ -44,7 +44,7 @@ GeneralSettings::GeneralSettings(QWidget *parent) :
connect(_ui->desktopNotificationsCheckBox, SIGNAL(toggled(bool)),
SLOT(slotToggleOptionalDesktopNotifications(bool)));
_ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup());
_ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName()));
connect(_ui->autostartCheckBox, SIGNAL(toggled(bool)), SLOT(slotToggleLaunchOnStartup(bool)));
// setup about section
@ -135,7 +135,8 @@ void GeneralSettings::saveMiscSettings()
void GeneralSettings::slotToggleLaunchOnStartup(bool enable)
{
Utility::setLaunchOnStartup(enable);
Theme *theme = Theme::instance();
Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), enable);
}
void GeneralSettings::slotToggleOptionalDesktopNotifications(bool enable)

View file

@ -14,7 +14,6 @@
#include "utility.h"
#include "mirall/version.h"
#include "mirall/theme.h"
#include <QCoreApplication>
#include <QSettings>
@ -162,9 +161,8 @@ void Utility::raiseDialog( QWidget *raiseWidget )
static const char runPathC[] = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
bool Utility::hasLaunchOnStartup()
bool Utility::hasLaunchOnStartup(const QString &appName)
{
QString appName = Theme::instance()->appName();
#if defined(Q_OS_WIN)
QString runPath(QLatin1String(runPathC));
QSettings settings(runPath, QSettings::NativeFormat);
@ -178,9 +176,11 @@ bool Utility::hasLaunchOnStartup()
#endif
}
void Utility::setLaunchOnStartup(bool enable)
namespace {
}
void Utility::setLaunchOnStartup(const QString &appName, const QString& guiName, bool enable)
{
QString appName = Theme::instance()->appName();
#if defined(Q_OS_WIN)
QString runPath(QLatin1String(runPathC));
QSettings settings(runPath, QSettings::NativeFormat);
@ -190,6 +190,7 @@ void Utility::setLaunchOnStartup(bool enable)
settings.remove(appName);
}
#elif defined(Q_OS_MAC)
Q_UNUSED(guiName)
if (enable) {
// Finder: Place under "Places"/"Favorites" on the left sidebar
QString filePath = QDir(applicationDirPath+QLatin1String("/../..")).absolutePath();
@ -221,7 +222,7 @@ void Utility::setLaunchOnStartup(bool enable)
}
QSettings desktopFile(desktopFileLocation, QSettings::IniFormat);
desktopFile.beginGroup("Desktop Entry");
desktopFile.setValue(QLatin1String("Name"), Theme::instance()->appNameGUI());
desktopFile.setValue(QLatin1String("Name"), guiName);
desktopFile.setValue(QLatin1String("GenericName"), QLatin1String("File Synchronizer"));
desktopFile.setValue(QLatin1String("Exec"), QCoreApplication::applicationFilePath());
desktopFile.setValue(QLatin1String("Terminal"), false);

View file

@ -29,8 +29,8 @@ namespace Utility
QString platform();
QByteArray userAgentString();
void raiseDialog(QWidget *);
bool hasLaunchOnStartup();
void setLaunchOnStartup(bool launch);
bool hasLaunchOnStartup(const QString &appName);
void setLaunchOnStartup(const QString &appName, const QString& guiName, bool launch);
}
}