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