summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Crain <jason@inspiresomeone.us>2020-02-12 19:16:20 -0700
committerAlbert Astals Cid <aacid@kde.org>2020-08-21 12:18:56 +0200
commit92b3edf32a9f7a3617681135290e9d2ba0205ffb (patch)
tree308ed35733e91aa498ade88400e27f2621b173fc
parentb13cd962b59e65846e3a9b18eee8a8b999b0291a (diff)
glib: Add accessor functions for PopplerAttachment
Issue #715
-rw-r--r--glib/demo/annots.c2
-rw-r--r--glib/demo/attachments.c21
-rw-r--r--glib/poppler-attachment.cc52
-rw-r--r--glib/poppler-attachment.h20
-rw-r--r--glib/reference/poppler-sections.txt4
5 files changed, 87 insertions, 12 deletions
diff --git a/glib/demo/annots.c b/glib/demo/annots.c
index 96640c5c..16a0db48 100644
--- a/glib/demo/annots.c
+++ b/glib/demo/annots.c
@@ -486,7 +486,7 @@ static void pgd_annot_save_file_attachment_button_clicked(GtkButton *button, Pop
return;
file_chooser = gtk_file_chooser_dialog_new("Save attachment", GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), GTK_FILE_CHOOSER_ACTION_SAVE, "_Cancel", GTK_RESPONSE_CANCEL, "_Save", GTK_RESPONSE_ACCEPT, NULL);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), attachment->name);
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), poppler_attachment_get_name(attachment));
g_signal_connect(G_OBJECT(file_chooser), "response", G_CALLBACK(pgd_annots_file_attachment_save_dialog_response), (gpointer)attachment);
gtk_widget_show(file_chooser);
}
diff --git a/glib/demo/attachments.c b/glib/demo/attachments.c
index 3106af19..5f834a2e 100644
--- a/glib/demo/attachments.c
+++ b/glib/demo/attachments.c
@@ -44,16 +44,20 @@ static void pgd_attachments_fill_model(GtkListStore *model, PopplerDocument *doc
gchar *size;
GDateTime *ctime, *mtime;
gchar *ctime_str, *mtime_str;
+ const gchar *name;
+ const gchar *description;
- size = g_strdup_printf("%" G_GSIZE_FORMAT, attachment->size);
+ name = poppler_attachment_get_name(attachment);
+ description = poppler_attachment_get_description(attachment);
+ size = g_strdup_printf("%" G_GSIZE_FORMAT, poppler_attachment_get_size(attachment));
ctime = poppler_attachment_get_ctime(attachment);
ctime_str = ctime ? g_date_time_format(ctime, "%c") : NULL;
mtime = poppler_attachment_get_mtime(attachment);
mtime_str = mtime ? g_date_time_format(mtime, "%c") : NULL;
gtk_list_store_append(model, &iter);
- gtk_list_store_set(model, &iter, ATTACHMENTS_NAME_COLUMN, attachment->name ? attachment->name : "Unknown", ATTACHMENTS_DESCRIPTION_COLUMN, attachment->description ? attachment->description : "Unknown", ATTACHMENTS_SIZE_COLUMN,
- size ? size : "Unknown", ATTACHMENTS_CTIME_COLUMN, ctime_str ? ctime_str : "Unknown", ATTACHMENTS_MTIME_COLUMN, mtime_str ? mtime_str : "Unknown", ATTACHMENTS_ATTACHMENT_COLUMN, attachment, -1);
+ gtk_list_store_set(model, &iter, ATTACHMENTS_NAME_COLUMN, name ? name : "Unknown", ATTACHMENTS_DESCRIPTION_COLUMN, description ? description : "Unknown", ATTACHMENTS_SIZE_COLUMN, size ? size : "Unknown", ATTACHMENTS_CTIME_COLUMN,
+ ctime_str ? ctime_str : "Unknown", ATTACHMENTS_MTIME_COLUMN, mtime_str ? mtime_str : "Unknown", ATTACHMENTS_ATTACHMENT_COLUMN, attachment, -1);
g_free(size);
g_free(ctime_str);
@@ -127,7 +131,7 @@ static void pgd_attachments_save_button_clicked(GtkButton *button, GtkTreeView *
return;
file_chooser = gtk_file_chooser_dialog_new("Save attachment", GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(treeview))), GTK_FILE_CHOOSER_ACTION_SAVE, "_Cancel", GTK_RESPONSE_CANCEL, "_Save", GTK_RESPONSE_ACCEPT, NULL);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), attachment->name);
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(file_chooser), poppler_attachment_get_name(attachment));
g_signal_connect(G_OBJECT(file_chooser), "response", G_CALLBACK(pgd_attachments_save_dialog_response), (gpointer)attachment);
gtk_widget_show(file_chooser);
}
@@ -155,6 +159,7 @@ static void pgd_attachments_validate_button_clicked(GtkButton *button, GtkTreeVi
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
+ const GString *checksum;
GChecksum *cs;
guint8 *digest;
gsize digest_len;
@@ -170,7 +175,9 @@ static void pgd_attachments_validate_button_clicked(GtkButton *button, GtkTreeVi
if (!attachment)
return;
- if (attachment->checksum->len == 0) {
+ checksum = poppler_attachment_get_checksum(attachment);
+
+ if (checksum->len == 0) {
message_dialog_run(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(treeview))), "Impossible to validate attachment: checksum is not available");
g_object_unref(attachment);
@@ -184,11 +191,11 @@ static void pgd_attachments_validate_button_clicked(GtkButton *button, GtkTreeVi
g_checksum_get_digest(cs, digest, &digest_len);
g_checksum_free(cs);
- if (attachment->checksum->len == digest_len) {
+ if (checksum->len == digest_len) {
gint i;
for (i = 0; i < digest_len; i++) {
- if ((guint8)attachment->checksum->str[i] != digest[i]) {
+ if ((guint8)checksum->str[i] != digest[i]) {
valid = FALSE;
break;
}
diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc
index 9aade86f..3195483b 100644
--- a/glib/poppler-attachment.cc
+++ b/glib/poppler-attachment.cc
@@ -140,6 +140,19 @@ PopplerAttachment *_poppler_attachment_new(FileSpec *emb_file)
}
/**
+ * poppler_attachment_get_checksum:
+ * @attachment: a #PopplerAttachment
+ *
+ * Returns: The attachment's checksum.
+ *
+ * Since: 20.09.0
+ */
+const GString *poppler_attachment_get_checksum(PopplerAttachment *attachment)
+{
+ return attachment->checksum;
+}
+
+/**
* poppler_attachment_get_ctime:
* @attachment: a #PopplerAttachment
*
@@ -154,6 +167,19 @@ GDateTime *poppler_attachment_get_ctime(PopplerAttachment *attachment)
}
/**
+ * poppler_attachment_get_description:
+ * @attachment: a #PopplerAttachment
+ *
+ * Returns: The attachment's descriptive text.
+ *
+ * Since: 20.09.0
+ */
+const gchar *poppler_attachment_get_description(PopplerAttachment *attachment)
+{
+ return attachment->description;
+}
+
+/**
* poppler_attachment_get_mtime:
* @attachment: a #PopplerAttachment
*
@@ -168,6 +194,32 @@ GDateTime *poppler_attachment_get_mtime(PopplerAttachment *attachment)
return GET_PRIVATE(attachment)->mtime;
}
+/**
+ * poppler_attachment_get_name:
+ * @attachment: a #PopplerAttachment
+ *
+ * Returns: The attachment's name.
+ *
+ * Since: 20.09.0
+ */
+const gchar *poppler_attachment_get_name(PopplerAttachment *attachment)
+{
+ return attachment->name;
+}
+
+/**
+ * poppler_attachment_get_size:
+ * @attachment: a #PopplerAttachment
+ *
+ * Returns: The attachment's size.
+ *
+ * Since: 20.09.0
+ */
+gsize poppler_attachment_get_size(PopplerAttachment *attachment)
+{
+ return attachment->size;
+}
+
static gboolean save_helper(const gchar *buf, gsize count, gpointer data, GError **error)
{
FILE *f = (FILE *)data;
diff --git a/glib/poppler-attachment.h b/glib/poppler-attachment.h
index 2b6019a4..3837a750 100644
--- a/glib/poppler-attachment.h
+++ b/glib/poppler-attachment.h
@@ -52,14 +52,18 @@ typedef gboolean (*PopplerAttachmentSaveFunc)(const gchar *buf, gsize count, gpo
/* GTime is deprecated, but is part of our ABI here (see #715, #765). */
/**
* PopplerAttachment:
- * @name: The filename
- * @description: Descriptive text
- * @size: The size of the file
+ * @name: The filename. Deprecated in poppler 20.09.0. Use
+ * poppler_attachment_get_name() instead.
+ * @description: Descriptive text. Deprecated in poppler 20.09.0. Use
+ * poppler_attachment_get_description() instead.
+ * @size: The size of the file. Deprecated in poppler 20.09.0. Use
+ * poppler_attachment_get_size() instead.
* @mtime: The date and time when the file was last modified. Deprecated in
* poppler 20.09.0. Use poppler_attachment_get_mtime() instead.
* @ctime: The date and time when the file was created. Deprecated in poppler
* 20.09.0. Use poppler_attachment_get_ctime() instead.
- * @checksum: A 16-byte checksum of the file.
+ * @checksum: A 16-byte checksum of the file. Deprecated in poppler 20.09.0. Use
+ * poppler_attachment_get_checksum() instead.
*/
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
struct _PopplerAttachment
@@ -84,10 +88,18 @@ typedef struct _PopplerAttachmentClass
POPPLER_PUBLIC
GType poppler_attachment_get_type(void) G_GNUC_CONST;
POPPLER_PUBLIC
+const GString *poppler_attachment_get_checksum(PopplerAttachment *attachment);
+POPPLER_PUBLIC
GDateTime *poppler_attachment_get_ctime(PopplerAttachment *attachment);
POPPLER_PUBLIC
+const gchar *poppler_attachment_get_description(PopplerAttachment *attachment);
+POPPLER_PUBLIC
GDateTime *poppler_attachment_get_mtime(PopplerAttachment *attachment);
POPPLER_PUBLIC
+const gchar *poppler_attachment_get_name(PopplerAttachment *attachment);
+POPPLER_PUBLIC
+gsize poppler_attachment_get_size(PopplerAttachment *attachment);
+POPPLER_PUBLIC
gboolean poppler_attachment_save(PopplerAttachment *attachment, const char *filename, GError **error);
POPPLER_PUBLIC
gboolean poppler_attachment_save_to_callback(PopplerAttachment *attachment, PopplerAttachmentSaveFunc save_func, gpointer user_data, GError **error);
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 900b1f9f..828a8bf1 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -334,8 +334,12 @@ poppler_action_movie_operation_get_type
<TITLE>PopplerAttachment</TITLE>
PopplerAttachment
PopplerAttachmentSaveFunc
+poppler_attachment_get_checksum
poppler_attachment_get_ctime
+poppler_attachment_get_description
poppler_attachment_get_mtime
+poppler_attachment_get_name
+poppler_attachment_get_size
poppler_attachment_save
poppler_attachment_save_to_callback