3f6cab541661c9b0d37b89c9998ca743396b08e2
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 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
23 #include <QTextCodec>
24
25 #ifdef BUILD_CORE
26 #  include "coreapplication.h"
27 #elif defined BUILD_QTUI
28 #  include "aboutdata.h"
29 #  include "qtuiapplication.h"
30 #elif defined BUILD_MONO
31 #  include "aboutdata.h"
32 #  include "monoapplication.h"
33
34 #else
35 #error "Something is wrong - you need to #define a build mode!"
36 #endif
37
38 // We don't want quasselcore to depend on KDE
39 #if defined HAVE_KDE4 && defined BUILD_CORE
40 #  undef HAVE_KDE4
41 #endif
42 // We don't want quasselcore to depend on KDE
43 #if defined HAVE_KF5 && defined BUILD_CORE
44 #  undef HAVE_KF5
45 #endif
46
47 #ifdef HAVE_KDE4
48 #  include <KAboutData>
49 #  include "kcmdlinewrapper.h"
50 #elif defined HAVE_KF5
51 #  include <KCoreAddons/KAboutData>
52 #  include "qt5cliparser.h"
53 #elif defined HAVE_QT5
54 #  include "qt5cliparser.h"
55 #else
56 #  include "cliparser.h"
57 #endif
58
59 #if !defined(BUILD_CORE) && defined(STATIC)
60 #include <QtPlugin>
61 Q_IMPORT_PLUGIN(qjpeg)
62 Q_IMPORT_PLUGIN(qgif)
63 #endif
64
65 #include "quassel.h"
66
67 int main(int argc, char **argv)
68 {
69 #if QT_VERSION < 0x050000
70     // All our source files are in UTF-8, and Qt5 even requires that
71     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
72     QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
73 #endif
74
75     Quassel::setupBuildInfo();
76     QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
77     QCoreApplication::setApplicationVersion(Quassel::buildInfo().plainVersionString);
78     QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
79     QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
80
81     // on OSX with Qt4, raster seems to fix performance issues
82 #if QT_VERSION < 0x050000 && defined Q_OS_MAC && !defined BUILD_CORE
83     QApplication::setGraphicsSystem("raster");
84 #endif
85
86     // We need to explicitly initialize the required resources when linking statically
87 #ifndef BUILD_QTUI
88     Q_INIT_RESOURCE(sql);
89 #endif
90 #ifndef BUILD_CORE
91     Q_INIT_RESOURCE(pics);
92     Q_INIT_RESOURCE(hicolor);
93 #endif
94
95 #ifdef EMBED_DATA
96     Q_INIT_RESOURCE(i18n);
97 # ifndef BUILD_CORE
98     Q_INIT_RESOURCE(data);
99 #   ifdef WITH_OXYGEN
100     Q_INIT_RESOURCE(oxygen);
101 #   endif
102 # endif
103 #endif
104
105     AbstractCliParser *cliParser;
106
107 #ifdef HAVE_KDE4
108     // We need to init KCmdLineArgs first
109     KAboutData aboutData("quassel", "kdelibs4", ki18n("Quassel IRC"), Quassel::buildInfo().plainVersionString.toUtf8(),
110         ki18n("A modern, distributed IRC client"));
111     aboutData.addLicense(KAboutData::License_GPL_V2);
112     aboutData.addLicense(KAboutData::License_GPL_V3);
113     aboutData.setBugAddress("http://bugs.quassel-irc.org/projects/quassel-irc/issues/new");
114     aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
115     KCmdLineArgs::init(argc, argv, &aboutData);
116
117     cliParser = new KCmdLineWrapper();
118 #elif defined HAVE_QT5
119     cliParser = new Qt5CliParser();
120 #else
121     cliParser = new CliParser();
122 #endif
123     Quassel::setCliParser(cliParser);
124
125     // Initialize CLI arguments
126     // NOTE: We can't use tr() at this point, since app is not yet created
127     // TODO: Change this once we get rid of KDE4 and can initialize the parser after creating the app
128
129     // put shared client&core arguments here
130     cliParser->addSwitch("debug", 'd', "Enable debug output");
131     cliParser->addSwitch("help", 'h', "Display this help and exit");
132     cliParser->addSwitch("version", 'v', "Display version information");
133 #ifdef BUILD_QTUI
134     cliParser->addOption("configdir", 'c', "Specify the directory holding the client configuration", "path");
135 #else
136     cliParser->addOption("configdir", 'c', "Specify the directory holding configuration files, the SQlite database and the SSL certificate", "path");
137 #endif
138     cliParser->addOption("datadir", 0, "DEPRECATED - Use --configdir instead", "path");
139
140 #ifndef BUILD_CORE
141     // put client-only arguments here
142     cliParser->addOption("icontheme", 0, "Override the system icon theme ('oxygen' is recommended)", "theme");
143     cliParser->addOption("qss", 0, "Load a custom application stylesheet", "file.qss");
144     cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
145     cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
146     cliParser->addSwitch("hidewindow", 0, "Start the client minimized to the system tray");
147 #endif
148 #ifndef BUILD_QTUI
149     // put core-only arguments here
150     cliParser->addOption("listen", 0, "The address(es) quasselcore will listen on", "<address>[,<address>[,...]]", "::,0.0.0.0");
151     cliParser->addOption("port", 'p', "The port quasselcore will listen at", "port", "4242");
152     cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
153     cliParser->addOption("loglevel", 'L', "Loglevel Debug|Info|Warning|Error", "level", "Info");
154 #ifdef HAVE_SYSLOG
155     cliParser->addSwitch("syslog", 0, "Log to syslog");
156 #endif
157     cliParser->addOption("logfile", 'l', "Log to a file", "path");
158     cliParser->addOption("select-backend", 0, "Switch storage backend (migrating data if possible)", "backendidentifier");
159     cliParser->addSwitch("add-user", 0, "Starts an interactive session to add a new core user");
160     cliParser->addOption("change-userpass", 0, "Starts an interactive session to change the password of the user identified by <username>", "username");
161     cliParser->addSwitch("oidentd", 0, "Enable oidentd integration");
162     cliParser->addOption("oidentd-conffile", 0, "Set path to oidentd configuration file", "file");
163 #ifdef HAVE_SSL
164     cliParser->addSwitch("require-ssl", 0, "Require SSL for client connections");
165 #endif
166     cliParser->addSwitch("enable-experimental-dcc", 0, "Enable highly experimental and unfinished support for CTCP DCC (DANGEROUS)");
167 #endif
168
169 #ifdef HAVE_KDE4
170     // the KDE version needs this extra call to parse argc/argv before app is instantiated
171     if (!cliParser->init()) {
172         cliParser->usage();
173         return EXIT_FAILURE;
174     }
175 #endif
176
177 #  if defined BUILD_CORE
178     CoreApplication app(argc, argv);
179 #  elif defined BUILD_QTUI
180     QtUiApplication app(argc, argv);
181 #  elif defined BUILD_MONO
182     MonolithicApplication app(argc, argv);
183 #  endif
184
185 #ifndef HAVE_KDE4
186     // the non-KDE version parses after app has been instantiated
187     if (!cliParser->init(app.arguments())) {
188         cliParser->usage();
189         return false;
190     }
191 #endif
192
193 #ifdef HAVE_KF5
194     // FIXME: This should be done after loading the translation catalogue, but still in main()
195     AboutData aboutData;
196     AboutData::setQuasselPersons(&aboutData);
197     KAboutData::setApplicationData(aboutData.kAboutData());
198 #endif
199
200     if (!app.init())
201         return EXIT_FAILURE;
202
203     return app.exec();
204 }