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