7861ae16b3009717f3b7c27da4f929b6f2eaf38b
[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 *vbox1;
67         GtkWidget *table;
68         GtkWidget *image;       
69         GtkWidget *vbox2;
70         GtkWidget *label;
71         GtkWidget *button;
72         GtkWidget *scrolledwin;
73         GtkStyle *style;
74         GdkColormap *cmap;
75         GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
76         gboolean success[2];
77         char *markup;
78         GtkWidget *text;
79         GtkWidget *confirm_area;
80         GtkWidget *close_button;
81         GtkTextBuffer *buffer;
82         GtkTextIter iter;
83
84 #if HAVE_SYS_UTSNAME_H
85         struct utsname utsbuf;
86 #endif
87         gchar buf[1024];
88         gint i;
89
90         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
91         gtk_window_set_title(GTK_WINDOW(window), _("About"));
92         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
93         gtk_widget_set_size_request(window, 518, 358);
94         g_signal_connect(G_OBJECT(window), "delete_event",
95                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
96         g_signal_connect(G_OBJECT(window), "key_press_event",
97                          G_CALLBACK(key_pressed), NULL);
98         gtk_widget_realize(window);
99
100         vbox1 = gtk_vbox_new(FALSE, 0);
101         gtk_container_add(GTK_CONTAINER(window), vbox1);
102
103         table = gtk_table_new (1, 2, FALSE);
104         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
105
106         image = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
107         gtk_table_attach(GTK_TABLE(table), image, 0, 1, 0, 1,
108                          (GtkAttachOptions) (GTK_SHRINK),
109                          (GtkAttachOptions) (GTK_SHRINK), 0, 0);
110
111         vbox2 = gtk_vbox_new (TRUE, 0);
112         gtk_table_attach(GTK_TABLE(table), vbox2, 1, 2, 0, 1,
113                          (GtkAttachOptions) (GTK_EXPAND),
114                          (GtkAttachOptions) (GTK_SHRINK), 0, 0);
115
116         label = gtk_label_new("");
117         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
118         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
119         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
120         markup = g_markup_printf_escaped
121                 ("<span weight=\"bold\" size=\"x-large\">Sylpheed-Claws</span>\nversion %s",
122                  VERSION);
123         gtk_label_set_markup(GTK_LABEL(label), markup);
124         g_free(markup);
125
126         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
127         gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0);
128         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
129         g_signal_connect(G_OBJECT(button), "clicked",
130                          G_CALLBACK(about_uri_clicked), NULL);
131         buf[0] = ' ';
132         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
133         strcpy(buf + i, " ");
134         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
135         cmap = gdk_window_get_colormap(window->window);
136         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
137         if (success[0] == TRUE && success[1] == TRUE) {
138                 gtk_widget_ensure_style(GTK_BIN(button)->child);
139                 style = gtk_style_copy
140                         (gtk_widget_get_style(GTK_BIN(button)->child));
141                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
142                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
143                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
144                 gtk_widget_set_style(GTK_BIN(button)->child, style);
145         } else
146                 g_warning("about_create(): color allocation failed.\n");
147
148 #if HAVE_SYS_UTSNAME_H
149         uname(&utsbuf);
150         g_snprintf(buf, sizeof(buf),
151                    _("GTK+ version %d.%d.%d\n"
152                    "Operating System: %s %s (%s)"),
153                    gtk_major_version, gtk_minor_version, gtk_micro_version,
154                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
155 #else
156         g_snprintf(buf, sizeof(buf),
157                    "GTK+ version %d.%d.%d\n"
158                    "Operating System: Windoze",
159                    gtk_major_version, gtk_minor_version, gtk_micro_version);
160 #endif
161
162         label = gtk_label_new(buf);
163         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
164         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
165         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
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 USE_THREADS
171                    " gthread"
172 #endif
173 #if INET6
174                    " IPv6"
175 #endif
176 #if HAVE_ICONV
177                    " iconv"
178 #endif
179 #if HAVE_LIBCOMPFACE
180                    " compface"
181 #endif
182 #if USE_OPENSSL
183                    " OpenSSL"
184 #endif
185 #if USE_LDAP
186                    " LDAP"
187 #endif
188 #if USE_JPILOT
189                    " JPilot"
190 #endif
191 #if USE_ASPELL
192                    " GNU/aspell"
193 #endif
194 #if HAVE_LIBETPAN
195                    " libetpan"
196 #endif
197 #if USE_GNOMEPRINT
198                    " libgnomeprint"
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>\n"
209                  "and the Sylpheed-Claws team");
210         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
211         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
212         gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0);
213
214         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
215         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
216                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
217         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
218                                             GTK_SHADOW_IN);
219         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, TRUE, TRUE, 0);
220
221         text = gtk_text_view_new();
222         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
223         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
224         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
225         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
226         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
227
228         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
229         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
230
231         gtk_text_buffer_insert(buffer, &iter,
232                 _("This program is free software; you can redistribute it and/or modify "
233                   "it under the terms of the GNU General Public License as published by "
234                   "the Free Software Foundation; either version 2, or (at your option) "
235                   "any later version.\n\n"), -1);
236
237         gtk_text_buffer_insert(buffer, &iter,
238                 _("This program is distributed in the hope that it will be useful, "
239                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
240                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
241                   "See the GNU General Public License for more details.\n\n"), -1);
242
243         gtk_text_buffer_insert(buffer, &iter,
244                 _("You should have received a copy of the GNU General Public License "
245                   "along with this program; if not, write to the Free Software "
246                   "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
247                   "MA 02111-1307, USA."), -1);
248 #ifdef USE_OPENSSL
249         gtk_text_buffer_insert(buffer, &iter,
250                 _("\n\nThis product includes software developed by the OpenSSL Project "
251                   "for use in the OpenSSL Toolkit (http://www.openssl.org/)"), -1);
252 #endif
253         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
254                                       NULL, NULL, NULL, NULL);
255         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 4);
256         gtk_widget_grab_default(close_button);
257         gtk_widget_grab_focus(close_button);
258         g_signal_connect_closure
259                 (G_OBJECT(close_button), "clicked",
260                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
261                                      window, NULL), FALSE);
262
263         gtk_widget_show_all(window);
264 }
265
266 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
267 {
268         if (event && event->keyval == GDK_Escape)
269                 gtk_widget_hide(window);
270         return FALSE;
271 }
272
273 static void about_uri_clicked(GtkButton *button, gpointer data)
274 {
275         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
276 }