7 #include "kmmainwidget.h"
8 #include "kstatusbar.h"
9 #include "messagesender.h"
10 #include "progressdialog.h"
11 #include "statusbarprogresswidget.h"
12 #include "accountwizard.h"
13 #include "broadcaststatus.h"
14 #include "accountmanager.h"
15 #include "kmtransport.h"
17 #include <tdeapplication.h>
18 #include <tdelocale.h>
19 #include <kedittoolbar.h>
20 #include <tdeconfig.h>
21 #include <tdemessagebox.h>
22 #include <kstringhandler.h>
26 #include "kmmainwin.moc"
28 KMMainWin::KMMainWin(TQWidget *)
29 : TDEMainWindow( 0,
"kmail-mainwindow#" ),
34 setWFlags( getWFlags() | WGroupLeader );
38 (void)
new TDEAction( i18n(
"New &Window"),
"window-new", 0,
39 this, TQ_SLOT(slotNewMailReader()),
40 actionCollection(),
"new_mail_client" );
42 mKMMainWidget =
new KMMainWidget(
this,
"KMMainWidget",
this, actionCollection() );
43 mKMMainWidget->resize( 450, 600 );
44 setCentralWidget(mKMMainWidget);
46 if (kmkernel->xmlGuiInstance())
47 setInstance( kmkernel->xmlGuiInstance() );
49 if ( kmkernel->firstInstance() )
50 TQTimer::singleShot( 200,
this, TQ_SLOT(slotShowTipOnStart()) );
52 setStandardToolBarMenuEnabled(
true);
54 KStdAction::configureToolbars(
this, TQ_SLOT(slotEditToolbars()),
57 KStdAction::keyBindings(mKMMainWidget, TQ_SLOT(slotEditKeys()),
60 KStdAction::quit(
this, TQ_SLOT(slotQuit()), actionCollection());
61 createGUI(
"kmmainwin.rc",
false );
65 mKMMainWidget->setupForwardingActionsList();
67 applyMainWindowSettings(KMKernel::config(),
"Main Window");
69 connect( KPIM::BroadcastStatus::instance(), TQ_SIGNAL( statusMsg(
const TQString& ) ),
70 this, TQ_SLOT( displayStatusMsg(
const TQString&) ) );
72 connect(kmkernel, TQ_SIGNAL(configChanged()),
73 this, TQ_SLOT(slotConfigChanged()));
75 connect(mKMMainWidget, TQ_SIGNAL(captionChangeRequest(
const TQString&)),
76 TQ_SLOT(setCaption(
const TQString&)) );
79 kmkernel->enableMailCheck();
81 if ( kmkernel->firstStart() )
82 AccountWizard::start( kmkernel,
this );
85 KMMainWin::~KMMainWin()
87 saveMainWindowSettings(KMKernel::config(),
"Main Window");
88 KMKernel::config()->sync();
91 if ( !kmkernel->haveSystemTrayApplet() ) {
93 int not_withdrawn = 0;
94 TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList);
95 for (it.toFirst(); it.current(); ++it){
96 if ( !it.current()->isHidden() &&
97 it.current()->isTopLevel() &&
98 it.current() !=
this &&
99 ::tqt_cast<KMMainWin *>( it.current() )
104 if ( not_withdrawn == 0 ) {
105 kdDebug(5006) <<
"Closing last KMMainWin: stopping mail check" << endl;
108 kmkernel->abortMailCheck();
109 kmkernel->acctMgr()->cancelMailCheck();
114 void KMMainWin::displayStatusMsg(
const TQString& aText)
116 if ( !statusBar() || !mLittleProgress)
return;
117 int statusWidth = statusBar()->width() - mLittleProgress->width()
118 - fontMetrics().maxWidth();
119 TQString text = KStringHandler::rPixelSqueeze(
" " + aText, fontMetrics(),
129 statusBar()->changeItem(text, mMessageStatusId);
133 void KMMainWin::slotNewMailReader()
139 d->resize(d->size());
143 void KMMainWin::slotEditToolbars()
145 saveMainWindowSettings(KMKernel::config(),
"Main Window");
146 KEditToolbar dlg(actionCollection(),
"kmmainwin.rc");
148 connect( &dlg, TQ_SIGNAL(newToolbarConfig()),
149 TQ_SLOT(slotUpdateToolbars()) );
154 void KMMainWin::slotUpdateToolbars()
157 mKMMainWidget->clearFilterActions();
159 createGUI(
"kmmainwin.rc",
false);
160 applyMainWindowSettings(KMKernel::config(),
"Main Window");
163 mKMMainWidget->initializeFilterActions();
166 void KMMainWin::setupStatusBar()
168 mMessageStatusId = 1;
171 mProgressDialog =
new KPIM::ProgressDialog( statusBar(),
this );
172 mProgressDialog->hide();
174 mLittleProgress =
new StatusbarProgressWidget( mProgressDialog, statusBar() );
175 mLittleProgress->show();
177 statusBar()->addWidget( mLittleProgress, 0 ,
true );
178 statusBar()->insertItem(i18n(
" Initializing..."), 1, 4 );
179 statusBar()->setItemAlignment( 1, AlignLeft | AlignVCenter );
180 statusBar()->addWidget( mKMMainWidget->vacationScriptIndicator(), 1 );
181 mLittleProgress->show();
185 void KMMainWin::readConfig(
void)
190 void KMMainWin::writeConfig(
void)
192 mKMMainWidget->writeConfig();
195 void KMMainWin::slotQuit()
201 void KMMainWin::slotConfigChanged()
207 bool KMMainWin::queryClose()
209 if ( kapp->sessionSaving() )
212 if ( kmkernel->shuttingDown() || kapp->sessionSaving() || mReallyClose )
214 return kmkernel->canQueryClose();
217 void KMMainWin::slotShowTipOnStart()
219 KTipDialog::showTip(
this );