qt4-b-gone: Reorganize the initialization sequence
[quassel.git] / src / common / quassel.cpp
index 57cbdca..af4c69b 100644 (file)
@@ -60,50 +60,15 @@ Quassel::Quassel()
 }
 
 
-bool Quassel::init()
+void Quassel::init(RunMode runMode)
 {
-    if (instance()->_initialized)
-        return true;  // allow multiple invocations because of MonolithicApplication
-
-#if 0
-    // Setup signal handling
-    // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
-    signal(SIGTERM, handleSignal);
-    signal(SIGINT, handleSignal);
-#ifndef Q_OS_WIN
-    // SIGHUP is used to reload configuration (i.e. SSL certificates)
-    // Windows does not support SIGHUP
-    signal(SIGHUP, handleSignal);
-#endif
-
-    if (instance()->_handleCrashes) {
-        // we have crashhandler for win32 and unix (based on execinfo).
-#if defined(Q_OS_WIN) || defined(HAVE_EXECINFO)
-# ifndef Q_OS_WIN
-        // we only handle crashes ourselves if coredumps are disabled
-        struct rlimit *limit = (rlimit *)malloc(sizeof(struct rlimit));
-        int rc = getrlimit(RLIMIT_CORE, limit);
-
-        if (rc == -1 || !((long)limit->rlim_cur > 0 || limit->rlim_cur == RLIM_INFINITY)) {
-# endif /* Q_OS_WIN */
-            signal(SIGABRT, handleSignal);
-            signal(SIGSEGV, handleSignal);
-# ifndef Q_OS_WIN
-            signal(SIGBUS, handleSignal);
-        }
-        free(limit);
-# endif /* Q_OS_WIN */
-#endif /* Q_OS_WIN || HAVE_EXECINFO */
-    }
-#endif
-
-    instance()->setupSignalHandling();
+    _runMode = runMode;
 
-    instance()->_initialized = true;
     qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
 
-    instance()->setupEnvironment();
-    instance()->registerMetaTypes();
+    setupSignalHandling();
+    setupEnvironment();
+    registerMetaTypes();
 
     Network::setDefaultCodecForServer("UTF-8");
     Network::setDefaultCodecForEncoding("UTF-8");
@@ -111,16 +76,16 @@ bool Quassel::init()
 
     if (isOptionSet("help")) {
         instance()->_cliParser->usage();
-        return false;
+        return;
     }
 
     if (isOptionSet("version")) {
         std::cout << qPrintable("Quassel IRC: " + Quassel::buildInfo().plainVersionString) << std::endl;
-        return false;
+        return;
     }
 
     // Don't keep a debug log on the core
-    return instance()->logger()->setup(runMode() != RunMode::CoreOnly);
+    logger()->setup(runMode != RunMode::CoreOnly);
 }
 
 
@@ -334,6 +299,7 @@ void Quassel::setupSignalHandling()
     connect(_signalWatcher, SIGNAL(handleSignal(AbstractSignalWatcher::Action)), this, SLOT(handleSignal(AbstractSignalWatcher::Action)));
 }
 
+
 void Quassel::handleSignal(AbstractSignalWatcher::Action action)
 {
     switch (action) {
@@ -366,12 +332,6 @@ Quassel::RunMode Quassel::runMode() {
 }
 
 
-void Quassel::setRunMode(RunMode runMode)
-{
-    instance()->_runMode = runMode;
-}
-
-
 void Quassel::setCliParser(std::shared_ptr<AbstractCliParser> parser)
 {
     instance()->_cliParser = std::move(parser);
@@ -590,7 +550,7 @@ void Quassel::loadTranslation(const QLocale &locale)
     quasselTranslator->setObjectName("QuasselTr");
     qApp->installTranslator(quasselTranslator);
 
-#if QT_VERSION >= 0x040800 && !defined Q_OS_MAC
+#ifndef Q_OS_MAC
     bool success = qtTranslator->load(locale, QString("qt_"), translationDirPath());
     if (!success)
         qtTranslator->load(locale, QString("qt_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath));