fix `make dist`
[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
38 StockPixmap legend_icons[ICONS] = {
39         STOCK_PIXMAP_NEW,
40         STOCK_PIXMAP_UNREAD,
41         STOCK_PIXMAP_REPLIED, 
42         STOCK_PIXMAP_FORWARDED, 
43         STOCK_PIXMAP_REPLIED_AND_FORWARDED, 
44         STOCK_PIXMAP_IGNORETHREAD,
45         STOCK_PIXMAP_WATCHTHREAD,
46         STOCK_PIXMAP_SPAM,
47         STOCK_PIXMAP_CLIP,
48         STOCK_PIXMAP_GPG_SIGNED,
49         STOCK_PIXMAP_KEY,
50         STOCK_PIXMAP_CLIP_GPG_SIGNED,
51         STOCK_PIXMAP_CLIP_KEY,
52         STOCK_PIXMAP_MARK,
53         STOCK_PIXMAP_DELETED,
54         STOCK_PIXMAP_MOVED,
55         STOCK_PIXMAP_COPIED,
56         STOCK_PIXMAP_LOCKED,
57         STOCK_PIXMAP_DIR_OPEN, 
58         STOCK_PIXMAP_DIR_OPEN_HRM,
59         STOCK_PIXMAP_DIR_OPEN_MARK,
60         STOCK_PIXMAP_DIR_NOSELECT_OPEN,
61         STOCK_PIXMAP_DIR_SUBS_OPEN,
62 };
63
64 static gchar *legend_icon_desc[] = {
65 /* status column */
66         N_("New message"),
67         N_("Unread message"),
68         N_("Message has been replied to"),
69         N_("Message has been forwarded"),
70         N_("Message has been forwarded and replied to"),
71         N_("Message is in an ignored thread"),
72         N_("Message is in a watched thread"),
73         N_("Message is spam"),
74 /* attachment column */
75         N_("Message has attachment(s)"),
76         N_("Digitally signed message"),
77         N_("Encrypted message"),
78         N_("Message is signed and has attachment(s)"),
79         N_("Message is encrypted and has attachment(s)"),
80 /* mark column */
81         N_("Marked message"),
82         N_("Message is marked for deletion"),
83         N_("Message is marked for moving"),
84         N_("Message is marked for copying"),
85 /* locked column */
86         N_("Locked message"),
87 /* others */
88         N_("Folder (normal, opened)"),
89         N_("Folder with read messages hidden"),
90         N_("Folder contains marked messages"),
91         N_("IMAP folder which contains sub-folders only"),
92         N_("IMAP mailbox showing only subscribed folders"),
93 };
94
95 static struct LegendDialog {
96         GtkWidget *window;
97 } legend;
98
99 static void legend_create(void);
100 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
101 static void legend_close(void);
102
103 void legend_show(void)
104 {
105         if (!legend.window)
106                 legend_create();
107         else
108                 gtk_window_present(GTK_WINDOW(legend.window));
109 }
110
111 static void legend_create(void)
112 {
113         GtkWidget *window;
114         GtkWidget *vbox;
115         GtkWidget *vbox1;
116         GtkWidget *vbox2;
117         GtkWidget *confirm_area;
118         GtkWidget *close_button;
119         GtkWidget *hbox;
120         GtkWidget *label;
121         GtkWidget *icon_label;
122         GtkWidget *desc_label;
123         gint i;
124
125         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "icon_legend");
126         gtk_window_set_title(GTK_WINDOW(window), _("Icon Legend"));
127         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
128         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
129         g_signal_connect(G_OBJECT(window), "delete_event",
130                          G_CALLBACK(legend_close), NULL);
131         g_signal_connect(G_OBJECT(window), "key_press_event",
132                          G_CALLBACK(key_pressed), NULL);
133         gtk_widget_realize(window);
134
135         vbox = gtk_vbox_new(FALSE, 8);
136         gtk_container_add(GTK_CONTAINER(window), vbox);
137         gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
138
139         hbox = gtk_hbox_new(FALSE, 8);
140         gtk_widget_show(hbox);
141         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
142
143         label = gtk_label_new(g_strconcat("<span weight=\"bold\">",_("The following icons "
144                                 "are used to show the status of messages and "
145                                 "folders:"), "</span>", NULL));
146         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
147         gtk_label_set_line_wrap(GTK_LABEL(label), FALSE);
148         gtk_widget_show(label);
149         gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
150
151         hbox = gtk_hbox_new(FALSE, 0);
152         gtk_widget_show(hbox);
153         gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
154
155         vbox1 = gtk_vbox_new(FALSE, VSPACING_NARROW);
156         gtk_widget_show(vbox1);
157         gtk_box_pack_start(GTK_BOX(hbox), vbox1, TRUE, FALSE, 0);
158
159         vbox2 = gtk_vbox_new(FALSE, VSPACING_NARROW);
160         gtk_widget_show (vbox2);
161         gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, FALSE, 0);
162
163         for (i = 0; i <= ICONS/2; ++i) {
164                 icon_label = stock_pixmap_widget(legend_icons[i]);
165                 gtk_misc_set_alignment (GTK_MISC (icon_label), 0.5, 0.5);
166                 hbox = gtk_hbox_new(FALSE, 8);
167                 gtk_widget_show(hbox);
168                 gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0);
169                 gtk_box_pack_start(GTK_BOX (hbox), icon_label, FALSE, FALSE, 0);
170
171                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
172                 gtk_misc_set_alignment (GTK_MISC (desc_label), 0, 0.5);
173                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
174                 gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 8);
175         }
176
177         for (i = ICONS/2+1; i < ICONS; ++i) {
178                 icon_label = stock_pixmap_widget(legend_icons[i]);
179                 gtk_misc_set_alignment (GTK_MISC (icon_label), 0.5, 0.5);
180                 hbox = gtk_hbox_new(FALSE, 8);
181                 gtk_widget_show(hbox);
182                 gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
183                 gtk_box_pack_start(GTK_BOX (hbox), icon_label, FALSE, FALSE, 0);
184
185                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
186                 gtk_misc_set_alignment (GTK_MISC (desc_label), 0, 0.5);
187                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
188                 gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 8);
189
190         }       
191
192         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
193                                       NULL, NULL, NULL, NULL);
194         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 4);
195         gtk_widget_grab_default(close_button);
196         g_signal_connect_closure
197                 (G_OBJECT(close_button), "clicked",
198                  g_cclosure_new_swap(G_CALLBACK(legend_close),
199                                      window, NULL), FALSE);
200
201         gtk_widget_show_all(window);
202
203         legend.window = window;
204 }
205
206 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
207 {
208         if (event && event->keyval == GDK_KEY_Escape) {
209                 legend_close();
210         }
211         return FALSE;
212 }
213
214 static void legend_close(void)
215 {
216         gtk_widget_destroy(legend.window);
217         legend.window = NULL;
218 }