2 * kmail: KDE mail client
3 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "kmmainwin.h"
22 #include "kmmainwidget.h"
23 #include "kstatusbar.h"
24 #include "progressdialog.h"
25 #include "statusbarprogresswidget.h"
26 #include "broadcaststatus.h"
28 #include "tagactionmanager.h"
30 #include <kapplication.h>
32 #include <kedittoolbar.h>
34 #include <kmessagebox.h>
35 #include <kxmlguifactory.h>
36 #include <kstringhandler.h>
37 #include <kstandardaction.h>
42 #include "messagecomposer/messagesender.h"
45 #include "kmmainwin.moc"
48 KMMainWin::KMMainWin(QWidget
*)
52 setObjectName( "kmail-mainwindow#" );
53 // Set this to be the group leader for all subdialogs - this means
54 // modal subdialogs will only affect this dialog, not the other windows
55 setAttribute( Qt::WA_GroupLeader
);
57 KAction
*action
= new KAction( KIcon("window-new"), i18n("New &Window"), this );
58 actionCollection()->addAction( "new_mail_client", action
);
59 connect( action
, SIGNAL( triggered(bool) ), SLOT( slotNewMailReader() ) );
61 resize( 700, 500 ); // The default size
63 mKMMainWidget
= new KMMainWidget( this, this, actionCollection() );
64 setCentralWidget( mKMMainWidget
);
66 if ( kmkernel
->xmlGuiInstance().isValid() )
67 setComponentData( kmkernel
->xmlGuiInstance() );
69 setStandardToolBarMenuEnabled( true );
71 KStandardAction::configureToolbars( this, SLOT( slotEditToolbars() ),
74 KStandardAction::keyBindings( guiFactory(), SLOT( configureShortcuts() ),
77 KStandardAction::quit( this, SLOT( slotQuit() ), actionCollection() );
78 createGUI( "kmmainwin.rc" );
80 //must be after createGUI, otherwise e.g toolbar settings are not loaded
81 applyMainWindowSettings( KMKernel::self()->config()->group( "Main Window") );
83 connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString
& ) ),
84 this, SLOT( displayStatusMsg(const QString
&) ) );
86 connect( mKMMainWidget
, SIGNAL( captionChangeRequest(const QString
&) ),
87 SLOT( setCaption(const QString
&) ) );
89 if ( kmkernel
->firstInstance() )
90 QTimer::singleShot( 200, this, SLOT( slotShowTipOnStart() ) );
93 KMMainWin::~KMMainWin()
95 saveMainWindowSettings( KMKernel::self()->config()->group( "Main Window") );
96 KMKernel::self()->config()->sync();
100 // Check if this was the last KMMainWin
101 uint not_withdrawn
= 0;
102 foreach ( KMainWindow
* window
, KMainWindow::memberList() ) {
103 if ( !window
->isHidden() && window
->isTopLevel() &&
104 window
!= this && ::qobject_cast
<KMMainWin
*>( window
) )
108 if ( not_withdrawn
== 0 ) {
109 kDebug() << "Closing last KMMainWin";
110 // In KDE <= 4.4 would would abort mail checks here, but we don't need to do that anymore.
116 void KMMainWin::displayStatusMsg( const QString
& aText
)
118 if ( !statusBar() || !mLittleProgress
)
120 int statusWidth
= statusBar()->width() - mLittleProgress
->width()
121 - fontMetrics().maxWidth();
123 QString text
= fontMetrics().elidedText( ' ' + aText
, Qt::ElideRight
,
126 // ### FIXME: We should disable richtext/HTML (to avoid possible denial of service attacks),
127 // but this code would double the size of the satus bar if the user hovers
128 // over an <foo@bar.com>-style email address :-(
129 // text.replace("&", "&");
130 // text.replace("<", "<");
131 // text.replace(">", ">");
133 statusBar()->changeItem( text
, mMessageStatusId
);
136 //-----------------------------------------------------------------------------
137 void KMMainWin::slotNewMailReader()
143 d
->resize( d
->size() );
147 void KMMainWin::slotEditToolbars()
149 saveMainWindowSettings(KMKernel::self()->config()->group( "Main Window") );
150 KEditToolBar
dlg(actionCollection(), this);
151 dlg
.setResourceFile( "kmmainwin.rc" );
153 connect( &dlg
, SIGNAL(newToolBarConfig()), SLOT(slotUpdateToolbars()) );
158 void KMMainWin::slotUpdateToolbars()
160 // remove dynamically created actions before editing
161 mKMMainWidget
->clearFilterActions();
162 mKMMainWidget
->tagActionManager()->clearActions();
164 createGUI("kmmainwin.rc");
165 applyMainWindowSettings(KMKernel::self()->config()->group( "Main Window") );
167 // plug dynamically created actions again
168 mKMMainWidget
->initializeFilterActions();
169 mKMMainWidget
->tagActionManager()->createActions();
172 void KMMainWin::setupStatusBar()
174 mMessageStatusId
= 1;
176 /* Create a progress dialog and hide it. */
177 mProgressDialog
= new KPIM::ProgressDialog( statusBar(), this );
178 mProgressDialog
->hide();
180 mLittleProgress
= new StatusbarProgressWidget( mProgressDialog
, statusBar() );
181 mLittleProgress
->show();
183 statusBar()->insertItem( i18n("Starting..."), 1, 4 );
184 QTimer::singleShot( 2000, KPIM::BroadcastStatus::instance(), SLOT( reset() ) );
185 statusBar()->setItemAlignment( 1, Qt::AlignLeft
| Qt::AlignVCenter
);
186 statusBar()->addPermanentWidget( mKMMainWidget
->vacationScriptIndicator() );
187 statusBar()->addPermanentWidget( mLittleProgress
);
188 mLittleProgress
->show();
191 void KMMainWin::slotQuit()
197 //-----------------------------------------------------------------------------
198 bool KMMainWin::restoreDockedState( int n
)
200 // Default restore behavior is to show the window once it is restored.
201 // Override this if the main window was hidden in the system tray
202 // when the session was saved.
203 KConfigGroup
config( kapp
->sessionConfig(), QString::number( n
) );
204 bool show
= !config
.readEntry ("docked", false );
206 return KMainWindow::restore ( n
, show
);
209 void KMMainWin::saveProperties( KConfigGroup
&config
)
211 // This is called by the session manager on log-off
212 // Save the shown/hidden status so we can restore to the same state.
213 KMainWindow::saveProperties( config
);
214 config
.writeEntry( "docked", isHidden() );
217 bool KMMainWin::queryClose()
219 if ( kmkernel
->shuttingDown() || kapp
->sessionSaving() || mReallyClose
)
221 return kmkernel
->canQueryClose();
224 void KMMainWin::slotShowTipOnStart()
226 KTipDialog::showTip( this );