{
MimeViewer mimeviewer;
+ gchar *file;
+ MimeInfo *mimeinfo;
+
GtkWidget *scrolledwin;
GtkWidget *image;
+ GtkWidget *notebook;
+ GtkWidget *filename;
+ GtkWidget *filesize;
+ GtkWidget *content_type;
};
static GtkWidget *image_viewer_get_widget(MimeViewer *_mimeviewer)
debug_print("image_viewer_get_widget\n");
- return imageviewer->scrolledwin;
+ return imageviewer->notebook;
}
#if HAVE_GDK_PIXBUF
-static void image_viewer_show_mimepart(MimeViewer *_mimeviewer, const gchar *file, MimeInfo *mimeinfo)
+static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfile)
{
- ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
GdkPixbuf *pixbuf;
GdkPixbuf *pixbuf_scaled;
GdkPixmap *pixmap;
gint avail_height;
gint new_width;
gint new_height;
- gchar *imgfile;
debug_print("image_viewer_show_mimepart\n");
- g_return_if_fail(imageviewer != NULL);
-
- image_viewer_clear_viewer(_mimeviewer);
-
- imgfile = procmime_get_tmp_file_name(mimeinfo);
- if (procmime_get_part(imgfile, file, mimeinfo) < 0) {
- g_warning("Can't get mimepart file");
- g_free(imgfile);
- return;
- }
-
pixbuf = gdk_pixbuf_new_from_file(imgfile);
- unlink(imgfile);
- g_free(imgfile);
if (!pixbuf) {
g_warning("Can't load the image.");
return;
}
if (imageviewerprefs.resize_img) {
- avail_width = imageviewer->scrolledwin->parent->allocation.width;
- avail_height = imageviewer->scrolledwin->parent->allocation.height;
+ avail_width = imageviewer->notebook->parent->allocation.width;
+ avail_height = imageviewer->notebook->parent->allocation.height;
if (avail_width > 8) avail_width -= 8;
if (avail_height > 8) avail_height -= 8;
}
#else
#if HAVE_GDK_IMLIB
-static void image_viewer_show_mimepart(MimeViewer *_mimeviewer, const gchar *file, MimeInfo *mimeinfo)
+static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfile)
{
- ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
GdkImlibImage *im;
gint avail_width;
gint avail_height;
gint new_width;
gint new_height;
- gchar *imgfile;
debug_print("image_viewer_show_mimepart\n");
- g_return_if_fail(imageviewer != NULL);
-
- image_viewer_clear_viewer(imageviewer);
-
- imgfile = procmime_get_tmp_file_name(mimeinfo);
- if (procmime_get_part(imgfile, file, mimeinfo) < 0) {
- g_warning("Can't get mimepart file");
- g_free(imgfile);
- return;
- }
-
im = gdk_imlib_load_image(imgfile);
- unlink(imgfile);
- g_free(imgfile);
if (!im) {
g_warning("Can't load the image.");
return;
}
if (imageviewerprefs.resize_img) {
- avail_width = imageviewer->scrolledwin->parent->allocation.width;
- avail_height = imageviewer->scrolledwin->parent->allocation.height;
+ avail_width = imageviewer->notebook->parent->allocation.width;
+ avail_height = imageviewer->notebook->parent->allocation.height;
if (avail_width > 8) avail_width -= 8;
if (avail_height > 8) avail_height -= 8;
#endif /* HAVE_GDK_IMLIB */
#endif /* HAVE_GDK_PIXBUF */
+static void image_viewer_set_notebook_page(MimeViewer *_mimeviewer)
+{
+ ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
+
+ if (!imageviewerprefs.display_img)
+ gtk_notebook_set_page(GTK_NOTEBOOK(imageviewer->notebook), 0);
+ else
+ gtk_notebook_set_page(GTK_NOTEBOOK(imageviewer->notebook), 1);
+}
+
+static void image_viewer_load_image(ImageViewer *imageviewer)
+{
+ gchar *imgfile;
+
+ imgfile = procmime_get_tmp_file_name(imageviewer->mimeinfo);
+ if (procmime_get_part(imgfile, imageviewer->file, imageviewer->mimeinfo) < 0) {
+ g_warning("Can't get mimepart file");
+ g_free(imgfile);
+ return;
+ }
+ image_viewer_load_file(imageviewer, imgfile);
+ unlink(imgfile);
+ g_free(imgfile);
+}
+
+static void image_viewer_show_mimepart(MimeViewer *_mimeviewer, const gchar *file, MimeInfo *mimeinfo)
+{
+ ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
+
+ image_viewer_clear_viewer(_mimeviewer);
+ g_free(imageviewer->file);
+ imageviewer->file = g_strdup(file);
+ imageviewer->mimeinfo = mimeinfo;
+
+ if (imageviewerprefs.display_img)
+ image_viewer_load_image(imageviewer);
+ else {
+ gtk_label_set_text(GTK_LABEL(imageviewer->filename), mimeinfo->filename);
+ gtk_label_set_text(GTK_LABEL(imageviewer->filesize), to_human_readable(mimeinfo->size));
+ gtk_label_set_text(GTK_LABEL(imageviewer->content_type), mimeinfo->content_type);
+ }
+}
+
static void image_viewer_clear_viewer(MimeViewer *_mimeviewer)
{
ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
debug_print("image_viewer_clear_viewer\n");
- if (imageviewer->image)
+ image_viewer_set_notebook_page(_mimeviewer);
+
+ if (imageviewer->image != NULL)
gtk_pixmap_set(GTK_PIXMAP(imageviewer->image), NULL, NULL);
hadj = gtk_scrolled_window_get_hadjustment
(GTK_SCROLLED_WINDOW(imageviewer->scrolledwin));
vadj = gtk_scrolled_window_get_vadjustment
(GTK_SCROLLED_WINDOW(imageviewer->scrolledwin));
gtk_adjustment_set_value(vadj, 0.0);
+
+ g_free(imageviewer->file);
+ imageviewer->file = NULL;
+ imageviewer->mimeinfo = NULL;
}
static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer)
debug_print("image_viewer_destroy_viewer\n");
image_viewer_clear_viewer(_mimeviewer);
- gtk_widget_unref(imageviewer->scrolledwin);
+ gtk_widget_unref(imageviewer->notebook);
g_free(imageviewer);
}
}
}
+static void load_cb(GtkButton *button, ImageViewer *imageviewer)
+{
+ gtk_notebook_set_page(GTK_NOTEBOOK(imageviewer->notebook), 1);
+ image_viewer_load_image(imageviewer);
+}
+
MimeViewer *image_viewer_create(void)
{
ImageViewer *imageviewer;
+ /*
+ * glade generated code (do not touch)
+ */
+ GtkWidget *notebook;
+ GtkWidget *table1;
+ GtkWidget *label3;
+ GtkWidget *label4;
+ GtkWidget *filename;
+ GtkWidget *filesize;
+ GtkWidget *load_button;
+ GtkWidget *label5;
+ GtkWidget *content_type;
GtkWidget *scrolledwin;
+ notebook = gtk_notebook_new();
+ gtk_widget_show(notebook);
+ GTK_WIDGET_UNSET_FLAGS(notebook, GTK_CAN_FOCUS);
+ gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
+ gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
+
+ table1 = gtk_table_new(4, 3, FALSE);
+ gtk_widget_show(table1);
+ gtk_container_add(GTK_CONTAINER(notebook), table1);
+ gtk_container_set_border_width(GTK_CONTAINER(table1), 8);
+ gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
+ gtk_table_set_col_spacings(GTK_TABLE(table1), 4);
+
+ label3 = gtk_label_new(_("Filename:"));
+ gtk_widget_show(label3);
+ gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
+
+ label4 = gtk_label_new(_("Filesize:"));
+ gtk_widget_show(label4);
+ gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
+
+ filename = gtk_label_new("");
+ gtk_widget_show(filename);
+ gtk_table_attach(GTK_TABLE(table1), filename, 1, 3, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(filename), 0, 0.5);
+
+ filesize = gtk_label_new("");
+ gtk_widget_show(filesize);
+ gtk_table_attach(GTK_TABLE(table1), filesize, 1, 3, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(filesize), 0, 0.5);
+
+ load_button = gtk_button_new_with_label(_("Load Image"));
+ gtk_widget_show(load_button);
+ gtk_table_attach(GTK_TABLE(table1), load_button, 1, 2, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ label5 = gtk_label_new(_("Content-Type:"));
+ gtk_widget_show(label5);
+ gtk_table_attach(GTK_TABLE(table1), label5, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label5), 0, 0.5);
+
+ content_type = gtk_label_new("");
+ gtk_widget_show(content_type);
+ gtk_table_attach(GTK_TABLE(table1), content_type, 1, 3, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(content_type), 0, 0.5);
+
+ 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);
+ /*
+ * end of glade code
+ */
+
debug_print("Creating image view...\n");
imageviewer = g_new0(ImageViewer, 1);
imageviewer->mimeviewer.factory = &image_viewer_factory;
imageviewer->mimeviewer.clear_viewer = image_viewer_clear_viewer;
imageviewer->mimeviewer.destroy_viewer = image_viewer_destroy_viewer;
- scrolledwin = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_widget_ref(scrolledwin);
-
- gtk_widget_show_all(scrolledwin);
-
imageviewer->scrolledwin = scrolledwin;
imageviewer->image = NULL;
+ imageviewer->notebook = notebook;
+ imageviewer->filename = filename;
+ imageviewer->filesize = filesize;
+ imageviewer->content_type = content_type;
+
+ gtk_widget_ref(notebook);
+
+ gtk_signal_connect(GTK_OBJECT(load_button), "released",
+ GTK_SIGNAL_FUNC(load_cb), imageviewer);
+
+ image_viewer_set_notebook_page((MimeViewer *)imageviewer);
return (MimeViewer *) imageviewer;
}
--- /dev/null
+<?xml version="1.0"?>
+<GTK-Interface>
+
+<project>
+ <name>sylpheed-claws</name>
+ <program_name>sylpheed-claws</program_name>
+ <directory></directory>
+ <source_directory>src</source_directory>
+ <pixmaps_directory>pixmaps</pixmaps_directory>
+ <language>C</language>
+ <gnome_support>False</gnome_support>
+ <gettext_support>True</gettext_support>
+ <output_main_file>False</output_main_file>
+ <output_build_files>False</output_build_files>
+</project>
+
+<widget>
+ <class>GtkWindow</class>
+ <name>imageviewer</name>
+ <border_width>8</border_width>
+ <title>window1</title>
+ <type>GTK_WINDOW_TOPLEVEL</type>
+ <position>GTK_WIN_POS_NONE</position>
+ <modal>False</modal>
+ <allow_shrink>False</allow_shrink>
+ <allow_grow>True</allow_grow>
+ <auto_shrink>False</auto_shrink>
+
+ <widget>
+ <class>GtkNotebook</class>
+ <name>notebook</name>
+ <show_tabs>False</show_tabs>
+ <show_border>False</show_border>
+ <tab_pos>GTK_POS_TOP</tab_pos>
+ <scrollable>False</scrollable>
+ <tab_hborder>2</tab_hborder>
+ <tab_vborder>2</tab_vborder>
+ <popup_enable>False</popup_enable>
+
+ <widget>
+ <class>GtkTable</class>
+ <name>table1</name>
+ <border_width>8</border_width>
+ <rows>4</rows>
+ <columns>3</columns>
+ <homogeneous>False</homogeneous>
+ <row_spacing>4</row_spacing>
+ <column_spacing>4</column_spacing>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>label3</name>
+ <label>Filename:</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>0</left_attach>
+ <right_attach>1</right_attach>
+ <top_attach>0</top_attach>
+ <bottom_attach>1</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>label4</name>
+ <label>Filesize:</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>0</left_attach>
+ <right_attach>1</right_attach>
+ <top_attach>1</top_attach>
+ <bottom_attach>2</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>filename</name>
+ <label></label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>1</left_attach>
+ <right_attach>3</right_attach>
+ <top_attach>0</top_attach>
+ <bottom_attach>1</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>filesize</name>
+ <label></label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>1</left_attach>
+ <right_attach>3</right_attach>
+ <top_attach>1</top_attach>
+ <bottom_attach>2</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkButton</class>
+ <name>load_button</name>
+ <can_focus>True</can_focus>
+ <label>Load Image</label>
+ <relief>GTK_RELIEF_NORMAL</relief>
+ <child>
+ <left_attach>1</left_attach>
+ <right_attach>2</right_attach>
+ <top_attach>3</top_attach>
+ <bottom_attach>4</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>label5</name>
+ <label>Content-Type:</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>0</left_attach>
+ <right_attach>1</right_attach>
+ <top_attach>2</top_attach>
+ <bottom_attach>3</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>content_type</name>
+ <label></label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <left_attach>1</left_attach>
+ <right_attach>3</right_attach>
+ <top_attach>2</top_attach>
+ <bottom_attach>3</bottom_attach>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <xexpand>False</xexpand>
+ <yexpand>False</yexpand>
+ <xshrink>False</xshrink>
+ <yshrink>False</yshrink>
+ <xfill>True</xfill>
+ <yfill>False</yfill>
+ </child>
+ </widget>
+ </widget>
+
+ <widget>
+ <class>Placeholder</class>
+ <child_name>Notebook:tab</child_name>
+ </widget>
+
+ <widget>
+ <class>GtkScrolledWindow</class>
+ <name>scrolledwin</name>
+ <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
+ <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
+ <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
+ <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
+
+ <widget>
+ <class>Placeholder</class>
+ </widget>
+ </widget>
+
+ <widget>
+ <class>Placeholder</class>
+ <child_name>Notebook:tab</child_name>
+ </widget>
+ </widget>
+</widget>
+
+</GTK-Interface>