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::setupForwardActions()
00280 {
00281 disconnect( mForwardActionMenu, SIGNAL( activated() ), 0, 0 );
00282 mForwardActionMenu->remove( mForwardInlineAction );
00283 mForwardActionMenu->remove( mForwardAttachedAction );
00284
00285 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00286 mForwardActionMenu->insert( mForwardInlineAction, 0 );
00287 mForwardActionMenu->insert( mForwardAttachedAction, 1 );
00288 mForwardInlineAction->setShortcut( Key_F );
00289 mForwardAttachedAction->setShortcut( SHIFT+Key_F );
00290 connect( mForwardActionMenu, SIGNAL(activated()), this,
00291 SLOT(slotForwardInlineMsg()) );
00292
00293 } else {
00294 mForwardActionMenu->insert( mForwardAttachedAction, 0 );
00295 mForwardActionMenu->insert( mForwardInlineAction, 1 );
00296 mForwardInlineAction->setShortcut( SHIFT+Key_F );
00297 mForwardAttachedAction->setShortcut( Key_F );
00298 connect( mForwardActionMenu, SIGNAL(activated()), this,
00299 SLOT(slotForwardAttachedMsg()) );
00300 }
00301 }
00302
00303
00304 void KMReaderMainWin::slotConfigChanged()
00305 {
00306
00307 setupForwardActions();
00308 setupForwardingActionsList();
00309 }
00310
00311 void KMReaderMainWin::setupAccel()
00312 {
00313 if ( kmkernel->xmlGuiInstance() )
00314 setInstance( kmkernel->xmlGuiInstance() );
00315
00316 mMsgActions = new KMail::MessageActions( actionCollection(), this );
00317 mMsgActions->setMessageView( mReaderWin );
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 mSaveAsAction = KStdAction::saveAs( mReaderWin, SLOT( slotSaveMsg() ),
00328 actionCollection() );
00329 mSaveAsAction->setShortcut( KStdAccel::shortcut( KStdAccel::Save ) );
00330 mPrintAction = KStdAction::print( this, SLOT( slotPrintMsg() ),
00331 actionCollection() );
00332
00333 KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
00334 KShortcut closeShortcut = closeAction->shortcut();
00335 closeShortcut.append( KKey(Key_Escape));
00336 closeAction->setShortcut(closeShortcut);
00337
00338
00339 KStdAction::copy( this, SLOT( slotCopy() ), actionCollection() );
00340 KStdAction::selectAll( this, SLOT( slotMarkAll() ), actionCollection() );
00341 KStdAction::find( this, SLOT(slotFind()), actionCollection() );
00342 KStdAction::findNext( this, SLOT( slotFindNext() ), actionCollection() );
00343 mTrashAction = new KAction( KGuiItem( i18n( "&Move to Trash" ), "edittrash",
00344 i18n( "Move message to trashcan" ) ),
00345 Key_Delete, this, SLOT( slotTrashMsg() ),
00346 actionCollection(), "move_to_trash" );
00347
00348
00349 mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00350 SLOT(slotShowMsgSrc()), actionCollection(),
00351 "view_source" );
00352
00353
00354 mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00355 "mail_forward", actionCollection(),
00356 "message_forward" );
00357 mForwardInlineAction = new KAction( i18n("&Inline..."),
00358 "mail_forward", SHIFT+Key_F, this,
00359 SLOT(slotForwardInlineMsg()),
00360 actionCollection(),
00361 "message_forward_inline" );
00362
00363 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00364 "mail_forward", Key_F, this,
00365 SLOT(slotForwardAttachedMsg()),
00366 actionCollection(),
00367 "message_forward_as_attachment" );
00368
00369 mForwardDigestAction = new KAction( i18n("Message->Forward->","As Di&gest..."),
00370 "mail_forward", 0, this,
00371 SLOT(slotForwardDigestMsg()),
00372 actionCollection(),
00373 "message_forward_as_digest" );
00374
00375 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00376 "mail_forward", Key_E, this,
00377 SLOT(slotRedirectMsg()),
00378 actionCollection(),
00379 "message_forward_redirect" );
00380
00381 setupForwardActions();
00382
00383 mForwardActionMenu->insert( mForwardDigestAction );
00384 mForwardActionMenu->insert( mRedirectAction );
00385
00386 fontAction = new KFontAction( "Select Font", 0, actionCollection(),
00387 "text_font" );
00388 fontAction->setFont( mReaderWin->cssHelper()->bodyFont().family() );
00389 connect( fontAction, SIGNAL( activated( const QString& ) ),
00390 SLOT( slotFontAction( const QString& ) ) );
00391 fontSizeAction = new KFontSizeAction( "Select Size", 0, actionCollection(),
00392 "text_size" );
00393 fontSizeAction->setFontSize( mReaderWin->cssHelper()->bodyFont().pointSize() );
00394 connect( fontSizeAction, SIGNAL( fontSizeChanged( int ) ),
00395 SLOT( slotSizeAction( int ) ) );
00396
00397 QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00398 accel->connectItem(accel->insertItem(Key_Up),
00399 mReaderWin, SLOT(slotScrollUp()));
00400 accel->connectItem(accel->insertItem(Key_Down),
00401 mReaderWin, SLOT(slotScrollDown()));
00402 accel->connectItem(accel->insertItem(Key_Prior),
00403 mReaderWin, SLOT(slotScrollPrior()));
00404 accel->connectItem(accel->insertItem(Key_Next),
00405 mReaderWin, SLOT(slotScrollNext()));
00406 accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00407 mReaderWin, SLOT(slotCopySelectedText()));
00408 connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00409 this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00410 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00411 mReaderWin, SLOT(slotUrlClicked()));
00412
00413 setStandardToolBarMenuEnabled(true);
00414 KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
00415 }
00416
00417
00418 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00419 {
00420 KPopupMenu * menu = new KPopupMenu;
00421 mUrl = aUrl;
00422 mMsg = &aMsg;
00423 bool urlMenuAdded=false;
00424 bool copyAdded = false;
00425 if (!aUrl.isEmpty())
00426 {
00427 if (aUrl.protocol() == "mailto") {
00428
00429 mReaderWin->mailToComposeAction()->plug( menu );
00430 if ( mMsg ) {
00431 mReaderWin->mailToReplyAction()->plug( menu );
00432 mReaderWin->mailToForwardAction()->plug( menu );
00433 menu->insertSeparator();
00434 }
00435 mReaderWin->addAddrBookAction()->plug( menu );
00436 mReaderWin->openAddrBookAction()->plug( menu );
00437 mReaderWin->copyAction()->plug( menu );
00438 copyAdded = true;
00439 } else {
00440
00441 mReaderWin->urlOpenAction()->plug( menu );
00442 mReaderWin->addBookmarksAction()->plug( menu );
00443 mReaderWin->urlSaveAsAction()->plug( menu );
00444 mReaderWin->copyURLAction()->plug( menu );
00445 }
00446 urlMenuAdded=true;
00447 }
00448 if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00449 if ( urlMenuAdded )
00450 menu->insertSeparator();
00451 mMsgActions->replyMenu()->plug( menu );
00452 menu->insertSeparator();
00453 if( !copyAdded )
00454 mReaderWin->copyAction()->plug( menu );
00455 mReaderWin->selectAllAction()->plug( menu );
00456 } else if ( !urlMenuAdded )
00457 {
00458
00459
00460 if (!mMsg)
00461 {
00462 delete menu;
00463 return;
00464 }
00465
00466 if ( ! ( aMsg.parent() && ( aMsg.parent()->isSent() ||
00467 aMsg.parent()->isDrafts() ||
00468 aMsg.parent()->isTemplates() ) ) ) {
00469
00470
00471
00472
00473
00474 mMsgActions->replyMenu()->plug( menu );
00475 mForwardActionMenu->plug( menu );
00476 menu->insertSeparator();
00477 }
00478
00479 QPopupMenu* copyMenu = new QPopupMenu(menu);
00480 KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00481 if ( mainwin )
00482 mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00483 &mMenuToFolder, copyMenu );
00484 menu->insertItem( i18n("&Copy To" ), copyMenu );
00485 menu->insertSeparator();
00486 mViewSourceAction->plug( menu );
00487 mReaderWin->toggleFixFontAction()->plug( menu );
00488 menu->insertSeparator();
00489 mPrintAction->plug( menu );
00490 mSaveAsAction->plug( menu );
00491 menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00492 mMsgActions->createTodoAction()->plug( menu );
00493 }
00494 menu->exec(aPoint, 0);
00495 delete menu;
00496 }
00497
00498 void KMReaderMainWin::copySelectedToFolder( int menuId )
00499 {
00500 if (!mMenuToFolder[menuId])
00501 return;
00502
00503 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00504 command->start();
00505 }
00506
00507 void KMReaderMainWin::slotFontAction( const QString& font)
00508 {
00509 QFont f( mReaderWin->cssHelper()->bodyFont() );
00510 f.setFamily( font );
00511 mReaderWin->cssHelper()->setBodyFont( f );
00512 mReaderWin->cssHelper()->setPrintFont( f );
00513 mReaderWin->saveRelativePosition();
00514 mReaderWin->update();
00515 }
00516
00517 void KMReaderMainWin::slotSizeAction( int size )
00518 {
00519 QFont f( mReaderWin->cssHelper()->bodyFont() );
00520 f.setPointSize( size );
00521 mReaderWin->cssHelper()->setBodyFont( f );
00522 mReaderWin->cssHelper()->setPrintFont( f );
00523 mReaderWin->saveRelativePosition();
00524 mReaderWin->update();
00525 }
00526
00527 void KMReaderMainWin::slotCreateTodo()
00528 {
00529 if ( !mMsg )
00530 return;
00531 KMCommand *command = new CreateTodoCommand( this, mMsg );
00532 command->start();
00533 }
00534
00535 void KMReaderMainWin::slotEditToolbars()
00536 {
00537 saveMainWindowSettings( KMKernel::config(), "ReaderWindow" );
00538 KEditToolbar dlg( guiFactory(), this );
00539 connect( &dlg, SIGNAL(newToolbarConfig()), SLOT(slotUpdateToolbars()) );
00540 dlg.exec();
00541 }
00542
00543 void KMReaderMainWin::slotUpdateToolbars()
00544 {
00545 createGUI("kmreadermainwin.rc");
00546 applyMainWindowSettings(KMKernel::config(), "ReaderWindow");
00547 }
00548
00549 #include "kmreadermainwin.moc"