Statistics
| Revision:

root / src / about.c @ 1607

History | View | Annotate | Download (8.3 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 1490 hiro
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#ifdef HAVE_CONFIG_H
21 1 hiro
#  include "config.h"
22 1 hiro
#endif
23 1 hiro
24 1 hiro
#include "defs.h"
25 1 hiro
26 1 hiro
#include <glib.h>
27 92 hiro
#include <glib/gi18n.h>
28 1 hiro
#include <gdk/gdkkeysyms.h>
29 1 hiro
#include <gtk/gtkwidget.h>
30 1 hiro
#include <gtk/gtkwindow.h>
31 1 hiro
#include <gtk/gtksignal.h>
32 1 hiro
#include <gtk/gtkvbox.h>
33 1 hiro
#include <gtk/gtkhbox.h>
34 1 hiro
#include <gtk/gtklabel.h>
35 1 hiro
#include <gtk/gtkhseparator.h>
36 1 hiro
#include <gtk/gtkscrolledwindow.h>
37 1 hiro
#include <gtk/gtktextview.h>
38 1 hiro
#include <gtk/gtkbutton.h>
39 237 hiro
#include <gtk/gtkstock.h>
40 237 hiro
41 1 hiro
#if HAVE_SYS_UTSNAME_H
42 1 hiro
#  include <sys/utsname.h>
43 1 hiro
#endif
44 1 hiro
45 1 hiro
#include "about.h"
46 1 hiro
#include "gtkutils.h"
47 1 hiro
#include "stock_pixmap.h"
48 1 hiro
#include "prefs_common.h"
49 1 hiro
#include "utils.h"
50 1 hiro
#include "version.h"
51 1 hiro
52 1 hiro
static GtkWidget *window;
53 1 hiro
54 1 hiro
static void about_create(void);
55 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
56 1 hiro
static void about_uri_clicked(GtkButton *button, gpointer data);
57 1 hiro
58 1 hiro
void about_show(void)
59 1 hiro
{
60 1 hiro
        if (!window)
61 1 hiro
                about_create();
62 94 hiro
        else
63 94 hiro
                gtk_window_present(GTK_WINDOW(window));
64 1 hiro
}
65 1 hiro
66 1 hiro
static void about_create(void)
67 1 hiro
{
68 1 hiro
        GtkWidget *vbox;
69 1 hiro
        GtkWidget *pixmap;
70 1 hiro
        GtkWidget *label;
71 1 hiro
        GtkWidget *hbox;
72 1 hiro
        GtkWidget *button;
73 1 hiro
        GtkWidget *scrolledwin;
74 1 hiro
        GtkWidget *text;
75 1 hiro
        GtkWidget *confirm_area;
76 1 hiro
        GtkWidget *ok_button;
77 1 hiro
        GtkTextBuffer *buffer;
78 1 hiro
        GtkTextIter iter;
79 1 hiro
        GtkStyle *style;
80 1 hiro
        GdkColormap *cmap;
81 1 hiro
        GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
82 1 hiro
        gboolean success[2];
83 1 hiro
84 1 hiro
#if HAVE_SYS_UTSNAME_H
85 1 hiro
        struct utsname utsbuf;
86 1 hiro
#endif
87 1 hiro
        gchar buf[1024];
88 1 hiro
        gint i;
89 1 hiro
90 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
91 1 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("About"));
92 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
93 1 hiro
        gtk_widget_set_size_request(window, 518, 358);
94 1 hiro
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
95 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
96 1 hiro
                         G_CALLBACK(gtk_widget_hide_on_delete), NULL);
97 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
98 1 hiro
                         G_CALLBACK(key_pressed), NULL);
99 1 hiro
        gtk_widget_realize(window);
100 1 hiro
101 1 hiro
        vbox = gtk_vbox_new(FALSE, 6);
102 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
103 1 hiro
104 398 hiro
        pixmap = stock_pixbuf_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
105 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), pixmap, FALSE, FALSE, 0);
106 1 hiro
107 1 hiro
        label = gtk_label_new("version "VERSION);
108 10 hiro
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
109 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
110 1 hiro
111 1 hiro
#if HAVE_SYS_UTSNAME_H
112 1 hiro
        uname(&utsbuf);
113 1 hiro
        g_snprintf(buf, sizeof(buf),
114 463 hiro
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
115 1 hiro
                   "Operating System: %s %s (%s)",
116 1 hiro
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
117 463 hiro
                   glib_major_version, glib_minor_version, glib_micro_version,
118 1 hiro
                   utsbuf.sysname, utsbuf.release, utsbuf.machine);
119 469 hiro
#elif defined(G_OS_WIN32)
120 463 hiro
        g_snprintf(buf, sizeof(buf),
121 463 hiro
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
122 463 hiro
                   "Operating System: %s",
123 463 hiro
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
124 463 hiro
                   glib_major_version, glib_minor_version, glib_micro_version,
125 463 hiro
                   "Win32");
126 1 hiro
#else
127 1 hiro
        g_snprintf(buf, sizeof(buf),
128 463 hiro
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
129 463 hiro
                   "Operating System: unknown",
130 463 hiro
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
131 463 hiro
                   glib_major_version, glib_minor_version, glib_micro_version);
132 1 hiro
#endif
133 1 hiro
134 1 hiro
        label = gtk_label_new(buf);
