Statistics
| Revision:

root / src / about.c @ 3207

History | View | Annotate | Download (8.46 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2013 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 <glib/gi18n.h>
28
#include <gdk/gdkkeysyms.h>
29
#include <gtk/gtkwidget.h>
30
#include <gtk/gtkwindow.h>
31
#include <gtk/gtksignal.h>
32
#include <gtk/gtkvbox.h>
33
#include <gtk/gtkhbox.h>
34
#include <gtk/gtklabel.h>
35
#include <gtk/gtkhseparator.h>
36
#include <gtk/gtkscrolledwindow.h>
37
#include <gtk/gtktextview.h>
38
#include <gtk/gtkbutton.h>
39
#include <gtk/gtkstock.h>
40

    
41
#if HAVE_SYS_UTSNAME_H
42
#  include <sys/utsname.h>
43
#endif
44

    
45
#include "about.h"
46
#include "gtkutils.h"
47
#include "stock_pixmap.h"
48
#include "prefs_common.h"
49
#include "utils.h"
50
#include "version.h"
51

    
52
static GtkWidget *window;
53

    
54
static void about_create(void);
55
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
56
static void about_uri_clicked(GtkButton *button, gpointer data);
57

    
58
void about_show(void)
59
{
60
        if (!window)
61
                about_create();
62
        else
63
                gtk_window_present(GTK_WINDOW(window));
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
        GtkTextBuffer *buffer;
78
        GtkTextIter iter;
79
        GtkStyle *style;
80
        GdkColormap *cmap;
81
        GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
82
        gboolean success[2];
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
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
95
        g_signal_connect(G_OBJECT(window), "delete_event",
96
                         G_CALLBACK(gtk_widget_hide_on_delete), NULL);
97
        g_signal_connect(G_OBJECT(window), "key_press_event",
98
                         G_CALLBACK(key_pressed), NULL);
99
        gtk_widget_realize(window);
100

    
101
        vbox = gtk_vbox_new(FALSE, 6);
102
        gtk_container_add(GTK_CONTAINER(window), vbox);
103

    
104
        pixmap = stock_pixbuf_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
105
        gtk_box_pack_start(GTK_BOX(vbox), pixmap, FALSE, FALSE, 0);
106

    
107
        label = gtk_label_new("Version " VERSION
108
                              " (Build " Xstr(BUILD_REVISION) ")");
109
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
110
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
111

    
112
#if HAVE_SYS_UTSNAME_H
113
        uname(&utsbuf);
114
        g_snprintf(buf, sizeof(buf),
115
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
116
                   "Operating System: %s %s (%s)",
117
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
118
                   glib_major_version, glib_minor_version, glib_micro_version,
119
                   utsbuf.sysname, utsbuf.release, utsbuf.machine);
120
#elif defined(G_OS_WIN32)
121
        g_snprintf(buf, sizeof(buf),
122
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
123
                   "Operating System: %s",
124
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
125
                   glib_major_version, glib_minor_version, glib_micro_version,
126
                   "Win32");
127
#else
128
        g_snprintf(buf, sizeof(buf),
129
                   "GTK+ %d.%d.%d / GLib %d.%d.%d\n"
130
                   "Operating System: unknown",
131
                   gtk_major_version, gtk_minor_version, gtk_micro_version,
132
                   glib_major_version, glib_minor_version, glib_micro_version);
133
#endif
134

    
135
        label = gtk_label_new(buf);
136
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
137
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
138
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
139

    
140
        g_snprintf(buf, sizeof(buf),
141
                   "Compiled-in features:%s",
142
#if USE_THREADS
143
                   " gthread"
144
#endif
145
#if INET6
146
                   " IPv6"
147
#endif
148
#if HAVE_ICONV
149
                   " iconv"
150
#endif
151
#if HAVE_LIBCOMPFACE
152
                   " compface"
153
#endif
154
#if USE_GPGME
155
                   " GnuPG"
156
#endif
157
#if USE_SSL
158
                   " OpenSSL"
159
#endif
160
#if USE_LDAP
161
                   " LDAP"
162
#endif
163
#if USE_JPILOT
164
                   " JPilot"
165
#endif
166
#if USE_GTKSPELL
167
                   " GtkSpell"
168
#endif
169
#if USE_ONIGURUMA
170
                   " Oniguruma"
171
#endif
172
        "");
173

    
174
        label = gtk_label_new(buf);
175
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
176
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
177

    
178
        label = gtk_label_new
179
                ("Copyright (C) 1999-2013 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>");
180
        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
181
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
182

    
183
        hbox = gtk_hbox_new(FALSE, 0);
184
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
185

    
186
        button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
187
        gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
188
        gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
189
        g_signal_connect(G_OBJECT(button), "clicked",
190
                         G_CALLBACK(about_uri_clicked), NULL);
191
        buf[0] = ' ';
192
        for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
193
        strcpy(buf + i, " ");
194
        gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
195
        cmap = gdk_window_get_colormap(window->window);
196
        gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
197
        if (success[0] == TRUE && success[1] == TRUE) {
198
                gtk_widget_ensure_style(GTK_BIN(button)->child);
199
                style = gtk_style_copy
200
                        (gtk_widget_get_style(GTK_BIN(button)->child));
201
                style->fg[GTK_STATE_NORMAL]   = uri_color[0];
202
                style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
203
                style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
204
                gtk_widget_set_style(GTK_BIN(button)->child, style);
205
        } else
206
                g_warning("about_create(): color allocation failed.\n");
207

    
208
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
209
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
210
                                       GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
211
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
212
                                            GTK_SHADOW_IN);
213
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
214

    
215
        text = gtk_text_view_new();
216
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
217
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
218
        gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
219
        gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
220
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
221

    
222
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
223
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
224

    
225
#if USE_GPGME
226
        gtk_text_buffer_insert(buffer, &iter,
227
                _("GPGME is copyright 2001 by Werner Koch <dd9jn@gnu.org>\n\n"), -1);
228
#endif /* USE_GPGME */
229

    
230
        gtk_text_buffer_insert(buffer, &iter,
231
                _("This program is free software; you can redistribute it and/or modify "
232
                  "it under the terms of the GNU General Public License as published by "
233
                  "the Free Software Foundation; either version 2, or (at your option) "
234
                  "any later version.\n\n"), -1);
235

    
236
        gtk_text_buffer_insert(buffer, &iter,
237
                _("This program is distributed in the hope that it will be useful, "
238
                  "but WITHOUT ANY WARRANTY; without even the implied warranty of "
239
                  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
240
                  "See the GNU General Public License for more details.\n\n"), -1);
241

    
242
        gtk_text_buffer_insert(buffer, &iter,
243
                _("You should have received a copy of the GNU General Public License "
244
                  "along with this program; if not, write to the Free Software "
245
                  "Foundation, Inc., 59 Temple Place - Suite 330, Boston, "
246
                  "MA 02111-1307, USA."), -1);
247

    
248
        gtk_text_buffer_get_start_iter(buffer, &iter);
249
        gtk_text_buffer_place_cursor(buffer, &iter);
250

    
251
        gtkut_stock_button_set_create(&confirm_area, &ok_button, GTK_STOCK_OK,
252
                                      NULL, NULL, NULL, NULL);
253
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
254
        gtk_widget_grab_default(ok_button);
255
        gtk_widget_grab_focus(ok_button);
256
        g_signal_connect_closure
257
                (G_OBJECT(ok_button), "clicked",
258
                 g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
259
                                     window, NULL), FALSE);
260

    
261
        gtk_widget_show_all(window);
262
}
263

    
264
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
265
{
266
        if (event && event->keyval == GDK_Escape)
267
                gtk_widget_hide(window);
268
        return FALSE;
269
}
270

    
271
static void about_uri_clicked(GtkButton *button, gpointer data)
272
{
273
        open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
274
}