]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-sidebar-attachments.c
Updated French translation by Robert-André Mauchin.
[evince.git] / shell / ev-sidebar-attachments.c
index e735b131ce0a29e69836d226ffff34f0ed957dd4..fa64fbce9561b4835e0c7a4bd9036903953dca8c 100644 (file)
 #include "config.h"
 #endif
 
 #include "config.h"
 #endif
 
+#include <string.h>
+
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
-#include <string.h>
-#include <libgnomeui/gnome-icon-lookup.h>
 
 
+#include "ev-jobs.h"
+#include "ev-job-scheduler.h"
 #include "ev-file-helpers.h"
 #include "ev-sidebar-attachments.h"
 #include "ev-sidebar-page.h"
 #include "ev-file-helpers.h"
 #include "ev-sidebar-attachments.h"
 #include "ev-sidebar-page.h"
@@ -99,20 +101,28 @@ static GdkPixbuf *
 icon_theme_get_pixbuf_from_mime_type (GtkIconTheme *icon_theme,
                                      const gchar  *mime_type)
 {
 icon_theme_get_pixbuf_from_mime_type (GtkIconTheme *icon_theme,
                                      const gchar  *mime_type)
 {
-       GdkPixbuf *pixbuf = NULL;
-       gchar     *icon;
-
-       icon = gnome_icon_lookup (icon_theme,
-                                 NULL, NULL,
-                                 NULL, NULL,
-                                 mime_type,
-                                 GNOME_ICON_LOOKUP_FLAGS_NONE,
-                                 NULL);
-
-       pixbuf = gtk_icon_theme_load_icon (icon_theme,
-                                          icon, 48, 0, NULL);
-       g_free (icon);
-
+       const char *separator;
+       GString *icon_name;
+       GdkPixbuf *pixbuf;
+
+       separator = strchr (mime_type, '/');
+       if (!separator)
+               return NULL; /* maybe we should return a GError with "invalid MIME-type" */
+
+       icon_name = g_string_new ("gnome-mime-");
+       g_string_append_len (icon_name, mime_type, separator - mime_type);
+       g_string_append_c (icon_name, '-');
+       g_string_append (icon_name, separator + 1);
+       pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str, 48, 0, NULL);
+       g_string_free (icon_name, TRUE);
+       if (pixbuf)
+               return pixbuf;
+       
+       icon_name = g_string_new ("gnome-mime-");
+       g_string_append_len (icon_name, mime_type, separator - mime_type);
+       pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str, 48, 0, NULL);
+       g_string_free (icon_name, TRUE);
+       
        return pixbuf;
 }
 
        return pixbuf;
 }
 
@@ -288,7 +298,7 @@ ev_sidebar_attachments_button_press (EvSidebarAttachments *ev_attachbar,
                                ev_attachment_open (attachment, &error);
                                
                                if (error) {
                                ev_attachment_open (attachment, &error);
                                
                                if (error) {
-                                       g_warning (error->message);
+                                       g_warning ("%s", error->message);
                                        g_error_free (error);
                                }
                                
                                        g_error_free (error);
                                }
                                
@@ -399,7 +409,8 @@ ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
                EvAttachment *attachment;
                GtkTreePath  *path;
                GtkTreeIter   iter;
                EvAttachment *attachment;
                GtkTreePath  *path;
                GtkTreeIter   iter;
-               gchar        *uri, *filename;
+               GFile        *file;
+               gchar        *filename;
                GError       *error = NULL;
                
                path = (GtkTreePath *) l->data;
                GError       *error = NULL;
                
                path = (GtkTreePath *) l->data;
@@ -413,21 +424,25 @@ ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
                filename = g_build_filename (ev_tmp_dir (),
                                             ev_attachment_get_name (attachment),
                                             NULL);
                filename = g_build_filename (ev_tmp_dir (),
                                             ev_attachment_get_name (attachment),
                                             NULL);
+               file = g_file_new_for_path (filename);
+               g_free (filename);
                
                
-               uri = g_filename_to_uri (filename, NULL, NULL);
+               if (ev_attachment_save (attachment, file, &error)) {
+                       gchar *uri;
 
 
-               if (ev_attachment_save (attachment, filename, &error)) {
+                       uri = g_file_get_uri (file);
                        g_string_append (uri_list, uri);
                        g_string_append_c (uri_list, '\n');
                        g_string_append (uri_list, uri);
                        g_string_append_c (uri_list, '\n');
+                       g_free (uri);
                }
        
                if (error) {
                }
        
                if (error) {
-                       g_warning (error->message);
+                       g_warning ("%s", error->message);
                        g_error_free (error);
                }
 
                        g_error_free (error);
                }
 
-               g_free (uri);
                gtk_tree_path_free (path);
                gtk_tree_path_free (path);
+               g_object_unref (file);
                g_object_unref (attachment);
        }
 
                g_object_unref (attachment);
        }
 
