kmail Library API Documentation

kmail_part.cpp

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