2005-04-01 [colin] 1.9.6cvs20
authorColin Leroy <colin@colino.net>
Fri, 1 Apr 2005 08:16:46 +0000 (08:16 +0000)
committerColin Leroy <colin@colino.net>
Fri, 1 Apr 2005 08:16:46 +0000 (08:16 +0000)
* src/image_viewer.c
* src/image_viewer.h
* src/procmime.c
* src/procmime.h
* src/textview.c
* src/textview.h
Implement inline image resizing and right-clicking

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/image_viewer.c
src/image_viewer.h
src/procmime.c
src/procmime.h
src/textview.c
src/textview.h

index 7f886cf..c1c4f80 100644 (file)
@@ -1,3 +1,13 @@
+2005-04-01 [colin]     1.9.6cvs20
+
+       * src/image_viewer.c
+       * src/image_viewer.h
+       * src/procmime.c
+       * src/procmime.h
+       * src/textview.c
+       * src/textview.h
+               Implement inline image resizing and right-clicking
+
 2005-04-01 [paul]      1.9.6cvs19
 
        * AUTHORS
index 23db78c..3555d36 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.382.2.115 -r 1.382.2.116 src/compose.c; ) > 1.9.6cvs17.patchset
 ( cvs diff -u -r 1.101.2.10 -r 1.101.2.11 src/news.c; cvs diff -u -r 1.16.2.16 -r 1.16.2.17 src/msgcache.c; cvs diff -u -r 1.47.2.18 -r 1.47.2.19 src/procheader.c; ) > 1.9.6cvs18.patchset
 ( cvs diff -u -r 1.100.2.15 -r 1.100.2.16 AUTHORS; cvs diff -u -r 1.24.2.6 -r 1.24.2.7 Makefile.am; cvs diff -u -r 1.654.2.471 -r 1.654.2.472 configure.ac; cvs diff -u -r 1.17.2.7 -r 1.17.2.8 po/ru.po; ) > 1.9.6cvs19.patchset
+( cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/image_viewer.c; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/image_viewer.h; cvs diff -u -r 1.49.2.37 -r 1.49.2.38 src/procmime.c; cvs diff -u -r 1.17.2.8 -r 1.17.2.9 src/procmime.h; cvs diff -u -r 1.96.2.51 -r 1.96.2.52 src/textview.c; cvs diff -u -r 1.12.2.4 -r 1.12.2.5 src/textview.h; ) > 1.9.6cvs20.patchset
index 9e151e7..4afbff4 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=19
+EXTRA_VERSION=20
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index d504347..95917c7 100644 (file)
@@ -35,7 +35,7 @@
 typedef struct _ImageViewer ImageViewer;
 
 MimeViewerFactory image_viewer_factory;
-static void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah,
+void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah,
                                          gint * sw, gint * sh);
 static void image_viewer_clear_viewer(MimeViewer *imageviewer);
 
@@ -203,7 +203,7 @@ static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer)
        g_free(imageviewer);
 }
 
-static void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah,
+void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah,
                             gint *sw, gint *sh)
 {
        gfloat wratio = 1.0;
index 6bd1a8a..eb9fe2a 100644 (file)
@@ -22,5 +22,7 @@
 
 void image_viewer_init (void);
 void image_viewer_done (void);
+void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah,
+                            gint *sw, gint *sh);
 
 #endif
index 7a2732a..48178f3 100644 (file)
@@ -2051,3 +2051,33 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
 
        return 0;
 }
+
+gchar *procmime_get_part_file_name(MimeInfo *mimeinfo)
+{
+       gchar *base;
+       const gchar *base_;
+
+       if ((mimeinfo->type == MIMETYPE_TEXT) && !g_ascii_strcasecmp(mimeinfo->subtype, "html"))
+               base = g_strdup("mimetmp.html");
+       else {
+               const gchar *basetmp;
+               gchar *basename;
+
+               basetmp = procmime_mimeinfo_get_parameter(mimeinfo, "filename");
+               if (basetmp == NULL)
+                       basetmp = procmime_mimeinfo_get_parameter(mimeinfo, "name");
+               if (basetmp == NULL)
+                       basetmp = "mimetmp";
+               basename = g_path_get_basename(basetmp);
+               if (*basename == '\0') {
+                       g_free(basename);
+                       basename = g_strdup("mimetmp");
+               }
+               base = conv_filename_from_utf8(basename);
+               g_free(basename);
+               subst_for_shellsafe_filename(base);
+       }
+       
+       return base;
+}
+
index ec5da02..f6d7e26 100644 (file)
@@ -198,6 +198,7 @@ gboolean procmime_find_string               (MsgInfo        *msginfo,
                                         StrFindFunc     find_func);
 
 gchar *procmime_get_tmp_file_name      (MimeInfo       *mimeinfo);
+gchar *procmime_get_part_file_name     (MimeInfo       *mimeinfo);
 
 gchar *procmime_get_mime_type          (const gchar    *filename);
 
