File: about.c

package info (click to toggle)
gwyddion 2.52-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 46,588 kB
  • sloc: ansic: 367,740; python: 7,788; sh: 5,245; makefile: 4,317; xml: 3,631; cpp: 2,550; pascal: 418; perl: 154; ruby: 130
file content (333 lines) | stat: -rw-r--r-- 12,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 *  $Id: about.c 21345 2018-08-27 18:48:04Z yeti-dn $
 *  Copyright (C) 2003 David Necas (Yeti), Petr Klapetek.
 *  E-mail: yeti@gwyddion.net, klapetek@gwyddion.net.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#ifdef HAVE_GTKGLEXT
#include <gtk/gtkgl.h>
#endif
#include <libgwyddion/gwymacros.h>
#include <libgwyddion/gwyversion.h>
#include <libgwydgets/gwystock.h>
#include <libgwymodule/gwymoduleloader.h>
#include <app/app.h>
#include "gwyddion.h"
#include "authors.h"
#include "release.h"

static void about_close  (void);
static void fill_credits (GtkTextBuffer *buffer);
static void fill_features(GtkTextBuffer *buffer);
static void construct_datetime_info(GString *str);

static GtkWidget *about = NULL;

void
gwy_app_about(void)
{
    GtkWidget *vbox, *hbox, *widget, *credits, *text, *notebook;
    GtkTextBuffer *buff;
    GtkTextIter iter;
    GString *str = g_string_new(NULL);
    const gchar *verextra = "";
    gint size;

    if (about) {
        gtk_window_present(GTK_WINDOW(about));
        return;
    }
    g_string_printf(str, _("About %s"), g_get_application_name());
    about = gtk_dialog_new_with_buttons(str->str,
                                        GTK_WINDOW(gwy_app_main_window_get()),
                                        GTK_DIALOG_NO_SEPARATOR
                                        | GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
                                        NULL);
    gtk_dialog_set_default_response(GTK_DIALOG(about), GTK_RESPONSE_CLOSE);
    gtk_container_set_border_width(GTK_CONTAINER(about), 6);
    gtk_window_set_transient_for(GTK_WINDOW(about),
                                 GTK_WINDOW(gwy_app_main_window_get()));
    gtk_window_set_position(GTK_WINDOW(about), GTK_WIN_POS_CENTER);
    gwy_app_add_main_accel_group(GTK_WINDOW(about));

    vbox = GTK_DIALOG(about)->vbox;
    gtk_box_set_spacing(GTK_BOX(vbox), 8);

    hbox = gtk_hbox_new(FALSE, 6);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

    size = gtk_icon_size_from_name(GWY_ICON_SIZE_ABOUT);
    widget = gtk_image_new_from_stock(GWY_STOCK_GWYDDION, size);

    gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0);
    gtk_misc_set_alignment(GTK_MISC(widget), 0.5, 0.0);

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);

    widget = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
    gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, FALSE, 0);
    /* If we have unset release date but simple (non-date-extended) version
     * string then we are not compiling from a public tarball. */
    if (RELEASEDATE == 0 && strlen(GWY_VERSION_STRING) < 9)
        verextra = "+SVN";
    g_string_printf(str, "<span size='x-large' weight='bold'>%s %s%s</span>\n",
                    g_get_application_name(), GWY_VERSION_STRING, verextra);
    construct_datetime_info(str);
    g_string_append(str, _("An SPM data visualization and analysis tool."));
    gtk_label_set_markup(GTK_LABEL(widget), str->str);

    widget = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
    gtk_misc_set_padding(GTK_MISC(widget), 2, 6);
    gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, FALSE, 0);
    g_string_printf(str, "<i>%s</i>\n%s <i>%s</i>",
                    PACKAGE_URL, _("Report bugs to:"), PACKAGE_BUGREPORT);
    gtk_label_set_markup(GTK_LABEL(widget), str->str);
    gtk_label_set_selectable(GTK_LABEL(widget), TRUE);

    notebook = gtk_notebook_new();
    gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(about)->vbox), notebook,
                       TRUE, TRUE, 0);

    /* Credits */
    credits = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(credits),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_widget_set_size_request(credits, 320, 160);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                             credits, gtk_label_new(_("Credits")));

    buff = gtk_text_buffer_new(NULL);
    fill_credits(buff);

    text = gtk_text_view_new_with_buffer(buff);
    g_object_unref(buff);
    gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
    gtk_container_add(GTK_CONTAINER(credits), text);

    /* License */
    credits = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(credits),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_widget_set_size_request(credits, 320, 160);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                             credits, gtk_label_new(_("License")));

    buff = gtk_text_buffer_new(NULL);
    gtk_text_buffer_get_end_iter(buff, &iter);
    g_string_printf(str,
                    _("%s is free software; "
                      "you can redistribute it and/or modify it "
                      "under the terms of the GNU General Public License "
                      "as published by the Free Software Foundation; "
                      "either version 2 of the License, or (at your option) "
                      "any later version. For full license text see file "
                      "COPYING included in the source tarball."),
                    g_get_application_name());
    gtk_text_buffer_insert(buff, &iter, str->str, str->len);

    text = gtk_text_view_new_with_buffer(buff);
    g_object_unref(buff);
    gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
    gtk_container_add(GTK_CONTAINER(credits), text);

    /* Features */
    credits = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(credits),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_widget_set_size_request(credits, 320, 160);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                             credits, gtk_label_new(_("Features")));

    buff = gtk_text_buffer_new(NULL);
    fill_features(buff);

    text = gtk_text_view_new_with_buffer(buff);
    g_object_unref(buff);
    gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
    gtk_container_add(GTK_CONTAINER(credits), text);
    g_string_free(str, TRUE);

    gtk_widget_show_all(about);

    g_signal_connect(about, "delete-event",
                     G_CALLBACK(about_close), NULL);
    g_signal_connect(about, "response",
                     G_CALLBACK(about_close), NULL);
}

