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