root / src / sourcewindow.c @ 1041
History | View | Annotate | Download (5.3 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 1 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 27 | hiro | * Copyright (C) 1999-2005 Hiroyuki Yamamoto |
| 4 | 1 | hiro | * |
| 5 | 1 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 1 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 1 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 1 | hiro | * (at your option) any later version. |
| 9 | 1 | hiro | * |
| 10 | 1 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 1 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 1 | hiro | * GNU General Public License for more details. |
| 14 | 1 | hiro | * |
| 15 | 1 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 1 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 1 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 1 | hiro | */ |
| 19 | 1 | hiro | |
| 20 | 1 | hiro | #include "defs.h" |
| 21 | 1 | hiro | |
| 22 | 1 | hiro | #include <glib.h> |
| 23 | 92 | hiro | #include <glib/gi18n.h> |
| 24 | 1 | hiro | #include <gdk/gdkkeysyms.h> |
| 25 | 1 | hiro | #include <gtk/gtkwidget.h> |
| 26 | 1 | hiro | #include <gtk/gtkwindow.h> |
| 27 | 1 | hiro | #include <gtk/gtksignal.h> |
| 28 | 1 | hiro | #include <gtk/gtkscrolledwindow.h> |
| 29 | 1 | hiro | #include <gtk/gtktextview.h> |
| 30 | 1 | hiro | #include <gtk/gtkstyle.h> |
| 31 | 1 | hiro | #include <stdio.h> |
| 32 | 1 | hiro | #include <stdlib.h> |
| 33 | 1 | hiro | |
| 34 | 1 | hiro | #include "sourcewindow.h" |
| 35 | 1 | hiro | #include "procmsg.h" |
| 36 | 543 | hiro | #include "codeconv.h" |
| 37 | 1 | hiro | #include "utils.h" |
| 38 | 1 | hiro | #include "gtkutils.h" |
| 39 | 1 | hiro | #include "prefs_common.h" |
| 40 | 1 | hiro | |
| 41 | 1 | hiro | static void source_window_size_alloc_cb (GtkWidget *widget, |
| 42 | 1 | hiro | GtkAllocation *allocation); |
| 43 | 316 | hiro | static gint source_window_delete_cb (GtkWidget *widget,
|
| 44 | 316 | hiro | GdkEventAny *event, |
| 45 | 1 | hiro | SourceWindow *sourcewin); |
| 46 | 1 | hiro | static gboolean key_pressed (GtkWidget *widget,
|
| 47 | 1 | hiro | GdkEventKey *event, |
| 48 | 1 | hiro | SourceWindow *sourcewin); |
| 49 | 1 | hiro | |
| 50 | 1 | hiro | static void source_window_init() |
| 51 | 1 | hiro | {
|
| 52 | 1 | hiro | } |
| 53 | 1 | hiro | |
| 54 | 1 | hiro | SourceWindow *source_window_create(void)
|
| 55 | 1 | hiro | {
|
| 56 | 1 | hiro | SourceWindow *sourcewin; |
| 57 | 1 | hiro | GtkWidget *window; |
| 58 | 1 | hiro | GtkWidget *scrolledwin; |
| 59 | 1 | hiro | GtkWidget *text; |
| 60 | 1 | hiro | static PangoFontDescription *font_desc = NULL; |
| 61 | 1 | hiro | |
| 62 | 1 | hiro | debug_print(_("Creating source window...\n"));
|
| 63 | 1 | hiro | sourcewin = g_new0(SourceWindow, 1);
|
| 64 | 1 | hiro | |
| 65 | 1 | hiro | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 66 | 1 | hiro | gtk_window_set_title(GTK_WINDOW(window), _("Source of the message"));
|
| 67 | 1 | hiro | gtk_window_set_wmclass(GTK_WINDOW(window), "source_window", "Sylpheed"); |
| 68 | 1 | hiro | gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE); |
| 69 | 1 | hiro | gtk_widget_set_size_request(window, prefs_common.sourcewin_width, |
| 70 | 1 | hiro | prefs_common.sourcewin_height); |
| 71 | 1 | hiro | g_signal_connect(G_OBJECT(window), "size_allocate",
|
| 72 | 1 | hiro | G_CALLBACK(source_window_size_alloc_cb), sourcewin); |
| 73 | 316 | hiro | g_signal_connect(G_OBJECT(window), "delete_event",
|
| 74 | 316 | hiro | G_CALLBACK(source_window_delete_cb), sourcewin); |
| 75 | 1 | hiro | g_signal_connect(G_OBJECT(window), "key_press_event",
|
| 76 | 1 | hiro | G_CALLBACK(key_pressed), sourcewin); |
| 77 | 1 | hiro | |
| 78 | 1 | hiro | scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
| 79 | 1 | hiro | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
| 80 | 106 | hiro | GTK_POLICY_AUTOMATIC, |
| 81 | 106 | hiro | GTK_POLICY_ALWAYS); |
| 82 | 4 | hiro | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), |
| 83 | 4 | hiro | GTK_SHADOW_IN); |
| 84 | 1 | hiro | gtk_container_add(GTK_CONTAINER(window), scrolledwin); |
| 85 | 1 | hiro | gtk_widget_show(scrolledwin); |
| 86 | 1 | hiro | |
| 87 | 1 | hiro | text = gtk_text_view_new(); |
| 88 | 1 | hiro | gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); |
| 89 | 769 | hiro | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
|
| 90 | 769 | hiro | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
|
| 91 | 1 | hiro | if (!font_desc && prefs_common.textfont)
|
| 92 | 1 | hiro | font_desc = pango_font_description_from_string |
| 93 | 1 | hiro | (prefs_common.textfont); |
| 94 | 1 | hiro | if (font_desc)
|
| 95 | 1 | hiro | gtk_widget_modify_font(text, font_desc); |
| 96 | 1 | hiro | gtk_container_add(GTK_CONTAINER(scrolledwin), text); |
| 97 | 1 | hiro | gtk_widget_show(text); |
| 98 | 1 | hiro | |
| 99 | 1 | hiro | sourcewin->window = window; |
| 100 | 1 | hiro | sourcewin->scrolledwin = scrolledwin; |
| 101 | 1 | hiro | sourcewin->text = text; |
| 102 | 1 | hiro | |
| 103 | 1 | hiro | source_window_init(); |
| 104 | 1 | hiro | |
| 105 | 1 | hiro | return sourcewin;
|
| 106 | 1 | hiro | } |
| 107 | 1 | hiro | |
| 108 | 1 | hiro | void source_window_show(SourceWindow *sourcewin)
|
| 109 | 1 | hiro | {
|
| 110 | 1 | hiro | gtk_widget_show_all(sourcewin->window); |
| 111 | 1 | hiro | } |
| 112 | 1 | hiro | |
| 113 | 1 | hiro | void source_window_destroy(SourceWindow *sourcewin)
|
| 114 | 1 | hiro | {
|
| 115 | 316 | hiro | gtk_widget_destroy(sourcewin->window); |
| 116 | 1 | hiro | g_free(sourcewin); |
| 117 | 1 | hiro | } |
| 118 | 1 | hiro | |
| 119 | 1 | hiro | void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo)
|
| 120 | 1 | hiro | {
|
| 121 | 1 | hiro | gchar *file; |
| 122 | 1 | hiro | gchar *title; |
| 123 | 1 | hiro | FILE *fp; |
| 124 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 125 | 1 | hiro | |
| 126 | 1 | hiro | g_return_if_fail(msginfo != NULL);
|
| 127 | 1 | hiro | |
| 128 | 1 | hiro | file = procmsg_get_message_file(msginfo); |
| 129 | 1 | hiro | g_return_if_fail(file != NULL);
|
| 130 | 1 | hiro | |
| 131 | 478 | hiro | if ((fp = g_fopen(file, "rb")) == NULL) { |
| 132 | 1 | hiro | FILE_OP_ERROR(file, "fopen");
|
| 133 | 1 | hiro | g_free(file); |
| 134 | 1 | hiro | return;
|
| 135 | 1 | hiro | } |
| 136 | 1 | hiro | |
| 137 | 1 | hiro | debug_print(_("Displaying the source of %s ...\n"), file);
|
| 138 | 1 | hiro | |
| 139 | 1 | hiro | title = g_strdup_printf(_("%s - Source"), file);
|
| 140 | 1 | hiro | gtk_window_set_title(GTK_WINDOW(sourcewin->window), title); |
| 141 | 1 | hiro | g_free(title); |
| 142 | 1 | hiro | g_free(file); |
| 143 | 1 | hiro | |
| 144 | 1 | hiro | while (fgets(buf, sizeof(buf), fp) != NULL) |
| 145 | 1 | hiro | source_window_append(sourcewin, buf); |
| 146 | 1 | hiro | |
| 147 | 1 | hiro | fclose(fp); |
| 148 | 1 | hiro | } |
| 149 | 1 | hiro | |
| 150 | 1 | hiro | void source_window_append(SourceWindow *sourcewin, const gchar *str) |
| 151 | 1 | hiro | {
|
| 152 | 1 | hiro | GtkTextView *text = GTK_TEXT_VIEW(sourcewin->text); |
| 153 | 1 | hiro | GtkTextBuffer *buffer; |
| 154 | 1 | hiro | GtkTextIter iter; |
| 155 | 1 | hiro | gchar *out; |
| 156 | 1 | hiro | |
| 157 | 1 | hiro | buffer = gtk_text_view_get_buffer(text); |
| 158 | 1 | hiro | |
| 159 | 185 | hiro | out = conv_utf8todisp(str, NULL);
|
| 160 | 1 | hiro | gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
|
| 161 | 1 | hiro | gtk_text_buffer_insert(buffer, &iter, out, -1);
|
| 162 | 180 | hiro | g_free(out); |
| 163 | 1 | hiro | } |
| 164 | 1 | hiro | |
| 165 | 1 | hiro | static void source_window_size_alloc_cb(GtkWidget *widget, |
| 166 | 1 | hiro | GtkAllocation *allocation) |
| 167 | 1 | hiro | {
|
| 168 | 1 | hiro | g_return_if_fail(allocation != NULL);
|
| 169 | 1 | hiro | |
| 170 | 1 | hiro | prefs_common.sourcewin_width = allocation->width; |
| 171 | 1 | hiro | prefs_common.sourcewin_height = allocation->height; |
| 172 | 1 | hiro | } |
| 173 | 1 | hiro | |
| 174 | 316 | hiro | static gint source_window_delete_cb(GtkWidget *widget, GdkEventAny *event,
|
| 175 | 316 | hiro | SourceWindow *sourcewin) |
| 176 | 1 | hiro | {
|
| 177 | 1 | hiro | source_window_destroy(sourcewin); |
| 178 | 316 | hiro | return TRUE;
|
| 179 | 1 | hiro | } |
| 180 | 1 | hiro | |
| 181 | 1 | hiro | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
|
| 182 | 1 | hiro | SourceWindow *sourcewin) |
| 183 | 1 | hiro | {
|
| 184 | 316 | hiro | if (event && event->keyval == GDK_Escape) {
|
| 185 | 316 | hiro | source_window_destroy(sourcewin); |
| 186 | 316 | hiro | return TRUE;
|
| 187 | 316 | hiro | } |
| 188 | 1 | hiro | return FALSE;
|
| 189 | 1 | hiro | } |