Bug 257790 - Cannot save a png attachment
Summary: Cannot save a png attachment
Status: CLOSED FIXED
Alias: None
Product: KOrganizer Mobile
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Maemo 5 Microsoft Windows CE
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-24 15:08 UTC by Ludwig Reiter
Modified: 2011-01-20 14:16 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 Ludwig Reiter 2010-11-24 15:08:42 UTC
Version:           unspecified (using Devel) 
OS:                Linux

version: 20101123.1199921-1maemo1.1199914 (enterprise5)

Clickon on the save butto has no effect.

Reproducible: Always

Steps to Reproduce:
1. Create an event with a png test attachment (with name and inline)
2. Select the event.
3. Open the attachments flaps
4. Click on the save/disc icon

Actual Results:  
No effect.

Expected Results:  
A file dialog should open and it should be possible to save the attachment.
Comment 1 Volker Krause 2010-11-26 14:37:27 UTC
SVN commit 1200997 by vkrause:

Actually attempt to save image attachments.

BUG: 256760
BUG: 257790


 M  +3 -0      AttachmentList.qml  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1200997
Comment 2 Ludwig Reiter 2010-12-01 15:13:54 UTC
version: 20101201.1202511

A file dialog opens. ok
But it has preconfigured "Document" as file name. (failure)
Save. 
The saved file has the size 0. (failure)
Comment 3 Tobias Koenig 2010-12-09 11:56:25 UTC
Works fine on desktop, so it must be a plain Maemo/WinCE problem...
Comment 4 Andre Heinecke 2011-01-04 10:00:17 UTC
Wince:
Looking at the attachment shows a fine preview of the png,
Test 1: 
-> Actions -> save all attachments
 - Save attachment dialog comes up
 - Filter ist set for all files
 - Filename is the filename for all attachments

-> Added .png suffig to the filename -> Hit save
 - MessageBox: "Prozess kann nicht gestartet werden: Keine Verbindung zu klauncher: The name org.kde.klauncher was not provided by any .service files"
 - File is not saved

Test 2:
-> Hit save icon in the attachment flap
 - File Dialog comes up, filename is not the filename of the attachment but korganizer-mobile301570
-> save
 - file is created but without .png suffix can not be opened

Test 3
-> Hit save icon in the attachment flap
 - File Dialog comes up, filename is not the filename of the attachment but korganizer-mobile301570
-> Change name to korganizer-mobile301570.png
 - save
 - file is there correctly
Comment 5 Andre Heinecke 2011-01-04 10:04:16 UTC
The Test in Comment #4 was with version -gitfc6a857 from 2011-01-01
Comment 6 Andre Heinecke 2011-01-05 15:26:31 UTC
commit 523864bd8dc0d928b549a59fe6cf6ccde66953b1
branch master
Author: Andre Heinecke <aheinecke@intevation.de>
Date:   Wed Jan 5 13:46:18 2011 +0000

    Modifiy attachment save function.
    
      Allow to supply a defaultFileName for saveAttachment that is
      independend ot the Url and will be preselected in the FileDialog.
      Also check if the MimeType of the attachment can be determined and
      if so use the patterns of this mimetype as a filter so that the
      file Suffix is correctly set.
      CCBUG: 257790

diff --git a/mobile/lib/kdeclarativemainview.cpp b/mobile/lib/kdeclarativemainview.cpp
index e713b16..094b1f6 100644
--- a/mobile/lib/kdeclarativemainview.cpp
+++ b/mobile/lib/kdeclarativemainview.cpp
@@ -738,15 +738,23 @@ void KDeclarativeMainView::openAttachment( const QString &url, const QString &mi
 #endif
 }
 
