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 <tqaccel.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 TQString& aFileName, const TQString& pname,
00083 const TQString & 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, TQT_SIGNAL( configChanged() ),
00107 this, TQT_SLOT( slotConfigChanged() ) );
00108 }
00109
00110 void KMReaderMainWin::setupForwardingActionsList()
00111 {
00112 TQPtrList<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 TQString & encoding, KMMessage *msg,
00144 unsigned long serNumOfOriginalMessage, int nodeIdOffset )
00145 {
00146 mReaderWin->setOverrideEncoding( encoding );
00147 mReaderWin->setMsg( msg, true );
00148 if ( serNumOfOriginalMessage != 0 ) {
00149 Q_ASSERT( nodeIdOffset != -1 );
00150 mReaderWin->setOriginalMsg( serNumOfOriginalMessage, nodeIdOffset );
00151 }
00152 mReaderWin->slotTouchMessage();
00153 setCaption( msg->subject() );
00154 mMsg = msg;
00155 mMsgActions->setCurrentMessage( msg );
00156 menuBar()->show();
00157 toolBar( "mainToolBar" )->show();
00158
00159 connect ( msg->parent(), TQT_SIGNAL( destroyed( TQObject* ) ), this, TQT_SLOT( slotFolderRemoved( TQObject* ) ) );
00160
00161 }
00162
00163 void KMReaderMainWin::slotFolderRemoved( TQObject* folderPtr )
00164 {
00165 assert(mMsg);
00166 assert(folderPtr == mMsg->parent());
00167 if( mMsg && folderPtr == mMsg->parent() )
00168 mMsg->setParent( 0 );
00169 }
00170
00171 void KMReaderMainWin::slotReplyOrForwardFinished()
00172 {
00173 if ( GlobalSettings::self()->closeAfterReplyOrForward() ) {
00174 close();
00175 }
00176 }
00177
00178
00179 void KMReaderMainWin::slotTrashMsg()
00180 {
00181 if ( !mMsg )
00182 return;
00183
00184 KMFolder* parent;
00185 int index;
00186 KMMsgDict::instance()->getLocation( mMsg->getMsgSerNum(), &parent, &index );
00187 if ( parent && !parent->isTrash() ) {
00188
00189 parent->open("trashmsg");
00190 KMMessage *msg = parent->getMsg( index );
00191 if (msg) {
00192 KMDeleteMsgCommand *command = new KMDeleteMsgCommand( parent, msg );
00193 command->start();
00194 }
00195 parent->close("trashmsg");
00196 }
00197 close();
00198 }
00199
00200
00201 void KMReaderMainWin::slotFind()
00202 {
00203 mReaderWin->slotFind();
00204 }
00205
00206 void KMReaderMainWin::slotFindNext()
00207 {
00208 mReaderWin->slotFindNext();
00209 }
00210
00211
00212 void KMReaderMainWin::slotCopy()
00213 {
00214 mReaderWin->slotCopySelectedText();
00215 }
00216
00217
00218 void KMReaderMainWin::slotMarkAll()
00219 {
00220 mReaderWin->selectAll();
00221 }
00222
00223
00224 void KMReaderMainWin::slotPrintMsg()
00225 {
00226 KMPrintCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00227 mReaderWin->headerStyle(), mReaderWin->headerStrategy(),
00228 mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
00229 mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
00230 command->setOverrideFont( mReaderWin->cssHelper()->bodyFont( mReaderWin->isFixedFont(), true ) );
00231 command->start();
00232 }
00233
00234
00235 void KMReaderMainWin::slotForwardInlineMsg()
00236 {
00237 KMCommand *command = 0;
00238 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00239 command = new KMForwardInlineCommand( this, mReaderWin->message(),
00240 mReaderWin->message()->parent()->identity() );
00241 } else {
00242 command = new KMForwardInlineCommand( this, mReaderWin->message() );
00243 }
00244 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
00245 this, TQT_SLOT( slotReplyOrForwardFinished() ) );
00246 command->start();
00247 }
00248
00249
00250 void KMReaderMainWin::slotForwardAttachedMsg()
00251 {
00252 KMCommand *command = 0;
00253 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00254 command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00255 mReaderWin->message()->parent()->identity() );
00256 } else {
00257 command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00258 }
00259 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
00260 this, TQT_SLOT( slotReplyOrForwardFinished() ) );
00261 command->start();
00262 }
00263
00264
00265 void KMReaderMainWin::slotForwardDigestMsg()
00266 {
00267 KMCommand *command = 0;
00268 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00269 command = new KMForwardDigestCommand( this, mReaderWin->message(),
00270 mReaderWin->message()->parent()->identity() );
00271 } else {
00272 command = new KMForwardDigestCommand( this, mReaderWin->message() );
00273 }
00274 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
00275 this, TQT_SLOT( slotReplyOrForwardFinished() ) );
00276 command->start();
00277 }
00278
00279
00280 void KMReaderMainWin::slotRedirectMsg()
00281 {
00282 KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00283 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
00284 this, TQT_SLOT( slotReplyOrForwardFinished() ) );
00285 command->start();
00286 }
00287
00288
00289 void KMReaderMainWin::slotShowMsgSrc()
00290 {
00291 KMMessage *msg = mReaderWin->message();
00292 if ( !msg )
00293 return;
00294 KMCommand *command = new KMShowMsgSrcCommand( this, msg,
00295 mReaderWin->isFixedFont() );
00296 command->start();
00297 }
00298
00299
00300 void KMReaderMainWin::setupForwardActions()
00301 {
00302 disconnect( mForwardActionMenu, TQT_SIGNAL( activated() ), 0, 0 );
00303 mForwardActionMenu->remove( mForwardInlineAction );
00304 mForwardActionMenu->remove( mForwardAttachedAction );
00305
00306 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00307 mForwardActionMenu->insert( mForwardInlineAction, 0 );
00308 mForwardActionMenu->insert( mForwardAttachedAction, 1 );
00309 mForwardInlineAction->setShortcut( Key_F );
00310 mForwardAttachedAction->setShortcut( SHIFT+Key_F );
00311 connect( mForwardActionMenu, TQT_SIGNAL(activated()), this,
00312 TQT_SLOT(slotForwardInlineMsg()) );
00313
00314 } else {
00315 mForwardActionMenu->insert( mForwardAttachedAction, 0 );
00316 mForwardActionMenu->insert( mForwardInlineAction, 1 );
00317 mForwardInlineAction->setShortcut( SHIFT+Key_F );
00318 mForwardAttachedAction->setShortcut( Key_F );
00319 connect( mForwardActionMenu, TQT_SIGNAL(activated()), this,
00320 TQT_SLOT(slotForwardAttachedMsg()) );
00321 }
00322 }
00323
00324
00325 void KMReaderMainWin::slotConfigChanged()
00326 {
00327
00328 setupForwardActions();
00329 setupForwardingActionsList();
00330 }
00331
00332 void KMReaderMainWin::setupAccel()
00333 {
00334 if ( kmkernel->xmlGuiInstance() )
00335 setInstance( kmkernel->xmlGuiInstance() );
00336
00337 mMsgActions = new KMail::MessageActions( actionCollection(), this );
00338 mMsgActions->setMessageView( mReaderWin );
00339 connect( mMsgActions, TQT_SIGNAL( replyActionFinished() ),
00340 this, TQT_SLOT( slotReplyOrForwardFinished() ) );
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 mSaveAsAction = KStdAction::saveAs( mReaderWin, TQT_SLOT( slotSaveMsg() ),
00352 actionCollection() );
00353 mSaveAsAction->setShortcut( KStdAccel::shortcut( KStdAccel::Save ) );
00354 mPrintAction = KStdAction::print( this, TQT_SLOT( slotPrintMsg() ),
00355 actionCollection() );
00356
00357 KAction *closeAction = KStdAction::close( this, TQT_SLOT( close() ), actionCollection() );
00358 KShortcut closeShortcut = closeAction->shortcut();
00359 closeShortcut.append( KKey(Key_Escape));
00360 closeAction->setShortcut(closeShortcut);
00361
00362
00363 KStdAction::copy( this, TQT_SLOT( slotCopy() ), actionCollection() );
00364 KStdAction::selectAll( this, TQT_SLOT( slotMarkAll() ), actionCollection() );
00365 KStdAction::find( this, TQT_SLOT(slotFind()), actionCollection() );
00366 KStdAction::findNext( this, TQT_SLOT( slotFindNext() ), actionCollection() );
00367 mTrashAction = new KAction( KGuiItem( i18n( "&Move to Trash" ), "edittrash",
00368 i18n( "Move message to trashcan" ) ),
00369 Key_Delete, this, TQT_SLOT( slotTrashMsg() ),
00370 actionCollection(), "move_to_trash" );
00371
00372
00373 mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00374 TQT_SLOT(slotShowMsgSrc()), actionCollection(),
00375 "view_source" );
00376
00377
00378 mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00379 "mail_forward", actionCollection(),
00380 "message_forward" );
00381 mForwardInlineAction = new KAction( i18n("&Inline..."),
00382 "mail_forward", SHIFT+Key_F, this,
00383 TQT_SLOT(slotForwardInlineMsg()),
00384 actionCollection(),
00385 "message_forward_inline" );
00386
00387 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00388 "mail_forward", Key_F, this,
00389 TQT_SLOT(slotForwardAttachedMsg()),
00390 actionCollection(),
00391 "message_forward_as_attachment" );
00392
00393 mForwardDigestAction = new KAction( i18n("Message->Forward->","As Di&gest..."),
00394 "mail_forward", 0, this,
00395 TQT_SLOT(slotForwardDigestMsg()),
00396 actionCollection(),
00397 "message_forward_as_digest" );
00398
00399 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00400 "mail_forward", Key_E, this,
00401 TQT_SLOT(slotRedirectMsg()),
00402 actionCollection(),
00403 "message_forward_redirect" );
00404
00405 setupForwardActions();
00406
00407 mForwardActionMenu->insert( mForwardDigestAction );
00408 mForwardActionMenu->insert( mRedirectAction );
00409
00410 fontAction = new KFontAction( "Select Font", 0, actionCollection(),
00411 "text_font" );
00412 fontAction->setFont( mReaderWin->cssHelper()->bodyFont().family() );
00413 connect( fontAction, TQT_SIGNAL( activated( const TQString& ) ),
00414 TQT_SLOT( slotFontAction( const TQString& ) ) );
00415 fontSizeAction = new KFontSizeAction( "Select Size", 0, actionCollection(),
00416 "text_size" );
00417 fontSizeAction->setFontSize( mReaderWin->cssHelper()->bodyFont().pointSize() );
00418 connect( fontSizeAction, TQT_SIGNAL( fontSizeChanged( int ) ),
00419 TQT_SLOT( slotSizeAction( int ) ) );
00420
00421 TQAccel *accel = new TQAccel(mReaderWin, "showMsg()");
00422 accel->connectItem(accel->insertItem(Key_Up),
00423 mReaderWin, TQT_SLOT(slotScrollUp()));
00424 accel->connectItem(accel->insertItem(Key_Down),
00425 mReaderWin, TQT_SLOT(slotScrollDown()));
00426 accel->connectItem(accel->insertItem(Key_Prior),
00427 mReaderWin, TQT_SLOT(slotScrollPrior()));
00428 accel->connectItem(accel->insertItem(Key_Next),
00429 mReaderWin, TQT_SLOT(slotScrollNext()));
00430 accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00431 mReaderWin, TQT_SLOT(slotCopySelectedText()));
00432 connect( mReaderWin, TQT_SIGNAL(popupMenu(KMMessage&,const KURL&,const TQPoint&)),
00433 this, TQT_SLOT(slotMsgPopup(KMMessage&,const KURL&,const TQPoint&)));
00434 connect(mReaderWin, TQT_SIGNAL(urlClicked(const KURL&,int)),
00435 mReaderWin, TQT_SLOT(slotUrlClicked()));
00436
00437 setStandardToolBarMenuEnabled(true);
00438 KStdAction::configureToolbars(this, TQT_SLOT(slotEditToolbars()), actionCollection());
00439 }
00440
00441
00442 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const TQPoint& aPoint)
00443 {
00444 KPopupMenu * menu = new KPopupMenu;
00445 mUrl = aUrl;
00446 mMsg = &aMsg;
00447 bool urlMenuAdded=false;
00448 bool copyAdded = false;
00449 if (!aUrl.isEmpty())
00450 {
00451 if (aUrl.protocol() == "mailto") {
00452
00453 mReaderWin->mailToComposeAction()->plug( menu );
00454 if ( mMsg ) {
00455 mReaderWin->mailToReplyAction()->plug( menu );
00456 mReaderWin->mailToForwardAction()->plug( menu );
00457 menu->insertSeparator();
00458 }
00459 mReaderWin->addAddrBookAction()->plug( menu );
00460 mReaderWin->openAddrBookAction()->plug( menu );
00461 mReaderWin->copyURLAction()->plug( menu );
00462 copyAdded = true;
00463 } else {
00464
00465 mReaderWin->urlOpenAction()->plug( menu );
00466 mReaderWin->addBookmarksAction()->plug( menu );
00467 mReaderWin->urlSaveAsAction()->plug( menu );
00468 mReaderWin->copyURLAction()->plug( menu );
00469 }
00470 urlMenuAdded=true;
00471 }
00472 if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00473 if ( urlMenuAdded )
00474 menu->insertSeparator();
00475 mMsgActions->replyMenu()->plug( menu );
00476 menu->insertSeparator();
00477 if( !copyAdded )
00478 mReaderWin->copyAction()->plug( menu );
00479 mReaderWin->selectAllAction()->plug( menu );
00480 } else if ( !urlMenuAdded )
00481 {
00482
00483
00484 if (!mMsg)
00485 {
00486 delete menu;
00487 return;
00488 }
00489
00490 if ( ! ( aMsg.parent() && ( aMsg.parent()->isSent() ||
00491 aMsg.parent()->isDrafts() ||
00492 aMsg.parent()->isTemplates() ) ) ) {
00493
00494
00495
00496
00497
00498 mMsgActions->replyMenu()->plug( menu );
00499 mForwardActionMenu->plug( menu );
00500 menu->insertSeparator();
00501 }
00502
00503 TQPopupMenu* copyMenu = new TQPopupMenu(menu);
00504 KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00505 if ( mainwin )
00506 mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00507 &mMenuToFolder, copyMenu );
00508 menu->insertItem( i18n("&Copy To" ), copyMenu );
00509 menu->insertSeparator();
00510 mViewSourceAction->plug( menu );
00511 mReaderWin->toggleFixFontAction()->plug( menu );
00512 menu->insertSeparator();
00513 mPrintAction->plug( menu );
00514 mSaveAsAction->plug( menu );
00515 menu->insertItem( i18n("Save Attachments..."), mReaderWin, TQT_SLOT(slotSaveAttachments()) );
00516 mMsgActions->createTodoAction()->plug( menu );
00517 }
00518 menu->exec(aPoint, 0);
00519 delete menu;
00520 }
00521
00522 void KMReaderMainWin::copySelectedToFolder( int menuId )
00523 {
00524 if (!mMenuToFolder[menuId])
00525 return;
00526
00527 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00528 command->start();
00529 }
00530
00531 void KMReaderMainWin::slotFontAction( const TQString& font)
00532 {
00533 TQFont f( mReaderWin->cssHelper()->bodyFont() );
00534 f.setFamily( font );
00535 mReaderWin->cssHelper()->setBodyFont( f );
00536 mReaderWin->cssHelper()->setPrintFont( f );
00537 mReaderWin->saveRelativePosition();
00538 mReaderWin->update();
00539 }
00540
00541 void KMReaderMainWin::slotSizeAction( int size )
00542 {
00543 TQFont f( mReaderWin->cssHelper()->bodyFont() );
00544 f.setPointSize( size );
00545 mReaderWin->cssHelper()->setBodyFont( f );
00546 mReaderWin->cssHelper()->setPrintFont( f );
00547 mReaderWin->saveRelativePosition();
00548 mReaderWin->update();
00549 }
00550
00551 void KMReaderMainWin::slotCreateTodo()
00552 {
00553 if ( !mMsg )
00554 return;
00555 KMCommand *command = new CreateTodoCommand( this, mMsg );
00556 command->start();
00557 }
00558
00559 void KMReaderMainWin::slotEditToolbars()
00560 {
00561 saveMainWindowSettings( KMKernel::config(), "ReaderWindow" );
00562 KEditToolbar dlg( guiFactory(), this );
00563 connect( &dlg, TQT_SIGNAL(newToolbarConfig()), TQT_SLOT(slotUpdateToolbars()) );
00564 dlg.exec();
00565 }
00566
00567 void KMReaderMainWin::slotUpdateToolbars()
00568 {
00569 createGUI("kmreadermainwin.rc");
00570 applyMainWindowSettings(KMKernel::config(), "ReaderWindow");
00571 }
00572
00573 #include "kmreadermainwin.moc"