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