config: singleton shared pointer refactor

This commit is contained in:
Stéphane L 2019-01-01 05:00:43 +01:00
parent 7d1f0e2a69
commit 9405b17e14
4 changed files with 16 additions and 12 deletions

View File

@ -36,7 +36,12 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#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() :
ServerEnabled(true),
@ -179,8 +184,3 @@ bool Config::CheckAuth(QString response)
return authSuccess;
}
Config* Config::Current()
{
return _instance;
}

View File

@ -20,9 +20,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#define CONFIG_H
#include <QString>
#include <QSharedPointer>
class Config;
typedef QSharedPointer<Config> ConfigPtr;
class Config {
public:
static ConfigPtr Current();
Config();
~Config();
void Load();
@ -46,10 +52,8 @@ class Config {
QString SessionChallenge;
bool SettingsLoaded;
static Config* Current();
private:
static Config* _instance;
static ConfigPtr _instance;
};
#endif // CONFIG_H

View File

@ -41,7 +41,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
}
void SettingsDialog::showEvent(QShowEvent* event) {
Config* conf = Config::Current();
auto conf = Config::Current();
ui->serverEnabled->setChecked(conf->ServerEnabled);
ui->serverPort->setValue(conf->ServerPort);
@ -68,7 +68,7 @@ void SettingsDialog::AuthCheckboxChanged() {
}
void SettingsDialog::FormAccepted() {
Config* conf = Config::Current();
auto conf = Config::Current();
conf->ServerEnabled = ui->serverEnabled->isChecked();
conf->ServerPort = ui->serverPort->value();

View File

@ -45,7 +45,7 @@ bool obs_module_load(void) {
QT_VERSION_STR, qVersion());
// Core setup
Config* config = Config::Current();
auto config = Config::Current();
config->Load();
WSEvents::Instance = new WSEvents(WSServer::Current());