-void KDeclarativeMainView::saveAttachment( const QString &url )
+void KDeclarativeMainView::saveAttachment( const QString &url , const QString &defaultFileName)
 {
-  QString fileName = KUrl( url ).fileName();
-  if ( fileName.isEmpty() ) {
-    fileName = i18nc( "filename for an unnamed attachment", "attachment.1" );
+  QString fileName = defaultFileName;
+  if ( defaultFileName.isEmpty() ) {
+    fileName = KUrl( url ).fileName();
+    if ( fileName.isEmpty() ) {
+      fileName = i18nc( "filename for an unnamed attachment", "attachment.1" );
+    }
+  }
+  QStringList patterns = KMimeType::findByUrl( url, 0, true, true, 0 )->patterns();
+  QString filter = QString();
+  if ( !patterns.isEmpty() ) {
+    filter += patterns.join( QLatin1String( "\n" ) );
+    filter += i18n( "\n*|all files" );
   }
-
   const QString targetFile = KFileDialog::getSaveFileName( KUrl( "kfiledialog:///saveAttachment/" + fileName ),
-                                                           QString(),
+                                                           filter,
                                                            this,
                                                            i18n( "Save Attachment" ) );
   if ( targetFile.isEmpty() ) {
diff --git a/mobile/lib/kdeclarativemainview.h b/mobile/lib/kdeclarativemainview.h
index dad6f03..672f177 100644
--- a/mobile/lib/kdeclarativemainview.h
+++ b/mobile/lib/kdeclarativemainview.h
@@ -172,7 +172,7 @@ class MOBILEUI_EXPORT KDeclarativeMainView : public KDeclarativeFullScreenView
     void openManual();
 
     void openAttachment( const QString &url, const QString &mimeType );
-    void saveAttachment( const QString &url );
+    void saveAttachment( const QString &url, const QString &defaultFileName = QString() );
 
     void reportBug();
Comment 7 Andre Heinecke 2011-01-05 15:26:32 UTC
commit 1c3bb63a51b8e6a06f21d7decbd63efcbc862bb0
branch master
Author: Andre Heinecke <aheinecke@intevation.de>
Date:   Wed Jan 5 14:21:13 2011 +0000

    Fix saveAllAttachments for WinCE.
    
        On Windows CE  CalendarSupport::saveAttachments does not work.
        So we now do the AttachmentLookup directly and then use the
        KDeclarativeMainView saveAttachment function to do the actual
        saving.
        CCBUG: 257790

diff --git a/mobile/calendar/mainview.cpp b/mobile/calendar/mainview.cpp
index edbdb60..43ba8e4 100644
--- a/mobile/calendar/mainview.cpp
+++ b/mobile/calendar/mainview.cpp
@@ -714,8 +714,37 @@ void MainView::fetchForSaveAllAttachmentsDone( KJob *job )
   }
 
   const Akonadi::Item item = static_cast<Akonadi::ItemFetchJob*>( job )->items().first();
-
+#ifndef Q_OS_WINCE
   CalendarSupport::saveAttachments( item, this );
+#else
+  // CalendarSupport is not completly ported for Windows CE so we use the
+  // attachment handling code from KDeclarativeMainView
+  KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence( item );
+
+  if ( !incidence ) {
+    KMessageBox::sorry(
+      this,
+      i18n( "No item selected." ),
+      "SaveAttachments" );
+    return;
+  }
+
+  KCalCore::Attachment::List attachments = incidence->attachments();
+
+  if ( attachments.empty() )
+    return;
+
+  Q_FOREACH( KCalCore::Attachment::Ptr attachment, attachments ) {
+    QString fileName = attachment->label();
+    QString sourceUrl;
+    if ( attachment->isUri() ) {
+      sourceUrl = attachment->uri();
+    } else {
+      sourceUrl = incidence->writeAttachmentToTempFile( attachment );
+    }
+      saveAttachment( sourceUrl, fileName );
+  }
+#endif //Q_OS_WINCE
 }
 
 void MainView::archiveOldEntries()
Comment 8 Andre Heinecke 2011-01-05 15:32:33 UTC
Issue that remains is that when saving a single file from the attachment menu the filename is something like korganizer-mobile301570.
Because the filename is there directly taken from the url which is a temporary file and not from the label as it should be.
Comment 9 Andre Heinecke 2011-01-13 11:28:22 UTC
To reproduce Comment #8 
-> Attach a file to an incidence
-> Pull out the attachment flap when looking at that incidence
-> hit the save icon in the bottom right corner
Comment 10 Tobias Koenig 2011-01-13 13:21:34 UTC
commit 48068ac956521cac309005b36ad2638c1a727b57
branch master
Author: Tobias Koenig <tokoe@kde.org>
Date:   Thu Jan 13 13:24:25 2011 +0100

    Use display name as filename suggestion for saving
    
    BUG: 257790

diff --git a/mobile/calendar/korganizer-mobile.qml b/mobile/calendar/korganizer-mobile.qml
index c47b47e..2eb0a41 100644
--- a/mobile/calendar/korganizer-mobile.qml
+++ b/mobile/calendar/korganizer-mobile.qml
@@ -507,7 +507,7 @@ KPIM.MainView {
           }
 
           onSaveAttachment: {
-            application.saveAttachment(url);
+            application.saveAttachment(url, fileName);
           }
         }
       ]
