common: Don't add quotes to exit exceptions
[quassel.git] / src / main / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include <cstdlib>
22 #include <memory>
23
24 #ifdef HAVE_UMASK
25 #    include <sys/stat.h>
26 #    include <sys/types.h>
27 #endif /* HAVE_UMASK */
28
29 #include <QCoreApplication>
30 #include <QTextCodec>
31
32 #ifdef BUILD_CORE
33 #    include "coreapplication.h"
34 #elif defined BUILD_QTUI
35 #    include "aboutdata.h"
36 #    include "qtuiapplication.h"
37 #elif defined BUILD_MONO
38 #    include "aboutdata.h"
39 #    include "monoapplication.h"
40
41 #else
42 #    error "Something is wrong - you need to #define a build mode!"
43 #endif
44
45 // We don't want quasselcore to depend on KDE
46 #if defined HAVE_KF5 && defined BUILD_CORE
47 #    undef HAVE_KF5
48 #endif
49
50 #if defined HAVE_KF5
51 #    include <KCoreAddons/KAboutData>
52 #    include <KCoreAddons/Kdelibs4ConfigMigrator>
53 #endif
54
55 #include "quassel.h"
56 #include "types.h"
57
58 int main(int argc, char** argv)
59 {
60     // Set umask so files are created with restricted permissions
61 #ifdef HAVE_UMASK
62     umask(S_IRWXG | S_IRWXO);
63 #endif
64
65     // Instantiate early, so log messages are handled
66     Quassel quassel;
67
68     Quassel::setupBuildInfo();
69     QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
70     QCoreApplication::setApplicationVersion(Quassel::buildInfo().plainVersionString);
71     QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
72     QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
73
74     // Migrate settings from KDE4 to KF5 if appropriate
75 #ifdef HAVE_KF5
76     Kdelibs4ConfigMigrator migrator(QCoreApplication::applicationName());
77     migrator.setConfigFiles(QStringList() << "quasselrc"
78                                           << "quassel.notifyrc");
79     migrator.migrate();
80 #endif
81
82     // Setup the High-DPI settings
83 #if QT_VERSION >= 0x050600 && defined(Q_OS_WIN)
84     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);  // Added in Qt 5.6
85 #endif
86     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
87
88     // Instantiate application
89 #if defined BUILD_CORE
90     CoreApplication app(argc, argv);
91     const auto runMode = Quassel::RunMode::CoreOnly;
92 #elif defined BUILD_QTUI
93     QtUiApplication app(argc, argv);
94     const auto runMode = Quassel::RunMode::ClientOnly;
95 #elif defined BUILD_MONO
96     MonolithicApplication app(argc, argv);
97     const auto runMode = Quassel::RunMode::Monolithic;
98 #endif
99
100     try {
101         Quassel::instance()->init(runMode);
102
103 #ifdef HAVE_KF5
104         AboutData aboutData;
105         AboutData::setQuasselPersons(&aboutData);
106         KAboutData::setApplicationData(aboutData.kAboutData());
107 #endif
108
109         // Initialize the application
110         app.init();
111     }
112     catch (ExitException e) {
113         if (!e.errorString.isEmpty()) {
114             qCritical() << qPrintable(e.errorString);
115         }
116         return e.exitCode;
117     }
118
119     return app.exec();
120 }