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

kontact

  • sources
  • kde-4.14
  • kdepim
  • kontact
  • src
main.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
5  Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
22 // Use the kdepim version
23 #include "kdepim-version.h"
24 
25 #include "mainwindow.h"
26 #include "prefs.h"
27 using namespace Kontact;
28 
29 #include <libkdepimdbusinterfaces/reminderclient.h>
30 
31 #include <KontactInterface/Plugin>
32 #include <KontactInterface/UniqueAppHandler>
33 #ifdef Q_WS_WIN
34 #include <KontactInterface/PimUniqueApplication>
35 #endif
36 
37 #include <KAboutData>
38 #include <KCmdLineArgs>
39 #include <KLocale>
40 #include <KService>
41 #include <KServiceTypeTrader>
42 #include <KUniqueApplication>
43 #include <KWindowSystem>
44 
45 #include <iostream>
46 using namespace std;
47 
48 static const char description[] = I18N_NOOP( "KDE personal information manager" );
49 
50 static const char version[] = KDEPIM_VERSION;
51 
52 class KontactApp : public
53  #ifdef Q_WS_WIN
54  KontactInterface::PimUniqueApplication
55  #else
56  KUniqueApplication
57  #endif
58 {
59  Q_OBJECT
60 public:
61  KontactApp() : mMainWindow( 0 ), mSessionRestored( false )
62  {
63  KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
64  }
65  ~KontactApp() {}
66 
67  /*reimp*/
68  int newInstance();
69 
70  void setMainWindow( MainWindow *window )
71  {
72  mMainWindow = window;
73  KontactInterface::UniqueAppHandler::setMainWidget( window );
74  }
75  void setSessionRestored( bool restored )
76  {
77  mSessionRestored = restored;
78  }
79 
80 public Q_SLOTS:
81  void loadCommandLineOptionsForNewInstance();
82 
83 private:
84  QPointer<MainWindow> mMainWindow;
85  bool mSessionRestored;
86 };
87 
88 static void listPlugins()
89 {
90  KComponentData instance( "kontact" ); //Can't use KontactApp -- too late for adding cmdline opts
91 
92  const KService::List offers = KServiceTypeTrader::self()->query(
93  QString::fromLatin1( "Kontact/Plugin" ),
94  QString::fromLatin1( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
95  KService::List::ConstIterator end( offers.end() );
96  for ( KService::List::ConstIterator it = offers.begin(); it != end; ++it ) {
97  KService::Ptr service = (*it);
98  // skip summary only plugins
99  QVariant var = service->property( QLatin1String("X-KDE-KontactPluginHasPart") );
100  if ( var.isValid() && var.toBool() == false ) {
101  continue;
102  }
103  cout << service->library().remove( QLatin1String("kontact_") ).toLatin1().data() << endl;
104  }
105 }
106 
107 static void loadCommandLineOptions()
108 {
109  KCmdLineOptions options;
110  options.add( "module <module>", ki18n( "Start with a specific Kontact module" ) );
111  options.add( "iconify", ki18n( "Start in iconified (minimized) mode" ) );
112  options.add( "list", ki18n( "List all possible modules and exit" ) );
113  KCmdLineArgs::addCmdLineOptions( options );
114 }
115 
116 // Called by KUniqueApplication
117 void KontactApp::loadCommandLineOptionsForNewInstance()
118 {
119  KCmdLineArgs::reset(); // forget options defined by other "applications"
120  loadCommandLineOptions(); // re-add the kontact options
121 }
122 
123 int KontactApp::newInstance()
124 {
125  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
126  QString moduleName;
127  if ( Prefs::self()->forceStartupPlugin() ) {
128  moduleName = Prefs::self()->forcedStartupPlugin();
129  }
130  if ( args->isSet( "module" ) ) {
131  moduleName = args->getOption( "module" );
132  }
133  if ( !mSessionRestored ) {
134  if ( !mMainWindow ) {
135  mMainWindow = new MainWindow();
136  if ( !moduleName.isEmpty() ) {
137  mMainWindow->setInitialActivePluginModule( moduleName );
138  }
139  mMainWindow->show();
140  KontactInterface::UniqueAppHandler::setMainWidget( mMainWindow );
141  // --iconify is needed in kontact, although kstart can do that too,
142  // because kstart returns immediately so it's too early to talk D-Bus to the app.
143  if ( args->isSet( "iconify" ) ) {
144  KWindowSystem::minimizeWindow( mMainWindow->winId(), false /*no animation*/);
145  }
146  } else {
147  if ( !moduleName.isEmpty() ) {
148  mMainWindow->setInitialActivePluginModule( moduleName );
149  }
150  }
151  }
152 
153  KPIM::ReminderClient::startDaemon();
154 
155  // Handle startup notification and window activation
156  // (The first time it will do nothing except note that it was called)
157  return KUniqueApplication::newInstance();
158 }
159 
160 int main( int argc, char **argv )
161 {
162  KAboutData about( "kontact", 0, ki18n( "Kontact" ), version, ki18n(description),
163  KAboutData::License_GPL,
164  ki18n( "Copyright © 2001–2014 Kontact authors" ),
165  KLocalizedString(), "https://userbase.kde.org/Kontact" );
166 
167  about.addAuthor( ki18n( "Allen Winter" ), KLocalizedString(), "winter@kde.org" );
168  about.addAuthor( ki18n( "Rafael Fernández López" ), KLocalizedString(), "ereslibre@kde.org" );
169  about.addAuthor( ki18n( "Daniel Molkentin" ), KLocalizedString(), "molkentin@kde.org" );
170  about.addAuthor( ki18n( "Don Sanders" ), KLocalizedString(), "sanders@kde.org" );
171  about.addAuthor( ki18n( "Cornelius Schumacher" ), KLocalizedString(), "schumacher@kde.org" );
172  about.addAuthor( ki18n( "Tobias K\303\266nig" ), KLocalizedString(), "tokoe@kde.org" );
173  about.addAuthor( ki18n( "David Faure" ), KLocalizedString(), "faure@kde.org" );
174  about.addAuthor( ki18n( "Ingo Kl\303\266cker" ), KLocalizedString(), "kloecker@kde.org" );
175  about.addAuthor( ki18n( "Sven L\303\274ppken" ), KLocalizedString(), "sven@kde.org" );
176  about.addAuthor( ki18n( "Zack Rusin" ), KLocalizedString(), "zack@kde.org" );
177  about.addAuthor( ki18n( "Matthias Hoelzer-Kluepfel" ),
178  ki18n( "Original Author" ), "mhk@kde.org" );
179  about.addCredit( ki18n( "Torgny Nyblom" ), ki18n("Git Migration"), "nyblom@kde.org" );
180  about.setOrganizationDomain( "kde.org" );
181 
182  KCmdLineArgs::init( argc, argv, &about );
183 
184  loadCommandLineOptions();
185  KUniqueApplication::addCmdLineOptions();
186  KCmdLineArgs::addStdCmdLineOptions();
187 
188  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
189  if ( args->isSet( "list" ) ) {
190  listPlugins();
191  return 0;
192  }
193 
194  if ( !KontactApp::start() ) {
195  // Already running, brought to the foreground.
196  return 0;
197  }
198 
199  KontactApp app;
200 
201  // Qt doesn't treat the system tray as a window, and therefore Qt would quit
202  // the event loop when an error message is clicked away while Kontact is in the
203  // tray.
204  // Rely on KGlobal::ref() and KGlobal::deref() instead, like we did in KDE3.
205  // See http://bugs.kde.org/show_bug.cgi?id=163479
206  QApplication::setQuitOnLastWindowClosed( false );
207 
208  if ( app.restoringSession() ) {
209  // There can only be one main window
210  if ( KMainWindow::canBeRestored( 1 ) ) {
211  MainWindow *mainWindow = new MainWindow();
212  app.setMainWindow( mainWindow );
213  app.setSessionRestored( true );
214  mainWindow->show();
215  mainWindow->restore( 1 );
216  }
217  }
218 
219  bool ret = app.exec();
220  qDeleteAll( KMainWindow::memberList() );
221 
222  return ret;
223 }
224 
225 #include "main.moc"
QApplication::setQuitOnLastWindowClosed
void setQuitOnLastWindowClosed(bool quit)
main
int main(int argc, char **argv)
Definition: main.cpp:160
QPointer< MainWindow >
listPlugins
static void listPlugins()
Definition: main.cpp:88
Kontact::MainWindow
Definition: mainwindow.h:51
QString::isEmpty
bool isEmpty() const
mainwindow.h
QString
QLatin1String
QVariant::toBool
bool toBool() const
description
static const char description[]
Definition: main.cpp:48
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QVariant::isValid
bool isValid() const
loadCommandLineOptions
static void loadCommandLineOptions()
Definition: main.cpp:107
version
static const char version[]
Definition: main.cpp:50
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • 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
  • pimprint

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