2005-03-21 [paul] 1.9.6cvs8
[claws.git] / src / gtk / about.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <gdk/gdkkeysyms.h>
29 #include <gtk/gtkwidget.h>
30 #include <gtk/gtkwindow.h>
31 #include <gtk/gtksignal.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtkhbox.h>
34 #include <gtk/gtklabel.h>
35 #include <gtk/gtkhseparator.h>
36 #include <gtk/gtkscrolledwindow.h>
37 #include <gtk/gtktext.h>
38 #include <gtk/gtkbutton.h>
39 #if HAVE_SYS_UTSNAME_H
40 #  include <sys/utsname.h>
41 #endif
42
43 #include "about.h"
44 #include "gtkutils.h"
45 #include "stock_pixmap.h"
46 #include "prefs_common.h"
47 #include "utils.h"
48 #include "version.h"
49
50 static GtkWidget *window;
51
52 static void about_create(void);
53 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
54 static void about_uri_clicked(GtkButton *button, gpointer data);
55
56 void about_show(void)
57 {
58         if (!window)
59                 about_create();
60         else
61                 gtk_window_present(GTK_WINDOW(window));
62 }
63
64 static void about_create(void)
65 {
66         GtkWidget *pixmap;
67         GtkWidget *label;
68         GtkWidget *hbox1;
69         GtkWidget *hbox2;
70         GtkWidget *vbox1;
71         GtkWidget *vbox2;
72         GtkWidget *button;
73         GtkWidget *scrolledwin;
74         GtkWidget *text;
75         GtkWidget *confirm_area;
76         GtkWidget *ok_button;
77         GtkTextBuffer *buffer;
78         GtkTextIter iter;
79         GtkStyle *style;
80         GdkColormap *cmap;
81         GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
82         gboolean success[2];
83         char *markup;
84
85 #if HAVE_SYS_UTSNAME_H
86         struct utsname utsbuf;
87 #endif
88         gchar buf[1024];
89         gint i;
90
91         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
92         gtk_window_set_title(GTK_WINDOW(window), _("About"));
93         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
94         gtk_widget_set_size_request(window, 518, 358);
95         g_signal_connect(G_OBJECT(window), "delete_event",
96                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
97         g_signal_connect(G_OBJECT(window), "key_press_event",
98                          G_CALLBACK(key_pressed), NULL);
99         gtk_widget_realize(window);
100
101         vbox1 = gtk_vbox_new(FALSE, 0);
102         gtk_container_add(GTK_CONTAINER(window), vbox1);
103
104         hbox1 = gtk_hbox_new (FALSE, 0);
105         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
106
107         pixmap = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
108         gtk_box_pack_start(GTK_BOX(hbox1), pixmap, FALSE, FALSE, 0);
109
110         vbox2 = gtk_vbox_new (FALSE, 6);
111         gtk_box_pack_start (GTK_BOX (hbox1), vbox2, TRUE, FALSE, 0);
112         
113         label = gtk_label_new("");
114         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
115         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
116         gtk_box_pack_start(GTK_BOX(vbox2), label, TRUE, FALSE, 0);
117
118         markup = g_markup_printf_escaped
119                 ("<span weight=\"bold\" size=\"x-large\">Sylpheed-Claws</span>\nversion %s",
120                  VERSION);
121         gtk_label_set_markup(GTK_LABEL(label), markup);
122         g_free(markup);
123
124         hbox2 = gtk_hbox_new(FALSE, 0);
125         gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
126
127         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
128         gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, FALSE, 0);
129         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
130         g_signal_connect(G_OBJECT(button), "clicked",
131                          G_CALLBACK(about_uri_clicked), NULL);
132         buf[0] = ' ';
133         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
134         strcpy(buf + i, " ");
135         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
136         cmap = gdk_window_get_colormap(window->window);
137         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
138         if (success[0] == TRUE && success[1] == TRUE) {
139                 gtk_widget_ensure_style(GTK_BIN(button)->child);
140                 style = gtk_style_copy
141                         (gtk_widget_get_style(GTK_BIN(button)->child));
142                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
143                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
144                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
145                 gtk_widget_set_style(GTK_BIN(button)->child, style);
146         } else
147                 g_warning("about_create(): color allocation failed.\n");
148
149 #if HAVE_SYS_UTSNAME_H
150         uname(&utsbuf);
151         g_snprintf(buf, sizeof(buf),
152                    _("GTK+ version %d.%d.%d\n"
153                    "Operating System: %s %s (%s)"),
154                    gtk_major_version, gtk_minor_version, gtk_micro_version,
155                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
156 #else
157         g_snprintf(buf, sizeof(buf),
158                    "GTK+ version %d.%d.%d\n"
159                    "Operating System: Windoze",
160                    gtk_major_version, gtk_minor_version, gtk_micro_version);
161 #endif
162
163         label = gtk_label_new(buf);
164         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
165         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
166         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
167
168         g_snprintf(buf, sizeof(buf),
169                    _("Compiled-in features:%s"),
170 #if HAVE_GDK_IMLIB
171                    " gdk_imlib"
172 #endif
173 #if HAVE_GDK_PIXBUF
174                    " gdk-pixbuf"
175 #endif
176 #if USE_THREADS
177                    " gthread"
178 #endif
179 #if INET6
180                    " IPv6"
181 #endif
182 #if HAVE_ICONV
183                    " iconv"
184 #endif
185 #if HAVE_LIBCOMPFACE
186                    " compface"
187 #endif
188 #if USE_OPENSSL
189                    " OpenSSL"
190 #endif
191 #if USE_LDAP
192                    " LDAP"
193 #endif
194 #if USE_JPILOT
195                    " JPilot"
196 #endif
197 #if USE_ASPELL
198                    " GNU/aspell"
199 #endif
200         "");
201
202         label = gtk_label_new(buf);
203         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
204         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
205         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
206
207         label = gtk_label_new
208                 ("Copyright (C) 1999-2005 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
209         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
210         gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, FALSE, 4);
211
212         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
213         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
214                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
215         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
216                                             GTK_SHADOW_IN);
217         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, TRUE, TRUE, 0);
218
219         text = gtk_text_view_new();
220         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
221         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
222         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
223         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
224         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
225
226         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
227         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
228
229         gtk_text_buffer_insert(buffer, &iter,
230                 _("This program is free software; you can redistribute it and/or modify "
231                   "it under the terms of the GNU General Public License as published by "
232                   "the Free Software Foundation; either version 2, or (at your option) "
233                   "any later version.\n\n"), -1);
234
235         gtk_text_buffer_insert(buffer, &iter,
236                 _("This program is distributed in the hope that it will be useful, "
237                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
238                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
239                   "See the GNU General Public License for more details.\n\n"), -1);
240
241         gtk_text_buffer_insert(buffer, &iter,
242                 _("You should have received a copy of the GNU General Public License "
243                   "along with this program; if not, write to the Free Software "
244                   "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
245                   "MA 02111-1307, USA."), -1);
246
247         gtkut_stock_button_set_create(&confirm_area, &ok_button, GTK_STOCK_OK,
248                                       NULL, NULL, NULL, NULL);
249         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0);
250         gtk_widget_grab_default(ok_button);
251         g_signal_connect_closure
252                 (G_OBJECT(ok_button), "clicked",
253                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
254                                      window, NULL), FALSE);
255
256         gtk_widget_show_all(window);
257 }
258
259 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
260 {
261         if (event && event->keyval == GDK_Escape)
262                 gtk_widget_hide(window);
263         return FALSE;
264 }
265
266 static void about_uri_clicked(GtkButton *button, gpointer data)
267 {
268         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
269 }