30 #include <kactionmenu.h>
31 #include <kedittoolbar.h>
33 #include <kstandardshortcut.h>
34 #include <kwindowsystem.h>
36 #include <kfontaction.h>
37 #include <kstandardaction.h>
38 #include <ktoggleaction.h>
41 #include <KFontAction>
42 #include <KFontSizeAction>
43 #include <kstatusbar.h>
44 #include <KMessageBox>
45 #include <KAcceleratorManager>
50 #include "messageviewer/viewer/csshelper.h"
51 #include "customtemplatesmenu.h"
54 #include "kernel/mailkernel.h"
55 #include "foldercollection.h"
57 #include "agents/folderarchiveagent/folderarchiveutil.h"
59 #include <KActionCollection>
60 #include <akonadi/contact/contactsearchjob.h>
61 #include <kpimutils/email.h>
62 #include <kmime/kmime_message.h>
64 #include <messageviewer/viewer/viewer.h>
65 #include <akonadi/item.h>
66 #include <akonadi/itemcopyjob.h>
67 #include <akonadi/itemcreatejob.h>
69 #include "messagecore/helpers/messagehelpers.h"
70 #include <util/mailutil.h>
72 using namespace MailCommon;
76 : KMail::SecondaryWindow( name ? name :
"readerwindow#" )
78 mReaderWin =
new KMReaderWin(
this,
this, actionCollection());
83 initKMReaderMainWin();
89 : KMail::SecondaryWindow( name ? name :
"readerwindow#" )
91 mReaderWin =
new KMReaderWin(
this,
this, actionCollection());
92 initKMReaderMainWin();
98 : KMail::SecondaryWindow( name ? name :
"readerwindow#" )
100 mReaderWin =
new KMReaderWin(
this,
this, actionCollection() );
104 initKMReaderMainWin();
108 void KMReaderMainWin::initKMReaderMainWin()
110 setCentralWidget( mReaderWin );
112 setupGUI( Keys | StatusBar | Create, QLatin1String(
"kmreadermainwin.rc") );
114 applyMainWindowSettings(
KMKernel::self()->config()->group(
"Separate Reader Window" ) );
115 if( ! mReaderWin->
message().isValid() ) {
117 toolBar( QLatin1String(
"mainToolBar") )->hide();
119 connect(
kmkernel, SIGNAL(configChanged()),
120 this, SLOT(slotConfigChanged()) );
121 connect( mReaderWin, SIGNAL(showStatusBarMessage(QString)),
128 saveMainWindowSettings(
KMKernel::self()->config()->group(
"Separate Reader Window" ) );
140 mParentCollection = parentCollection;
142 mReaderWin->
setMessage( msg, MessageViewer::Viewer::Force );
143 KMime::Message::Ptr message = MessageCore::Util::message( msg );
146 caption = message->subject()->asUnicodeString();
148 if(mParentCollection.isValid()) {
149 caption += QLatin1String(
" - ");
150 caption += MailCommon::Util::fullCollectionPath( mParentCollection );
152 if(!caption.isEmpty()) {
158 const bool canChange = mParentCollection.isValid() ? (bool)( mParentCollection.rights() & Akonadi::Collection::CanDeleteItem ) :
false;
159 mTrashAction->setEnabled( canChange );
162 toolBar( QLatin1String(
"mainToolBar") )->show();
172 item.setPayload<KMime::Message::Ptr>( message );
173 item.setMimeType( KMime::Message::mimeType() );
180 setCaption( message->subject()->asUnicodeString() );
182 mTrashAction->setEnabled(
false );
185 toolBar( QLatin1String(
"mainToolBar") )->show();
189 void KMReaderMainWin::slotReplyOrForwardFinished()
196 Akonadi::Collection KMReaderMainWin::parentCollection()
const
198 if ( mParentCollection.isValid() )
199 return mParentCollection;
201 return mMsg.parentCollection();
205 void KMReaderMainWin::slotTrashMsg()
207 if ( !mMsg.isValid() )
215 void KMReaderMainWin::slotForwardInlineMsg()
217 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
219 const Akonadi::Collection parentCol = mReaderWin->
message().parentCollection();
220 if ( parentCol.isValid() ) {
230 connect( command, SIGNAL(completed(
KMCommand*)),
231 this, SLOT(slotReplyOrForwardFinished()) );
236 void KMReaderMainWin::slotForwardAttachedMsg()
238 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
240 const Akonadi::Collection parentCol = mReaderWin->
message().parentCollection();
241 if ( parentCol.isValid() ) {
252 connect( command, SIGNAL(completed(
KMCommand*)),
253 this, SLOT(slotReplyOrForwardFinished()) );
258 void KMReaderMainWin::slotRedirectMsg()
260 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
262 connect( command, SIGNAL(completed(
KMCommand*)),
263 this, SLOT(slotReplyOrForwardFinished()) );
268 void KMReaderMainWin::slotCustomReplyToMsg(
const QString &tmpl )
270 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
273 MessageComposer::ReplySmart,
276 connect( command, SIGNAL(completed(
KMCommand*)),
277 this, SLOT(slotReplyOrForwardFinished()) );
282 void KMReaderMainWin::slotCustomReplyAllToMsg(
const QString &tmpl )
284 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
287 MessageComposer::ReplyAll,
290 connect( command, SIGNAL(completed(
KMCommand*)),
291 this, SLOT(slotReplyOrForwardFinished()) );
297 void KMReaderMainWin::slotCustomForwardMsg(
const QString &tmpl)
299 if ( !mReaderWin->
message().hasPayload<KMime::Message::Ptr>() )
return;
303 connect( command, SIGNAL(completed(
KMCommand*)),
304 this, SLOT(slotReplyOrForwardFinished()) );
310 void KMReaderMainWin::slotConfigChanged()
317 void KMReaderMainWin::setupAccel()
319 if (
kmkernel->xmlGuiInstance().isValid() )
320 setComponentData(
kmkernel->xmlGuiInstance() );
324 connect( mMsgActions, SIGNAL(replyActionFinished()),
325 this, SLOT(slotReplyOrForwardFinished()) );
329 mSaveAtmAction =
new KAction(KIcon(QLatin1String(
"mail-attachment")), i18n(
"Save A&ttachments..."), actionCollection() );
330 connect( mSaveAtmAction, SIGNAL(triggered(
bool)), mReaderWin->
viewer(), SLOT(slotAttachmentSaveAll()) );
332 mTrashAction =
new KAction( KIcon( QLatin1String(
"user-trash") ), i18n(
"&Move to Trash"),
this );
333 mTrashAction->setIconText( i18nc(
"@action:intoolbar Move to Trash",
"Trash" ) );
334 mTrashAction->setHelpText( i18n(
"Move message to trashcan" ) );
335 mTrashAction->setShortcut( QKeySequence( Qt::Key_Delete ) );
336 actionCollection()->addAction( QLatin1String(
"move_to_trash"), mTrashAction );
337 connect( mTrashAction, SIGNAL(triggered()),
this, SLOT(slotTrashMsg()) );
339 KAction *closeAction = KStandardAction::close(
this, SLOT(close()), actionCollection() );
340 KShortcut closeShortcut = KShortcut(closeAction->shortcuts());
341 closeShortcut.setAlternate( QKeySequence(Qt::Key_Escape));
342 closeAction->setShortcuts(closeShortcut);
346 mFontAction =
new KFontAction( i18n(
"Select Font"),
this );
347 actionCollection()->addAction( QLatin1String(
"text_font"), mFontAction );
348 mFontAction->setFont( mReaderWin->
cssHelper()->bodyFont().family() );
349 connect( mFontAction, SIGNAL(triggered(QString)),
350 SLOT(slotFontAction(QString)) );
351 mFontSizeAction =
new KFontSizeAction( i18n(
"Select Size" ),
this );
352 mFontSizeAction->setFontSize( mReaderWin->
cssHelper()->bodyFont().pointSize() );
353 actionCollection()->addAction( QLatin1String(
"text_size"), mFontSizeAction );
354 connect( mFontSizeAction, SIGNAL(fontSizeChanged(
int)),
355 SLOT(slotSizeAction(
int)) );
358 connect( mReaderWin->
viewer(), SIGNAL(popupMenu(Akonadi::Item,KUrl,KUrl,QPoint)),
359 this, SLOT(slotMessagePopup(Akonadi::Item,KUrl,KUrl,QPoint)) );
361 connect( mReaderWin->
viewer(), SIGNAL(itemRemoved()),
362 this, SLOT(close()) );
364 setStandardToolBarMenuEnabled(
true);
365 KStandardAction::configureToolbars(
this, SLOT(slotEditToolbars()), actionCollection());
366 connect( mReaderWin->
viewer(), SIGNAL(moveMessageToTrash()),
this, SLOT(slotTrashMsg()) );
370 KAction *KMReaderMainWin::copyActionMenu(
QMenu *menu)
375 KActionMenu *action =
new KActionMenu( menu );
376 action->setIcon( KIcon( QLatin1String(
"edit-copy")) );
377 action->setText( i18n(
"Copy Item To...") );
378 mainwin->
standardMailActionManager()->standardActionManager()->createActionFolderMenu( action->menu(), Akonadi::StandardActionManager::CopyItemToMenu );
379 connect( action->menu(), SIGNAL(triggered(QAction*)), SLOT(slotCopyItem(QAction*)) );
387 void KMReaderMainWin::slotCopyItem(QAction*action)
391 const QModelIndex index = action->data().value<QModelIndex>();
392 const Akonadi::Collection collection = index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
394 if ( mMsg.isValid() ) {
395 Akonadi::ItemCopyJob *job =
new Akonadi::ItemCopyJob( mMsg, collection,
this );
396 connect( job, SIGNAL(result(
KJob*)),
this, SLOT(slotCopyResult(
KJob*)) );
400 Akonadi::ItemCreateJob *job =
new Akonadi::ItemCreateJob( mMsg, collection,
this );
401 connect( job, SIGNAL(result(
KJob*)),
this, SLOT(slotCopyResult(
KJob*)) );
406 void KMReaderMainWin::slotCopyResult(
KJob * job )
408 if ( job->error() ) {
409 KMessageBox::sorry(
this, i18n(
"Cannot copy item. %1", job->errorString() ) );
413 void KMReaderMainWin::slotMessagePopup(
const Akonadi::Item&aMsg ,
const KUrl&aUrl,
const KUrl&imageUrl,
const QPoint& aPoint)
417 const QString
email = KPIMUtils::firstEmailAddress( aUrl.path() ).toLower();
418 if ( aUrl.protocol() == QLatin1String(
"mailto") && !email.isEmpty()) {
419 Akonadi::ContactSearchJob *job =
new Akonadi::ContactSearchJob(
this );
421 job->setQuery( Akonadi::ContactSearchJob::Email, email, Akonadi::ContactSearchJob::ExactMatch );
422 job->setProperty(
"msg", QVariant::fromValue( mMsg ) );
423 job->setProperty(
"point", aPoint );
424 job->setProperty(
"imageUrl", imageUrl );
425 job->setProperty(
"url", aUrl );
426 connect( job, SIGNAL(result(
KJob*)), SLOT(slotContactSearchJobForMessagePopupDone(
KJob*)) );
432 void KMReaderMainWin::slotContactSearchJobForMessagePopupDone(
KJob *job )
434 const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
435 const bool contactAlreadyExists = !searchJob->contacts().isEmpty();
438 const bool uniqueContactFound = (listContact.count() == 1);
439 if(uniqueContactFound) {
440 mReaderWin->
setContactItem(listContact.first(), searchJob->contacts().at(0));
445 const Akonadi::Item msg = job->property(
"msg" ).value<Akonadi::Item>();
446 const QPoint aPoint = job->property(
"point" ).toPoint();
447 const KUrl imageUrl = job->property(
"imageUrl").value<KUrl>();
448 const KUrl url = job->property(
"url").value<KUrl>();
450 showMessagePopup(msg, url, imageUrl, aPoint, contactAlreadyExists, uniqueContactFound);
457 bool urlMenuAdded =
false;
458 bool copyAdded =
false;
459 const bool messageHasPayload = msg.hasPayload<KMime::Message::Ptr>();
460 if ( !url.isEmpty() ) {
461 if ( url.protocol() == QLatin1String(
"mailto" ) ) {
465 if ( messageHasPayload ) {
468 menu->addSeparator();
471 if ( contactAlreadyExists ) {
472 if(uniqueContactFound) {
480 menu->addSeparator();
482 menu->addSeparator();
486 }
else if( url.protocol() != QLatin1String(
"attachment" ) ){
495 menu->addSeparator();
498 if(!imageUrl.isEmpty()) {
499 menu->addSeparator();
504 menu->addSeparator();
511 const QString selectedText(mReaderWin->
copyText());
512 if ( !selectedText.isEmpty() ) {
515 if ( urlMenuAdded ) {
516 menu->addSeparator();
518 if(messageHasPayload) {
519 menu->addAction( mMsgActions->
replyMenu() );
520 menu->addSeparator();
525 menu->addSeparator();
527 menu->addSeparator();
529 menu->addSeparator();
531 }
else if ( !urlMenuAdded ) {
536 if (messageHasPayload) {
537 bool replyForwardMenu =
false;
538 Akonadi::Collection col = parentCollection();
539 if ( col.isValid() ) {
540 if ( ! ( CommonKernel->folderIsSentMailFolder( col ) ||
541 CommonKernel->folderIsDrafts( col ) ||
542 CommonKernel->folderIsTemplates( col ) ) ) {
543 replyForwardMenu =
true;
545 }
else if ( messageHasPayload ) {
546 replyForwardMenu =
true;
548 if ( replyForwardMenu ) {
551 menu->addAction( mMsgActions->
replyMenu() );
553 menu->addSeparator();
555 menu->addAction( copyActionMenu(menu) );
557 menu->addSeparator();
558 if(!imageUrl.isEmpty()) {
559 menu->addSeparator();
563 menu->addSeparator();
566 menu->addSeparator();
573 menu->addSeparator();
577 menu->addAction( mSaveAtmAction );
578 if ( msg.isValid() ) {
579 menu->addSeparator();
581 menu->addSeparator();
590 menu->addSeparator();
595 KAcceleratorManager::manage(menu);
596 menu->exec( aPoint, 0 );
601 void KMReaderMainWin::slotFontAction(
const QString& font)
603 QFont f( mReaderWin->
cssHelper()->bodyFont() );
605 mReaderWin->
cssHelper()->setBodyFont( f );
606 mReaderWin->
cssHelper()->setPrintFont( f );
610 void KMReaderMainWin::slotSizeAction(
int size )
612 QFont f( mReaderWin->
cssHelper()->bodyFont() );
613 f.setPointSize( size );
614 mReaderWin->
cssHelper()->setBodyFont( f );
615 mReaderWin->
cssHelper()->setPrintFont( f );
619 void KMReaderMainWin::slotEditToolbars()
621 saveMainWindowSettings( KConfigGroup(
KMKernel::self()->config(),
"ReaderWindow") );
622 KEditToolBar dlg( guiFactory(),
this );
623 connect( &dlg, SIGNAL(newToolBarConfig()), SLOT(slotUpdateToolbars()) );
627 void KMReaderMainWin::slotUpdateToolbars()
629 createGUI(QLatin1String(
"kmreadermainwin.rc"));
630 applyMainWindowSettings( KConfigGroup(
KMKernel::self()->config(),
"ReaderWindow") );
634 #include "kmreadermainwin.moc"
void addWebShortcutsMenu(KMenu *menu, const QString &text)
void showMessage(const QString &encoding, const Akonadi::Item &msg, const Akonadi::Collection &parentCollection=Akonadi::Collection())
take ownership of and show
KAction * urlOpenAction() const
This class implements a "reader window", that is a window used for reading or viewing messages...
KAction * blockImage() const
KAction * copyURLAction() const
MessageViewer::Viewer * viewer()
KMReaderMainWin(bool htmlOverride, bool htmlLoadExtOverride, char *name=0)
virtual void setCaption(const QString &caption)
Reimplement because we have this bug #Bug 163978.
KMenu * viewHtmlOption() const
Manages common actions that can be performed on one or more messages.
bool isAShortUrl(const KUrl &url) const
KAction * mailToComposeAction() const
KAction * saveAsAction() const
KAction * mailToReplyAction() const
Akonadi::Item message() const
static KMKernel * self()
normal control stuff
void setupForwardingActionsList(KXMLGUIClient *guiClient)
Sets up action list for forward menu.
void setOverrideEncoding(const QString &encoding)
Set the override character encoding.
void setContactItem(const Akonadi::Item &contact, const KABC::Addressee &address)
MessageViewer::CSSHelper * cssHelper() const
KAction * expandShortUrlAction() const
KAction * copyImageLocation() const
KAction * openAddrBookAction() const
void update(bool force=false)
KAction * printPreviewAction() const
Small helper structure which encapsulates the KMMessage created when creating a reply, and.
void setDecryptMessageOverwrite(bool overwrite=true)
Enforce message decryption.
KAction * viewSourceAction() const
void showMessagePopup(const Akonadi::Item &msg, const KUrl &aUrl, const KUrl &imageUrl, const QPoint &aPoint, bool contactAlreadyExists, bool uniqueContactFound)
void setMsgPart(KMime::Content *aMsgPart)
Instead of settings a message to be shown sets a message part to be shown.
KAction * translateAction() const
void setHtmlOverride(bool override)
void setHtmlLoadExtOverride(bool override)
void setMessage(const Akonadi::Item &item, MessageViewer::Viewer::UpdateMode updateMode=MessageViewer::Viewer::Delayed)
KActionMenu * forwardMenu() const
KAction * resetMessageDisplayFormatAction() const
void setCurrentMessage(const Akonadi::Item &item, const Akonadi::Item::List &items=Akonadi::Item::List())
KAction * downloadImageToDiskAction() const
bool adblockEnabled() const
KAction * shareImage() const
KAction * createTodoAction() const
KAction * urlSaveAsAction() const
KAction * saveMessageDisplayFormatAction() const
KAction * copyAction() const
static GlobalSettings * self()
KToggleAction * toggleFixFontAction() const
KAction * addAddrBookAction() const
KActionMenu * replyMenu() const
KAction * editContactAction() const
void setMessageView(KMReaderWin *msgView)
QString copyText() const
Return selected text.
KAction * addBookmarksAction() const
KAction * openBlockableItems() const
KAction * toggleMimePartTreeAction() const
KAction * mailToForwardAction() const
void setUseFixedFont(bool useFixedFont)
KAction * printAction() const
void setUseFixedFont(bool useFixedFont)
virtual ~KMReaderMainWin()
KAction * selectAllAction() const
Akonadi::StandardMailActionManager * standardMailActionManager() const
void setupForwardActions()
This function adds or updates the actions of the forward action menu, taking the preference whether t...
KAction * speakTextAction() const