00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 <kstatusbar.h>
00054 #include <ksettings/dispatcher.h>
00055
00056
00057 #include <qlayout.h>
00058
00059
00060 typedef KParts::GenericFactory< KMailPart > KMailFactory;
00061 K_EXPORT_COMPONENT_FACTORY( libkmailpart, KMailFactory )
00062
00063 KMailPart::KMailPart(QWidget *parentWidget, const char *widgetName,
00064 QObject *parent, const char *name, const QStringList &) :
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
00077 KMail::insertLibraryCataloguesAndIcons();
00078
00079
00080
00081 KNotifyClient::startDaemon();
00082
00083 KMail::lockOrDie();
00084
00085 kapp->dcopClient()->suspend();
00086
00087
00088 KMKernel *mKMailKernel = new KMKernel();
00089 mKMailKernel->init();
00090 mKMailKernel->setXmlGuiInstance( KMailFactory::instance() );
00091
00092
00093 mKMailKernel->doSessionManagement();
00094
00095
00096 mKMailKernel->recoverDeadLetters();
00097
00098 kmsetSignalHandler(kmsignalHandler);
00099 kapp->dcopClient()->resume();
00100
00101
00102 QWidget *canvas = new QWidget(parentWidget, widgetName);
00103 canvas->setFocusPolicy(QWidget::ClickFocus);
00104 setWidget(canvas);
00105 KGlobal::iconLoader()->addAppDir("kmail");
00106 #if 0
00107
00108 KMReaderWin *mReaderWin = new KMReaderWin( canvas, canvas, actionCollection() );
00109 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00110 mReaderWin, SLOT(slotUrlClicked()));
00111 QVBoxLayout *topLayout = new QVBoxLayout(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(QWidget::ClickFocus);
00118 mStatusBar = new KMailStatusBarExtension(this);
00119
00120 KGlobal::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 QVBoxLayout *topLayout = new QVBoxLayout(canvas);
00127 topLayout->addWidget(mainWidget);
00128 mainWidget->setFocusPolicy(QWidget::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
00137 KParts::InfoExtension *ie = new KParts::InfoExtension( this, "KMailInfo" );
00138 connect( mainWidget->folderTree(), SIGNAL(folderSelected(KMFolder*)), this, SLOT(exportFolder(KMFolder*)) );
00139 connect( mainWidget->folderTree(), SIGNAL(iconChanged(KMFolderTreeItem*)),
00140 this, SLOT(slotIconChanged(KMFolderTreeItem*)) );
00141 connect( mainWidget->folderTree(), SIGNAL(nameChanged(KMFolderTreeItem*)),
00142 this, SLOT(slotNameChanged(KMFolderTreeItem*)) );
00143 connect( this, SIGNAL(textChanged(const QString&)), ie, SIGNAL(textChanged(const QString&)) );
00144 connect( this, SIGNAL(iconChanged(const QPixmap&)), ie, SIGNAL(iconChanged(const QPixmap&)) );
00145
00146 KGlobal::iconLoader()->addAppDir( "kmail" );
00147 setXMLFile( "kmail_part.rc" );
00148 #endif
00149
00150 KSettings::Dispatcher::self()->registerInstance( KMailFactory::instance(), mKMailKernel,
00151 SLOT( slotConfigChanged() ) );
00152 }
00153
00154 KMailPart::~KMailPart()
00155 {
00156 kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
00157
00158
00159 kmkernel->abortMailCheck();
00160 kmkernel->acctMgr()->cancelMailCheck();
00161
00162 mainWidget->destruct();
00163 kmkernel->cleanup();
00164 delete kmkernel;
00165 KMail::cleanup();
00166 }
00167
00168 KAboutData *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
00205
00206
00207
00208
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->updateVactionScriptStatus();
00227 }
00228
00229 void KMailPart::exit()
00230 {
00231 delete this;
00232 }
00233
00234 QWidget* 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 KMainWindow * KMailStatusBarExtension::mainWindow() const
00246 {
00247 return static_cast<KMainWindow*>( mParent->parentWidget() );
00248 }
00249
00250 #include "kmail_part.moc"
00251