NetSurf
about.c
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf 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, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /**
20  * \file gtk/about.c
21  *
22  * Implementation of gtk about dialog.
23  */
24 
25 #include <stdlib.h>
26 #include <stdint.h>
27 
28 #include "utils/messages.h"
29 #include "utils/nsoption.h"
30 #include "utils/nsurl.h"
31 #include "netsurf/browser_window.h"
32 #include "desktop/version.h"
33 
34 #include "gtk/warn.h"
35 #include "gtk/compat.h"
36 #include "gtk/about.h"
37 
38 #define ABOUT_RESPONSE_ID_LICENCE 1
39 #define ABOUT_RESPONSE_ID_CREDITS 2
40 
41 
42 /**
43  * Open a url and a browser window/tab
44  *
45  * \param url_text The text of the url to open
46  */
47 static void about_open(const char *url_text)
48 {
49  nsurl *url;
50  nserror ret;
52 
53  if (nsoption_bool(show_single_tab) == true) {
54  flags |= BW_CREATE_TAB;
55  }
56 
57  ret = nsurl_create(url_text, &url);
58  if (ret == NSERROR_OK) {
59  ret = browser_window_create(flags, url, NULL, NULL, NULL);
60  nsurl_unref(url);
61  }
62 
63  if (ret != NSERROR_OK) {
65  }
66 }
67 
68 /**
69  * About dialog response handling.
70  *
71  * \param dialog The dialog widget
72  * \param response_id The response ID from the user clicking.
73  * \param user_data The value from the signal connection.
74  */
75 static void
77  gint response_id,
78  gpointer user_data)
79 {
80  switch (response_id) {
81 
83  about_open("about:licence");
84  break;
85 
87  about_open("about:credits");
88  break;
89  }
90 
91  /* close about dialog */
92  gtk_widget_destroy(GTK_WIDGET(dialog));
93 }
94 
96 {
97  GtkWidget *dialog, *vbox, *label;
98  gchar *name_string;
99  GList *pixbufs;
100 
101  /* Create the dialog */
102  dialog = gtk_dialog_new_with_buttons("About NetSurf",
103  parent,
104  GTK_DIALOG_DESTROY_WITH_PARENT,
105  "Licence", ABOUT_RESPONSE_ID_LICENCE,
106  "Credits", ABOUT_RESPONSE_ID_CREDITS,
107  "Close", GTK_RESPONSE_CANCEL,
108  NULL, NULL);
109 
110  vbox = nsgtk_vbox_new(FALSE, 8);
111 
112  gtk_box_pack_start(GTK_BOX(nsgtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, TRUE, TRUE, 0);
113 
114  /* NetSurf icon */
115  pixbufs = gtk_window_get_default_icon_list();
116  if (pixbufs != NULL) {
117  GtkWidget *image;
118 
119  image = nsgtk_image_new_from_pixbuf_icon(GDK_PIXBUF(g_list_nth_data(pixbufs, 0)),
120  GTK_ICON_SIZE_DIALOG);
121  g_list_free(pixbufs);
122 
123  gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
124  }
125 
126  /* version string */
127  label = gtk_label_new (NULL);
128  name_string = g_markup_printf_escaped("<span size=\"xx-large\" weight=\"bold\">NetSurf %s</span>", netsurf_version);
129  gtk_label_set_markup (GTK_LABEL (label), name_string);
130  g_free(name_string);
131  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
132  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
133  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
134 
135  label = gtk_label_new(messages_get("AboutDesc"));
136  gtk_label_set_selectable(GTK_LABEL (label), TRUE);
137  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
138  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
139  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
140 
141  label = gtk_label_new(messages_get("NetSurfCopyright"));
142  gtk_label_set_selectable(GTK_LABEL(label), TRUE);
143  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
144  gtk_box_pack_start(GTK_BOX (vbox), label, FALSE, FALSE, 0);
145 
146  /* Remove separator */
147  nsgtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE);
148 
149  /* Ensure that the dialog box response is processed. */
150  g_signal_connect_swapped(dialog,
151  "response",
152  G_CALLBACK(nsgtk_about_dialog_response),
153  dialog);
154 
155  /* Add the label, and show everything we've added to the dialog. */
156  gtk_widget_show_all(dialog);
157 }
GtkWidget * nsgtk_vbox_new(gboolean homogeneous, gint spacing)
Definition: compat.c:326
Localised message support (interface).
static void nsgtk_about_dialog_response(GtkDialog *dialog, gint response_id, gpointer user_data)
About dialog response handling.
Definition: about.c:76
wimp_w dialog
Definition: dialog.c:87
GtkWidget * nsgtk_dialog_get_content_area(GtkDialog *dialog)
Definition: compat.c:413
void nsgtk_dialog_set_has_separator(GtkDialog *dialog, gboolean setting)
Definition: compat.c:105
Option reading and saving interface.
nserror
Enumeration of error codes.
Definition: errors.h:29
New gui_window to be tab in same window as "existing" gui_window.
#define ABOUT_RESPONSE_ID_CREDITS
Definition: about.c:39
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
No error.
Definition: errors.h:30
const char *const netsurf_version
User friendly version string.
Definition: gui_menu.c:92
this will form a new history node (don&#39;t set for back/reload/etc)
wimp_w parent
Definition: dialog.c:88
Compatibility functions for older GTK versions (interface)
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
nserror nsgtk_warning(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:615
#define ABOUT_RESPONSE_ID_LICENCE
Definition: about.c:38
Version information interface.
Browser window creation and manipulation interface.
browser_window_create_flags
flags to browser_window_create
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
static void about_open(const char *url_text)
Open a url and a browser window/tab.
Definition: about.c:47
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
NetSurf URL handling (interface).
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
void nsgtk_about_dialog_init(GtkWindow *parent)
Definition: about.c:95
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:270
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
GtkWidget * nsgtk_image_new_from_pixbuf_icon(GdkPixbuf *pixbuf, GtkIconSize size)
creates a new image widget of an appropriate icon size from a pixbuf.
Definition: compat.c:502