2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
|
|
|
|
*
|
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "AppConfig.h"
|
2015-02-05 14:17:34 +00:00
|
|
|
#include "EditionType.h"
|
2013-06-04 17:37:27 +00:00
|
|
|
#include "QUtility.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QtNetwork>
|
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
const char AppConfig::m_SynergysName[] = "synergys.exe";
|
|
|
|
|
const char AppConfig::m_SynergycName[] = "synergyc.exe";
|
|
|
|
|
const char AppConfig::m_SynergyLogDir[] = "log/";
|
2012-07-28 22:58:51 +00:00
|
|
|
#define DEFAULT_PROCESS_MODE Service
|
2012-06-10 16:50:54 +00:00
|
|
|
#else
|
|
|
|
|
const char AppConfig::m_SynergysName[] = "synergys";
|
|
|
|
|
const char AppConfig::m_SynergycName[] = "synergyc";
|
|
|
|
|
const char AppConfig::m_SynergyLogDir[] = "/var/log/";
|
2012-07-28 22:58:51 +00:00
|
|
|
#define DEFAULT_PROCESS_MODE Desktop
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
2016-06-10 14:43:44 +00:00
|
|
|
const ElevateMode defaultElevateMode = ElevateAsNeeded;
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
static const char* logLevelNames[] =
|
|
|
|
|
{
|
2015-07-09 20:26:31 +00:00
|
|
|
"ERROR",
|
|
|
|
|
"WARNING",
|
|
|
|
|
"NOTE",
|
2012-06-10 16:50:54 +00:00
|
|
|
"INFO",
|
|
|
|
|
"DEBUG",
|
|
|
|
|
"DEBUG1",
|
|
|
|
|
"DEBUG2"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AppConfig::AppConfig(QSettings* settings) :
|
|
|
|
|
m_pSettings(settings),
|
|
|
|
|
m_ScreenName(),
|
|
|
|
|
m_Port(24800),
|
|
|
|
|
m_Interface(),
|
|
|
|
|
m_LogLevel(0),
|
2013-04-11 16:51:17 +00:00
|
|
|
m_WizardLastRun(0),
|
2014-08-26 11:22:09 +00:00
|
|
|
m_ProcessMode(DEFAULT_PROCESS_MODE),
|
2014-11-28 11:21:45 +00:00
|
|
|
m_AutoConfig(true),
|
2016-06-07 16:20:22 +00:00
|
|
|
m_ElevateMode(defaultElevateMode),
|
2015-02-12 15:50:08 +00:00
|
|
|
m_AutoConfigPrompted(false),
|
2015-04-23 14:37:07 +00:00
|
|
|
m_CryptoEnabled(false),
|
2015-11-17 22:51:04 +00:00
|
|
|
m_AutoHide(false),
|
|
|
|
|
m_LastExpiringWarningTime(0)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_pSettings);
|
|
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppConfig::~AppConfig()
|
|
|
|
|
{
|
|
|
|
|
saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 14:03:49 +00:00
|
|
|
const QString &AppConfig::screenName() const { return m_ScreenName; }
|
|
|
|
|
|
|
|
|
|
int AppConfig::port() const { return m_Port; }
|
|
|
|
|
|
|
|
|
|
const QString &AppConfig::interface() const { return m_Interface; }
|
|
|
|
|
|
|
|
|
|
int AppConfig::logLevel() const { return m_LogLevel; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::logToFile() const { return m_LogToFile; }
|
|
|
|
|
|
|
|
|
|
const QString &AppConfig::logFilename() const { return m_LogFilename; }
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
QString AppConfig::synergyLogDir() const
|
|
|
|
|
{
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
// on windows, we want to log to program files
|
|
|
|
|
return synergyProgramDir() + "log/";
|
|
|
|
|
#else
|
|
|
|
|
// on unix, we'll log to the standard log dir
|
|
|
|
|
return "/var/log/";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AppConfig::synergyProgramDir() const
|
|
|
|
|
{
|
|
|
|
|
// synergy binaries should be in the same dir.
|
|
|
|
|
return QCoreApplication::applicationDirPath() + "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::persistLogDir()
|
|
|
|
|
{
|
|
|
|
|
QDir dir = synergyLogDir();
|
|
|
|
|
|
|
|
|
|
// persist the log directory
|
|
|
|
|
if (!dir.exists())
|
|
|
|
|
{
|
|
|
|
|
dir.mkpath(dir.path());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 13:14:12 +00:00
|
|
|
const QString AppConfig::logFilenameCmd() const
|
2014-06-18 12:59:30 +00:00
|
|
|
{
|
|
|
|
|
QString filename = m_LogFilename;
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
// wrap in quotes in case username contains spaces.
|
|
|
|
|
filename = QString("\"%1\"").arg(filename);
|
|
|
|
|
#endif
|
|
|
|
|
return filename;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
QString AppConfig::logLevelText() const
|
|
|
|
|
{
|
|
|
|
|
return logLevelNames[logLevel()];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 14:03:49 +00:00
|
|
|
ProcessMode AppConfig::processMode() const { return m_ProcessMode; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::wizardShouldRun() const { return m_WizardLastRun < kWizardVersion; }
|
|
|
|
|
|
|
|
|
|
const QString &AppConfig::language() const { return m_Language; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::startedBefore() const { return m_StartedBefore; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::autoConfig() const { return m_AutoConfig; }
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
void AppConfig::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
m_ScreenName = settings().value("screenName", QHostInfo::localHostName()).toString();
|
|
|
|
|
m_Port = settings().value("port", 24800).toInt();
|
|
|
|
|
m_Interface = settings().value("interface").toString();
|
2015-07-09 20:26:31 +00:00
|
|
|
m_LogLevel = settings().value("logLevel", 3).toInt(); // level 3: INFO
|
2012-06-10 16:50:54 +00:00
|
|
|
m_LogToFile = settings().value("logToFile", false).toBool();
|
|
|
|
|
m_LogFilename = settings().value("logFilename", synergyLogDir() + "synergy.log").toString();
|
2013-04-11 16:51:17 +00:00
|
|
|
m_WizardLastRun = settings().value("wizardLastRun", 0).toInt();
|
2013-05-29 20:46:24 +00:00
|
|
|
m_Language = settings().value("language", QLocale::system().name()).toString();
|
2014-03-21 09:22:18 +00:00
|
|
|
m_StartedBefore = settings().value("startedBefore", false).toBool();
|
2014-11-28 11:21:45 +00:00
|
|
|
m_AutoConfig = settings().value("autoConfig", true).toBool();
|
2016-06-07 16:20:22 +00:00
|
|
|
QVariant elevateMode = settings().value("elevateModeEnum");
|
|
|
|
|
if (!elevateMode.isValid()) {
|
|
|
|
|
elevateMode = settings().value ("elevateMode",
|
|
|
|
|
QVariant(static_cast<int>(defaultElevateMode)));
|
|
|
|
|
}
|
|
|
|
|
m_ElevateMode = static_cast<ElevateMode>(elevateMode.toInt());
|
2014-11-28 10:51:52 +00:00
|
|
|
m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool();
|
2016-09-30 14:03:49 +00:00
|
|
|
m_Edition = settings().value("edition", Unregistered).toInt();
|
2015-02-05 14:17:34 +00:00
|
|
|
m_ActivateEmail = settings().value("activateEmail", "").toString();
|
2016-09-30 16:01:43 +00:00
|
|
|
m_CryptoEnabled = settings().value("cryptoEnabled", true).toBool();
|
2015-04-23 14:37:07 +00:00
|
|
|
m_AutoHide = settings().value("autoHide", false).toBool();
|
2015-10-22 23:31:46 +00:00
|
|
|
m_Serialkey = settings().value("serialKey", "").toString();
|
2015-11-17 22:51:04 +00:00
|
|
|
m_LastExpiringWarningTime = settings().value("lastExpiringWarningTime", 0).toInt();
|
2016-09-30 15:04:49 +00:00
|
|
|
m_ActivationHasRun = settings().value("activationHasRun", false).toBool();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::saveSettings()
|
|
|
|
|
{
|
|
|
|
|
settings().setValue("screenName", m_ScreenName);
|
|
|
|
|
settings().setValue("port", m_Port);
|
|
|
|
|
settings().setValue("interface", m_Interface);
|
|
|
|
|
settings().setValue("logLevel", m_LogLevel);
|
|
|
|
|
settings().setValue("logToFile", m_LogToFile);
|
|
|
|
|
settings().setValue("logFilename", m_LogFilename);
|
2013-04-11 16:51:17 +00:00
|
|
|
settings().setValue("wizardLastRun", kWizardVersion);
|
2013-05-29 20:46:24 +00:00
|
|
|
settings().setValue("language", m_Language);
|
2014-03-21 09:22:18 +00:00
|
|
|
settings().setValue("startedBefore", m_StartedBefore);
|
2014-11-28 10:51:52 +00:00
|
|
|
settings().setValue("autoConfig", m_AutoConfig);
|
2016-06-07 16:20:22 +00:00
|
|
|
// Refer to enum ElevateMode declaration for insight in to why this
|
|
|
|
|
// flag is mapped this way
|
|
|
|
|
settings().setValue("elevateMode", m_ElevateMode == ElevateAlways);
|
|
|
|
|
settings().setValue("elevateModeEnum", static_cast<int>(m_ElevateMode));
|
2014-11-28 10:51:52 +00:00
|
|
|
settings().setValue("autoConfigPrompted", m_AutoConfigPrompted);
|
2015-02-05 14:17:34 +00:00
|
|
|
settings().setValue("edition", m_Edition);
|
|
|
|
|
settings().setValue("activateEmail", m_ActivateEmail);
|
2015-02-12 15:50:08 +00:00
|
|
|
settings().setValue("cryptoEnabled", m_CryptoEnabled);
|
2015-04-23 14:37:07 +00:00
|
|
|
settings().setValue("autoHide", m_AutoHide);
|
2015-10-22 23:31:46 +00:00
|
|
|
settings().setValue("serialKey", m_Serialkey);
|
2015-11-17 22:51:04 +00:00
|
|
|
settings().setValue("lastExpiringWarningTime", m_LastExpiringWarningTime);
|
2016-09-30 15:04:49 +00:00
|
|
|
settings().setValue("activationHasRun", m_ActivationHasRun);
|
2016-10-03 14:27:38 +00:00
|
|
|
settings().sync();
|
2016-09-30 15:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppConfig::activationHasRun() const
|
|
|
|
|
{
|
|
|
|
|
return m_ActivationHasRun;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppConfig& AppConfig::activationHasRun(bool value)
|
|
|
|
|
{
|
|
|
|
|
m_ActivationHasRun = value;
|
|
|
|
|
return *this;
|
2013-04-11 16:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-30 14:03:49 +00:00
|
|
|
QSettings &AppConfig::settings() { return *m_pSettings; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setScreenName(const QString &s) { m_ScreenName = s; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setPort(int i) { m_Port = i; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setInterface(const QString &s) { m_Interface = s; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogLevel(int i) { m_LogLevel = i; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogToFile(bool b) { m_LogToFile = b; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogFilename(const QString &s) { m_LogFilename = s; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setWizardHasRun() { m_WizardLastRun = kWizardVersion; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLanguage(const QString language) { m_Language = language; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setStartedBefore(bool b) { m_StartedBefore = b; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setElevateMode(ElevateMode em) { m_ElevateMode = em; }
|
|
|
|
|
|
2014-11-28 10:51:52 +00:00
|
|
|
void AppConfig::setAutoConfig(bool autoConfig)
|
2014-08-26 11:22:09 +00:00
|
|
|
{
|
2014-11-28 10:51:52 +00:00
|
|
|
m_AutoConfig = autoConfig;
|
2014-08-26 11:22:09 +00:00
|
|
|
}
|
2014-10-27 17:10:12 +00:00
|
|
|
|
2016-09-30 14:03:49 +00:00
|
|
|
bool AppConfig::autoConfigPrompted() { return m_AutoConfigPrompted; }
|
|
|
|
|
|
2014-11-28 10:51:52 +00:00
|
|
|
void AppConfig::setAutoConfigPrompted(bool prompted)
|
2014-11-12 16:44:25 +00:00
|
|
|
{
|
2014-11-28 10:51:52 +00:00
|
|
|
m_AutoConfigPrompted = prompted;
|
2014-11-12 16:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-04 12:41:27 +00:00
|
|
|
void AppConfig::setEdition(int e) {
|
|
|
|
|
m_Edition = e;
|
|
|
|
|
emit editionSet (e);
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2016-09-30 16:01:43 +00:00
|
|
|
int AppConfig::edition() const { return m_Edition; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
|
|
|
|
bool AppConfig::setActivateEmail(QString e) {
|
|
|
|
|
m_ActivateEmail = e;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AppConfig::activateEmail() { return m_ActivateEmail; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::setSerialKey(QString serial, QString& errorOut) {
|
|
|
|
|
if (serial.isEmpty()) {
|
|
|
|
|
errorOut = "Your serial key cannot be blank.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_Serialkey = serial;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::clearSerialKey()
|
|
|
|
|
{
|
|
|
|
|
m_Serialkey.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AppConfig::serialKey() { return m_Serialkey; }
|
|
|
|
|
|
|
|
|
|
int AppConfig::lastExpiringWarningTime() const { return m_LastExpiringWarningTime; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLastExpiringWarningTime(int t) { m_LastExpiringWarningTime = t; }
|
|
|
|
|
|
|
|
|
|
QString AppConfig::synergysName() const { return m_SynergysName; }
|
|
|
|
|
|
|
|
|
|
QString AppConfig::synergycName() const { return m_SynergycName; }
|
|
|
|
|
|
2016-06-07 16:20:22 +00:00
|
|
|
ElevateMode AppConfig::elevateMode()
|
2014-10-27 17:10:12 +00:00
|
|
|
{
|
|
|
|
|
return m_ElevateMode;
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
|
|
|
|
void AppConfig::setCryptoEnabled(bool e) { m_CryptoEnabled = e; }
|
|
|
|
|
|
2016-09-30 16:01:43 +00:00
|
|
|
bool AppConfig::getCryptoEnabled() const {
|
|
|
|
|
return (edition() == Pro) && m_CryptoEnabled;
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
|
|
|
|
void AppConfig::setAutoHide(bool b) { m_AutoHide = b; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::getAutoHide() { return m_AutoHide; }
|