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