Statistics
| Revision:

root / src / about.c @ 135

History | View | Annotate | Download (7.9 kB)

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