Change GTK UI builder handling to use resource API

GTK UI builder resources have till now been exclusively stored on disc
requiring netsurf to ship numerous additional resource files. This
requires going to disc every time a UI action is performed which can
become a lot of unwanted file handling.

GLib/GTK has moved towards GResource handling for such resources
instead. It now seems that migrating to this style of usage is
expected and indeed the only portable way to include pixbufs.

This introduces an API to hide the various implementation details of
how resources are handled from the rest of the codebase.
This commit is contained in:
Vincent Sanders 2015-06-13 11:31:23 +01:00
parent 16fbb97dbb
commit 8ef292b9ca
24 changed files with 1000 additions and 578 deletions

View File

@ -65,6 +65,7 @@ $(eval $(call pkg_config_find_and_add,gtk+-$(NETSURF_GTK_MAJOR).0,GTK-$(NETSURF_
$(eval $(call pkg_config_find_and_add,gthread-2.0,GThread2))
$(eval $(call pkg_config_find_and_add,gmodule-2.0,GModule2))
CFLAGS += $(GTKCFLAGS)
LDFLAGS += -lm
@ -76,9 +77,40 @@ ifeq ($(HOST),Windows_NT)
CFLAGS += -U__STRICT_ANSI__
endif
# ----------------------------------------------------------------------------
# Builtin resource handling
# ----------------------------------------------------------------------------
# builtin resource sources
S_RESOURCE :=
# Glib prior to 2.32 does not have GResource handling.
#
# This uses pkg-config to check for the minimum required version for
# this feature. Note we check for gmodule-2.0 which is a specific
# part of glib we require.
# It would be nice if we could check for this functionality rather
# than "knowing" the version but there does not appear to be a simple
# way to implement that.
NETSURF_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes)
ifeq ($(NETSURF_GRESOURCE_AVAILABLE),yes)
GLIB_COMPILE_RESOURCES := glib-compile-resources
CFLAGS += -DWITH_GRESOURCE
S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
NSGTK_RESOURCES_DIR := gtk/res
GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
# generate the gresource source file
$(OBJROOT)/netsurf_gresource.c: $(GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(GRESOURCE_XML))
$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
endif
# ----------------------------------------------------------------------------
# Pixbuf
# Builtin Pixbuf resources
# ----------------------------------------------------------------------------
GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
@ -88,7 +120,8 @@ GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
# 3: bitmap name
define convert_image
S_PIXBUF += $(2)
# add converted pixbuf to builtin resource sources
S_RESOURCE += $(2)
$(2): $(1)
$(Q)echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $(2)
@ -101,8 +134,6 @@ endef
# Source file setup
# ----------------------------------------------------------------------------
#converted pixbuf sources
S_PIXBUF :=
$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
@ -120,7 +151,7 @@ S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c)
# This is the final source build list
# Note this is deliberately *not* expanded here as common and image
# are not yet available
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PIXBUF) $(S_GTK)
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RESOURCE) $(S_GTK)
# The gtk binary target
EXETARGET := nsgtk

View File

@ -601,3 +601,40 @@ void nsgtk_widget_set_margins(GtkWidget *widget, gint hmargin, gint vmargin)
gtk_misc_set_padding(GTK_MISC(widget), hmargin, vmargin);
#endif
}
/* exported interface documented in gtk/compat.h */
guint
nsgtk_builder_add_from_resource(GtkBuilder *builder,
const gchar *resource_path,
GError **error)
{
guint ret;
#ifdef WITH_GRESOURCE
#if GTK_CHECK_VERSION(3,4,0)
ret = gtk_builder_add_from_resource(builder, resource_path, error);
#else
GBytes *data;
const gchar *buffer;
gsize buffer_length;
g_assert(error && *error == NULL);
data = g_resources_lookup_data(resource_path, 0, error);
if (data == NULL) {
return 0;
}
buffer_length = 0;
buffer = g_bytes_get_data(data, &buffer_length);
g_assert(buffer != NULL);
ret = gtk_builder_add_from_string(builder, buffer, buffer_length, error);
g_bytes_unref(data);
#endif
#else
ret = 0; /* return an error as GResource not supported before GLIB 2.32 */
#endif
return ret;
}

View File

@ -268,4 +268,29 @@ GtkWidget *nsgtk_image_menu_item_new_with_mnemonic(const gchar *label);
*/
void nsgtk_image_menu_item_set_image(GtkWidget *image_menu_item, GtkWidget *image);
/**
* Parses a resource file containing a GtkBuilder UI definition and
* merges it with the current contents of builder.
*
* Compatability interface as this did not exist prior to GTK 3.4
*
* GTK prior to 3.4 can have the resources in a GResource but
* gtk_builder cannot directly instantiate from them
*
* GTK 3.4 onwards can use gtk_builder_add_from_resource() to add
* directly from resources. The gtk_builder_new_ type operations
* cannot be used because they are only available post 3.10 and handle
* all errors by aborting the application
*
* @note prior to GLIB 2.32 resources did not exist and this wrapper
* returns the error code.
*
* \param builder a GtkBuilder
* \param resource_path the path of the resource file to parse
* \param error return location for an error, or NULL.
* \return A positive value on success, 0 if an error occurred.
*/
guint nsgtk_builder_add_from_resource(GtkBuilder *builder, const gchar *resource_path, GError **error);
#endif /* NETSURF_GTK_COMPAT_H */

View File

@ -32,12 +32,11 @@
#include "gtk/plotters.h"
#include "gtk/scaffolding.h"
#include "gtk/treeview.h"
#define GLADE_NAME "cookies.glade"
#include "gtk/resources.h"
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
GtkMenuItem *widget, gpointer g)
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUHANDLER(x) gboolean nsgtk_on_##x##_activate(GtkMenuItem *widget, \
gpointer g)
@ -46,8 +45,6 @@ struct menu_events {
GCallback handler;
};
static void nsgtk_cookies_init_menu(void);
/* edit menu */
MENUPROTO(delete_selected);
MENUPROTO(delete_all);
@ -64,98 +61,97 @@ MENUPROTO(collapse_cookies);
static struct menu_events menu_events[] = {
/* edit menu */
MENUEVENT(delete_selected),
MENUEVENT(delete_all),
MENUEVENT(select_all),
MENUEVENT(clear_selection),
/* view menu*/
MENUEVENT(expand_all),
MENUEVENT(expand_domains),
MENUEVENT(expand_cookies),
MENUEVENT(expand_cookies),
MENUEVENT(collapse_all),
MENUEVENT(collapse_domains),
MENUEVENT(collapse_cookies),
{NULL, NULL}
};
static struct nsgtk_treeview *cookies_window;
static GtkBuilder *gladeFile;
static struct nsgtk_treeview *cookies_treeview;
static GtkBuilder *cookie_builder;
GtkWindow *wndCookies;
/**
* Creates the window for the cookies tree.
*/
bool nsgtk_cookies_init(const char *glade_file_location)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
GError* error = NULL;
gladeFile = gtk_builder_new ();
if (!gtk_builder_add_from_file(gladeFile, glade_file_location, &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
return false;
}
gtk_builder_connect_signals(gladeFile, NULL);
wndCookies = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndCookies"));
window = wndCookies;
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(gladeFile,
"cookiesScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(gladeFile,
"cookiesDrawingArea"));
cookies_window = nsgtk_treeview_create(TREE_COOKIES, window,
scrolled, drawing_area);
if (cookies_window == NULL)
return false;
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, cookies_window);
nsgtk_cookies_init_menu();
return true;
}
/**
* Connects menu events in the cookies window.
*/
void nsgtk_cookies_init_menu()
static void nsgtk_cookies_init_menu(void)
{
struct menu_events *event = menu_events;
GtkWidget *w;
while (event->widget != NULL) {
w = GTK_WIDGET(gtk_builder_get_object(gladeFile, event->widget));
w = GTK_WIDGET(gtk_builder_get_object(cookie_builder, event->widget));
if (w == NULL) {
LOG("Unable to connect menu widget ""%s""", event->widget); } else {
g_signal_connect(G_OBJECT(w), "activate", event->handler, cookies_window);
g_signal_connect(G_OBJECT(w), "activate", event->handler, cookies_treeview);
}
event++;
}
}
/* exported interface documented in gtk/cookies.h */
nserror nsgtk_cookies_init(void)
{
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
nserror res;
res = nsgtk_builder_new_from_resname("cookies", &cookie_builder);
if (res != NSERROR_OK) {
LOG("Cookie UI builder init failed");
return res;
}
gtk_builder_connect_signals(cookie_builder, NULL);
wndCookies = GTK_WINDOW(gtk_builder_get_object(cookie_builder,
"wndCookies"));
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(cookie_builder,
"cookiesScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(cookie_builder,
"cookiesDrawingArea"));
cookies_treeview = nsgtk_treeview_create(TREE_COOKIES,
wndCookies,
scrolled,
drawing_area);
if (cookies_treeview == NULL) {
return NSERROR_INIT_FAILED;
}
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(wndCookies, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(wndCookies, "hide", nsgtk_tree_window_hide, cookies_treeview);
nsgtk_cookies_init_menu();
return NSERROR_OK;
}
/**
* Destroys the cookies window and performs any other necessary cleanup actions.
*/
void nsgtk_cookies_destroy(void)
{
/* TODO: what about gladeFile? */
nsgtk_treeview_destroy(cookies_window);
/** \todo what about cookie_builder? */
nsgtk_treeview_destroy(cookies_treeview);
}

View File