index a83eccb..2a3404c 100644 (file)
 #include "mimeview.h"
 #include "alertpanel.h"
 #include "menu.h"
+#include "image_viewer.h"
+#include "filesel.h"
 
 struct _RemoteURI
 {
        gchar *uri;
 
+       gchar *filename;
+
        guint start;
        guint end;
 };
@@ -201,6 +205,9 @@ static void mail_to_uri_cb                  (TextView       *textview,
 static void copy_mail_to_uri_cb                        (TextView       *textview,
                                                 guint           action,
                                                 void           *data);
+static void save_file_cb                       (TextView       *textview,
+                                                guint           action,
+                                                void           *data);
 
 static GtkItemFactoryEntry textview_link_popup_entries[] = 
 {
@@ -215,6 +222,11 @@ static GtkItemFactoryEntry textview_mail_popup_entries[] =
        {N_("/_Copy"),                  NULL, copy_mail_to_uri_cb, 0, NULL},
 };
 
+static GtkItemFactoryEntry textview_file_popup_entries[] = 
+{
+       {N_("/_Save this image..."),            NULL, save_file_cb, 0, NULL},
+};
+
 
 TextView *textview_create(void)
 {
@@ -224,8 +236,8 @@ TextView *textview_create(void)
        GtkWidget *text;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
-       GtkItemFactory *link_popupfactory, *mail_popupfactory;
-       GtkWidget *link_popupmenu, *mail_popupmenu;
+       GtkItemFactory *link_popupfactory, *mail_popupfactory, *file_popupfactory;
+       GtkWidget *link_popupmenu, *mail_popupmenu, *file_popupmenu;
        gint n_entries;
 
        debug_print("Creating text view...\n");
@@ -288,6 +300,12 @@ TextView *textview_create(void)
                                      "<UriPopupMenu>", &mail_popupfactory,
                                      textview);
 
+       n_entries = sizeof(textview_file_popup_entries) /
+               sizeof(textview_file_popup_entries[0]);
+       file_popupmenu = menu_create_items(textview_file_popup_entries, n_entries,
+                                     "<FilePopupMenu>", &file_popupfactory,
+                                     textview);
+
        textview->vbox               = vbox;
        textview->scrolledwin        = scrolledwin;
        textview->text               = text;
@@ -299,6 +317,8 @@ TextView *textview_create(void)
        textview->link_popup_factory = link_popupfactory;
        textview->mail_popup_menu    = mail_popupmenu;
        textview->mail_popup_factory = mail_popupfactory;
+       textview->file_popup_menu    = file_popupmenu;
+       textview->file_popup_factory = file_popupfactory;
 
        return textview;
 }
@@ -445,7 +465,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
 {
        GtkTextView *text;
        GtkTextBuffer *buffer;
-       GtkTextIter iter;
+       GtkTextIter iter, start_iter;
        gchar buf[BUFFSIZE];
        GPtrArray *headers = NULL;
        const gchar *name;
@@ -522,28 +542,42 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                return;
                        }
 
-                       /* if (prefs_common.resize_img) {
+                       if (prefs_common.resize_img) {
+                               int new_width, new_height;
                                GdkPixbuf *scaled;
+                               image_viewer_get_resized_size(gdk_pixbuf_get_width(pixbuf),
+                                                gdk_pixbuf_get_height(pixbuf),
+                                                textview->scrolledwin->allocation.width - 100, 
+                                                gdk_pixbuf_get_height(pixbuf),
+                                                &new_width, &new_height);
+                               scaled = gdk_pixbuf_scale_simple
+                                       (pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
 
-                               scaled = imageview_get_resized_pixbuf
-                                       (pixbuf, textview->text, 8);
                                g_object_unref(pixbuf);
                                pixbuf = scaled;
-                       } */
+                       }
 
-                       /* uri_str = g_filename_to_uri(filename, NULL, NULL);
+                       uri_str = g_filename_to_uri(filename, NULL, NULL);
                        if (uri_str) {
                                uri = g_new(RemoteURI, 1);
                                uri->uri = uri_str;
-                               uri->filename =
-                                       procmime_get_part_file_name(mimeinfo);
                                uri->start = gtk_text_iter_get_offset(&iter);
+                               
+                               gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+                               
                                uri->end = uri->start + 1;
+                               uri->filename = procmime_get_part_file_name(mimeinfo);
                                textview->uri_list =
                                        g_slist_append(textview->uri_list, uri);
-                       } */
-                       gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
-                       gtk_text_buffer_insert(buffer, &iter, "\n", 1);
+                               
+                               gtk_text_buffer_insert(buffer, &iter, " ", 1);
+                               gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, uri->start);    
+                               gtk_text_buffer_apply_tag_by_name(buffer, "link", 
+                                               &start_iter, &iter);
+                       } else {
+                               gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+                               gtk_text_buffer_insert(buffer, &iter, " ", 1);
+                       }
 
                        g_object_unref(pixbuf);
                        g_free(filename);
