[evolution] [ECompEditor] Use ICAL_FILENAME_PARAMETER for attachments, if available
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] [ECompEditor] Use ICAL_FILENAME_PARAMETER for attachments, if available
- Date: Fri, 19 May 2017 06:07:19 +0000 (UTC)
commit 086d1be1d017721f0e600a2ae1ee3db1e0e22fd7
Author: Milan Crha <mcrha redhat com>
Date: Fri May 19 08:05:04 2017 +0200
[ECompEditor] Use ICAL_FILENAME_PARAMETER for attachments, if available
libical supports ICAL_FILENAME_PARAMETER since 2.0.0. It's part of
an extension which sets filename for attachments, thus even inline
attachments keep their original filename.
CMakeLists.txt | 9 +++
config.h.in | 3 +
src/calendar/gui/e-comp-editor-page-attachments.c | 75 ++++++++++++++++-----
3 files changed, 70 insertions(+), 17 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cee883b..dd6d1f4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -572,6 +572,15 @@ CHECK_C_SOURCE_COMPILES("#include <libical/ical.h>
return 0;
}" HAVE_ICALTZUTIL_SET_EXACT_VTIMEZONES_SUPPORT)
+CHECK_C_SOURCE_COMPILES("#include <libical/ical.h>
+ int main(void) {
+ icalparameter *param;
+ param = icalproperty_get_first_parameter (NULL, ICAL_FILENAME_PARAMETER);
+ icalparameter_get_filename (param);
+ icalparameter_new_filename (NULL);
+ return 0;
+ }" HAVE_ICAL_FILENAME_PARAMETER)
+
unset(CMAKE_REQUIRED_DEFINITIONS)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)
diff --git a/config.h.in b/config.h.in
index d7897a5..6d6e3f5 100644
--- a/config.h.in
+++ b/config.h.in
@@ -99,6 +99,9 @@
/* libical provides icaltzutil_set_exact_vtimezones_support function */
#cmakedefine HAVE_ICALTZUTIL_SET_EXACT_VTIMEZONES_SUPPORT 1
+/* libical provides ICAL_FILENAME_PARAMETER */
+#cmakedefine HAVE_ICAL_FILENAME_PARAMETER 1
+
/* When defined spell checking is enabled */
#cmakedefine HAVE_GTKSPELL 1
diff --git a/src/calendar/gui/e-comp-editor-page-attachments.c
b/src/calendar/gui/e-comp-editor-page-attachments.c
index 5a1825a..5fe0fd3 100644
--- a/src/calendar/gui/e-comp-editor-page-attachments.c
+++ b/src/calendar/gui/e-comp-editor-page-attachments.c
@@ -139,8 +139,6 @@ ecep_attachments_attachment_loaded_cb (EAttachment *attachment,
{
GFileInfo *file_info;
const gchar *display_name;
- const gchar *uid;
- gchar *new_name;
GError *error = NULL;
/* Prior to 2.27.2, attachment files were named:
@@ -163,10 +161,19 @@ ecep_attachments_attachment_loaded_cb (EAttachment *attachment,
file_info = e_attachment_ref_file_info (attachment);
if (file_info) {
+ const gchar *uid;
+ const gchar *prefer_filename;
+
display_name = g_file_info_get_display_name (file_info);
uid = g_object_get_data (G_OBJECT (attachment), "uid");
+ prefer_filename = g_object_get_data (G_OBJECT (attachment), "prefer-filename");
+
+ if (prefer_filename && *prefer_filename) {
+ g_file_info_set_display_name (file_info, prefer_filename);
+ g_object_notify (G_OBJECT (attachment), "file-info");
+ } else if (g_str_has_prefix (display_name, uid)) {
+ gchar *new_name;
- if (g_str_has_prefix (display_name, uid)) {
new_name = g_strdup (display_name + strlen (uid) + 1);
g_file_info_set_display_name (file_info, new_name);
g_object_notify (G_OBJECT (attachment), "file-info");
@@ -266,13 +273,25 @@ ecep_attachments_fill_widgets (ECompEditorPage *page,
for (prop = icalcomponent_get_first_property (component, ICAL_ATTACH_PROPERTY), index = 0;
prop;
prop = icalcomponent_get_next_property (component, ICAL_ATTACH_PROPERTY), index++) {
+ icalparameter *param;
icalattach *attach;
- gchar *uri = NULL;
+ gchar *uri = NULL, *filename = NULL;
attach = icalproperty_get_attach (prop);
if (!attach)
continue;
+ #ifdef HAVE_ICAL_FILENAME_PARAMETER
+ param = icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER);
+ if (param) {
+ filename = g_strdup (icalparameter_get_filename (param));
+ if (!filename || !*filename) {
+ g_free (filename);
+ filename = NULL;
+ }
+ }
+ #endif
+
if (icalattach_get_is_url (attach)) {
const gchar *data;
gsize buf_size;
@@ -325,22 +344,24 @@ ecep_attachments_fill_widgets (ECompEditorPage *page,
g_free (id_str);
if (g_mkdir_with_parents (dir, 0700) >= 0) {
- icalparameter *param;
- gchar *file = NULL;
-
for (param = icalproperty_get_first_parameter (prop,
ICAL_X_PARAMETER);
- param && !file;
+ param && !filename;
param = icalproperty_get_next_parameter (prop,
ICAL_X_PARAMETER)) {
if (e_util_strstrcase
(icalparameter_get_xname (param), "NAME") &&
icalparameter_get_xvalue (param) &&
- *icalparameter_get_xvalue (param))
- file = g_strdup
(icalparameter_get_xvalue (param));
+ *icalparameter_get_xvalue (param)) {
+ filename = g_strdup
(icalparameter_get_xvalue (param));
+ if (!filename || !*filename) {
+ g_free (filename);
+ filename = NULL;
+ }
+ }
}
- if (!file)
- file = g_strdup_printf ("%d.dat", index);
+ if (!filename)
+ filename = g_strdup_printf ("%d.dat", index);
- temporary_filename = g_build_filename (dir, file,
NULL);
+ temporary_filename = g_build_filename (dir, filename,
NULL);
if (!g_file_set_contents (temporary_filename, (const
gchar *) data, data_len, NULL)) {
g_free (temporary_filename);
temporary_filename = NULL;
@@ -366,16 +387,16 @@ ecep_attachments_fill_widgets (ECompEditorPage *page,
attachment = e_attachment_new_for_uri (uri);
e_attachment_store_add_attachment (store, attachment);
- g_object_set_data_full (
- G_OBJECT (attachment),
- "uid", g_strdup (uid),
- (GDestroyNotify) g_free);
+ g_object_set_data_full (G_OBJECT (attachment), "uid", g_strdup (uid), g_free);
+ if (filename)
+ g_object_set_data_full (G_OBJECT (attachment), "prefer-filename", g_strdup
(filename), g_free);
e_attachment_load_async (
attachment, (GAsyncReadyCallback)
ecep_attachments_attachment_loaded_cb, page_attachments);
g_object_unref (attachment);
}
+ g_free (filename);
g_free (uri);
}
}
@@ -412,6 +433,9 @@ ecep_attachments_fill_component (ECompEditorPage *page,
gsize buf_size;
gchar *buf, *uri, *description;
GFile *file;
+ #ifdef HAVE_ICAL_FILENAME_PARAMETER
+ GFileInfo *file_info;
+ #endif
if (!attachment)
continue;
@@ -462,6 +486,23 @@ ecep_attachments_fill_component (ECompEditorPage *page,
icalvalue_encode_ical_string (uri, buf, buf_size);
attach = icalattach_new_from_url (buf);
prop = icalproperty_new_attach (attach);
+
+ #ifdef HAVE_ICAL_FILENAME_PARAMETER
+ file_info = e_attachment_ref_file_info (attachment);
+ if (file_info) {
+ const gchar *display_name = g_file_info_get_display_name (file_info);
+
+ if (display_name && *display_name) {
+ icalparameter *param;
+
+ param = icalparameter_new_filename (display_name);
+ icalproperty_add_parameter (prop, param);
+ }
+
+ g_object_unref (file_info);
+ }
+ #endif
+
icalcomponent_add_property (component, prop);
icalattach_unref (attach);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]