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

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • editor
attachmentcontroller.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KMail.
3  * Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
4  *
5  * Parts based on KMail code by:
6  * Various authors.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #include "attachmentcontroller.h"
24 
25 #include "attachmentview.h"
26 #include "messagecomposer/job/attachmentfrompublickeyjob.h"
27 #include "foldercollection.h"
28 #include "settings/globalsettings.h"
29 #include "kmcommands.h"
30 #include "editor/kmcomposewin.h"
31 #include "kmkernel.h"
32 #include "kmreadermainwin.h"
33 #include "util/mailutil.h"
34 
35 #include <akonadi/itemfetchjob.h>
36 #include <kabc/addressee.h>
37 #include <kdebug.h>
38 #include <libkleo/kleo/cryptobackendfactory.h>
39 
40 #include <messagecomposer/attachment/attachmentmodel.h>
41 #include <messagecore/attachment/attachmentpart.h>
42 
43 using namespace KMail;
44 using namespace KPIM;
45 using namespace MailCommon;
46 using namespace MessageCore;
47 
48 AttachmentController::AttachmentController( MessageComposer::AttachmentModel *model, AttachmentView *view, KMComposeWin *composer )
49  : AttachmentControllerBase( model, composer, composer->actionCollection() ),
50  mComposer(composer),
51  mView(view)
52 {
53  connect( composer, SIGNAL(identityChanged(KPIMIdentities::Identity)),
54  this, SLOT(identityChanged()) );
55 
56  connect( view, SIGNAL(contextMenuRequested()), this, SLOT(showContextMenu()) );
57  connect( view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
58  this, SLOT(selectionChanged()) );
59  connect( view, SIGNAL(doubleClicked(QModelIndex)),
60  this, SLOT(doubleClicked(QModelIndex)) );
61 
62  connect( this, SIGNAL(refreshSelection()), SLOT(selectionChanged()));
63 
64  connect( this, SIGNAL(showAttachment(KMime::Content*,QByteArray)),
65  SLOT(onShowAttachment(KMime::Content*,QByteArray)));
66  connect( this, SIGNAL(selectedAllAttachment()), SLOT(slotSelectAllAttachment()));
67  connect( model, SIGNAL(attachItemsRequester(Akonadi::Item::List)), this, SLOT(addAttachmentItems(Akonadi::Item::List)) );
68 }
69 
70 AttachmentController::~AttachmentController()
71 {
72 }
73 
74 void AttachmentController::slotSelectAllAttachment()
75 {
76  mView->selectAll();
77 }
78 
79 void AttachmentController::identityChanged()
80 {
81  const KPIMIdentities::Identity &identity = mComposer->identity();
82 
83  // "Attach public key" is only possible if OpenPGP support is available:
84  enableAttachPublicKey( Kleo::CryptoBackendFactory::instance()->openpgp() );
85 
86  // "Attach my public key" is only possible if OpenPGP support is
87  // available and the user specified his key for the current identity:
88  enableAttachMyPublicKey( Kleo::CryptoBackendFactory::instance()->openpgp() && !identity.pgpEncryptionKey().isEmpty() );
89 }
90 
91 void AttachmentController::attachMyPublicKey()
92 {
93  const KPIMIdentities::Identity &identity = mComposer->identity();
94  kDebug() << identity.identityName();
95  exportPublicKey( QString::fromLatin1(identity.pgpEncryptionKey()) );
96 }
97 
98 void AttachmentController::actionsCreated()
99 {
100  // Disable public key actions if appropriate.
101  identityChanged();
102 
103  // Disable actions like 'Remove', since nothing is currently selected.
104  selectionChanged();
105 }
106 
107 void AttachmentController::addAttachmentItems( const Akonadi::Item::List &items )
108 {
109  Akonadi::ItemFetchJob *itemFetchJob = new Akonadi::ItemFetchJob( items, this );
110  itemFetchJob->fetchScope().fetchFullPayload( true );
111  itemFetchJob->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
112  connect( itemFetchJob, SIGNAL(result(KJob*)), mComposer, SLOT(slotFetchJob(KJob*)) );
113 }
114 
115 void AttachmentController::selectionChanged()
116 {
117  const QModelIndexList selectedRows = mView->selectionModel()->selectedRows();
118  AttachmentPart::List selectedParts;
119  foreach( const QModelIndex &index, selectedRows ) {
120  AttachmentPart::Ptr part = mView->model()->data(
121  index, MessageComposer::AttachmentModel::AttachmentPartRole ).value<AttachmentPart::Ptr>();
122  selectedParts.append( part );
123  }
124  setSelectedParts( selectedParts );
125 }
126 
127 void AttachmentController::onShowAttachment( KMime::Content *content, const QByteArray &charset )
128 {
129  KMReaderMainWin *win =
130  new KMReaderMainWin( content, false, QString::fromLatin1(charset) );
131  win->show();
132 }
133 
134 void AttachmentController::doubleClicked( const QModelIndex &itemClicked )
135 {
136  if ( !itemClicked.isValid() ) {
137  kDebug() << "Received an invalid item clicked index";
138  return;
139  }
140  // The itemClicked index will contain the column information. But we want to retrieve
141  // the AttachmentPart, so we must recreate the QModelIndex without the column information
142  const QModelIndex &properItemClickedIndex = mView->model()->index( itemClicked.row(), 0 );
143  AttachmentPart::Ptr part = mView->model()->data(
144  properItemClickedIndex,
145  MessageComposer::AttachmentModel::AttachmentPartRole ).value<AttachmentPart::Ptr>();
146 
147  // We can't edit encapsulated messages, but we can view them.
148  if ( part->isMessageOrMessageCollection() ) {
149  viewAttachment( part );
150  }
151  else {
152  editAttachment( part );
153  }
154 }
155 
156 #include "attachmentcontroller.moc"
globalsettings.h
KMail::AttachmentView
Definition: attachmentview.h:38
KMail::AttachmentController::attachMyPublicKey
void attachMyPublicKey()
Definition: attachmentcontroller.cpp:91
KMComposeWin::identity
const KPIMIdentities::Identity & identity() const
Definition: kmcomposewin.cpp:1956
attachmentview.h
KMComposeWin
Definition: kmcomposewin.h:106
KMail::AttachmentController::AttachmentController
AttachmentController(MessageComposer::AttachmentModel *model, AttachmentView *view, KMComposeWin *composer)
Definition: attachmentcontroller.cpp:48
KMail::AttachmentController::~AttachmentController
~AttachmentController()
Definition: attachmentcontroller.cpp:70
attachmentcontroller.h
kmkernel.h
kmcomposewin.h
KMReaderMainWin
Definition: kmreadermainwin.h:32
kmreadermainwin.h
kmcommands.h
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 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

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