ccad7702f7
* src/addrbook.c * src/addrindex.c * src/alertpanel.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/export.c * src/folder_item_prefs.c * src/html.c * src/imap.c * src/import.c * src/jpilot.c * src/mainwindow.c * src/matcher_parser_lex.l * src/messageview.c * src/mh.c * src/prefs_account.c * src/prefs_actions.c * src/prefs_common.c * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_themes.c * src/procheader.c * src/procmime.c * src/sourcewindow.c * src/statusbar.c * src/summaryview.c * src/textview.c * src/toolbar.c * src/unmime.c * src/common/template.c * src/common/utils.c * src/common/xml.c * src/common/xml.h * src/gtk/gtkaspell.c * src/plugins/clamav/clamav_plugin.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/image_viewer/viewerprefs.c * src/plugins/pgpmime/passphrase.c * src/plugins/pgpmime/prefs_gpg.c * src/plugins/pgpmime/select-keys.c * src/plugins/spamassassin/spamassassin.c second part of initial sync with main-gtk2 (more to follow)
210 lines
5.6 KiB
C
210 lines
5.6 KiB
C
/*
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
|
* Copyright (C) 1999-2005 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 2 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, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "defs.h"
|
|
|
|
#include <glib.h>
|
|
#include <gdk/gdkkeysyms.h>
|
|
#include <gtk/gtkwidget.h>
|
|
#include <gtk/gtkwindow.h>
|
|
#include <gtk/gtksignal.h>
|
|
#include <gtk/gtkscrolledwindow.h>
|
|
#include <gtk/gtktext.h>
|
|
#include <gtk/gtkstyle.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "intl.h"
|
|
#include "sourcewindow.h"
|
|
#include "utils.h"
|
|
#include "gtkutils.h"
|
|
#include "prefs_common.h"
|
|
|
|
static void source_window_size_alloc_cb (GtkWidget *widget,
|
|
GtkAllocation *allocation);
|
|
static void source_window_destroy_cb (GtkWidget *widget,
|
|
SourceWindow *sourcewin);
|
|
static gboolean key_pressed (GtkWidget *widget,
|
|
GdkEventKey *event,
|
|
SourceWindow *sourcewin);
|
|
|
|
static void source_window_init()
|
|
{
|
|
}
|
|
|
|
SourceWindow *source_window_create(void)
|
|
{
|
|
SourceWindow *sourcewin;
|
|
GtkWidget *window;
|
|
GtkWidget *scrolledwin;
|
|
GtkWidget *text;
|
|
static PangoFontDescription *font_desc = NULL;
|
|
|
|
static GdkGeometry geometry;
|
|
|
|
debug_print("Creating source window...\n");
|
|
sourcewin = g_new0(SourceWindow, 1);
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
gtk_window_set_title(GTK_WINDOW(window), _("Source of the message"));
|
|
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
|
|
gtk_widget_set_size_request(window, prefs_common.sourcewin_width,
|
|
prefs_common.sourcewin_height);
|
|
|
|
if (!geometry.min_height) {
|
|
geometry.min_width = 400;
|
|
geometry.min_height = 320;
|
|
}
|
|
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
|
|
GDK_HINT_MIN_SIZE);
|
|
|
|
g_signal_connect(G_OBJECT(window), "size_allocate",
|
|
G_CALLBACK(source_window_size_alloc_cb),
|
|
sourcewin);
|
|
g_signal_connect(G_OBJECT(window), "destroy",
|
|
G_CALLBACK(source_window_destroy_cb),
|
|
sourcewin);
|
|
g_signal_connect(G_OBJECT(window), "key_press_event",
|
|
G_CALLBACK(key_pressed), sourcewin);
|
|
gtk_widget_realize(window);
|
|
|
|
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
|
|
GTK_SHADOW_IN);
|
|
gtk_container_add(GTK_CONTAINER(window), scrolledwin);
|
|
gtk_widget_show(scrolledwin);
|
|
|
|
text = gtk_text_view_new();
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
|
|
if (!font_desc && prefs_common.textfont)
|
|
font_desc = pango_font_description_from_string
|
|
(prefs_common.textfont);
|
|
if (font_desc)
|
|
gtk_widget_modify_font(text, font_desc);
|
|
gtk_container_add(GTK_CONTAINER(scrolledwin), text);
|
|
gtk_widget_show(text);
|
|
|
|
sourcewin->window = window;
|
|
sourcewin->scrolledwin = scrolledwin;
|
|
sourcewin->text = text;
|
|
|
|
source_window_init();
|
|
|
|
return sourcewin;
|
|
}
|
|
|
|
void source_window_show(SourceWindow *sourcewin)
|
|
{
|
|
gtk_widget_show_all(sourcewin->window);
|
|
}
|
|
|
|
void source_window_destroy(SourceWindow *sourcewin)
|
|
{
|
|
g_free(sourcewin);
|
|
}
|
|
|
|
void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo)
|
|
{
|
|
gchar *file;
|
|
gchar *title;
|
|
FILE *fp;
|
|
gchar buf[BUFFSIZE];
|
|
|
|
g_return_if_fail(msginfo != NULL);
|
|
|
|
file = procmsg_get_message_file(msginfo);
|
|
g_return_if_fail(file != NULL);
|
|
|
|
if ((fp = fopen(file, "rb")) == NULL) {
|
|
FILE_OP_ERROR(file, "fopen");
|
|
g_free(file);
|
|
return;
|
|
}
|
|
|
|
debug_print("Displaying the source of %s ...\n", file);
|
|
|
|
title = g_strdup_printf(_("%s - Source"), file);
|
|
gtk_window_set_title(GTK_WINDOW(sourcewin->window), title);
|
|
g_free(title);
|
|
g_free(file);
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL)
|
|
source_window_append(sourcewin, buf);
|
|
|
|
fclose(fp);
|
|
}
|
|
|
|
void source_window_append(SourceWindow *sourcewin, const gchar *str)
|
|
{
|
|
GtkTextView *text = GTK_TEXT_VIEW(sourcewin->text);
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
|
|
GtkTextIter iter;
|
|
gchar *out;
|
|
gint len;
|
|
|
|
len = strlen(str) + 1;
|
|
Xalloca(out, len, return);
|
|
conv_utf8todisp(out, len, str);
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
|
|
gtk_text_buffer_insert(buffer, &iter, out, -1);
|
|
}
|
|
|
|
static void source_window_size_alloc_cb(GtkWidget *widget,
|
|
GtkAllocation *allocation)
|
|
{
|
|
g_return_if_fail(allocation != NULL);
|
|
|
|
prefs_common.sourcewin_width = allocation->width;
|
|
prefs_common.sourcewin_height = allocation->height;
|
|
}
|
|
|
|
static void source_window_destroy_cb(GtkWidget *widget,
|
|
SourceWindow *sourcewin)
|
|
{
|
|
source_window_destroy(sourcewin);
|
|
}
|
|
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
|
|
SourceWindow *sourcewin)
|
|
{
|
|
|
|
if (!event || !sourcewin) return FALSE;
|
|
|
|
switch (event->keyval) {
|
|
case GDK_A:
|
|
case GDK_a:
|
|
if ((event->state & GDK_CONTROL_MASK) != 0)
|
|
gtk_editable_select_region(GTK_EDITABLE(sourcewin->text), 0, -1);
|
|
break;
|
|
case GDK_W:
|
|
case GDK_w:
|
|
if ((event->state & GDK_CONTROL_MASK) != 0)
|
|
gtk_widget_destroy(sourcewin->window);
|
|
break;
|
|
case GDK_Escape:
|
|
gtk_widget_destroy(sourcewin->window);
|
|
break;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|