• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
messageactions.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include "messageactions.h"
20 
21 #include "settings/globalsettings.h"
22 #include "kmreaderwin.h"
23 #include "kmkernel.h"
24 #include "kernel/mailkernel.h"
25 #include "kmmainwidget.h"
26 #include "util.h"
27 #include "kmcommands.h"
28 #include "customtemplatesmenu.h"
29 
30 #include "messagecore/widgets/annotationdialog.h"
31 #include "messagecore/settings/globalsettings.h"
32 #include "messagecore/misc/mailinglist.h"
33 #include "messagecore/helpers/messagehelpers.h"
34 #include "messageviewer/viewer/csshelper.h"
35 #include "messageviewer/settings/globalsettings.h"
36 
37 #include "pimcommon/baloodebug/baloodebugdialog.h"
38 
39 #include "followupreminder/followupreminderselectdatedialog.h"
40 #include "job/createfollowupreminderonexistingmessagejob.h"
41 
42 #include <akonadi/itemfetchjob.h>
43 #include <akonadi/kmime/messageparts.h>
44 #include <Akonadi/ChangeRecorder>
45 #include <KAction>
46 #include <KActionMenu>
47 #include <KActionCollection>
48 #include <KDebug>
49 #include <KLocalizedString>
50 #include <KXMLGUIClient>
51 #include <KStandardDirs>
52 #include <KRun>
53 #include <KMenu>
54 #include <KUriFilterData>
55 #include <KToolInvocation>
56 #include <KUriFilter>
57 #include <KStringHandler>
58 #include <KPrintPreview>
59 
60 #include <QVariant>
61 #include <qwidget.h>
62 #include <akonadi/collection.h>
63 #include <akonadi/entityannotationsattribute.h>
64 #include <util/mailutil.h>
65 
66 using namespace KMail;
67 
68 MessageActions::MessageActions( KActionCollection *ac, QWidget *parent )
69  : QObject( parent ),
70  mParent( parent ),
71  mMessageView( 0 ),
72  mRedirectAction( 0 ),
73  mPrintPreviewAction( 0 ),
74  mCustomTemplatesMenu( 0 ),
75  mAddFollowupReminderAction( 0 ),
76  mDebugBalooAction(0)
77 {
78  mReplyActionMenu = new KActionMenu( KIcon(QLatin1String("mail-reply-sender")), i18nc("Message->","&Reply"), this );
79  ac->addAction( QLatin1String("message_reply_menu"), mReplyActionMenu );
80  connect( mReplyActionMenu, SIGNAL(triggered(bool)),
81  this, SLOT(slotReplyToMsg()) );
82 
83  mReplyAction = new KAction( KIcon(QLatin1String("mail-reply-sender")), i18n("&Reply..."), this );
84  ac->addAction( QLatin1String("reply"), mReplyAction );
85  mReplyAction->setShortcut(Qt::Key_R);
86  connect( mReplyAction, SIGNAL(triggered(bool)),
87  this, SLOT(slotReplyToMsg()) );
88  mReplyActionMenu->addAction( mReplyAction );
89 
90  mReplyAuthorAction = new KAction( KIcon(QLatin1String("mail-reply-sender")), i18n("Reply to A&uthor..."), this );
91  ac->addAction( QLatin1String("reply_author"), mReplyAuthorAction );
92  mReplyAuthorAction->setShortcut(Qt::SHIFT+Qt::Key_A);
93  connect( mReplyAuthorAction, SIGNAL(triggered(bool)),
94  this, SLOT(slotReplyAuthorToMsg()) );
95  mReplyActionMenu->addAction( mReplyAuthorAction );
96 
97  mReplyAllAction = new KAction( KIcon(QLatin1String("mail-reply-all")), i18n("Reply to &All..."), this );
98  ac->addAction( QLatin1String("reply_all"), mReplyAllAction );
99  mReplyAllAction->setShortcut( Qt::Key_A );
100  connect( mReplyAllAction, SIGNAL(triggered(bool)),
101  this, SLOT(slotReplyAllToMsg()) );
102  mReplyActionMenu->addAction( mReplyAllAction );
103 
104  mReplyListAction = new KAction( KIcon(QLatin1String("mail-reply-list")), i18n("Reply to Mailing-&List..."), this );
105  ac->addAction( QLatin1String("reply_list"), mReplyListAction );
106  mReplyListAction->setShortcut( Qt::Key_L );
107  connect( mReplyListAction, SIGNAL(triggered(bool)),
108  this, SLOT(slotReplyListToMsg()) );
109  mReplyActionMenu->addAction( mReplyListAction );
110 
111  mNoQuoteReplyAction = new KAction( i18n("Reply Without &Quote..."), this );
112  ac->addAction(QLatin1String("noquotereply"), mNoQuoteReplyAction );
113  mNoQuoteReplyAction->setShortcut( Qt::SHIFT+Qt::Key_R );
114  connect( mNoQuoteReplyAction, SIGNAL(triggered(bool)),
115  this, SLOT(slotNoQuoteReplyToMsg()) );
116 
117 
118  mListFilterAction = new KAction(i18n("Filter on Mailing-&List..."), this);
119  ac->addAction(QLatin1String("mlist_filter"), mListFilterAction );
120  connect(mListFilterAction, SIGNAL(triggered(bool)), SLOT(slotMailingListFilter()));
121 
122  mStatusMenu = new KActionMenu ( i18n( "Mar&k Message" ), this );
123  ac->addAction( QLatin1String("set_status"), mStatusMenu );
124 
125 
126  KMMainWidget* mainwin = kmkernel->getKMMainWidget();
127  if ( mainwin ) {
128  KAction * action = mainwin->akonadiStandardAction( Akonadi::StandardMailActionManager::MarkMailAsRead );
129  mStatusMenu->addAction( action );
130 
131  action = mainwin->akonadiStandardAction( Akonadi::StandardMailActionManager::MarkMailAsUnread );
132  mStatusMenu->addAction( action );
133 
134  mStatusMenu->addSeparator();
135  action = mainwin->akonadiStandardAction( Akonadi::StandardMailActionManager::MarkMailAsImportant );
136  mStatusMenu->addAction( action );
137 
138  action = mainwin->akonadiStandardAction( Akonadi::StandardMailActionManager::MarkMailAsActionItem );
139  mStatusMenu->addAction( action );
140 
141  }
142 
143  mEditAction = new KAction( KIcon(QLatin1String("accessories-text-editor")), i18n("&Edit Message"), this );
144  ac->addAction( QLatin1String("edit"), mEditAction );
145  connect( mEditAction, SIGNAL(triggered(bool)),
146  this, SLOT(editCurrentMessage()) );
147  mEditAction->setShortcut( Qt::Key_T );
148 
149  mAnnotateAction = new KAction( KIcon( QLatin1String("view-pim-notes") ), i18n( "Add Note..."), this );
150  ac->addAction( QLatin1String("annotate"), mAnnotateAction );
151  connect( mAnnotateAction, SIGNAL(triggered(bool)),
152  this, SLOT(annotateMessage()) );
153 
154  mPrintAction = KStandardAction::print( this, SLOT(slotPrintMsg()), ac );
155  if(KPrintPreview::isAvailable())
156  mPrintPreviewAction = KStandardAction::printPreview( this, SLOT(slotPrintPreviewMsg()), ac );
157 
158  mForwardActionMenu = new KActionMenu(KIcon(QLatin1String("mail-forward")), i18nc("Message->","&Forward"), this);
159  ac->addAction(QLatin1String("message_forward"), mForwardActionMenu );
160 
161  mForwardAttachedAction = new KAction( KIcon(QLatin1String("mail-forward")),
162  i18nc( "@action:inmenu Message->Forward->",
163  "As &Attachment..." ),
164  this );
165  connect( mForwardAttachedAction, SIGNAL(triggered(bool)),
166  parent, SLOT(slotForwardAttachedMsg()) );
167  ac->addAction( QLatin1String("message_forward_as_attachment"), mForwardAttachedAction );
168 
169  mForwardInlineAction = new KAction( KIcon( QLatin1String("mail-forward") ),
170  i18nc( "@action:inmenu Message->Forward->",
171  "&Inline..." ),
172  this );
173  connect( mForwardInlineAction, SIGNAL(triggered(bool)),
174  parent, SLOT(slotForwardInlineMsg()) );
175  ac->addAction( QLatin1String("message_forward_inline"), mForwardInlineAction );
176 
177  setupForwardActions();
178 
179  mRedirectAction = new KAction(i18nc("Message->Forward->", "&Redirect..."), this );
180  ac->addAction( QLatin1String("message_forward_redirect"), mRedirectAction );
181  connect( mRedirectAction, SIGNAL(triggered(bool)),
182  parent, SLOT(slotRedirectMsg()) );
183  mRedirectAction->setShortcut( QKeySequence( Qt::Key_E ) );
184  mForwardActionMenu->addAction( mRedirectAction );
185 
186  //FIXME add KIcon("mail-list") as first arguement. Icon can be derived from
187  // mail-reply-list icon by removing top layers off svg
188  mMailingListActionMenu = new KActionMenu( i18nc( "Message->", "Mailing-&List" ), this );
189  connect( mMailingListActionMenu->menu(), SIGNAL(triggered(QAction*)),
190  this, SLOT(slotRunUrl(QAction*)) );
191  ac->addAction( QLatin1String("mailing_list"), mMailingListActionMenu );
192  mMailingListActionMenu->setEnabled(false);
193 
194  connect( kmkernel->folderCollectionMonitor(), SIGNAL(itemChanged(Akonadi::Item,QSet<QByteArray>)), SLOT(slotItemModified(Akonadi::Item,QSet<QByteArray>)));
195  connect( kmkernel->folderCollectionMonitor(), SIGNAL(itemRemoved(Akonadi::Item)), SLOT(slotItemRemoved(Akonadi::Item)));
196 
197  mCustomTemplatesMenu = new TemplateParser::CustomTemplatesMenu( parent, ac );
198 
199  connect( mCustomTemplatesMenu, SIGNAL(replyTemplateSelected(QString)),
200  parent, SLOT(slotCustomReplyToMsg(QString)) );
201  connect( mCustomTemplatesMenu, SIGNAL(replyAllTemplateSelected(QString)),
202  parent, SLOT(slotCustomReplyAllToMsg(QString)) );
203  connect( mCustomTemplatesMenu, SIGNAL(forwardTemplateSelected(QString)),
204  parent, SLOT(slotCustomForwardMsg(QString)) );
205  connect( KMKernel::self(), SIGNAL(customTemplatesChanged()), mCustomTemplatesMenu, SLOT(update()) );
206 
207  forwardMenu()->addSeparator();
208  forwardMenu()->addAction( mCustomTemplatesMenu->forwardActionMenu() );
209  replyMenu()->addSeparator();
210  replyMenu()->addAction( mCustomTemplatesMenu->replyActionMenu() );
211  replyMenu()->addAction( mCustomTemplatesMenu->replyAllActionMenu() );
212 
213  //Don't translate it. Shown only when we set env variable KDEPIM_BALOO_DEBUG
214  mDebugBalooAction = new QAction(QLatin1String("Debug Baloo..."), this);
215  connect( mDebugBalooAction, SIGNAL(triggered(bool)), this, SLOT(slotDebugBaloo()) );
216 
217  mAddFollowupReminderAction = new KAction(i18n("Add Followup Reminder..."), this );
218  ac->addAction( QLatin1String("message_followup_reminder"), mAddFollowupReminderAction );
219  connect( mAddFollowupReminderAction, SIGNAL(triggered(bool)),this, SLOT(slotAddFollowupReminder()) );
220 
221  updateActions();
222 }
223 
224 MessageActions::~MessageActions()
225 {
226  delete mCustomTemplatesMenu;
227 }
228 
229 TemplateParser::CustomTemplatesMenu* MessageActions::customTemplatesMenu() const
230 {
231  return mCustomTemplatesMenu;
232 }
233 
234 void MessageActions::setCurrentMessage( const Akonadi::Item &msg, const Akonadi::Item::List &items )
235 {
236  mCurrentItem = msg;
237 
238  if (!items.isEmpty()) {
239  if (msg.isValid()) {
240  mVisibleItems = items;
241  } else {
242  mVisibleItems.clear();
243  }
244  }
245 
246  if ( !msg.isValid() ) {
247  mVisibleItems.clear();
248  clearMailingListActions();
249  }
250 
251  updateActions();
252 }
253 
254 void MessageActions::slotItemRemoved(const Akonadi::Item& item)
255 {
256  if ( item == mCurrentItem ) {
257  mCurrentItem = Akonadi::Item();
258  updateActions();
259  }
260 }
261 
262 void MessageActions::slotItemModified( const Akonadi::Item & item, const QSet< QByteArray > & partIdentifiers )
263 {
264  Q_UNUSED( partIdentifiers );
265  if ( item == mCurrentItem ) {
266  mCurrentItem = item;
267  const int numberOfVisibleItems = mVisibleItems.count();
268  for ( int i = 0; i < numberOfVisibleItems; ++i ) {
269  Akonadi::Item it = mVisibleItems.at(i);
270  if ( item == it ) {
271  mVisibleItems[i] = item;
272  }
273  }
274  updateActions();
275  }
276 }
277 
278 void MessageActions::updateActions()
279 {
280  const bool hasPayload = mCurrentItem.hasPayload<KMime::Message::Ptr>();
281  bool itemValid = mCurrentItem.isValid();
282  Akonadi::Collection parent;
283  if ( itemValid ) //=> valid
284  parent = mCurrentItem.parentCollection();
285  if ( parent.isValid() ) {
286  if ( CommonKernel->folderIsTemplates(parent) )
287  itemValid = false;
288  }
289 
290  const bool multiVisible = mVisibleItems.count() > 0 || mCurrentItem.isValid();
291  const bool uniqItem = ( itemValid||hasPayload ) && ( mVisibleItems.count()<=1 );
292  mReplyActionMenu->setEnabled( hasPayload );
293  mReplyAction->setEnabled( hasPayload );
294  mNoQuoteReplyAction->setEnabled( hasPayload );
295  mReplyAuthorAction->setEnabled( hasPayload );
296  mReplyAllAction->setEnabled( hasPayload );
297  mReplyListAction->setEnabled( hasPayload );
298  mNoQuoteReplyAction->setEnabled( hasPayload );
299 
300  mAnnotateAction->setEnabled( uniqItem );
301  if ( !mCurrentItem.hasAttribute<Akonadi::EntityAnnotationsAttribute>() )
302  mAnnotateAction->setText( i18n( "Add Note..." ) );
303  else
304  mAnnotateAction->setText( i18n( "Edit Note...") );
305 
306  mStatusMenu->setEnabled( multiVisible );
307 
308  if ( mCurrentItem.hasPayload<KMime::Message::Ptr>() ) {
309  if ( mCurrentItem.loadedPayloadParts().contains("RFC822") ) {
310  updateMailingListActions( mCurrentItem );
311  } else {
312  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mCurrentItem );
313  job->fetchScope().fetchAllAttributes();
314  job->fetchScope().fetchFullPayload( true );
315  job->fetchScope().fetchPayloadPart( Akonadi::MessagePart::Header );
316  job->fetchScope().fetchAttribute<Akonadi::EntityAnnotationsAttribute>();
317  connect( job, SIGNAL(result(KJob*)), SLOT(slotUpdateActionsFetchDone(KJob*)) );
318  }
319  }
320  mEditAction->setEnabled( uniqItem );
321 }
322 
323 void MessageActions::slotUpdateActionsFetchDone(KJob* job)
324 {
325  if ( job->error() )
326  return;
327 
328  Akonadi::ItemFetchJob *fetchJob = static_cast<Akonadi::ItemFetchJob*>( job );
329  if ( fetchJob->items().isEmpty() )
330  return;
331  Akonadi::Item messageItem = fetchJob->items().first();
332  if ( messageItem == mCurrentItem ) {
333  mCurrentItem = messageItem;
334  updateMailingListActions( messageItem );
335  }
336 }
337 
338 void MessageActions::clearMailingListActions()
339 {
340  mMailingListActionMenu->setEnabled( false );
341  mListFilterAction->setEnabled( false );
342  mListFilterAction->setText( i18n("Filter on Mailing-List...") );
343 }
344 
345 void MessageActions::updateMailingListActions( const Akonadi::Item& messageItem )
346 {
347  KMime::Message::Ptr message = messageItem.payload<KMime::Message::Ptr>();
348  const MessageCore::MailingList mailList = MessageCore::MailingList::detect( message );
349 
350  if ( mailList.features() == MessageCore::MailingList::None ) {
351  clearMailingListActions();
352  } else {
353  // A mailing list menu with only a title is pretty boring
354  // so make sure theres at least some content
355  QString listId;
356  if ( mailList.features() & MessageCore::MailingList::Id ) {
357  // From a list-id in the form, "Birds of France <bof.yahoo.com>",
358  // take "Birds of France" if it exists otherwise "bof.yahoo.com".
359  listId = mailList.id();
360  const int start = listId.indexOf( QLatin1Char( '<' ) );
361  if ( start > 0 ) {
362  listId.truncate( start - 1 );
363  } else if ( start == 0 ) {
364  const int end = listId.lastIndexOf( QLatin1Char( '>' ) );
365  if ( end < 1 ) { // shouldn't happen but account for it anyway
366  listId.remove( 0, 1 );
367  } else {
368  listId = listId.mid( 1, end-1 );
369  }
370  }
371  }
372  mMailingListActionMenu->menu()->clear();
373  qDeleteAll(mMailListActionList);
374  mMailListActionList.clear();
375  if ( !listId.isEmpty() )
376  mMailingListActionMenu->menu()->addTitle( listId );
377 
378  if ( mailList.features() & MessageCore::MailingList::ArchivedAt )
379  // IDEA: this may be something you want to copy - "Copy in submenu"?
380  addMailingListActions( i18n( "Open Message in List Archive" ), mailList.archivedAtUrls() );
381  if ( mailList.features() & MessageCore::MailingList::Post )
382  addMailingListActions( i18n( "Post New Message" ), mailList.postUrls() );
383  if ( mailList.features() & MessageCore::MailingList::Archive )
384  addMailingListActions( i18n( "Go to Archive" ), mailList.archiveUrls() );
385  if ( mailList.features() & MessageCore::MailingList::Help )
386  addMailingListActions( i18n( "Request Help" ), mailList.helpUrls() );
387  if ( mailList.features() & MessageCore::MailingList::Owner )
388  addMailingListActions( i18nc( "Contact the owner of the mailing list", "Contact Owner" ), mailList.ownerUrls() );
389  if ( mailList.features() & MessageCore::MailingList::Subscribe )
390  addMailingListActions( i18n( "Subscribe to List" ), mailList.subscribeUrls() );
391  if ( mailList.features() & MessageCore::MailingList::Unsubscribe )
392  addMailingListActions( i18n( "Unsubscribe from List" ), mailList.unsubscribeUrls() );
393  mMailingListActionMenu->setEnabled( true );
394 
395  QByteArray name;
396  QString value;
397  const QString lname = MailingList::name( message, name, value );
398  if ( !lname.isEmpty() ) {
399  mListFilterAction->setEnabled( true );
400  mListFilterAction->setText( i18n( "Filter on Mailing-List %1...", lname ) );
401  }
402  }
403 }
404 
405 
406 void MessageActions::replyCommand(MessageComposer::ReplyStrategy strategy)
407 {
408  if ( !mCurrentItem.hasPayload<KMime::Message::Ptr>() ) return;
409 
410  const QString text = mMessageView ? mMessageView->copyText() : QString();
411  KMCommand *command = new KMReplyCommand( mParent, mCurrentItem, strategy, text );
412  connect( command, SIGNAL(completed(KMCommand*)),
413  this, SIGNAL(replyActionFinished()) );
414  command->start();
415 }
416 
417 void MessageActions::setMessageView(KMReaderWin * msgView)
418 {
419  mMessageView = msgView;
420 }
421 
422 void MessageActions::setupForwardActions()
423 {
424  disconnect( mForwardActionMenu, SIGNAL(triggered(bool)), 0, 0 );
425  mForwardActionMenu->removeAction( mForwardInlineAction );
426  mForwardActionMenu->removeAction( mForwardAttachedAction );
427 
428  if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
429  mForwardActionMenu->insertAction( mRedirectAction, mForwardInlineAction );
430  mForwardActionMenu->insertAction( mRedirectAction, mForwardAttachedAction );
431  mForwardInlineAction->setShortcut(QKeySequence(Qt::Key_F));
432  mForwardAttachedAction->setShortcut(QKeySequence(Qt::SHIFT+Qt::Key_F));
433  QObject::connect( mForwardActionMenu, SIGNAL(triggered(bool)),
434  mParent, SLOT(slotForwardInlineMsg()) );
435  } else {
436  mForwardActionMenu->insertAction( mRedirectAction, mForwardAttachedAction );
437  mForwardActionMenu->insertAction( mRedirectAction, mForwardInlineAction );
438  mForwardInlineAction->setShortcut(QKeySequence(Qt::Key_F));
439  mForwardAttachedAction->setShortcut(QKeySequence(Qt::SHIFT+Qt::Key_F));
440  QObject::connect( mForwardActionMenu, SIGNAL(triggered(bool)),
441  mParent, SLOT(slotForwardAttachedMsg()) );
442  }
443 }
444 
445 void MessageActions::setupForwardingActionsList( KXMLGUIClient *guiClient )
446 {
447  QList<QAction*> forwardActionList;
448  guiClient->unplugActionList( QLatin1String("forward_action_list") );
449  if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
450  forwardActionList.append( mForwardInlineAction );
451  forwardActionList.append( mForwardAttachedAction );
452  } else {
453  forwardActionList.append( mForwardAttachedAction );
454  forwardActionList.append( mForwardInlineAction );
455  }
456  forwardActionList.append( mRedirectAction );
457  guiClient->plugActionList( QLatin1String("forward_action_list"), forwardActionList );
458 }
459 
460 
461 void MessageActions::slotReplyToMsg()
462 {
463  replyCommand( MessageComposer::ReplySmart );
464 }
465 
466 void MessageActions::slotReplyAuthorToMsg()
467 {
468  replyCommand( MessageComposer::ReplyAuthor );
469 }
470 
471 void MessageActions::slotReplyListToMsg()
472 {
473  replyCommand( MessageComposer::ReplyList );
474 }
475 
476 void MessageActions::slotReplyAllToMsg()
477 {
478  replyCommand( MessageComposer::ReplyAll );
479 }
480 
481 void MessageActions::slotNoQuoteReplyToMsg()
482 {
483  if ( !mCurrentItem.hasPayload<KMime::Message::Ptr>() )
484  return;
485  KMCommand *command = new KMReplyCommand( mParent, mCurrentItem, MessageComposer::ReplySmart, QString(), true );
486  command->start();
487 }
488 
489 void MessageActions::slotRunUrl( QAction *urlAction )
490 {
491  const QVariant q = urlAction->data();
492  if ( q.type() == QVariant::String ) {
493  new KRun( KUrl( q.toString() ) , mParent );
494  }
495 }
496 
497 void MessageActions::slotMailingListFilter()
498 {
499  if ( !mCurrentItem.hasPayload<KMime::Message::Ptr>() )
500  return;
501 
502  KMCommand *command = new KMMailingListFilterCommand( mParent, mCurrentItem );
503  command->start();
504 }
505 
506 void MessageActions::printMessage(bool preview)
507 {
508  bool result = false;
509  if ( mMessageView ) {
510  if (MessageViewer::GlobalSettings::self()->printSelectedText()) {
511  result = mMessageView->printSelectedText(preview);
512  }
513  }
514  if (!result) {
515  const bool useFixedFont = MessageViewer::GlobalSettings::self()->useFixedFont();
516  const QString overrideEncoding = MessageCore::GlobalSettings::self()->overrideCharacterEncoding();
517 
518  const Akonadi::Item message = mCurrentItem;
519  KMPrintCommand *command =
520  new KMPrintCommand( mParent, message,
521  mMessageView->viewer()->headerStyle(), mMessageView->viewer()->headerStrategy(),
522  mMessageView->viewer()->displayFormatMessageOverwrite(), mMessageView->viewer()->htmlLoadExternal(),
523  useFixedFont, overrideEncoding );
524  command->setPrintPreview(preview);
525  command->start();
526  }
527 }
528 
529 void MessageActions::slotPrintPreviewMsg()
530 {
531  printMessage(true);
532 }
533 
534 void MessageActions::slotPrintMsg()
535 {
536  printMessage(false);
537 }
538 
547 void MessageActions::addMailingListActions( const QString &item, const KUrl::List &list )
548 {
549  foreach ( const KUrl& url, list ) {
550  addMailingListAction( item, url );
551  }
552 }
553 
558 void MessageActions::addMailingListAction( const QString &item, const KUrl &url )
559 {
560  QString protocol = url.protocol().toLower();
561  QString prettyUrl = url.prettyUrl();
562  if ( protocol == QLatin1String("mailto") ) {
563  protocol = i18n( "email" );
564  prettyUrl.remove( 0, 7 ); // length( "mailto:" )
565  } else if ( protocol.startsWith( QLatin1String( "http" ) ) ) {
566  protocol = i18n( "web" );
567  }
568  // item is a mailing list url description passed from the updateActions method above.
569  KAction *act = new KAction( i18nc( "%1 is a 'Contact Owner' or similar action. %2 is a protocol normally web or email though could be irc/ftp or other url variant", "%1 (%2)", item, protocol ) , this );
570  mMailListActionList.append(act);
571  const QVariant v( url.url() );
572  act->setData( v );
573  act->setHelpText( prettyUrl );
574  mMailingListActionMenu->addAction( act );
575 }
576 
577 void MessageActions::editCurrentMessage()
578 {
579  KMCommand *command = 0;
580  if ( mCurrentItem.isValid() ) {
581  Akonadi::Collection col = mCurrentItem.parentCollection();
582  qDebug()<<" mCurrentItem.parentCollection()"<<mCurrentItem.parentCollection();
583  // edit, unlike send again, removes the message from the folder
584  // we only want that for templates and drafts folders
585  if ( col.isValid()
586  && ( CommonKernel->folderIsDraftOrOutbox( col ) ||
587  CommonKernel->folderIsTemplates( col ) )
588  )
589  command = new KMEditItemCommand( mParent, mCurrentItem, true );
590  else
591  command = new KMEditItemCommand( mParent, mCurrentItem, false );
592  command->start();
593  } else if ( mCurrentItem.hasPayload<KMime::Message::Ptr>() ) {
594  command = new KMEditMessageCommand( mParent, mCurrentItem.payload<KMime::Message::Ptr>() );
595  command->start();
596  }
597 }
598 
599 void MessageActions::annotateMessage()
600 {
601  if ( !mCurrentItem.isValid() )
602  return;
603 
604  MessageCore::AnnotationEditDialog *dialog = new MessageCore::AnnotationEditDialog( mCurrentItem );
605  dialog->setAttribute( Qt::WA_DeleteOnClose );
606  dialog->exec();
607 }
608 
609 void MessageActions::addWebShortcutsMenu( KMenu *menu, const QString & text )
610 {
611  if ( text.isEmpty() )
612  return;
613 
614  QString searchText = text;
615  searchText = searchText.replace( QLatin1Char('\n'), QLatin1Char(' ') ).replace( QLatin1Char('\r'), QLatin1Char(' ') ).simplified();
616 
617  if ( searchText.isEmpty() )
618  return;
619 
620  KUriFilterData filterData( searchText );
621 
622  filterData.setSearchFilteringOptions( KUriFilterData::RetrievePreferredSearchProvidersOnly );
623 
624  if ( KUriFilter::self()->filterSearchUri( filterData, KUriFilter::NormalTextFilter ) ) {
625  const QStringList searchProviders = filterData.preferredSearchProviders();
626 
627  if ( !searchProviders.isEmpty() ) {
628  KMenu *webShortcutsMenu = new KMenu( menu );
629  webShortcutsMenu->setIcon( KIcon( QLatin1String("preferences-web-browser-shortcuts") ) );
630 
631  const QString squeezedText = KStringHandler::rsqueeze( searchText, 21 );
632  webShortcutsMenu->setTitle( i18n( "Search for '%1' with", squeezedText ) );
633 
634  KAction *action = 0;
635 
636  foreach( const QString &searchProvider, searchProviders ) {
637  action = new KAction( searchProvider, webShortcutsMenu );
638  action->setIcon( KIcon( filterData.iconNameForPreferredSearchProvider( searchProvider ) ) );
639  action->setData( filterData.queryForPreferredSearchProvider( searchProvider ) );
640  connect( action, SIGNAL(triggered()), this, SLOT(slotHandleWebShortcutAction()) );
641  webShortcutsMenu->addAction( action );
642  }
643 
644  webShortcutsMenu->addSeparator();
645 
646  action = new KAction( i18n( "Configure Web Shortcuts..." ), webShortcutsMenu );
647  action->setIcon( KIcon( QLatin1String("configure") ) );
648  connect( action, SIGNAL(triggered()), this, SLOT(slotConfigureWebShortcuts()) );
649  webShortcutsMenu->addAction( action );
650 
651  menu->addMenu(webShortcutsMenu);
652  }
653  }
654 }
655 
656 void MessageActions::slotHandleWebShortcutAction()
657 {
658  KAction *action = qobject_cast<KAction*>( sender() );
659 
660  if (action) {
661  KUriFilterData filterData( action->data().toString() );
662  if ( KUriFilter::self()->filterSearchUri( filterData, KUriFilter::WebShortcutFilter ) ) {
663  KToolInvocation::invokeBrowser( filterData.uri().url() );
664  }
665  }
666 }
667 
668 void MessageActions::slotConfigureWebShortcuts()
669 {
670  KToolInvocation::kdeinitExec( QLatin1String("kcmshell4"), QStringList() << QLatin1String("ebrowsing") );
671 }
672 
673 void MessageActions::slotDebugBaloo()
674 {
675  if ( !mCurrentItem.isValid() )
676  return;
677  QPointer<PimCommon::BalooDebugDialog> dlg = new PimCommon::BalooDebugDialog;
678  dlg->setAkonadiId(mCurrentItem.id());
679  dlg->setAttribute( Qt::WA_DeleteOnClose );
680  dlg->setSearchType(PimCommon::BalooDebugSearchPathComboBox::Emails);
681  dlg->doSearch();
682  dlg->show();
683 }
684 
685 void MessageActions::slotAddFollowupReminder()
686 {
687  if (!mCurrentItem.isValid() )
688  return;
689 
690  QPointer<FollowUpReminderSelectDateDialog> dlg = new FollowUpReminderSelectDateDialog;
691  if (dlg->exec()) {
692  const QDate date = dlg->selectedDate();
693  CreateFollowupReminderOnExistingMessageJob *job = new CreateFollowupReminderOnExistingMessageJob(this);
694  job->setDate(date);
695  job->setCollection(dlg->collection());
696  job->setMessageItem(mCurrentItem);
697  job->start();
698  }
699  delete dlg;
700 }
followupreminderselectdatedialog.h
QList::clear
void clear()
KMReplyCommand
Definition: kmcommands.h:319
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
globalsettings.h
QWidget
KMail::MessageActions::addWebShortcutsMenu
void addWebShortcutsMenu(KMenu *menu, const QString &text)
Definition: messageactions.cpp:609
KMail::MessageActions::editCurrentMessage
void editCurrentMessage()
Definition: messageactions.cpp:577
QString::truncate
void truncate(int position)
KMail::MessageActions::replyActionFinished
void replyActionFinished()
kmmainwidget.h
KXMLGUIClient
KMMainWidget::akonadiStandardAction
KAction * akonadiStandardAction(Akonadi::StandardActionManager::Type type)
Definition: kmmainwidget.cpp:4349
KMail::MessageActions::~MessageActions
~MessageActions()
Definition: messageactions.cpp:224
QByteArray
KMReaderWin
This class implements a "reader window", that is a window used for reading or viewing messages...
Definition: kmreaderwin.h:49
KMReaderWin::viewer
MessageViewer::Viewer * viewer()
Definition: kmreaderwin.h:133
text
virtual QByteArray text(quint32 serialNumber) const =0
QObject::sender
QObject * sender() const
date
time_t date() const
QAction::data
QVariant data() const
QPointer
QString::simplified
QString simplified() const
KMMailingListFilterCommand
Definition: kmcommands.h:492
KMail::MessageActions::MessageActions
MessageActions(KActionCollection *ac, QWidget *parent)
Definition: messageactions.cpp:68
QString::remove
QString & remove(int position, int n)
KMail::MessageActions::customTemplatesMenu
TemplateParser::CustomTemplatesMenu * customTemplatesMenu() const
Definition: messageactions.cpp:229
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
createfollowupreminderonexistingmessagejob.h
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1471
kmreaderwin.h
KMail::MessageActions::setupForwardingActionsList
void setupForwardingActionsList(KXMLGUIClient *guiClient)
Sets up action list for forward menu.
Definition: messageactions.cpp:445
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
messageactions.h
CreateFollowupReminderOnExistingMessageJob
Definition: createfollowupreminderonexistingmessagejob.h:26
QObject::name
const char * name() const
QList::append
void append(const T &value)
CreateFollowupReminderOnExistingMessageJob::setCollection
void setCollection(const Akonadi::Collection &collection)
Definition: createfollowupreminderonexistingmessagejob.cpp:115
KMCommand
Small helper structure which encapsulates the KMMessage created when creating a reply, and.
Definition: kmcommands.h:48
FollowUpReminderSelectDateDialog
Definition: followupreminderselectdatedialog.h:28
QObject
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
KMCommand::start
void start()
Definition: kmcommands.cpp:233
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KMMainWidget
Definition: kmmainwidget.h:91
QDate
QSet
KMail::MessageActions::forwardMenu
KActionMenu * forwardMenu() const
Definition: messageactions.h:80
QString
QList< QAction * >
util.h
kmkernel
#define kmkernel
Definition: kmkernel.h:24
QStringList
KMail::MessageActions::setCurrentMessage
void setCurrentMessage(const Akonadi::Item &item, const Akonadi::Item::List &items=Akonadi::Item::List())
Definition: messageactions.cpp:234
QString::toLower
QString toLower() const
CreateFollowupReminderOnExistingMessageJob::start
void start()
Definition: createfollowupreminderonexistingmessagejob.cpp:35
KMail::MessageActions::annotateMessage
void annotateMessage()
Definition: messageactions.cpp:599
QLatin1Char
QString::replace
QString & replace(int position, int n, QChar after)
GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:30
kmkernel.h
KActionMenu
KMail::MessageActions::replyMenu
KActionMenu * replyMenu() const
Definition: messageactions.h:72
QString::mid
QString mid(int position, int n) const
KMPrintCommand::setPrintPreview
void setPrintPreview(bool preview)
Definition: kmcommands.cpp:1114
KMail::MessageActions::setMessageView
void setMessageView(KMReaderWin *msgView)
Definition: messageactions.cpp:417
KMReaderWin::copyText
QString copyText() const
Return selected text.
Definition: kmreaderwin.cpp:455
QLatin1String
QKeySequence
CreateFollowupReminderOnExistingMessageJob::setDate
void setDate(const QDate &date)
Definition: createfollowupreminderonexistingmessagejob.cpp:125
KMReaderWin::printSelectedText
bool printSelectedText(bool preview)
Definition: kmreaderwin.cpp:762
QAction
KMPrintCommand
Definition: kmcommands.h:384
KMEditItemCommand
Definition: kmcommands.h:225
kmcommands.h
QVariant::type
Type type() const
CreateFollowupReminderOnExistingMessageJob::setMessageItem
void setMessageItem(const Akonadi::Item &messageItem)
Definition: createfollowupreminderonexistingmessagejob.cpp:134
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
QVariant::toString
QString toString() const
KJob
KMail::MessageActions::setupForwardActions
void setupForwardActions()
This function adds or updates the actions of the forward action menu, taking the preference whether t...
Definition: messageactions.cpp:422
QVariant
KMEditMessageCommand
Definition: kmcommands.h:239
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal