Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12:Update
gnome-documents
pdf-converter-modify.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pdf-converter-modify.patch of Package gnome-documents
diff --git a/src/lib/gd-pdf-loader.c b/src/lib/gd-pdf-loader.c index 2e5d732..5f191b5 100644 --- a/src/lib/gd-pdf-loader.c +++ b/src/lib/gd-pdf-loader.c @@ -39,7 +39,7 @@ typedef struct { EvDocument *document; gchar *uri; gchar *pdf_path; - GPid unoconv_pid; + GPid libreoffice_pid; gchar *passwd; gboolean passwd_tried; @@ -148,9 +148,9 @@ pdf_load_job_free (PdfLoadJob *job) g_free (job->pdf_path); } - if (job->unoconv_pid != -1) { - kill (job->unoconv_pid, SIGKILL); - job->unoconv_pid = -1; + if (job->libreoffice_pid != -1) { + kill (job->libreoffice_pid, SIGKILL); + job->libreoffice_pid = -1; } g_slice_free (PdfLoadJob, job); @@ -168,7 +168,7 @@ pdf_load_job_new (GSimpleAsyncResult *result, retval = g_slice_new0 (PdfLoadJob); retval->result = g_object_ref (result); - retval->unoconv_pid = -1; + retval->libreoffice_pid = -1; retval->unlink_cache = FALSE; retval->from_old_cache = FALSE; @@ -650,18 +650,45 @@ pdf_load_job_from_zpj_cache (PdfLoadJob *job) } static void -unoconv_cancelled_cb (GCancellable *cancellable, +libreoffice_cancelled_cb (GCancellable *cancellable, gpointer user_data) { PdfLoadJob *job = user_data; - /* job->unoconv_pid will be reset by unoconv_child_watch_cb */ - if (job->unoconv_pid != -1) - kill (job->unoconv_pid, SIGKILL); + /* job->libreoffice_pid will be reset by libreoffice_child_watch_cb */ + if (job->libreoffice_pid != -1) + kill (job->libreoffice_pid, SIGKILL); +} + +static void pdf_load_job_cache_set_file_name (PdfLoadJob *job) +{ + GFile *file; + gchar *file_name, *tmp_path, *tmp_name, *index, *tmp; + + file = g_file_new_for_uri (job->uri); + file_name = g_file_get_basename (file); + + index = g_strrstr (file_name,"."); + if (index) { + tmp = g_strndup (file_name, (index-file_name)); + tmp_name = g_strconcat (tmp, ".pdf", NULL); + } else { + tmp_name = g_strconcat (file_name, ".pdf", NULL); + } + + tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL); + tmp_path = g_build_filename (tmp_path, tmp_name, NULL); + g_rename (tmp_path, job->pdf_path); + + g_object_unref (file); + g_free (file_name); + g_free (tmp); + g_free (tmp_name); + g_free (tmp_path); } static void -unoconv_child_watch_cb (GPid pid, +libreoffice_child_watch_cb (GPid pid, gint status, gpointer user_data) { @@ -673,7 +700,7 @@ unoconv_child_watch_cb (GPid pid, } g_spawn_close_pid (pid); - job->unoconv_pid = -1; + job->libreoffice_pid = -1; /* We need to clean up the downloaded file (if any) that was * converted. @@ -692,12 +719,13 @@ unoconv_child_watch_cb (GPid pid, return; } - + + pdf_load_job_cache_set_file_name (job); pdf_load_job_cache_set_attributes (job); } static void -openoffice_missing_unoconv_ready_cb (GObject *source, +openoffice_missing_libreoffice_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { @@ -708,8 +736,8 @@ openoffice_missing_unoconv_ready_cb (GObject *source, if (error != NULL) { GError *local_error; - /* can't install unoconv with packagekit - nothing else we can do */ - g_warning ("unoconv not found, and PackageKit failed to install it with error %s", + /* can't install libreoffice with packagekit - nothing else we can do */ + g_warning ("libreoffice not found, and PackageKit failed to install it with error %s", error->message); local_error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("LibreOffice is required to view this document")); @@ -719,26 +747,26 @@ openoffice_missing_unoconv_ready_cb (GObject *source, return; } - /* now that we have unoconv installed, try again refreshing the cache */ + /* now that we have libreoffice installed, try again refreshing the cache */ pdf_load_job_openoffice_refresh_cache (job); } static void -pdf_load_job_openoffice_missing_unoconv (PdfLoadJob *job) +pdf_load_job_openoffice_missing_libreoffice (PdfLoadJob *job) { GApplication *app = g_application_get_default (); GtkWidget *widget = GTK_WIDGET (gtk_application_get_active_window (GTK_APPLICATION (app))); GDBusConnection *connection = g_application_get_dbus_connection (app); guint xid = 0; GdkWindow *gdk_window; - const gchar *unoconv_path[2]; + const gchar *libreoffice_path[2]; gdk_window = gtk_widget_get_window (widget); if (gdk_window != NULL) xid = GDK_WINDOW_XID (gdk_window); - unoconv_path[0] = "/usr/bin/unoconv"; - unoconv_path[1] = NULL; + libreoffice_path[0] = "/usr/bin/libreoffice"; + libreoffice_path[1] = NULL; g_dbus_connection_call (connection, "org.freedesktop.PackageKit", @@ -747,50 +775,55 @@ pdf_load_job_openoffice_missing_unoconv (PdfLoadJob *job) "InstallProvideFiles", g_variant_new ("(u^ass)", xid, - unoconv_path, + libreoffice_path, "hide-confirm-deps"), NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, job->cancellable, - openoffice_missing_unoconv_ready_cb, + openoffice_missing_libreoffice_ready_cb, job); } static void pdf_load_job_openoffice_refresh_cache (PdfLoadJob *job) { - gchar *doc_path, *cmd, *quoted_path, *unoconv_path; + gchar *doc_path, *cmd, *quoted_path, *libreoffice_path; GFile *file; gint argc; GPid pid; gchar **argv = NULL; GError *error = NULL; + gchar *tmp_path; + - unoconv_path = g_find_program_in_path ("unoconv"); - if (unoconv_path == NULL) + libreoffice_path = g_find_program_in_path ("libreoffice"); + if (libreoffice_path == NULL) { - pdf_load_job_openoffice_missing_unoconv (job); + pdf_load_job_openoffice_missing_libreoffice (job); return; } - g_free (unoconv_path); + g_free (libreoffice_path); /* build the temporary PDF file path */ file = g_file_new_for_uri (job->uri); doc_path = g_file_get_path (file); quoted_path = g_shell_quote (doc_path); + tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL); + g_object_unref (file); g_free (doc_path); - /* call into the unoconv executable to convert the OpenOffice document + /* call into the libreoffice executable to convert the OpenOffice document * to the temporary PDF. */ - cmd = g_strdup_printf ("unoconv -f pdf -o %s %s", job->pdf_path, quoted_path); + cmd = g_strdup_printf ("libreoffice --headless --convert-to pdf --outdir %s %s", tmp_path, quoted_path); g_shell_parse_argv (cmd, &argc, &argv, &error); g_free (cmd); g_free (quoted_path); + g_free (tmp_path); if (error != NULL) { pdf_load_job_complete_error (job, error); @@ -810,12 +843,12 @@ pdf_load_job_openoffice_refresh_cache (PdfLoadJob *job) return; } - /* now watch when the unoconv child process dies */ - g_child_watch_add (pid, unoconv_child_watch_cb, job); - job->unoconv_pid = pid; + /* now watch when the libreoffice child process dies */ + g_child_watch_add (pid, libreoffice_child_watch_cb, job); + job->libreoffice_pid = pid; if (job->cancellable != NULL) - job->cancelled_id = g_cancellable_connect (job->cancellable, G_CALLBACK (unoconv_cancelled_cb), job, NULL); + job->cancelled_id = g_cancellable_connect (job->cancellable, G_CALLBACK (libreoffice_cancelled_cb), job, NULL); } static void
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor