• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
main.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
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 
21 #include <kontactinterface/pimuniqueapplication.h>
22 #include <kglobal.h>
23 #include "kmkernel.h" //control center
24 #include "kmmainwidget.h"
25 #include "kmail_options.h"
26 
27 #include <kdebug.h>
28 #include <kmessagebox.h>
29 #undef Status // stupid X headers
30 
31 #include "aboutdata.h"
32 
33 #include "kmstartup.h"
34 
35 #ifdef Q_WS_WIN
36 #include <unistd.h>
37 #include <windows.h>
38 #endif
39 
40 #include <QDir>
41 
42 //-----------------------------------------------------------------------------
43 
44 class KMailApplication : public KontactInterface::PimUniqueApplication
45 {
46 public:
47  KMailApplication() : KontactInterface::PimUniqueApplication(),
48  mDelayedInstanceCreation( false ),
49  mEventLoopReached( false ) { }
50  virtual int newInstance();
51  void commitData(QSessionManager& sm);
52  void setEventLoopReached();
53  void delayedInstanceCreation();
54 protected:
55  bool mDelayedInstanceCreation;
56  bool mEventLoopReached;
57 
58 };
59 
60 void KMailApplication::commitData(QSessionManager& sm) {
61  kmkernel->dumpDeadLetters();
62  kmkernel->setShuttingDown( true ); // Prevent further dumpDeadLetters calls
63  KApplication::commitData( sm );
64 }
65 
66 void KMailApplication::setEventLoopReached() {
67  mEventLoopReached = true;
68 }
69 
70 int KMailApplication::newInstance()
71 {
72  kDebug();
73 
74  // If the event loop hasn't been reached yet, the kernel is probably not
75  // fully initialized. Creating an instance would therefore fail, this is why
76  // that is delayed until delayedInstanceCreation() is called.
77  if ( !mEventLoopReached ) {
78  kDebug() << "Delaying instance creation.";
79  mDelayedInstanceCreation = true;
80  return 0;
81  }
82 
83  if (!kmkernel)
84  return 0;
85 
86  if (!kmkernel->firstInstance() || !kapp->isSessionRestored())
87  kmkernel->handleCommandLine( true );
88  kmkernel->setFirstInstance(false);
89  return 0;
90 }
91 
92 void KMailApplication::delayedInstanceCreation() {
93  if ( mDelayedInstanceCreation )
94  newInstance();
95 }
96 
97 int main(int argc, char *argv[])
98 {
99  // WABA: KMail is a KUniqueApplication. Unfortunately this makes debugging
100  // a bit harder: You should pass --nofork as commandline argument when using
101  // a debugger. In gdb you can do this by typing "set args --nofork" before
102  // typing "run".
103 #if 0 // for testing KUniqueAppliaction on Windows
104  MessageBoxA(NULL,
105  QString("main() %1 pid=%2").arg(argv[0]).arg(getpid()).toLatin1(),
106  QString("main() \"%1\"").arg(argv[0]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
107 #endif
108  KMail::AboutData about;
109 
110  KCmdLineArgs::setCwd(QDir::currentPath().toLocal8Bit());
111  KCmdLineArgs::init(argc, argv, &about);
112  KCmdLineArgs::addCmdLineOptions( kmail_options() ); // Add kmail options
113  if (!KMailApplication::start())
114  return 0;
115 
116  KMailApplication app;
117 
118  // Qt doesn't treat the system tray as a window, and therefore Qt would quit
119  // the event loop when an error message is clicked away while KMail is in the
120  // tray.
121  // Rely on KGlobal::ref() and KGlobal::deref() instead, like we did in KDE3.
122  // See http://bugs.kde.org/show_bug.cgi?id=163479
123  QApplication::setQuitOnLastWindowClosed( false );
124 
125  // import i18n data and icons from libraries:
126  KMail::insertLibraryCataloguesAndIcons();
127 
128  //local, do the init
129  KMKernel kmailKernel;
130  kmailKernel.init();
131 
132  // and session management
133  kmailKernel.doSessionManagement();
134 
135  // any dead letters?
136  kmailKernel.recoverDeadLetters();
137 
138  kmkernel->setupDBus(); // Ok. We are ready for D-Bus requests.
139  kmkernel->setStartingUp( false ); // Starting up is finished
140 
141  //If the instance hasn't been created yet, do that now
142  app.setEventLoopReached();
143  app.delayedInstanceCreation();
144 
145  // Go!
146  int ret = qApp->exec();
147  // clean up
148  kmailKernel.cleanup();
149  return ret;
150 }
KMKernel::init
void init()
Definition: kmkernel.cpp:1152
KMail::AboutData
Definition: aboutdata.h:40
kmmainwidget.h
KMKernel
Central point of coordination in KMail.
Definition: kmkernel.h:103
kmail_options.h
KMKernel::cleanup
void cleanup(void)
Definition: kmkernel.cpp:1250
kmail_options
static KCmdLineOptions kmail_options()
Definition: kmail_options.h:8
aboutdata.h
KMKernel::recoverDeadLetters
void recoverDeadLetters()
Definition: kmkernel.cpp:1094
kmkernel
#define kmkernel
Definition: kmkernel.h:22
kmkernel.h
kmstartup.h
KMKernel::doSessionManagement
bool doSessionManagement()
Definition: kmkernel.cpp:1201
main
int main(int argc, char *argv[])
Definition: main.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal