2005-10-20 [colin] 1.9.15cvs83
[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., 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 <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 #include "authors.h"
50 #include "codeconv.h"
51
52 static GtkWidget *window;
53 static GtkWidget *scrolledwin;
54
55 static void about_create(void);
56 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
57 static void about_uri_clicked(GtkButton *button, gpointer data);
58 static gboolean scrollme = FALSE;
59
60 static gboolean scroller(gpointer data)
61 {
62         GtkAdjustment *adj = (GtkAdjustment *)data;
63         if (adj->value != adj->upper)
64                 gtk_adjustment_set_value(adj, adj->value + 1);
65         else
66                 gtk_adjustment_set_value(adj, 0);
67         return scrollme;
68 }
69
70 void about_show(void)
71 {
72         GtkAdjustment *adj = NULL;
73         if (!window)
74                 about_create();
75         else
76                 gtk_window_present(GTK_WINDOW(window));
77         scrollme = TRUE;
78         adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin));
79         gtk_adjustment_set_value(adj, 0);
80         g_timeout_add(30, scroller, adj);
81 }
82
83 static void about_create(void)
84 {
85         GtkWidget *vbox1;
86         GtkWidget *table;
87         GtkWidget *image;       
88         GtkWidget *vbox2;
89         GtkWidget *label;
90         GtkWidget *button;
91         GtkStyle *style;
92         GdkColormap *cmap;
93         GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
94         gboolean success[2];
95         char *markup;
96         GtkWidget *text;
97         GtkWidget *confirm_area;
98         GtkWidget *close_button;
99         GtkTextBuffer *buffer;
100         GtkTextIter iter;
101         GdkColor color = {0, 0, 0, 0};
102
103 #if HAVE_SYS_UTSNAME_H
104         struct utsname utsbuf;
105 #endif
106         gchar buf[1024];
107         gint i;
108
109         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
110         gtk_window_set_title(GTK_WINDOW(window), _("About"));
111         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
112         gtk_widget_set_size_request(window, 518, 358);
113         g_signal_connect(G_OBJECT(window), "delete_event",
114                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
115         g_signal_connect(G_OBJECT(window), "key_press_event",
116                          G_CALLBACK(key_pressed), NULL);
117         gtk_widget_realize(window);
118
119         vbox1 = gtk_vbox_new(FALSE, 0);
120         gtk_container_add(GTK_CONTAINER(window), vbox1);
121
122         table = gtk_table_new (1, 2, FALSE);
123         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
124
125         image = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
126         gtk_table_attach(GTK_TABLE(table), image, 0, 1, 0, 1,
127                          (GtkAttachOptions) (GTK_SHRINK),
128                          (GtkAttachOptions) (GTK_SHRINK), 0, 0);
129
130         vbox2 = gtk_vbox_new (TRUE, 0);
131         gtk_table_attach(GTK_TABLE(table), vbox2, 1, 2, 0, 1,
132                          (GtkAttachOptions) (GTK_EXPAND),
133                          (GtkAttachOptions) (GTK_SHRINK), 0, 0);
134
135         label = gtk_label_new("");
136         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
137         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
138         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
139         markup = g_markup_printf_escaped
140                 ("<span weight=\"bold\" size=\"x-large\">Sylpheed-Claws</span>\nversion %s",
141                  VERSION);
142         gtk_label_set_markup(GTK_LABEL(label), markup);
143         g_free(markup);
144
145         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
146         gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0);
147         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
148         g_signal_connect(G_OBJECT(button), "clicked",
149                          G_CALLBACK(about_uri_clicked), NULL);
150         buf[0] = ' ';
151         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
152         strcpy(buf + i, " ");
153         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
154         cmap = gdk_drawable_get_colormap(window->window);
155         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
156         if (success[0] == TRUE && success[1] == TRUE) {
157                 gtk_widget_ensure_style(GTK_BIN(button)->child);
158                 style = gtk_style_copy
159                         (gtk_widget_get_style(GTK_BIN(button)->child));
160                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
161                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
162                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
163                 gtk_widget_set_style(GTK_BIN(button)->child, style);
164         } else
165                 g_warning("about_create(): color allocation failed.\n");
166
167 #if HAVE_SYS_UTSNAME_H
168         uname(&utsbuf);
169         g_snprintf(buf, sizeof(buf),
170                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
171                    "Operating System: %s %s (%s)"),
172                    gtk_major_version, gtk_minor_version, gtk_micro_version,
173                    glib_major_version, glib_minor_version, glib_micro_version,
174                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
175 #elif defined(G_OS_WIN32)
176         g_snprintf(buf, sizeof(buf),
177                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
178                    "Operating System: %s"),
179                    gtk_major_version, gtk_minor_version, gtk_micro_version,
180                    glib_major_version, glib_minor_version, glib_micro_version,
181                    "Win32");
182 #else
183         g_snprintf(buf, sizeof(buf),
184                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
185                    "Operating System: unknown"),
186                    gtk_major_version, gtk_minor_version, gtk_micro_version,
187                    glib_major_version, glib_minor_version, glib_micro_version);
188 #endif
189
190         label = gtk_label_new(buf);
191         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
192         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
193         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
194         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
195
196         g_snprintf(buf, sizeof(buf),
197                    _("Compiled-in features:%s"),
198 #if USE_THREADS
199                    " gthread"
200 #endif
201 #if INET6
202                    " IPv6"
203 #endif
204 #if HAVE_ICONV
205                    " iconv"
206 #endif
207 #if HAVE_LIBCOMPFACE
208                    " compface"
209 #endif
210 #if USE_OPENSSL
211                    " OpenSSL"
212 #endif
213 #if USE_LDAP
214                    " LDAP"
215 #endif
216 #if USE_JPILOT
217                    " JPilot"
218 #endif
219 #if USE_ASPELL
220                    " GNU/aspell"
221 #endif
222 #if HAVE_LIBETPAN
223                    " libetpan"
224 #endif
225 #if USE_GNOMEPRINT
226                    " libgnomeprint"
227 #endif
228         "");
229
230         label = gtk_label_new(buf);
231         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
232         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
233         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
234
235         label = gtk_label_new
236                 ("Copyright (C) 1999-2005 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>\n"
237                  "and the Sylpheed-Claws team");
238         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
239         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
240         gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0);
241
242         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
243         gtk_widget_set_size_request(scrolledwin, -1, 80);
244         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
245                                        GTK_POLICY_NEVER, GTK_POLICY_NEVER);
246         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
247                                             GTK_SHADOW_NONE);
248         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, FALSE, FALSE, 0);
249
250         text = gtk_text_view_new();
251         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
252         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
253         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
254         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
255         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
256
257         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
258         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
259
260         color = gtk_widget_get_style(label)->bg[GTK_STATE_NORMAL];
261         gtk_widget_modify_base (text, GTK_STATE_NORMAL, &color);
262
263
264         gtk_text_buffer_insert(buffer, &iter, "\n\n\n\n\n\n\n\n", -1);
265
266         gtk_text_buffer_insert(buffer, &iter,
267                 _("This program is free software; you can redistribute it and/or modify "
268                   "it under the terms of the GNU General Public License as published by "
269                   "the Free Software Foundation; either version 2, or (at your option) "
270                   "any later version.\n\n"), -1);
271
272         gtk_text_buffer_insert(buffer, &iter,
273                 _("This program is distributed in the hope that it will be useful, "
274                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
275                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
276                   "See the GNU General Public License for more details.\n\n"), -1);
277
278         gtk_text_buffer_insert(buffer, &iter,
279                 _("You should have received a copy of the GNU General Public License "
280                   "along with this program; if not, write to the Free Software "
281                   "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, "
282                   "MA 02110-1301, USA."), -1);
283 #ifdef USE_OPENSSL
284         gtk_text_buffer_insert(buffer, &iter,
285                 _("\n\nThis product includes software developed by the OpenSSL Project "
286                   "for use in the OpenSSL Toolkit (http://www.openssl.org/)"), -1);
287 #endif
288         gtk_text_buffer_insert(buffer, &iter,
289                 _("\n\n\nSylpheed-Claws is "
290                   "proudly brought to you by:\n\n"), -1);
291                 
292         if (g_utf8_validate(AUTHORS_LIST, -1, NULL))
293                 gtk_text_buffer_insert(buffer, &iter, AUTHORS_LIST, -1);
294         else {
295                 gchar *conv = conv_codeset_strdup(AUTHORS_LIST, CS_ISO_8859_1, CS_UTF_8);
296                 if (conv)
297                         gtk_text_buffer_insert(buffer, &iter, conv, -1);
298                 g_free(conv);
299         }
300                  
301         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
302                                       NULL, NULL, NULL, NULL);
303         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 4);
304         gtk_widget_grab_default(close_button);
305         gtk_widget_grab_focus(close_button);
306         g_signal_connect_closure
307                 (G_OBJECT(close_button), "clicked",
308                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
309                                      window, NULL), FALSE);
310
311         gtk_widget_show_all(window);
312 }
313
314 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
315 {
316         if (event && event->keyval == GDK_Escape) {
317                 scrollme = FALSE;
318                 gtk_widget_hide(window);
319         }
320         return FALSE;
321 }
322
323 static void about_uri_clicked(GtkButton *button, gpointer data)
324 {
325         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
326 }