kmail Library API Documentation

kmail_part.cpp

00001 /* -*- mode: C++; c-file-style: "gnu" -*- 00002 00003 This file is part of KMail. 00004 Copyright (c) 2002-2003 Don Sanders <sanders@kde.org>, 00005 Copyright (c) 2003 Zack Rusin <zack@kde.org>, 00006 Based on the work of Cornelius Schumacher <schumacher@kde.org> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 00022 As a special exception, permission is given to link this program 00023 with any edition of Qt, and distribute the resulting executable, 00024 without including the source code for Qt in the source distribution. 00025 */ 00026 00027 #ifdef HAVE_CONFIG_H 00028 #include <config.h> 00029 #endif 00030 00031 #include "kmail_part.h" 00032 00033 #include "kmmainwin.h" 00034 #include "kmmainwidget.h" 00035 #include "kmfoldertree.h" 00036 #include "kmstartup.h" 00037 #include "aboutdata.h" 00038 #include "kmkernel.h" 00039 #include "kmfolder.h" 00040 #include "kmacctmgr.h" 00041 #include "sidebarextension.h" 00042 #include "infoextension.h" 00043 #include "recentaddresses.h" 00044 using KRecentAddress::RecentAddresses; 00045 00046 #include <kapplication.h> 00047 #include <kparts/mainwindow.h> 00048 #include <kparts/genericfactory.h> 00049 #include <knotifyclient.h> 00050 #include <dcopclient.h> 00051 #include <kiconloader.h> 00052 #include <kdebug.h> 00053 00054 #include <qlayout.h> 00055 00056 00057 typedef KParts::GenericFactory< KMailPart > KMailFactory; 00058 K_EXPORT_COMPONENT_FACTORY( libkmailpart, KMailFactory ) 00059 00060 KMailPart::KMailPart(QWidget *parentWidget, const char *widgetName, 00061 QObject *parent, const char *name, const QStringList &) : 00062 DCOPObject("KMailIface"), KParts::ReadOnlyPart(parent, name), 00063 mParentWidget( parentWidget ) 00064 { 00065 kdDebug(5006) << "KMailPart()" << endl; 00066 kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl; 00067 00068 setInstance(KMailFactory::instance()); 00069 00070 kdDebug(5006) << "KMailPart()..." << endl; 00071 kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl; 00072 00073 // import i18n data and icons from libraries: 00074 KMail::insertLibraryCataloguesAndIcons(); 00075 00076 // Make sure that the KNotify Daemon is running (this is necessary for people 00077 // using KMail without KDE) 00078 KNotifyClient::startDaemon(); 00079 00080 KMail::lockOrDie(); 00081 00082 kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet 00083 00084 //local, do the init 00085 KMKernel *kmailKernel = new KMKernel(); 00086 kmailKernel->init(); 00087 kmailKernel->setXmlGuiInstance( KMailFactory::instance() ); 00088 00089 // and session management 00090 kmailKernel->doSessionManagement(); 00091 00092 // any dead letters? 00093 kmailKernel->recoverDeadLetters(); 00094 00095 kmsetSignalHandler(kmsignalHandler); 00096 kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests. 00097 00098 // create a canvas to insert our widget 00099 QWidget *canvas = new QWidget(parentWidget, widgetName); 00100 canvas->setFocusPolicy(QWidget::ClickFocus); 00101 setWidget(canvas); 00102 KGlobal::iconLoader()->addAppDir("kmail"); 00103 #if 0 00104 //It's also possible to make a part out of a readerWin 00105 KMReaderWin *mReaderWin = new KMReaderWin( canvas, canvas, actionCollection() ); 00106 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)), 00107 mReaderWin, SLOT(slotUrlClicked())); 00108 QVBoxLayout *topLayout = new QVBoxLayout(canvas); 00109 topLayout->addWidget(mReaderWin); 00110 mReaderWin->setAutoDelete( true ); 00111 kmkernel->inboxFolder()->open(); 00112 KMMessage *msg = kmkernel->inboxFolder()->getMsg(0); 00113 mReaderWin->setMsg( msg, true ); 00114 mReaderWin->setFocusPolicy(QWidget::ClickFocus); 00115 m_extension = new KMailBrowserExtension(this); 00116 mStatusBar = new KMailStatusBarExtension(this); 00117 //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this ); 00118 KGlobal::iconLoader()->addAppDir("kmail"); 00119 setXMLFile( "kmmainwin.rc" ); 00120 kmkernel->inboxFolder()->close(); 00121 #else 00122 mainWidget = new KMMainWidget( canvas, "mainWidget", this, actionCollection(), 00123 kapp->config()); 00124 QVBoxLayout *topLayout = new QVBoxLayout(canvas); 00125 topLayout->addWidget(mainWidget); 00126 mainWidget->setFocusPolicy(QWidget::ClickFocus); 00127 m_extension = new KMailBrowserExtension(this); 00128 mStatusBar = new KMailStatusBarExtension(this); 00129 new KParts::SideBarExtension( mainWidget->folderTree(), 00130 this, 00131 "KMailSidebar" ); 00132 00133 // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact 00134 KParts::InfoExtension *ie = new KParts::InfoExtension( this, "KMailInfo" ); 00135 connect( mainWidget->folderTree(), SIGNAL(folderSelected(KMFolder*)), this, SLOT(exportFolder(KMFolder*)) ); 00136 connect( mainWidget->folderTree(), SIGNAL(iconChanged(KMFolderTreeItem*)), 00137 this, SLOT(slotIconChanged(KMFolderTreeItem*)) ); 00138 connect( mainWidget->folderTree(), SIGNAL(nameChanged(KMFolderTreeItem*)), 00139 this, SLOT(slotNameChanged(KMFolderTreeItem*)) ); 00140 connect( this, SIGNAL(textChanged(const QString&)), ie, SIGNAL(textChanged(const QString&)) ); 00141 connect( this, SIGNAL(iconChanged(const QPixmap&)), ie, SIGNAL(iconChanged(const QPixmap&)) ); 00142 00143 KGlobal::iconLoader()->addAppDir( "kmail" ); 00144 setXMLFile( "kmmainwin.rc" ); 00145 #endif 00146 } 00147 00148 KMailPart::~KMailPart() 00149 { 00150 kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl; 00151 // Running KIO jobs prevent kapp from exiting, so we need to kill them 00152 // if they are only about checking mail (not important stuff like moving messages) 00153 kmkernel->abortMailCheck(); 00154 kmkernel->acctMgr()->cancelMailCheck(); 00155 00156 mainWidget->destruct(); 00157 kmkernel->cleanup(); 00158 delete kmkernel; 00159 KMail::cleanup(); // pid file (see kmstartup.cpp) 00160 } 00161 00162 KAboutData *KMailPart::createAboutData() 00163 { 00164 return new KMail::AboutData(); 00165 } 00166 00167 bool KMailPart::openFile() 00168 { 00169 kdDebug(5006) << "KMailPart:openFile()" << endl; 00170 00171 mainWidget->show(); 00172 return true; 00173 } 00174 00175 void KMailPart::exportFolder( KMFolder *folder ) 00176 { 00177 KMFolderTreeItem* fti = static_cast< KMFolderTreeItem* >( mainWidget->folderTree()->currentItem() ); 00178 00179 if ( folder != 0 ) 00180 emit textChanged( folder->label() ); 00181 00182 if ( fti ) 00183 emit iconChanged( fti->normalIcon( 22 ) ); 00184 } 00185 00186 void KMailPart::slotIconChanged( KMFolderTreeItem *fti ) 00187 { 00188 emit iconChanged( fti->normalIcon( 22 ) ); 00189 } 00190 00191 void KMailPart::slotNameChanged( KMFolderTreeItem *fti ) 00192 { 00193 emit textChanged( fti->folder()->label() ); 00194 } 00195 00196 //----------------------------------------------------------------------------- 00197 00198 // The sole purpose of the following class is to publicize the protected 00199 // method KParts::MainWindow::createGUI() since we need to call it so that 00200 // the toolbar is redrawn when necessary. 00201 // It can be removed once createGUI() has been made public _and_ we don't 00202 // longer rely on kdelibs 3.2. 00203 class KPartsMainWindowWithPublicizedCreateGUI : public KParts::MainWindow 00204 { 00205 public: 00206 void createGUIPublic( KParts::Part *part ) { 00207 createGUI( part ); 00208 } 00209 }; 00210 00211 //----------------------------------------------------------------------------- 00212 00213 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e) 00214 { 00215 kdDebug(5006) << "KMailPart::guiActivateEvent" << endl; 00216 KParts::ReadOnlyPart::guiActivateEvent(e); 00217 } 00218 00219 void KMailPart::exit() 00220 { 00221 delete this; 00222 } 00223 00224 QWidget* KMailPart::parentWidget() const 00225 { 00226 return mParentWidget; 00227 } 00228 00229 KMailBrowserExtension::KMailBrowserExtension(KMailPart *parent) : 00230 KParts::BrowserExtension(parent, "KMailBrowserExtension") 00231 { 00232 } 00233 00234 KMailBrowserExtension::~KMailBrowserExtension() 00235 { 00236 } 00237 00238 KMailStatusBarExtension::KMailStatusBarExtension( KMailPart *parent ) 00239 : KParts::StatusBarExtension( parent ), mParent( parent ) 00240 { 00241 } 00242 00243 KMainWindow * KMailStatusBarExtension::mainWindow() const 00244 { 00245 return static_cast<KMainWindow*>( mParent->parentWidget() ); 00246 } 00247 00248 00249 #include "kmail_part.moc" 00250
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:17 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003