kmail

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "kmfolder.h"
00039 #include "accountmanager.h"
00040 using KMail::AccountManager;
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   mStatusBar  = new KMailStatusBarExtension(this);
00118   //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this );
00119   KGlobal::iconLoader()->addAppDir("kmail");
00120   setXMLFile( "kmail_part.rc" );
00121   kmkernel->inboxFolder()->close();
00122 #else
00123   mainWidget = new KMMainWidget( canvas, "mainWidget", this, actionCollection(),
00124                                  kapp->config());
00125   QVBoxLayout *topLayout = new QVBoxLayout(canvas);
00126   topLayout->addWidget(mainWidget);
00127   mainWidget->setFocusPolicy(QWidget::ClickFocus);
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( "kmail_part.rc" );
00145 #endif
00146 
00147   KSettings::Dispatcher::self()->registerInstance( KMailFactory::instance(), mKMailKernel,
00148                                                    SLOT( slotConfigChanged() ) );
00149 }
00150 
00151 KMailPart::~KMailPart()
00152 {
00153   kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
00154   // Running KIO jobs prevent kapp from exiting, so we need to kill them
00155   // if they are only about checking mail (not important stuff like moving messages)
00156   kmkernel->abortMailCheck();
00157   kmkernel->acctMgr()->cancelMailCheck();
00158 
00159   mainWidget->destruct();
00160   kmkernel->cleanup();
00161   delete kmkernel;
00162   KMail::cleanup(); // pid file (see kmstartup.cpp)
00163 }
00164 
00165 KAboutData *KMailPart::createAboutData()
00166 {
00167   return new KMail::AboutData();
00168 }
00169 
00170 bool KMailPart::openFile()
00171 {
00172   kdDebug(5006) << "KMailPart:openFile()" << endl;
00173 
00174   mainWidget->show();
00175   return true;
00176 }
00177 
00178 void KMailPart::exportFolder( KMFolder *folder )
00179 {
00180   KMFolderTreeItem* fti = static_cast< KMFolderTreeItem* >( mainWidget->folderTree()->currentItem() );
00181 
00182   if ( folder != 0 )
00183     emit textChanged( folder->label() );
00184 
00185   if ( fti )
00186     emit iconChanged( fti->normalIcon( 22 ) );
00187 }
00188 
00189 void KMailPart::slotIconChanged( KMFolderTreeItem *fti )
00190 {
00191   emit iconChanged( fti->normalIcon( 22 ) );
00192 }
00193 
00194 void KMailPart::slotNameChanged( KMFolderTreeItem *fti )
00195 {
00196   emit textChanged( fti->folder()->label() );
00197 }
00198 
00199 //-----------------------------------------------------------------------------
00200 
00201 // The sole purpose of the following class is to publicize the protected
00202 // method KParts::MainWindow::createGUI() since we need to call it so that
00203 // the toolbar is redrawn when necessary.
00204 // It can be removed once createGUI() has been made public _and_ we don't
00205 // longer rely on kdelibs 3.2.
00206 class KPartsMainWindowWithPublicizedCreateGUI : public KParts::MainWindow
00207 {
00208 public:
00209   void createGUIPublic( KParts::Part *part ) {
00210     createGUI( part );
00211   }
00212 };
00213 
00214 //-----------------------------------------------------------------------------
00215 
00216 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
00217 {
00218   kdDebug(5006) << "KMailPart::guiActivateEvent" << endl;
00219   KParts::ReadOnlyPart::guiActivateEvent(e);
00220   mainWidget->initializeFilterActions();
00221   mainWidget->initializeFolderShortcutActions();
00222 }
00223 
00224 void KMailPart::exit()
00225 {
00226   delete this;
00227 }
00228 
00229 QWidget* KMailPart::parentWidget() const
00230 {
00231   return mParentWidget;
00232 }
00233 
00234 
00235 KMailStatusBarExtension::KMailStatusBarExtension( KMailPart *parent )
00236   : KParts::StatusBarExtension( parent ), mParent( parent )
00237 {
00238 }
00239 
00240 KMainWindow * KMailStatusBarExtension::mainWindow() const
00241 {
00242   return static_cast<KMainWindow*>( mParent->parentWidget() );
00243 }
00244 
00245 #include "kmail_part.moc"
00246 
KDE Home | KDE Accessibility Home | Description of Access Keys