kmail

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