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 "sidebarextension.h" 00041 #include "infoextension.h" 00042 #include "recentaddresses.h" 00043 using KRecentAddress::RecentAddresses; 00044 00045 #include <kapplication.h> 00046 #include <kparts/mainwindow.h> 00047 #include <kparts/genericfactory.h> 00048 #include <knotifyclient.h> 00049 #include <dcopclient.h> 00050 #include <kiconloader.h> 00051 #include <kdebug.h> 00052 00053 #include <qlayout.h> 00054 00055 00056 typedef KParts::GenericFactory< KMailPart > KMailFactory; 00057 K_EXPORT_COMPONENT_FACTORY( libkmailpart, KMailFactory ) 00058 00059 KMailPart::KMailPart(QWidget *parentWidget, const char *widgetName, 00060 QObject *parent, const char *name, const QStringList &) : 00061 DCOPObject("KMailIface"), KParts::ReadOnlyPart(parent, name), 00062 mParentWidget( parentWidget ) 00063 { 00064 kdDebug(5006) << "KMailPart()" << endl; 00065 kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl; 00066 00067 setInstance(KMailFactory::instance()); 00068 00069 kdDebug(5006) << "KMailPart()..." << endl; 00070 kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl; 00071 00072 // import i18n data and icons from libraries: 00073 KMail::insertLibraryCataloguesAndIcons(); 00074 00075 // Make sure that the KNotify Daemon is running (this is necessary for people 00076 // using KMail without KDE) 00077 KNotifyClient::startDaemon(); 00078 00079 KMail::lockOrDie(); 00080 00081 kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet 00082 00083 //local, do the init 00084 KMKernel *kmailKernel = new KMKernel(); 00085 kmailKernel->init(); 00086 kmailKernel->setXmlGuiInstance( KMailFactory::instance() ); 00087 00088 // and session management 00089 kmailKernel->doSessionManagement(); 00090 00091 // any dead letters? 00092 kmailKernel->recoverDeadLetters(); 00093 00094 kmsetSignalHandler(kmsignalHandler); 00095 kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests. 00096 00097 // create a canvas to insert our widget 00098 QWidget *canvas = new QWidget(parentWidget, widgetName); 00099 canvas->setFocusPolicy(QWidget::ClickFocus); 00100 setWidget(canvas); 00101 KGlobal::iconLoader()->addAppDir("kmail"); 00102 #if 0 00103 //It's also possible to make a part out of a readerWin 00104 KMReaderWin *mReaderWin = new KMReaderWin( canvas, canvas, actionCollection() ); 00105 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)), 00106 mReaderWin, SLOT(slotUrlClicked())); 00107 QVBoxLayout *topLayout = new QVBoxLayout(canvas); 00108 topLayout->addWidget(mReaderWin); 00109 mReaderWin->setAutoDelete( true ); 00110 kmkernel->inboxFolder()->open(); 00111 KMMessage *msg = kmkernel->inboxFolder()->getMsg(0); 00112 mReaderWin->setMsg( msg, true ); 00113 mReaderWin->setFocusPolicy(QWidget::ClickFocus); 00114 m_extension = new KMailBrowserExtension(this); 00115 mStatusBar = new KMailStatusBarExtension(this); 00116 //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this ); 00117 KGlobal::iconLoader()->addAppDir("kmail"); 00118 setXMLFile( "kmmainwin.rc" ); 00119 kmkernel->inboxFolder()->close(); 00120 #else 00121 mainWidget = new KMMainWidget( canvas, "mainWidget", actionCollection(), kapp->config()); 00122 QVBoxLayout *topLayout = new QVBoxLayout(canvas); 00123 topLayout->addWidget(mainWidget); 00124 mainWidget->setFocusPolicy(QWidget::ClickFocus); 00125 m_extension = new KMailBrowserExtension(this); 00126 mStatusBar = new KMailStatusBarExtension(this); 00127 new KParts::SideBarExtension( mainWidget->folderTree(), 00128 this, 00129 "KMailSidebar" ); 00130 00131 // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact 00132 KParts::InfoExtension *ie = new KParts::InfoExtension( this, "KMailInfo" ); 00133 connect( mainWidget->folderTree(), SIGNAL(folderSelected(KMFolder*)), this, SLOT(exportFolder(KMFolder*)) ); 00134 connect( mainWidget->folderTree(), SIGNAL(iconChanged(KMFolderTreeItem*)), 00135 this, SLOT(slotIconChanged(KMFolderTreeItem*)) ); 00136 connect( mainWidget->folderTree(), SIGNAL(nameChanged(KMFolderTreeItem*)), 00137 this, SLOT(slotNameChanged(KMFolderTreeItem*)) ); 00138 connect( mainWidget, SIGNAL(modifiedToolBarConfig()), 00139 this, SLOT(slotToolbarChanged()) ); 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 mainWidget->destruct(); 00151 kmkernel->cleanup(); 00152 delete kmkernel; 00153 KMail::cleanup(); // pid file (see kmstartup.cpp) 00154 } 00155 00156 KAboutData *KMailPart::createAboutData() 00157 { 00158 return new KMail::AboutData(); 00159 } 00160 00161 bool KMailPart::openFile() 00162 { 00163 kdDebug(5006) << "KMailPart:openFile()" << endl; 00164 00165 mainWidget->show(); 00166 return true; 00167 } 00168 00169 void KMailPart::exportFolder( KMFolder *folder ) 00170 { 00171 KMFolderTreeItem* fti = static_cast< KMFolderTreeItem* >( mainWidget->folderTree()->currentItem() ); 00172 00173 if ( folder != 0 ) 00174 emit textChanged( folder->label() ); 00175 00176 if ( fti ) 00177 emit iconChanged( fti->normalIcon( 22 ) ); 00178 } 00179 00180 void KMailPart::slotIconChanged( KMFolderTreeItem *fti ) 00181 { 00182 emit iconChanged( fti->normalIcon( 22 ) ); 00183 } 00184 00185 void KMailPart::slotNameChanged( KMFolderTreeItem *fti ) 00186 { 00187 emit textChanged( fti->folder()->label() ); 00188 } 00189 00190 //----------------------------------------------------------------------------- 00191 00192 // The sole purpose of the following class is to publicize the protected 00193 // method KParts::MainWindow::createGUI() since we need to call it so that 00194 // the toolbar is redrawn when necessary. 00195 // It can be removed once createGUI() has been made public _and_ we don't 00196 // longer rely on kdelibs 3.2. 00197 class KPartsMainWindowWithPublicizedCreateGUI : public KParts::MainWindow 00198 { 00199 public: 00200 void createGUIPublic( KParts::Part *part ) { 00201 createGUI( part ); 00202 } 00203 }; 00204 00205 void KMailPart::slotToolbarChanged() 00206 { 00207 kdDebug(5006) << "KMailPart - need to reload the toolbar" << endl; 00208 reloadXML(); 00209 KParts::MainWindow *win = 00210 dynamic_cast<KParts::MainWindow*>( mainWidget->topLevelWidget() ); 00211 if ( win ) { 00212 ( static_cast<KPartsMainWindowWithPublicizedCreateGUI*>( win ) ) 00213 ->createGUIPublic( this ); 00214 } 00215 else { 00216 kdDebug(5006) << "KMailPart::slotToolbarChanged() - " 00217 << "dynamic_cast<KPart::MainWindow*>( toplevelWidget() ) " 00218 << "failed" << endl; 00219 } 00220 } 00221 00222 //----------------------------------------------------------------------------- 00223 00224 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e) 00225 { 00226 kdDebug(5006) << "KMailPart::guiActivateEvent" << endl; 00227 KParts::ReadOnlyPart::guiActivateEvent(e); 00228 } 00229 00230 void KMailPart::exit() 00231 { 00232 delete this; 00233 } 00234 00235 QWidget* KMailPart::parentWidget() const 00236 { 00237 return mParentWidget; 00238 } 00239 00240 KMailBrowserExtension::KMailBrowserExtension(KMailPart *parent) : 00241 KParts::BrowserExtension(parent, "KMailBrowserExtension") 00242 { 00243 } 00244 00245 KMailBrowserExtension::~KMailBrowserExtension() 00246 { 00247 } 00248 00249 KMailStatusBarExtension::KMailStatusBarExtension( KMailPart *parent ) 00250 : KParts::StatusBarExtension( parent ), mParent( parent ) 00251 { 00252 } 00253 00254 KMainWindow * KMailStatusBarExtension::mainWindow() const 00255 { 00256 return static_cast<KMainWindow*>( mParent->parentWidget() ); 00257 } 00258 00259 00260 #include "kmail_part.moc" 00261
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 Aug 27 12:52:19 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003