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