fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / gtk / icon_legend.c
1 /*
2  * This file Copyright (C) 2005-2012 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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31
32 #include "gtkutils.h"
33 #include "stock_pixmap.h"
34 #include "prefs_gtk.h"
35
36 #define ICONS 23
37 #define ROWS ((ICONS % 2 == 0)? ICONS / 2: (ICONS + 1) / 2)
38
39 StockPixmap legend_icons[ICONS] = {
40         STOCK_PIXMAP_NEW,
41         STOCK_PIXMAP_UNREAD,
42         STOCK_PIXMAP_REPLIED, 
43         STOCK_PIXMAP_FORWARDED, 
44         STOCK_PIXMAP_REPLIED_AND_FORWARDED, 
45         STOCK_PIXMAP_IGNORETHREAD,
46         STOCK_PIXMAP_WATCHTHREAD,
47         STOCK_PIXMAP_SPAM,
48         STOCK_PIXMAP_CLIP,
49         STOCK_PIXMAP_GPG_SIGNED,
50         STOCK_PIXMAP_KEY,
51         STOCK_PIXMAP_CLIP_GPG_SIGNED,
52         STOCK_PIXMAP_CLIP_KEY,
53         STOCK_PIXMAP_MARK,
54         STOCK_PIXMAP_DELETED,
55         STOCK_PIXMAP_MOVED,
56         STOCK_PIXMAP_COPIED,
57         STOCK_PIXMAP_LOCKED,
58         STOCK_PIXMAP_DIR_OPEN, 
59         STOCK_PIXMAP_DIR_OPEN_HRM,
60         STOCK_PIXMAP_DIR_OPEN_MARK,
61         STOCK_PIXMAP_DIR_NOSELECT_OPEN,
62         STOCK_PIXMAP_DIR_SUBS_OPEN,
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 has been forwarded and replied to"),
72         N_("Message is in an ignored thread"),
73         N_("Message is in a watched thread"),
74         N_("Message is spam"),
75 /* attachment column */
76         N_("Message has attachment(s)"),
77         N_("Digitally signed message"),
78         N_("Encrypted message"),
79         N_("Message is signed and has attachment(s)"),
80         N_("Message is encrypted and has attachment(s)"),
81 /* mark column */
82         N_("Marked message"),
83         N_("Message is marked for deletion"),
84         N_("Message is marked for moving"),
85         N_("Message is marked for copying"),
86 /* locked column */
87         N_("Locked message"),
88 /* others */
89         N_("Folder (normal, opened)"),
90         N_("Folder with read messages hidden"),
91         N_("Folder contains marked messages"),
92         N_("IMAP folder which contains sub-folders only"),
93         N_("IMAP mailbox showing only subscribed folders"),
94 };
95
96 static struct LegendDialog {
97         GtkWidget *window;
98 } legend;
99
100 static void legend_create(void);
101 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
102 static void legend_close(void);
103
104 void legend_show(void)
105 {
106         if (!legend.window)
107                 legend_create();
108         else
109                 gtk_window_present(GTK_WINDOW(legend.window));
110 }
111
112 static void legend_create(void)
113 {
114         GtkWidget *window;
115         GtkWidget *vbox;
116         GtkWidget *confirm_area;
117         GtkWidget *close_button;
118         GtkWidget *hbox;
119         GtkWidget *label;
120         GtkWidget *icon_label;
121         GtkWidget *desc_label;
122         GtkWidget *table;
123         GtkWidget *frame;
124         gint i, j, k;
125
126         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "icon_legend");
127         gtk_window_set_title(GTK_WINDOW(window), _("Icon Legend"));
128         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
129         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
130         gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
131         gtk_window_set_default_size(GTK_WINDOW(window), 666, 340);
132         g_signal_connect(G_OBJECT(window), "delete_event",
133                          G_CALLBACK(legend_close), NULL);
134         g_signal_connect(G_OBJECT(window), "key_press_event",
135                          G_CALLBACK(key_pressed), NULL);
136         gtk_widget_realize(window);
137
138         vbox = gtk_vbox_new(FALSE, 8);
139         gtk_container_add(GTK_CONTAINER(window), vbox);
140         gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
141
142         hbox = gtk_hbox_new(FALSE, 8);
143         gtk_widget_show(hbox);
144         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
145
146         label = gtk_label_new(g_strconcat("<span weight=\"bold\">",_("The following icons "
147                                 "are used to show the status of messages and "
148                                 "folders:"), "</span>", NULL));
149         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
150         gtk_widget_show(label);
151         gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
152
153         table = gtk_table_new(ROWS, 4, FALSE);
154         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
155         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
156         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
157
158         for (i = 0, j = 0, k = 0; i < ICONS; ++i, ++k) {
159                 icon_label = stock_pixmap_widget(legend_icons[i]);
160                 gtk_misc_set_alignment (GTK_MISC (icon_label), 0.5, 0.5);
161                 gtk_table_attach(GTK_TABLE(table), icon_label, j, j + 1, k, k + 1,
162                                 GTK_FILL, 0, 0, 0);
163
164                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
165                 gtk_misc_set_alignment (GTK_MISC (desc_label), 0, 0.5);
166                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
167                 gtk_table_attach(GTK_TABLE(table), desc_label, j + 1, j + 2, k, k + 1,
168                                 GTK_FILL, 0, 0, 0);
169
170                 if (i == ICONS / 2) {
171                         j = 2;
172                         k = -1;
173                 }
174         }
175
176         PACK_FRAME(vbox, frame, NULL);
177         gtk_container_add(GTK_CONTAINER(frame), table);
178
179         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
180                                       NULL, NULL, NULL, NULL);
181         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 4);
182         gtk_widget_grab_default(close_button);
183         g_signal_connect_closure
184                 (G_OBJECT(close_button), "clicked",
185                  g_cclosure_new_swap(G_CALLBACK(legend_close),
186                                      window, NULL), FALSE);
187
188         gtk_widget_show_all(window);
189
190         legend.window = window;
191 }
192
193 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
194 {
195         if (event && event->keyval == GDK_KEY_Escape) {
196                 legend_close();
197         }
198         return FALSE;
199 }
200
201 static void legend_close(void)
202 {
203         gtk_widget_destroy(legend.window);
204         legend.window = NULL;
205 }