* config/.cvsignore
[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 #include "manage_window.h"
30 #include "gtkutils.h"
31
32 static GtkWidget *quote_desc_win;
33
34 static void quote_fmt_quote_description_create          (void);
35 static void quote_fmt_quote_description_key_pressed     (GtkWidget *widget,
36                                                          GdkEventKey *event,
37                                                          gpointer data);
38
39 static gchar *symbol_table[][2] =
40 {
41         {"%D{fmt}",     N_("Customize date format (see man strftime)")}, /* date expression */
42         {"%d",          N_("Date")}, /* date */
43         {"%f",          N_("From")}, /* from */
44         {"%N",          N_("Full Name of Sender")}, /* full name */
45         {"%F",          N_("First Name of Sender")}, /* first name */
46         {"%L",          N_("Last Name of Sender")}, /* last name */
47         {"%I",          N_("Initials of Sender")}, /* initial of sender */
48         {"%s",          N_("Subject")}, /* subject */ 
49         {"%t",          N_("To")}, /* to */ 
50         {"%c",          N_("Cc")}, /* cc */ 
51         {"%n",          N_("Newsgroups")}, /* newsgroups */ 
52         {"%r",          N_("References")}, /* references */ 
53         {"%i",          N_("Message-ID")}, /* message-id */ 
54         {"%M",          N_("Message body")}, /* message */ 
55         {"%Q",          N_("Quoted message body")}, /* quoted message */ 
56         {"%m",          N_("Message body without signature")}, /* message with no signature */ 
57         {"%q",          N_("Quoted message body without signature")}, /* quoted message with no signature */ 
58         {"",            NULL},
59         {"?x{expr}",    N_("Insert expr if x is set\nx is one of the characters above after %")},
60         {"",            NULL},
61         {"\\%",         N_("Literal %")},
62         {"\\\\",        N_("Literal backslash")},
63         {"\\?",         N_("Literal question mark")},
64         {"\\|",         N_("Literal pipe")},
65         {"\\{",         N_("Literal opening curly brace")},
66         {"\\}",         N_("Literal closing curly brace")},
67         {"",            NULL},
68         {"|f{file}",    N_("Insert File")},
69         {"|p{command}", N_("Insert program output")}, /* insert program output */ 
70         {NULL,NULL},
71 };
72
73 void quote_fmt_quote_description(void)
74 {
75         if (!quote_desc_win)
76                 quote_fmt_quote_description_create();
77
78         manage_window_set_transient(GTK_WINDOW(quote_desc_win));
79         gtk_widget_show(quote_desc_win);
80         gtk_main();
81         gtk_widget_hide(quote_desc_win);
82 }
83
84 static void quote_fmt_quote_description_create(void)
85 {
86         GtkWidget *table;
87         GtkWidget *hbbox;
88         GtkWidget *ok_btn;
89         int i;
90
91         quote_desc_win = gtk_window_new(GTK_WINDOW_DIALOG);
92         gtk_window_set_title(GTK_WINDOW(quote_desc_win),
93                              _("Description of symbols"));
94         gtk_container_set_border_width(GTK_CONTAINER(quote_desc_win), 8);
95         gtk_window_set_position(GTK_WINDOW(quote_desc_win), GTK_WIN_POS_CENTER);
96         gtk_window_set_modal(GTK_WINDOW(quote_desc_win), TRUE);
97         gtk_window_set_policy(GTK_WINDOW(quote_desc_win), FALSE, FALSE, FALSE);
98
99         table = gtk_table_new(sizeof(symbol_table), 2, FALSE);
100         gtk_container_add(GTK_CONTAINER(quote_desc_win), table);
101         gtk_table_set_col_spacings(GTK_TABLE(table), 10);
102
103         for(i = 0; symbol_table[i][0] != NULL; i++) {
104                 if(symbol_table[i][0][0] != '\0') {
105                         GtkWidget *label;
106
107                         label = gtk_label_new(symbol_table[i][0]);
108                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
109                         gtk_table_attach(GTK_TABLE(table), label,
110                                          0, 1, i, i+1,
111                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
112                                          0, 0);
113                         label = gtk_label_new(gettext(symbol_table[i][1]));
114                         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
115                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
116                         gtk_table_attach(GTK_TABLE(table), label,
117                                          1, 2, i, i+1,
118                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
119                                          0, 0);
120                 } else {
121                         GtkWidget *separator;
122                         
123                         separator = gtk_hseparator_new();
124                         gtk_table_attach(GTK_TABLE(table), separator,
125                                          0, 2, i, i+1,
126                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
127                                          0, 4);
128                 }
129         }
130
131         gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
132                                 NULL, NULL, NULL, NULL);
133         gtk_table_attach_defaults(GTK_TABLE(table), hbbox,
134                                   1, 2, i, i+1);
135
136         gtk_widget_grab_default(ok_btn);
137         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
138                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
139         gtk_signal_connect
140                 (GTK_OBJECT(quote_desc_win), "key_press_event",
141                  GTK_SIGNAL_FUNC(quote_fmt_quote_description_key_pressed),
142                  NULL);
143         gtk_signal_connect(GTK_OBJECT(quote_desc_win), "delete_event",
144                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
145
146         gtk_widget_show_all(table);
147 }
148
149 static void quote_fmt_quote_description_key_pressed(GtkWidget *widget,
150                                                 GdkEventKey *event,
151                                                 gpointer data)
152 {
153         if (event && event->keyval == GDK_Escape)
154                 gtk_main_quit();
155 }
156