Add listen option.
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "cliparser.h"
45 #include "quassel.h"
46
47 int main(int argc, char **argv) {
48   Q_INIT_RESOURCE(i18n);
49
50   // Setup build information and version string
51   # include "version.gen"
52   buildinfo.append(QString(",%1,%2").arg(__DATE__, __TIME__));
53   Quassel::setupBuildInfo(buildinfo);
54   QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
55   QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
56   QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
57
58   AbstractCliParser *cliParser;
59
60 #ifdef HAVE_KDE
61   // We need to init KCmdLineArgs first
62   // TODO: build an AboutData compat class to replace our aboutDlg strings
63   KAboutData aboutData("quassel", "kdelibs4", ki18n("Quassel IRC"), Quassel::buildInfo().plainVersionString.toUtf8(),
64                         ki18n("A modern, distributed IRC client"));
65   aboutData.addLicense(KAboutData::License_GPL_V2);
66   aboutData.addLicense(KAboutData::License_GPL_V3);
67   aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
68   KCmdLineArgs::init(argc, argv, &aboutData);
69
70   cliParser = new KCmdLineWrapper();
71 #else
72   cliParser = new CliParser();
73 #endif
74   Quassel::setCliParser(cliParser);
75
76   // Initialize CLI arguments
77   // NOTE: We can't use tr() at this point, since app is not yet created
78
79   // put shared client&core arguments here
80   cliParser->addSwitch("debug",'d', "Enable debug output");
81   cliParser->addSwitch("help",'h', "Display this help and exit");
82
83 #ifndef BUILD_CORE
84   // put client-only arguments here
85   cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
86   cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
87 #endif
88 #ifndef BUILD_QTCLIENT
89   // put core-only arguments here
90   cliParser->addOption("listen <address>[,<address[,...]]>", 0, "The address(es) quasselcore will listen on", "0.0.0.0,::");
91   cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
92   cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
93   cliParser->addOption("logfile <path>", 'l', "Path to logfile");
94   cliParser->addOption("loglevel <level>", 'L', "Loglevel Debug|Info|Warning|Error", "Info");
95   cliParser->addOption("datadir <path>", 0, "Specify the directory holding datafiles like the Sqlite DB and the SSL Cert");
96 #endif
97
98 #ifdef HAVE_KDE
99   // the KDE version needs this extra call to parse argc/argv before app is instantiated
100   if(!cliParser->init()) {
101     cliParser->usage();
102     return EXIT_FAILURE;
103   }
104 #endif
105
106 #  if defined BUILD_CORE
107     CoreApplication app(argc, argv);
108 #  elif defined BUILD_QTUI
109     QtUiApplication app(argc, argv);
110 #  elif defined BUILD_MONO
111     MonolithicApplication app(argc, argv);
112 #  endif
113
114 #ifndef HAVE_KDE
115   // the non-KDE version parses after app has been instantiated
116   if(!cliParser->init(app.arguments())) {
117     cliParser->usage();
118     return false;
119   }
120 #endif
121
122   if(!app.init()) return EXIT_FAILURE;
123   return app.exec();
124 }