@@ -600,32 +615,12 @@ ev_sidebar_attachments_new (void)
 }
 
 static void
 }
 
 static void
-ev_sidebar_attachments_set_document (EvSidebarPage   *page,
-                                    EvDocument      *document)
+job_finished_callback (EvJobAttachments     *job,
+                      EvSidebarAttachments *ev_attachbar)
 {
 {
-       EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
-       GList *attachments = NULL;
        GList *l;
        
        GList *l;
        
-       if (!ev_document_has_attachments (document))
-               return;
-
-       if (!ev_attachbar->priv->icon_theme) {
-               GdkScreen *screen;
-
-               screen = gtk_widget_get_screen (GTK_WIDGET (ev_attachbar));
-               ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
-               g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_theme),
-                                         "changed",
-                                         G_CALLBACK (ev_sidebar_attachments_update_icons),
-                                         (gpointer) ev_attachbar);
-       }
-               
-       attachments = ev_document_get_attachments (document);
-
-       gtk_list_store_clear (ev_attachbar->priv->model);
-                                          
-       for (l = attachments; l && l->data; l = g_list_next (l)) {
+       for (l = job->attachments; l && l->data; l = g_list_next (l)) {
                EvAttachment *attachment;
                GtkTreeIter   iter;
                GdkPixbuf    *pixbuf = NULL;
                EvAttachment *attachment;
                GtkTreeIter   iter;
                GdkPixbuf    *pixbuf = NULL;
@@ -643,11 +638,43 @@ ev_sidebar_attachments_set_document (EvSidebarPage   *page,
                                    COLUMN_ICON, pixbuf,
                                    COLUMN_ATTACHMENT, attachment, 
                                    -1);
                                    COLUMN_ICON, pixbuf,
                                    COLUMN_ATTACHMENT, attachment, 
                                    -1);
+       }
 
 
-               g_object_unref (attachment);
+       g_object_unref (job);
+}
+
+static void
+ev_sidebar_attachments_set_document (EvSidebarPage   *page,
+                                    EvDocument      *document)
+{
+       EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
+       EvJob *job;
+       
+       if (!ev_document_has_attachments (document))
+               return;
+
+       if (!ev_attachbar->priv->icon_theme) {
+               GdkScreen *screen;
+
+               screen = gtk_widget_get_screen (GTK_WIDGET (ev_attachbar));
+               ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
+               g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_theme),
+                                         "changed",
+                                         G_CALLBACK (ev_sidebar_attachments_update_icons),
+                                         (gpointer) ev_attachbar);
        }
        }
+               
+       gtk_list_store_clear (ev_attachbar->priv->model);
 
 
-       g_list_free (attachments);
+       job = ev_job_attachments_new (document);
+       g_signal_connect (job, "finished",
+                         G_CALLBACK (job_finished_callback),
+                         ev_attachbar);
+       g_signal_connect (job, "cancelled",
+                         G_CALLBACK (g_object_unref),
+                         NULL);
+       /* The priority doesn't matter for this job */
+       ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
 }
 
 static gboolean
 }
 
 static gboolean