talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit bc7407a0ec3961cccb5186ba7420780f1ce0a8a5
parent 9dab38766bb4f6d32c8818607c4c544ca9acf431
Author: Oliver Lowe <o@olowe.co>
Date:   Thu, 14 Aug 2025 23:15:03 +1000

Only open images with external program

Diffstat:
Msrc/Makefile.am | 4----
Dsrc/image_viewer.c | 493-------------------------------------------------------------------------------
Dsrc/image_viewer.h | 28----------------------------
Msrc/main.c | 5-----
Dsrc/prefs_image_viewer.c | 190-------------------------------------------------------------------------------
Dsrc/prefs_image_viewer.h | 28----------------------------
Msrc/printing.c | 62++------------------------------------------------------------
Msrc/textview.c | 99++++---------------------------------------------------------------------------
8 files changed, 6 insertions(+), 903 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -78,7 +78,6 @@ claws_mail_SOURCES = \ folderview.c \ headerview.c \ html.c \ - image_viewer.c \ imap.c \ imap_gtk.c \ import.c \ @@ -117,7 +116,6 @@ claws_mail_SOURCES = \ prefs_folder_item.c \ prefs_fonts.c \ prefs_gtk.c \ - prefs_image_viewer.c \ prefs_logging.c \ prefs_matcher.c \ prefs_message.c \ @@ -190,7 +188,6 @@ claws_mailinclude_HEADERS = \ folderview.h \ headerview.h \ html.h \ - image_viewer.h \ imap.h \ imap_gtk.h \ import.h \ @@ -231,7 +228,6 @@ claws_mailinclude_HEADERS = \ prefs_folder_item.h \ prefs_fonts.h \ prefs_gtk.h \ - prefs_image_viewer.h \ prefs_logging.h \ prefs_matcher.h \ prefs_message.h \ diff --git a/src/image_viewer.c b/src/image_viewer.c @@ -1,493 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2025 the Claws Mail team and Hiroyuki Yamamoto - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include <glib.h> -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -#include "procmime.h" -#include "utils.h" -#include "mimeview.h" - -#include "prefs_common.h" - -typedef struct _ImageViewer ImageViewer; - -MimeViewerFactory image_viewer_factory; -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); -static void scrolledwin_resize_cb(GtkWidget *scrolledwin, GtkAllocation *alloc, - ImageViewer *imageviewer); -struct _ImageViewer -{ - MimeViewer mimeviewer; - - gchar *file; - MimeInfo *mimeinfo; - gboolean resize_img; - gboolean fit_img_height; - - GtkWidget *scrolledwin; - GtkWidget *image; - GtkWidget *notebook; - GtkWidget *filename; - GtkWidget *filesize; - GtkWidget *error_lbl; - GtkWidget *error_msg; - GtkWidget *content_type; - GtkWidget *load_button; -}; - -static GtkWidget *image_viewer_get_widget(MimeViewer *_mimeviewer) -{ - ImageViewer *imageviewer = (ImageViewer *) _mimeviewer; - - debug_print("image_viewer_get_widget\n"); - - return imageviewer->notebook; -} - -static void image_viewer_load_image(ImageViewer *imageviewer) -{ - GtkAllocation allocation; - GdkPixbufAnimation *animation = NULL; - GdkPixbuf *pixbuf = NULL; - GError *error = NULL; - GInputStream *stream; - - cm_return_if_fail(imageviewer != NULL); - - if (imageviewer->mimeinfo == NULL) - return; - - stream = procmime_get_part_as_inputstream(imageviewer->mimeinfo); - if (stream == NULL) { - g_warning("couldn't get image MIME part"); - return; - } - -#if GDK_PIXBUF_MINOR >= 28 - animation = gdk_pixbuf_animation_new_from_stream(stream, NULL, &error); -#else - pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error); -#endif - g_object_unref(stream); - - if (error) { - g_warning("couldn't load image: %s", error->message); - gtk_label_set_text(GTK_LABEL(imageviewer->error_lbl), _("Error:")); - gtk_label_set_text(GTK_LABEL(imageviewer->error_msg), error->message); - gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 0); - gtk_widget_hide(imageviewer->load_button); - g_error_free(error); - return; - } - -#if GDK_PIXBUF_MINOR >= 28 - if ((animation && gdk_pixbuf_animation_is_static_image(animation)) || - imageviewer->resize_img || imageviewer->fit_img_height) { - pixbuf = gdk_pixbuf_animation_get_static_image(animation); - g_object_ref(pixbuf); - g_object_unref(animation); - animation = NULL; -#else - if (imageviewer->resize_img || imageviewer->fit_img_height) { -#endif - if (imageviewer->resize_img) { - gtk_widget_get_allocation(imageviewer->scrolledwin, &allocation); - pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE, - imageviewer->fit_img_height, - allocation.width, - allocation.height); - } else - pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE, - imageviewer->fit_img_height, - -1, -1); - } - - if (!pixbuf && !animation) { - g_warning("couldn't load the image"); - return; - } - - g_signal_handlers_block_by_func(G_OBJECT(imageviewer->scrolledwin), - G_CALLBACK(scrolledwin_resize_cb), imageviewer); - - if (animation) - gtk_image_set_from_animation(GTK_IMAGE(imageviewer->image), animation); - else - gtk_image_set_from_pixbuf(GTK_IMAGE(imageviewer->image), pixbuf); - - gtk_widget_get_allocation(imageviewer->scrolledwin, &allocation); - gtk_widget_size_allocate(imageviewer->scrolledwin, &allocation); - - gtk_widget_show(imageviewer->image); - - g_signal_handlers_unblock_by_func(G_OBJECT(imageviewer->scrolledwin), - G_CALLBACK(scrolledwin_resize_cb), imageviewer); - - if (pixbuf) - g_object_unref(pixbuf); - if (animation) - g_object_unref(animation); -} - -static void image_viewer_set_notebook_page(MimeViewer *_mimeviewer) -{ - ImageViewer *imageviewer = (ImageViewer *) _mimeviewer; - - if (!prefs_common.display_img) - gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 0); - else - gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 1); -} - -static void image_viewer_show_mimepart(MimeViewer *_mimeviewer, const gchar *file, MimeInfo *mimeinfo) -{ - ImageViewer *imageviewer = (ImageViewer *) _mimeviewer; - - debug_print("image_viewer_show_mimepart\n"); - - image_viewer_clear_viewer(_mimeviewer); - g_free(imageviewer->file); - imageviewer->file = g_strdup(file); - imageviewer->mimeinfo = mimeinfo; - - gtk_label_set_text(GTK_LABEL(imageviewer->filename), - (procmime_mimeinfo_get_parameter(mimeinfo, "name") != NULL)? - procmime_mimeinfo_get_parameter(mimeinfo, "name") : - procmime_mimeinfo_get_parameter(mimeinfo, "filename")); - gtk_label_set_text(GTK_LABEL(imageviewer->filesize), to_human_readable((goffset)mimeinfo->length)); - gtk_label_set_text(GTK_LABEL(imageviewer->content_type), mimeinfo->subtype); - gtk_label_set_text(GTK_LABEL(imageviewer->error_lbl), ""); - gtk_label_set_text(GTK_LABEL(imageviewer->error_msg), ""); - - if (prefs_common.display_img) - image_viewer_load_image(imageviewer); -} - -static void image_viewer_clear_viewer(MimeViewer *_mimeviewer) -{ - ImageViewer *imageviewer = (ImageViewer *) _mimeviewer; - GtkAdjustment *hadj, *vadj; - - debug_print("image_viewer_clear_viewer\n"); - - image_viewer_set_notebook_page(_mimeviewer); - - if (imageviewer->scrolledwin) { - hadj = gtk_scrolled_window_get_hadjustment - (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin)); - if (hadj) { - gtk_adjustment_set_value(hadj, 0.0); - } - vadj = gtk_scrolled_window_get_vadjustment - (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin)); - if (vadj) { - gtk_adjustment_set_value(vadj, 0.0); - } - } - g_free(imageviewer->file); - imageviewer->file = NULL; - imageviewer->mimeinfo = NULL; - imageviewer->resize_img = prefs_common.resize_img; - imageviewer->fit_img_height = prefs_common.fit_img_height; -} - -static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer) -{ - ImageViewer *imageviewer = (ImageViewer *) _mimeviewer; - - debug_print("image_viewer_destroy_viewer\n"); - - image_viewer_clear_viewer(_mimeviewer); - g_object_unref(imageviewer->notebook); - g_free(imageviewer); -} - -void image_viewer_get_resized_size(gint w, gint h, gint aw, gint ah, - gint *sw, gint *sh) -{ - gfloat wratio = 1.0; - gfloat hratio = 1.0; - gfloat ratio = 1.0; - - if (w > aw) - wratio = (gfloat)aw / (gfloat)w; - if (h > ah) - hratio = (gfloat)ah / (gfloat)h; - - ratio = (wratio > hratio) ? hratio : wratio; - - *sw = (gint)(w * ratio); - *sh = (gint)(h * ratio); - - /* be paranoid */ - if (*sw <= 0 || *sh <= 0) { - *sw = w; - *sh = h; - } -} - -static void load_cb(GtkButton *button, ImageViewer *imageviewer) -{ - gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 1); - image_viewer_load_image(imageviewer); -} - -static gboolean image_button_cb(GtkWidget *scrolledwin, GdkEventButton *event, - ImageViewer *imageviewer) -{ - if (event->button == 1 && imageviewer->image) { - imageviewer->resize_img = !imageviewer->resize_img; - image_viewer_load_image(imageviewer); - return TRUE; - } else if (event->button == 3 && imageviewer->image) { - imageviewer->fit_img_height = !imageviewer->fit_img_height; - image_viewer_load_image(imageviewer); - return TRUE; - } - return FALSE; -} - -static void scrolledwin_resize_cb(GtkWidget *scrolledwin, GtkAllocation *alloc, - ImageViewer *imageviewer) -{ - if (imageviewer->resize_img) - image_viewer_load_image(imageviewer); -} - -static MimeViewer *image_viewer_create(void) -{ - ImageViewer *imageviewer; - GtkWidget *notebook; - GtkWidget *table1; - GtkWidget *label3; - GtkWidget *label4; - GtkWidget *filename; - GtkWidget *filesize; - GtkWidget *load_button; - GtkWidget *label5; - GtkWidget *content_type; - GtkWidget *scrolledwin; - GtkWidget *eventbox; - GtkWidget *image; - GtkWidget *error_lbl; - GtkWidget *error_msg; - - notebook = gtk_notebook_new(); - gtk_widget_set_name(GTK_WIDGET(notebook), "image_viewer"); - gtk_widget_show(notebook); - gtk_widget_set_can_focus(notebook, FALSE); - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); - gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE); - - table1 = gtk_grid_new(); - gtk_widget_show(table1); - gtk_container_add(GTK_CONTAINER(notebook), table1); - gtk_container_set_border_width(GTK_CONTAINER(table1), 8); - gtk_grid_set_row_spacing(GTK_GRID(table1), 4); - gtk_grid_set_column_spacing(GTK_GRID(table1), 4); - - label3 = gtk_label_new(_("Filename:")); - gtk_widget_show(label3); - gtk_label_set_xalign(GTK_LABEL(label3), 0.0); - gtk_grid_attach(GTK_GRID(table1), label3, 0, 0, 2, 1); - - filename = gtk_label_new(""); - gtk_widget_show(filename); - gtk_label_set_xalign(GTK_LABEL(filename), 0.0); - gtk_grid_attach(GTK_GRID(table1), filename, 1, 0, 2, 1); - gtk_widget_set_hexpand(filename, TRUE); - gtk_widget_set_halign(filename, GTK_ALIGN_FILL); - - label4 = gtk_label_new(_("Filesize:")); - gtk_widget_show(label4); - gtk_label_set_xalign(GTK_LABEL(label4), 0.0); - gtk_grid_attach(GTK_GRID(table1), label4, 0, 1, 2, 1); - - filesize = gtk_label_new(""); - gtk_widget_show(filesize); - gtk_label_set_xalign(GTK_LABEL(filesize), 0.0); - gtk_grid_attach(GTK_GRID(table1), filesize, 1, 1, 2, 1); - gtk_widget_set_hexpand(filesize, TRUE); - gtk_widget_set_halign(filesize, GTK_ALIGN_FILL); - - label5 = gtk_label_new(_("Content-Type:")); - gtk_widget_show(label5); - gtk_label_set_xalign(GTK_LABEL(label5), 0.0); - gtk_grid_attach(GTK_GRID(table1), label5, 0, 2, 2, 1); - gtk_widget_set_hexpand(label5, TRUE); - gtk_widget_set_halign(label5, GTK_ALIGN_FILL); - - content_type = gtk_label_new(""); - gtk_widget_show(content_type); - gtk_label_set_xalign(GTK_LABEL(content_type), 0.0); - gtk_grid_attach(GTK_GRID(table1), content_type, 1, 2, 2, 1); - gtk_widget_set_hexpand(content_type, TRUE); - gtk_widget_set_halign(content_type, GTK_ALIGN_FILL); - - error_lbl = gtk_label_new(""); - gtk_widget_show(error_lbl); - gtk_label_set_xalign(GTK_LABEL(error_lbl), 0.0); - gtk_grid_attach(GTK_GRID(table1), error_lbl, 0, 3, 2, 1); - gtk_widget_set_hexpand(error_lbl, TRUE); - gtk_widget_set_halign(error_lbl, GTK_ALIGN_FILL); - - error_msg = gtk_label_new(""); - gtk_widget_show(error_msg); - gtk_label_set_xalign(GTK_LABEL(error_msg), 0.0); - gtk_grid_attach(GTK_GRID(table1), error_msg, 1, 3, 2, 1); - gtk_widget_set_hexpand(error_msg, TRUE); - gtk_widget_set_halign(error_msg, GTK_ALIGN_FILL); - - load_button = gtk_button_new_with_label(_("Load Image")); - gtk_widget_show(load_button); - gtk_widget_set_size_request(GTK_WIDGET(load_button), 6, -1); - gtk_grid_attach(GTK_GRID(table1), load_button, 0, 4, 1, 1); - gtk_widget_set_hexpand(load_button, TRUE); - gtk_widget_set_halign(load_button, GTK_ALIGN_START); - - scrolledwin = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_show(scrolledwin); - gtk_container_add(GTK_CONTAINER(notebook), scrolledwin); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolledwin), TRUE); - - eventbox = gtk_event_box_new(); - gtk_widget_show(eventbox); - gtk_container_add(GTK_CONTAINER(scrolledwin), eventbox); - - image = gtk_image_new(); - gtk_container_add( GTK_CONTAINER(eventbox), image); - - debug_print("Creating image view...\n"); - imageviewer = g_new0(ImageViewer, 1); - imageviewer->mimeviewer.factory = &image_viewer_factory; - - imageviewer->mimeviewer.get_widget = image_viewer_get_widget; - imageviewer->mimeviewer.show_mimepart = image_viewer_show_mimepart; - imageviewer->mimeviewer.clear_viewer = image_viewer_clear_viewer; - imageviewer->mimeviewer.destroy_viewer = image_viewer_destroy_viewer; - imageviewer->mimeviewer.get_selection = NULL; - - imageviewer->resize_img = prefs_common.resize_img; - imageviewer->fit_img_height = prefs_common.fit_img_height; - - imageviewer->scrolledwin = scrolledwin; - imageviewer->image = image; - imageviewer->notebook = notebook; - imageviewer->filename = filename; - imageviewer->filesize = filesize; - imageviewer->content_type = content_type; - imageviewer->error_msg = error_msg; - imageviewer->error_lbl = error_lbl; - imageviewer->load_button = load_button; - - g_object_ref(notebook); - - g_signal_connect(G_OBJECT(load_button), "clicked", - G_CALLBACK(load_cb), imageviewer); - g_signal_connect(G_OBJECT(eventbox), "button-press-event", - G_CALLBACK(image_button_cb), imageviewer); - g_signal_connect(G_OBJECT(scrolledwin), "size-allocate", - G_CALLBACK(scrolledwin_resize_cb), imageviewer); - - image_viewer_set_notebook_page((MimeViewer *)imageviewer); - - return (MimeViewer *) imageviewer; -} - -static gchar *content_types[] = - {"image/png", - "image/jpeg", - "image/x-wmf", - "image/x-adobe-dng", - "image/x-canon-cr2", - "image/x-canon-crw", - "image/x-nikon-nef", - "image/x-olympus-orf", - "image/x-pentax-pef", - "image/x-sony-arw", - "image/x-epson-erf", - "image/x-minolta-mrw", - "image/x-fuji-raf", - "application/x-navi-animation", - "image/avif", - "image/bmp", - "image/x-bmp", - "image/x-MS-bmp", - "image/gif", - "image/heif", - "image/heic", - "image/avif", - "image/x-icns", - "image/x-icon", - "image/x-ico", - "image/x-win-bitmap", - "image/vnd.microsoft.icon", - "application/ico", - "image/ico", - "image/icon", - "text/ico", - "image/jxl", - "image/x-portable-anymap", - "image/x-portable-bitmap", - "image/x-portable-graymap", - "image/x-portable-pixmap", - "image/x-quicktime", - "image/qtif", - "image/x-tga", - "image/tiff", - "image/webp", - "audio/x-riff", - "image/x-xbitmap", - "image/x-xpixmap", - "image/svg+xml", - "image/svg", - "image/svg-xml", - "image/vnd.adobe.svg+xml", - "text/xml-svg", - "image/svg+xml-compressed", - NULL }; - -MimeViewerFactory image_viewer_factory = -{ - content_types, - 0, - - image_viewer_create, -}; - -void image_viewer_init(void) -{ - mimeview_register_viewer_factory(&image_viewer_factory); -} - -void image_viewer_done(void) -{ - mimeview_unregister_viewer_factory(&image_viewer_factory); -} diff --git a/src/image_viewer.h b/src/image_viewer.h @@ -1,28 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef IMAGE_VIEWER_H -#define IMAGE_VIEWER_H - -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 diff --git a/src/main.c b/src/main.c @@ -65,14 +65,12 @@ #include "main.h" #include "mainwindow.h" #include "folderview.h" -#include "image_viewer.h" #include "summaryview.h" #include "prefs_common.h" #include "prefs_account.h" #include "prefs_actions.h" #include "prefs_ext_prog.h" #include "prefs_fonts.h" -#include "prefs_image_viewer.h" #include "prefs_message.h" #include "prefs_migration.h" #include "prefs_receive.h" @@ -702,8 +700,6 @@ int main(int argc, char *argv[]) prefs_ext_prog_init(); prefs_wrapping_init(); prefs_compose_writing_init(); - image_viewer_init(); - prefs_image_viewer_init(); prefs_quote_init(); prefs_summaries_init(); prefs_message_init(); @@ -1036,7 +1032,6 @@ static void exit_claws(MainWindow *mainwin) prefs_ext_prog_done(); prefs_wrapping_done(); prefs_compose_writing_done(); - image_viewer_done(); prefs_quote_done(); prefs_summaries_done(); prefs_message_done(); diff --git a/src/prefs_image_viewer.c b/src/prefs_image_viewer.c @@ -1,190 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2020 the Claws Mail Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -#include "common/utils.h" -#include "prefs.h" -#include "prefs_gtk.h" -#include "prefswindow.h" - -#include "prefs_common.h" - -typedef struct _ImageViewerPage -{ - PrefsPage page; - - GtkWidget *window; /* do not modify */ - - GtkWidget *autoload_img; - GtkWidget *resize_img; - GtkWidget *fit_img_height_radiobtn; - GtkWidget *fit_img_width_radiobtn; - GtkWidget *inline_img; - GtkWidget *print_imgs; -}ImageViewerPage; - -static void imageviewer_create_widget_func(PrefsPage * _page, - GtkWindow * window, - gpointer data) -{ - ImageViewerPage *prefs_imageviewer = (ImageViewerPage *) _page; - - GtkWidget *table; - GtkWidget *autoload_img; - GtkWidget *resize_img; - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *fit_img_label; - GtkWidget *fit_img_height_radiobtn; - GtkWidget *fit_img_width_radiobtn; - GtkWidget *inline_img; - GtkWidget *print_imgs; - - table = gtk_grid_new(); - gtk_grid_set_column_homogeneous(GTK_GRID(table), FALSE); - gtk_widget_show(table); - gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER); - gtk_grid_set_row_spacing(GTK_GRID(table), 4); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - autoload_img = gtk_check_button_new_with_label(_("Automatically display attached images")); - gtk_widget_show(autoload_img); - gtk_grid_attach(GTK_GRID(table), autoload_img, 0, 0, 1, 1); - - resize_img = gtk_check_button_new_with_label(_("Resize attached images by default")); - gtk_widget_show(resize_img); - CLAWS_SET_TIP(resize_img, - _("Clicking image toggles scaling")); - gtk_grid_attach(GTK_GRID(table), resize_img, 0, 1, 1, 1); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING); - hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show(vbox); - gtk_widget_show(hbox); - - fit_img_label = gtk_label_new (_("Fit image")); - gtk_widget_set_halign(fit_img_label, GTK_ALIGN_END); - gtk_widget_show(fit_img_label); - CLAWS_SET_TIP(fit_img_label, - _("Right-clicking image toggles fitting height/width")); - gtk_box_pack_start(GTK_BOX(hbox), fit_img_label, FALSE, FALSE, 0); - - fit_img_height_radiobtn = gtk_radio_button_new_with_label(NULL, _("Height")); - gtk_widget_set_halign(fit_img_height_radiobtn, GTK_ALIGN_START); - gtk_widget_show(fit_img_height_radiobtn); - gtk_box_pack_start(GTK_BOX(hbox), fit_img_height_radiobtn, FALSE, FALSE, 0); - - fit_img_width_radiobtn = gtk_radio_button_new_with_label_from_widget( - GTK_RADIO_BUTTON(fit_img_height_radiobtn), _("Width")); - gtk_widget_show(fit_img_width_radiobtn); - gtk_box_pack_start(GTK_BOX(hbox), fit_img_width_radiobtn, FALSE, FALSE, 0); - gtk_grid_attach(GTK_GRID(table), vbox, 0, 2, 1, 1); - - inline_img = gtk_check_button_new_with_label(_("Display images inline")); - gtk_widget_show(inline_img); - gtk_grid_attach(GTK_GRID(table), inline_img, 0, 3, 1, 1); - - print_imgs = gtk_check_button_new_with_label(_("Print images")); - gtk_widget_show(print_imgs); - gtk_grid_attach(GTK_GRID(table), print_imgs, 0, 4, 1, 1); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img); - if (prefs_common.fit_img_height) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_height_radiobtn), TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_width_radiobtn), TRUE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs); - - SET_TOGGLE_SENSITIVITY(resize_img, vbox); - - prefs_imageviewer->window = GTK_WIDGET(window); - prefs_imageviewer->autoload_img = autoload_img; - prefs_imageviewer->resize_img = resize_img; - prefs_imageviewer->fit_img_height_radiobtn = fit_img_height_radiobtn; - prefs_imageviewer->fit_img_width_radiobtn = fit_img_width_radiobtn; - prefs_imageviewer->inline_img = inline_img; - prefs_imageviewer->print_imgs = print_imgs; - - prefs_imageviewer->page.widget = table; -} - -static void imageviewer_destroy_widget_func(PrefsPage *_page) -{ -} - -static void imageviewer_save_func(PrefsPage * _page) -{ - ImageViewerPage *imageviewer = (ImageViewerPage *) _page; - - prefs_common.display_img = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (imageviewer->autoload_img)); - prefs_common.resize_img = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (imageviewer->resize_img)); - prefs_common.fit_img_height = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (imageviewer->fit_img_height_radiobtn)); - prefs_common.inline_img = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (imageviewer->inline_img)); - prefs_common.print_imgs = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (imageviewer->print_imgs)); -} - -ImageViewerPage *prefs_imageviewer; - -void prefs_image_viewer_init(void) -{ - ImageViewerPage *page; - static gchar *path[3]; - - path[0] = _("Message View"); - path[1] = _("Image Viewer"); - path[2] = NULL; - - page = g_new0(ImageViewerPage, 1); - page->page.path = path; - page->page.create_widget = imageviewer_create_widget_func; - page->page.destroy_widget = imageviewer_destroy_widget_func; - page->page.save_page = imageviewer_save_func; - page->page.weight = 160.0; - prefs_gtk_register_page((PrefsPage *) page); - prefs_imageviewer = page; -} - -void prefs_image_viewer_done(void) -{ - prefs_gtk_unregister_page((PrefsPage *) prefs_imageviewer); - g_free(prefs_imageviewer); -} diff --git a/src/prefs_image_viewer.h b/src/prefs_image_viewer.h @@ -1,28 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef PREFS_IMAGE_VIEWER_H -#define PREFS_IMAGE_VIEWER_H - -#include <glib.h> - -void prefs_image_viewer_init (void); -void prefs_image_viewer_done (void); - -#endif diff --git a/src/printing.c b/src/printing.c @@ -25,7 +25,6 @@ #include "defs.h" #include "printing.h" -#include "image_viewer.h" #include "gtkutils.h" #include "toolbar.h" @@ -48,7 +47,6 @@ struct _PrintData { guint npages; gint sel_start; gint sel_end; - GHashTable *images; gint img_cnt; gdouble zoom; gdouble ypos_line; @@ -129,12 +127,6 @@ static gint printing_text_iter_get_offset_bytes(PrintData *, const GtkTextIt #define PREVIEW_ZOOM_MAX 10. #define PREVIEW_ZOOM_MIN 0.2 -static void free_pixbuf(gpointer key, gpointer value, gpointer data) -{ - PangoAttrShape *attr = (PangoAttrShape *) value; - g_object_unref(G_OBJECT(attr->data)); -} - gpointer printing_get_renderer_data(PrintData *print_data) { if (!print_data) @@ -264,8 +256,6 @@ void printing_print_full(GtkWindow *parent, PrintRenderer *renderer, gpointer re print_data->zoom = 1.; - print_data->images = g_hash_table_new(g_direct_hash, g_direct_equal); - print_data->pango_context = renderer->get_pango_context(renderer_data); print_data->to_print = renderer->get_data_to_print(renderer_data, sel_start, sel_end); @@ -297,8 +287,6 @@ void printing_print_full(GtkWindow *parent, PrintRenderer *renderer, gpointer re printing_store_settings(gtk_print_operation_get_print_settings(op)); } - g_hash_table_foreach(print_data->images, free_pixbuf, NULL); - g_hash_table_destroy(print_data->images); if (print_data->to_print) g_free(print_data->to_print); g_list_free(print_data->page_breaks); @@ -927,17 +915,10 @@ static void printing_textview_cb_begin_print(GtkPrintOperation *op, GtkPrintCont do { PangoRectangle logical_rect; - PangoAttrShape *attr = NULL; if (ii >= start) { pango_layout_iter_get_line_extents(iter, NULL, &logical_rect); - - if ((attr = g_hash_table_lookup(print_data->images, - GINT_TO_POINTER(pango_layout_iter_get_index(iter)))) != NULL) { - line_height = (double)gdk_pixbuf_get_height(GDK_PIXBUF(attr->data)); - } else { - line_height = ((double)logical_rect.height) / PANGO_SCALE; - } + line_height = ((double)logical_rect.height) / PANGO_SCALE; } if ((page_height + line_height) > height) { page_breaks = g_list_prepend(page_breaks, GINT_TO_POINTER(ii)); @@ -1078,7 +1059,6 @@ static void printing_textview_cb_draw_page(GtkPrintOperation *op, GtkPrintContex do { PangoRectangle logical_rect; PangoLayoutLine *line; - PangoAttrShape *attr = NULL; int baseline; if (ii >= start) { @@ -1112,19 +1092,7 @@ static void printing_textview_cb_draw_page(GtkPrintOperation *op, GtkPrintContex ((double)logical_rect.x) / PANGO_SCALE, ((double)baseline) / PANGO_SCALE - start_pos); - if ((attr = g_hash_table_lookup(print_data->images, - GINT_TO_POINTER(pango_layout_iter_get_index(iter)))) != NULL) { - cairo_surface_t *surface; - - surface = pixbuf_to_surface(GDK_PIXBUF(attr->data)); - cairo_set_source_surface (cr, surface, - ((double)logical_rect.x) / PANGO_SCALE, - ((double)baseline) / PANGO_SCALE - start_pos); - cairo_paint (cr); - cairo_surface_destroy (surface); - } else { - pango_cairo_show_layout_line(cr, line); - } + pango_cairo_show_layout_line(cr, line); } ii++; } while(ii < end && (notlast = pango_layout_iter_next_line(iter))); @@ -1181,32 +1149,6 @@ static void printing_layout_set_text_attributes(PrintData *print_data, PangoUnderline underline; gboolean strikethrough; gint weight; - GdkPixbuf *image; - - if (prefs_common.print_imgs && (image = gtk_text_iter_get_pixbuf(&iter)) != NULL) { - PangoRectangle rect = {0, 0, 0, 0}; - gint startpos = printing_text_iter_get_offset_bytes(print_data, &iter); - gint h = gdk_pixbuf_get_height(image); - gint w = gdk_pixbuf_get_width(image); - gint a_h = gtk_print_context_get_height(context); - gint a_w = gtk_print_context_get_width(context); - gint r_h, r_w; - GdkPixbuf *scaled = NULL; - image_viewer_get_resized_size(w, h, a_w, a_h, &r_w, &r_h); - rect.x = 0; - rect.y = 0; - rect.width = r_w * PANGO_SCALE; - rect.height = r_h * PANGO_SCALE; - - scaled = gdk_pixbuf_scale_simple(image, r_w, r_h, GDK_INTERP_BILINEAR); - attr = pango_attr_shape_new_with_data (&rect, &rect, - scaled, NULL, NULL); - attr->start_index = startpos; - attr->end_index = startpos+1; - pango_attr_list_insert(attr_list, attr); - g_hash_table_insert(print_data->images, GINT_TO_POINTER(startpos), attr); - print_data->img_cnt++; - } if (gtk_text_iter_ends_tag(&iter, NULL)) { PangoAttrColor *attr_color; diff --git a/src/textview.c b/src/textview.c @@ -55,7 +55,6 @@ #include "mimeview.h" #include "alertpanel.h" #include "menu.h" -#include "image_viewer.h" #include "filesel.h" #include "inputdialog.h" #include "tags.h" @@ -117,6 +116,9 @@ static GdkCursor *watch_cursor= NULL; #define TEXTVIEW_FONT_SIZE_MAX 3100 /* this gives 200 zoom in steps at 15% */ #define TEXTVIEW_FONT_SIZE_UNSET -666 /* default value when unset (must be lower than TEXTVIEW_FONT_SIZE_MIN */ +#define WIDTH 48 +#define HEIGHT 48 + /* font size in session (will apply to next message views we open */ /* must be lower than TEXTVIEW_FONT_SIZE_MIN */ static gint textview_font_size_percent = TEXTVIEW_FONT_SIZE_UNSET; @@ -245,44 +247,14 @@ static GtkActionEntry textview_mail_popup_entries[] = {"TextviewPopupMail/Copy", NULL, N_("Copy this add_ress"), NULL, NULL, G_CALLBACK(copy_mail_to_uri_cb) }, }; -static gboolean move_textview_image_cb (gpointer data) -{ -#ifndef WIDTH -# define WIDTH 48 -# define HEIGHT 48 -#endif - TextView *textview = (TextView *)data; - GtkAllocation allocation; - gint x, wx, wy; - gtk_widget_get_allocation(textview->text, &allocation); - x = allocation.width - WIDTH - 5; - gtk_text_view_buffer_to_window_coords( - GTK_TEXT_VIEW(textview->text), - GTK_TEXT_WINDOW_TEXT, x, 5, &wx, &wy); - gtk_text_view_move_child(GTK_TEXT_VIEW(textview->text), - textview->image, wx, wy); - - return G_SOURCE_REMOVE; -} - static void scrolled_cb (GtkAdjustment *adj, gpointer data) { - TextView *textview = (TextView *)data; - - if (textview->image) { - move_textview_image_cb(textview); - } } static void textview_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer data) { - TextView *textview = (TextView *)data; - - if (textview->image) { - g_timeout_add(0, &move_textview_image_cb, textview); - } } TextView *textview_create(void) @@ -293,7 +265,6 @@ TextView *textview_create(void) GtkWidget *text; GtkTextBuffer *buffer; GtkClipboard *clipboard; - GtkAdjustment *adj; debug_print("Creating text view...\n"); textview = g_new0(TextView, 1); @@ -320,8 +291,6 @@ TextView *textview_create(void) clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); gtk_text_buffer_add_selection_clipboard(buffer, clipboard); - gtk_widget_ensure_style(text); - g_object_ref(scrolledwin); gtk_container_add(GTK_CONTAINER(scrolledwin), text); @@ -334,10 +303,6 @@ TextView *textview_create(void) G_CALLBACK(textview_leave_notify), textview); g_signal_connect(G_OBJECT(text), "visibility-notify-event", G_CALLBACK(textview_visibility_notify), textview); - adj = gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(scrolledwin)); - g_signal_connect(G_OBJECT(adj), "value-changed", - G_CALLBACK(scrolled_cb), textview); g_signal_connect(G_OBJECT(text), "size_allocate", G_CALLBACK(textview_size_allocate_cb), textview); @@ -630,10 +595,9 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp) static void textview_add_part(TextView *textview, MimeInfo *mimeinfo) { - GtkAllocation allocation; GtkTextView *text; GtkTextBuffer *buffer; - GtkTextIter iter, start_iter; + GtkTextIter iter; gchar buf[BUFFSIZE]; GPtrArray *headers = NULL; const gchar *name; @@ -706,58 +670,6 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo) gtk_text_buffer_insert(buffer, &iter, "\n", 1); TEXTVIEW_INSERT_LINK(buf, "cm://select_attachment", mimeinfo); gtk_text_buffer_insert(buffer, &iter, " \n", -1); - if (mimeinfo->type == MIMETYPE_IMAGE && mimeinfo->subtype && - g_ascii_strcasecmp(mimeinfo->subtype, "x-eps") && - prefs_common.inline_img ) { - GdkPixbuf *pixbuf; - GError *error = NULL; - ClickableText *uri; - - - pixbuf = procmime_get_part_as_pixbuf(mimeinfo, &error); - if (error != NULL) { - g_warning("can't load the image: %s", error->message); - g_error_free(error); - return; - } - - if (textview->stop_loading) { - return; - } - - gtk_widget_get_allocation(textview->scrolledwin, &allocation); - pixbuf = claws_load_pixbuf_fitting(pixbuf, prefs_common.inline_img, - prefs_common.fit_img_height, allocation.width, - allocation.height); - - if (textview->stop_loading) { - return; - } - - uri = g_new0(ClickableText, 1); - uri->uri = g_strdup(""); - uri->filename = g_strdup("cm://select_attachment"); - uri->data = mimeinfo; - - uri->start = gtk_text_iter_get_offset(&iter); - gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf); - g_object_unref(pixbuf); - if (textview->stop_loading) { - g_free(uri); - return; - } - uri->end = gtk_text_iter_get_offset(&iter); - - textview->uri_list = - g_slist_prepend(textview->uri_list, uri); - - 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); - - GTK_EVENTS_FLUSH(); - } } else if (mimeinfo->type == MIMETYPE_TEXT) { if (prefs_common.display_header && (charcount > 0)) gtk_text_buffer_insert(buffer, &iter, "\n", 1); @@ -1761,9 +1673,6 @@ void textview_clear(TextView *textview) textview->prev_quote_level = -1; textview->body_pos = 0; - if (textview->image) - gtk_widget_destroy(textview->image); - textview->image = NULL; textview->avatar_type = 0; if (textview->messageview->mainwin->cursor_count == 0) {