X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=libdocument%2Fev-attachment.c;h=9f9f4fed534f4cbe04c65fbf9a4fec077fe4cd2e;hb=f4dd355fb0ec24f49be5d8d4321ceeeb9088fd90;hp=02d5f3d22153143c07f636eefef723266f9b3fde;hpb=e912e532fd67211aa87ac79414efb30f30a00fab;p=evince.git diff --git a/libdocument/ev-attachment.c b/libdocument/ev-attachment.c index 02d5f3d2..9f9f4fed 100644 --- a/libdocument/ev-attachment.c +++ b/libdocument/ev-attachment.c @@ -14,12 +14,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -#include +#include #include +#include #include "ev-file-helpers.h" #include "ev-attachment.h" @@ -100,7 +101,7 @@ ev_attachment_finalize (GObject *object) attachment->priv->tmp_file = NULL; } - (* G_OBJECT_CLASS (ev_attachment_parent_class)->finalize) (object); + G_OBJECT_CLASS (ev_attachment_parent_class)->finalize (object); } static void @@ -292,7 +293,7 @@ ev_attachment_save (EvAttachment *attachment, g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); - output_stream = g_file_create (file, 0, NULL, &ioerror); + output_stream = g_file_replace (file, NULL, FALSE, 0, NULL, &ioerror); if (output_stream == NULL) { char *uri; @@ -340,18 +341,29 @@ ev_attachment_save (EvAttachment *attachment, static gboolean ev_attachment_launch_app (EvAttachment *attachment, + GdkScreen *screen, + guint32 timestamp, GError **error) { - gboolean result; - GList *files = NULL; - GError *ioerror = NULL; + gboolean result; + GList *files = NULL; + GAppLaunchContext *context = NULL; + GError *ioerror = NULL; g_assert (G_IS_FILE (attachment->priv->tmp_file)); g_assert (G_IS_APP_INFO (attachment->priv->app)); files = g_list_prepend (files, attachment->priv->tmp_file); + + context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ()); + gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context), screen); + gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context), timestamp); + result = g_app_info_launch (attachment->priv->app, files, - NULL, &ioerror); + context, &ioerror); + + if (context) + g_object_unref (context); if (!result) { g_set_error (error, @@ -374,6 +386,8 @@ ev_attachment_launch_app (EvAttachment *attachment, gboolean ev_attachment_open (EvAttachment *attachment, + GdkScreen *screen, + guint32 timestamp, GError **error) { GAppInfo *app_info; @@ -382,7 +396,7 @@ ev_attachment_open (EvAttachment *attachment, g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE); if (!attachment->priv->app) { - app_info = g_app_info_get_default_for_type (attachment->priv->mime_type, TRUE); + app_info = g_app_info_get_default_for_type (attachment->priv->mime_type, FALSE); attachment->priv->app = app_info; } @@ -396,26 +410,28 @@ ev_attachment_open (EvAttachment *attachment, return FALSE; } - if (attachment->priv->tmp_file && - g_file_query_exists (attachment->priv->tmp_file, NULL)) { - retval = ev_attachment_launch_app (attachment, error); + if (attachment->priv->tmp_file) { + retval = ev_attachment_launch_app (attachment, screen, + timestamp, error); } else { - GFile *tmpdir; + char *template; GFile *file; - - tmpdir = g_file_new_for_path (ev_tmp_dir ()); - file = g_file_get_child (tmpdir, attachment->priv->name); - if (ev_attachment_save (attachment, file, error)) { + /* FIXMEchpe: convert to filename encoding first! */ + template = g_strdup_printf ("%s.XXXXXX", ev_attachment_get_name (attachment)); + file = ev_mkstemp_file (template, error); + g_free (template); + + if (file != NULL && ev_attachment_save (attachment, file, error)) { if (attachment->priv->tmp_file) g_object_unref (attachment->priv->tmp_file); attachment->priv->tmp_file = g_object_ref (file); - retval = ev_attachment_launch_app (attachment, error); + retval = ev_attachment_launch_app (attachment, screen, + timestamp, error); } g_object_unref (file); - g_object_unref (tmpdir); } return retval;