mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
config: singleton shared pointer refactor
This commit is contained in:
parent
7d1f0e2a69
commit
9405b17e14
@ -36,7 +36,12 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#define QT_TO_UTF8(str) str.toUtf8().constData()
|
#define QT_TO_UTF8(str) str.toUtf8().constData()
|
||||||
|
|
||||||
Config* Config::_instance = new Config();
|
ConfigPtr Config::_instance = ConfigPtr(new Config());
|
||||||
|
|
||||||
|
ConfigPtr Config::Current()
|
||||||
|
{
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
Config::Config() :
|
Config::Config() :
|
||||||
ServerEnabled(true),
|
ServerEnabled(true),
|
||||||
@ -179,8 +184,3 @@ bool Config::CheckAuth(QString response)
|
|||||||
|
|
||||||
return authSuccess;
|
return authSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config* Config::Current()
|
|
||||||
{
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
10
src/Config.h
10
src/Config.h
@ -20,9 +20,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
class Config;
|
||||||
|
typedef QSharedPointer<Config> ConfigPtr;
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
public:
|
public:
|
||||||
|
static ConfigPtr Current();
|
||||||
|
|
||||||
Config();
|
Config();
|
||||||
~Config();
|
~Config();
|
||||||
void Load();
|
void Load();
|
||||||
@ -46,10 +52,8 @@ class Config {
|
|||||||
QString SessionChallenge;
|
QString SessionChallenge;
|
||||||
bool SettingsLoaded;
|
bool SettingsLoaded;
|
||||||
|
|
||||||
static Config* Current();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Config* _instance;
|
static ConfigPtr _instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONFIG_H
|
#endif // CONFIG_H
|
||||||
|
@ -41,7 +41,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::showEvent(QShowEvent* event) {
|
void SettingsDialog::showEvent(QShowEvent* event) {
|
||||||
Config* conf = Config::Current();
|
auto conf = Config::Current();
|
||||||
|
|
||||||
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
||||||
ui->serverPort->setValue(conf->ServerPort);
|
ui->serverPort->setValue(conf->ServerPort);
|
||||||
@ -68,7 +68,7 @@ void SettingsDialog::AuthCheckboxChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::FormAccepted() {
|
void SettingsDialog::FormAccepted() {
|
||||||
Config* conf = Config::Current();
|
auto conf = Config::Current();
|
||||||
|
|
||||||
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
||||||
conf->ServerPort = ui->serverPort->value();
|
conf->ServerPort = ui->serverPort->value();
|
||||||
|
@ -45,7 +45,7 @@ bool obs_module_load(void) {
|
|||||||
QT_VERSION_STR, qVersion());
|
QT_VERSION_STR, qVersion());
|
||||||
|
|
||||||
// Core setup
|
// Core setup
|
||||||
Config* config = Config::Current();
|
auto config = Config::Current();
|
||||||
config->Load();
|
config->Load();
|
||||||
|
|
||||||
WSEvents::Instance = new WSEvents(WSServer::Current());
|
WSEvents::Instance = new WSEvents(WSServer::Current());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user