2006-11-18 [paul] 2.6.0cvs55
[claws.git] / src / gtk / icon_legend.c
1 /*
2  * This file Copyright (C) 2005 Paul Mangan <paul@claws-mail.org>
3  * and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkwindow.h>
32 #include <gtk/gtksignal.h>
33 #include <gtk/gtkvbox.h>
34 #include <gtk/gtkhbox.h>
35 #include <gtk/gtklabel.h>
36
37 #include "gtkutils.h"
38 #include "stock_pixmap.h"
39 #include "prefs_gtk.h"
40
41 #define ICONS 19
42
43 StockPixmap legend_icons[ICONS] = {
44         STOCK_PIXMAP_NEW,
45         STOCK_PIXMAP_UNREAD,
46         STOCK_PIXMAP_REPLIED, 
47         STOCK_PIXMAP_FORWARDED, 
48         STOCK_PIXMAP_IGNORETHREAD,
49         STOCK_PIXMAP_SPAM,
50         STOCK_PIXMAP_CLIP,
51         STOCK_PIXMAP_GPG_SIGNED,
52         STOCK_PIXMAP_KEY,
53         STOCK_PIXMAP_CLIP_GPG_SIGNED,
54         STOCK_PIXMAP_CLIP_KEY,
55         STOCK_PIXMAP_MARK,
56         STOCK_PIXMAP_DELETED,
57         STOCK_PIXMAP_MOVED,
58         STOCK_PIXMAP_COPIED,
59         STOCK_PIXMAP_LOCKED,
60         STOCK_PIXMAP_DIR_OPEN, 
61         STOCK_PIXMAP_DIR_OPEN_HRM,
62         STOCK_PIXMAP_DIR_OPEN_MARK,
63 };
64
65 static gchar *legend_icon_desc[] = {
66 /* status column */
67         N_("New message"),
68         N_("Unread message"),
69         N_("Message has been replied to"),
70         N_("Message has been forwarded"),
71         N_("Message is in an ignored thread"),
72         N_("Message is spam"),
73 /* attachment column */
74         N_("Message has attachment(s)"),
75         N_("Digitally signed message"),
76         N_("Encrypted message"),
77         N_("Message is signed and has attachment(s)"),
78         N_("Message is encrypted and has attachment(s)"),
79 /* mark column */
80         N_("Marked message"),
81         N_("Message is marked for deletion"),
82         N_("Message is marked for moving"),
83         N_("Message is marked for copying"),
84 /* locked column */
85         N_("Locked message"),
86 /* others */
87         N_("Folder (normal, opened)"),
88         N_("Folder with read messages hidden"),
89         N_("Folder contains marked messages"),
90 };
91
92 static struct LegendDialog {
93         GtkWidget *window;
94 } legend;
95
96 static void legend_create(void);
97 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
98 static void legend_close(void);
99
100 void legend_show(void)
101 {
102         if (!legend.window)
103                 legend_create();
104         else
105                 gtk_window_present(GTK_WINDOW(legend.window));
106 }
107
108 static void legend_create(void)
109 {
110         GtkWidget *window;
111         GtkWidget *vbox;
112         GtkWidget *confirm_area;
113         GtkWidget *close_button;
114         GtkWidget *hbox;
115         GtkWidget *label;
116         GtkWidget *icon_label;
117         GtkWidget *desc_label;
118         GtkWidget *table;
119         gint i;
120
121         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
122         gtk_window_set_title(GTK_WINDOW(window), _("Icon Legend"));
123         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
124         gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
125         gtk_widget_set_size_request(window, -1, -1);
126         g_signal_connect(G_OBJECT(window), "delete_event",
127                          G_CALLBACK(legend_close), NULL);
128         g_signal_connect(G_OBJECT(window), "key_press_event",
129                          G_CALLBACK(key_pressed), NULL);
130         gtk_widget_realize(window);
131
132         vbox = gtk_vbox_new(FALSE, 8);
133         gtk_container_add(GTK_CONTAINER(window), vbox);
134         gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
135
136         hbox = gtk_hbox_new(FALSE, 8);
137         gtk_widget_show(hbox);
138         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
139
140         label = gtk_label_new(_("<span weight=\"bold\">The following icons "
141                                 "are used to show the status of messages and "
142                                 "folders:</span>"));
143         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
144         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
145         gtk_widget_show(label);
146         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
147
148         table = gtk_table_new(ICONS, 2, FALSE);
149         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
150         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
151         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
152
153         for (i = 0; i < ICONS; ++i) {
154                 icon_label = stock_pixmap_widget(window, legend_icons[i]);
155                 gtk_misc_set_alignment (GTK_MISC (icon_label), 0.5, 0.5);
156                 gtk_table_attach(GTK_TABLE(table), icon_label, 0, 1, i, i+1,
157                                 GTK_FILL, 0, 0, 0);
158
159                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
160                 gtk_misc_set_alignment (GTK_MISC (desc_label), 0, 0.5);
161                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
162                 gtk_table_attach(GTK_TABLE(table), desc_label, 1, 2, i, i+1,
163                                 GTK_FILL, 0, 0, 0);
164         }       
165
166         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
167
168         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
169                                       NULL, NULL, NULL, NULL);
170         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 4);
171         gtk_widget_grab_default(close_button);
172         g_signal_connect_closure
173                 (G_OBJECT(close_button), "clicked",
174                  g_cclosure_new_swap(G_CALLBACK(legend_close),
175                                      window, NULL), FALSE);
176
177         gtk_widget_show_all(window);
178
179         legend.window = window;
180 }
181
182 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
183 {
184         if (event && event->keyval == GDK_Escape) {
185                 legend_close();
186         }
187         return FALSE;
188 }
189
190 static void legend_close(void)
191 {
192         gtk_widget_destroy(legend.window);
193         legend.window = NULL;
194 }