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