703590899b41bdbbd1bb49950e5b455f8948d47b
[claws.git] / src / about.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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 <gdk/gdkkeysyms.h>
28 #include <gtk/gtkwidget.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtksignal.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkhbox.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtkhseparator.h>
35 #include <gtk/gtkscrolledwindow.h>
36 #include <gtk/gtktext.h>
37 #include <gtk/gtkbutton.h>
38 #if HAVE_SYS_UTSNAME_H
39 #  include <sys/utsname.h>
40 #endif
41
42 #include "intl.h"
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 void 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_widget_show(window);
62 }
63
64 static void about_create(void)
65 {
66         GtkWidget *vbox;
67         GtkWidget *pixmap;
68         GtkWidget *label;
69         GtkWidget *hbox;
70         GtkWidget *button;
71         GtkWidget *scrolledwin;
72         GtkWidget *text;
73         GtkWidget *confirm_area;
74         GtkWidget *ok_button;
75         GtkStyle *style;
76         GdkColormap *cmap;
77         GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
78         gboolean success[2];
79
80 #if HAVE_SYS_UTSNAME_H
81         struct utsname utsbuf;
82 #endif
83         gchar buf[1024];
84         gint i;
85
86         window = gtk_window_new(GTK_WINDOW_DIALOG);
87         gtk_window_set_title(GTK_WINDOW(window), _("About"));
88         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
89         gtk_widget_set_usize(window, 518, 358);
90         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
91         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
92                            GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), NULL);
93         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
94                            GTK_SIGNAL_FUNC(key_pressed), NULL);
95         gtk_widget_realize(window);
96
97         vbox = gtk_vbox_new(FALSE, 6);
98         gtk_container_add(GTK_CONTAINER(window), vbox);
99
100         pixmap = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
101         gtk_box_pack_start(GTK_BOX(vbox), pixmap, FALSE, FALSE, 0);
102
103         label = gtk_label_new("version "VERSION);
104         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
105
106 #if HAVE_SYS_UTSNAME_H
107         uname(&utsbuf);
108         g_snprintf(buf, sizeof(buf),
109                    "GTK+ version %d.%d.%d\n"
110                    "Operating System: %s %s (%s)",
111                    gtk_major_version, gtk_minor_version, gtk_micro_version,
112                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
113 #else
114         g_snprintf(buf, sizeof(buf),
115                    "GTK+ version %d.%d.%d\n"
116                    "Operating System: Windoze",
117                    gtk_major_version, gtk_minor_version, gtk_micro_version);
118 #endif
119
120         label = gtk_label_new(buf);
121         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
122
123         g_snprintf(buf, sizeof(buf),
124                    "Compiled-in features:%s",
125 #if HAVE_GDK_IMLIB
126                    " gdk_imlib"
127 #endif
128 #if HAVE_GDK_PIXBUF
129                    " gdk-pixbuf"
130 #endif
131 #if USE_THREADS
132                    " gthread"
133 #endif
134 #if INET6
135                    " IPv6"
136 #endif
137 #if HAVE_LIBCOMPFACE
138                    " libcompface"
139 #endif
140 #if HAVE_LIBJCONV
141                    " libjconv"
142 #endif
143 #if USE_GPGME
144                    " GPGME"
145 #endif
146 #if USE_SSL
147                    " SSL"
148 #endif
149 #if USE_LDAP
150                    " LDAP"
151 #endif
152 #if USE_JPILOT
153                    " JPilot"
154 #endif
155 #if USE_PSPELL
156                    " pspell"
157 #endif
158         "");
159
160         label = gtk_label_new(buf);
161         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
162
163         label = gtk_label_new
164                 ("Copyright (C) 1999-2002 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
165         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
166
167         hbox = gtk_hbox_new(FALSE, 0);
168         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
169
170         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
171         gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
172         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
173         gtk_signal_connect(GTK_OBJECT(button), "clicked",
174                            GTK_SIGNAL_FUNC(about_uri_clicked), NULL);
175         buf[0] = ' ';
176         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
177         strcpy(buf + i, " ");
178         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
179         cmap = gdk_window_get_colormap(window->window);
180         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
181         if (success[0] == TRUE && success[1] == TRUE) {
182                 gtk_widget_ensure_style(GTK_BIN(button)->child);
183                 style = gtk_style_copy
184                         (gtk_widget_get_style(GTK_BIN(button)->child));
185                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
186                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
187                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
188                 gtk_widget_set_style(GTK_BIN(button)->child, style);
189         } else
190                 g_warning("about_create(): color allocation failed.\n");
191
192         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
193         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
194                                        GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
195         gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
196
197         text = gtk_text_new(gtk_scrolled_window_get_hadjustment
198                             (GTK_SCROLLED_WINDOW(scrolledwin)),
199                             gtk_scrolled_window_get_vadjustment
200                             (GTK_SCROLLED_WINDOW(scrolledwin)));
201         gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
202         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
203
204         gtk_text_freeze(GTK_TEXT(text));
205
206         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
207                 _("The portions applied from fetchmail is Copyright 1997 by Eric S. "
208                   "Raymond.  Portions of those are also copyrighted by Carl Harris, "
209                   "1993 and 1995.  Copyright retained for the purpose of protecting free "
210                   "redistribution of source.\n\n"), -1);
211
212         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
213                 _("Kcc is copyright by Yasuhiro Tonooka <tonooka@msi.co.jp>, "
214                   "and libkcc is copyright by takeshi@SoftAgency.co.jp.\n\n"), -1);
215
216 #if USE_GPGME
217         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
218                 _("GPGME is copyright 2001 by Werner Koch <dd9jn@gnu.org>\n\n"), -1);
219 #endif /* USE_GPGME */
220
221         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
222                 _("This program is free software; you can redistribute it and/or modify "
223                   "it under the terms of the GNU General Public License as published by "
224                   "the Free Software Foundation; either version 2, or (at your option) "
225                   "any later version.\n\n"), -1);
226
227         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
228                 _("This program is distributed in the hope that it will be useful, "
229                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
230                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
231                   "See the GNU General Public License for more details.\n\n"), -1);
232
233         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
234                 _("You should have received a copy of the GNU General Public License "
235                   "along with this program; if not, write to the Free Software "
236                   "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
237                   "MA 02111-1307, USA."), -1);
238
239         gtk_text_thaw(GTK_TEXT(text));
240
241         gtkut_button_set_create(&confirm_area, &ok_button, _("OK"),
242                                 NULL, NULL, NULL, NULL);
243         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
244         gtk_widget_grab_default(ok_button);
245         gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
246                                   GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
247                                   GTK_OBJECT(window));
248
249         gtk_widget_show_all(window);
250 }
251
252 static void key_pressed(GtkWidget *widget, GdkEventKey *event)
253 {
254         if (event && event->keyval == GDK_Escape)
255                 gtk_widget_hide(window);
256 }
257
258 static void about_uri_clicked(GtkButton *button, gpointer data)
259 {
260         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
261 }