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