3922a9d86884846685310061b1a67ce5ef15b636
[claws.git] / src / quote_fmt.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdkkeysyms.h>
27
28 #include "intl.h"
29
30 static GtkWidget *quote_desc_win;
31
32 static void quote_fmt_quote_description_create          (void);
33 static void quote_fmt_quote_description_key_pressed     (GtkWidget *widget,
34                                                          GdkEventKey *event,
35                                                          gpointer data);
36
37 static gchar *symbol_table[][2] =
38 {
39         {"%d",          N_("Date")}, /* date */
40         {"%f",          N_("From")}, /* from */
41         {"%N",          N_("Full Name of Sender")}, /* full name */
42         {"%F",          N_("First Name of Sender")}, /* first name */
43         {"%I",          N_("Initial of Sender")}, /* initial of sender */
44         {"%s",          N_("Subject")}, /* subject */ 
45         {"%t",          N_("To")}, /* to */ 
46         {"%c",          N_("Cc")}, /* cc */ 
47         {"%n",          N_("Newsgroups")}, /* newsgroups */ 
48         {"%r",          N_("References")}, /* references */ 
49         {"%i",          N_("Message-ID")}, /* message-id */ 
50         {"%M",          N_("Message body")}, /* message */ 
51         {"%Q",          N_("Quoted message body")}, /* quoted message */ 
52         {"%m",          N_("Message body without signature")}, /* message with no signature */ 
53         {"%q",          N_("Quoted message body without signature")}, /* quoted message with no signature */ 
54         {"",            NULL},
55         {"?x{expr}",    N_("Insert expr if x is set\nx is one of the characters above after \%")},
56         {"",            NULL},
57         {"\\%",         N_("Literal \%")}, /* % */ 
58         {"\\\\",        N_("Literal backslash")}, /* \ */ 
59         {"\\?",         N_("Literal question mark")}, /* ? */ 
60         {"\\|",         N_("Literal pipe")}, /* | */
61         {"\\{",         N_("Literal opening curly brace")},
62         {"\\}",         N_("Literal closing curly brace")},
63         {"",            NULL},
64         {"|f{file}",    N_("Insert File")}, /* insert file */ 
65         {"|p{command}", N_("Insert program output")}, /* insert program output */ 
66         {NULL,NULL},
67 };
68
69 void quote_fmt_quote_description(void)
70 {
71         if (!quote_desc_win)
72                 quote_fmt_quote_description_create();
73
74         manage_window_set_transient(GTK_WINDOW(quote_desc_win));
75         gtk_widget_show(quote_desc_win);
76         gtk_main();
77         gtk_widget_hide(quote_desc_win);
78 }
79
80 static void quote_fmt_quote_description_create(void)
81 {
82         GtkWidget *table;
83         GtkWidget *hbbox;
84         GtkWidget *ok_btn;
85         int i;
86
87         quote_desc_win = gtk_window_new(GTK_WINDOW_DIALOG);
88         gtk_window_set_title(GTK_WINDOW(quote_desc_win),
89                              _("Description of symbols"));
90         gtk_container_set_border_width(GTK_CONTAINER(quote_desc_win), 8);
91         gtk_window_set_position(GTK_WINDOW(quote_desc_win), GTK_WIN_POS_CENTER);
92         gtk_window_set_modal(GTK_WINDOW(quote_desc_win), TRUE);
93         gtk_window_set_policy(GTK_WINDOW(quote_desc_win), FALSE, FALSE, FALSE);
94
95         table = gtk_table_new(sizeof(symbol_table), 2, FALSE);
96         gtk_container_add(GTK_CONTAINER(quote_desc_win), table);
97
98         for(i = 0; symbol_table[i][0] != NULL; i++) {
99                 if(symbol_table[i][0][0] != '\0') {
100                         GtkWidget *label;
101
102                         label = gtk_label_new(symbol_table[i][0]);
103                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
104                         gtk_table_attach(GTK_TABLE(table), label,
105                                          0, 1, i, i+1,
106                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
107                                          0, 0);
108                         label = gtk_label_new(gettext(symbol_table[i][1]));
109                         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
110                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
111                         gtk_table_attach(GTK_TABLE(table), label,
112                                          1, 2, i, i+1,
113                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
114                                          0, 0);
115                 } else {
116                         GtkWidget *separator;
117                         
118                         separator = gtk_hseparator_new();
119                         gtk_table_attach(GTK_TABLE(table), separator,
120                                          0, 2, i, i+1,
121                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
122                                          0, 4);
123                 }
124         }
125
126         gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
127                                 NULL, NULL, NULL, NULL);
128         gtk_table_attach_defaults(GTK_TABLE(table), hbbox,
129                                   1, 2, i, i+1);
130
131         gtk_widget_grab_default(ok_btn);
132         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
133                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
134         gtk_signal_connect
135                 (GTK_OBJECT(quote_desc_win), "key_press_event",
136                  GTK_SIGNAL_FUNC(quote_fmt_quote_description_key_pressed),
137                  NULL);
138         gtk_signal_connect(GTK_OBJECT(quote_desc_win), "delete_event",
139                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
140
141         gtk_widget_show_all(table);
142 }
143
144 static void quote_fmt_quote_description_key_pressed(GtkWidget *widget,
145                                                 GdkEventKey *event,
146                                                 gpointer data)
147 {
148         if (event && event->keyval == GDK_Escape)
149                 gtk_main_quit();
150 }
151