5ca90f2a73dd00544888dd567573e8d2a1ec565c
[claws.git] / src / about.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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/gtkpixmap.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 #include <sys/utsname.h>
40
41 #include "intl.h"
42 #include "about.h"
43 #include "gtkutils.h"
44 #include "prefs_common.h"
45 #include "utils.h"
46
47 #include "pixmaps/sylpheed-logo.xpm"
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_show(window);
61 }
62
63 static void about_create(void)
64 {
65         GtkWidget *vbox;
66         GdkPixmap *logoxpm = NULL;
67         GdkBitmap *logoxpmmask;
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         struct utsname utsbuf;
82         gchar buf[1024];
83         gint i;
84
85         window = gtk_window_new(GTK_WINDOW_DIALOG);
86         gtk_window_set_title(GTK_WINDOW(window), _("About"));
87         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
88         gtk_widget_set_usize(window, 518, 358);
89         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
90         //gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
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_CREATE(window, logoxpm, logoxpmmask, sylpheed_logo_xpm);
101         pixmap = gtk_pixmap_new(logoxpm, logoxpmmask);
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         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
114         label = gtk_label_new(buf);
115         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
116
117         g_snprintf(buf, sizeof(buf),
118                    "Compiled-in features:%s",
119 #if HAVE_GDK_IMLIB
120                    " gdk_imlib"
121 #endif
122 #if HAVE_GDK_PIXBUF
123                    " gdk-pixbuf"
124 #endif
125 #if USE_THREADS
126                    " gthread"
127 #endif
128 #if INET6
129                    " IPv6"
130 #endif
131 #if HAVE_LIBCOMPFACE
132                    " libcompface"
133 #endif
134 #if HAVE_LIBJCONV
135                    " libjconv"
136 #endif
137 #if USE_GPGME
138                    " GPGME"
139 #endif
140         "");
141
142         label = gtk_label_new(buf);
143         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
144
145         label = gtk_label_new
146                 ("Copyright (C) 1999-2001 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
147         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
148
149         hbox = gtk_hbox_new(FALSE, 0);
150         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
151
152         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
153         gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
154         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
155         gtk_signal_connect(GTK_OBJECT(button), "clicked",
156                            GTK_SIGNAL_FUNC(about_uri_clicked), NULL);
157         buf[0] = ' ';
158         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
159         strcpy(buf + i, " ");
160         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
161         cmap = gdk_window_get_colormap(window->window);
162         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
163         if (success[0] == TRUE && success[1] == TRUE) {
164                 gtk_widget_ensure_style(GTK_BIN(button)->child);
165                 style = gtk_style_copy
166                         (gtk_widget_get_style(GTK_BIN(button)->child));
167                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
168                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
169                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
170                 gtk_widget_set_style(GTK_BIN(button)->child, style);
171         } else
172                 g_warning("about_create(): color allocation failed.\n");
173
174         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
175         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
176                                        GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
177         gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
178
179         text = gtk_text_new(gtk_scrolled_window_get_hadjustment
180                             (GTK_SCROLLED_WINDOW(scrolledwin)),
181                             gtk_scrolled_window_get_vadjustment
182                             (GTK_SCROLLED_WINDOW(scrolledwin)));
183         gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
184         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
185
186         gtk_text_freeze(GTK_TEXT(text));
187
188         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
189                 _("The portions applied from fetchmail is Copyright 1997 by Eric S. "
190                   "Raymond.  Portions of those are also copyrighted by Carl Harris, "
191                   "1993 and 1995.  Copyright retained for the purpose of protecting free "
192                   "redistribution of source.\n\n"), -1);
193
194         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
195                 _("The MD5 support is copyright by RSA Data Security, Inc.  See the "
196                   "header comment of the md5.c module for license terms.\n\n"), -1);
197
198         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
199                 _("Kcc is copyright by Yasuhiro Tonooka <tonooka@msi.co.jp>, "
200                   "and libkcc is copyright by takeshi@SoftAgency.co.jp.\n\n"), -1);
201
202 #if USE_GPGME
203         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
204                 _("GPGME is copyright 2001 by Werner Koch <dd9jn@gnu.org>\n\n"), -1);
205 #endif /* USE_GPGME */
206
207         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
208                 _("This program is free software; you can redistribute it and/or modify "
209                   "it under the terms of the GNU General Public License as published by "
210                   "the Free Software Foundation; either version 2, or (at your option) "
211                   "any later version.\n\n"), -1);
212
213         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
214                 _("This program is distributed in the hope that it will be useful, "
215                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
216                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
217                   "See the GNU General Public License for more details.\n\n"), -1);
218
219         gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL,
220                 _("You should have received a copy of the GNU General Public License "
221                   "along with this program; if not, write to the Free Software "
222                   "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
223                   "MA 02111-1307, USA."), -1);
224
225         gtk_text_thaw(GTK_TEXT(text));
226
227         gtkut_button_set_create(&confirm_area, &ok_button, _("OK"),
228                                 NULL, NULL, NULL, NULL);
229         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
230         gtk_widget_grab_default(ok_button);
231         gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
232                                   GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
233                                   GTK_OBJECT(window));
234
235         gtk_widget_show_all(window);
236 }
237
238 static void key_pressed(GtkWidget *widget, GdkEventKey *event)
239 {
240         if (event && event->keyval == GDK_Escape)
241                 gtk_widget_hide(window);
242 }
243
244 static void about_uri_clicked(GtkButton *button, gpointer data)
245 {
246         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
247 }