static gboolean print_to_pdf (WebKitWebFrame *frame, GError **err) { GtkPrintOperation *op; GtkPrintOperationResult res; char *path; gboolean rv; path = g_strdup_printf ("%s%c%x.pdf",mu_util_cache_dir(), G_DIR_SEPARATOR, (unsigned)random()); if (!mu_util_create_dir_maybe (mu_util_cache_dir(),0700,FALSE)) { g_warning ("Couldn't create tempdir"); return FALSE; } op = gtk_print_operation_new (); gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION(op), path); res = webkit_web_frame_print_full (frame, op, GTK_PRINT_OPERATION_ACTION_EXPORT, err); g_object_unref (op); rv = (res != GTK_PRINT_OPERATION_RESULT_ERROR); if (rv) g_print ("%s\n", path); g_free (path); return rv; }
gchar* mu_msg_part_get_cache_path (MuMsg *msg, MuMsgOptions opts, guint partid, GError **err) { char *dirname, *filepath; const char* path; g_return_val_if_fail (msg, NULL); if (!mu_msg_load_msg_file (msg, NULL)) return NULL; path = mu_msg_get_path (msg); /* g_compute_checksum_for_string may be better, but requires * rel. new glib (2.16) */ dirname = g_strdup_printf ("%s%c%x%c%u", mu_util_cache_dir(), G_DIR_SEPARATOR, g_str_hash (path), G_DIR_SEPARATOR, partid); if (!mu_util_create_dir_maybe (dirname, 0700, FALSE)) { mu_util_g_set_error (err, MU_ERROR_FILE, "failed to create dir %s", dirname); g_free (dirname); return NULL; } filepath = mu_msg_part_get_path (msg, opts, dirname, partid, err); g_free (dirname); return filepath; }