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