[Bug 257790] Cannot save a png attachment
Andre Heinecke
aheinecke at intevation.de
Wed Jan 5 14:26:33 GMT 2011
https://bugs.kde.org/show_bug.cgi?id=257790
--- Comment #6 from Andre Heinecke <aheinecke intevation de> 2011-01-05 15:26:31 ---
commit 523864bd8dc0d928b549a59fe6cf6ccde66953b1
branch master
Author: Andre Heinecke <aheinecke at 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 from Andre Heinecke <aheinecke intevation de> 2011-01-05 15:26:32 ---
commit 1c3bb63a51b8e6a06f21d7decbd63efcbc862bb0
branch master
Author: Andre Heinecke <aheinecke at 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()
--
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the Kdepim-bugs
mailing list