26 #include "messagecomposer/job/attachmentfrompublickeyjob.h"
27 #include "foldercollection.h"
33 #include "util/mailutil.h"
35 #include <akonadi/itemfetchjob.h>
36 #include <kabc/addressee.h>
38 #include <libkleo/kleo/cryptobackendfactory.h>
40 #include <messagecomposer/attachment/attachmentmodel.h>
41 #include <messagecore/attachment/attachmentpart.h>
43 using namespace KMail;
45 using namespace MailCommon;
46 using namespace MessageCore;
49 : AttachmentControllerBase( model, composer, composer->actionCollection() ),
53 connect( composer, SIGNAL(identityChanged(KPIMIdentities::Identity)),
54 this, SLOT(identityChanged()) );
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)) );
62 connect(
this, SIGNAL(refreshSelection()), SLOT(selectionChanged()));
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)) );
74 void AttachmentController::slotSelectAllAttachment()
79 void AttachmentController::identityChanged()
81 const KPIMIdentities::Identity &identity = mComposer->
identity();
84 enableAttachPublicKey( Kleo::CryptoBackendFactory::instance()->openpgp() );
88 enableAttachMyPublicKey( Kleo::CryptoBackendFactory::instance()->openpgp() && !identity.pgpEncryptionKey().isEmpty() );
93 const KPIMIdentities::Identity &identity = mComposer->
identity();
94 kDebug() << identity.identityName();
95 exportPublicKey( QString::fromLatin1(identity.pgpEncryptionKey()) );
98 void AttachmentController::actionsCreated()
107 void AttachmentController::addAttachmentItems(
const Akonadi::Item::List &items )
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*)) );
115 void AttachmentController::selectionChanged()
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 );
124 setSelectedParts( selectedParts );
127 void AttachmentController::onShowAttachment( KMime::Content *content,
const QByteArray &charset )
134 void AttachmentController::doubleClicked(
const QModelIndex &itemClicked )
136 if ( !itemClicked.isValid() ) {
137 kDebug() <<
"Received an invalid item clicked index";
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>();
148 if ( part->isMessageOrMessageCollection() ) {
149 viewAttachment( part );
152 editAttachment( part );
156 #include "attachmentcontroller.moc"
const KPIMIdentities::Identity & identity() const
AttachmentController(MessageComposer::AttachmentModel *model, AttachmentView *view, KMComposeWin *composer)