change the way the singleton is created.

This commit is contained in:
Patrick von Reth 2015-06-26 12:34:39 +02:00
parent 711e880dd7
commit 229b725c55
3 changed files with 22 additions and 21 deletions

View File

@ -48,13 +48,8 @@ SnoreCore::SnoreCore(QObject *parent):
SnoreCore &SnoreCore::instance() SnoreCore &SnoreCore::instance()
{ {
static SnoreCore *instance = nullptr; static SnoreCore instance(qApp);
if (!instance) { return instance;
SnoreCorePrivate::loadTranslator();
SnoreCorePrivate::registerMetaTypes();
instance = new SnoreCore(qApp);
}
return *instance;
} }
SnoreCore::~SnoreCore() SnoreCore::~SnoreCore()

View File

@ -44,6 +44,8 @@ SnoreCorePrivate::SnoreCorePrivate():
snoreDebug(SNORE_DEBUG) << "Snore local settings are located in" << normalizeKey("Test", LOCAL_SETTING); snoreDebug(SNORE_DEBUG) << "Snore local settings are located in" << normalizeKey("Test", LOCAL_SETTING);
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit())); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit()));
m_defaultApp = Application("SnoreNotify", Icon(":/root/snore.png"));
} }
SnoreCorePrivate::~SnoreCorePrivate() SnoreCorePrivate::~SnoreCorePrivate()
@ -141,7 +143,6 @@ void SnoreCorePrivate::init()
Q_Q(SnoreCore); Q_Q(SnoreCore);
setDefaultValueIntern("Timeout", 10); setDefaultValueIntern("Timeout", 10);
setDefaultValueIntern("Silent", false); setDefaultValueIntern("Silent", false);
q->setDefaultApplication(Application("SnoreNotify", Icon(":/root/snore.png")));
} }
void SnoreCorePrivate::setDefaultValueIntern(const QString &key, const QVariant &value) void SnoreCorePrivate::setDefaultValueIntern(const QString &key, const QVariant &value)
@ -192,14 +193,6 @@ void SnoreCorePrivate::setLocalSttingsPrefix(const QString &prefix)
syncSettings(); syncSettings();
} }
void SnoreCorePrivate::registerMetaTypes()
{
qRegisterMetaType<Notification>();
qRegisterMetaType<Application>();
qRegisterMetaType<SnorePlugin::PluginTypes>();
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
}
QString SnoreCorePrivate::tempPath() QString SnoreCorePrivate::tempPath()
{ {
static QTemporaryDir dir; static QTemporaryDir dir;
@ -233,7 +226,7 @@ void SnoreCorePrivate::slotAboutToQuit()
} }
} }
void SnoreCorePrivate::loadTranslator() static void loadTranslator()
{ {
auto installTranslator = [](const QString & locale) { auto installTranslator = [](const QString & locale) {
snoreDebug(SNORE_DEBUG) << locale; snoreDebug(SNORE_DEBUG) << locale;
@ -260,3 +253,20 @@ void SnoreCorePrivate::loadTranslator()
} }
} }
} }
static void registerMetaTypes()
{
qRegisterMetaType<Notification>();
qRegisterMetaType<Application>();
qRegisterMetaType<SnorePlugin::PluginTypes>();
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
}
static void snoreStartup(){
loadTranslator();
registerMetaTypes();
}
Q_COREAPP_STARTUP_FUNCTION(snoreStartup)

View File

@ -35,16 +35,12 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject
Q_OBJECT Q_OBJECT
public: public:
static void registerMetaTypes();
/** /**
* @brief tempPath * @brief tempPath
* @return the path of a QTemporaryDir, this location is used to store images. * @return the path of a QTemporaryDir, this location is used to store images.
*/ */
static QString tempPath(); static QString tempPath();
static void loadTranslator();
public: public:
static SnoreCorePrivate *instance(); static SnoreCorePrivate *instance();
~SnoreCorePrivate(); ~SnoreCorePrivate();