QssParser: Interpret "oblique" as italic
[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_KDE4 && defined BUILD_CORE
47 #  undef HAVE_KDE4
48 #endif
49 // We don't want quasselcore to depend on KDE
50 #if defined HAVE_KF5 && defined BUILD_CORE
51 #  undef HAVE_KF5
52 #endif
53
54 #ifdef HAVE_KDE4
55 #  include <KAboutData>
56 #  include "kcmdlinewrapper.h"
57 #elif defined HAVE_KF5
58 #  include <KCoreAddons/KAboutData>
59 #  include <KCoreAddons/Kdelibs4ConfigMigrator>
60 #  include "qt5cliparser.h"
61 #elif defined HAVE_QT5
62 #  include "qt5cliparser.h"
63 #else
64 #  include "cliparser.h"
65 #endif
66
67 #if !defined(BUILD_CORE) && defined(STATIC)
68 #include <QtPlugin>
69 Q_IMPORT_PLUGIN(qjpeg)
70 Q_IMPORT_PLUGIN(qgif)
71 #endif
72
73 #include "quassel.h"
74 #include "types.h"
75
76 int main(int argc, char **argv)
77 {
78 #ifdef HAVE_UMASK
79     umask(S_IRWXG | S_IRWXO);
80 #endif
81
82     // Instantiate early, so log messages are handled
83     Quassel::instance();
84
85 #if QT_VERSION < 0x050000
86     // All our source files are in UTF-8, and Qt5 even requires that
87     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
88     QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
89 #endif
90
91     Quassel::setupBuildInfo();
92     QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
93     QCoreApplication::setApplicationVersion(Quassel::buildInfo().plainVersionString);
94     QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
95     QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
96
97     // on OSX with Qt4, raster seems to fix performance issues
98 #if QT_VERSION < 0x050000 && defined Q_OS_MAC && !defined BUILD_CORE
99     QApplication::setGraphicsSystem("raster");
100 #endif
101 //Setup the High-DPI settings
102 # if QT_VERSION >= 0x050600 && defined(Q_OS_WIN)
103     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); //Added in Qt 5.6
104 #endif
105 # if QT_VERSION >= 0x050400
106    //Added in the early Qt5 versions (5.0?)- use 5.4 as the cutoff since lots of high-DPI work was added then
107     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
108 # endif
109     // We need to explicitly initialize the required resources when linking statically
110 #ifndef BUILD_QTUI
111     Q_INIT_RESOURCE(sql);
112 #endif
113 #ifndef BUILD_CORE
114     Q_INIT_RESOURCE(pics);
115     Q_INIT_RESOURCE(hicolor_icons);
116 #endif
117
118 #ifdef EMBED_DATA
119     Q_INIT_RESOURCE(i18n);
120 # ifndef BUILD_CORE
121     Q_INIT_RESOURCE(data);
122     Q_INIT_RESOURCE(breeze_icons);
123     Q_INIT_RESOURCE(breeze_dark_icons);
124 #  ifdef WITH_OXYGEN_ICONS
125     Q_INIT_RESOURCE(oxygen_icons);
126 #  endif
127 #  ifdef WITH_BUNDLED_ICONS
128       Q_INIT_RESOURCE(breeze_icon_theme);
129       Q_INIT_RESOURCE(breeze_dark_icon_theme);
130 #   ifdef WITH_OXYGEN_ICONS
131       Q_INIT_RESOURCE(oxygen_icon_theme);
132 #   endif
133 #  endif
134 # endif
135 #endif
136
137     std::shared_ptr<AbstractCliParser> cliParser;
138
139 #ifdef HAVE_KDE4
140     // We need to init KCmdLineArgs first
141     KAboutData aboutData("quassel", "kdelibs4", ki18n("Quassel IRC"), Quassel::buildInfo().plainVersionString.toUtf8(),
142         ki18n("A modern, distributed IRC client"));
143     aboutData.addLicense(KAboutData::License_GPL_V2);
144     aboutData.addLicense(KAboutData::License_GPL_V3);
145     aboutData.setBugAddress("https://bugs.quassel-irc.org/projects/quassel-irc/issues/new");
146     aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
147     KCmdLineArgs::init(argc, argv, &aboutData);
148
149     cliParser = std::make_shared<KCmdLineWrapper>();
150 #elif defined HAVE_QT5
151     cliParser = std::make_shared<Qt5CliParser>();
152 #else
153     cliParser = std::make_shared<CliParser>();
154 #endif
155     Quassel::setCliParser(cliParser);
156
157     // Initialize CLI arguments
158     // NOTE: We can't use tr() at this point, since app is not yet created
159     // TODO: Change this once we get rid of KDE4 and can initialize the parser after creating the app
160
161     // put shared client&core arguments here
162     cliParser->addSwitch("debug", 'd', "Enable debug output");
163     cliParser->addSwitch("help", 'h', "Display this help and exit");
164     cliParser->addSwitch("version", 'v', "Display version information");
165 #ifdef BUILD_QTUI
166     cliParser->addOption("configdir", 'c', "Specify the directory holding the client configuration", "path");
167 #else
168     cliParser->addOption("configdir", 'c', "Specify the directory holding configuration files, the SQlite database and the SSL certificate", "path");
169 #endif
170     cliParser->addOption("datadir", 0, "DEPRECATED - Use --configdir instead", "path");
171     cliParser->addOption("loglevel", 'L', "Loglevel Debug|Info|Warning|Error", "level", "Info");
172 #ifdef HAVE_SYSLOG
173     cliParser->addSwitch("syslog", 0, "Log to syslog");
174 #endif
175     cliParser->addOption("logfile", 'l', "Log to a file", "path");
176
177 #ifndef BUILD_CORE
178     // put client-only arguments here
179     cliParser->addOption("icontheme", 0, "Override the system icon theme ('breeze' is recommended)", "theme");
180     cliParser->addOption("qss", 0, "Load a custom application stylesheet", "file.qss");
181     cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
182     cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
183     cliParser->addSwitch("hidewindow", 0, "Start the client minimized to the system tray");
184 #endif
185 #ifndef BUILD_QTUI
186     // put core-only arguments here
187     cliParser->addOption("listen", 0, "The address(es) quasselcore will listen on", "<address>[,<address>[,...]]", "::,0.0.0.0");
188     cliParser->addOption("port", 'p', "The port quasselcore will listen at", "port", "4242");
189     cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
190     cliParser->addSwitch("config-from-environment", 0, "Load configuration from environment variables");
191     cliParser->addOption("select-backend", 0, "Switch storage backend (migrating data if possible)", "backendidentifier");
192     cliParser->addOption("select-authenticator", 0, "Select authentication backend", "authidentifier");
193     cliParser->addSwitch("add-user", 0, "Starts an interactive session to add a new core user");
194     cliParser->addOption("change-userpass", 0, "Starts an interactive session to change the password of the user identified by <username>", "username");
195     cliParser->addSwitch("oidentd", 0, "Enable oidentd integration.  In most cases you should also enable --strict-ident");
196     cliParser->addOption("oidentd-conffile", 0, "Set path to oidentd configuration file", "file");
197     cliParser->addSwitch("strict-ident", 0, "Use users' quasselcore username as ident reply. Ignores each user's configured ident setting.");
198     cliParser->addSwitch("ident-daemon", 0, "Enable internal ident daemon");
199     cliParser->addOption("ident-port", 0, "The port quasselcore will listen at for ident requests. Only meaningful with --ident-daemon", "port", "10113");
200 #ifdef HAVE_SSL
201     cliParser->addSwitch("require-ssl", 0, "Require SSL for remote (non-loopback) client connections");
202     cliParser->addOption("ssl-cert", 0, "Specify the path to the SSL Certificate", "path", "configdir/quasselCert.pem");
203     cliParser->addOption("ssl-key", 0, "Specify the path to the SSL key", "path", "ssl-cert-path");
204 #endif
205     cliParser->addSwitch("enable-experimental-dcc", 0, "Enable highly experimental and unfinished support for CTCP DCC (DANGEROUS)");
206 #endif
207
208 #ifdef HAVE_KDE4
209     // the KDE version needs this extra call to parse argc/argv before app is instantiated
210     if (!cliParser->init()) {
211         cliParser->usage();
212         return EXIT_FAILURE;
213     }
214 #endif
215
216 #if defined BUILD_CORE
217     CoreApplication app(argc, argv);
218 #elif defined BUILD_QTUI
219     QtUiApplication app(argc, argv);
220 #elif defined BUILD_MONO
221     MonolithicApplication app(argc, argv);
222 #endif
223
224 #ifndef HAVE_KDE4
225     // the non-KDE version parses after app has been instantiated
226     if (!cliParser->init(app.arguments())) {
227         cliParser->usage();
228         return EXIT_FAILURE;
229     }
230 #endif
231
232 // Migrate settings from KDE4 to KF5 if appropriate
233 #ifdef HAVE_KF5
234     Kdelibs4ConfigMigrator migrator(QCoreApplication::applicationName());
235     migrator.setConfigFiles(QStringList() << "quasselrc" << "quassel.notifyrc");
236     migrator.migrate();
237 #endif
238
239 #ifdef HAVE_KF5
240     // FIXME: This should be done after loading the translation catalogue, but still in main()
241     AboutData aboutData;
242     AboutData::setQuasselPersons(&aboutData);
243     KAboutData::setApplicationData(aboutData.kAboutData());
244 #endif
245     try {
246         app.init();
247     }
248     catch (ExitException e) {
249         if (!e.errorString.isEmpty()) {
250             qCritical() << e.errorString;
251         }
252         return e.exitCode;
253     }
254
255     return app.exec();
256 }