diff --git a/attachmentcontroller.cpp b/attachmentcontroller.cpp index 8cdfc1f71..f66b66089 100644 --- a/attachmentcontroller.cpp +++ b/attachmentcontroller.cpp @@ -29,6 +29,8 @@ #include "globalsettings.h" #include "kmkernel.h" #include "kmcomposewin.h" +#include "kmcommands.h" +#include "foldercollection.h" #include #include @@ -363,6 +365,7 @@ AttachmentController::AttachmentController( AttachmentModel *model, AttachmentVi d->model = model; connect( model, SIGNAL(attachUrlsRequested(KUrl::List)), this, SLOT(addAttachments(KUrl::List)) ); + connect( model, SIGNAL(attachItemsRequester(Akonadi::Item::List ) ), this, SLOT( addAttachmentItems( Akonadi::Item::List ) ) ); connect( model, SIGNAL(attachmentRemoved(KPIM::AttachmentPart::Ptr)), this, SLOT(attachmentRemoved(KPIM::AttachmentPart::Ptr)) ); connect( model, SIGNAL(attachmentCompressRequested(KPIM::AttachmentPart::Ptr,bool)), @@ -670,6 +673,17 @@ void AttachmentController::addAttachments( const KUrl::List &urls ) } } +void AttachmentController::addAttachmentItems( const Akonadi::Item::List &items ) +{ + uint identity = 0; + if ( items.at( 0 ).isValid() && items.at( 0 ).parentCollection().isValid() ) { + FolderCollection fd( items.at( 0 ).parentCollection(),false ); + identity = fd.identity(); + } + KMCommand *command = new KMForwardAttachedCommand( d->composer, items,identity, d->composer ); + command->start(); +} + void AttachmentController::showAttachPublicKeyDialog() { using Kleo::KeySelectionDialog; diff --git a/attachmentcontroller.h b/attachmentcontroller.h index e0d980f6d..4262ae166 100644 --- a/attachmentcontroller.h +++ b/attachmentcontroller.h @@ -30,7 +30,7 @@ #include #include - +#include class KMComposeWin; @@ -69,6 +69,7 @@ class AttachmentController : public QObject void addAttachment( KPIM::AttachmentPart::Ptr part ); void addAttachment( const KUrl &url ); void addAttachments( const KUrl::List &urls ); + void addAttachmentItems( const Akonadi::Item::List &items ); void showAttachPublicKeyDialog(); void attachMyPublicKey(); diff --git a/attachmentmodel.cpp b/attachmentmodel.cpp index 9392c7a60..a8705eb09 100644 --- a/attachmentmodel.cpp +++ b/attachmentmodel.cpp @@ -30,11 +30,12 @@ #include #include +#include +#include "foldercollection.h" +#include "kmcommands.h" #include -#include - using namespace KMail; using namespace KPIM; @@ -106,45 +107,24 @@ bool AttachmentModel::dropMimeData( const QMimeData *data, Qt::DropAction action //} else if( action != Qt::CopyAction ) { // return false; } - - if( KPIM::MailList::canDecode( data ) ) { - // The dropped data is a list of messages. - kDebug() << "Port me to Akonadi..."; // TODO -#if 0 - // Decode the list of serial numbers stored as the drag data - QByteArray serNums = KPIM::MailList::serialsFromMimeData( md ); - QBuffer serNumBuffer( &serNums ); - serNumBuffer.open( QIODevice::ReadOnly ); - QDataStream serNumStream( &serNumBuffer ); - quint32 serNum; - KMFolder *folder = 0; - int idx; - QList messageList; - while( !serNumStream.atEnd() ) { - KMMsgBase *msgBase = 0; - serNumStream >> serNum; - KMMsgDict::instance()->getLocation( serNum, &folder, &idx ); - if( folder ) - msgBase = folder->getMsgBase( idx ); - if( msgBase ) - messageList.append( msgBase ); + // The dropped data is a list of URLs. + KUrl::List urls = KUrl::List::fromMimeData( data ); + if( !urls.isEmpty() ) { + Akonadi::Item::List items; + foreach ( const KUrl &url, urls ) { + Akonadi::Item item = Akonadi::Item::fromUrl( url ); + if ( item.isValid() ) { + items << item; + } } - serNumBuffer.close(); - uint identity = folder ? folder->identity() : 0; - KMCommand *command = new KMForwardAttachedCommand( mComposer, messageList, - identity, mComposer ); - command->start(); -#endif - return true; - } else { - // The dropped data is a list of URLs. - KUrl::List urls = KUrl::List::fromMimeData( data ); - if( !urls.isEmpty() ) { + if ( items.isEmpty() ) emit attachUrlsRequested( urls ); - return true; - } else { - return false; + else { + emit attachItemsRequester( items ); } + return true; + } else { + return false; } } diff --git a/attachmentmodel.h b/attachmentmodel.h index 402a45b54..ab556d5cf 100644 --- a/attachmentmodel.h +++ b/attachmentmodel.h @@ -25,6 +25,7 @@ #include #include +#include namespace KMail { @@ -104,6 +105,7 @@ class AttachmentModel : public QAbstractItemModel void encryptEnabled( bool enabled ); void signEnabled( bool enabled ); void attachUrlsRequested( const KUrl::List &urls ); + void attachItemsRequester( const Akonadi::Item::List & ); void attachmentRemoved( KPIM::AttachmentPart::Ptr part ); void attachmentCompressRequested( KPIM::AttachmentPart::Ptr part, bool compress );