2006-01-30 [colin] 2.0.0cvs1
[claws.git] / src / gtk / icon_legend.c
1 /*
2  * This file Copyright (C) 2005 Paul Mangan <claws@thewildbeast.co.uk>
3  * and the Sylpheed-Claws 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 12
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_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_LOCKED,
55         STOCK_PIXMAP_IGNORETHREAD,
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         N_("New"),
63         N_("Unread"),
64         N_("Has been replied to"),
65         N_("Has been forwarded"),
66         N_("Has attachment(s)"),
67         N_("Digitally signed"),
68         N_("Encrypted"),
69         N_("Signed and has attachment(s)"),
70         N_("Encrypted and has attachment(s)"),
71         N_("Marked"),
72         N_("Locked"),
73         N_("In an ignored thread"),
74         N_("Folder (normal, opened)"),
75         N_("Folder with read messages hidden"),
76         N_("Folder contains marked emails"),
77 };
78
79 static struct LegendDialog {
80         GtkWidget *window;
81 } legend;
82
83 static void legend_create(void);
84 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
85 static void legend_close(void);
86
87 void legend_show(void)
88 {
89         if (!legend.window)
90                 legend_create();
91         else
92                 gtk_window_present(GTK_WINDOW(legend.window));
93 }
94
95 static void legend_create(void)
96 {
97         GtkWidget *window;
98         GtkWidget *vbox;
99         GtkWidget *confirm_area;
100         GtkWidget *close_button;
101         GtkWidget *hbox;
102         GtkWidget *label;
103         GtkWidget *icon_label;
104         GtkWidget *desc_label;
105         gint i;
106
107         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
108         gtk_window_set_title(GTK_WINDOW(window), _("Icon Legend"));
109         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
110         gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
111         gtk_widget_set_size_request(window, -1, -1);
112         g_signal_connect(G_OBJECT(window), "delete_event",
113                          G_CALLBACK(legend_close), NULL);
114         g_signal_connect(G_OBJECT(window), "key_press_event",
115                          G_CALLBACK(key_pressed), NULL);
116         gtk_widget_realize(window);
117
118         vbox = gtk_vbox_new(FALSE, 8);
119         gtk_container_add(GTK_CONTAINER(window), vbox);
120         gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
121
122         hbox = gtk_hbox_new(FALSE, 8);
123         gtk_widget_show(hbox);
124         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
125
126         label = gtk_label_new(_("<span weight=\"bold\">The following icons are used to show the status of a message:</span>"));
127         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
128         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
129         gtk_widget_show(label);
130         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
131
132         for (i = 0; i < ICONS; ++i) {
133                 icon_label = stock_pixmap_widget(window, legend_icons[i]);
134                 desc_label = gtk_label_new(gettext(legend_icon_desc[i]));
135                 gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
136
137                 hbox = gtk_hbox_new(FALSE, 4);
138                 gtk_widget_show(hbox);
139                 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
140                 gtk_box_pack_start(GTK_BOX(hbox), icon_label, FALSE, FALSE, 0);
141                 gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 0);
142         }       
143
144         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
145                                       NULL, NULL, NULL, NULL);
146         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 4);
147         gtk_widget_grab_default(close_button);
148         g_signal_connect_closure
149                 (G_OBJECT(close_button), "clicked",
150                  g_cclosure_new_swap(G_CALLBACK(legend_close),
151                                      window, NULL), FALSE);
152
153         gtk_widget_show_all(window);
154
155         legend.window = window;
156 }
157
158 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
159 {
160         if (event && event->keyval == GDK_Escape) {
161                 legend_close();
162         }
163         return FALSE;
164 }
165
166 static void legend_close(void)
167 {
168         gtk_widget_destroy(legend.window);
169         legend.window = NULL;
170 }