1f556240e9d1aea33ed87f00e8964b8d8cd860e4
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 HAVE_KDE
24 #  include <KCmdLineArgs>
25 #  include <KAboutData>
26 #endif
27
28 #ifdef BUILD_CORE
29 #  include "coreapplication.h"
30 #elif defined BUILD_QTUI
31 #  include "qtuiapplication.h"
32 #elif defined BUILD_MONO
33 #  include "monoapplication.h"
34
35 #else
36 #error "Something is wrong - you need to #define a build mode!"
37 #endif
38
39 #include "quassel.h"
40
41 int main(int argc, char **argv) {
42
43   // Setup build information and version string
44   # include "version.gen"
45   buildinfo.append(QString(",%1,%2").arg(__DATE__, __TIME__));
46   Quassel::setupBuildInfo(buildinfo);
47   QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
48   QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
49   QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
50
51 #ifdef HAVE_KDE
52   // We need to init KCmdLineArgs first
53   // TODO: build an AboutData class to replace our aboutDlg strings
54   KAboutData aboutData(argv[0], 0, ki18n("Quassel IRC"), Quassel::buildInfo().plainVersionString.toUtf8());
55   aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
56   KCmdLineArgs::init(argc, argv, &aboutData);
57 #endif
58
59   // Initialize CLI arguments
60   // NOTE: We can't use tr() at this point, since app is not yet created
61   CliParser *cliParser = Quassel::cliParser();
62
63   // put shared client&core arguments here
64   cliParser->addSwitch("debug",'d', "Enable debug output");
65   cliParser->addSwitch("help",'h', "Display this help and exit");
66
67 #ifndef BUILD_CORE
68   // put client-only arguments here
69   cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
70   cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
71 #endif
72 #ifndef BUILD_QTCLIENT
73   // put core-only arguments here
74   cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
75   cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
76   cliParser->addOption("logfile <path>", 'l', "Path to logfile");
77   cliParser->addOption("loglevel <level>", 'L', "Loglevel Debug|Info|Warning|Error", "Info");
78   cliParser->addOption("datadir <path>", 0, "Specify the directory holding datafiles like the Sqlite DB and the SSL Cert");
79 #endif
80
81 #ifdef HAVE_KDE
82   // the KDE version needs this extra call to parse argc/argv before app is instantiated
83   if(!cliParser->init()) {
84     cliParser->usage();
85     return EXIT_FAILURE;
86   }
87 #endif
88
89 #  if defined BUILD_CORE
90     CoreApplication app(argc, argv);
91 #  elif defined BUILD_QTUI
92     QtUiApplication app(argc, argv);
93 #  elif defined BUILD_MONO
94     MonolithicApplication app(argc, argv);
95 #  endif
96
97 #ifndef HAVE_KDE
98   // the non-KDE version parses after app has been instantiated
99   if(!cliParser->init(app.arguments())) {
100     cliParser->usage();
101     return false;
102   }
103 #endif
104
105   if(!app.init()) return EXIT_FAILURE;
106   return app.exec();
107 }