Ejemplo n.º 1
0
void
test_attachment_save (void)
{
  GList *attachments, *node;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  attachments = poppler_document_get_attachments (document);
  gcut_take_list (attachments, attachment_unref);
  for (node = attachments; node; node = g_list_next (node))
    {
      PopplerAttachment *attachment = node->data;
      const gchar *filename;
      gchar *contents;
      const gchar *expected_contents;
      GError *error = NULL;

      filename = cut_take_string (g_build_filename (tmp_dir,
                                                    attachment->name,
                                                    NULL));
      poppler_attachment_save (attachment, filename, &error);
      gcut_assert_error (error);

      g_file_get_contents (filename, &contents, NULL, &error);
      gcut_assert_error (error);
      expected_contents = cut_get_fixture_data_string (attachment->name, NULL);
      cut_set_message ("%s", attachment->name);
      cut_assert_equal_string_with_free (expected_contents, contents);
    }
}
Ejemplo n.º 2
0
zathura_error_t
pdf_document_attachment_save(zathura_document_t* document,
    PopplerDocument* poppler_document, const char* attachmentname, const char* file)
{
  if (document == NULL || poppler_document == NULL) {
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }

  if (poppler_document_has_attachments(poppler_document) == FALSE) {
    girara_warning("PDF file has no attachments");
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }


  GList* attachment_list = poppler_document_get_attachments(poppler_document);
  GList* attachments;

  for (attachments = attachment_list; attachments; attachments = g_list_next(attachments)) {
    PopplerAttachment* attachment = (PopplerAttachment*) attachments->data;
    if (g_strcmp0(attachment->name, attachmentname) != 0) {
      continue;
    }

    return poppler_attachment_save(attachment, file, NULL);
  }

  return ZATHURA_ERROR_OK;
}
Ejemplo n.º 3
0
static void
pgd_annots_file_attachment_save_dialog_response (GtkFileChooser    *file_chooser,
						 gint               response,
						 PopplerAttachment *attachment)
{
    gchar  *filename;
    GError *error = NULL;

    if (response != GTK_RESPONSE_ACCEPT) {
        g_object_unref (attachment);
	gtk_widget_destroy (GTK_WIDGET (file_chooser));
	return;
    }

    filename = gtk_file_chooser_get_filename (file_chooser);
    if (!poppler_attachment_save (attachment, filename, &error)) {
        g_warning ("%s", error->message);
	g_error_free (error);
    }
    g_free (filename);
    g_object_unref (attachment);
    gtk_widget_destroy (GTK_WIDGET (file_chooser));
}