kontact

main.cpp
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
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20*/
21
22#include <iostream>
23
24#include <dcopclient.h>
25#include <tdeaboutdata.h>
26#include <tdecmdlineargs.h>
27#include <kdebug.h>
28#include <kiconloader.h>
29#include <tdelocale.h>
30#include <tdestartupinfo.h>
31#include <tdeuniqueapplication.h>
32#include <twin.h>
33#include <tdestandarddirs.h>
34#include <ktrader.h>
35#include "plugin.h"
36
37#include <tqlabel.h>
38#include "prefs.h"
39
40#include "alarmclient.h"
41#include "mainwindow.h"
42#include <uniqueapphandler.h> // in ../interfaces
43#include "profilemanager.h"
44
45using namespace std;
46
47static const char description[] =
48 I18N_NOOP( "TDE personal information manager" );
49
50static const char version[] = "1.2.9";
51
52class KontactApp : public TDEUniqueApplication {
53 public:
54 KontactApp() : mMainWindow( 0 ), mSessionRestored( false )
55 {
56 TDEGlobal::iconLoader()->addAppDir( "tdepim" );
57 }
58 ~KontactApp() {}
59
60 int newInstance();
61 void setMainWindow( Kontact::MainWindow *window ) {
62 mMainWindow = window;
63 setMainWidget( window );
64 }
65 void setSessionRestored( bool restored ) {
66 mSessionRestored = restored;
67 }
68
69 private:
70 void startKOrgac();
71 Kontact::MainWindow *mMainWindow;
72 bool mSessionRestored;
73};
74
75static void listPlugins()
76{
77 TDEInstance instance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options
78 TDETrader::OfferList offers = TDETrader::self()->query(
79 TQString::fromLatin1( "Kontact/Plugin" ),
80 TQString( "[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
81 for ( KService::List::Iterator it = offers.begin(); it != offers.end(); ++it ) {
82 KService::Ptr service = (*it);
83 // skip summary only plugins
84 TQVariant var = service->property( "X-TDE-KontactPluginHasPart" );
85 if ( var.isValid() && var.toBool() == false )
86 continue;
87 cout << service->library().remove( "libkontact_" ).latin1() << endl;
88 }
89}
90
91static void listProfiles()
92{
93 TQValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles();
94 for( TQValueListIterator<Kontact::Profile> it = profiles.begin() ; it != profiles.end(); ++it ) {
95 cout << (*it).name().latin1() << endl;
96 }
97}
98
99int KontactApp::newInstance()
100{
101 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
102 TQString moduleName;
103 if ( Kontact::Prefs::self()->forceStartupPlugin() ) {
104 moduleName = Kontact::Prefs::self()->forcedStartupPlugin();
105 }
106 if ( args->isSet( "module" ) ) {
107 moduleName = TQString::fromLocal8Bit( args->getOption( "module" ) );
108 }
109
110 if ( !mSessionRestored ) {
111 if ( !mMainWindow ) {
112 mMainWindow = new Kontact::MainWindow();
113 if ( !moduleName.isEmpty() )
114 mMainWindow->setActivePluginModule( moduleName );
115 mMainWindow->show();
116 setMainWidget( mMainWindow );
117 // --iconify is needed in kontact, although kstart can do that too,
118 // because kstart returns immediately so it's too early to talk DCOP to the app.
119 if ( args->isSet( "iconify" ) )
120 KWin::iconifyWindow( mMainWindow->winId(), false /*no animation*/ );
121 } else {
122 if ( !moduleName.isEmpty() )
123 mMainWindow->setActivePluginModule( moduleName );
124 }
125 }
126
127 if ( args->isSet( "profile" ) ) {
128 TQValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles();
129 for( TQValueListIterator<Kontact::Profile> it = profiles.begin(); it != profiles.end(); ++it ){
130 if( args->getOption("profile") == (*it).name().latin1() ) {
131 Kontact::ProfileManager::self()->loadProfile( (*it).id() );
132 break;
133 }
134 }
135 }
136
137 AlarmClient alarmclient;
138 alarmclient.startDaemon();
139
140 // Handle startup notification and window activation
141 // (The first time it will do nothing except note that it was called)
142 return TDEUniqueApplication::newInstance();
143}
144
145int main( int argc, char **argv )
146{
147 TDEAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
148 TDEAboutData::License_GPL,
149 I18N_NOOP("(C) 2008-2018 The Trinity Desktop Project\n(C) 2001-2008 The Kontact developers"),
150 0, "http://www.trinitydesktop.org" );
151 about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
152 about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
153 about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
154 about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
155 about.addAuthor( "David Faure", 0, "faure@kde.org" );
156 about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
157 about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
158 about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
159 about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
160
161 TDECmdLineArgs::init( argc, argv, &about );
163
164 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
165 if ( args->isSet( "list" ) ) {
166 listPlugins();
167 return 0;
168 }
169
170 if ( args->isSet( "listprofiles" ) ) {
171 listProfiles();
172 return 0;
173 }
174
175 if ( !KontactApp::start() ) {
176 // Already running, brought to the foreground.
177 return 0;
178 }
179
180 KontactApp app;
181 if ( app.restoringSession() ) {
182 // There can only be one main window
183 if ( TDEMainWindow::canBeRestored( 1 ) ) {
184 Kontact::MainWindow *mainWindow = new Kontact::MainWindow();
185 app.setMainWindow( mainWindow );
186 app.setSessionRestored( true );
187 mainWindow->show();
188 mainWindow->restore( 1 );
189 }
190 }
191
192 bool ret = app.exec();
193 while ( TDEMainWindow::memberList->first() )
194 delete TDEMainWindow::memberList->first();
195
196 return ret;
197}
static void loadKontactCommandLineOptions()
Load the kontact command line options.