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