kmail

main.cpp
1/*
2 * kmail: KDE mail client
3 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.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) any later version.
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 Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#include <config.h>
21
22#include <tdeuniqueapplication.h>
23#include <tdeglobal.h>
24#include <knotifyclient.h>
25#include <dcopclient.h>
26#include "kmkernel.h" //control center
27#include "kmail_options.h"
28
29#include <kdebug.h>
30
31#undef Status // stupid X headers
32
33#include "aboutdata.h"
34
35#include "kmstartup.h"
36
37//-----------------------------------------------------------------------------
38
39class KMailApplication : public TDEUniqueApplication
40{
41public:
42 KMailApplication() : TDEUniqueApplication() { };
43 virtual int newInstance();
44 void commitData(TQSessionManager& sm);
45
46};
47
48void KMailApplication::commitData(TQSessionManager& sm) {
49 kmkernel->dumpDeadLetters();
50 kmkernel->setShuttingDown( true ); // Prevent further dumpDeadLetters calls
51 TDEApplication::commitData( sm );
52}
53
54
55int KMailApplication::newInstance()
56{
57 kdDebug(5006) << "KMailApplication::newInstance()" << endl;
58 if (!kmkernel)
59 return 0;
60
61 if (!kmkernel->firstInstance() || !tdeApp->isRestored())
62 kmkernel->handleCommandLine( true );
63 kmkernel->setFirstInstance(FALSE);
64 return 0;
65}
66
67int main(int argc, char *argv[])
68{
69 // WABA: KMail is a TDEUniqueApplication. Unfortunately this makes debugging
70 // a bit harder: You should pass --nofork as commandline argument when using
71 // a debugger. In gdb you can do this by typing "set args --nofork" before
72 // typing "run".
73
74 KMail::AboutData about;
75
76 TDECmdLineArgs::init(argc, argv, &about);
77 TDECmdLineArgs::addCmdLineOptions( kmail_options ); // Add kmail options
78 if (!KMailApplication::start())
79 return 0;
80
81 KMailApplication app;
82
83 // import i18n data and icons from libraries:
84 KMail::insertLibraryCataloguesAndIcons();
85
86 // Make sure that the KNotify Daemon is running (this is necessary for people
87 // using KMail without KDE)
88 KNotifyClient::startDaemon();
89
90 tdeApp->dcopClient()->suspend(); // Don't handle DCOP requests yet
91
92 KMail::lockOrDie();
93
94 //local, do the init
95 KMKernel kmailKernel;
96 kmailKernel.init();
97 tdeApp->dcopClient()->setDefaultObject( kmailKernel.objId() );
98
99 // and session management
100 kmailKernel.doSessionManagement();
101
102 // any dead letters?
103 kmailKernel.recoverDeadLetters();
104
105 kmsetSignalHandler(kmsignalHandler);
106
107 tdeApp->dcopClient()->resume(); // Ok. We are ready for DCOP requests.
108 kmailKernel.setStartingUp( false ); // Starting up is finished
109 // Go!
110 int ret = tdeApp->exec();
111 // clean up
112 kmailKernel.cleanup();
113
114 KMail::cleanup(); // pid file (see kmstartup.cpp)
115 return ret;
116}
Central point of coordination in KMail.
Definition: kmkernel.h:92