2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2012 Bolton Software 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
|
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
|
*
|
|
|
|
|
* 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"
|
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
|
|
|
|
|
|
|
|
|
|
static const char* logLevelNames[] =
|
|
|
|
|
{
|
|
|
|
|
"ERROR",
|
|
|
|
|
"WARNING",
|
|
|
|
|
"NOTE",
|
|
|
|
|
"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),
|
|
|
|
|
m_CryptoPass(),
|
2012-07-28 22:58:51 +00:00
|
|
|
m_ProcessMode(DEFAULT_PROCESS_MODE)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_pSettings);
|
|
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppConfig::~AppConfig()
|
|
|
|
|
{
|
|
|
|
|
saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AppConfig::logLevelText() const
|
|
|
|
|
{
|
|
|
|
|
return logLevelNames[logLevel()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
m_ScreenName = settings().value("screenName", QHostInfo::localHostName()).toString();
|
|
|
|
|
m_Port = settings().value("port", 24800).toInt();
|
|
|
|
|
m_Interface = settings().value("interface").toString();
|
2013-09-18 08:34:32 +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();
|
|
|
|
|
m_CryptoPass = settings().value("cryptoPass", "").toString();
|
2013-08-16 18:06:30 +00:00
|
|
|
m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool();
|
2013-05-29 20:46:24 +00:00
|
|
|
m_Language = settings().value("language", QLocale::system().name()).toString();
|
2013-09-18 08:34:32 +00:00
|
|
|
m_PremiumEmail = settings().value("premiumEmail", "").toString();
|
2013-06-04 17:37:27 +00:00
|
|
|
m_PremiumToken = settings().value("premiumToken", "").toString();
|
2014-03-21 09:22:18 +00:00
|
|
|
m_StartedBefore = settings().value("startedBefore", 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);
|
|
|
|
|
settings().setValue("cryptoPass", m_CryptoPass);
|
2013-08-16 18:06:30 +00:00
|
|
|
settings().setValue("cryptoEnabled", m_CryptoEnabled);
|
2013-05-29 20:46:24 +00:00
|
|
|
settings().setValue("language", m_Language);
|
2013-06-04 17:37:27 +00:00
|
|
|
settings().setValue("premiumEmail", m_PremiumEmail);
|
|
|
|
|
settings().setValue("premiumToken", m_PremiumToken);
|
2014-03-21 09:22:18 +00:00
|
|
|
settings().setValue("startedBefore", m_StartedBefore);
|
2013-04-11 16:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setCryptoPass(const QString &s)
|
|
|
|
|
{
|
|
|
|
|
// clear field to user doesn't get confused.
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
m_CryptoPass.clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only hash if password changes -- don't re-hash the hash.
|
|
|
|
|
if (m_CryptoPass != s)
|
|
|
|
|
{
|
|
|
|
|
m_CryptoPass = hash(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-04 17:37:27 +00:00
|
|
|
bool AppConfig::isPremium()
|
|
|
|
|
{
|
|
|
|
|
QString hashSrc = m_PremiumEmail + getFirstMacAddress();
|
|
|
|
|
QString hashResult = hash(hashSrc);
|
|
|
|
|
return hashResult == m_PremiumToken;
|
|
|
|
|
}
|