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