@ -23,11 +23,14 @@
#ifndef __NSGTK_COOKIES_H__
#define __NSGTK_COOKIES_H__
#include <gtk/gtk.h>
extern GtkWindow *wndCookies;
bool nsgtk_cookies_init(const char *glade_file_location);
/**
* Creates the window for the cookies tree.
*
* \return NSERROR_OK on success else appropriate error code on faliure.
*/
nserror nsgtk_cookies_init(void);
void nsgtk_cookies_destroy(void);

View File

@ -32,9 +32,10 @@
#include "desktop/gui_download.h"
#include "gtk/scaffolding.h"
#include "gtk/download.h"
#include "gtk/window.h"
#include "gtk/compat.h"
#include "gtk/resources.h"
#include "gtk/download.h"
#define UPDATE_RATE 500 /* In milliseconds */
@ -458,24 +459,26 @@ static void nsgtk_download_store_cancel_item (struct gui_download_window *dl)
}
}
static gboolean nsgtk_download_hide (GtkWidget *window)
static gboolean nsgtk_download_hide(GtkWidget *window)
{
gtk_widget_hide(window);
return TRUE;
}
bool nsgtk_download_init(const char *glade_file_location)
/* exported interface documented in gtk/download.h */
nserror nsgtk_download_init(void)
{
GError* error = NULL;
GtkBuilder* builder = gtk_builder_new();
GtkBuilder* builder;
nserror res;
if (!gtk_builder_add_from_file(builder, glade_file_location, &error))
{
g_warning("Couldn't load builder file: %s", error->message);
g_error_free(error);
return false;
res = nsgtk_builder_new_from_resname("downloads", &builder);
if (res != NSERROR_OK) {
LOG("Download UI builder init failed");
return res;
}
gtk_builder_connect_signals(builder, NULL);
nsgtk_download_button_pause = GTK_BUTTON(gtk_builder_get_object(builder, "buttonPause"));
nsgtk_download_button_clear = GTK_BUTTON(gtk_builder_get_object(builder, "buttonClear"));
nsgtk_download_button_cancel = GTK_BUTTON(gtk_builder_get_object(builder, "buttonCancel"));
@ -538,7 +541,7 @@ bool nsgtk_download_init(const char *glade_file_location)
g_signal_connect(G_OBJECT(nsgtk_download_window), "delete-event",
G_CALLBACK(nsgtk_download_hide), NULL);
return true;
return NSERROR_OK;
}
void nsgtk_download_destroy ()

View File

@ -21,9 +21,18 @@
#include <gtk/gtk.h>
/**
* download operation table for gtk
*/
struct gui_download_table *nsgtk_download_table;
bool nsgtk_download_init(const char *glade_file_location);
/**
* Initialise download window ready for use.
*
* \return NSERROR_OK on success else appropriate error code on faliure.
*/
nserror nsgtk_download_init(void);
void nsgtk_download_destroy (void);
bool nsgtk_check_for_downloads(GtkWindow *parent);
void nsgtk_download_show(GtkWindow *parent);

202
gtk/gui.c
View File

@ -67,6 +67,8 @@
#include "gtk/search.h"
#include "gtk/ssl_cert.h"
#include "gtk/bitmap.h"
#include "gtk/resources.h"
#include "gtk/login.h"
bool nsgtk_complete = false;
@ -79,10 +81,7 @@ char *nsgtk_config_home; /* exported global defined in gtk/gui.h */
GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
struct glade_file_location_s *glade_file_location;
static GtkWindow *nsgtk_warning_window;
GtkWidget *widWarning;
GtkBuilder *warning_builder;
#define THROBBER_FRAMES 9
@ -155,87 +154,6 @@ static bool nsgtk_throbber_init(char **respath, int framec)
}
#define NEW_GLADE_ERROR_SIZE 128
static char *
nsgtk_new_ui(char **respath, const char *name, GtkBuilder **pglade)
{
GtkBuilder *builder;
GError* error = NULL;
char *filepath;
char errorstr[NEW_GLADE_ERROR_SIZE];
char resname[PATH_MAX];
#if GTK_CHECK_VERSION(3,0,0)
int gtkv = 3;
#else
int gtkv = 2;
#endif
snprintf(resname, PATH_MAX, "%s.gtk%d.ui", name, gtkv);
filepath = filepath_find(respath, resname);
if (filepath == NULL) {
snprintf(errorstr, NEW_GLADE_ERROR_SIZE,
"Unable to locate %s glade template file.\n", name);
die(errorstr);
}
builder = gtk_builder_new();
if (!gtk_builder_add_from_file(builder, filepath, &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
snprintf(errorstr, NEW_GLADE_ERROR_SIZE,
"Unable to load glade %s window definitions.\n", name);
die(errorstr);
}
gtk_builder_connect_signals(builder, NULL);
LOG("Using '%s' as %s ui template file", filepath, name);
if (pglade != NULL) {
*pglade = builder;
} else {
/* release our reference to the builder if it is not
* being used.
*/
g_object_unref(G_OBJECT(builder));
}
return filepath;
}
/**
* Load definitions from glade files.
*/
static void
nsgtk_init_glade(char **respath)
{
GtkBuilder *gladeWarning;
glade_file_location = calloc(1, sizeof(struct glade_file_location_s));
if (glade_file_location == NULL) {
die("Unable to allocate glade file locations");
}
glade_file_location->netsurf = nsgtk_new_ui(respath, "netsurf", NULL);
glade_file_location->tabcontents = nsgtk_new_ui(respath, "tabcontents", NULL);
glade_file_location->password = nsgtk_new_ui(respath, "password", NULL);
glade_file_location->login = nsgtk_new_ui(respath, "login", NULL);
glade_file_location->ssl = nsgtk_new_ui(respath, "ssl", NULL);
glade_file_location->toolbar = nsgtk_new_ui(respath, "toolbar", NULL);
glade_file_location->downloads = nsgtk_new_ui(respath, "downloads", NULL);
glade_file_location->history = nsgtk_new_ui(respath, "history", NULL);
glade_file_location->options = nsgtk_new_ui(respath, "options", NULL);
glade_file_location->hotlist = nsgtk_new_ui(respath, "hotlist", NULL);
glade_file_location->cookies = nsgtk_new_ui(respath, "cookies", NULL);
glade_file_location->viewdata = nsgtk_new_ui(respath, "viewdata", NULL);
glade_file_location->warning = nsgtk_new_ui(respath, "warning", &gladeWarning);
nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(gladeWarning, "wndWarning"));
widWarning = GTK_WIDGET(gtk_builder_get_object(gladeWarning, "labelWarning"));
}
/**
* Set option defaults for gtk frontend.
@ -347,8 +265,20 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
strlen(languages_file_location) - 9);
LOG("Using '%s' for resource path", res_dir_location);
/* initialise the glade templates */
nsgtk_init_glade(respath);
/* initialise the gtk resource handling */
error = nsgtk_init_resources(respath);
if (error != NSERROR_OK) {
LOG("Unable to initialise resources");
return error;
}
error = nsgtk_builder_new_from_resname("warning", &warning_builder);
if (error != NSERROR_OK) {
LOG("Unable to initialise warning dialog");
return error;
}
gtk_builder_connect_signals(warning_builder, NULL);
/* set default icon if its available */
resource_filename = filepath_find(respath, "netsurf.xpm");
@ -366,14 +296,9 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
}
/* Default favicon */
resource_filename = filepath_find(respath, "favicon.png");
if (resource_filename != NULL) {
favicon_pixbuf = gdk_pixbuf_new_from_file(resource_filename, NULL);
free(resource_filename);
if (favicon_pixbuf == NULL) {
favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16);
}
error = nsgdk_pixbuf_new_from_resname("favicon.png", &favicon_pixbuf);
if (error != NSERROR_OK) {
favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16);
}
/* Toolbar inicies file */
@ -402,17 +327,30 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
browser_set_dpi(gdk_screen_get_resolution(gdk_screen_get_default()));
LOG("Set CSS DPI to %d", browser_get_dpi());
if (nsgtk_history_init(glade_file_location->history) == false)
die("Unable to initialise history window.\n");
/* Initialise top level UI elements */
error = nsgtk_history_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise global history window.");
return error;
}
if (nsgtk_download_init(glade_file_location->downloads) == false)
die("Unable to initialise download window.\n");
error = nsgtk_download_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise download window.");
return error;
}
if (nsgtk_cookies_init(glade_file_location->cookies) == false)
die("Unable to initialise cookies window.\n");
error = nsgtk_cookies_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise cookies window.");
return error;
}
if (nsgtk_hotlist_init(glade_file_location->hotlist) == false)
die("Unable to initialise hotlist window.\n");
error = nsgtk_hotlist_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise hotlist window.");
return error;
}
/* If there is a url specified on the command line use it */
if (argc > 1) {
@ -566,15 +504,21 @@ static nserror gui_launch_url(struct nsurl *url)
void warn_user(const char *warning, const char *detail)
{
char buf[300]; /* 300 is the size the RISC OS GUI uses */
static GtkWindow *nsgtk_warning_window;
GtkLabel *WarningLabel;
LOG("%s %s", warning, detail ? detail : "");
fflush(stdout);
nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(warning_builder, "wndWarning"));
WarningLabel = GTK_LABEL(gtk_builder_get_object(warning_builder,
"labelWarning"));
snprintf(buf, sizeof(buf), "%s %s", messages_get(warning),
detail ? detail : "");
buf[sizeof(buf) - 1] = 0;
gtk_label_set_text(GTK_LABEL(widWarning), buf);
gtk_label_set_text(WarningLabel, buf);
gtk_widget_show_all(GTK_WIDGET(nsgtk_warning_window));
}
@ -585,34 +529,34 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
char **owner_pass = ((void **)data)[0];
char **user_pass = ((void **)data)[1];
GtkWindow *wnd = ((void **)data)[2];
GtkBuilder *gladeFile = ((void **)data)[3];
GtkBuilder *password_builder = ((void **)data)[3];
char *path = ((void **)data)[4];
char *op, *op1;
char *up, *up1;
op = strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_builder_get_object(gladeFile,
GTK_ENTRY(gtk_builder_get_object(password_builder,
"entryPDFOwnerPassword"))));
op1 = strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_builder_get_object(gladeFile,
GTK_ENTRY(gtk_builder_get_object(password_builder,
"entryPDFOwnerPassword1"))));
up = strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_builder_get_object(gladeFile,
GTK_ENTRY(gtk_builder_get_object(password_builder,
"entryPDFUserPassword"))));
up1 = strdup(gtk_entry_get_text(
GTK_ENTRY(gtk_builder_get_object(gladeFile,
GTK_ENTRY(gtk_builder_get_object(password_builder,
"entryPDFUserPassword1"))));
if (op[0] == '\0') {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile,
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
"Owner password must be at least 1 character long:");
free(op);
free(up);
} else if (!strcmp(op, up)) {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile,
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
"User and owner passwords must be different:");
free(op);
@ -627,13 +571,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
free(data);
gtk_widget_destroy(GTK_WIDGET(wnd));
g_object_unref(G_OBJECT(gladeFile));
g_object_unref(G_OBJECT(password_builder));
save_pdf(path);
free(path);
} else {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile,
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")), "Passwords not confirmed:");
free(op);
free(up);
@ -646,13 +590,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data)
{
GtkWindow *wnd = ((void **)data)[2];
GtkBuilder *gladeFile = ((void **)data)[3];
GtkBuilder *password_builder = ((void **)data)[3];
char *path = ((void **)data)[4];
free(data);
gtk_widget_destroy(GTK_WIDGET(wnd));
g_object_unref(G_OBJECT(gladeFile));
g_object_unref(G_OBJECT(password_builder));
save_pdf(path);
@ -664,19 +608,19 @@ static void nsgtk_pdf_password(char **owner_pass, char **user_pass, char *path)
GtkButton *ok, *no;
GtkWindow *wnd;
void **data;
GtkBuilder *gladeFile;
GError* error = NULL;
GtkBuilder *password_builder;
nserror res;
gladeFile = gtk_builder_new();
if (!gtk_builder_add_from_file(gladeFile,
glade_file_location->password,
&error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
res = nsgtk_builder_new_from_resname("password", &password_builder);
if (res != NSERROR_OK) {
LOG("Password UI builder init failed");
return;
}
wnd = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndPDFPassword"));
gtk_builder_connect_signals(password_builder, NULL);
wnd = GTK_WINDOW(gtk_builder_get_object(password_builder,
"wndPDFPassword"));
data = malloc(5 * sizeof(void *));
@ -686,11 +630,13 @@ static void nsgtk_pdf_password(char **owner_pass, char **user_pass, char *path)
data[0] = owner_pass;
data[1] = user_pass;
data[2] = wnd;
data[3] = gladeFile;
data[3] = password_builder;
data[4] = path;
ok = GTK_BUTTON(gtk_builder_get_object(gladeFile, "buttonPDFSetPassword"));
no = GTK_BUTTON(gtk_builder_get_object(gladeFile, "buttonPDFNoPassword"));
ok = GTK_BUTTON(gtk_builder_get_object(password_builder,
"buttonPDFSetPassword"));
no = GTK_BUTTON(gtk_builder_get_object(password_builder,
"buttonPDFNoPassword"));
g_signal_connect(G_OBJECT(ok), "clicked",
G_CALLBACK(nsgtk_PDF_set_pass), (gpointer)data);
@ -1177,7 +1123,7 @@ int main(int argc, char** argv)
/* run the browser */
ret = nsgtk_init(argc, argv, respaths);
if (ret != NSERROR_OK) {
fprintf(stderr, "NetSurf gtk specific initialise failed (%s)\n",
fprintf(stderr, "NetSurf gtk initialise failed (%s)\n",
messages_get_errorcode(ret));
} else {
nsgtk_main();

View File

@ -21,26 +21,6 @@
struct nsurl;
/** glade file paths. */
struct glade_file_location_s {
char *netsurf;
char *tabcontents;
char *password;
char *warning;
char *login;
char *ssl;
char *toolbar;
char *options;
char *downloads;
char *history;
char *hotlist;
char *cookies;
char *viewdata;
};
/** location of all glade files. */
extern struct glade_file_location_s *glade_file_location;
/** language list file path. */
extern char *languages_file_location;
@ -65,9 +45,6 @@ extern char **respaths;
/** input conversion. */
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *eventkey);
/** login window request. */
extern void gui_401login_open(struct nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw);
/** set when no windows remain open. */
extern bool nsgtk_complete;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@ -26,15 +26,16 @@
#include "desktop/tree.h"
#include "desktop/textinput.h"
#include "gtk/history.h"
#include "gtk/plotters.h"
#include "gtk/scaffolding.h"
#include "gtk/treeview.h"
#include "gtk/compat.h"
#include "gtk/resources.h"
#include "gtk/history.h"
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
GtkMenuItem *widget, gpointer g)
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUHANDLER(x) gboolean nsgtk_on_##x##_activate(GtkMenuItem *widget, \
gpointer g)
@ -43,8 +44,6 @@ struct menu_events {
GCallback handler;
};
static void nsgtk_history_init_menu(void);
/* file menu*/
MENUPROTO(export);
@ -57,7 +56,7 @@ MENUPROTO(clear_selection);
/* view menu*/
MENUPROTO(expand_all);
MENUPROTO(expand_directories);
MENUPROTO(expand_addresses);
MENUPROTO(expand_addresses);
MENUPROTO(collapse_all);
MENUPROTO(collapse_directories);
MENUPROTO(collapse_addresses);
@ -65,95 +64,103 @@ MENUPROTO(collapse_addresses);
MENUPROTO(launch);
static struct menu_events menu_events[] = {
/* file menu*/
MENUEVENT(export),
/* edit menu */
MENUEVENT(delete_selected),
MENUEVENT(delete_all),
MENUEVENT(select_all),
MENUEVENT(clear_selection),
/* view menu*/
MENUEVENT(expand_all),
MENUEVENT(expand_directories),
MENUEVENT(expand_addresses),
MENUEVENT(expand_addresses),
MENUEVENT(collapse_all),
MENUEVENT(collapse_directories),
MENUEVENT(collapse_addresses),
MENUEVENT(launch),
{NULL, NULL}
};
static struct nsgtk_treeview *global_history_window;
static GtkBuilder *gladeFile;
static GtkBuilder *history_builder;
GtkWindow *wndHistory;
/* exported interface, documented in gtk_history.h */
bool nsgtk_history_init(const char *glade_file_location)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
GError* error = NULL;
gladeFile = gtk_builder_new();
if (!gtk_builder_add_from_file(gladeFile, glade_file_location, &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
return false;
}
gtk_builder_connect_signals(gladeFile, NULL);
wndHistory = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndHistory"));
window = wndHistory;
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(gladeFile, "globalHistoryScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(gladeFile, "globalHistoryDrawingArea"));
global_history_window = nsgtk_treeview_create(
TREE_HISTORY, window, scrolled, drawing_area);
if (global_history_window == NULL)
return false;
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, global_history_window);
nsgtk_history_init_menu();
return true;
}
/**
* Connects menu events in the global history window.
*/
void nsgtk_history_init_menu(void)
static void nsgtk_history_init_menu(void)
{
struct menu_events *event = menu_events;
GtkWidget *w;
while (event->widget != NULL) {
w = GTK_WIDGET(gtk_builder_get_object(gladeFile, event->widget));
w = GTK_WIDGET(gtk_builder_get_object(history_builder,
event->widget));
if (w == NULL) {
LOG("Unable to connect menu widget ""%s""", event->widget);
LOG("Unable to connect menu widget ""%s""",
event->widget);
} else {
g_signal_connect(G_OBJECT(w), "activate", event->handler, global_history_window);
g_signal_connect(G_OBJECT(w),
"activate",
event->handler,
global_history_window);
}
event++;
}
}
/* exported interface, documented in gtk/history.h */
nserror nsgtk_history_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
nserror res;
res = nsgtk_builder_new_from_resname("history", &history_builder);
if (res != NSERROR_OK) {
LOG("History UI builder init failed");
return res;
}
gtk_builder_connect_signals(history_builder, NULL);
wndHistory = GTK_WINDOW(gtk_builder_get_object(history_builder,
"wndHistory"));
window = wndHistory;
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(history_builder,
"globalHistoryScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(history_builder,
"globalHistoryDrawingArea"));
global_history_window = nsgtk_treeview_create(TREE_HISTORY,
window,
scrolled,
drawing_area);
if (global_history_window == NULL) {
return NSERROR_INIT_FAILED;
}
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, global_history_window);
nsgtk_history_init_menu();
return NSERROR_OK;
}
/**
* Destroys the global history window and performs any other necessary cleanup
@ -161,12 +168,12 @@ void nsgtk_history_init_menu(void)
*/
void nsgtk_history_destroy(void)
{
/* TODO: what about gladeFile? */
/** \todo what about history_builder? */
nsgtk_treeview_destroy(global_history_window);
}
/* file menu*/
/* file menu */
MENUHANDLER(export)
{
GtkWidget *save_dialog;
@ -176,21 +183,21 @@ MENUHANDLER(export)
NSGTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NSGTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(save_dialog),
getenv("HOME") ? getenv("HOME") : "/");
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_dialog),
"history.html");
if (gtk_dialog_run(GTK_DIALOG(save_dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *filename = gtk_file_chooser_get_filename(
GTK_FILE_CHOOSER(save_dialog));
global_history_export(filename, NULL);
global_history_export(filename, NULL);
g_free(filename);
}
gtk_widget_destroy(save_dialog);
return TRUE;

View File

@ -27,10 +27,9 @@ extern GtkWindow *wndHistory;
/**
* Creates the window for the global history tree.
*
* \param glade_file_location The glade file to use for the window.
* \return true on success false on faliure.
* \return NSERROR_OK on sucess else appropriate error code.
*/
bool nsgtk_history_init(const char *glade_file_location);
nserror nsgtk_history_init(void);
/**
* Free global resources associated with the gtk history window.

View File

@ -25,13 +25,12 @@
#include "desktop/plotters.h"
#include "desktop/tree.h"
#include "gtk/hotlist.h"
#include "gtk/plotters.h"
#include "gtk/scaffolding.h"
#include "gtk/treeview.h"
#include "gtk/compat.h"
#define GLADE_NAME "hotlist.glade"
#include "gtk/resources.h"
#include "gtk/hotlist.h"
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
GtkMenuItem *widget, gpointer g)
@ -44,7 +43,6 @@ struct menu_events {
GCallback handler;
};
static void nsgtk_hotlist_init_menu(void);
/* file menu*/
MENUPROTO(export);
@ -92,83 +90,83 @@ static struct menu_events menu_events[] = {
{NULL, NULL}
};
static struct nsgtk_treeview *hotlist_window;
static GtkBuilder *gladeFile;
static struct nsgtk_treeview *hotlist_treeview;
static GtkBuilder *hotlist_builder;
GtkWindow *wndHotlist;
/* exported interface docuemnted in gtk_hotlist.h */
bool nsgtk_hotlist_init(const char *glade_file_location)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
GError* error = NULL;
gladeFile = gtk_builder_new();
if (!gtk_builder_add_from_file(gladeFile, glade_file_location, &error)) {
g_warning("Couldn't load builder file: %s", error->message);
g_error_free(error);
return false;
}
gtk_builder_connect_signals(gladeFile, NULL);
wndHotlist = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndHotlist"));
window = wndHotlist;
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(gladeFile,
"hotlistScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(gladeFile,
"hotlistDrawingArea"));
tree_hotlist_path = nsoption_charp(hotlist_path);
hotlist_window = nsgtk_treeview_create(TREE_HOTLIST, window,
scrolled, drawing_area);
if (hotlist_window == NULL)
return false;
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, hotlist_window);
nsgtk_hotlist_init_menu();
return true;
}
/**
* Connects menu events in the hotlist window.
*/
void nsgtk_hotlist_init_menu(void)
static void nsgtk_hotlist_init_menu(void)
{
struct menu_events *event = menu_events;
GtkWidget *w;
while (event->widget != NULL) {
w = GTK_WIDGET(gtk_builder_get_object(gladeFile, event->widget));
w = GTK_WIDGET(gtk_builder_get_object(hotlist_builder, event->widget));
if (w == NULL) {
LOG("Unable to connect menu widget ""%s""", event->widget); } else {
g_signal_connect(G_OBJECT(w), "activate", event->handler, hotlist_window);
g_signal_connect(G_OBJECT(w), "activate", event->handler, hotlist_treeview);
}
event++;
}
}
/* exported interface docuemnted in gtk/hotlist.h */
nserror nsgtk_hotlist_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
nserror res;
res = nsgtk_builder_new_from_resname("hotlist", &hotlist_builder);
if (res != NSERROR_OK) {
LOG("Cookie UI builder init failed");
return res;
}
gtk_builder_connect_signals(hotlist_builder, NULL);
wndHotlist = GTK_WINDOW(gtk_builder_get_object(hotlist_builder, "wndHotlist"));
window = wndHotlist;
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(hotlist_builder,
"hotlistScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(hotlist_builder,
"hotlistDrawingArea"));
tree_hotlist_path = nsoption_charp(hotlist_path);
hotlist_treeview = nsgtk_treeview_create(TREE_HOTLIST, window,
scrolled, drawing_area);
if (hotlist_treeview == NULL) {
return NSERROR_INIT_FAILED;
}
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
CONNECT(window, "hide", nsgtk_tree_window_hide, hotlist_treeview);
nsgtk_hotlist_init_menu();
return NSERROR_OK;
}
/**
* Destroys the hotlist window and performs any other necessary cleanup actions.
*/
void nsgtk_hotlist_destroy(void)
{
/* TODO: what about gladeFile? */
nsgtk_treeview_destroy(hotlist_window);
/** \todo what about hotlist_builder? */
nsgtk_treeview_destroy(hotlist_treeview);
}

