00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028
00029 #include <qaccel.h>
00030 #include <kapplication.h>
00031 #include <kedittoolbar.h>
00032 #include <klocale.h>
00033 #include <kstdaccel.h>
00034 #include <kwin.h>
00035 #include <kaction.h>
00036 #include <kiconloader.h>
00037 #include <kdebug.h>
00038 #include "kmcommands.h"
00039 #include "kmenubar.h"
00040 #include "kpopupmenu.h"
00041 #include "kmreaderwin.h"
00042 #include "kmfolder.h"
00043 #include "kmmainwidget.h"
00044 #include "kmfoldertree.h"
00045 #include "kmmsgdict.h"
00046 #include "csshelper.h"
00047 #include "messageactions.h"
00048
00049 #include "globalsettings.h"
00050
00051 #include "kmreadermainwin.h"
00052
00053 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride,
00054 char *name )
00055 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00056 mMsg( 0 )
00057 {
00058 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00059
00060 mReaderWin->setAutoDelete( true );
00061 mReaderWin->setHtmlOverride( htmlOverride );
00062 mReaderWin->setHtmlLoadExtOverride( htmlLoadExtOverride );
00063 mReaderWin->setDecryptMessageOverwrite( true );
00064 mReaderWin->setShowSignatureDetails( false );
00065 initKMReaderMainWin();
00066 }
00067
00068
00069
00070 KMReaderMainWin::KMReaderMainWin( char *name )
00071 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00072 mMsg( 0 )
00073 {
00074 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00075 mReaderWin->setAutoDelete( true );
00076 initKMReaderMainWin();
00077 }
00078
00079
00080
00081 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00082 bool aHTML, const QString& aFileName, const QString& pname,
00083 const QString & encoding, char *name )
00084 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00085 mMsg( 0 )
00086 {
00087 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00088 mReaderWin->setOverrideEncoding( encoding );
00089 mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00090 initKMReaderMainWin();
00091 }
00092
00093
00094
00095 void KMReaderMainWin::initKMReaderMainWin() {
00096 setCentralWidget( mReaderWin );
00097 setupAccel();
00098 setupGUI( Keys | StatusBar | Create, "kmreadermainwin.rc" );
00099 setupForwardingActionsList();
00100 applyMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00101 if ( ! mReaderWin->message() ) {
00102 menuBar()->hide();
00103 toolBar( "mainToolBar" )->hide();
00104 }
00105
00106 connect( kmkernel, SIGNAL( configChanged() ),
00107 this, SLOT( slotConfigChanged() ) );
00108 }
00109
00110 void KMReaderMainWin::setupForwardingActionsList()
00111 {
00112 QPtrList<KAction> mForwardActionList;
00113 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00114 unplugActionList( "forward_action_list" );
00115 mForwardActionList.append( mForwardInlineAction );
00116 mForwardActionList.append( mForwardAttachedAction );
00117 mForwardActionList.append( mForwardDigestAction );
00118 mForwardActionList.append( mRedirectAction );
00119 plugActionList( "forward_action_list", mForwardActionList );
00120 } else {
00121 unplugActionList( "forward_action_list" );
00122 mForwardActionList.append( mForwardAttachedAction );
00123 mForwardActionList.append( mForwardInlineAction );
00124 mForwardActionList.append( mForwardDigestAction );
00125 mForwardActionList.append( mRedirectAction );
00126 plugActionList( "forward_action_list", mForwardActionList );
00127 }
00128 }
00129
00130
00131 KMReaderMainWin::~KMReaderMainWin()
00132 {
00133 saveMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00134 }
00135
00136
00137 void KMReaderMainWin::setUseFixedFont( bool useFixedFont )
00138 {
00139 mReaderWin->setUseFixedFont( useFixedFont );
00140 }
00141
00142
00143 void KMReaderMainWin::showMsg( const QString & encoding, KMMessage *msg )
00144 {
00145 mReaderWin->setOverrideEncoding( encoding );
00146 mReaderWin->setMsg( msg, true );
00147 mReaderWin->slotTouchMessage();
00148 setCaption( msg->subject() );
00149 mMsg = msg;
00150 mMsgActions->setCurrentMessage( msg );
00151 menuBar()->show();
00152 toolBar( "mainToolBar" )->show();
00153
00154 connect ( msg->parent(), SIGNAL( destroyed( QObject* ) ), this, SLOT( slotFolderRemoved( QObject* ) ) );
00155
00156 }
00157
00158 void KMReaderMainWin::slotFolderRemoved( QObject* folderPtr )
00159 {
00160 assert(mMsg);
00161 assert(folderPtr == mMsg->parent());
00162 if( mMsg && folderPtr == mMsg->parent() )
00163 mMsg->setParent( 0 );
00164 }
00165
00166
00167 void KMReaderMainWin::slotTrashMsg()
00168 {
00169 if ( !mMsg )
00170 return;
00171
00172 KMFolder* parent;
00173 int index;
00174 KMMsgDict::instance()->getLocation( mMsg->getMsgSerNum(), &parent, &index );
00175 if ( parent && !parent->isTrash() ) {
00176
00177 parent->open("trashmsg");
00178 KMMessage *msg = parent->getMsg( index );
00179 if (msg) {
00180 KMDeleteMsgCommand *command = new KMDeleteMsgCommand( parent, msg );
00181 command->start();
00182 }
00183 parent->close("trashmsg");
00184 }
00185 close();
00186 }
00187
00188
00189 void KMReaderMainWin::slotFind()
00190 {
00191 mReaderWin->slotFind();
00192 }
00193
00194 void KMReaderMainWin::slotFindNext()
00195 {
00196 mReaderWin->slotFindNext();
00197 }
00198
00199
00200 void KMReaderMainWin::slotCopy()
00201 {
00202 mReaderWin->slotCopySelectedText();
00203 }
00204
00205
00206 void KMReaderMainWin::slotMarkAll()
00207 {
00208 mReaderWin->selectAll();
00209 }
00210
00211
00212 void KMReaderMainWin::slotPrintMsg()
00213 {
00214 KMPrintCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00215 mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
00216 mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
00217 command->setOverrideFont( mReaderWin->cssHelper()->bodyFont( mReaderWin->isFixedFont(), true ) );
00218 command->start();
00219 }
00220
00221
00222 void KMReaderMainWin::slotForwardInlineMsg()
00223 {
00224 KMCommand *command = 0;
00225 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00226 command = new KMForwardInlineCommand( this, mReaderWin->message(),
00227 mReaderWin->message()->parent()->identity() );
00228 } else {
00229 command = new KMForwardInlineCommand( this, mReaderWin->message() );
00230 }
00231 command->start();
00232 }
00233
00234
00235 void KMReaderMainWin::slotForwardAttachedMsg()
00236 {
00237 KMCommand *command = 0;
00238 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00239 command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00240 mReaderWin->message()->parent()->identity() );
00241 } else {
00242 command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00243 }
00244 command->start();
00245 }
00246
00247
00248 void KMReaderMainWin::slotForwardDigestMsg()
00249 {
00250 KMCommand *command = 0;
00251 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00252 command = new KMForwardDigestCommand( this, mReaderWin->message(),
00253 mReaderWin->message()->parent()->identity() );
00254 } else {
00255 command = new KMForwardDigestCommand( this, mReaderWin->message() );
00256 }
00257 command->start();
00258 }
00259
00260
00261 void KMReaderMainWin::slotRedirectMsg()
00262 {
00263 KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00264 command->start();
00265 }
00266
00267
00268 void KMReaderMainWin::slotShowMsgSrc()
00269 {
00270 KMMessage *msg = mReaderWin->message();
00271 if ( !msg )
00272 return;
00273 KMCommand *command = new KMShowMsgSrcCommand( this, msg,
00274 mReaderWin->isFixedFont() );
00275 command->start();
00276 }
00277
00278
00279 void KMReaderMainWin::slotConfigChanged()
00280 {
00281
00282 }
00283
00284 void KMReaderMainWin::setupAccel()
00285 {
00286 if ( kmkernel->xmlGuiInstance() )
00287 setInstance( kmkernel->xmlGuiInstance() );
00288
00289 mMsgActions = new KMail::MessageActions( actionCollection(), this );
00290 mMsgActions->setMessageView( mReaderWin );
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 mSaveAsAction = KStdAction::saveAs( mReaderWin, SLOT( slotSaveMsg() ),
00301 actionCollection() );
00302 mSaveAsAction->setShortcut( KStdAccel::shortcut( KStdAccel::Save ) );
00303 mPrintAction = KStdAction::print( this, SLOT( slotPrintMsg() ),
00304 actionCollection() );
00305
00306 KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
00307 KShortcut closeShortcut = closeAction->shortcut();
00308 closeShortcut.append( KKey(Key_Escape));
00309 closeAction->setShortcut(closeShortcut);
00310
00311
00312 KStdAction::copy( this, SLOT( slotCopy() ), actionCollection() );
00313 KStdAction::selectAll( this, SLOT( slotMarkAll() ), actionCollection() );
00314 KStdAction::find( this, SLOT(slotFind()), actionCollection() );
00315 KStdAction::findNext( this, SLOT( slotFindNext() ), actionCollection() );
00316 mTrashAction = new KAction( KGuiItem( i18n( "&Move to Trash" ), "edittrash",
00317 i18n( "Move message to trashcan" ) ),
00318 Key_Delete, this, SLOT( slotTrashMsg() ),
00319 actionCollection(), "move_to_trash" );
00320
00321
00322 mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00323 SLOT(slotShowMsgSrc()), actionCollection(),
00324 "view_source" );
00325
00326
00327 mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00328 "mail_forward", actionCollection(),
00329 "message_forward" );
00330 mForwardInlineAction = new KAction( i18n("&Inline..."),
00331 "mail_forward", SHIFT+Key_F, this,
00332 SLOT(slotForwardInlineMsg()),
00333 actionCollection(),
00334 "message_forward_inline" );
00335
00336 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00337 "mail_forward", Key_F, this,
00338 SLOT(slotForwardAttachedMsg()),
00339 actionCollection(),
00340 "message_forward_as_attachment" );
00341
00342 mForwardDigestAction = new KAction( i18n("Message->Forward->","As Di&gest..."),
00343 "mail_forward", 0, this,
00344 SLOT(slotForwardDigestMsg()),
00345 actionCollection(),
00346 "message_forward_as_digest" );
00347
00348 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00349 "mail_forward", Key_E, this,
00350 SLOT(slotRedirectMsg()),
00351 actionCollection(),
00352 "message_forward_redirect" );
00353
00354 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00355 mForwardActionMenu->insert( mForwardInlineAction );
00356 mForwardActionMenu->insert( mForwardAttachedAction );
00357 mForwardInlineAction->setShortcut( Key_F );
00358 mForwardAttachedAction->setShortcut( SHIFT+Key_F );
00359 connect( mForwardActionMenu, SIGNAL(activated()), this,
00360 SLOT(slotForwardInlineMsg()) );
00361 } else {
00362 mForwardActionMenu->insert( mForwardAttachedAction );
00363 mForwardActionMenu->insert( mForwardInlineAction );
00364 mForwardInlineAction->setShortcut( SHIFT+Key_F );
00365 mForwardAttachedAction->setShortcut( Key_F );
00366 connect( mForwardActionMenu, SIGNAL(activated()), this,
00367 SLOT(slotForwardAttachedMsg()) );
00368 }
00369
00370 mForwardActionMenu->insert( mForwardDigestAction );
00371 mForwardActionMenu->insert( mRedirectAction );
00372
00373 fontAction = new KFontAction( "Select Font", 0, actionCollection(),
00374 "text_font" );
00375 fontAction->setFont( mReaderWin->cssHelper()->bodyFont().family() );
00376 connect( fontAction, SIGNAL( activated( const QString& ) ),
00377 SLOT( slotFontAction( const QString& ) ) );
00378 fontSizeAction = new KFontSizeAction( "Select Size", 0, actionCollection(),
00379 "text_size" );
00380 fontSizeAction->setFontSize( mReaderWin->cssHelper()->bodyFont().pointSize() );
00381 connect( fontSizeAction, SIGNAL( fontSizeChanged( int ) ),
00382 SLOT( slotSizeAction( int ) ) );
00383
00384 QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00385 accel->connectItem(accel->insertItem(Key_Up),
00386 mReaderWin, SLOT(slotScrollUp()));
00387 accel->connectItem(accel->insertItem(Key_Down),
00388 mReaderWin, SLOT(slotScrollDown()));
00389 accel->connectItem(accel->insertItem(Key_Prior),
00390 mReaderWin, SLOT(slotScrollPrior()));
00391 accel->connectItem(accel->insertItem(Key_Next),
00392 mReaderWin, SLOT(slotScrollNext()));
00393 accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00394 mReaderWin, SLOT(slotCopySelectedText()));
00395 connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00396 this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00397 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00398 mReaderWin, SLOT(slotUrlClicked()));
00399
00400 setStandardToolBarMenuEnabled(true);
00401 KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
00402 }
00403
00404
00405 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00406 {
00407 KPopupMenu * menu = new KPopupMenu;
00408 mUrl = aUrl;
00409 mMsg = &aMsg;
00410 bool urlMenuAdded=false;
00411
00412 if (!aUrl.isEmpty())
00413 {
00414 if (aUrl.protocol() == "mailto") {
00415
00416 mReaderWin->mailToComposeAction()->plug( menu );
00417 if ( mMsg ) {
00418 mReaderWin->mailToReplyAction()->plug( menu );
00419 mReaderWin->mailToForwardAction()->plug( menu );
00420 menu->insertSeparator();
00421 }
00422 mReaderWin->addAddrBookAction()->plug( menu );
00423 mReaderWin->openAddrBookAction()->plug( menu );
00424 mReaderWin->copyAction()->plug( menu );
00425 } else {
00426
00427 mReaderWin->urlOpenAction()->plug( menu );
00428 mReaderWin->addBookmarksAction()->plug( menu );
00429 mReaderWin->urlSaveAsAction()->plug( menu );
00430 mReaderWin->copyURLAction()->plug( menu );
00431 }
00432 urlMenuAdded=true;
00433 }
00434 if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00435 if ( urlMenuAdded )
00436 menu->insertSeparator();
00437 mMsgActions->replyMenu()->plug( menu );
00438 menu->insertSeparator();
00439
00440 mReaderWin->copyAction()->plug( menu );
00441 mReaderWin->selectAllAction()->plug( menu );
00442 } else if ( !urlMenuAdded )
00443 {
00444
00445
00446 if (!mMsg)
00447 {
00448 delete menu;
00449 return;
00450 }
00451
00452 if ( ! ( aMsg.parent() && ( aMsg.parent()->isSent() ||
00453 aMsg.parent()->isDrafts() ||
00454 aMsg.parent()->isTemplates() ) ) ) {
00455
00456
00457
00458
00459
00460 mMsgActions->replyMenu()->plug( menu );
00461 mForwardActionMenu->plug( menu );
00462 menu->insertSeparator();
00463 }
00464
00465 QPopupMenu* copyMenu = new QPopupMenu(menu);
00466 KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00467 if ( mainwin )
00468 mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00469 &mMenuToFolder, copyMenu );
00470 menu->insertItem( i18n("&Copy To" ), copyMenu );
00471 menu->insertSeparator();
00472 mViewSourceAction->plug( menu );
00473 mReaderWin->toggleFixFontAction()->plug( menu );
00474 menu->insertSeparator();
00475 mPrintAction->plug( menu );
00476 mSaveAsAction->plug( menu );
00477 menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00478 mMsgActions->createTodoAction()->plug( menu );
00479 }
00480 menu->exec(aPoint, 0);
00481 delete menu;
00482 }
00483
00484 void KMReaderMainWin::copySelectedToFolder( int menuId )
00485 {
00486 if (!mMenuToFolder[menuId])
00487 return;
00488
00489 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00490 command->start();
00491 }
00492
00493 void KMReaderMainWin::slotFontAction( const QString& font)
00494 {
00495 QFont f( mReaderWin->cssHelper()->bodyFont() );
00496 f.setFamily( font );
00497 mReaderWin->cssHelper()->setBodyFont( f );
00498 mReaderWin->cssHelper()->setPrintFont( f );
00499 mReaderWin->saveRelativePosition();
00500 mReaderWin->update();
00501 }
00502
00503 void KMReaderMainWin::slotSizeAction( int size )
00504 {
00505 QFont f( mReaderWin->cssHelper()->bodyFont() );
00506 f.setPointSize( size );
00507 mReaderWin->cssHelper()->setBodyFont( f );
00508 mReaderWin->cssHelper()->setPrintFont( f );
00509 mReaderWin->saveRelativePosition();
00510 mReaderWin->update();
00511 }
00512
00513 void KMReaderMainWin::slotCreateTodo()
00514 {
00515 if ( !mMsg )
00516 return;
00517 KMCommand *command = new CreateTodoCommand( this, mMsg );
00518 command->start();
00519 }
00520
00521 void KMReaderMainWin::slotEditToolbars()
00522 {
00523 saveMainWindowSettings( KMKernel::config(), "ReaderWindow" );
00524 KEditToolbar dlg( guiFactory(), this );
00525 connect( &dlg, SIGNAL(newToolbarConfig()), SLOT(slotUpdateToolbars()) );
00526 dlg.exec();
00527 }
00528
00529 void KMReaderMainWin::slotUpdateToolbars()
00530 {
00531 createGUI("kmreadermainwin.rc");
00532 applyMainWindowSettings(KMKernel::config(), "ReaderWindow");
00533 }
00534
00535 #include "kmreadermainwin.moc"