diff --git a/mobile/lib/AttachmentList.qml b/mobile/lib/AttachmentList.qml
index 343f718..3f3be4a 100644
--- a/mobile/lib/AttachmentList.qml
+++ b/mobile/lib/AttachmentList.qml
@@ -34,7 +34,7 @@ Item {
 
   /** Emittted when an attachment has been selected. */
   signal openAttachment(string url, string mimeType)
-  signal saveAttachment(string url)
+  signal saveAttachment(string url, string fileName)
 
   Component {
     id: attachmentDelegate
@@ -63,6 +63,7 @@ Item {
           wrapper.ListView.view.currentIndex = model.index
           wrapper.ListView.view.currentMimeType = model.mimeType;
           wrapper.ListView.view.currentAttachmentUrl = model.attachmentUrl;
+          wrapper.ListView.view.currentFileName = model.display;
         }
       }
     }
@@ -71,6 +72,7 @@ Item {
   KPIM.DecoratedListView {
     property string currentMimeType
     property string currentAttachmentUrl
+    property string currentFileName
 
     id: attachmentListView
     anchors.top: parent.top
@@ -87,6 +89,7 @@ Item {
         attachmentListView.currentIndex = -1
         attachmentListView.currentMimeType = "";
         attachmentListView.currentAttachmentUrl = "";
+        attachmentListView.currentFileName = "";
       }
     }
   }
@@ -119,7 +122,7 @@ Item {
       height: parent.height / 6
       buttonText: KDE.i18n( "Save" )
       onClicked: {
-         saveAttachment(attachmentListView.currentAttachmentUrl);
+         saveAttachment(attachmentListView.currentAttachmentUrl, attachmentListView.currentFileName);
       }
     }
   }
@@ -154,7 +157,7 @@ Item {
       height: 48
       icon: KDE.iconPath( "document-save", width );
       onClicked: {
-        saveAttachment(attachmentListView.currentAttachmentUrl);
+        saveAttachment(attachmentListView.currentAttachmentUrl, attachmentListView.currentFileName);
       }
       states: [
         State {
diff --git a/mobile/lib/kdeclarativemainview.cpp b/mobile/lib/kdeclarativemainview.cpp
index dbff324..fafe342 100644
--- a/mobile/lib/kdeclarativemainview.cpp
+++ b/mobile/lib/kdeclarativemainview.cpp
@@ -748,7 +748,7 @@ void KDeclarativeMainView::openAttachment( const QString &url, const QString &mi
 #endif
 }
 
-void KDeclarativeMainView::saveAttachment( const QString &url , const QString &defaultFileName)
+void KDeclarativeMainView::saveAttachment( const QString &url, const QString &defaultFileName )
 {
   QString fileName = defaultFileName;
   if ( defaultFileName.isEmpty() ) {
diff --git a/mobile/mail/kmail-mobile.qml b/mobile/mail/kmail-mobile.qml
index 66fb2fd..fae1896 100644
--- a/mobile/mail/kmail-mobile.qml
+++ b/mobile/mail/kmail-mobile.qml
@@ -489,7 +489,7 @@ KPIM.MainView {
           }
 
           onSaveAttachment: {
-            application.saveAttachment(url);
+            application.saveAttachment(url, fileName);
           }
         }
       ]
diff --git a/mobile/tasks/tasks.qml b/mobile/tasks/tasks.qml
index ee0448e..10ec061 100644
--- a/mobile/tasks/tasks.qml
+++ b/mobile/tasks/tasks.qml
@@ -341,7 +341,7 @@ KPIM.MainView {
           }
 
           onSaveAttachment: {
-            application.saveAttachment(url);
+            application.saveAttachment(url, fileName);
           }
         }
       ]
Comment 11 Ludwig Reiter 2011-01-20 14:16:36 UTC
Calendar Touch (Windows CE) 2011-01-16
Test of the description: passed
Closed.