kmail

kmail_part.cpp
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  This file is part of KMail.
4  Copyright (c) 2002-2003 Don Sanders <sanders@kde.org>,
5  Copyright (c) 2003 Zack Rusin <zack@kde.org>,
6  Based on the work of Cornelius Schumacher <schumacher@kde.org>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of TQt, and distribute the resulting executable,
24  without including the source code for TQt in the source distribution.
25 */
26 
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 
31 #include "kmail_part.h"
32 
33 #include "kmmainwin.h"
34 #include "kmmainwidget.h"
35 #include "kmfoldertree.h"
36 #include "kmstartup.h"
37 #include "aboutdata.h"
38 #include "kmfolder.h"
39 #include "accountmanager.h"
41 #include "sidebarextension.h"
42 #include "infoextension.h"
43 #include "recentaddresses.h"
44 using TDERecentAddress::RecentAddresses;
45 
46 #include <tdeapplication.h>
47 #include <tdeparts/mainwindow.h>
48 #include <tdeparts/genericfactory.h>
49 #include <knotifyclient.h>
50 #include <dcopclient.h>
51 #include <kiconloader.h>
52 #include <kdebug.h>
53 #include <kstatusbar.h>
54 #include <ksettings/dispatcher.h>
55 
56 
57 #include <tqlayout.h>
58 
59 
60 typedef KParts::GenericFactory< KMailPart > KMailFactory;
61 K_EXPORT_COMPONENT_FACTORY( libkmailpart, KMailFactory )
62 
63 KMailPart::KMailPart(TQWidget *parentWidget, const char *widgetName,
64  TQObject *parent, const char *name, const TQStringList &) :
65  DCOPObject("KMailIface"), KParts::ReadOnlyPart(parent, name),
66  mParentWidget( parentWidget )
67 {
68  kdDebug(5006) << "KMailPart()" << endl;
69  kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl;
70 
71  setInstance(KMailFactory::instance());
72 
73  kdDebug(5006) << "KMailPart()..." << endl;
74  kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl;
75 
76  // import i18n data and icons from libraries:
77  KMail::insertLibraryCataloguesAndIcons();
78 
79  // Make sure that the KNotify Daemon is running (this is necessary for people
80  // using KMail without KDE)
81  KNotifyClient::startDaemon();
82 
83  KMail::lockOrDie();
84 
85  kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet
86 
87  //local, do the init
88  KMKernel *mKMailKernel = new KMKernel();
89  mKMailKernel->init();
90  mKMailKernel->setXmlGuiInstance( KMailFactory::instance() );
91 
92  // and session management
93  mKMailKernel->doSessionManagement();
94 
95  // any dead letters?
96  mKMailKernel->recoverDeadLetters();
97 
98  kmsetSignalHandler(kmsignalHandler);
99  kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests.
100 
101  // create a canvas to insert our widget
102  TQWidget *canvas = new TQWidget(parentWidget, widgetName);
103  canvas->setFocusPolicy(TQ_ClickFocus);
104  setWidget(canvas);
105  TDEGlobal::iconLoader()->addAppDir("kmail");
106 #if 0
107  //It's also possible to make a part out of a readerWin
108  KMReaderWin *mReaderWin = new KMReaderWin( canvas, canvas, actionCollection() );
109  connect(mReaderWin, TQT_SIGNAL(urlClicked(const KURL&,int)),
110  mReaderWin, TQT_SLOT(slotUrlClicked()));
111  TQVBoxLayout *topLayout = new TQVBoxLayout(canvas);
112  topLayout->addWidget(mReaderWin);
113  mReaderWin->setAutoDelete( true );
114  kmkernel->inboxFolder()->open();
115  KMMessage *msg = kmkernel->inboxFolder()->getMsg(0);
116  mReaderWin->setMsg( msg, true );
117  mReaderWin->setFocusPolicy(TQWidget::ClickFocus);
118  mStatusBar = new KMailStatusBarExtension(this);
119  //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this );
120  TDEGlobal::iconLoader()->addAppDir("kmail");
121  setXMLFile( "kmail_part.rc" );
122  kmkernel->inboxFolder()->close();
123 #else
124  mainWidget = new KMMainWidget( canvas, "mainWidget", this, actionCollection(),
125  kapp->config());
126  TQVBoxLayout *topLayout = new TQVBoxLayout(canvas);
127  topLayout->addWidget(mainWidget);
128  mainWidget->setFocusPolicy(TQ_ClickFocus);
129  mStatusBar = new KMailStatusBarExtension(this);
130  mStatusBar->addStatusBarItem( mainWidget->vacationScriptIndicator(), 2, false );
131 
132  new KParts::SideBarExtension( mainWidget->folderTree(),
133  this,
134  "KMailSidebar" );
135 
136  // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact
137  KParts::InfoExtension *ie = new KParts::InfoExtension( this, "KMailInfo" );
138  connect( mainWidget->folderTree(), TQT_SIGNAL(folderSelected(KMFolder*)), this, TQT_SLOT(exportFolder(KMFolder*)) );
139  connect( mainWidget->folderTree(), TQT_SIGNAL(iconChanged(KMFolderTreeItem*)),
140  this, TQT_SLOT(slotIconChanged(KMFolderTreeItem*)) );
141  connect( mainWidget->folderTree(), TQT_SIGNAL(nameChanged(KMFolderTreeItem*)),
142  this, TQT_SLOT(slotNameChanged(KMFolderTreeItem*)) );
143  connect( this, TQT_SIGNAL(textChanged(const TQString&)), ie, TQT_SIGNAL(textChanged(const TQString&)) );
144  connect( this, TQT_SIGNAL(iconChanged(const TQPixmap&)), ie, TQT_SIGNAL(iconChanged(const TQPixmap&)) );
145 
146  TDEGlobal::iconLoader()->addAppDir( "kmail" );
147  setXMLFile( "kmail_part.rc" );
148 #endif
149 
150  KSettings::Dispatcher::self()->registerInstance( KMailFactory::instance(), mKMailKernel,
151  TQT_SLOT( slotConfigChanged() ) );
152 }
153 
154 KMailPart::~KMailPart()
155 {
156  kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
157  // Running TDEIO jobs prevent kapp from exiting, so we need to kill them
158  // if they are only about checking mail (not important stuff like moving messages)
159  kmkernel->abortMailCheck();
160  kmkernel->acctMgr()->cancelMailCheck();
161 
162  mainWidget->destruct();
163  kmkernel->cleanup();
164  delete kmkernel;
165  KMail::cleanup(); // pid file (see kmstartup.cpp)
166 }
167 
168 TDEAboutData *KMailPart::createAboutData()
169 {
170  return new KMail::AboutData();
171 }
172 
173 bool KMailPart::openFile()
174 {
175  kdDebug(5006) << "KMailPart:openFile()" << endl;
176 
177  mainWidget->show();
178  return true;
179 }
180 
181 void KMailPart::exportFolder( KMFolder *folder )
182 {
183  KMFolderTreeItem* fti = static_cast< KMFolderTreeItem* >( mainWidget->folderTree()->currentItem() );
184 
185  if ( folder != 0 )
186  emit textChanged( folder->label() );
187 
188  if ( fti )
189  emit iconChanged( fti->normalIcon( 22 ) );
190 }
191 
192 void KMailPart::slotIconChanged( KMFolderTreeItem *fti )
193 {
194  emit iconChanged( fti->normalIcon( 22 ) );
195 }
196 
197 void KMailPart::slotNameChanged( KMFolderTreeItem *fti )
198 {
199  emit textChanged( fti->folder()->label() );
200 }
201 
202 //-----------------------------------------------------------------------------
203 
204 // The sole purpose of the following class is to publicize the protected
205 // method KParts::MainWindow::createGUI() since we need to call it so that
206 // the toolbar is redrawn when necessary.
207 // It can be removed once createGUI() has been made public _and_ we don't
208 // longer rely on tdelibs 3.2.
209 class KPartsMainWindowWithPublicizedCreateGUI : public KParts::MainWindow
210 {
211 public:
212  void createGUIPublic( KParts::Part *part ) {
213  createGUI( part );
214  }
215 };
216 
217 //-----------------------------------------------------------------------------
218 
219 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
220 {
221  kdDebug(5006) << "KMailPart::guiActivateEvent" << endl;
222  KParts::ReadOnlyPart::guiActivateEvent(e);
223  mainWidget->initializeFilterActions();
224  mainWidget->initializeFolderShortcutActions();
225  mainWidget->setupForwardingActionsList();
226  mainWidget->updateVactionScripStatus();
227 }
228 
229 void KMailPart::exit()
230 {
231  delete this;
232 }
233 
234 TQWidget* KMailPart::parentWidget() const
235 {
236  return mParentWidget;
237 }
238 
239 
240 KMailStatusBarExtension::KMailStatusBarExtension( KMailPart *parent )
241  : KParts::StatusBarExtension( parent ), mParent( parent )
242 {
243 }
244 
245 TDEMainWindow * KMailStatusBarExtension::mainWindow() const
246 {
247  return static_cast<TDEMainWindow*>( mParent->parentWidget() );
248 }
249 
250 #include "kmail_part.moc"
251 
This class implements a "reader window", that is a window used for reading or viewing messages...
Definition: kmreaderwin.h:76
Central point of coordination in KMail.
Definition: kmkernel.h:93
checkMail wont show reader but will check mail.
Definition: kmailIface.h:17
Mail folder.
Definition: kmfolder.h:68
virtual void setMsg(KMMessage *msg, bool force=false, bool updateOnly=false)
Set the message that shall be shown.
virtual TQString label() const
Returns the label of the folder for visualization.
Definition: kmfolder.cpp:581
The account manager is responsible for creating accounts of various types via the factory method crea...
This is a Mime Message.
Definition: kmmessage.h:68