@@ -1211,6 +1245,7 @@ static void textview_make_clickable_parts(TextView *textview,
                                (buffer, &iter, last->bp, last->ep - last->bp,
                                 uri_tag, fg_tag, NULL);
                        uri->end = gtk_text_iter_get_offset(&iter);
+                       uri->filename = NULL;
                        textview->uri_list =
                                g_slist_append(textview->uri_list, uri);
                }
@@ -1326,6 +1361,7 @@ void textview_write_link(TextView *textview, const gchar *str,
        gtk_text_buffer_insert_with_tags_by_name
                (buffer, &iter, bufp, -1, "link", NULL);
        r_uri->end = gtk_text_iter_get_offset(&iter);
+       r_uri->filename = NULL;
        textview->uri_list = g_slist_append(textview->uri_list, r_uri);
 }
 
@@ -2074,7 +2110,7 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                                compose_new(account, uri->uri + 7, NULL);
                        }
                        return TRUE;
-               } else {
+               } else if (g_ascii_strncasecmp(uri->uri, "file:", 5)) {
                        if (bevent->button == 1 &&
                            textview_uri_security_check(textview, uri) == TRUE) 
                                        open_uri(uri->uri,
@@ -2088,6 +2124,16 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                                               bevent->button, bevent->time);
                        }
                        return TRUE;
+               } else {
+                       if (bevent->button == 3) {
+                               g_object_set_data(
+                                       G_OBJECT(textview->file_popup_menu),
+                                       "menu_button", uri);
+                               gtk_menu_popup(GTK_MENU(textview->file_popup_menu), 
+                                              NULL, NULL, NULL, NULL, 
+                                              bevent->button, bevent->time);
+                               return TRUE;
+                       }
                }
        }
 
@@ -2163,6 +2209,7 @@ static void textview_uri_list_remove_all(GSList *uri_list)
        for (cur = uri_list; cur != NULL; cur = cur->next) {
                if (cur->data) {
                        g_free(((RemoteURI *)cur->data)->uri);
+                       g_free(((RemoteURI *)cur->data)->filename);
                        g_free(cur->data);
                }
        }
@@ -2184,6 +2231,75 @@ static void open_uri_cb (TextView *textview, guint action, void *data)
                          NULL);
 }
 
+static void save_file_cb (TextView *textview, guint action, void *data)
+{
+       RemoteURI *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
+                                          "menu_button");
+       gchar *filename = NULL;
+       gchar *filepath = NULL;
+       gchar *filedir = NULL;
+       gchar *tmp_filename = NULL;
+       if (uri == NULL)
+               return;
+
+       if (uri->filename == NULL)
+               return;
+       
+       filename = g_strdup(uri->filename);
+       
+       if (!g_utf8_validate(filename, -1, NULL)) {
+               gchar *tmp = conv_filename_to_utf8(filename);
+               g_free(filename);
+               filename = tmp;
+       }
+
+       subst_for_filename(filename);
+       
+       if (prefs_common.attach_save_dir)
+               filepath = g_strconcat(prefs_common.attach_save_dir,
+                                      G_DIR_SEPARATOR_S, filename, NULL);
+       else
+               filepath = g_strdup(filename);
+
+       g_free(filename);
+
+       filename = filesel_select_file_save(_("Save as"), filepath);
+       if (!filename) {
+               g_free(filepath);
+               return;
+       }
+
+       if (is_file_exist(filename)) {
+               AlertValue aval;
+               gchar *res;
+               
+               res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                     filename);
+               aval = alertpanel(_("Overwrite"), res, GTK_STOCK_OK, 
+                                 GTK_STOCK_CANCEL, NULL);
+               g_free(res);                                      
+               if (G_ALERTDEFAULT != aval) 
+                       return;
+       }
+
+       tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
+       copy_file(tmp_filename, filename, FALSE);
+       g_free(tmp_filename);
+       
+       filedir = g_path_get_dirname(filename);
+       if (filedir && strcmp(filedir, ".")) {
+               if (prefs_common.attach_save_dir)
+                       g_free(prefs_common.attach_save_dir);
+               prefs_common.attach_save_dir = g_strdup(filedir);
+       }
+
+       g_free(filedir);
+       g_free(filepath);
+
+       g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
+                         NULL);
+}
+
 static void copy_uri_cb        (TextView *textview, guint action, void *data)
 {
        RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
index 22af79d..e6b78e6 100644 (file)
@@ -44,6 +44,8 @@ struct _TextView
        GtkItemFactory *link_popup_factory;
        GtkWidget *mail_popup_menu;
        GtkItemFactory *mail_popup_factory;
+       GtkWidget *file_popup_menu;
+       GtkItemFactory *file_popup_factory;
 
        gboolean default_text;
        gboolean is_in_signature;