2007-08-25 [paul] 2.10.0cvs172
[claws.git] / src / gtk / icon_legend.c
1 /*
2  * This file Copyright (C) 2005-2007 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 #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 20
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_WATCHTHREAD,
50         STOCK_PIXMAP_SPAM,
51         STOCK_PIXMAP_CLIP,
52         STOCK_PIXMAP_GPG_SIGNED,
53         STOCK_PIXMAP_KEY,
54         STOCK_PIXMAP_CLIP_GPG_SIGNED,
55         STOCK_PIXMAP_CLIP_KEY,
56         STOCK_PIXMAP_MARK,
57         STOCK_PIXMAP_DELETED,
58         STOCK_PIXMAP_MOVED,
59         STOCK_PIXMAP_COPIED,
60         STOCK_PIXMAP_LOCKED,
61         STOCK_PIXMAP_DIR_OPEN, 
62         STOCK_PIXMAP_DIR_OPEN_HRM,
63         STOCK_PIXMAP_DIR_OPEN_MARK,
64 };
65
66 static gchar *legend_icon_desc[] = {
67 /* status column */
68         N_("New message"),
69         N_("Unread message"),
70         N_("Message has been replied to"),
71         N_("Message has been forwarded"),
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 };
93
94 static struct LegendDialog {
95         GtkWidget *window;
96 } legend;
97
98 static void legend_create(void);
99 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
100 static void legend_close(void);
101
102 void legend_show(void)
103 {
104         if (!legend.window)
105                 legend_create();
106         else
107                 gtk_window_present(GTK_WINDOW(legend.window));
108 }
109
110 static void legend_create(void)
111 {
112         GtkWidget *window;
113         GtkWidget *vbox;
114         GtkWidget *confirm_area;
115         GtkWidget *close_button;
116         GtkWidget *hbox;
117         GtkWidget *label;
118         GtkWidget *icon_label;
119         GtkWidget *desc_label;
120         GtkWidget *scrolled_window;
121         GtkWidget *table;
122         gint i;
123
124         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "icon_legend");
125         gtk_window_set_title(GTK_WINDOW(window), _("Icon Legend"));
126         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
127         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
128         gtk_widget_set_size_request(window, 360, 570);
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(_("<span weight=\"bold\">The following icons "
144                                 "are used to show the status of messages and "
145                                 "folders:</span>"));
146         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
147         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
148         gtk_widget_show(label);
149         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
150
151         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
152         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
153                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
154         gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
155
156         table = gtk_table_new(ICONS, 2, FALSE);
157         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
158         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
159         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
160
161         for (i = 0; i < ICONS; ++i) {
162                 icon_label = stock_pixmap_widget(window, legend_icons[i]);
163                 gtk_misc_set_alignment (GTK_MISC (icon_label), 0.5, 0.5);
164                 gtk_table_attach(GTK_TABLE(table), icon_label, 0, 1, i, i+1,
165                                 GTK_FILL, 0, 0, 0);
166
167                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
168                 gtk_misc_set_alignment (GTK_MISC (desc_label), 0, 0.5);
169                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
170                 gtk_table_attach(GTK_TABLE(table), desc_label, 1, 2, i, i+1,
171                                 GTK_FILL, 0, 0, 0);
172         }       
173
174         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
175                                               table);
176
177         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
178                                       NULL, NULL, NULL, NULL);
179         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 4);
180         gtk_widget_grab_default(close_button);
181         g_signal_connect_closure
182                 (G_OBJECT(close_button), "clicked",
183                  g_cclosure_new_swap(G_CALLBACK(legend_close),
184                                      window, NULL), FALSE);
185
186         gtk_widget_show_all(window);
187
188         legend.window = window;
189 }
190
191 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
192 {
193         if (event && event->keyval == GDK_Escape) {
194                 legend_close();
195         }
196         return FALSE;
197 }
198
199 static void legend_close(void)
200 {
201         gtk_widget_destroy(legend.window);
202         legend.window = NULL;
203 }