TDE personal information management applications
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

223 linhas
6.1KB

  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif
  4. #include "kmmainwin.h"
  5. #include "kmmainwidget.h"
  6. #include "kstatusbar.h"
  7. #include "messagesender.h"
  8. #include "progressdialog.h"
  9. #include "statusbarprogresswidget.h"
  10. #include "accountwizard.h"
  11. #include "broadcaststatus.h"
  12. #include "accountmanager.h"
  13. #include "kmtransport.h"
  14. #include <tdeapplication.h>
  15. #include <tdelocale.h>
  16. #include <kedittoolbar.h>
  17. #include <tdeconfig.h>
  18. #include <tdemessagebox.h>
  19. #include <kstringhandler.h>
  20. #include <kdebug.h>
  21. #include <ktip.h>
  22. #include "kmmainwin.moc"
  23. KMMainWin::KMMainWin(TQWidget *)
  24. : TDEMainWindow( 0, "kmail-mainwindow#" ),
  25. mReallyClose( false )
  26. {
  27. // Set this to be the group leader for all subdialogs - this means
  28. // modal subdialogs will only affect this dialog, not the other windows
  29. setWFlags( getWFlags() | WGroupLeader );
  30. kapp->ref();
  31. (void) new TDEAction( i18n("New &Window"), "window_new", 0,
  32. TQT_TQOBJECT(this), TQT_SLOT(slotNewMailReader()),
  33. actionCollection(), "new_mail_client" );
  34. mKMMainWidget = new KMMainWidget( TQT_TQWIDGET(this), "KMMainWidget", this, actionCollection() );
  35. mKMMainWidget->resize( 450, 600 );
  36. setCentralWidget(mKMMainWidget);
  37. setupStatusBar();
  38. if (kmkernel->xmlGuiInstance())
  39. setInstance( kmkernel->xmlGuiInstance() );
  40. if ( kmkernel->firstInstance() )
  41. TQTimer::singleShot( 200, this, TQT_SLOT(slotShowTipOnStart()) );
  42. setStandardToolBarMenuEnabled(true);
  43. KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotEditToolbars()),
  44. actionCollection());
  45. KStdAction::keyBindings(TQT_TQOBJECT(mKMMainWidget), TQT_SLOT(slotEditKeys()),
  46. actionCollection());
  47. KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), actionCollection());
  48. createGUI( "kmmainwin.rc", false );
  49. // Don't use conserveMemory() because this renders dynamic plugging
  50. // of actions unusable!
  51. mKMMainWidget->setupForwardingActionsList();
  52. applyMainWindowSettings(KMKernel::config(), "Main Window");
  53. connect( KPIM::BroadcastStatus::instance(), TQT_SIGNAL( statusMsg( const TQString& ) ),
  54. this, TQT_SLOT( displayStatusMsg(const TQString&) ) );
  55. connect(kmkernel, TQT_SIGNAL(configChanged()),
  56. this, TQT_SLOT(slotConfigChanged()));
  57. connect(mKMMainWidget, TQT_SIGNAL(captionChangeRequest(const TQString&)),
  58. TQT_SLOT(setCaption(const TQString&)) );
  59. // Enable mail checks again (see destructor)
  60. kmkernel->enableMailCheck();
  61. if ( kmkernel->firstStart() )
  62. AccountWizard::start( kmkernel, this );
  63. }
  64. KMMainWin::~KMMainWin()
  65. {
  66. saveMainWindowSettings(KMKernel::config(), "Main Window");
  67. KMKernel::config()->sync();
  68. kapp->deref();
  69. if ( !kmkernel->haveSystemTrayApplet() ) {
  70. // Check if this was the last KMMainWin
  71. int not_withdrawn = 0;
  72. TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList);
  73. for (it.toFirst(); it.current(); ++it){
  74. if ( !it.current()->isHidden() &&
  75. it.current()->isTopLevel() &&
  76. it.current() != this &&
  77. ::tqqt_cast<KMMainWin *>( it.current() )
  78. )
  79. not_withdrawn++;
  80. }
  81. if ( not_withdrawn == 0 ) {
  82. kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
  83. // Running TDEIO jobs prevent kapp from exiting, so we need to kill them
  84. // if they are only about checking mail (not important stuff like moving messages)
  85. kmkernel->abortMailCheck();
  86. kmkernel->acctMgr()->cancelMailCheck();
  87. }
  88. }
  89. }
  90. void KMMainWin::displayStatusMsg(const TQString& aText)
  91. {
  92. if ( !statusBar() || !mLittleProgress) return;
  93. int statusWidth = statusBar()->width() - mLittleProgress->width()
  94. - fontMetrics().maxWidth();
  95. TQString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(),
  96. statusWidth );
  97. // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks),
  98. // but this code would double the size of the satus bar if the user hovers
  99. // over an <foo@bar.com>-style email address :-(
  100. // text.replace("&", "&amp;");
  101. // text.replace("<", "&lt;");
  102. // text.replace(">", "&gt;");
  103. statusBar()->changeItem(text, mMessageStatusId);
  104. }
  105. //-----------------------------------------------------------------------------
  106. void KMMainWin::slotNewMailReader()
  107. {
  108. KMMainWin *d;
  109. d = new KMMainWin();
  110. d->show();
  111. d->resize(d->size());
  112. }
  113. void KMMainWin::slotEditToolbars()
  114. {
  115. saveMainWindowSettings(KMKernel::config(), "Main Window");
  116. KEditToolbar dlg(actionCollection(), "kmmainwin.rc");
  117. connect( &dlg, TQT_SIGNAL(newToolbarConfig()),
  118. TQT_SLOT(slotUpdateToolbars()) );
  119. dlg.exec();
  120. }
  121. void KMMainWin::slotUpdateToolbars()
  122. {
  123. // remove dynamically created actions before editing
  124. mKMMainWidget->clearFilterActions();
  125. createGUI("kmmainwin.rc", false);
  126. applyMainWindowSettings(KMKernel::config(), "Main Window");
  127. // plug dynamically created actions again
  128. mKMMainWidget->initializeFilterActions();
  129. }
  130. void KMMainWin::setupStatusBar()
  131. {
  132. mMessageStatusId = 1;
  133. /* Create a progress dialog and hide it. */
  134. mProgressDialog = new KPIM::ProgressDialog( statusBar(), this );
  135. mProgressDialog->hide();
  136. mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() );
  137. mLittleProgress->show();
  138. statusBar()->addWidget( mLittleProgress, 0 , true );
  139. statusBar()->insertItem(i18n(" Initializing..."), 1, 4 );
  140. statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter );
  141. statusBar()->addWidget( mKMMainWidget->vacationScriptIndicator(), 1 );
  142. mLittleProgress->show();
  143. }
  144. /** Read configuration options after widgets are created. */
  145. void KMMainWin::readConfig(void)
  146. {
  147. }
  148. /** Write configuration options. */
  149. void KMMainWin::writeConfig(void)
  150. {
  151. mKMMainWidget->writeConfig();
  152. }
  153. void KMMainWin::slotQuit()
  154. {
  155. mReallyClose = true;
  156. close();
  157. }
  158. void KMMainWin::slotConfigChanged()
  159. {
  160. readConfig();
  161. }
  162. //-----------------------------------------------------------------------------
  163. bool KMMainWin::queryClose()
  164. {
  165. if ( kapp->sessionSaving() )
  166. writeConfig();
  167. if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose )
  168. return true;
  169. return kmkernel->canQueryClose();
  170. }
  171. void KMMainWin::slotShowTipOnStart()
  172. {
  173. KTipDialog::showTip( this );
  174. }