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