View File

@ -30,9 +30,11 @@ extern GtkWindow *wndHotlist;
/**
* Initialise the gtk specific hotlist (bookmarks) display.
*
* \param glade_hotlist_file_location the path to the glade file for the hotlist
* \return NSERROR_OK on success else appropriate error code on faliure.
*/
bool nsgtk_hotlist_init(const char *glade_hotlist_file_location);
nserror nsgtk_hotlist_init(void);
void nsgtk_hotlist_destroy(void);
#endif /* __NSGTK_HOTLIST_H__ */

View File

@ -30,7 +30,8 @@
#include "utils/utils.h"
#include "desktop/browser.h"
#include "gtk/gui.h"
#include "gtk/resources.h"
#include "gtk/login.h"
struct session_401 {
nsurl *url; /**< URL being fetched */
@ -65,28 +66,28 @@ void gui_401login_open(nsurl *url, const char *realm,
lwc_string_unref(host);
}
/* create a new instance of the login window, and get handles to all
* the widgets we're interested in.
*/
void create_login_window(nsurl *url, lwc_string *host, const char *realm,
nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
struct session_401 *session;
/* create a new instance of the login window, and get handles to all
* the widgets we're interested in.
*/
GtkWindow *wnd;
GtkLabel *lhost, *lrealm;
GtkEntry *euser, *epass;
GtkButton *bok, *bcan;
GError* error = NULL;
GtkBuilder* builder;
nserror res;
builder = gtk_builder_new ();
if (!gtk_builder_add_from_file(builder, glade_file_location->login, &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
res = nsgtk_builder_new_from_resname("login", &builder);
if (res != NSERROR_OK) {
LOG("Login UI builder init failed");
return;
}
gtk_builder_connect_signals(builder, NULL);
wnd = GTK_WINDOW(gtk_builder_get_object(builder, "wndLogin"));
lhost = GTK_LABEL(gtk_builder_get_object(builder, "labelLoginHost"));
lrealm = GTK_LABEL(gtk_builder_get_object(builder, "labelLoginRealm"));

31
gtk/login.h Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright 2015 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
* Login interfaces.
*/
#ifndef __NSGTK_LOGIN_H__
#define __NSGTK_LOGIN_H__
/**
* login window request.
*/
extern void gui_401login_open(struct nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw);
#endif

View File

@ -34,6 +34,7 @@
#include "gtk/gui.h"
#include "gtk/scaffolding.h"
#include "gtk/theme.h"
#include "gtk/resources.h"
#include "gtk/preferences.h"
/* private prefs */
@ -1039,9 +1040,9 @@ nsgtk_preferences_dialogPreferences_destroy(GtkDialog *dlg, struct ppref *priv)
/* exported interface documented in gtk/preferences.h */
GtkWidget* nsgtk_preferences(struct browser_window *bw, GtkWindow *parent)
{
GError *error = NULL;
GtkBuilder *preferences_builder;
struct ppref *priv = &ppref;
nserror res;
priv->bw = bw; /* for setting "current" page */
@ -1051,17 +1052,12 @@ GtkWidget* nsgtk_preferences(struct browser_window *bw, GtkWindow *parent)
return GTK_WIDGET(priv->dialog);
}
/* populate builder object */
preferences_builder = gtk_builder_new();
if (!gtk_builder_add_from_file(preferences_builder,
glade_file_location->options,
&error)) {
g_warning("Couldn't load builder file: %s", error->message);
g_error_free(error);
res = nsgtk_builder_new_from_resname("options", &preferences_builder);
if (res != NSERROR_OK) {
LOG("Preferences UI builder init failed");
return NULL;
}
priv->dialog = gtk_builder_get_object(preferences_builder,
"dialogPreferences");
if (priv->dialog == NULL) {

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/netsurf">
<file>cookies.gtk2.ui</file>
<file>history.gtk3.ui</file>
<file>netsurf.gtk2.ui</file>
<file>password.gtk3.ui</file>
<file>toolbar.gtk2.ui</file>
<file>warning.gtk3.ui</file>
<file>cookies.gtk3.ui</file>
<file>hotlist.gtk2.ui</file>
<file>netsurf.gtk3.ui</file>
<file>ssl.gtk2.ui</file>
<file>toolbar.gtk3.ui</file>
<file>downloads.gtk2.ui</file>
<file>hotlist.gtk3.ui</file>
<file>options.gtk2.ui</file>
<file>ssl.gtk3.ui</file>
<file>viewdata.gtk2.ui</file>
<file>downloads.gtk3.ui</file>
<file>login.gtk2.ui</file>
<file>options.gtk3.ui</file>
<file>tabcontents.gtk2.ui</file>
<file>viewdata.gtk3.ui</file>
<file>history.gtk2.ui</file>
<file>login.gtk3.ui</file>
<file>password.gtk2.ui</file>
<file>tabcontents.gtk3.ui</file>
<file>warning.gtk2.ui</file>
<file>favicon.png</file>
</gresource>
</gresources>

View File

@ -20,11 +20,20 @@
* \file
* Implementation of gtk builtin resource handling.
*
* \todo resource handling in gtk3 has switched to using GResource
* This presents a unified interface to the rest of the codebase to
* obtain resources. Note this is not anything to do with the resource
* scheme handling beyond possibly providing the underlying data.
*
*/
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/filepath.h"
#include "gtk/compat.h"
#include "gtk/resources.h"
#ifdef __GNUC__
@ -33,6 +42,41 @@ extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
extern const guint8 menu_cursor_pixdata[];
#endif
enum nsgtk_resource_type_e {
NSGTK_RESOURCE_FILE,
NSGTK_RESOURCE_BUILTIN,
};
struct nsgtk_resource_s {
const char *name;
unsigned int len;
enum nsgtk_resource_type_e type;
char *path;
};
static struct nsgtk_resource_s ui_resource[] = {
{ "netsurf", 7, NSGTK_RESOURCE_FILE, NULL },
{ "tabcontents", 10, NSGTK_RESOURCE_FILE, NULL },
{ "password", 8, NSGTK_RESOURCE_FILE, NULL },
{ "login", 5, NSGTK_RESOURCE_FILE, NULL },
{ "ssl", 3, NSGTK_RESOURCE_FILE, NULL },
{ "toolbar", 7, NSGTK_RESOURCE_FILE, NULL },
{ "downloads", 9, NSGTK_RESOURCE_FILE, NULL },
{ "history", 7, NSGTK_RESOURCE_FILE, NULL },
{ "options", 7, NSGTK_RESOURCE_FILE, NULL },
{ "hotlist", 7, NSGTK_RESOURCE_FILE, NULL },
{ "cookies", 7, NSGTK_RESOURCE_FILE, NULL },
{ "viewdata", 8, NSGTK_RESOURCE_FILE, NULL },
{ "warning", 7, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
static struct nsgtk_resource_s gen_resource[] = {
{ "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
/* exported interface documented in gtk/resources.h */
GdkCursor *nsgtk_create_menu_cursor(void)
{
GdkCursor *cursor = NULL;
@ -44,3 +88,243 @@ GdkCursor *nsgtk_create_menu_cursor(void)
return cursor;
}
/*
* locate a resource
*
* The way GTK accesses resource files has changed greatly between
* releases. This initilises the interface that hides all the
* implementation details from the rest of the code.
*
* If the GResource is not enabled or the item cannot be found in the
* compiled in resources the files will be loaded directly from disc
* instead.
*
* \param respath A string vector containing the valid resource search paths
* \param ui_res A resource entry to initialise
*/
static nserror
init_resource(char **respath, struct nsgtk_resource_s *resource)
{
int resnamelen;
char *resname;
#ifdef WITH_GRESOURCE
gboolean present;
resnamelen = snprintf(NULL, 0, "/org/netsurf/%s", resource->name);
resname = malloc(resnamelen + 1);
if (resname == NULL) {
return NSERROR_NOMEM;
}
snprintf(resname, resnamelen + 1, "/org/netsurf/%s", resource->name);
present = g_resources_get_info(resname,
G_RESOURCE_LOOKUP_FLAGS_NONE,
NULL, NULL, NULL);
if (present == TRUE) {
/* found an entry in the resources */
resource->path = resname;
resource->type = NSGTK_RESOURCE_BUILTIN;
LOG("Found gresource path %s", resource->path);
return NSERROR_OK;
}
LOG("gresource \"%s\" not found", resname);
free(resname);
#endif
resname = filepath_find(respath, resource->name);
if (resname == NULL) {
LOG("Unable to find resource %s on resource path",
resource->name);
return NSERROR_NOT_FOUND;
}
/* found an entry on the path */
resource->path = resname;
resource->type = NSGTK_RESOURCE_FILE;
LOG("Found file resource path %s", resource->path);
return NSERROR_OK;
}
/*
* locate a ui resource
*
* UI resources need their resource name changing to account for gtk versions
*
* \param respath A string vector containing the valid resource search paths
* \param ui_res A resource entry to initialise
*/
static nserror init_ui_resource(char **respath, struct nsgtk_resource_s *ui_res)
{
#if GTK_CHECK_VERSION(3,0,0)
int gtkv = 3;
#else
int gtkv = 2;
#endif
int resnamelen;
char *resname;
struct nsgtk_resource_s resource;
nserror res;
resnamelen = ui_res->len + 10; /* allow for the expanded ui name */
resname = malloc(resnamelen);
if (resname == NULL) {
return NSERROR_NOMEM;
}
snprintf(resname, resnamelen, "%s.gtk%d.ui", ui_res->name, gtkv);
resource.name = resname;
resource.len = ui_res->len;
resource.path = NULL;
res = init_resource(respath, &resource);
ui_res->path = resource.path;
ui_res->type = resource.type;
free(resname);
return res;
}
#define SHOW_GRESOURCE
/**
* Initialise UI resource table
*
*/
nserror nsgtk_init_resources(char **respath)
{
struct nsgtk_resource_s *resource;
nserror res;
#ifdef SHOW_GRESOURCE
const char *nspath = "/org/netsurf";
char **reslist;
char **cur;
GError* gerror = NULL;
reslist = g_resources_enumerate_children(nspath,G_RESOURCE_LOOKUP_FLAGS_NONE, &gerror);
if (gerror) {
LOG("gerror %s", gerror->message);
g_error_free(gerror);
} else {
cur = reslist;
while (cur != NULL && *cur != NULL) {
LOG("gres %s", *cur);
cur++;
}
g_strfreev(reslist);
}
#endif
/* walk the ui resource table and initialise all its members */
resource = &ui_resource[0];
while (resource->name != NULL) {
res = init_ui_resource(respath, resource);
if (res != NSERROR_OK) {
return res;
}
resource++;
}
/* walk the general resource table and initialise all its members */
resource = &gen_resource[0];
while (resource->name != NULL) {
res = init_resource(respath, resource);
if (res != NSERROR_OK) {
return res;
}
resource++;
}
return NSERROR_OK;
}
static struct nsgtk_resource_s *
find_resource_from_name(const char *resname, struct nsgtk_resource_s *resource)
{
/* find resource from name */
while ((resource->name != NULL) &&
((resname[0] != resource->name[0]) ||
(strncmp(resource->name, resname, resource->len) != 0))) {
resource++;
}
return resource;
}
/* exported interface documented in gtk/resources.h */
nserror
nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
{
struct nsgtk_resource_s *resource;
GdkPixbuf *new_pixbuf;
GError* error = NULL;
resource = find_resource_from_name(resname, &gen_resource[0]);
if (resource->name == NULL) {
return NSERROR_NOT_FOUND;
}
if (resource->type == NSGTK_RESOURCE_FILE) {
new_pixbuf = gdk_pixbuf_new_from_file(resource->path, &error);
} else {
new_pixbuf = gdk_pixbuf_new_from_resource(resource->path, &error);
}
if (new_pixbuf == NULL) {
LOG("Unable to create pixbuf from file for %s with path %s \"%s\"",
resource->name, resource->path, error->message);
g_error_free(error);
return NSERROR_INIT_FAILED;
}
*pixbuf_out = new_pixbuf;
return NSERROR_OK;
}
/* exported interface documented in gtk/resources.h */
nserror
nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
{
GtkBuilder *new_builder;
struct nsgtk_resource_s *ui_res;
GError* error = NULL;
ui_res = find_resource_from_name(resname, &ui_resource[0]);
if (ui_res->name == NULL) {
return NSERROR_NOT_FOUND;
}
new_builder = gtk_builder_new();
if (ui_res->type == NSGTK_RESOURCE_FILE) {
if (!gtk_builder_add_from_file(new_builder,
ui_res->path,
&error)) {
LOG("Unable to add UI builder from file for %s with path %s \"%s\"",
ui_res->name, ui_res->path, error->message);
g_error_free(error);
g_object_unref(G_OBJECT(new_builder));
return NSERROR_INIT_FAILED;
}
} else {
if (!nsgtk_builder_add_from_resource(new_builder,
ui_res->path,
&error)) {
LOG("Unable to add UI builder from resource for %s with path %s \"%s\"",
ui_res->name, ui_res->path, error->message);
g_error_free(error);
g_object_unref(G_OBJECT(new_builder));
return NSERROR_INIT_FAILED;
}
}
*builder_out = new_builder;
return NSERROR_OK;
}

View File

@ -24,4 +24,36 @@
*/
GdkCursor *nsgtk_create_menu_cursor(void);
nserror nsgtk_init_resources(char **respath);
/**
* Create gtk builder object for the named ui resource
*
* Creating gtk builder objects from a named resource requires the
* source xml resource to be parsed.
*
* This creates a gtk builder instance using an identifier name which
* is mapped to the ui_resource table which must be initialised with
* nsgtk_init_resources()
*
* \param resname The resource name to construct for
* \param builder_out The builder result
* \return NSERROR_OK and builder_out updated or appropriate error code
*/
nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out);
/**
* Create gdk pixbuf for the named ui resource
*
* This creates a pixbuf using an identifier name which is mapped to
* the ui_resource table which must be initialised with
* nsgtk_init_resources()
*
* \param resname The resource name to construct for
* \param pixbuf_out The pixbuf result
* \return NSERROR_OK and pixbuf_out updated or appropriate error code
*/
nserror nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out);
#endif

View File

@ -71,6 +71,7 @@
#include "gtk/tabs.h"
#include "gtk/schedule.h"
#include "gtk/viewdata.h"
#include "gtk/resources.h"
/** Macro to define a handler for menu, button and activate events. */
#define MULTIHANDLER(q)\
@ -122,7 +123,7 @@ struct nsgtk_scaffolding {
int toolbarbase;
int historybase;
GtkBuilder *xml;
GtkBuilder *builder;
struct gtk_history_window *history_window;
@ -2032,95 +2033,87 @@ void nsgtk_scaffolding_toolbars(struct nsgtk_scaffolding *g, int tbi)
/* exported interface documented in gtk/scaffolding.h */
struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
{
struct nsgtk_scaffolding *g;
struct nsgtk_scaffolding *gs;
int i;
GtkAccelGroup *group;
GError* error = NULL;
g = malloc(sizeof(*g));
if (g == NULL) {
gs = malloc(sizeof(*gs));
if (gs == NULL) {
return NULL;
}
LOG("Constructing a scaffold of %p for gui_window %p", g, toplevel);
LOG("Constructing a scaffold of %p for gui_window %p", gs, toplevel);
g->top_level = toplevel;
gs->top_level = toplevel;
/* load the window template from the glade xml file, and extract
* widget references from it for later use.
*/
g->xml = gtk_builder_new();
if (!gtk_builder_add_from_file(g->xml, glade_file_location->netsurf, &error)) {
g_warning("Couldn't load builder file: \"%s\"", error->message);
g_error_free(error);
free(g);
/* Construct UI widgets */
if (nsgtk_builder_new_from_resname("netsurf", &gs->builder) != NSERROR_OK) {
free(gs);
return NULL;
}
gtk_builder_connect_signals(g->xml, NULL);
gtk_builder_connect_signals(gs->builder, NULL);
/** Obtain a GTK widget handle from glade xml object */
#define GET_WIDGET(x) GTK_WIDGET (gtk_builder_get_object(g->xml, (x)))
/** Obtain a GTK widget handle from UI builder object */
#define GET_WIDGET(x) GTK_WIDGET (gtk_builder_get_object(gs->builder, (x)))
g->window = GTK_WINDOW(GET_WIDGET("wndBrowser"));
g->notebook = GTK_NOTEBOOK(GET_WIDGET("notebook"));
g->tool_bar = GTK_TOOLBAR(GET_WIDGET("toolbar"));
gs->window = GTK_WINDOW(GET_WIDGET("wndBrowser"));
gs->notebook = GTK_NOTEBOOK(GET_WIDGET("notebook"));
gs->tool_bar = GTK_TOOLBAR(GET_WIDGET("toolbar"));
g->search = malloc(sizeof(struct gtk_search));
if (g->search == NULL) {
free(g);
gs->search = malloc(sizeof(struct gtk_search));
if (gs->search == NULL) {
free(gs);
return NULL;
}
g->search->bar = GTK_TOOLBAR(GET_WIDGET("searchbar"));
g->search->entry = GTK_ENTRY(GET_WIDGET("searchEntry"));
gs->search->bar = GTK_TOOLBAR(GET_WIDGET("searchbar"));
gs->search->entry = GTK_ENTRY(GET_WIDGET("searchEntry"));
g->search->buttons[0] = GTK_TOOL_BUTTON(GET_WIDGET("searchBackButton"));
g->search->buttons[1] = GTK_TOOL_BUTTON(GET_WIDGET(
"searchForwardButton"));
g->search->buttons[2] = GTK_TOOL_BUTTON(GET_WIDGET(
"closeSearchButton"));
g->search->checkAll = GTK_CHECK_BUTTON(GET_WIDGET("checkAllSearch"));
g->search->caseSens = GTK_CHECK_BUTTON(GET_WIDGET("caseSensButton"));
gs->search->buttons[0] = GTK_TOOL_BUTTON(GET_WIDGET("searchBackButton"));
gs->search->buttons[1] = GTK_TOOL_BUTTON(GET_WIDGET("searchForwardButton"));
gs->search->buttons[2] = GTK_TOOL_BUTTON(GET_WIDGET("closeSearchButton"));
gs->search->checkAll = GTK_CHECK_BUTTON(GET_WIDGET("checkAllSearch"));
gs->search->caseSens = GTK_CHECK_BUTTON(GET_WIDGET("caseSensButton"));
#undef GET_WIDGET
/* allocate buttons */
for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
g->buttons[i] = calloc(1, sizeof(struct nsgtk_button_connect));
if (g->buttons[i] == NULL) {
gs->buttons[i] = calloc(1, sizeof(struct nsgtk_button_connect));
if (gs->buttons[i] == NULL) {
for (i-- ; i >= BACK_BUTTON; i--) {
free(g->buttons[i]);
free(gs->buttons[i]);
}
free(g);
free(gs);
return NULL;
}
g->buttons[i]->location = -1;
g->buttons[i]->sensitivity = true;
gs->buttons[i]->location = -1;
gs->buttons[i]->sensitivity = true;
}
/* here custom toolbutton adding code */
g->offset = 0;
g->toolbarmem = 0;
g->toolbarbase = 0;
g->historybase = 0;
nsgtk_toolbar_customization_load(g);
nsgtk_toolbar_set_physical(g);
gs->offset = 0;
gs->toolbarmem = 0;
gs->toolbarbase = 0;
gs->historybase = 0;
nsgtk_toolbar_customization_load(gs);
nsgtk_toolbar_set_physical(gs);
group = gtk_accel_group_new();
gtk_window_add_accel_group(g->window, group);
gtk_window_add_accel_group(gs->window, group);
g->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(g->xml, "menubar")), group);
gs->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(gs->builder, "menubar")), group);
/* set this window's size and position to what's in the options, or
* or some sensible default if they're not set yet.
*/
if (nsoption_int(window_width) > 0) {
gtk_window_move(g->window,
gtk_window_move(gs->window,
nsoption_int(window_x),
nsoption_int(window_y));
gtk_window_resize(g->window,
gtk_window_resize(gs->window,
nsoption_int(window_width),
nsoption_int(window_height));
} else {
@ -2128,7 +2121,7 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
* 1024x768 displays, not being able to take into account
* window furniture or panels.
*/
gtk_window_set_default_size(g->window, 1000, 700);
gtk_window_set_default_size(gs->window, 1000, 700);
}
/* Default toolbar button type uses system defaults */
@ -2164,137 +2157,151 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
}
}
nsgtk_scaffolding_toolbars(g, nsoption_int(button_type));
nsgtk_scaffolding_toolbars(gs, nsoption_int(button_type));
gtk_toolbar_set_show_arrow(g->tool_bar, TRUE);
gtk_widget_show_all(GTK_WIDGET(g->tool_bar));
nsgtk_tab_init(g);
gtk_toolbar_set_show_arrow(gs->tool_bar, TRUE);
gtk_widget_show_all(GTK_WIDGET(gs->tool_bar));
nsgtk_tab_init(gs);
gtk_widget_set_size_request(GTK_WIDGET(
g->buttons[HISTORY_BUTTON]->button), 20, -1);
gs->buttons[HISTORY_BUTTON]->button), 20, -1);
/* create the local history window to be associated with this browser */
g->history_window = malloc(sizeof(struct gtk_history_window));
g->history_window->g = g;
g->history_window->window =
gs->history_window = malloc(sizeof(struct gtk_history_window));
gs->history_window->g = gs;
gs->history_window->window =
GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
gtk_window_set_transient_for(g->history_window->window, g->window);
gtk_window_set_title(g->history_window->window, "NetSurf History");
gtk_window_set_type_hint(g->history_window->window,
gtk_window_set_transient_for(gs->history_window->window, gs->window);
gtk_window_set_title(gs->history_window->window, "NetSurf History");
gtk_window_set_type_hint(gs->history_window->window,
GDK_WINDOW_TYPE_HINT_UTILITY);
g->history_window->scrolled =
gs->history_window->scrolled =
GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(0, 0));
gtk_container_add(GTK_CONTAINER(g->history_window->window),
GTK_WIDGET(g->history_window->scrolled));
gtk_container_add(GTK_CONTAINER(gs->history_window->window),
GTK_WIDGET(gs->history_window->scrolled));
gtk_widget_show(GTK_WIDGET(g->history_window->scrolled));
g->history_window->drawing_area =
gtk_widget_show(GTK_WIDGET(gs->history_window->scrolled));
gs->history_window->drawing_area =
GTK_DRAWING_AREA(gtk_drawing_area_new());
gtk_widget_set_events(GTK_WIDGET(g->history_window->drawing_area),
gtk_widget_set_events(GTK_WIDGET(gs->history_window->drawing_area),
GDK_EXPOSURE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK);
nsgtk_widget_override_background_color(GTK_WIDGET(g->history_window->drawing_area),
nsgtk_widget_override_background_color(GTK_WIDGET(gs->history_window->drawing_area),
GTK_STATE_NORMAL,
0, 0xffff, 0xffff, 0xffff);
nsgtk_scrolled_window_add_with_viewport(g->history_window->scrolled,
GTK_WIDGET(g->history_window->drawing_area));
gtk_widget_show(GTK_WIDGET(g->history_window->drawing_area));
nsgtk_scrolled_window_add_with_viewport(gs->history_window->scrolled,
GTK_WIDGET(gs->history_window->drawing_area));
gtk_widget_show(GTK_WIDGET(gs->history_window->drawing_area));
/* set up URL bar completion */
g->url_bar_completion = gtk_entry_completion_new();
gtk_entry_completion_set_match_func(g->url_bar_completion,
gs->url_bar_completion = gtk_entry_completion_new();
gtk_entry_completion_set_match_func(gs->url_bar_completion,
nsgtk_completion_match, NULL, NULL);
gtk_entry_completion_set_model(g->url_bar_completion,
gtk_entry_completion_set_model(gs->url_bar_completion,
GTK_TREE_MODEL(nsgtk_completion_list));
gtk_entry_completion_set_text_column(g->url_bar_completion, 0);
gtk_entry_completion_set_minimum_key_length(g->url_bar_completion, 1);
gtk_entry_completion_set_popup_completion(g->url_bar_completion, TRUE);
g_object_set(G_OBJECT(g->url_bar_completion),
gtk_entry_completion_set_text_column(gs->url_bar_completion, 0);
gtk_entry_completion_set_minimum_key_length(gs->url_bar_completion, 1);
gtk_entry_completion_set_popup_completion(gs->url_bar_completion, TRUE);
g_object_set(G_OBJECT(gs->url_bar_completion),
"popup-set-width", TRUE,
"popup-single-match", TRUE,
NULL);
/* set up the throbber. */
g->throb_frame = 0;
gs->throb_frame = 0;
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
/* connect history window signals to their handlers */
nsgtk_connect_draw_event(GTK_WIDGET(g->history_window->drawing_area),
nsgtk_connect_draw_event(GTK_WIDGET(gs->history_window->drawing_area),
G_CALLBACK(nsgtk_history_draw_event),
g->history_window);
/*CONNECT(g->history_window->drawing_area, "motion_notify_event",
nsgtk_history_motion_notify_event, g->history_window);*/
CONNECT(g->history_window->drawing_area, "button_press_event",
nsgtk_history_button_press_event, g->history_window);
CONNECT(g->history_window->window, "delete_event",
gs->history_window);
/*CONNECT(gs->history_window->drawing_area, "motion_notify_event",
nsgtk_history_motion_notify_event, gs->history_window);*/
CONNECT(gs->history_window->drawing_area, "button_press_event",
nsgtk_history_button_press_event, gs->history_window);
CONNECT(gs->history_window->window, "delete_event",
gtk_widget_hide_on_delete, NULL);
g_signal_connect_after(g->notebook, "page-added",
G_CALLBACK(nsgtk_window_tabs_add), g);
g_signal_connect_after(g->notebook, "page-removed",
G_CALLBACK(nsgtk_window_tabs_remove), g);
g_signal_connect_after(gs->notebook, "page-added",
G_CALLBACK(nsgtk_window_tabs_add), gs);
g_signal_connect_after(gs->notebook, "page-removed",
G_CALLBACK(nsgtk_window_tabs_remove), gs);
/* connect main window signals to their handlers. */
CONNECT(g->window, "delete-event", scaffolding_window_delete_event, g);
CONNECT(g->window, "destroy", scaffolding_window_destroy, g);
CONNECT(gs->window, "delete-event",
scaffolding_window_delete_event, gs);
CONNECT(gs->window, "destroy", scaffolding_window_destroy, gs);
/* toolbar URL bar menu bar search bar signal handlers */
CONNECT(g->menu_bar->edit_submenu->edit, "show", nsgtk_window_edit_menu_clicked, g);
CONNECT(g->menu_bar->edit_submenu->edit, "hide", nsgtk_window_edit_menu_hidden, g);
CONNECT(g->search->buttons[1], "clicked",
nsgtk_search_forward_button_clicked, g);
CONNECT(g->search->buttons[0], "clicked",
nsgtk_search_back_button_clicked, g);
CONNECT(g->search->entry, "changed", nsgtk_search_entry_changed, g);
CONNECT(g->search->entry, "activate", nsgtk_search_entry_activate, g);
CONNECT(g->search->entry, "key-press-event", nsgtk_search_entry_key, g);
CONNECT(g->search->buttons[2], "clicked",
nsgtk_search_close_button_clicked, g);
CONNECT(g->search->caseSens, "toggled", nsgtk_search_entry_changed, g);
CONNECT(gs->menu_bar->edit_submenu->edit, "show",
nsgtk_window_edit_menu_clicked, gs);
CONNECT(gs->menu_bar->edit_submenu->edit, "hide",
nsgtk_window_edit_menu_hidden, gs);
CONNECT(g->tool_bar, "popup-context-menu",
nsgtk_window_tool_bar_clicked, g);
CONNECT(gs->search->buttons[1], "clicked",
nsgtk_search_forward_button_clicked, gs);
CONNECT(gs->search->buttons[0], "clicked",
nsgtk_search_back_button_clicked, gs);
CONNECT(gs->search->entry, "changed", nsgtk_search_entry_changed, gs);
CONNECT(gs->search->entry, "activate", nsgtk_search_entry_activate, gs);
CONNECT(gs->search->entry, "key-press-event",
nsgtk_search_entry_key, gs);
CONNECT(gs->search->buttons[2], "clicked",
nsgtk_search_close_button_clicked, gs);
CONNECT(gs->search->caseSens, "toggled",
nsgtk_search_entry_changed, gs);
CONNECT(gs->tool_bar, "popup-context-menu",
nsgtk_window_tool_bar_clicked, gs);
/* create popup menu */
g->menu_popup = nsgtk_new_scaffolding_popup(g, group);
gs->menu_popup = nsgtk_new_scaffolding_popup(gs, group);
g->link_menu = nsgtk_new_scaffolding_link_popup(g, group);
gs->link_menu = nsgtk_new_scaffolding_link_popup(gs, group);
/* set up the menu signal handlers */
nsgtk_scaffolding_toolbar_init(g);
nsgtk_toolbar_connect_all(g);
nsgtk_attach_menu_handlers(g);
nsgtk_scaffolding_toolbar_init(gs);
nsgtk_toolbar_connect_all(gs);
nsgtk_attach_menu_handlers(gs);
nsgtk_scaffolding_initial_sensitivity(g);
nsgtk_scaffolding_initial_sensitivity(gs);
g->fullscreen = false;
gs->fullscreen = false;
/* attach to the list */
if (scaf_list)
scaf_list->prev = g;
g->next = scaf_list;
g->prev = NULL;
scaf_list = g;
if (scaf_list) {
scaf_list->prev = gs;
}
gs->next = scaf_list;
gs->prev = NULL;
scaf_list = gs;
/* call functions that need access from the list */
nsgtk_theme_init();
nsgtk_theme_implement(g);
nsgtk_theme_implement(gs);
/* set web search provider */
search_web_select_provider(nsoption_int(search_provider));
/* finally, show the window. */
gtk_widget_show(GTK_WIDGET(g->window));
gtk_widget_show(GTK_WIDGET(gs->window));
LOG("creation complete");
return g;
return gs;
}
/* exported function documented in gtk/scaffolding.h */

View File

@ -19,14 +19,14 @@
#include <stdlib.h>
#include <gtk/gtk.h>
#include "utils/errors.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "desktop/tree.h"
#include "desktop/sslcert_viewer.h"
#include "gtk/gui.h"
#include "gtk/treeview.h"
#include "gtk/scaffolding.h"
#include "gtk/resources.h"
#include "gtk/ssl_cert.h"
@ -75,9 +75,9 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
GtkDialog *dlg;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
GError *error = NULL;
GtkBuilder *builder;
GtkWindow *gtk_parent;
nserror res;
/* state while dlg is open */
session = calloc(sizeof(void *), 3);
@ -85,15 +85,16 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
return;
}
builder = gtk_builder_new();
if (!gtk_builder_add_from_file(builder, glade_file_location->ssl, &error)) {
g_warning("Couldn't load builder file: %s", error->message);
g_error_free(error);
res = nsgtk_builder_new_from_resname("ssl", &builder);
if (res != NSERROR_OK) {
LOG("SSL UI builder init failed");
free(session);
cb(false, cbpw);
return;
}
gtk_builder_connect_signals(builder, NULL);
sslcert_viewer_create_session_data(num, url, cb, cbpw, certs, &data);
ssl_current_session = data;
@ -106,7 +107,6 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(builder, "SSLScrolled"));
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "SSLDrawingArea"));
ssl_window = nsgtk_treeview_create(TREE_SSLCERT, GTK_WINDOW(dlg), scrolled,
drawing_area);

View File

@ -25,7 +25,6 @@
#include "utils/messages.h"
#include "utils/utils.h"
#include "gtk/toolbar.h"
#include "gtk/gui.h"
#include "gtk/scaffolding.h"
#include "gtk/search.h"
@ -33,6 +32,8 @@
#include "gtk/throbber.h"
#include "gtk/window.h"
#include "gtk/compat.h"
#include "gtk/resources.h"
#include "gtk/toolbar.h"
static GtkTargetEntry entry = {(char *)"nsgtk_button_data",
GTK_TARGET_SAME_APP, 0};
@ -45,7 +46,7 @@ struct nsgtk_toolbar_custom_store {
GtkWidget *widgetvbox;
GtkWidget *currentbar;
char numberh; /* current horizontal location while adding */
GtkBuilder *glade; /* button widgets to store */
GtkBuilder *builder; /* button widgets to store */
int buttonlocations[PLACEHOLDER_BUTTON];
int currentbutton;
bool fromstore;
@ -727,30 +728,29 @@ nsgtk_toolbar_store_action(GtkWidget *widget, GdkDragContext *gdc,
static void nsgtk_toolbar_window_open(struct nsgtk_scaffolding *g)
{
int x = 0, y = 0;
GError* error = NULL;
struct nsgtk_theme *theme =
nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR);
struct nsgtk_theme *theme;
nserror res;
theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR);
if (theme == NULL) {
warn_user(messages_get("NoMemory"), 0);
nsgtk_toolbar_cancel_clicked(NULL, g);
return;
}
window->glade = gtk_builder_new();
if (!gtk_builder_add_from_file(window->glade,
glade_file_location->toolbar,
&error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
res = nsgtk_builder_new_from_resname("toolbar", &window->builder);
if (res != NSERROR_OK) {
LOG("Toolbar UI builder init failed");
warn_user(messages_get("NoMemory"), 0);
nsgtk_toolbar_cancel_clicked(NULL, g);
free(theme);
return;
}
gtk_builder_connect_signals(window->glade, NULL);
gtk_builder_connect_signals(window->builder, NULL);
window->window = GTK_WIDGET(gtk_builder_get_object(window->glade, "toolbarwindow"));
window->window = GTK_WIDGET(gtk_builder_get_object(window->builder,
"toolbarwindow"));
if (window->window == NULL) {
warn_user(messages_get("NoMemory"), 0);
nsgtk_toolbar_cancel_clicked(NULL, g);
@ -758,7 +758,8 @@ static void nsgtk_toolbar_window_open(struct nsgtk_scaffolding *g)
return;
}
window->widgetvbox = GTK_WIDGET(gtk_builder_get_object(window->glade, "widgetvbox"));
window->widgetvbox = GTK_WIDGET(gtk_builder_get_object(window->builder,
"widgetvbox"));
if (window->widgetvbox == NULL) {
warn_user(messages_get("NoMemory"), 0);
nsgtk_toolbar_cancel_clicked(NULL, g);
@ -767,7 +768,7 @@ static void nsgtk_toolbar_window_open(struct nsgtk_scaffolding *g)
}
window->numberh = NSGTK_STORE_WIDTH; /* preset to width [in buttons] of */
/* store to cause creation of a new toolbar */
/* store to cause creation of a new toolbar */
window->currentbutton = -1;
/* load toolbuttons */
/* add toolbuttons to window */
@ -776,44 +777,57 @@ static void nsgtk_toolbar_window_open(struct nsgtk_scaffolding *g)
if (i == URL_BAR_ITEM)
continue;
window->store_buttons[i] =
nsgtk_toolbar_make_widget(g, i, theme);
nsgtk_toolbar_make_widget(g, i, theme);
if (window->store_buttons[i] == NULL) {
warn_user(messages_get("NoMemory"), 0);
continue;
}
nsgtk_toolbar_add_store_widget(window->store_buttons[i]);
g_signal_connect(window->store_buttons[i], "drag-data-get",
G_CALLBACK(
nsgtk_scaffolding_button(g, i)->dataplus), g);
G_CALLBACK(
nsgtk_scaffolding_button(g, i)->dataplus), g);
}
free(theme);
gtk_window_set_transient_for(GTK_WINDOW(window->window),
nsgtk_scaffolding_window(g));
nsgtk_scaffolding_window(g));
gtk_window_set_title(GTK_WINDOW(window->window), messages_get(
"gtkToolBarTitle"));
"gtkToolBarTitle"));
gtk_window_set_accept_focus(GTK_WINDOW(window->window), FALSE);
gtk_drag_dest_set(GTK_WIDGET(window->window), GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP, &entry, 1, GDK_ACTION_COPY);
GTK_DEST_DEFAULT_DROP, &entry, 1, GDK_ACTION_COPY);
gtk_widget_show_all(window->window);
gtk_window_set_position(GTK_WINDOW(window->window),
GTK_WIN_POS_CENTER_ON_PARENT);
GTK_WIN_POS_CENTER_ON_PARENT);
gtk_window_get_position(nsgtk_scaffolding_window(g), &x, &y);
gtk_window_move(GTK_WINDOW(window->window), x, y + 100);
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->glade, "cancelbutton")),
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->builder,
"cancelbutton")),
"clicked",
G_CALLBACK(nsgtk_toolbar_cancel_clicked),
g);
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->glade, "okbutton")),
"clicked", G_CALLBACK(nsgtk_toolbar_persist), g);
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->glade, "resetbutton")),
"clicked", G_CALLBACK(nsgtk_toolbar_reset), g);
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->builder,
"okbutton")),
"clicked",
G_CALLBACK(nsgtk_toolbar_persist),
g);
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(window->builder,
"resetbutton")),
"clicked",
G_CALLBACK(nsgtk_toolbar_reset),
g);
g_signal_connect(window->window, "delete-event",
G_CALLBACK(nsgtk_toolbar_delete), g);
G_CALLBACK(nsgtk_toolbar_delete), g);
g_signal_connect(window->window, "drag-drop",
G_CALLBACK(nsgtk_toolbar_store_return), g);
G_CALLBACK(nsgtk_toolbar_store_return), g);
g_signal_connect(window->window, "drag-motion",
G_CALLBACK(nsgtk_toolbar_store_action), g);
G_CALLBACK(nsgtk_toolbar_store_action), g);
}
/**

View File

@ -45,7 +45,7 @@
#include "gtk/about.h"
#include "gtk/fetch.h"
#include "gtk/compat.h"
#include "gtk/gui.h"
#include "gtk/resources.h"
#include "gtk/viewdata.h"
struct nsgtk_viewdata_ctx {
@ -351,7 +351,6 @@ window_init(const char *title,
char *ndata,
size_t ndata_len)
{
GError* error = NULL;
GtkWindow *window;
GtkWidget *cutbutton;
GtkWidget *pastebutton;
@ -361,30 +360,24 @@ window_init(const char *title,
PangoFontDescription *fontdesc;
GtkTextBuffer *tb;
struct nsgtk_viewdata_ctx *newctx;
nserror res;
newctx = malloc(sizeof(struct nsgtk_viewdata_ctx));
if (newctx == NULL) {
return NSERROR_NOMEM;
}
newctx->builder = gtk_builder_new();
if (newctx->builder == NULL) {
res = nsgtk_builder_new_from_resname("viewdata", &newctx->builder);
if (res != NSERROR_OK) {
LOG("Viewdata UI builder init failed");
free(newctx);
return NSERROR_INIT_FAILED;
return res;
}
if (!gtk_builder_add_from_file(newctx->builder,
glade_file_location->viewdata,
&error)) {
LOG("Couldn't load builder file: %s", error->message);
g_error_free(error);
free(newctx);
return NSERROR_INIT_FAILED;
}
window = GTK_WINDOW(gtk_builder_get_object(newctx->builder, "ViewDataWindow"));
gtk_builder_connect_signals(newctx->builder, NULL);
window = GTK_WINDOW(gtk_builder_get_object(newctx->builder,
"ViewDataWindow"));
if (window == NULL) {
LOG("Unable to find window in builder ");

View File

@ -736,25 +736,24 @@ gui_window_create(struct browser_window *bw,
struct gui_window *existing,
gui_window_create_flags flags)
{
struct gui_window *g; /* what is being creating to return */
GError* error = NULL;
struct gui_window *g; /* what is being created to return */
bool tempback;
GtkBuilder* xml;
GtkBuilder* tab_builder;
/* open builder file first to ease error handling on faliure */
xml = gtk_builder_new();
if (!gtk_builder_add_from_file(xml,
glade_file_location->tabcontents,
&error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free(error);
nserror res;
res = nsgtk_builder_new_from_resname("tabcontents", &tab_builder);
if (res != NSERROR_OK) {
LOG("Tab contents UI builder init failed");
return NULL;
}
gtk_builder_connect_signals(tab_builder, NULL);
g = calloc(1, sizeof(*g));
if (!g) {
warn_user("NoMemory", 0);
g_object_unref(xml);
g_object_unref(tab_builder);
return NULL;
}
@ -778,15 +777,15 @@ gui_window_create(struct browser_window *bw,
if (g->scaffold == NULL) {
warn_user("NoMemory", 0);
free(g);
g_object_unref(xml);
g_object_unref(tab_builder);
return NULL;
}
/* Construct our primary elements */
g->container = GTK_WIDGET(gtk_builder_get_object(xml, "tabContents"));
g->layout = GTK_LAYOUT(gtk_builder_get_object(xml, "layout"));
g->status_bar = GTK_LABEL(gtk_builder_get_object(xml, "status_bar"));
g->paned = GTK_PANED(gtk_builder_get_object(xml, "hpaned1"));
g->container = GTK_WIDGET(gtk_builder_get_object(tab_builder, "tabContents"));
g->layout = GTK_LAYOUT(gtk_builder_get_object(tab_builder, "layout"));
g->status_bar = GTK_LABEL(gtk_builder_get_object(tab_builder, "status_bar"));
g->paned = GTK_PANED(gtk_builder_get_object(tab_builder, "hpaned1"));
g->input_method = gtk_im_multicontext_new();
@ -876,10 +875,10 @@ gui_window_create(struct browser_window *bw,
}
nsgtk_tab_add(g, g->container, tempback);
/* safe to drop the reference to the xml as the container is
/* safe to drop the reference to the tab_builder as the container is
* referenced by the notebook now.
*/
g_object_unref(xml);
g_object_unref(tab_builder);
return g;
}