File: about.c

package info (click to toggle)
gretl 2016d-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 48,620 kB
  • ctags: 22,779
  • sloc: ansic: 345,830; sh: 4,648; makefile: 2,712; xml: 570; perl: 364
file content (230 lines) | stat: -rw-r--r-- 7,218 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
/* 
 *  gretl -- Gnu Regression, Econometrics and Time-series Library
 *  Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
 * 
 *  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 3 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, see <http://www.gnu.org/licenses/>.
 * 
 */

#include "gretl.h"
#include "version.h"
#include "dlgutils.h"
#include "build.h"

#ifdef G_OS_WIN32
# include "gretlwin32.h"
#endif

const gchar *copyright = "Copyright (C) 2000-2016 Allin Cottrell and "
                         "Riccardo \"Jack\" Lucchetti";
const gchar *bonmot = N_("\"By econometricians, for econometricians.\"");
const gchar *website = "http://gretl.sourceforge.net/";

static GtkWidget *open_logo (void)
{
    char *fname;
    GdkPixbuf *pbuf;
    GError *error = NULL;
    GtkWidget *image = NULL;

    fname = g_strdup_printf("%sgretl-logo.xpm", gretl_home());
    pbuf = gdk_pixbuf_new_from_file(fname, &error);

    if (pbuf == NULL) {
	errbox(error->message);
	g_error_free(error);
    } else {
	image = gtk_image_new_from_pixbuf(pbuf);
	g_object_unref(pbuf);
    }

    g_free(fname);

    return image;
}

static void license_callback (GtkWidget *w, gpointer p)
{
    gchar *fname;

    fname = g_strdup_printf("%sCOPYING", gretl_home());
    view_file(fname, 0, 0, 78, 350, VIEW_DOC);
    g_free(fname);
}

static void relnotes_callback (GtkWidget *w, gpointer p)
{
    gchar *fname;

    fname = g_strdup_printf("%sNEWS", gretl_home());
    view_file(fname, 0, 0, 78, 350, VIEW_DOC);
    g_free(fname);
}

static void show_link_cursor (GtkWidget *w, gpointer p)
{
    GdkWindow *window = gtk_widget_get_window(w);
    GdkCursor *c;

    c = gdk_cursor_new(GDK_HAND2);
    gdk_window_set_cursor(window, c);
    gdk_cursor_unref(c);
}

static void show_website (GtkWidget *w, gpointer p)
{
    if (browser_open(website)) {
	errbox("Failed to open URL");
    }
}

void about_dialog (void) 
{
    GtkWidget *vbox, *hbox, *label;
    GtkWidget *dialog, *image, *button;
    GtkWidget *ebox, *abox;
    gchar *buf, *sysinfo = NULL;

    dialog = gtk_dialog_new();
    gtk_window_set_title(GTK_WINDOW(dialog),_("About gretl")); 
    gtk_window_set_transient_for(GTK_WINDOW(dialog), 
				 GTK_WINDOW(mdata->main));

    vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
    abox = gtk_dialog_get_action_area(GTK_DIALOG(dialog));

    gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
    gtk_box_set_spacing(GTK_BOX(vbox), 5);
    gtk_container_set_border_width(GTK_CONTAINER(abox), 5);
    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);

    /* arrange for a little horizontal padding */
    hbox = gtk_hbox_new(FALSE, 5);
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);

    vbox = gtk_vbox_new(FALSE, 5);
    gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 5);
    
    image = open_logo();
    if (image != NULL) {
	gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 20);
	gtk_widget_show(image);
    }

#ifdef PKGBUILD
# if defined(_WIN64)
    sysinfo = g_strdup_printf("MS Windows (x86_64)");
# elif defined(G_OS_WIN32)
    sysinfo = g_strdup_printf("MS Windows (x86)");
# elif defined(MAC_NATIVE)
    sysinfo = g_strdup_printf("Mac OS X (quartz, x86_64)");
# elif defined(__ppc__)
    sysinfo = g_strdup_printf("Mac OS X (X11, ppc)");
# elif defined(OS_OSX)
    sysinfo = g_strdup_printf("Mac OS X (X11, x86)");
# endif
#elif defined(__GNUC__)
# if defined(linux) && defined(__x86_64__)
    sysinfo = g_strdup_printf("Linux x86_64");
# elif defined(__x86_64__)
    sysinfo = g_strdup_printf("Intel x86_64");
# endif
#endif

    if (sysinfo == NULL) {
	buf = g_markup_printf_escaped("<span weight=\"bold\" size=\"x-large\">"
				      "gretl %s</span>\n"
				      "%s %s\n%s", GRETL_VERSION, 
				      _("build date"), BUILD_DATE, 
				      _(bonmot));
    } else {
	buf = g_markup_printf_escaped("<span weight=\"bold\" size=\"x-large\">"
				      "gretl %s</span>\n"
				      "%s\n%s %s\n%s", GRETL_VERSION,
				      sysinfo, _("build date"), BUILD_DATE, 
				      _(bonmot));
	g_free(sysinfo);
    }

    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), buf);
    g_free(buf);
    gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);

    /* Website link */
    ebox = gtk_event_box_new();
    buf = g_markup_printf_escaped("<span color=\"blue\"><u>%s</u></span>",
				  website);
    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), buf);
    g_free(buf);
    gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
    gtk_container_add(GTK_CONTAINER(ebox), label);
    gtk_box_pack_start(GTK_BOX(vbox), ebox, FALSE, FALSE, 0);
    g_signal_connect(ebox, "button-press-event",
		     G_CALLBACK(show_website), NULL);
    g_signal_connect(ebox, "enter-notify-event",
		     G_CALLBACK(show_link_cursor), NULL);

    /* Copyright label */
    buf = g_markup_printf_escaped("<span size=\"small\">%s</span>",
				  copyright);
    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), buf);
    g_free(buf);
    gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);

    /* Translator credits */
    if (strcmp(_("translator_credits"), "translator_credits")) {
	buf = g_markup_printf_escaped("<span size=\"small\">%s</span>",
				      _("translator_credits"));
	label = gtk_label_new(NULL);
	gtk_label_set_markup(GTK_LABEL(label), buf);
	g_free(buf);
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
    }

    /* NEWS button */
    button = gtk_button_new_with_label(_("News"));
    gtk_box_pack_start(GTK_BOX(abox), button, FALSE, FALSE, 0);
    g_signal_connect(G_OBJECT(button), "clicked", 
		     G_CALLBACK(relnotes_callback), 
		     NULL);

    /* GPL button */
    button = gtk_button_new_with_label(_("License"));
    gtk_box_pack_start(GTK_BOX(abox), button, FALSE, FALSE, 0);
    g_signal_connect(G_OBJECT(button), "clicked", 
		     G_CALLBACK(license_callback), 
		     NULL);

    /* Close button */
    button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
    gtk_widget_set_can_default(button, TRUE);
    gtk_box_pack_start(GTK_BOX(abox), button, FALSE, FALSE, 0);
    g_signal_connect(G_OBJECT(button), "clicked", 
		     G_CALLBACK(delete_widget), 
		     dialog);
    gtk_widget_grab_default(button);

#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12
    gtk_window_set_titlebar((GtkWindow *) dialog, NULL);
#endif

    gtk_widget_show_all(dialog);
}