summaryrefslogtreecommitdiffstats
path: root/kmail/kmmainwin.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kmail/kmmainwin.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/kmmainwin.cpp')
-rw-r--r--kmail/kmmainwin.cpp222
1 files changed, 222 insertions, 0 deletions
diff --git a/kmail/kmmainwin.cpp b/kmail/kmmainwin.cpp
new file mode 100644
index 000000000..ce0c64607
--- /dev/null
+++ b/kmail/kmmainwin.cpp
@@ -0,0 +1,222 @@
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "kmmainwin.h"
+#include "kmmainwidget.h"
+#include "kstatusbar.h"
+#include "messagesender.h"
+#include "progressdialog.h"
+#include "statusbarprogresswidget.h"
+#include "accountwizard.h"
+#include "broadcaststatus.h"
+#include "accountmanager.h"
+#include "kmtransport.h"
+
+#include <kapplication.h>
+#include <klocale.h>
+#include <kedittoolbar.h>
+#include <kconfig.h>
+#include <kmessagebox.h>
+#include <kstringhandler.h>
+#include <kdebug.h>
+#include <ktip.h>
+
+#include "kmmainwin.moc"
+
+KMMainWin::KMMainWin(QWidget *)
+ : KMainWindow( 0, "kmail-mainwindow#" ),
+ mReallyClose( false )
+{
+ // Set this to be the group leader for all subdialogs - this means
+ // modal subdialogs will only affect this dialog, not the other windows
+ setWFlags( getWFlags() | WGroupLeader );
+
+ kapp->ref();
+
+ (void) new KAction( i18n("New &Window"), "window_new", 0,
+ this, SLOT(slotNewMailReader()),
+ actionCollection(), "new_mail_client" );
+
+ mKMMainWidget = new KMMainWidget( this, "KMMainWidget", this, actionCollection() );
+ mKMMainWidget->resize( 725, 700 );
+ setCentralWidget(mKMMainWidget);
+ setupStatusBar();
+ if (kmkernel->xmlGuiInstance())
+ setInstance( kmkernel->xmlGuiInstance() );
+
+ if ( kmkernel->firstInstance() )
+ QTimer::singleShot( 200, this, SLOT(slotShowTipOnStart()) );
+
+ setStandardToolBarMenuEnabled(true);
+
+ KStdAction::configureToolbars(this, SLOT(slotEditToolbars()),
+ actionCollection());
+
+ KStdAction::keyBindings(mKMMainWidget, SLOT(slotEditKeys()),
+ actionCollection());
+
+ KStdAction::quit( this, SLOT(slotQuit()), actionCollection());
+ createGUI( "kmmainwin.rc", false );
+ // Don't use conserveMemory() because this renders dynamic plugging
+ // of actions unusable!
+
+ mKMMainWidget->setupForwardingActionsList();
+
+ applyMainWindowSettings(KMKernel::config(), "Main Window");
+
+ connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ),
+ this, SLOT( displayStatusMsg(const QString&) ) );
+
+ connect(kmkernel, SIGNAL(configChanged()),
+ this, SLOT(slotConfigChanged()));
+
+ connect(mKMMainWidget, SIGNAL(captionChangeRequest(const QString&)),
+ SLOT(setCaption(const QString&)) );
+
+ // Enable mail checks again (see destructor)
+ kmkernel->enableMailCheck();
+
+ if ( kmkernel->firstStart() )
+ AccountWizard::start( kmkernel, this );
+}
+
+KMMainWin::~KMMainWin()
+{
+ saveMainWindowSettings(KMKernel::config(), "Main Window");
+ KMKernel::config()->sync();
+ kapp->deref();
+
+ if ( !kmkernel->haveSystemTrayApplet() ) {
+ // Check if this was the last KMMainWin
+ int not_withdrawn = 0;
+ QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
+ for (it.toFirst(); it.current(); ++it){
+ if ( !it.current()->isHidden() &&
+ it.current()->isTopLevel() &&
+ it.current() != this &&
+ ::qt_cast<KMMainWin *>( it.current() )
+ )
+ not_withdrawn++;
+ }
+
+ if ( not_withdrawn == 0 ) {
+ kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl;
+ // Running KIO jobs prevent kapp from exiting, so we need to kill them
+ // if they are only about checking mail (not important stuff like moving messages)
+ kmkernel->abortMailCheck();
+ kmkernel->acctMgr()->cancelMailCheck();
+ }
+ }
+}
+
+void KMMainWin::displayStatusMsg(const QString& aText)
+{
+ if ( !statusBar() || !mLittleProgress) return;
+ int statusWidth = statusBar()->width() - mLittleProgress->width()
+ - fontMetrics().maxWidth();
+ QString text = KStringHandler::rPixelSqueeze( " " + aText, fontMetrics(),
+ statusWidth );
+
+ // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks),
+ // but this code would double the size of the satus bar if the user hovers
+ // over an <foo@bar.com>-style email address :-(
+// text.replace("&", "&amp;");
+// text.replace("<", "&lt;");
+// text.replace(">", "&gt;");
+
+ statusBar()->changeItem(text, mMessageStatusId);
+}
+
+//-----------------------------------------------------------------------------
+void KMMainWin::slotNewMailReader()
+{
+ KMMainWin *d;
+
+ d = new KMMainWin();
+ d->show();
+ d->resize(d->size());
+}
+
+
+void KMMainWin::slotEditToolbars()
+{
+ saveMainWindowSettings(KMKernel::config(), "Main Window");
+ KEditToolbar dlg(actionCollection(), "kmmainwin.rc");
+
+ connect( &dlg, SIGNAL(newToolbarConfig()),
+ SLOT(slotUpdateToolbars()) );
+
+ dlg.exec();
+}
+
+void KMMainWin::slotUpdateToolbars()
+{
+ // remove dynamically created actions before editing
+ mKMMainWidget->clearFilterActions();
+
+ createGUI("kmmainwin.rc", false);
+ applyMainWindowSettings(KMKernel::config(), "Main Window");
+
+ // plug dynamically created actions again
+ mKMMainWidget->initializeFilterActions();
+}
+
+void KMMainWin::setupStatusBar()
+{
+ mMessageStatusId = 1;
+
+ /* Create a progress dialog and hide it. */
+ mProgressDialog = new KPIM::ProgressDialog( statusBar(), this );
+ mProgressDialog->hide();
+
+ mLittleProgress = new StatusbarProgressWidget( mProgressDialog, statusBar() );
+ mLittleProgress->show();
+
+ statusBar()->addWidget( mLittleProgress, 0 , true );
+ statusBar()->insertItem(i18n(" Initializing..."), 1, 4 );
+ statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter );
+ statusBar()->addWidget( mKMMainWidget->vacationScriptIndicator(), 1 );
+ mLittleProgress->show();
+}
+
+/** Read configuration options after widgets are created. */
+void KMMainWin::readConfig(void)
+{
+}
+
+/** Write configuration options. */
+void KMMainWin::writeConfig(void)
+{
+ mKMMainWidget->writeConfig();
+}
+
+void KMMainWin::slotQuit()
+{
+ mReallyClose = true;
+ close();
+}
+
+void KMMainWin::slotConfigChanged()
+{
+ readConfig();
+}
+
+//-----------------------------------------------------------------------------
+bool KMMainWin::queryClose()
+{
+ if ( kapp->sessionSaving() )
+ writeConfig();
+
+ if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose )
+ return true;
+ return kmkernel->canQueryClose();
+}
+
+void KMMainWin::slotShowTipOnStart()
+{
+ KTipDialog::showTip( this );
+}
+
+