20ea4d30dd9bfaad1d99e2650e6fa992dd4815f5
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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/types.h>
26 #  include <sys/stat.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 #if !defined(BUILD_CORE) && defined(STATIC)
56 #include <QtPlugin>
57 Q_IMPORT_PLUGIN(qjpeg)
58 Q_IMPORT_PLUGIN(qgif)
59 #endif
60
61 #include "quassel.h"
62 #include "types.h"
63
64 int main(int argc, char **argv)
65 {
66     // We need to explicitly initialize the required resources when linking statically
67 #ifndef BUILD_QTUI
68     Q_INIT_RESOURCE(sql);
69 #endif
70 #ifndef BUILD_CORE
71     Q_INIT_RESOURCE(pics);
72     Q_INIT_RESOURCE(hicolor_icons);
73 #endif
74
75 #ifdef EMBED_DATA
76     Q_INIT_RESOURCE(i18n);
77 # ifndef BUILD_CORE
78     Q_INIT_RESOURCE(data);
79     Q_INIT_RESOURCE(breeze_icons);
80     Q_INIT_RESOURCE(breeze_dark_icons);
81 #  ifdef WITH_OXYGEN_ICONS
82       Q_INIT_RESOURCE(oxygen_icons);
83 #  endif
84 #  ifdef WITH_BUNDLED_ICONS
85       Q_INIT_RESOURCE(breeze_icon_theme);
86       Q_INIT_RESOURCE(breeze_dark_icon_theme);
87 #   ifdef WITH_OXYGEN_ICONS
88       Q_INIT_RESOURCE(oxygen_icon_theme);
89 #   endif
90 #  endif
91 # endif
92 #endif
93
94     // Set umask so files are created with restricted permissions
95 #ifdef HAVE_UMASK
96     umask(S_IRWXG | S_IRWXO);
97 #endif
98
99     // Instantiate early, so log messages are handled
100     Quassel quassel;
101
102     Quassel::setupBuildInfo();
103     QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
104     QCoreApplication::setApplicationVersion(Quassel::buildInfo().plainVersionString);
105     QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
106     QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
107
108     // Migrate settings from KDE4 to KF5 if appropriate
109 #ifdef HAVE_KF5
110     Kdelibs4ConfigMigrator migrator(QCoreApplication::applicationName());
111     migrator.setConfigFiles(QStringList() << "quasselrc" << "quassel.notifyrc");
112     migrator.migrate();
113 #endif
114
115     //Setup the High-DPI settings
116 # if QT_VERSION >= 0x050600 && defined(Q_OS_WIN)
117     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); //Added in Qt 5.6
118 #endif
119     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
120
121     // Instantiate application
122 #if defined BUILD_CORE
123     CoreApplication app(argc, argv);
124     const auto runMode = Quassel::RunMode::CoreOnly;
125 #elif defined BUILD_QTUI
126     QtUiApplication app(argc, argv);
127     const auto runMode = Quassel::RunMode::ClientOnly;
128 #elif defined BUILD_MONO
129     MonolithicApplication app(argc, argv);
130     const auto runMode = Quassel::RunMode::Monolithic;
131 #endif
132
133     try {
134         Quassel::instance()->init(runMode);
135
136 #ifdef HAVE_KF5
137         AboutData aboutData;
138         AboutData::setQuasselPersons(&aboutData);
139         KAboutData::setApplicationData(aboutData.kAboutData());
140 #endif
141
142         // Initialize the application
143         app.init();
144     }
145     catch (ExitException e) {
146         if (!e.errorString.isEmpty()) {
147             qCritical() << e.errorString;
148         }
149         return e.exitCode;
150     }
151
152     return app.exec();
153 }