TDE personal information management applications
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

kmail_part.cpp 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* -*- mode: C++; c-file-style: "gnu" -*-
  2. This file is part of KMail.
  3. Copyright (c) 2002-2003 Don Sanders <sanders@kde.org>,
  4. Copyright (c) 2003 Zack Rusin <zack@kde.org>,
  5. Based on the work of Cornelius Schumacher <schumacher@kde.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. As a special exception, permission is given to link this program
  18. with any edition of TQt, and distribute the resulting executable,
  19. without including the source code for TQt in the source distribution.
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include "kmail_part.h"
  25. #include "kmmainwin.h"
  26. #include "kmmainwidget.h"
  27. #include "kmfoldertree.h"
  28. #include "kmstartup.h"
  29. #include "aboutdata.h"
  30. #include "kmfolder.h"
  31. #include "accountmanager.h"
  32. using KMail::AccountManager;
  33. #include "sidebarextension.h"
  34. #include "infoextension.h"
  35. #include "recentaddresses.h"
  36. using TDERecentAddress::RecentAddresses;
  37. #include <tdeapplication.h>
  38. #include <tdeparts/mainwindow.h>
  39. #include <tdeparts/genericfactory.h>
  40. #include <knotifyclient.h>
  41. #include <dcopclient.h>
  42. #include <kiconloader.h>
  43. #include <kdebug.h>
  44. #include <kstatusbar.h>
  45. #include <ksettings/dispatcher.h>
  46. #include <tqlayout.h>
  47. typedef KParts::GenericFactory< KMailPart > KMailFactory;
  48. K_EXPORT_COMPONENT_FACTORY( libkmailpart, KMailFactory )
  49. KMailPart::KMailPart(TQWidget *parentWidget, const char *widgetName,
  50. TQObject *parent, const char *name, const TQStringList &) :
  51. DCOPObject("KMailIface"), KParts::ReadOnlyPart(parent, name),
  52. mParentWidget( parentWidget )
  53. {
  54. kdDebug(5006) << "KMailPart()" << endl;
  55. kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl;
  56. setInstance(KMailFactory::instance());
  57. kdDebug(5006) << "KMailPart()..." << endl;
  58. kdDebug(5006) << " InstanceName: " << kapp->instanceName() << endl;
  59. // import i18n data and icons from libraries:
  60. KMail::insertLibraryCataloguesAndIcons();
  61. // Make sure that the KNotify Daemon is running (this is necessary for people
  62. // using KMail without KDE)
  63. KNotifyClient::startDaemon();
  64. KMail::lockOrDie();
  65. kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet
  66. //local, do the init
  67. KMKernel *mKMailKernel = new KMKernel();
  68. mKMailKernel->init();
  69. mKMailKernel->setXmlGuiInstance( KMailFactory::instance() );
  70. // and session management
  71. mKMailKernel->doSessionManagement();
  72. // any dead letters?
  73. mKMailKernel->recoverDeadLetters();
  74. kmsetSignalHandler(kmsignalHandler);
  75. kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests.
  76. // create a canvas to insert our widget
  77. TQWidget *canvas = new TQWidget(parentWidget, widgetName);
  78. canvas->setFocusPolicy(TQ_ClickFocus);
  79. setWidget(canvas);
  80. TDEGlobal::iconLoader()->addAppDir("kmail");
  81. #if 0
  82. //It's also possible to make a part out of a readerWin
  83. KMReaderWin *mReaderWin = new KMReaderWin( canvas, canvas, actionCollection() );
  84. connect(mReaderWin, TQT_SIGNAL(urlClicked(const KURL&,int)),
  85. mReaderWin, TQT_SLOT(slotUrlClicked()));
  86. TQVBoxLayout *topLayout = new TQVBoxLayout(canvas);
  87. topLayout->addWidget(mReaderWin);
  88. mReaderWin->setAutoDelete( true );
  89. kmkernel->inboxFolder()->open();
  90. KMMessage *msg = kmkernel->inboxFolder()->getMsg(0);
  91. mReaderWin->setMsg( msg, true );
  92. mReaderWin->setFocusPolicy(TQWidget::ClickFocus);
  93. mStatusBar = new KMailStatusBarExtension(this);
  94. //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this );
  95. TDEGlobal::iconLoader()->addAppDir("kmail");
  96. setXMLFile( "kmail_part.rc" );
  97. kmkernel->inboxFolder()->close();
  98. #else
  99. mainWidget = new KMMainWidget( canvas, "mainWidget", this, actionCollection(),
  100. kapp->config());
  101. TQVBoxLayout *topLayout = new TQVBoxLayout(canvas);
  102. topLayout->addWidget(mainWidget);
  103. mainWidget->setFocusPolicy(TQ_ClickFocus);
  104. mStatusBar = new KMailStatusBarExtension(this);
  105. mStatusBar->addStatusBarItem( mainWidget->vacationScriptIndicator(), 2, false );
  106. new KParts::SideBarExtension( mainWidget->folderTree(),
  107. this,
  108. "KMailSidebar" );
  109. // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact
  110. KParts::InfoExtension *ie = new KParts::InfoExtension( this, "KMailInfo" );
  111. connect( mainWidget->folderTree(), TQT_SIGNAL(folderSelected(KMFolder*)), this, TQT_SLOT(exportFolder(KMFolder*)) );
  112. connect( mainWidget->folderTree(), TQT_SIGNAL(iconChanged(KMFolderTreeItem*)),
  113. this, TQT_SLOT(slotIconChanged(KMFolderTreeItem*)) );
  114. connect( mainWidget->folderTree(), TQT_SIGNAL(nameChanged(KMFolderTreeItem*)),
  115. this, TQT_SLOT(slotNameChanged(KMFolderTreeItem*)) );
  116. connect( this, TQT_SIGNAL(textChanged(const TQString&)), ie, TQT_SIGNAL(textChanged(const TQString&)) );
  117. connect( this, TQT_SIGNAL(iconChanged(const TQPixmap&)), ie, TQT_SIGNAL(iconChanged(const TQPixmap&)) );
  118. TDEGlobal::iconLoader()->addAppDir( "kmail" );
  119. setXMLFile( "kmail_part.rc" );
  120. #endif
  121. KSettings::Dispatcher::self()->registerInstance( KMailFactory::instance(), mKMailKernel,
  122. TQT_SLOT( slotConfigChanged() ) );
  123. }
  124. KMailPart::~KMailPart()
  125. {
  126. kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
  127. // Running TDEIO jobs prevent kapp from exiting, so we need to kill them
  128. // if they are only about checking mail (not important stuff like moving messages)
  129. kmkernel->abortMailCheck();
  130. kmkernel->acctMgr()->cancelMailCheck();
  131. mainWidget->destruct();
  132. kmkernel->cleanup();
  133. delete kmkernel;
  134. KMail::cleanup(); // pid file (see kmstartup.cpp)
  135. }
  136. TDEAboutData *KMailPart::createAboutData()
  137. {
  138. return new KMail::AboutData();
  139. }
  140. bool KMailPart::openFile()
  141. {
  142. kdDebug(5006) << "KMailPart:openFile()" << endl;
  143. mainWidget->show();
  144. return true;
  145. }
  146. void KMailPart::exportFolder( KMFolder *folder )
  147. {
  148. KMFolderTreeItem* fti = static_cast< KMFolderTreeItem* >( mainWidget->folderTree()->currentItem() );
  149. if ( folder != 0 )
  150. emit textChanged( folder->label() );
  151. if ( fti )
  152. emit iconChanged( fti->normalIcon( 22 ) );
  153. }
  154. void KMailPart::slotIconChanged( KMFolderTreeItem *fti )
  155. {
  156. emit iconChanged( fti->normalIcon( 22 ) );
  157. }
  158. void KMailPart::slotNameChanged( KMFolderTreeItem *fti )
  159. {
  160. emit textChanged( fti->folder()->label() );
  161. }
  162. //-----------------------------------------------------------------------------
  163. // The sole purpose of the following class is to publicize the protected
  164. // method KParts::MainWindow::createGUI() since we need to call it so that
  165. // the toolbar is redrawn when necessary.
  166. // It can be removed once createGUI() has been made public _and_ we don't
  167. // longer rely on tdelibs 3.2.
  168. class KPartsMainWindowWithPublicizedCreateGUI : public KParts::MainWindow
  169. {
  170. public:
  171. void createGUIPublic( KParts::Part *part ) {
  172. createGUI( part );
  173. }
  174. };
  175. //-----------------------------------------------------------------------------
  176. void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
  177. {
  178. kdDebug(5006) << "KMailPart::guiActivateEvent" << endl;
  179. KParts::ReadOnlyPart::guiActivateEvent(e);
  180. mainWidget->initializeFilterActions();
  181. mainWidget->initializeFolderShortcutActions();
  182. mainWidget->setupForwardingActionsList();
  183. mainWidget->updateVactionScripStatus();
  184. }
  185. void KMailPart::exit()
  186. {
  187. delete this;
  188. }
  189. TQWidget* KMailPart::parentWidget() const
  190. {
  191. return mParentWidget;
  192. }
  193. KMailStatusBarExtension::KMailStatusBarExtension( KMailPart *parent )
  194. : KParts::StatusBarExtension( parent ), mParent( parent )
  195. {
  196. }
  197. TDEMainWindow * KMailStatusBarExtension::mainWindow() const
  198. {
  199. return static_cast<TDEMainWindow*>( mParent->parentWidget() );
  200. }
  201. #include "kmail_part.moc"