/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <QDateTime>
-#include <QString>
-#include <QTimer>
-#include <QTranslator>
+#include <cstdlib>
+#include <memory>
-#include "global.h"
-#include "logger.h"
-#include "network.h"
-#include "settings.h"
+#ifdef HAVE_UMASK
+# include <sys/types.h>
+# include <sys/stat.h>
+#endif /* HAVE_UMASK */
-#if defined BUILD_CORE
#include <QCoreApplication>
-#include <QDir>
-#include "core.h"
-#include "message.h"
+#include <QTextCodec>
+#ifdef BUILD_CORE
+# include "coreapplication.h"
#elif defined BUILD_QTUI
-#include <QApplication>
-#include "client.h"
-#include "qtui.h"
-
+# include "aboutdata.h"
+# include "qtuiapplication.h"
#elif defined BUILD_MONO
-#include <QApplication>
-#include "client.h"
-#include "core.h"
-#include "coresession.h"
-#include "qtui.h"
+# include "aboutdata.h"
+# include "monoapplication.h"
#else
#error "Something is wrong - you need to #define a build mode!"
#endif
-#include <signal.h>
-
-//! Signal handler for graceful shutdown.
-void handle_signal(int sig) {
- qWarning("%s", qPrintable(QString("Caught signal %1 - exiting.").arg(sig)));
- QCoreApplication::quit();
-}
-
-int main(int argc, char **argv) {
- // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
- signal(SIGTERM, handle_signal);
- signal(SIGINT, handle_signal);
-
- // Logger logger;
-
- Global::registerMetaTypes();
- Global::setupVersion();
-
-#if defined BUILD_CORE
- Global::runMode = Global::CoreOnly;
- QCoreApplication app(argc, argv);
-#elif defined BUILD_QTUI
- Global::runMode = Global::ClientOnly;
- QApplication app(argc, argv);
-#else
- Global::runMode = Global::Monolithic;
- QApplication app(argc, argv);
+// We don't want quasselcore to depend on KDE
+#if defined HAVE_KF5 && defined BUILD_CORE
+# undef HAVE_KF5
#endif
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
- // Set up i18n support
- QLocale locale = QLocale::system();
+#if defined HAVE_KF5
+# include <KCoreAddons/KAboutData>
+# include <KCoreAddons/Kdelibs4ConfigMigrator>
+#endif
- QTranslator qtTranslator;
- qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
- app.installTranslator(&qtTranslator);
+#include "quassel.h"
+#include "types.h"
- QTranslator quasselTranslator;
- quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
- app.installTranslator(&quasselTranslator);
+int main(int argc, char **argv)
+{
+ // We need to explicitly initialize the required resources when linking statically
+#ifndef BUILD_QTUI
+ Q_INIT_RESOURCE(sql);
+#endif
+#ifndef BUILD_CORE
+ Q_INIT_RESOURCE(pics);
+ Q_INIT_RESOURCE(hicolor_icons);
+#endif
- Network::setDefaultCodecForServer("ISO-8859-1");
- Network::setDefaultCodecForEncoding("UTF-8");
- Network::setDefaultCodecForDecoding("ISO-8859-15");
+#ifdef EMBED_DATA
+ Q_INIT_RESOURCE(i18n);
+# ifndef BUILD_CORE
+ Q_INIT_RESOURCE(data);
+ Q_INIT_RESOURCE(breeze_icons);
+ Q_INIT_RESOURCE(breeze_dark_icons);
+# ifdef WITH_OXYGEN_ICONS
+ Q_INIT_RESOURCE(oxygen_icons);
+# endif
+# ifdef WITH_BUNDLED_ICONS
+ Q_INIT_RESOURCE(breeze_icon_theme);
+ Q_INIT_RESOURCE(breeze_dark_icon_theme);
+# ifdef WITH_OXYGEN_ICONS
+ Q_INIT_RESOURCE(oxygen_icon_theme);
+# endif
+# endif
+# endif
+#endif
- QCoreApplication::setOrganizationDomain("quassel-irc.org");
- QCoreApplication::setApplicationName("Quassel IRC");
- QCoreApplication::setOrganizationName("Quassel Project");
+ // Set umask so files are created with restricted permissions
+#ifdef HAVE_UMASK
+ umask(S_IRWXG | S_IRWXO);
+#endif
- // Check if a non-standard core port is requested
- QStringList args = QCoreApplication::arguments(); // TODO Build a CLI parser
- Global::DEBUG = args.contains("--debug"); // This enables various debug features.
+ // Instantiate early, so log messages are handled
+ Quassel quassel;
- Global::defaultPort = 4242;
- int idx;
- if((idx = args.indexOf("-p")) > 0 && idx < args.count() - 1) {
- int port = args[idx+1].toInt();
- if(port >= 1024 && port < 65536) Global::defaultPort = port;
- }
+ Quassel::setupBuildInfo();
+ QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
+ QCoreApplication::setApplicationVersion(Quassel::buildInfo().plainVersionString);
+ QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
+ QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
-#ifndef BUILD_QTUI
- Core::instance(); // create and init the core
+ // Migrate settings from KDE4 to KF5 if appropriate
+#ifdef HAVE_KF5
+ Kdelibs4ConfigMigrator migrator(QCoreApplication::applicationName());
+ migrator.setConfigFiles(QStringList() << "quasselrc" << "quassel.notifyrc");
+ migrator.migrate();
#endif
- //Settings::init();
-
-#ifndef BUILD_CORE
- QtUi *gui = new QtUi();
- Client::init(gui);
- // init gui only after the event loop has started
- QTimer::singleShot(0, gui, SLOT(init()));
- //gui->init();
+ //Setup the High-DPI settings
+# if QT_VERSION >= 0x050600 && defined(Q_OS_WIN)
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); //Added in Qt 5.6
#endif
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
-#ifndef BUILD_QTUI
- if(!args.contains("--norestore")) {
- Core::restoreState();
- }
+ // Instantiate application
+#if defined BUILD_CORE
+ CoreApplication app(argc, argv);
+ const auto runMode = Quassel::RunMode::CoreOnly;
+#elif defined BUILD_QTUI
+ QtUiApplication app(argc, argv);
+ const auto runMode = Quassel::RunMode::ClientOnly;
+#elif defined BUILD_MONO
+ MonolithicApplication app(argc, argv);
+ const auto runMode = Quassel::RunMode::Monolithic;
#endif
- int exitCode = app.exec();
-
-#ifndef BUILD_QTUI
- Core::saveState();
-#endif
+ try {
+ Quassel::instance()->init(runMode);
-#ifndef BUILD_CORE
- // the mainWin has to be deleted before the Core
- // if not Quassel will crash on exit under certain conditions since the gui
- // still wants to access clientdata
- delete gui;
- Client::destroy();
-#endif
-#ifndef BUILD_QTUI
- Core::destroy();
+#ifdef HAVE_KF5
+ AboutData aboutData;
+ AboutData::setQuasselPersons(&aboutData);
+ KAboutData::setApplicationData(aboutData.kAboutData());
#endif
- return exitCode;
+ // Initialize the application
+ app.init();
+ }
+ catch (ExitException e) {
+ if (!e.errorString.isEmpty()) {
+ qCritical() << e.errorString;
+ }
+ return e.exitCode;
+ }
+
+ return app.exec();
}