summaryrefslogtreecommitdiff
path: root/gtk/about.c
blob: aa9a14b2bad0ce6063470bd487fcfdd1f4a28de3 (plain)
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
/*
 * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf 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; version 2 of the License.
 *
 * NetSurf 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/>.
 */

/**
 * \file gtk/about.c
 *
 * Implementation of gtk about dialog.
 */

#include <stdint.h>

#include "utils/utils.h"
#include "utils/messages.h"
#include "utils/nsoption.h"
#include "desktop/browser.h"
#include "desktop/version.h"

#include "gtk/compat.h"
#include "gtk/gui.h"
#include "gtk/about.h"

/**
 * About dialog information button click.
 *
 * \param button The button widget that was clicked
 * \param data The text of the url to open
 */
static void
nsgtk_about_dialog_info(GtkWidget *button, gpointer data)
{
	nsurl *url;
	nserror ret;
	const char *url_text = data;
	enum browser_window_create_flags flags = BW_CREATE_HISTORY;

	if (nsoption_bool(show_single_tab) == true) {
		flags |= BW_CREATE_TAB;
	}

	ret = nsurl_create(url_text, &url);
	if (ret == NSERROR_OK) {
		ret = browser_window_create(flags, url, NULL, NULL, NULL);
		nsurl_unref(url);
	}

	if (ret != NSERROR_OK) {
		warn_user(messages_get_errorcode(ret), 0);
	}

	/* close about dialog */
	gtk_widget_destroy(gtk_widget_get_toplevel(button));
}

void nsgtk_about_dialog_init(GtkWindow *parent)
{
	GtkWidget *dialog, *vbox, *button, *label;
	gchar *name_string;
	GList *pixbufs = gtk_window_get_default_icon_list();

	name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">NetSurf %s</span>", netsurf_version);


	/* Create the widgets */
	dialog = gtk_dialog_new_with_buttons("About NetSurf",
					     parent,
					     GTK_DIALOG_DESTROY_WITH_PARENT,
					     NULL,
					     NULL);

	vbox = nsgtk_vbox_new(FALSE, 8);

	gtk_box_pack_start(GTK_BOX(nsgtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, TRUE, TRUE, 0);

	if (pixbufs != NULL) {
		GtkWidget *image = gtk_image_new_from_pixbuf(GDK_PIXBUF(pixbufs->data));

		g_list_free (pixbufs);

		gtk_box_pack_start(GTK_BOX (vbox), image, FALSE, FALSE, 0);
	}


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

	label = gtk_label_new("NetSurf is a small fast web browser");
	gtk_label_set_selectable(GTK_LABEL (label), TRUE);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

	label = gtk_label_new("Copyright © 2003 - 2011 The NetSurf Developers");
	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start(GTK_BOX (vbox), label, FALSE, FALSE, 0);


	nsgtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);

	/* Add the OK button */
	gtk_dialog_add_button(GTK_DIALOG(dialog), "_Close", GTK_RESPONSE_CLOSE);
	gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);

	/* Add the credits button */
	button = gtk_button_new_with_label ("Credits");
	gtk_box_pack_end(GTK_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
			 button, FALSE, TRUE, 0);
	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:credits");

	/* Add the Licence button */
	button = gtk_button_new_with_label ("Licence");
	gtk_box_pack_end(GTK_BOX (nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
			 button, FALSE, TRUE, 0);
	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:licence");


	/* Ensure that the dialog box is destroyed when the user responds. */
	g_signal_connect_swapped(dialog,
				  "response",
				  G_CALLBACK (gtk_widget_destroy),
				  dialog);

	/* Add the label, and show everything we've added to the dialog. */
	gtk_widget_show_all(dialog);
}