2005-03-21 [holger] 1.9.6cvs7
[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
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         hbox1 = gtk_hbox_new (FALSE, 0);
104         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
105
106         pixmap = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
107         gtk_box_pack_start(GTK_BOX(hbox1), pixmap, FALSE, FALSE, 0);
108
109         vbox2 = gtk_vbox_new (FALSE, 6);
110         gtk_box_pack_start (GTK_BOX (hbox1), vbox2, TRUE, FALSE, 0);
111         
112         label = gtk_label_new("Sylpheed-Claws\nversion "VERSION);
113         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
114         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
115         gtk_box_pack_start(GTK_BOX(vbox2), label, TRUE, FALSE, 0);
116
117         hbox2 = gtk_hbox_new(FALSE, 0);
118         gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
119
120         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
121         gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, FALSE, 0);
122         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
123         g_signal_connect(G_OBJECT(button), "clicked",
124                          G_CALLBACK(about_uri_clicked), NULL);
125         buf[0] = ' ';
126         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
127         strcpy(buf + i, " ");
128         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
129         cmap = gdk_window_get_colormap(window->window);
130         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
131         if (success[0] == TRUE && success[1] == TRUE) {
132                 gtk_widget_ensure_style(GTK_BIN(button)->child);
133                 style = gtk_style_copy
134                         (gtk_widget_get_style(GTK_BIN(button)->child));
135                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
136                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
137                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
138                 gtk_widget_set_style(GTK_BIN(button)->child, style);
139         } else
140                 g_warning("about_create(): color allocation failed.\n");
141
142 #if HAVE_SYS_UTSNAME_H
143         uname(&utsbuf);
144         g_snprintf(buf, sizeof(buf),
145                    _("GTK+ version %d.%d.%d\n"
146                    "Operating System: %s %s (%s)"),
147                    gtk_major_version, gtk_minor_version, gtk_micro_version,
148                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
149 #else
150         g_snprintf(buf, sizeof(buf),
151                    "GTK+ version %d.%d.%d\n"
152                    "Operating System: Windoze",
153                    gtk_major_version, gtk_minor_version, gtk_micro_version);
154 #endif
155
156         label = gtk_label_new(buf);
157         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
158         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
159         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
160
161         g_snprintf(buf, sizeof(buf),
162                    _("Compiled-in features:%s"),
163 #if HAVE_GDK_IMLIB
164                    " gdk_imlib"
165 #endif
166 #if HAVE_GDK_PIXBUF
167                    " gdk-pixbuf"
168 #endif
169 #if USE_THREADS
170                    " gthread"
171 #endif
172 #if INET6
173                    " IPv6"
174 #endif
175 #if HAVE_ICONV
176                    " iconv"
177 #endif
178 #if HAVE_LIBCOMPFACE
179                    " compface"
180 #endif
181 #if USE_OPENSSL
182                    " OpenSSL"
183 #endif
184 #if USE_LDAP
185                    " LDAP"
186 #endif
187 #if USE_JPILOT
188                    " JPilot"
189 #endif
190 #if USE_ASPELL
191                    " GNU/aspell"
192 #endif
193         "");
194
195         label = gtk_label_new(buf);
196         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
197         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
198         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
199
200         label = gtk_label_new
201                 ("Copyright (C) 1999-2005 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
202         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
203         gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, FALSE, 4);
204
205         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
206         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
207                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
208         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
209                                             GTK_SHADOW_IN);
210         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, TRUE, TRUE, 0);
211
212         text = gtk_text_view_new();
213         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
214         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
215         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
216         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
217         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
218
219         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
220         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
221
222         gtk_text_buffer_insert(buffer, &iter,
223                 _("This program is free software; you can redistribute it and/or modify "
224                   "it under the terms of the GNU General Public License as published by "
225                   "the Free Software Foundation; either version 2, or (at your option) "
226                   "any later version.\n\n"), -1);
227
228         gtk_text_buffer_insert(buffer, &iter,
229                 _("This program is distributed in the hope that it will be useful, "
230                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
231                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
232                   "See the GNU General Public License for more details.\n\n"), -1);
233
234         gtk_text_buffer_insert(buffer, &iter,
235                 _("You should have received a copy of the GNU General Public License "
236                   "along with this program; if not, write to the Free Software "
237                   "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
238                   "MA 02111-1307, USA."), -1);
239
240         gtkut_stock_button_set_create(&confirm_area, &ok_button, GTK_STOCK_OK,
241                                       NULL, NULL, NULL, NULL);
242         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0);
243         gtk_widget_grab_default(ok_button);
244         g_signal_connect_closure
245                 (G_OBJECT(ok_button), "clicked",
246                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
247                                      window, NULL), FALSE);
248
249         gtk_widget_show_all(window);
250 }
251
252 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
253 {
254         if (event && event->keyval == GDK_Escape)
255                 gtk_widget_hide(window);
256         return FALSE;
257 }
258
259 static void about_uri_clicked(GtkButton *button, gpointer data)
260 {
261         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
262 }