static void
about_close(void)
{
    gtk_widget_destroy(about);
    about = NULL;
}

static void
add_credits_block(GtkTextBuffer *buffer,
                  const gchar *title,
                  const gchar *body,
                  gboolean italicize)
{
    GtkTextIter iter;

    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, title, -1,
                                             "b", NULL);
    gtk_text_buffer_insert(buffer, &iter, "\n", 1);
    if (italicize)
        gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, body, -1,
                                                 "i", NULL);
    else
        gtk_text_buffer_insert(buffer, &iter, body, -1);
    gtk_text_buffer_insert(buffer, &iter, "\n", 1);
}

static void
fill_credits(GtkTextBuffer *buffer)
{
    GtkTextIter iter;

    gtk_text_buffer_create_tag(buffer, "uri",
                               "style", PANGO_STYLE_ITALIC,
                               "wrap-mode", GTK_WRAP_NONE,
                               NULL);
    gtk_text_buffer_create_tag(buffer, "b",
                               "weight", PANGO_WEIGHT_BOLD,
                               NULL);

    add_credits_block(buffer, _("Developers"), developers, FALSE);
    add_credits_block(buffer, _("Translators"), translators, FALSE);

    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert(buffer, &iter,
                           _("Development is supported by "
                             "the Czech Metrology Institute: "), -1);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
                                             "http://www.cmi.cz/", -1,
                                             "uri", NULL);
}

static void
fill_features(GtkTextBuffer *buffer)
{
    const GwyModuleInfo *modinfo;
    G_GNUC_UNUSED gchar *s;
    G_GNUC_UNUSED const gchar *cs;
    gboolean b;

    gtk_text_buffer_create_tag(buffer, "b",
                               "weight", PANGO_WEIGHT_BOLD,
                               NULL);
    gtk_text_buffer_create_tag(buffer, "i",
                               "style", PANGO_STYLE_ITALIC,
                               NULL);

#ifdef HAVE_GTKGLEXT
    /* FIXME: This shows some strange numbers in Win32 */
    s = g_strdup_printf("GtkGLExt %d.%d.%d\n",
                        gtkglext_major_version,
                        gtkglext_minor_version,
                        gtkglext_micro_version);
    add_credits_block(buffer, _("OpenGL 3D View"), s, FALSE);
    g_free(s);
#else
    add_credits_block(buffer, _("OpenGL 3D View"),
                      _("not available\n"), TRUE);
#endif

    b = FALSE;
#if (REMOTE_BACKEND == REMOTE_NONE)
    cs = _("not available\n");
    b = TRUE;
#elif (REMOTE_BACKEND == REMOTE_X11)
    cs = _("X11 protocol\n");
#elif (REMOTE_BACKEND == REMOTE_WIN32)
    cs = _("Win32 protocol\n");
#elif (REMOTE_BACKEND == REMOTE_UNIQUE)
    cs = _("LibUnique\n");
#else
#error "An unknown remote control backend."
#endif
    add_credits_block(buffer, _("Remote Control"), cs, b);

    if ((modinfo = gwy_module_lookup("pygwy"))) {
        s = g_strdup_printf("pygwy %s\n", modinfo->version);
        add_credits_block(buffer, _("Python Scripting Interface"), s, FALSE);
        g_free(s);
    }
    else
        add_credits_block(buffer, _("Python Scripting Interface"),
                          _("not available\n"), TRUE);
}

#if (RELEASEDATE == 0)
static void
construct_datetime_info(GString *str)
{
    GDate *gdate = g_date_new();
    gchar buf[12];

    g_date_set_parse(gdate, __DATE__);
    if (!g_date_valid(gdate)) {
        g_warning("Build date is invalid.");
        /* Avoid trigraphs. */
        g_snprintf(buf, sizeof(buf), "%.10s", "????" "-" "??" "-" "??");
    }
    else {
        g_snprintf(buf, sizeof(buf), "%04u-%02u-%02u",
                   (guint)g_date_get_year(gdate),
                   (guint)g_date_get_month(gdate),
                   (guint)g_date_get_day(gdate));
    }

    g_string_append(str, "<b>");
    /* TRANSLATORS: %s is replaced with date in ISO format YYYY-MM-DD. */
    g_string_append_printf(str, _("Development version, built %s"), buf);
    g_string_append(str, "</b>\n");
    g_date_free(gdate);
}
#else
static void
construct_datetime_info(GString *str)
{
    guint year = RELEASEDATE/0x10000u;
    guint month = (RELEASEDATE/0x100u % 0x100);
    guint day = RELEASEDATE % 0x100;
    gchar buf[12];

    g_snprintf(buf, sizeof(buf), "%04x-%02x-%02x", year, month, day);

    g_string_append(str, "<b>");
    /* TRANSLATORS: %s is replaced with date in ISO format YYYY-MM-DD. */
    g_string_append_printf(str, _("Released %s"), buf);
    g_string_append(str, "</b>\n");
}
#endif

/* vim: set cin et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */