diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index d082704a1..cdf8015b3 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -380,6 +380,8 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) this, SLOT (slotSpellcheckDone (int))); connect (mEditor, SIGNAL( pasteImage() ), this, SLOT (slotPaste() ) ); + connect (mEditor, SIGNAL( attachPNGImageData(const QByteArray &) ), + this, SLOT ( slotAttachPNGImageData(const QByteArray &) ) ); connect (mEditor, SIGNAL( focusChanged(bool) ), this, SLOT (editorFocusChanged(bool)) ); @@ -491,33 +493,21 @@ void KMComposeWin::addAttachment(const QString &name, addAttach(msgPart); } } + //----------------------------------------------------------------------------- -void KMComposeWin::addImageFromClipboard() +void KMComposeWin::slotAttachPNGImageData(const QByteArray &image) { bool ok; - QFile *tmpFile; QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this ); if ( !ok ) return; - mTempDir = new KTempDir(); - mTempDir->setAutoDelete( true ); - - if ( attName.lower().endsWith(".png") ) - tmpFile = new QFile(mTempDir->name() + attName ); - else - tmpFile = new QFile(mTempDir->name() + attName + ".png" ); + if ( !attName.lower().endsWith(".png") ) attName += ".png"; - if ( !QApplication::clipboard()->image().save( tmpFile->name(), "PNG" ) ) { - KMessageBox::error( this, i18n("Unknown error trying to save image."), i18n("Attaching Image Failed") ); - delete mTempDir; - mTempDir = 0; - return; - } - - addAttach( tmpFile->name() ); + addAttachment( attName, "base64", image, "image", "png", QCString(), QString(), QCString() ); } + //----------------------------------------------------------------------------- void KMComposeWin::setBody(QString body) { @@ -3410,7 +3400,11 @@ void KMComposeWin::slotPasteAsAttachment() return; } - if ( QApplication::clipboard()->image().isNull() ) { + QMimeSource *mimeSource = QApplication::clipboard()->data(); + if ( QImageDrag::canDecode(mimeSource) ) { + slotAttachPNGImageData(mimeSource->encodedData("image/png")); + } + else { bool ok; QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this ); if ( !ok ) @@ -3422,9 +3416,6 @@ void KMComposeWin::slotPasteAsAttachment() kmkernel->msgSender()->sendQuotedPrintable()); addAttach(msgPart); } - else - addImageFromClipboard(); - } void KMComposeWin::slotAddQuotes() @@ -3557,8 +3548,9 @@ void KMComposeWin::slotPaste() QWidget* fw = focusWidget(); if (!fw) return; - if ( ! QApplication::clipboard()->image().isNull() ) { - addImageFromClipboard(); + QMimeSource *mimeSource = QApplication::clipboard()->data(); + if ( mimeSource->provides("image/png") ) { + slotAttachPNGImageData(mimeSource->encodedData("image/png")); } else { diff --git a/kmcomposewin.h b/kmcomposewin.h index a40809b47..c3a6420f0 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -284,6 +284,7 @@ private slots: void slotPasteAsAttachment(); void slotAddQuotes(); void slotRemoveQuotes(); + void slotAttachPNGImageData(const QByteArray &image); void slotMarkAll(); @@ -461,12 +462,6 @@ public: // kmcommand */ void addAttach(const KMMessagePart* msgPart); -private: - /** - * Add an image from the clipboard as attachment - */ - void addImageFromClipboard(); - private: const KPIM::Identity & identity() const; uint identityUid() const; diff --git a/kmedit.cpp b/kmedit.cpp index 4a653379f..bce0afc59 100644 --- a/kmedit.cpp +++ b/kmedit.cpp @@ -60,6 +60,8 @@ void KMEdit::contentsDragEnterEvent(QDragEnterEvent *e) { if (e->provides(MailListDrag::format())) e->accept(true); + else if (e->provides("image/png")) + e->accept(); else return KEdit::contentsDragEnterEvent(e); } @@ -68,6 +70,8 @@ void KMEdit::contentsDragMoveEvent(QDragMoveEvent *e) { if (e->provides(MailListDrag::format())) e->accept(); + else if (e->provides("image/png")) + e->accept(); else return KEdit::contentsDragMoveEvent(e); } @@ -164,6 +168,9 @@ void KMEdit::contentsDropEvent(QDropEvent *e) identity, mComposer); command->start(); } + else if( e->provides("image/png") ) { + emit attachPNGImageData(e->encodedData("image/png")); + } else if( KURLDrag::canDecode( e ) ) { KURL::List urlList; if( KURLDrag::decode( e, urlList ) ) { diff --git a/kmedit.h b/kmedit.h index b12d73d36..e2a90f398 100644 --- a/kmedit.h +++ b/kmedit.h @@ -75,6 +75,7 @@ public: signals: void spellcheck_done(int result); + void attachPNGImageData(const QByteArray &image); void pasteImage(); void focusUp(); void focusChanged( bool );