135 10 hiro
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
136 10 hiro
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
137 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
138 1 hiro
139 1 hiro
        g_snprintf(buf, sizeof(buf),
140 1 hiro
                   "Compiled-in features:%s",
141 1 hiro
#if USE_THREADS
142 1 hiro
                   " gthread"
143 1 hiro
#endif
144 1 hiro
#if INET6
145 1 hiro
                   " IPv6"
146 1 hiro
#endif
147 1 hiro
#if HAVE_ICONV
148 1 hiro
                   " iconv"
149 1 hiro
#endif
150 1 hiro
#if HAVE_LIBCOMPFACE
151 1 hiro
                   " compface"
152 1 hiro
#endif
153 1 hiro
#if USE_GPGME
154 1 hiro
                   " GnuPG"
155 1 hiro
#endif
156 1 hiro
#if USE_SSL
157 1 hiro
                   " OpenSSL"
158 1 hiro
#endif
159 1 hiro
#if USE_LDAP
160 1 hiro
                   " LDAP"
161 1 hiro
#endif
162 1 hiro
#if USE_JPILOT
163 1 hiro
                   " JPilot"
164 1 hiro
#endif
165 756 hiro
#if USE_GTKSPELL
166 756 hiro
                   " GtkSpell"
167 756 hiro
#endif
168 1113 hiro
#if USE_ONIGURUMA
169 1113 hiro
                   " Oniguruma"
170 1113 hiro
#endif
171 1 hiro
        "");
172 1 hiro
173 1 hiro
        label = gtk_label_new(buf);
174 10 hiro
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
175 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
176 1 hiro
177 1 hiro
        label = gtk_label_new
178 1490 hiro
                ("Copyright (C) 1999-2007 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
179 10 hiro
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
180 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
181 1 hiro
182 1 hiro
        hbox = gtk_hbox_new(FALSE, 0);
183 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
184 1 hiro
185 1 hiro
        button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
186 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
187 1 hiro
        gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
188 1 hiro
        g_signal_connect(G_OBJECT(button), "clicked",
189 1 hiro
                         G_CALLBACK(about_uri_clicked), NULL);
190 1 hiro
        buf[0] = ' ';
191 1 hiro
        for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
192 1 hiro
        strcpy(buf + i, " ");
193 1 hiro
        gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
194 1 hiro
        cmap = gdk_window_get_colormap(window->window);
195 1 hiro
        gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
196 1 hiro
        if (success[0] == TRUE && success[1] == TRUE) {
197 1 hiro
                gtk_widget_ensure_style(GTK_BIN(button)->child);
198 1 hiro
                style = gtk_style_copy
199 1 hiro
                        (gtk_widget_get_style(GTK_BIN(button)->child));
200 1 hiro
                style->fg[GTK_STATE_NORMAL]   = uri_color[0];
201 1 hiro
                style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
202 1 hiro
                style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
203 1 hiro
                gtk_widget_set_style(GTK_BIN(button)->child, style);
204 1 hiro
        } else
205 1 hiro
                g_warning("about_create(): color allocation failed.\n");
206 1 hiro
207 1 hiro
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
208 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
209 1 hiro
                                       GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
210 9 hiro
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
211 9 hiro
                                            GTK_SHADOW_IN);
212 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
213 1 hiro
214 1 hiro
        text = gtk_text_view_new();
215 1 hiro
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
216 1 hiro
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
217 10 hiro
        gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
218 10 hiro
        gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
219 1 hiro
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
220 1 hiro
221 1 hiro
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
222 1 hiro
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
223 1 hiro
224 1 hiro
#if USE_GPGME
225 1 hiro
        gtk_text_buffer_insert(buffer, &iter,
226 1 hiro
                _("GPGME is copyright 2001 by Werner Koch <dd9jn@gnu.org>\n\n"), -1);
227 1 hiro
#endif /* USE_GPGME */
228 1 hiro
229 1 hiro
        gtk_text_buffer_insert(buffer, &iter,
230 1 hiro
                _("This program is free software; you can redistribute it and/or modify "
231 1 hiro
                  "it under the terms of the GNU General Public License as published by "
232 1 hiro
                  "the Free Software Foundation; either version 2, or (at your option) "
233 1 hiro
                  "any later version.\n\n"), -1);
234 1 hiro
235 1 hiro
        gtk_text_buffer_insert(buffer, &iter,
236 1 hiro
                _("This program is distributed in the hope that it will be useful, "
237 1 hiro
                  "but WITHOUT ANY WARRANTY; without even the implied warranty of "
238 1 hiro
                  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
239 1 hiro
                  "See the GNU General Public License for more details.\n\n"), -1);
240 1 hiro
241 1 hiro
        gtk_text_buffer_insert(buffer, &iter,
242 1 hiro
                _("You should have received a copy of the GNU General Public License "
243 1 hiro
                  "along with this program; if not, write to the Free Software "
244 1 hiro
                  "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
245 1 hiro
                  "MA 02111-1307, USA."), -1);
246 1 hiro
247 30 hiro
        gtkut_stock_button_set_create(&confirm_area, &ok_button, GTK_STOCK_OK,
248 30 hiro
                                      NULL, NULL, NULL, NULL);
249 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
250 1 hiro
        gtk_widget_grab_default(ok_button);
251 457 hiro
        gtk_widget_grab_focus(ok_button);
252 1 hiro
        g_signal_connect_closure
253 1 hiro
                (G_OBJECT(ok_button), "clicked",
254 1 hiro
                 g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
255 1 hiro
                                     window, NULL), FALSE);
256 1 hiro
257 1 hiro
        gtk_widget_show_all(window);
258 1 hiro
}
259 1 hiro
260 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
261 1 hiro
{
262 1 hiro
        if (event && event->keyval == GDK_Escape)
263 1 hiro
                gtk_widget_hide(window);
264 1 hiro
        return FALSE;
265 1 hiro
}
266 1 hiro
267 1 hiro
static void about_uri_clicked(GtkButton *button, gpointer data)
268 1 hiro
{
269 1 hiro
        open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
270 1 hiro
}