Bug 50912 - Wish: insert attachment from clipboard
Summary: Wish: insert attachment from clipboard
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR wishlist
Target Milestone: ---
Assignee: Edwin Schepers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-18 17:11 UTC by Nicolas Goutte
Modified: 2004-10-26 23:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Goutte 2002-11-18 17:11:30 UTC
Version:            (using KDE KDE 3.0.3)
Installed from:    SuSE RPMs
Compiler:          gcc 3.2 
OS:          Linux

I would like a "Edit/Insert clipboard as attachment" function in KMail.

For now, you can only add an attachment as a file to a new message. So when you have data in the clipboard that you wnat to attch to a message youhave to call another program first, insert the clipboard content, save into a file and then attch the file in KMail.

It would be better if this procedure could be made directly in KMail. Sure,
a selection dialog is perhaps needed if the clipboard holds a few formats.

Have a nice day/evening/night!
Comment 1 Nicolas Goutte 2002-11-18 17:12:44 UTC
Sorry, it seems that I have written "attach" always as "attch". 
Comment 2 Fred Schättgen 2004-07-23 17:58:48 UTC
I would also love to see this feature. One occasion where I have that wish
regularly is when I want to send someone a screenshot. It would be so conveniant to start a new mail, launch ksnapshot, take a snapshot and drag it into the mail. No more saving to /tmp, clicking "attach", going to the /tmp folder with kmail.
Btw. this works between kword and ksnapshot for instance.
Comment 3 Christoph Eckert 2004-09-21 20:27:23 UTC
The problem is that there isn't a real good clipboard on linux; I guess that ksnapshot and kwrod do this using dcop?
Comment 4 David Faure 2004-09-21 20:28:49 UTC
> The problem is that there isn't a real good clipboard on linux; I guess that ksnapshot and kwrod do this using dcop?
Certainly not - we use the clipboard, which works very well for this kind of thing.

Comment 5 Tom Albers 2004-10-17 18:33:09 UTC
*** Bug 91364 has been marked as a duplicate of this bug. ***
Comment 6 Tom Albers 2004-10-17 23:22:59 UTC
*** Bug 91364 has been marked as a duplicate of this bug. ***
Comment 7 Edwin Schepers 2004-10-26 23:04:25 UTC
CVS commit by eschepers: 

Ability to paste into an attachment (Edit menu)
BUG: 50912


  M +2 -1      kmcomposerui.rc   1.36
  M +48 -23    kmcomposewin.cpp   1.874
  M +6 -0      kmcomposewin.h   1.258


--- kdepim/kmail/kmcomposerui.rc  #1.35:1.36
@@ -1,3 +1,3 @@
-<!DOCTYPE kpartgui ><kpartgui version="22" name="kmcomposer" >
+<!DOCTYPE kpartgui ><kpartgui version="23" name="kmcomposer" >
  <MenuBar>
   <Menu noMerge="1" name="file" >
@@ -18,4 +18,5 @@
    <text>&amp;Edit</text>
    <Action name="paste_quoted" append="edit_paste_merge"/>
+   <Action name="paste_att" append="edit_paste_merge"/>
    <Action name="clean_spaces" />
    <Separator/>

--- kdepim/kmail/kmcomposewin.cpp  #1.873:1.874
@@ -400,5 +400,31 @@ void KMComposeWin::addAttachment(const Q
   }
 }
+//-----------------------------------------------------------------------------
+void KMComposeWin::addImageFromClipboard()
+{
+  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 ( !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() );
+}
 //-----------------------------------------------------------------------------
 void KMComposeWin::setBody(QString body)
@@ -985,4 +1011,7 @@ void KMComposeWin::setupActions(void)
                       actionCollection(), "paste_quoted");
 
+  (void) new KAction (i18n("Paste as Attac&hment"),0,this,SLOT( slotPasteAsAttachment()),
+                      actionCollection(), "paste_att");
+
   (void) new KAction(i18n("Add &Quote Characters"), 0, this,
               SLOT(slotAddQuotes()), actionCollection(), "tools_quote");
@@ -2680,4 +2709,22 @@ void KMComposeWin::slotPasteAsQuotation(
 }
 
+void KMComposeWin::slotPasteAsAttachment()
+{
+  if ( QApplication::clipboard()->image().isNull() )  {
+    bool ok;
+    QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok, this );
+    if ( !ok )
+      return;
+    KMMessagePart *msgPart = new KMMessagePart;
+    msgPart->setName(attName);
+    QValueList<int> dummy;
+    msgPart->setBodyAndGuessCte(QCString(QApplication::clipboard()->text().latin1()), dummy,
+                                kmkernel->msgSender()->sendQuotedPrintable());
+    addAttach(msgPart);
+  }
+  else
+    addImageFromClipboard();
+
+}
 
 void KMComposeWin::slotAddQuotes()
@@ -2789,27 +2836,5 @@ void KMComposeWin::slotPaste()
 
   if ( ! QApplication::clipboard()->image().isNull() )  {
-    bool ok;
-    QFile *tmpFile;
-
-    QString attName = KInputDialog::getText( "KMail", i18n("Name of the attachment:"), QString::null, &ok );
-    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 ( !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() );
+    addImageFromClipboard();
   }
   else {

--- kdepim/kmail/kmcomposewin.h  #1.257:1.258
@@ -394,4 +394,5 @@ public slots:
   void slotPaste();
   void slotPasteAsQuotation();
+  void slotPasteAsAttachment();
   void slotAddQuotes();
   void slotRemoveQuotes();
@@ -573,4 +574,9 @@ public slots:
    void addAttach(const KMMessagePart* msgPart);
 
+  /**
+   * Add an image from the clipboard as attachment
+   */
+   void addImageFromClipboard();
+
 public:
   const KPIM::Identity & identity() const;