diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index 3a0cae0..a39e988 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -48,13 +48,8 @@ SnoreCore::SnoreCore(QObject *parent): SnoreCore &SnoreCore::instance() { - static SnoreCore *instance = nullptr; - if (!instance) { - SnoreCorePrivate::loadTranslator(); - SnoreCorePrivate::registerMetaTypes(); - instance = new SnoreCore(qApp); - } - return *instance; + static SnoreCore instance(qApp); + return instance; } SnoreCore::~SnoreCore() diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index 004759e..cc22712 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -44,6 +44,8 @@ SnoreCorePrivate::SnoreCorePrivate(): snoreDebug(SNORE_DEBUG) << "Snore local settings are located in" << normalizeKey("Test", LOCAL_SETTING); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit())); + + m_defaultApp = Application("SnoreNotify", Icon(":/root/snore.png")); } SnoreCorePrivate::~SnoreCorePrivate() @@ -141,7 +143,6 @@ void SnoreCorePrivate::init() Q_Q(SnoreCore); setDefaultValueIntern("Timeout", 10); setDefaultValueIntern("Silent", false); - q->setDefaultApplication(Application("SnoreNotify", Icon(":/root/snore.png"))); } void SnoreCorePrivate::setDefaultValueIntern(const QString &key, const QVariant &value) @@ -192,14 +193,6 @@ void SnoreCorePrivate::setLocalSttingsPrefix(const QString &prefix) syncSettings(); } -void SnoreCorePrivate::registerMetaTypes() -{ - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); -} - QString SnoreCorePrivate::tempPath() { static QTemporaryDir dir; @@ -233,7 +226,7 @@ void SnoreCorePrivate::slotAboutToQuit() } } -void SnoreCorePrivate::loadTranslator() +static void loadTranslator() { auto installTranslator = [](const QString & locale) { snoreDebug(SNORE_DEBUG) << locale; @@ -260,3 +253,20 @@ void SnoreCorePrivate::loadTranslator() } } } + +static void registerMetaTypes() +{ + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); +} + +static void snoreStartup(){ + loadTranslator(); + registerMetaTypes(); +} + +Q_COREAPP_STARTUP_FUNCTION(snoreStartup) + + diff --git a/src/libsnore/snore_p.h b/src/libsnore/snore_p.h index d63fdb5..b958568 100644 --- a/src/libsnore/snore_p.h +++ b/src/libsnore/snore_p.h @@ -35,16 +35,12 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject Q_OBJECT public: - static void registerMetaTypes(); - /** * @brief tempPath * @return the path of a QTemporaryDir, this location is used to store images. */ static QString tempPath(); - static void loadTranslator(); - public: static SnoreCorePrivate *instance(); ~SnoreCorePrivate();