Commit 92b3edf3 authored by Jason Crain's avatar Jason Crain Committed by Albert Astals Cid

glib: Add accessor functions for PopplerAttachment

Issue #715
parent b13cd962
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -139,6 +139,19 @@ PopplerAttachment *_poppler_attachment_new(FileSpec *emb_file)
return attachment;
}
/**
* 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
......@@ -153,6 +166,19 @@ GDateTime *poppler_attachment_get_ctime(PopplerAttachment *attachment)
return GET_PRIVATE(attachment)->ctime;
}
/**
* 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;
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment