mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Allow only main (IPC owner) instance to save global settings
This commit is contained in:
parent
886ee3ff10
commit
41fd5ab558
|
@ -81,6 +81,15 @@ IPC::~IPC()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPC& IPC::getInstance()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
Q_ASSERT(0 && "IPC can not be used on android");
|
||||||
|
#endif
|
||||||
|
static IPC instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
time_t IPC::postEvent(const QString &name, const QByteArray& data/*=QByteArray()*/, uint32_t dest/*=0*/)
|
time_t IPC::postEvent(const QString &name, const QByteArray& data/*=QByteArray()*/, uint32_t dest/*=0*/)
|
||||||
{
|
{
|
||||||
QByteArray binName = name.toUtf8();
|
QByteArray binName = name.toUtf8();
|
||||||
|
|
|
@ -34,6 +34,7 @@ using IPCEventHandler = std::function<bool (const QByteArray&)>;
|
||||||
class IPC : public QThread
|
class IPC : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
IPC();
|
||||||
protected:
|
protected:
|
||||||
static const int EVENT_TIMER_MS = 1000;
|
static const int EVENT_TIMER_MS = 1000;
|
||||||
static const int EVENT_GC_TIMEOUT = 5;
|
static const int EVENT_GC_TIMEOUT = 5;
|
||||||
|
@ -41,9 +42,10 @@ protected:
|
||||||
static const int OWNERSHIP_TIMEOUT_S = 5;
|
static const int OWNERSHIP_TIMEOUT_S = 5;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IPC();
|
|
||||||
~IPC();
|
~IPC();
|
||||||
|
|
||||||
|
static IPC& getInstance();
|
||||||
|
|
||||||
struct IPCEvent
|
struct IPCEvent
|
||||||
{
|
{
|
||||||
uint32_t dest;
|
uint32_t dest;
|
||||||
|
|
|
@ -70,6 +70,9 @@ int main(int argc, char *argv[])
|
||||||
parser.addOption(QCommandLineOption("p", QObject::tr("Starts new instance and loads specified profile."), QObject::tr("profile")));
|
parser.addOption(QCommandLineOption("p", QObject::tr("Starts new instance and loads specified profile."), QObject::tr("profile")));
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
IPC::getInstance();
|
||||||
|
#endif
|
||||||
Settings::getInstance(); // Build our Settings singleton as soon as QApplication is ready, not before
|
Settings::getInstance(); // Build our Settings singleton as soon as QApplication is ready, not before
|
||||||
|
|
||||||
if (parser.isSet("p"))
|
if (parser.isSet("p"))
|
||||||
|
@ -126,7 +129,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
// Inter-process communication
|
// Inter-process communication
|
||||||
IPC ipc;
|
IPC& ipc = IPC::getInstance();
|
||||||
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
ipc.registerEventHandler("uri", &toxURIEventHandler);
|
||||||
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
ipc.registerEventHandler("save", &toxSaveEventHandler);
|
||||||
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
ipc.registerEventHandler("activate", &toxActivateEventHandler);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#ifdef QTOX_PLATFORM_EXT
|
#ifdef QTOX_PLATFORM_EXT
|
||||||
#include "src/platform/autorun.h"
|
#include "src/platform/autorun.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "src/ipc.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -332,6 +333,17 @@ void Settings::save(bool writePersonal)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::save(QString path, bool writePersonal)
|
void Settings::save(QString path, bool writePersonal)
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
if (IPC::getInstance().isCurrentOwner())
|
||||||
|
#endif
|
||||||
|
saveGlobal(path);
|
||||||
|
|
||||||
|
if (writePersonal) // Core::switchConfiguration
|
||||||
|
savePersonal(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::saveGlobal(QString path)
|
||||||
{
|
{
|
||||||
qDebug() << "Settings: Saving in " << path;
|
qDebug() << "Settings: Saving in " << path;
|
||||||
|
|
||||||
|
@ -420,9 +432,18 @@ void Settings::save(QString path, bool writePersonal)
|
||||||
s.beginGroup("Video");
|
s.beginGroup("Video");
|
||||||
s.setValue("camVideoRes",camVideoRes);
|
s.setValue("camVideoRes",camVideoRes);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
if (writePersonal && !currentProfile.isEmpty()) // Core::switchConfiguration
|
void Settings::savePersonal(QString path)
|
||||||
{
|
{
|
||||||
|
if (currentProfile.isEmpty())
|
||||||
|
{
|
||||||
|
qDebug() << "Settings: could not save personal settings because currentProfile profile is empty";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Settings: Saving personal in " << path;
|
||||||
|
|
||||||
QSettings ps(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat);
|
QSettings ps(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat);
|
||||||
ps.beginGroup("Friends");
|
ps.beginGroup("Friends");
|
||||||
ps.beginWriteArray("Friend", friendLst.size());
|
ps.beginWriteArray("Friend", friendLst.size());
|
||||||
|
@ -445,7 +466,6 @@ void Settings::save(QString path, bool writePersonal)
|
||||||
ps.setValue("encryptTox", encryptTox);
|
ps.setValue("encryptTox", encryptTox);
|
||||||
ps.endGroup();
|
ps.endGroup();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Settings::makeProfileId(const QString& profile)
|
uint32_t Settings::makeProfileId(const QString& profile)
|
||||||
{
|
{
|
||||||
|
|
|
@ -254,6 +254,8 @@ private:
|
||||||
Settings(Settings &settings) = delete;
|
Settings(Settings &settings) = delete;
|
||||||
Settings& operator=(const Settings&) = delete;
|
Settings& operator=(const Settings&) = delete;
|
||||||
static uint32_t makeProfileId(const QString& profile);
|
static uint32_t makeProfileId(const QString& profile);
|
||||||
|
void saveGlobal(QString path);
|
||||||
|
void savePersonal(QString path);
|
||||||
|
|
||||||
static const QString FILENAME;
|
static const QString FILENAME;
|
||||||
static const QString OLDFILENAME;
|
static const QString OLDFILENAME;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user