/***************************************************************************
- * 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 <QFile>
+#include <cstdlib>
+#include <memory>
-#include "global.h"
-#include "logger.h"
-#include "network.h"
-#include "settings.h"
-#include "cliparser.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);
-
- Global::registerMetaTypes();
- Global::setupVersion();
+// We don't want quasselcore to depend on KDE
+#if defined HAVE_KF5 && defined BUILD_CORE
+# undef HAVE_KF5
+#endif
-#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);
+#if defined HAVE_KF5
+# include <KCoreAddons/KAboutData>
+# include <KCoreAddons/Kdelibs4ConfigMigrator>
#endif
- Global::parser = CliParser(QCoreApplication::arguments());
+#include "quassel.h"
+#include "types.h"
+int main(int argc, char **argv)
+{
+ // We need to explicitly initialize the required resources when linking statically
#ifndef BUILD_QTUI
-// put core-only arguments here
- Global::parser.addOption("port",'p',"The port quasselcore will listen at",QString("4242"));
- Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state");
- Global::parser.addOption("logfile",'l',"Path to logfile");
- Global::parser.addOption("loglevel",'L',"Loglevel Debug|Info|Warning|Error","Info");
-#endif // BUILD_QTUI
+ Q_INIT_RESOURCE(sql);
+#endif
#ifndef BUILD_CORE
-// put client-only arguments here
- Global::parser.addSwitch("debugbufferswitches",0,"Enables debugging for bufferswitches");
- Global::parser.addSwitch("debugmodel",0,"Enables debugging for models");
-#endif // BUILD_QTCORE
-// put shared client&core arguments here
- Global::parser.addSwitch("debug",'d',"Enable debug output");
- Global::parser.addSwitch("help",'h', "Display this help and exit");
-
- if(!Global::parser.parse() || Global::parser.isSet("help")) {
- Global::parser.usage();
- return 1;
- }
-
- /*
- This is an initial check if logfile is writable since the warning would spam stdout if done
- in current Logger implementation. Can be dropped whenever the logfile is only opened once.
- */
- if(Global::runMode != Global::ClientOnly) {
- QFile logFile;
- if(!Global::parser.value("logfile").isEmpty()) {
- logFile.setFileName(Global::parser.value("logfile"));
- if(!logFile.open(QIODevice::Append | QIODevice::Text))
- qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
- else logFile.close();
- }
- else qWarning("No logfile set - will log to stdout instead");
- }
-
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
- // Set up i18n support
- QLocale locale = QLocale::system();
+ Q_INIT_RESOURCE(pics);
+ Q_INIT_RESOURCE(hicolor_icons);
+#endif
- QTranslator qtTranslator(&app);
- qtTranslator.setObjectName("QtTr");
- qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
- app.installTranslator(&qtTranslator);
+#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
- QTranslator quasselTranslator(&app);
- quasselTranslator.setObjectName("QuasselTr");
- quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
- app.installTranslator(&quasselTranslator);
+ // Set umask so files are created with restricted permissions
+#ifdef HAVE_UMASK
+ umask(S_IRWXG | S_IRWXO);
+#endif
- Network::setDefaultCodecForServer("ISO-8859-1");
- Network::setDefaultCodecForEncoding("UTF-8");
- Network::setDefaultCodecForDecoding("ISO-8859-15");
+ // Instantiate early, so log messages are handled
+ Quassel quassel;
- QCoreApplication::setOrganizationDomain("quassel-irc.org");
- QCoreApplication::setApplicationName("Quassel IRC");
- QCoreApplication::setOrganizationName("Quassel Project");
+ 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(!Global::parser.isSet("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();
+ try {
+ Quassel::instance()->init(runMode);
-#ifndef BUILD_QTUI
- Core::saveState();
+#ifdef HAVE_KF5
+ AboutData aboutData;
+ AboutData::setQuasselPersons(&aboutData);
+ KAboutData::setApplicationData(aboutData.kAboutData());
#endif
-#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();
-#endif
+ // Initialize the application
+ app.init();
+ }
+ catch (ExitException e) {
+ if (!e.errorString.isEmpty()) {
+ qCritical() << e.errorString;
+ }
+ return e.exitCode;
+ }
- return exitCode;
+ return app.exec();
}