30#include <tdeapplication.h>
31#include <kedittoolbar.h>
33#include <tdestdaccel.h>
36#include <kiconloader.h>
38#include "kmcommands.h"
39#include "tdemenubar.h"
40#include "tdepopupmenu.h"
41#include "kmreaderwin.h"
43#include "kmmainwidget.h"
44#include "kmfoldertree.h"
47#include "messageactions.h"
49#include "globalsettings.h"
51#include "kmreadermainwin.h"
53KMReaderMainWin::KMReaderMainWin(
bool htmlOverride,
bool htmlLoadExtDefault,
58 mReaderWin =
new KMReaderWin(
this,
this, actionCollection() );
60 mReaderWin->setAutoDelete(
true );
61 mReaderWin->setHtmlOverride( htmlOverride );
62 mReaderWin->setHtmlLoadExtDefault( htmlLoadExtDefault );
63 mReaderWin->setDecryptMessageOverwrite(
true );
64 mReaderWin->setShowSignatureDetails(
false );
65 initKMReaderMainWin();
70KMReaderMainWin::KMReaderMainWin(
char *name )
74 mReaderWin =
new KMReaderWin(
this,
this, actionCollection() );
75 mReaderWin->setAutoDelete(
true );
76 initKMReaderMainWin();
81KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
82 bool aHTML,
const TQString& aFileName,
const TQString& pname,
83 const TQString & encoding,
char *name )
87 mReaderWin =
new KMReaderWin(
this,
this, actionCollection() );
88 mReaderWin->setOverrideEncoding( encoding );
89 mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
90 initKMReaderMainWin();
95void KMReaderMainWin::initKMReaderMainWin() {
96 setCentralWidget( mReaderWin );
98 setupGUI( Keys | StatusBar | Create,
"kmreadermainwin.rc" );
99 setupForwardingActionsList();
100 applyMainWindowSettings( KMKernel::config(),
"Separate Reader Window" );
101 if ( ! mReaderWin->message() ) {
103 toolBar(
"mainToolBar" )->hide();
106 connect( kmkernel, TQ_SIGNAL( configChanged() ),
107 this, TQ_SLOT( slotConfigChanged() ) );
110void KMReaderMainWin::setupForwardingActionsList()
112 TQPtrList<TDEAction> mForwardActionList;
113 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
114 unplugActionList(
"forward_action_list" );
115 mForwardActionList.append( mForwardInlineAction );
116 mForwardActionList.append( mForwardAttachedAction );
117 mForwardActionList.append( mForwardDigestAction );
118 mForwardActionList.append( mRedirectAction );
119 plugActionList(
"forward_action_list", mForwardActionList );
121 unplugActionList(
"forward_action_list" );
122 mForwardActionList.append( mForwardAttachedAction );
123 mForwardActionList.append( mForwardInlineAction );
124 mForwardActionList.append( mForwardDigestAction );
125 mForwardActionList.append( mRedirectAction );
126 plugActionList(
"forward_action_list", mForwardActionList );
131KMReaderMainWin::~KMReaderMainWin()
133 saveMainWindowSettings( KMKernel::config(),
"Separate Reader Window" );
137void KMReaderMainWin::setUseFixedFont(
bool useFixedFont )
139 mReaderWin->setUseFixedFont( useFixedFont );
143void KMReaderMainWin::showMsg(
const TQString & encoding,
KMMessage *msg,
144 unsigned long serNumOfOriginalMessage,
int nodeIdOffset )
146 mReaderWin->setOverrideEncoding( encoding );
147 mReaderWin->setMsg( msg,
true );
148 if ( serNumOfOriginalMessage != 0 ) {
149 Q_ASSERT( nodeIdOffset != -1 );
150 mReaderWin->setOriginalMsg( serNumOfOriginalMessage, nodeIdOffset );
152 mReaderWin->slotTouchMessage();
155 mMsgActions->setCurrentMessage( msg );
157 toolBar(
"mainToolBar" )->show();
159 connect ( msg->parent(), TQ_SIGNAL( destroyed( TQObject* ) ),
this, TQ_SLOT( slotFolderRemoved( TQObject* ) ) );
163void KMReaderMainWin::slotFolderRemoved( TQObject* folderPtr )
166 assert(folderPtr == mMsg->parent());
167 if( mMsg && folderPtr == mMsg->parent() )
168 mMsg->setParent( 0 );
171void KMReaderMainWin::slotReplyOrForwardFinished()
173 if ( GlobalSettings::self()->closeAfterReplyOrForward() ) {
179void KMReaderMainWin::slotTrashMsg()
187 if ( parent && !parent->
isTrash() ) {
189 parent->
open(
"trashmsg");
190 KMMessage *msg = parent->
getMsg( index );
192 KMDeleteMsgCommand *command =
new KMDeleteMsgCommand( parent, msg );
195 parent->
close(
"trashmsg");
201void KMReaderMainWin::slotFind()
203 mReaderWin->slotFind();
206void KMReaderMainWin::slotFindNext()
208 mReaderWin->slotFindNext();
212void KMReaderMainWin::slotCopy()
214 mReaderWin->slotCopySelectedText();
218void KMReaderMainWin::slotMarkAll()
220 mReaderWin->selectAll();
224void KMReaderMainWin::slotPrintMsg()
226 KMPrintCommand *command =
new KMPrintCommand(
this, mReaderWin->message(),
227 mReaderWin->headerStyle(), mReaderWin->headerStrategy(),
228 mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
229 mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
230 command->setOverrideFont( mReaderWin->cssHelper()->bodyFont( mReaderWin->isFixedFont(),
true ) );
235void KMReaderMainWin::slotForwardInlineMsg()
237 KMCommand *command = 0;
238 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
239 command =
new KMForwardInlineCommand(
this, mReaderWin->message(),
240 mReaderWin->message()->parent()->identity() );
242 command =
new KMForwardInlineCommand(
this, mReaderWin->message() );
244 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
245 this, TQ_SLOT( slotReplyOrForwardFinished() ) );
250void KMReaderMainWin::slotForwardAttachedMsg()
252 KMCommand *command = 0;
253 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
254 command =
new KMForwardAttachedCommand(
this, mReaderWin->message(),
255 mReaderWin->message()->parent()->identity() );
257 command =
new KMForwardAttachedCommand(
this, mReaderWin->message() );
259 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
260 this, TQ_SLOT( slotReplyOrForwardFinished() ) );
265void KMReaderMainWin::slotForwardDigestMsg()
267 KMCommand *command = 0;
268 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
269 command =
new KMForwardDigestCommand(
this, mReaderWin->message(),
270 mReaderWin->message()->parent()->identity() );
272 command =
new KMForwardDigestCommand(
this, mReaderWin->message() );
274 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
275 this, TQ_SLOT( slotReplyOrForwardFinished() ) );
280void KMReaderMainWin::slotRedirectMsg()
282 KMCommand *command =
new KMRedirectCommand(
this, mReaderWin->message() );
283 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
284 this, TQ_SLOT( slotReplyOrForwardFinished() ) );
289void KMReaderMainWin::slotShowMsgSrc()
291 KMMessage *msg = mReaderWin->message();
294 KMCommand *command =
new KMShowMsgSrcCommand(
this, msg,
295 mReaderWin->isFixedFont() );
300void KMReaderMainWin::setupForwardActions()
302 disconnect( mForwardActionMenu, TQ_SIGNAL( activated() ), 0, 0 );
303 mForwardActionMenu->remove( mForwardInlineAction );
304 mForwardActionMenu->remove( mForwardAttachedAction );
306 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
307 mForwardActionMenu->insert( mForwardInlineAction, 0 );
308 mForwardActionMenu->insert( mForwardAttachedAction, 1 );
309 mForwardInlineAction->setShortcut( Key_F );
310 mForwardAttachedAction->setShortcut( SHIFT+Key_F );
311 connect( mForwardActionMenu, TQ_SIGNAL(activated()),
this,
312 TQ_SLOT(slotForwardInlineMsg()) );
315 mForwardActionMenu->insert( mForwardAttachedAction, 0 );
316 mForwardActionMenu->insert( mForwardInlineAction, 1 );
317 mForwardInlineAction->setShortcut( SHIFT+Key_F );
318 mForwardAttachedAction->setShortcut( Key_F );
319 connect( mForwardActionMenu, TQ_SIGNAL(activated()),
this,
320 TQ_SLOT(slotForwardAttachedMsg()) );
325void KMReaderMainWin::slotConfigChanged()
328 setupForwardActions();
329 setupForwardingActionsList();
332void KMReaderMainWin::setupAccel()
334 if ( kmkernel->xmlGuiInstance() )
335 setInstance( kmkernel->xmlGuiInstance() );
337 mMsgActions =
new KMail::MessageActions( actionCollection(),
this );
338 mMsgActions->setMessageView( mReaderWin );
339 connect( mMsgActions, TQ_SIGNAL( replyActionFinished() ),
340 this, TQ_SLOT( slotReplyOrForwardFinished() ) );
351 mSaveAsAction = KStdAction::saveAs( mReaderWin, TQ_SLOT( slotSaveMsg() ),
352 actionCollection() );
353 mSaveAsAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Save ) );
354 mPrintAction = KStdAction::print(
this, TQ_SLOT( slotPrintMsg() ),
355 actionCollection() );
357 TDEAction *closeAction = KStdAction::close(
this, TQ_SLOT( close() ), actionCollection() );
358 TDEShortcut closeShortcut = closeAction->shortcut();
359 closeShortcut.append( KKey(Key_Escape));
360 closeAction->setShortcut(closeShortcut);
363 KStdAction::copy(
this, TQ_SLOT( slotCopy() ), actionCollection() );
364 KStdAction::selectAll(
this, TQ_SLOT( slotMarkAll() ), actionCollection() );
365 KStdAction::find(
this, TQ_SLOT(slotFind()), actionCollection() );
366 KStdAction::findNext(
this, TQ_SLOT( slotFindNext() ), actionCollection() );
367 mTrashAction =
new TDEAction( KGuiItem( i18n(
"&Move to Trash" ),
"edittrash",
368 i18n(
"Move message to trashcan" ) ),
369 Key_Delete,
this, TQ_SLOT( slotTrashMsg() ),
370 actionCollection(),
"move_to_trash" );
373 mViewSourceAction =
new TDEAction( i18n(
"&View Source"), Key_V,
this,
374 TQ_SLOT(slotShowMsgSrc()), actionCollection(),
378 mForwardActionMenu =
new TDEActionMenu( i18n(
"Message->",
"&Forward"),
379 "mail-forward", actionCollection(),
381 mForwardInlineAction =
new TDEAction( i18n(
"&Inline..."),
382 "mail-forward", SHIFT+Key_F,
this,
383 TQ_SLOT(slotForwardInlineMsg()),
385 "message_forward_inline" );
387 mForwardAttachedAction =
new TDEAction( i18n(
"Message->Forward->",
"As &Attachment..."),
388 "mail-forward", Key_F,
this,
389 TQ_SLOT(slotForwardAttachedMsg()),
391 "message_forward_as_attachment" );
393 mForwardDigestAction =
new TDEAction( i18n(
"Message->Forward->",
"As Di&gest..."),
394 "mail-forward", 0,
this,
395 TQ_SLOT(slotForwardDigestMsg()),
397 "message_forward_as_digest" );
399 mRedirectAction =
new TDEAction( i18n(
"Message->Forward->",
"&Redirect..."),
400 "mail-forward", Key_E,
this,
401 TQ_SLOT(slotRedirectMsg()),
403 "message_forward_redirect" );
405 setupForwardActions();
407 mForwardActionMenu->insert( mForwardDigestAction );
408 mForwardActionMenu->insert( mRedirectAction );
410 fontAction =
new TDEFontAction(
"Select Font", 0, actionCollection(),
412 fontAction->setFont( mReaderWin->cssHelper()->bodyFont().family() );
413 connect( fontAction, TQ_SIGNAL( activated(
const TQString& ) ),
414 TQ_SLOT( slotFontAction(
const TQString& ) ) );
415 fontSizeAction =
new TDEFontSizeAction(
"Select Size", 0, actionCollection(),
417 fontSizeAction->setFontSize( mReaderWin->cssHelper()->bodyFont().pointSize() );
418 connect( fontSizeAction, TQ_SIGNAL( fontSizeChanged(
int ) ),
419 TQ_SLOT( slotSizeAction(
int ) ) );
421 TQAccel *accel =
new TQAccel(mReaderWin,
"showMsg()");
422 accel->connectItem(accel->insertItem(Key_Up),
423 mReaderWin, TQ_SLOT(slotScrollUp()));
424 accel->connectItem(accel->insertItem(Key_Down),
425 mReaderWin, TQ_SLOT(slotScrollDown()));
426 accel->connectItem(accel->insertItem(Key_Prior),
427 mReaderWin, TQ_SLOT(slotScrollPrior()));
428 accel->connectItem(accel->insertItem(Key_Next),
429 mReaderWin, TQ_SLOT(slotScrollNext()));
430 accel->connectItem(accel->insertItem(TDEStdAccel::shortcut(TDEStdAccel::Copy)),
431 mReaderWin, TQ_SLOT(slotCopySelectedText()));
432 connect( mReaderWin, TQ_SIGNAL(popupMenu(KMMessage&,
const KURL&,
const TQPoint&)),
433 this, TQ_SLOT(slotMsgPopup(KMMessage&,
const KURL&,
const TQPoint&)));
434 connect(mReaderWin, TQ_SIGNAL(urlClicked(
const KURL&,
int)),
435 mReaderWin, TQ_SLOT(slotUrlClicked()));
437 setStandardToolBarMenuEnabled(
true);
438 KStdAction::configureToolbars(
this, TQ_SLOT(slotEditToolbars()), actionCollection());
442void KMReaderMainWin::slotMsgPopup(
KMMessage &aMsg,
const KURL &aUrl,
const TQPoint& aPoint)
444 TDEPopupMenu * menu =
new TDEPopupMenu;
447 bool urlMenuAdded=
false;
448 bool copyAdded =
false;
451 if (aUrl.protocol() ==
"mailto") {
453 mReaderWin->mailToComposeAction()->plug( menu );
455 mReaderWin->mailToReplyAction()->plug( menu );
456 mReaderWin->mailToForwardAction()->plug( menu );
457 menu->insertSeparator();
459 mReaderWin->addAddrBookAction()->plug( menu );
460 mReaderWin->openAddrBookAction()->plug( menu );
461 mReaderWin->copyURLAction()->plug( menu );
465 mReaderWin->urlOpenAction()->plug( menu );
466 mReaderWin->addBookmarksAction()->plug( menu );
467 mReaderWin->urlSaveAsAction()->plug( menu );
468 mReaderWin->copyURLAction()->plug( menu );
472 if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
474 menu->insertSeparator();
475 mMsgActions->replyMenu()->plug( menu );
476 menu->insertSeparator();
478 mReaderWin->copyAction()->plug( menu );
479 mReaderWin->selectAllAction()->plug( menu );
480 }
else if ( !urlMenuAdded )
490 if ( ! ( aMsg.parent() && ( aMsg.parent()->
isSent() ||
498 mMsgActions->replyMenu()->plug( menu );
499 mForwardActionMenu->plug( menu );
500 menu->insertSeparator();
503 TQPopupMenu* copyMenu =
new TQPopupMenu(menu);
504 KMMainWidget* mainwin = kmkernel->getKMMainWidget();
506 mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage,
this,
507 &mMenuToFolder, copyMenu );
508 menu->insertItem( i18n(
"&Copy To" ), copyMenu );
509 menu->insertSeparator();
510 mViewSourceAction->plug( menu );
511 mReaderWin->toggleFixFontAction()->plug( menu );
512 mReaderWin->toggleMimePartTreeAction()->plug( menu );
513 menu->insertSeparator();
514 mPrintAction->plug( menu );
515 mSaveAsAction->plug( menu );
516 menu->insertItem( i18n(
"Save Attachments..."), mReaderWin, TQ_SLOT(slotSaveAttachments()) );
517 mMsgActions->createTodoAction()->plug( menu );
519 menu->exec(aPoint, 0);
523void KMReaderMainWin::copySelectedToFolder(
int menuId )
525 if (!mMenuToFolder[menuId])
528 KMCommand *command =
new KMCopyCommand( mMenuToFolder[menuId], mMsg );
532void KMReaderMainWin::slotFontAction(
const TQString& font)
534 TQFont f( mReaderWin->cssHelper()->bodyFont() );
536 mReaderWin->cssHelper()->setBodyFont( f );
537 mReaderWin->cssHelper()->setPrintFont( f );
538 mReaderWin->saveRelativePosition();
539 mReaderWin->update();
542void KMReaderMainWin::slotSizeAction(
int size )
544 TQFont f( mReaderWin->cssHelper()->bodyFont() );
545 f.setPointSize( size );
546 mReaderWin->cssHelper()->setBodyFont( f );
547 mReaderWin->cssHelper()->setPrintFont( f );
548 mReaderWin->saveRelativePosition();
549 mReaderWin->update();
552void KMReaderMainWin::slotCreateTodo()
556 KMCommand *command =
new CreateTodoCommand(
this, mMsg );
560void KMReaderMainWin::slotEditToolbars()
562 saveMainWindowSettings( KMKernel::config(),
"ReaderWindow" );
563 KEditToolbar dlg( guiFactory(),
this );
564 connect( &dlg, TQ_SIGNAL(newToolbarConfig()), TQ_SLOT(slotUpdateToolbars()) );
568void KMReaderMainWin::slotUpdateToolbars()
570 createGUI(
"kmreadermainwin.rc");
571 applyMainWindowSettings(KMKernel::config(),
"ReaderWindow");
574#include "kmreadermainwin.moc"
bool isTrash()
Returns true if this folder is configured as a trash folder, locally or for one of the accounts.
bool isDrafts()
Returns true if this folder is the drafts box of the local account, or is configured to be the drafts...
bool isTemplates()
Returns true if this folder is the templates folder of the local account, or is configured to be the ...
bool isSent()
Returns true if this folder is the sent-mail box of the local account, or is configured to be the sen...
void close(const char *owner, bool force=false)
Close folder.
KMMessage * getMsg(int idx)
Read message at given index.
int open(const char *owner)
Open folder for access.
TQString subject() const
Get or set the 'Subject' header field.
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
static const KMMsgDict * instance()
Access the globally unique MessageDict.
This class implements a "reader window", that is a window used for reading or viewing messages.
Window class for secondary KMail window like the composer window and the separate message window.