kmail

main.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #include <config.h>
00021 
00022 #include <kuniqueapplication.h>
00023 #include <kglobal.h>
00024 #include <knotifyclient.h>
00025 #include <dcopclient.h>
00026 #include "kmkernel.h" //control center
00027 #include "kmail_options.h"
00028 
00029 #include <kdebug.h>
00030 
00031 #undef Status // stupid X headers
00032 
00033 #include "aboutdata.h"
00034 
00035 #include "kmstartup.h"
00036 
00037 //-----------------------------------------------------------------------------
00038 
00039 class KMailApplication : public KUniqueApplication
00040 {
00041 public:
00042   KMailApplication() : KUniqueApplication() { };
00043   virtual int newInstance();
00044   void commitData(QSessionManager& sm);
00045 
00046 };
00047 
00048 void KMailApplication::commitData(QSessionManager& sm) {
00049   kmkernel->dumpDeadLetters();
00050   kmkernel->setShuttingDown( true ); // Prevent further dumpDeadLetters calls
00051   KApplication::commitData( sm );
00052 }
00053 
00054 
00055 int KMailApplication::newInstance()
00056 {
00057   kdDebug(5006) << "KMailApplication::newInstance()" << endl;
00058   if (!kmkernel)
00059      return 0;
00060 
00061   if (!kmkernel->firstInstance() || !kapp->isRestored())
00062     kmkernel->handleCommandLine( true );
00063   kmkernel->setFirstInstance(FALSE);
00064   return 0;
00065 }
00066 
00067 int main(int argc, char *argv[])
00068 {
00069   // WABA: KMail is a KUniqueApplication. Unfortunately this makes debugging
00070   // a bit harder: You should pass --nofork as commandline argument when using
00071   // a debugger. In gdb you can do this by typing "set args --nofork" before
00072   // typing "run".
00073 
00074   KMail::AboutData about;
00075 
00076   KCmdLineArgs::init(argc, argv, &about);
00077   KCmdLineArgs::addCmdLineOptions( kmail_options ); // Add kmail options
00078   if (!KMailApplication::start())
00079      return 0;
00080 
00081   KMailApplication app;
00082 
00083   // import i18n data and icons from libraries:
00084   KMail::insertLibraryCataloguesAndIcons();
00085 
00086   // Make sure that the KNotify Daemon is running (this is necessary for people
00087   // using KMail without KDE)
00088   KNotifyClient::startDaemon();
00089 
00090   kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet
00091 
00092   KMail::lockOrDie();
00093 
00094   //local, do the init
00095   KMKernel kmailKernel;
00096   kmailKernel.init();
00097   kapp->dcopClient()->setDefaultObject( kmailKernel.objId() );
00098 
00099   // and session management
00100   kmailKernel.doSessionManagement();
00101 
00102   // any dead letters?
00103   kmailKernel.recoverDeadLetters();
00104 
00105   kmsetSignalHandler(kmsignalHandler);
00106 
00107   kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests.
00108   kmkernel->setStartingUp( false ); // Starting up is finished
00109   // Go!
00110   int ret = kapp->exec();
00111   // clean up
00112   kmailKernel.cleanup();
00113 
00114   KMail::cleanup(); // pid file (see kmstartup.cpp)
00115   return ret;
00116 }