netsurf: branch master updated. release/3.3-181-g51a92fb
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/51a92fbd844b9ae4a1024...
...commit http://git.netsurf-browser.org/netsurf.git/commit/51a92fbd844b9ae4a102452...
...tree http://git.netsurf-browser.org/netsurf.git/tree/51a92fbd844b9ae4a102452a9...
The branch, master has been updated
via 51a92fbd844b9ae4a102452a9bccf0d1af48a004 (commit)
from c08bccbcea4e907836234279fd964dd1baa4fd4d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=51a92fbd844b9ae4a10...
commit 51a92fbd844b9ae4a102452a9bccf0d1af48a004
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Consolidate default style.
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79
index 9ee7388..3892aff 100644
--- a/!NetSurf/Resources/CSS,f79
+++ b/!NetSurf/Resources/CSS,f79
@@ -116,29 +116,30 @@ form { display: block; }
input, button { background-color: #fff; color: #000; text-align: left;
font-family: sans-serif; width: auto; height: auto; overflow: hidden;
- border: 2px solid #333; padding: 1px 2px; line-height: 1.33; }
+ border: 1px solid #444; padding: 2px 3px; line-height: 1.33;
+ margin: 1px; }
input[readonly] { background-color: #ddd; color: #333; }
input[type=button], input[type=reset], input[type=submit], button {
background-color: #d9d9d9; color: #000; text-align: center;
- border: medium outset #d9d9d9; padding: 1px 0.5em; }
+ border: 2px outset #d9d9d9; padding: 1px 0.5em; }
input[type=image] { background-color: transparent; color: #000;
border: none; padding: 0 2px; }
input[type=checkbox], input[type=radio] { background-color: transparent;
border: none; padding: 0 0.1em; }
input[type=file] { background-color: #d9d9d9; color: #000; font-style: italic;
- border: medium inset #d9d9d9; padding: 1px 2px; }
+ border: 2px inset #d9d9d9; padding: 1px 2px; }
input[align=left] { float: left; }
input[align=right] { float: right; }
select { background-color: #d9d9d9; color: #000; text-align: left;
font-family: sans-serif; width: auto; height: auto; overflow: hidden;
- margin: 1px; border: medium inset #d9d9d9; padding: 1px 3px 1px 2px;
- white-space: nowrap; }
-select:after { content: "\25bc"; border-left: 4px ridge #d9d9d9; }
+ border: medium inset #d9d9d9; padding: 1px 3px 1px 2px;
+ white-space: nowrap; margin: 1px; }
+select:after { content: "\25bc"; border-left: 2px ridge #d9d9d9; }
textarea { background-color: #fff; color: #000; text-align: left;
font-family: monospace; width: auto; height: auto; overflow: scroll;
- margin: 1px; border: 2px solid #333; padding: 0 2px; }
+ margin: 1px; border: 1px solid #333; padding: 1px 3px; }
textarea[readonly] { background-color: #ddd; color: #333; }
fieldset { display: block; border: thin solid #888; margin: 1.12em 0; }
diff --git a/gtk/res/gtkdefault.css b/gtk/res/gtkdefault.css
index 300c13a..b22564b 100644
--- a/gtk/res/gtkdefault.css
+++ b/gtk/res/gtkdefault.css
@@ -6,16 +6,3 @@
@import "default.css";
-/* Apply GTK specific rules. */
-
-input { font-size: 95%; border: medium inset #ddd; }
-input[type=button], input[type=reset], input[type=submit], button {
- background-color: #ddd; border: medium outset #ddd; }
-input[type=checkbox], input[type=radio] { font-size: 105%; }
-input[type=file] { background-color: #ddd; border: medium outset #ddd; }
-
-select { background-color: #ddd; border: medium inset #ddd; font-size: 95%; }
-select:after { border-left:4px ridge #ddd; }
-
-textarea { font-size: 95%; border: medium inset #ddd; }
-
-----------------------------------------------------------------------
Summary of changes:
!NetSurf/Resources/CSS,f79 | 15 ++++++++-------
gtk/res/gtkdefault.css | 13 -------------
2 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79
index 9ee7388..3892aff 100644
--- a/!NetSurf/Resources/CSS,f79
+++ b/!NetSurf/Resources/CSS,f79
@@ -116,29 +116,30 @@ form { display: block; }
input, button { background-color: #fff; color: #000; text-align: left;
font-family: sans-serif; width: auto; height: auto; overflow: hidden;
- border: 2px solid #333; padding: 1px 2px; line-height: 1.33; }
+ border: 1px solid #444; padding: 2px 3px; line-height: 1.33;
+ margin: 1px; }
input[readonly] { background-color: #ddd; color: #333; }
input[type=button], input[type=reset], input[type=submit], button {
background-color: #d9d9d9; color: #000; text-align: center;
- border: medium outset #d9d9d9; padding: 1px 0.5em; }
+ border: 2px outset #d9d9d9; padding: 1px 0.5em; }
input[type=image] { background-color: transparent; color: #000;
border: none; padding: 0 2px; }
input[type=checkbox], input[type=radio] { background-color: transparent;
border: none; padding: 0 0.1em; }
input[type=file] { background-color: #d9d9d9; color: #000; font-style: italic;
- border: medium inset #d9d9d9; padding: 1px 2px; }
+ border: 2px inset #d9d9d9; padding: 1px 2px; }
input[align=left] { float: left; }
input[align=right] { float: right; }
select { background-color: #d9d9d9; color: #000; text-align: left;
font-family: sans-serif; width: auto; height: auto; overflow: hidden;
- margin: 1px; border: medium inset #d9d9d9; padding: 1px 3px 1px 2px;
- white-space: nowrap; }
-select:after { content: "\25bc"; border-left: 4px ridge #d9d9d9; }
+ border: medium inset #d9d9d9; padding: 1px 3px 1px 2px;
+ white-space: nowrap; margin: 1px; }
+select:after { content: "\25bc"; border-left: 2px ridge #d9d9d9; }
textarea { background-color: #fff; color: #000; text-align: left;
font-family: monospace; width: auto; height: auto; overflow: scroll;
- margin: 1px; border: 2px solid #333; padding: 0 2px; }
+ margin: 1px; border: 1px solid #333; padding: 1px 3px; }
textarea[readonly] { background-color: #ddd; color: #333; }
fieldset { display: block; border: thin solid #888; margin: 1.12em 0; }
diff --git a/gtk/res/gtkdefault.css b/gtk/res/gtkdefault.css
index 300c13a..b22564b 100644
--- a/gtk/res/gtkdefault.css
+++ b/gtk/res/gtkdefault.css
@@ -6,16 +6,3 @@
@import "default.css";
-/* Apply GTK specific rules. */
-
-input { font-size: 95%; border: medium inset #ddd; }
-input[type=button], input[type=reset], input[type=submit], button {
- background-color: #ddd; border: medium outset #ddd; }
-input[type=checkbox], input[type=radio] { font-size: 105%; }
-input[type=file] { background-color: #ddd; border: medium outset #ddd; }
-
-select { background-color: #ddd; border: medium inset #ddd; font-size: 95%; }
-select:after { border-left:4px ridge #ddd; }
-
-textarea { font-size: 95%; border: medium inset #ddd; }
-
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-180-gc08bccb
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/c08bccbcea4e907836234...
...commit http://git.netsurf-browser.org/netsurf.git/commit/c08bccbcea4e90783623427...
...tree http://git.netsurf-browser.org/netsurf.git/tree/c08bccbcea4e907836234279f...
The branch, master has been updated
via c08bccbcea4e907836234279fd964dd1baa4fd4d (commit)
from a94ae7a80a9d96c4aa88995412ea26feafa69f3b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=c08bccbcea4e9078362...
commit c08bccbcea4e907836234279fd964dd1baa4fd4d
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
fixup missing lincludes from messages API update
diff --git a/amiga/login.c b/amiga/login.c
index 655a4b1..4cf9ba8 100755
--- a/amiga/login.c
+++ b/amiga/login.c
@@ -19,6 +19,7 @@
#include "amiga/os3support.h"
#include <assert.h>
+#include <stdlib.h>
#include <proto/exec.h>
#include <proto/intuition.h>
diff --git a/monkey/main.c b/monkey/main.c
index 2b1a3bc..d2529d8 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include "utils/log.h"
+#include "utils/messages.h"
#include "utils/filepath.h"
#include "utils/nsoption.h"
#include "content/urldb.h"
diff --git a/riscos/configure/con_home.c b/riscos/configure/con_home.c
index 4dec6ad..f8a13ce 100644
--- a/riscos/configure/con_home.c
+++ b/riscos/configure/con_home.c
@@ -17,6 +17,7 @@
*/
#include <stdbool.h>
+#include <stdlib.h>
#include "utils/messages.h"
#include "utils/utils.h"
-----------------------------------------------------------------------
Summary of changes:
amiga/login.c | 1 +
monkey/main.c | 1 +
riscos/configure/con_home.c | 1 +
3 files changed, 3 insertions(+)
diff --git a/amiga/login.c b/amiga/login.c
index 655a4b1..4cf9ba8 100755
--- a/amiga/login.c
+++ b/amiga/login.c
@@ -19,6 +19,7 @@
#include "amiga/os3support.h"
#include <assert.h>
+#include <stdlib.h>
#include <proto/exec.h>
#include <proto/intuition.h>
diff --git a/monkey/main.c b/monkey/main.c
index 2b1a3bc..d2529d8 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include "utils/log.h"
+#include "utils/messages.h"
#include "utils/filepath.h"
#include "utils/nsoption.h"
#include "content/urldb.h"
diff --git a/riscos/configure/con_home.c b/riscos/configure/con_home.c
index 4dec6ad..f8a13ce 100644
--- a/riscos/configure/con_home.c
+++ b/riscos/configure/con_home.c
@@ -17,6 +17,7 @@
*/
#include <stdbool.h>
+#include <stdlib.h>
#include "utils/messages.h"
#include "utils/utils.h"
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-179-ga94ae7a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/a94ae7a80a9d96c4aa889...
...commit http://git.netsurf-browser.org/netsurf.git/commit/a94ae7a80a9d96c4aa88995...
...tree http://git.netsurf-browser.org/netsurf.git/tree/a94ae7a80a9d96c4aa8899541...
The branch, master has been updated
via a94ae7a80a9d96c4aa88995412ea26feafa69f3b (commit)
via 67ded2a02a4f3f4d2a0ab156f3343dc93f4ba04c (commit)
via 335bbe4f52b9fdb74e377b83906eaab4456666cf (commit)
via 9ccf0cee9f4c070146a225fc633591436b1a88eb (commit)
via 010306e1ad48c66650bff68ec0e4e485f6518a65 (commit)
from fcadb1f6f884dac4191090175655602ed5117127 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=a94ae7a80a9d96c4aa8...
commit a94ae7a80a9d96c4aa88995412ea26feafa69f3b
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Allow translation messages to be compiled in as GTK resources
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index cc85162..fbc1ecb 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -70,6 +70,17 @@ CFLAGS += $(GTKCFLAGS)
LDFLAGS += -lm
# ---------------------------------------------------------------------------
+# Target setup
+# ---------------------------------------------------------------------------
+
+# The gtk binary target
+EXETARGET := nsgtk
+
+# The filter and target for split messages
+MESSAGES_FILTER=gtk
+MESSAGES_TARGET=gtk/res
+
+# ---------------------------------------------------------------------------
# Windows flag setup
# ---------------------------------------------------------------------------
@@ -84,6 +95,9 @@ endif
# builtin resource sources
S_RESOURCE :=
+# Path to GTK resources
+NSGTK_RESOURCES_DIR := gtk/res
+
# Glib prior to 2.32 does not have GResource handling.
#
# This uses pkg-config to check for the minimum required version for
@@ -106,16 +120,24 @@ NETSURF_FEATURE_GRESOURCE_ENABLED := yes
GLIB_COMPILE_RESOURCES := glib-compile-resources
CFLAGS += -DWITH_GRESOURCE
-S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
+NETSURF_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
+MESSAGES_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/messages.gresource.xml
-NSGTK_RESOURCES_DIR := gtk/res
-GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
+# generate the netsurf gresource source files
+$(OBJROOT)/netsurf_gresource.c: $(NETSURF_GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(NETSURF_GRESOURCE_XML))
+ $(VQ)echo "GRESORCE: $<"
+ $(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+
+S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
-# generate the gresource source file
-$(OBJROOT)/netsurf_gresource.c: $(GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(GRESOURCE_XML))
+# generate the messages gresource source file
+$(OBJROOT)/messages_gresource.c: $(MESSAGES_GRESOURCE_XML) $(addsuffix /Messages,$(addprefix $(MESSAGES_TARGET)/,$(MESSAGES_LANGUAGES)))
$(VQ)echo "GRESORCE: $<"
$(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+S_RESOURCE += $(OBJROOT)/messages_gresource.c
+
+
endif
endif
@@ -125,7 +147,9 @@ ifneq ($(NETSURF_FEATURE_GRESOURCE_ENABLED),yes)
CFLAGS += -DWITH_BUILTIN_PIXBUF
-GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
+GTK_IMAGE_favicon := favicon.png
+GTK_IMAGE_netsurf := netsurf.xpm
+GTK_IMAGE_menu_cursor := menu_cursor.png
# 1: input file
# 2: output file
@@ -143,7 +167,7 @@ $(2): $(1)
endef
-$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
+$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$(addprefix $(NSGTK_RESOURCES_DIR)/,$($(V))),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
endif
endif
@@ -167,13 +191,6 @@ S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c)
# are not yet available
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RESOURCE) $(S_GTK)
-# The gtk binary target
-EXETARGET := nsgtk
-
-# The filter and target for split messages
-MESSAGES_FILTER=gtk
-MESSAGES_TARGET=gtk/res
-
# ----------------------------------------------------------------------------
# Install target
# ----------------------------------------------------------------------------
diff --git a/gtk/gui.c b/gtk/gui.c
index 15348b9..3a41b60 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -1047,13 +1047,22 @@ static struct gui_browser_table nsgtk_browser_table = {
static nserror nsgtk_messages_init(char **respaths)
{
char *messages;
- nserror ret = NSERROR_NOT_FOUND;
+ nserror ret;
+ const uint8_t *data;
+ size_t data_size;
- /* Obtain path to messages */
- messages = filepath_find(respaths, "Messages");
- if (messages != NULL) {
- ret = messages_add_from_file(messages);
- free(messages);
+ ret = nsgtk_data_from_resname("Messages", &data, &data_size);
+ if (ret == NSERROR_OK) {
+ ret = messages_add_from_inline(data, data_size);
+ } else {
+ /* Obtain path to messages */
+ messages = filepath_find(respaths, "Messages");
+ if (messages != NULL) {
+ ret = messages_add_from_file(messages);
+ free(messages);
+ } else {
+ ret = NSERROR_NOT_FOUND;
+ }
}
return ret;
}
diff --git a/gtk/res/messages.gresource.xml b/gtk/res/messages.gresource.xml
new file mode 100644
index 0000000..684a108
--- /dev/null
+++ b/gtk/res/messages.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/netsurf">
+ <file>Messages</file>
+ <file>nl/Messages</file>
+ <file>de/Messages</file>
+ <file>fr/Messages</file>
+ <file>it/Messages</file>
+ </gresource>
+</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index 1998034..c9f08f4 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -45,8 +45,12 @@
#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
+const guint8 favicon_pixdata[] __attribute__ ((__aligned__ (4)));
+const guint8 netsurf_pixdata[] __attribute__ ((__aligned__ (4)));
#else
extern const guint8 menu_cursor_pixdata[];
+const guint8 favicon_pixdata[];
+const guint8 netsurf_pixdata[];
#endif
#endif
@@ -119,6 +123,7 @@ static struct nsgtk_resource_s direct_resource[] = {
RES_ENTRY("icons/hotlist-add.png"),
RES_ENTRY("icons/hotlist-rmv.png"),
RES_ENTRY("icons/search.png"),
+ RES_ENTRY("Messages"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
@@ -129,9 +134,8 @@ GdkCursor *nsgtk_create_menu_cursor(void)
GdkCursor *cursor = NULL;
GdkPixbuf *pixbuf;
nserror res;
- const char *resname = "menu_cursor.png";
- res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf);
+ res = nsgdk_pixbuf_new_from_resname("menu_cursor.png", &pixbuf);
if (res == NSERROR_OK) {
cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
pixbuf, 0, 3);
@@ -284,6 +288,20 @@ init_pixbuf_resource(char **respath, struct nsgtk_resource_s *resource)
LOG("Found builtin for %s", resource->name);
return NSERROR_OK;
}
+
+ if (strncmp(resource->name, "netsurf.xpm", resource->len) == 0) {
+ resource->path = (char *)&netsurf_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
+
+ if (strncmp(resource->name, "favicon.png", resource->len) == 0) {
+ resource->path = (char *)&favicon_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
#endif
return init_resource(respath, resource);
}
diff --git a/utils/messages.c b/utils/messages.c
index 91b41cb..d652fef 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -45,6 +45,41 @@
static struct hash_table *messages_hash = NULL;
/**
+ * process a line of input.
+ */
+static nserror
+message_process_line(struct hash_table *hash, uint8_t *ln, int lnlen)
+{
+ uint8_t *value;
+ uint8_t *colon;
+
+ /* empty or comment lines */
+ if (ln[0] == 0 || ln[0] == '#') {
+ return NSERROR_OK;
+ }
+
+ /* find first colon as key/value separator */
+ for (colon = ln; colon < (ln + lnlen); colon++) {
+ if (*colon == ':') {
+ break;
+ }
+ }
+ if (colon == (ln + lnlen)) {
+ /* no colon found */
+ return NSERROR_INVALID;
+ }
+
+ *colon = 0; /* terminate key */
+ value = colon + 1;
+
+ if (hash_add(hash, (char *)ln, (char *)value) == false) {
+ LOG("Unable to add %s:%s to hash table", ln, value);
+ return NSERROR_INVALID;
+ }
+ return NSERROR_OK;
+}
+
+/**
* Read keys and values from messages file.
*
* \param path pathname of messages file
@@ -147,19 +182,89 @@ nserror messages_add_from_file(const char *path)
nserror err;
if (path == NULL) {
- err = NSERROR_BAD_PARAMETER;
- } else {
- LOG("Loading Messages from '%s'", path);
-
- err = messages_load_ctx(path, &messages_hash);
+ return NSERROR_BAD_PARAMETER;
}
+ LOG("Loading Messages from '%s'", path);
+
+ err = messages_load_ctx(path, &messages_hash);
+
+
return err;
}
+
/* exported interface documented in messages.h */
-nserror messages_add_from_inline(const char *data)
+nserror messages_add_from_inline(const uint8_t *data, size_t data_size)
{
+ z_stream strm;
+ int ret;
+ uint8_t s[512]; /* line buffer */
+ size_t used = 0; /* number of bytes in buffer in use */
+ uint8_t *nl;
+
+ /* ensure the hash table is initialised */
+ if (messages_hash == NULL) {
+ messages_hash = hash_create(HASH_SIZE);
+ }
+ if (messages_hash == NULL) {
+ LOG("Unable to create hash table");
+ return NSERROR_NOMEM;
+ }
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+
+ strm.next_in = (uint8_t *)data;
+ strm.avail_in = data_size;
+
+ ret = inflateInit2(&strm, 32 + MAX_WBITS);
+ if (ret != Z_OK) {
+ LOG("inflateInit returned %d", ret);
+ return NSERROR_INVALID;
+ }
+
+ do {
+ strm.next_out = s + used;
+ strm.avail_out = sizeof(s) - used;
+
+ ret = inflate(&strm, Z_NO_FLUSH);
+ if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
+ break;
+ }
+
+ used = sizeof(s) - strm.avail_out;
+ while (used > 0) {
+ /* find nl */
+ for (nl = &s[0]; nl < &s[used]; nl++) {
+ if (*nl == '\n') {
+ break;
+ }
+ }
+ if (nl == &s[used]) {
+ /* no nl found */
+ break;
+ }
+ /* found newline */
+ *nl = 0; /* null terminate line */
+ message_process_line(messages_hash, &s[0], nl - &s[0]);
+ memmove(&s[0], nl + 1, used - ((nl + 1) - &s[0]) );
+ used -= ((nl +1) - &s[0]);
+ }
+ if (used == sizeof(s)) {
+ /* entire buffer used and no newline */
+ LOG("Overlength line");
+ used = 0;
+ }
+ } while (ret != Z_STREAM_END);
+
+ inflateEnd(&strm);
+
+ if (ret != Z_STREAM_END) {
+ LOG("inflate returned %d", ret);
+ return NSERROR_INVALID;
+ }
return NSERROR_OK;
}
@@ -181,7 +286,7 @@ char *messages_get_buff(const char *key, ...)
if (buff == NULL) {
LOG("malloc failed");
- warn_user("NoMemory", 0);
+ warn_user("NoMemory", 0);
} else {
va_start(ap, key);
vsnprintf(buff, buff_len + 1, msg_fmt, ap);
@@ -268,7 +373,7 @@ const char *messages_get_errorcode(nserror code)
return messages_get_ctx("ParsingFail", messages_hash);
case NSERROR_CSS:
- /* CSS call returned error */
+ /* CSS call returned error */
return messages_get_ctx("CSSGeneric", messages_hash);
case NSERROR_CSS_BASE:
diff --git a/utils/messages.h b/utils/messages.h
index 4d04cd5..ac1ea98 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -33,6 +33,8 @@
#ifndef _NETSURF_UTILS_MESSAGES_H_
#define _NETSURF_UTILS_MESSAGES_H_
+#include <stdint.h>
+
#include "utils/errors.h"
/**
@@ -57,7 +59,7 @@ nserror messages_add_from_file(const char *path);
* \param data The inline message data.
* \return NSERROR_OK on success or error code on faliure.
*/
-nserror messages_add_from_inline(const char *data);
+nserror messages_add_from_inline(const uint8_t *data, size_t data_size);
/**
* Fast lookup of a message by key from the standard Messages hash.
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=67ded2a02a4f3f4d2a0...
commit 67ded2a02a4f3f4d2a0ab156f3343dc93f4ba04c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
This moves message loading out of netsurf_init into each frontend
The translated message loading is dependant on configuration of
resource location in each frontend, additionally they should have the
ability to deal with errors in this loading in a implementation
specific manner.
This also extends the message loading API to be capable of loading
from an inline memory buffer instead of from a file.
diff --git a/amiga/gui.c b/amiga/gui.c
index f0132f3..5c671e1 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5499,7 +5499,9 @@ int main(int argc, char** argv)
return RETURN_FAIL;
}
- ret = netsurf_init(messages, current_user_cache);
+ ret = messages_add_from_file(messages);
+
+ ret = netsurf_init(current_user_cache);
if (ret != NSERROR_OK) {
ami_misc_fatal_error("NetSurf failed to initialise");
return RETURN_FAIL;
diff --git a/amiga/theme.c b/amiga/theme.c
index 4d6107a..0b77dc5 100644
--- a/amiga/theme.c
+++ b/amiga/theme.c
@@ -152,7 +152,7 @@ void ami_theme_init(void)
if(lock)
{
UnLock(lock);
- messages_load(themefile);
+ messages_add_from_file(themefile);
}
}
diff --git a/atari/gui.c b/atari/gui.c
index 23d3142..265ae5a 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -1169,9 +1169,11 @@ int main(int argc, char** argv)
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
+ ret = messages_add_from_file(messages);
+
/* common initialisation */
LOG("Initialising core...");
- ret = netsurf_init(messages, store);
+ ret = netsurf_init(store);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
diff --git a/beos/gui.cpp b/beos/gui.cpp
index 36cc922..5eabfa8 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -1035,7 +1035,9 @@ int main(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
- ret = netsurf_init(messages.Path(), NULL);
+ ret = messages_add_from_file(messages.Path());
+
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
@@ -1096,7 +1098,9 @@ int gui_init_replicant(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
- ret = netsurf_init(messages.Path(), NULL);
+ ret = messages_add_from_file(messages.Path());
+
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
// FIXME: must not die when in replicant!
die("NetSurf failed to initialise");
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index ac26c9c..d9c711a 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -248,8 +248,10 @@ int main( int argc, char **argv )
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
+ error = messages_add_from_file(messages);
+
/* common initialisation */
- error = netsurf_init(messages, NULL);
+ error = netsurf_init(NULL);
if (error != NSERROR_OK) {
die("NetSurf failed to initialise");
}
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index bf8ff86..0fd7b7b 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -122,7 +122,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query,
}
/* exported interface documented in desktop/netsurf.h */
-nserror netsurf_init(const char *messages, const char *store_path)
+nserror netsurf_init(const char *store_path)
{
nserror ret;
struct hlcache_parameters hlcache_parameters = {
@@ -151,8 +151,6 @@ nserror netsurf_init(const char *messages, const char *store_path)
signal(SIGPIPE, SIG_IGN);
#endif
- messages_load(messages);
-
/* corestrings init */
ret = corestrings_init();
if (ret != NSERROR_OK)
diff --git a/desktop/netsurf.h b/desktop/netsurf.h
index 4f37219..ee6e53a 100644
--- a/desktop/netsurf.h
+++ b/desktop/netsurf.h
@@ -40,11 +40,10 @@ nserror netsurf_register(struct netsurf_table *table);
/**
* Initialise netsurf core.
*
- * @param messages path to translation mesage file.
* @param store_path path to persistant storage.
* @return NSERROR_OK on success or error code on faliure.
*/
-nserror netsurf_init(const char *messages, const char *store_path);
+nserror netsurf_init(const char *store_path);
/**
* Finalise NetSurf core
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 1c60bee..dcf4873 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -2107,9 +2107,12 @@ main(int argc, char** argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
- /* common initialisation */
+ /* message init */
messages = filepath_find(respaths, "Messages");
- ret = netsurf_init(messages, NULL);
+ ret = messages_add_from_file(messages);
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
diff --git a/gtk/gui.c b/gtk/gui.c
index a5c2fb0..15348b9 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -508,7 +508,7 @@ void warn_user(const char *warning, const char *detail)
static GtkWindow *nsgtk_warning_window;
GtkLabel *WarningLabel;
- LOG("%s %s", warning, detail ? detail : "");
+ LOG("%s %s", warning, detail ? detail : "");
fflush(stdout);
nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(warning_builder, "wndWarning"));
@@ -553,13 +553,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
if (op[0] == '\0') {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
- "Owner password must be at least 1 character long:");
+ "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(password_builder,
"labelInfo")),
- "User and owner passwords must be different:");
+ "User and owner passwords must be different:");
free(op);
free(up);
} else if (!strcmp(op, op1) && !strcmp(up, up1)) {
@@ -1043,12 +1043,26 @@ static struct gui_browser_table nsgtk_browser_table = {
.pdf_password = nsgtk_pdf_password,
};
+
+static nserror nsgtk_messages_init(char **respaths)
+{
+ char *messages;
+ nserror ret = NSERROR_NOT_FOUND;
+
+ /* Obtain path to messages */
+ messages = filepath_find(respaths, "Messages");
+ if (messages != NULL) {
+ ret = messages_add_from_file(messages);
+ free(messages);
+ }
+ return ret;
+}
+
/**
* Main entry point from OS.
*/
int main(int argc, char** argv)
{
- char *messages;
char *cache_home = NULL;
nserror ret;
struct netsurf_table nsgtk_table = {
@@ -1110,8 +1124,14 @@ int main(int argc, char** argv)
return 1;
}
- /* Obtain path to messages */
- messages = filepath_find(respaths, "Messages");
+ /* Initialise translated messages */
+ ret = nsgtk_messages_init(respaths);
+ if (ret != NSERROR_OK) {
+ fprintf(stderr, "Unable to load translated messages (%s)\n",
+ messages_get_errorcode(ret));
+ LOG("Unable to load translated messages");
+ /** \todo decide if message load faliure should be fatal */
+ }
/* Locate the correct user cache directory path */
ret = get_cache_home(&cache_home);
@@ -1124,8 +1144,7 @@ int main(int argc, char** argv)
}
/* core initialisation */
- ret = netsurf_init(messages, cache_home);
- free(messages);
+ ret = netsurf_init(cache_home);
free(cache_home);
if (ret != NSERROR_OK) {
fprintf(stderr, "NetSurf core failed to initialise (%s)\n",
diff --git a/monkey/main.c b/monkey/main.c
index 81406bc..2b1a3bc 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -172,9 +172,14 @@ main(int argc, char **argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
- /* common initialisation */
messages = filepath_find(respaths, "Messages");
- ret = netsurf_init(messages, NULL);
+ ret = messages_add_from_file(messages);
+ if (ret != NSERROR_OK) {
+ LOG("Messages failed to load");
+ }
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
diff --git a/riscos/gui.c b/riscos/gui.c
index 3a47d08..2dd9433 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -2481,11 +2481,14 @@ int main(int argc, char** argv)
die("Failed to locate Messages resource.");
}
+ /* initialise messages */
+ messages_add_from_file(path);
+
/* obtain cache path */
cachepath = get_cachepath();
/* common initialisation */
- ret = netsurf_init(path, cachepath);
+ ret = netsurf_init(cachepath);
free(cachepath);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise core");
@@ -2496,7 +2499,7 @@ int main(int argc, char** argv)
sprite_init();
/* Load some extra RISC OS specific Messages */
- messages_load("NetSurf:Resources.LangNames");
+ messages_add_from_file("NetSurf:Resources.LangNames");
ret = gui_init(argc, argv);
if (ret != NSERROR_OK) {
diff --git a/utils/messages.c b/utils/messages.c
index 78b9a79..91b41cb 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -142,7 +142,7 @@ messages_get_ctx(const char *key, struct hash_table *ctx)
}
/* exported interface documented in messages.h */
-nserror messages_load(const char *path)
+nserror messages_add_from_file(const char *path)
{
nserror err;
@@ -158,6 +158,12 @@ nserror messages_load(const char *path)
}
/* exported interface documented in messages.h */
+nserror messages_add_from_inline(const char *data)
+{
+ return NSERROR_OK;
+}
+
+/* exported interface documented in messages.h */
char *messages_get_buff(const char *key, ...)
{
const char *msg_fmt;
diff --git a/utils/messages.h b/utils/messages.h
index c9946e6..4d04cd5 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -38,13 +38,26 @@
/**
* Read keys and values from messages file into the standard Messages hash.
*
- * The messages are merged with any previously loaded messages. Any keys which
- * are present already are replaced with the new value.
+ * The messages are merged with any previously loaded messages. Any
+ * keys which are present already are replaced with the new value. The
+ * file may be gzip compressed.
*
* \param path pathname of messages file.
* \return NSERROR_OK on success or error code on faliure.
*/
-nserror messages_load(const char *path);
+nserror messages_add_from_file(const char *path);
+
+/**
+ * Read keys and values from inline message data into the standard Messages hash.
+ *
+ * The messages are merged with any previously loaded messages. Any
+ * keys which are present already are replaced with the new value. The
+ * data may be gzip compressed.
+ *
+ * \param data The inline message data.
+ * \return NSERROR_OK on success or error code on faliure.
+ */
+nserror messages_add_from_inline(const char *data);
/**
* Fast lookup of a message by key from the standard Messages hash.
diff --git a/windows/main.c b/windows/main.c
index 1997c85..b9ef44a 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -183,10 +183,13 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
nsoption_read(options_file_location, NULL);
nsoption_commandline(&argc, argv, NULL);
- /* common initialisation */
+ /* message init */
messages = filepath_find(respaths, "messages");
- ret = netsurf_init(messages, NULL);
+ messages_add_from_file(messages);
free(messages);
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
free(options_file_location);
LOG("NetSurf failed to initialise");
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=335bbe4f52b9fdb74e3...
commit 335bbe4f52b9fdb74e377b83906eaab4456666cf
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Move the browser identification and machine info logging.
Previously this information was logged when netsurf_init was called
which might be many lines out output into the log.
It is useful to have this information at the beginning of the log to
make it easily found. In addition it makes netsurf_init less complex.
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 5702ebe..bf8ff86 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -26,7 +26,6 @@
#include <libwapcaplet/libwapcaplet.h>
#include "utils/config.h"
-#include "utils/utsname.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
@@ -45,7 +44,6 @@
#include "render/html.h"
#include "render/textplain.h"
-#include "desktop/version.h"
#include "desktop/browser.h"
#include "desktop/system_colour.h"
#include "desktop/searchweb.h"
@@ -127,7 +125,6 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query,
nserror netsurf_init(const char *messages, const char *store_path)
{
nserror ret;
- struct utsname utsname;
struct hlcache_parameters hlcache_parameters = {
.bg_clean_time = HL_CACHE_CLEAN_TIME,
.llcache = {
@@ -154,12 +151,6 @@ nserror netsurf_init(const char *messages, const char *store_path)
signal(SIGPIPE, SIG_IGN);
#endif
- LOG("NetSurf version '%s'", netsurf_version);
- if (uname(&utsname) < 0)
- LOG("Failed to extract machine information");
- else
- LOG("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, ""machine <%s>", utsname.sysname, utsname.nodename, utsname.release, utsname.version, utsname.machine);
-
messages_load(messages);
/* corestrings init */
diff --git a/utils/log.c b/utils/log.c
index d67ed76..cc3f7a8 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -24,6 +24,10 @@
#include <stdio.h>
#include <sys/time.h>
+#include "utils/config.h"
+#include "utils/utsname.h"
+#include "desktop/version.h"
+
#include "utils/log.h"
/** flag to enable verbose logging */
@@ -34,6 +38,7 @@ static FILE *logfile;
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
{
+ struct utsname utsname;
nserror ret = NSERROR_OK;
if (((*pargc) > 1) &&
@@ -88,6 +93,21 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
verbose_log = false;
}
+ /* sucessfull logging initialisation so log system info */
+ if (ret == NSERROR_OK) {
+ LOG("NetSurf version '%s'", netsurf_version);
+ if (uname(&utsname) < 0) {
+ LOG("Failed to extract machine information");
+ } else {
+ LOG("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, machine <%s>",
+ utsname.sysname,
+ utsname.nodename,
+ utsname.release,
+ utsname.version,
+ utsname.machine);
+ }
+ }
+
return ret;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=9ccf0cee9f4c070146a...
commit 9ccf0cee9f4c070146a225fc633591436b1a88eb
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Change GTK resource path to use the users netsurf directory
This changes the path used to find resources from containg a hard
coded ${HOME}/.netsurf to using the computed path to the users netsurf
config.
diff --git a/gtk/gui.c b/gtk/gui.c
index 4986f42..a5c2fb0 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -107,12 +107,41 @@ static void die(const char * const error)
* searched for.
*/
static char **
-nsgtk_init_resource_path(const char *resource_path)
+nsgtk_init_resource_path(const char *config_home)
{
+ char *resource_path;
+ int resource_path_len;
const gchar * const *langv;
char **pathv; /* resource path string vector */
char **respath; /* resource paths vector */
+ if (config_home != NULL) {
+ resource_path_len = snprintf(NULL, 0,
+ "%s:${NETSURFRES}:%s:./gtk/res",
+ config_home,
+ GTK_RESPATH);
+ resource_path = malloc(resource_path_len + 1);
+ if (resource_path == NULL) {
+ return NULL;
+ }
+ snprintf(resource_path, resource_path_len + 1,
+ "%s:${NETSURFRES}:%s:./gtk/res",
+ config_home,
+ GTK_RESPATH);
+ } else {
+ resource_path_len = snprintf(NULL, 0,
+ "${NETSURFRES}:%s:./gtk/res",
+ GTK_RESPATH);
+ resource_path = malloc(resource_path_len + 1);
+ if (resource_path == NULL) {
+ return NULL;
+ }
+ snprintf(resource_path,
+ resource_path_len + 1,
+ "${NETSURFRES}:%s:./gtk/res",
+ GTK_RESPATH);
+ }
+
pathv = filepath_path_to_strvec(resource_path);
langv = g_get_language_names();
@@ -121,6 +150,8 @@ nsgtk_init_resource_path(const char *resource_path)
filepath_free_strvec(pathv);
+ free(resource_path);
+
return respath;
}
@@ -1057,7 +1088,11 @@ int main(int argc, char** argv)
nslog_init(nslog_stream_configure, &argc, argv);
/* build the common resource path list */
- respaths = nsgtk_init_resource_path("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+ respaths = nsgtk_init_resource_path(nsgtk_config_home);
+ if (respaths == NULL) {
+ fprintf(stderr, "Unable to locate resources\n");
+ return 1;
+ }
/* initialise the gtk resource handling */
ret = nsgtk_init_resources(respaths);
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=010306e1ad48c66650b...
commit 010306e1ad48c66650bff68ec0e4e485f6518a65
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Clean up doxygen errors in image handlers.
diff --git a/image/bmp.c b/image/bmp.c
index dfa573f..7e992ae 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -34,6 +34,7 @@
#include "image/bitmap.h"
#include "image/bmp.h"
+/** bmp context. */
typedef struct nsbmp_content {
struct content base;
@@ -45,10 +46,10 @@ typedef struct nsbmp_content {
/**
* Callback for libnsbmp; forwards the call to bitmap_create()
*
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \param state a flag word indicating the initial state
- * \return an opaque struct bitmap, or NULL on memory exhaustion
+ * \param width width of image in pixels
+ * \param height width of image in pixels
+ * \param bmp_state A flag word indicating the initial state
+ * \return An opaque struct bitmap, or NULL on memory exhaustion
*/
static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
{
diff --git a/image/gif.c b/image/gif.c
index 871b1cc..3f5f630 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -305,7 +305,8 @@ static bool nsgif_convert(struct content *c)
/**
* Updates the GIF bitmap to display the current frame
*
- * \param c the content to update
+ * \param gif The gif context to update.
+ * \return GIF_OK on success else apropriate error code.
*/
static gif_result nsgif_get_frame(nsgif_content *gif)
{
@@ -317,10 +318,11 @@ static gif_result nsgif_get_frame(nsgif_content *gif)
current_frame = 0;
}
- if (current_frame < gif->gif->decoded_frame)
+ if (current_frame < gif->gif->decoded_frame) {
previous_frame = 0;
- else
+ } else {
previous_frame = gif->gif->decoded_frame + 1;
+ }
for (frame = previous_frame; frame <= current_frame; frame++) {
res = gif_decode_frame(gif->gif, frame);
diff --git a/image/ico.c b/image/ico.c
index 9cb650b..cf74592 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -45,7 +45,7 @@ typedef struct nsico_content {
*
* \param width width of image in pixels
* \param height width of image in pixels
- * \param state a flag word indicating the initial state
+ * \param bmp_state A flag word indicating the initial state
* \return an opaque struct bitmap, or NULL on memory exhaustion
*/
static void *nsico_bitmap_create(int width, int height, unsigned int bmp_state)
-----------------------------------------------------------------------
Summary of changes:
amiga/gui.c | 4 +-
amiga/theme.c | 2 +-
atari/gui.c | 4 +-
beos/gui.cpp | 8 ++-
cocoa/NetsurfApp.m | 4 +-
desktop/netsurf.c | 13 +---
desktop/netsurf.h | 3 +-
framebuffer/gui.c | 7 ++-
gtk/Makefile.target | 45 +++++++++-----
gtk/gui.c | 83 ++++++++++++++++++++++----
gtk/res/messages.gresource.xml | 10 ++++
gtk/resources.c | 22 ++++++-
image/bmp.c | 9 +--
image/gif.c | 8 ++-
image/ico.c | 2 +-
monkey/main.c | 9 ++-
riscos/gui.c | 7 ++-
utils/log.c | 20 +++++++
utils/messages.c | 127 +++++++++++++++++++++++++++++++++++++---
utils/messages.h | 21 ++++++-
windows/main.c | 7 ++-
21 files changed, 342 insertions(+), 73 deletions(-)
create mode 100644 gtk/res/messages.gresource.xml
diff --git a/amiga/gui.c b/amiga/gui.c
index f0132f3..5c671e1 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5499,7 +5499,9 @@ int main(int argc, char** argv)
return RETURN_FAIL;
}
- ret = netsurf_init(messages, current_user_cache);
+ ret = messages_add_from_file(messages);
+
+ ret = netsurf_init(current_user_cache);
if (ret != NSERROR_OK) {
ami_misc_fatal_error("NetSurf failed to initialise");
return RETURN_FAIL;
diff --git a/amiga/theme.c b/amiga/theme.c
index 4d6107a..0b77dc5 100644
--- a/amiga/theme.c
+++ b/amiga/theme.c
@@ -152,7 +152,7 @@ void ami_theme_init(void)
if(lock)
{
UnLock(lock);
- messages_load(themefile);
+ messages_add_from_file(themefile);
}
}
diff --git a/atari/gui.c b/atari/gui.c
index 23d3142..265ae5a 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -1169,9 +1169,11 @@ int main(int argc, char** argv)
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
+ ret = messages_add_from_file(messages);
+
/* common initialisation */
LOG("Initialising core...");
- ret = netsurf_init(messages, store);
+ ret = netsurf_init(store);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
diff --git a/beos/gui.cpp b/beos/gui.cpp
index 36cc922..5eabfa8 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -1035,7 +1035,9 @@ int main(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
- ret = netsurf_init(messages.Path(), NULL);
+ ret = messages_add_from_file(messages.Path());
+
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
@@ -1096,7 +1098,9 @@ int gui_init_replicant(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
- ret = netsurf_init(messages.Path(), NULL);
+ ret = messages_add_from_file(messages.Path());
+
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
// FIXME: must not die when in replicant!
die("NetSurf failed to initialise");
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index ac26c9c..d9c711a 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -248,8 +248,10 @@ int main( int argc, char **argv )
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
+ error = messages_add_from_file(messages);
+
/* common initialisation */
- error = netsurf_init(messages, NULL);
+ error = netsurf_init(NULL);
if (error != NSERROR_OK) {
die("NetSurf failed to initialise");
}
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 5702ebe..0fd7b7b 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -26,7 +26,6 @@
#include <libwapcaplet/libwapcaplet.h>
#include "utils/config.h"
-#include "utils/utsname.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
@@ -45,7 +44,6 @@
#include "render/html.h"
#include "render/textplain.h"
-#include "desktop/version.h"
#include "desktop/browser.h"
#include "desktop/system_colour.h"
#include "desktop/searchweb.h"
@@ -124,10 +122,9 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query,
}
/* exported interface documented in desktop/netsurf.h */
-nserror netsurf_init(const char *messages, const char *store_path)
+nserror netsurf_init(const char *store_path)
{
nserror ret;
- struct utsname utsname;
struct hlcache_parameters hlcache_parameters = {
.bg_clean_time = HL_CACHE_CLEAN_TIME,
.llcache = {
@@ -154,14 +151,6 @@ nserror netsurf_init(const char *messages, const char *store_path)
signal(SIGPIPE, SIG_IGN);
#endif
- LOG("NetSurf version '%s'", netsurf_version);
- if (uname(&utsname) < 0)
- LOG("Failed to extract machine information");
- else
- LOG("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, ""machine <%s>", utsname.sysname, utsname.nodename, utsname.release, utsname.version, utsname.machine);
-
- messages_load(messages);
-
/* corestrings init */
ret = corestrings_init();
if (ret != NSERROR_OK)
diff --git a/desktop/netsurf.h b/desktop/netsurf.h
index 4f37219..ee6e53a 100644
--- a/desktop/netsurf.h
+++ b/desktop/netsurf.h
@@ -40,11 +40,10 @@ nserror netsurf_register(struct netsurf_table *table);
/**
* Initialise netsurf core.
*
- * @param messages path to translation mesage file.
* @param store_path path to persistant storage.
* @return NSERROR_OK on success or error code on faliure.
*/
-nserror netsurf_init(const char *messages, const char *store_path);
+nserror netsurf_init(const char *store_path);
/**
* Finalise NetSurf core
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 1c60bee..dcf4873 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -2107,9 +2107,12 @@ main(int argc, char** argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
- /* common initialisation */
+ /* message init */
messages = filepath_find(respaths, "Messages");
- ret = netsurf_init(messages, NULL);
+ ret = messages_add_from_file(messages);
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index cc85162..fbc1ecb 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -70,6 +70,17 @@ CFLAGS += $(GTKCFLAGS)
LDFLAGS += -lm
# ---------------------------------------------------------------------------
+# Target setup
+# ---------------------------------------------------------------------------
+
+# The gtk binary target
+EXETARGET := nsgtk
+
+# The filter and target for split messages
+MESSAGES_FILTER=gtk
+MESSAGES_TARGET=gtk/res
+
+# ---------------------------------------------------------------------------
# Windows flag setup
# ---------------------------------------------------------------------------
@@ -84,6 +95,9 @@ endif
# builtin resource sources
S_RESOURCE :=
+# Path to GTK resources
+NSGTK_RESOURCES_DIR := gtk/res
+
# Glib prior to 2.32 does not have GResource handling.
#
# This uses pkg-config to check for the minimum required version for
@@ -106,16 +120,24 @@ NETSURF_FEATURE_GRESOURCE_ENABLED := yes
GLIB_COMPILE_RESOURCES := glib-compile-resources
CFLAGS += -DWITH_GRESOURCE
-S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
+NETSURF_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
+MESSAGES_GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/messages.gresource.xml
-NSGTK_RESOURCES_DIR := gtk/res
-GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
+# generate the netsurf gresource source files
+$(OBJROOT)/netsurf_gresource.c: $(NETSURF_GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(NETSURF_GRESOURCE_XML))
+ $(VQ)echo "GRESORCE: $<"
+ $(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+
+S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
-# generate the gresource source file
-$(OBJROOT)/netsurf_gresource.c: $(GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(GRESOURCE_XML))
+# generate the messages gresource source file
+$(OBJROOT)/messages_gresource.c: $(MESSAGES_GRESOURCE_XML) $(addsuffix /Messages,$(addprefix $(MESSAGES_TARGET)/,$(MESSAGES_LANGUAGES)))
$(VQ)echo "GRESORCE: $<"
$(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+S_RESOURCE += $(OBJROOT)/messages_gresource.c
+
+
endif
endif
@@ -125,7 +147,9 @@ ifneq ($(NETSURF_FEATURE_GRESOURCE_ENABLED),yes)
CFLAGS += -DWITH_BUILTIN_PIXBUF
-GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
+GTK_IMAGE_favicon := favicon.png
+GTK_IMAGE_netsurf := netsurf.xpm
+GTK_IMAGE_menu_cursor := menu_cursor.png
# 1: input file
# 2: output file
@@ -143,7 +167,7 @@ $(2): $(1)
endef
-$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
+$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$(addprefix $(NSGTK_RESOURCES_DIR)/,$($(V))),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
endif
endif
@@ -167,13 +191,6 @@ S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c)
# are not yet available
SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RESOURCE) $(S_GTK)
-# The gtk binary target
-EXETARGET := nsgtk
-
-# The filter and target for split messages
-MESSAGES_FILTER=gtk
-MESSAGES_TARGET=gtk/res
-
# ----------------------------------------------------------------------------
# Install target
# ----------------------------------------------------------------------------
diff --git a/gtk/gui.c b/gtk/gui.c
index 4986f42..3a41b60 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -107,12 +107,41 @@ static void die(const char * const error)
* searched for.
*/
static char **
-nsgtk_init_resource_path(const char *resource_path)
+nsgtk_init_resource_path(const char *config_home)
{
+ char *resource_path;
+ int resource_path_len;
const gchar * const *langv;
char **pathv; /* resource path string vector */
char **respath; /* resource paths vector */
+ if (config_home != NULL) {
+ resource_path_len = snprintf(NULL, 0,
+ "%s:${NETSURFRES}:%s:./gtk/res",
+ config_home,
+ GTK_RESPATH);
+ resource_path = malloc(resource_path_len + 1);
+ if (resource_path == NULL) {
+ return NULL;
+ }
+ snprintf(resource_path, resource_path_len + 1,
+ "%s:${NETSURFRES}:%s:./gtk/res",
+ config_home,
+ GTK_RESPATH);
+ } else {
+ resource_path_len = snprintf(NULL, 0,
+ "${NETSURFRES}:%s:./gtk/res",
+ GTK_RESPATH);
+ resource_path = malloc(resource_path_len + 1);
+ if (resource_path == NULL) {
+ return NULL;
+ }
+ snprintf(resource_path,
+ resource_path_len + 1,
+ "${NETSURFRES}:%s:./gtk/res",
+ GTK_RESPATH);
+ }
+
pathv = filepath_path_to_strvec(resource_path);
langv = g_get_language_names();
@@ -121,6 +150,8 @@ nsgtk_init_resource_path(const char *resource_path)
filepath_free_strvec(pathv);
+ free(resource_path);
+
return respath;
}
@@ -477,7 +508,7 @@ void warn_user(const char *warning, const char *detail)
static GtkWindow *nsgtk_warning_window;
GtkLabel *WarningLabel;
- LOG("%s %s", warning, detail ? detail : "");
+ LOG("%s %s", warning, detail ? detail : "");
fflush(stdout);
nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(warning_builder, "wndWarning"));
@@ -522,13 +553,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data)
if (op[0] == '\0') {
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(password_builder,
"labelInfo")),
- "Owner password must be at least 1 character long:");
+ "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(password_builder,
"labelInfo")),
- "User and owner passwords must be different:");
+ "User and owner passwords must be different:");
free(op);
free(up);
} else if (!strcmp(op, op1) && !strcmp(up, up1)) {
@@ -1012,12 +1043,35 @@ static struct gui_browser_table nsgtk_browser_table = {
.pdf_password = nsgtk_pdf_password,
};
+
+static nserror nsgtk_messages_init(char **respaths)
+{
+ char *messages;
+ nserror ret;
+ const uint8_t *data;
+ size_t data_size;
+
+ ret = nsgtk_data_from_resname("Messages", &data, &data_size);
+ if (ret == NSERROR_OK) {
+ ret = messages_add_from_inline(data, data_size);
+ } else {
+ /* Obtain path to messages */
+ messages = filepath_find(respaths, "Messages");
+ if (messages != NULL) {
+ ret = messages_add_from_file(messages);
+ free(messages);
+ } else {
+ ret = NSERROR_NOT_FOUND;
+ }
+ }
+ return ret;
+}
+
/**
* Main entry point from OS.
*/
int main(int argc, char** argv)
{
- char *messages;
char *cache_home = NULL;
nserror ret;
struct netsurf_table nsgtk_table = {
@@ -1057,7 +1111,11 @@ int main(int argc, char** argv)
nslog_init(nslog_stream_configure, &argc, argv);
/* build the common resource path list */
- respaths = nsgtk_init_resource_path("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+ respaths = nsgtk_init_resource_path(nsgtk_config_home);
+ if (respaths == NULL) {
+ fprintf(stderr, "Unable to locate resources\n");
+ return 1;
+ }
/* initialise the gtk resource handling */
ret = nsgtk_init_resources(respaths);
@@ -1075,8 +1133,14 @@ int main(int argc, char** argv)
return 1;
}
- /* Obtain path to messages */
- messages = filepath_find(respaths, "Messages");
+ /* Initialise translated messages */
+ ret = nsgtk_messages_init(respaths);
+ if (ret != NSERROR_OK) {
+ fprintf(stderr, "Unable to load translated messages (%s)\n",
+ messages_get_errorcode(ret));
+ LOG("Unable to load translated messages");
+ /** \todo decide if message load faliure should be fatal */
+ }
/* Locate the correct user cache directory path */
ret = get_cache_home(&cache_home);
@@ -1089,8 +1153,7 @@ int main(int argc, char** argv)
}
/* core initialisation */
- ret = netsurf_init(messages, cache_home);
- free(messages);
+ ret = netsurf_init(cache_home);
free(cache_home);
if (ret != NSERROR_OK) {
fprintf(stderr, "NetSurf core failed to initialise (%s)\n",
diff --git a/gtk/res/messages.gresource.xml b/gtk/res/messages.gresource.xml
new file mode 100644
index 0000000..684a108
--- /dev/null
+++ b/gtk/res/messages.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/netsurf">
+ <file>Messages</file>
+ <file>nl/Messages</file>
+ <file>de/Messages</file>
+ <file>fr/Messages</file>
+ <file>it/Messages</file>
+ </gresource>
+</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index 1998034..c9f08f4 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -45,8 +45,12 @@
#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
+const guint8 favicon_pixdata[] __attribute__ ((__aligned__ (4)));
+const guint8 netsurf_pixdata[] __attribute__ ((__aligned__ (4)));
#else
extern const guint8 menu_cursor_pixdata[];
+const guint8 favicon_pixdata[];
+const guint8 netsurf_pixdata[];
#endif
#endif
@@ -119,6 +123,7 @@ static struct nsgtk_resource_s direct_resource[] = {
RES_ENTRY("icons/hotlist-add.png"),
RES_ENTRY("icons/hotlist-rmv.png"),
RES_ENTRY("icons/search.png"),
+ RES_ENTRY("Messages"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
@@ -129,9 +134,8 @@ GdkCursor *nsgtk_create_menu_cursor(void)
GdkCursor *cursor = NULL;
GdkPixbuf *pixbuf;
nserror res;
- const char *resname = "menu_cursor.png";
- res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf);
+ res = nsgdk_pixbuf_new_from_resname("menu_cursor.png", &pixbuf);
if (res == NSERROR_OK) {
cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
pixbuf, 0, 3);
@@ -284,6 +288,20 @@ init_pixbuf_resource(char **respath, struct nsgtk_resource_s *resource)
LOG("Found builtin for %s", resource->name);
return NSERROR_OK;
}
+
+ if (strncmp(resource->name, "netsurf.xpm", resource->len) == 0) {
+ resource->path = (char *)&netsurf_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
+
+ if (strncmp(resource->name, "favicon.png", resource->len) == 0) {
+ resource->path = (char *)&favicon_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
#endif
return init_resource(respath, resource);
}
diff --git a/image/bmp.c b/image/bmp.c
index dfa573f..7e992ae 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -34,6 +34,7 @@
#include "image/bitmap.h"
#include "image/bmp.h"
+/** bmp context. */
typedef struct nsbmp_content {
struct content base;
@@ -45,10 +46,10 @@ typedef struct nsbmp_content {
/**
* Callback for libnsbmp; forwards the call to bitmap_create()
*
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \param state a flag word indicating the initial state
- * \return an opaque struct bitmap, or NULL on memory exhaustion
+ * \param width width of image in pixels
+ * \param height width of image in pixels
+ * \param bmp_state A flag word indicating the initial state
+ * \return An opaque struct bitmap, or NULL on memory exhaustion
*/
static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
{
diff --git a/image/gif.c b/image/gif.c
index 871b1cc..3f5f630 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -305,7 +305,8 @@ static bool nsgif_convert(struct content *c)
/**
* Updates the GIF bitmap to display the current frame
*
- * \param c the content to update
+ * \param gif The gif context to update.
+ * \return GIF_OK on success else apropriate error code.
*/
static gif_result nsgif_get_frame(nsgif_content *gif)
{
@@ -317,10 +318,11 @@ static gif_result nsgif_get_frame(nsgif_content *gif)
current_frame = 0;
}
- if (current_frame < gif->gif->decoded_frame)
+ if (current_frame < gif->gif->decoded_frame) {
previous_frame = 0;
- else
+ } else {
previous_frame = gif->gif->decoded_frame + 1;
+ }
for (frame = previous_frame; frame <= current_frame; frame++) {
res = gif_decode_frame(gif->gif, frame);
diff --git a/image/ico.c b/image/ico.c
index 9cb650b..cf74592 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -45,7 +45,7 @@ typedef struct nsico_content {
*
* \param width width of image in pixels
* \param height width of image in pixels
- * \param state a flag word indicating the initial state
+ * \param bmp_state A flag word indicating the initial state
* \return an opaque struct bitmap, or NULL on memory exhaustion
*/
static void *nsico_bitmap_create(int width, int height, unsigned int bmp_state)
diff --git a/monkey/main.c b/monkey/main.c
index 81406bc..2b1a3bc 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -172,9 +172,14 @@ main(int argc, char **argv)
free(options);
nsoption_commandline(&argc, argv, nsoptions);
- /* common initialisation */
messages = filepath_find(respaths, "Messages");
- ret = netsurf_init(messages, NULL);
+ ret = messages_add_from_file(messages);
+ if (ret != NSERROR_OK) {
+ LOG("Messages failed to load");
+ }
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
free(messages);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
diff --git a/riscos/gui.c b/riscos/gui.c
index 3a47d08..2dd9433 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -2481,11 +2481,14 @@ int main(int argc, char** argv)
die("Failed to locate Messages resource.");
}
+ /* initialise messages */
+ messages_add_from_file(path);
+
/* obtain cache path */
cachepath = get_cachepath();
/* common initialisation */
- ret = netsurf_init(path, cachepath);
+ ret = netsurf_init(cachepath);
free(cachepath);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise core");
@@ -2496,7 +2499,7 @@ int main(int argc, char** argv)
sprite_init();
/* Load some extra RISC OS specific Messages */
- messages_load("NetSurf:Resources.LangNames");
+ messages_add_from_file("NetSurf:Resources.LangNames");
ret = gui_init(argc, argv);
if (ret != NSERROR_OK) {
diff --git a/utils/log.c b/utils/log.c
index d67ed76..cc3f7a8 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -24,6 +24,10 @@
#include <stdio.h>
#include <sys/time.h>
+#include "utils/config.h"
+#include "utils/utsname.h"
+#include "desktop/version.h"
+
#include "utils/log.h"
/** flag to enable verbose logging */
@@ -34,6 +38,7 @@ static FILE *logfile;
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
{
+ struct utsname utsname;
nserror ret = NSERROR_OK;
if (((*pargc) > 1) &&
@@ -88,6 +93,21 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
verbose_log = false;
}
+ /* sucessfull logging initialisation so log system info */
+ if (ret == NSERROR_OK) {
+ LOG("NetSurf version '%s'", netsurf_version);
+ if (uname(&utsname) < 0) {
+ LOG("Failed to extract machine information");
+ } else {
+ LOG("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, machine <%s>",
+ utsname.sysname,
+ utsname.nodename,
+ utsname.release,
+ utsname.version,
+ utsname.machine);
+ }
+ }
+
return ret;
}
diff --git a/utils/messages.c b/utils/messages.c
index 78b9a79..d652fef 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -45,6 +45,41 @@
static struct hash_table *messages_hash = NULL;
/**
+ * process a line of input.
+ */
+static nserror
+message_process_line(struct hash_table *hash, uint8_t *ln, int lnlen)
+{
+ uint8_t *value;
+ uint8_t *colon;
+
+ /* empty or comment lines */
+ if (ln[0] == 0 || ln[0] == '#') {
+ return NSERROR_OK;
+ }
+
+ /* find first colon as key/value separator */
+ for (colon = ln; colon < (ln + lnlen); colon++) {
+ if (*colon == ':') {
+ break;
+ }
+ }
+ if (colon == (ln + lnlen)) {
+ /* no colon found */
+ return NSERROR_INVALID;
+ }
+
+ *colon = 0; /* terminate key */
+ value = colon + 1;
+
+ if (hash_add(hash, (char *)ln, (char *)value) == false) {
+ LOG("Unable to add %s:%s to hash table", ln, value);
+ return NSERROR_INVALID;
+ }
+ return NSERROR_OK;
+}
+
+/**
* Read keys and values from messages file.
*
* \param path pathname of messages file
@@ -142,21 +177,97 @@ messages_get_ctx(const char *key, struct hash_table *ctx)
}
/* exported interface documented in messages.h */
-nserror messages_load(const char *path)
+nserror messages_add_from_file(const char *path)
{
nserror err;
if (path == NULL) {
- err = NSERROR_BAD_PARAMETER;
- } else {
- LOG("Loading Messages from '%s'", path);
-
- err = messages_load_ctx(path, &messages_hash);
+ return NSERROR_BAD_PARAMETER;
}
+ LOG("Loading Messages from '%s'", path);
+
+ err = messages_load_ctx(path, &messages_hash);
+
+
return err;
}
+
+/* exported interface documented in messages.h */
+nserror messages_add_from_inline(const uint8_t *data, size_t data_size)
+{
+ z_stream strm;
+ int ret;
+ uint8_t s[512]; /* line buffer */
+ size_t used = 0; /* number of bytes in buffer in use */
+ uint8_t *nl;
+
+ /* ensure the hash table is initialised */
+ if (messages_hash == NULL) {
+ messages_hash = hash_create(HASH_SIZE);
+ }
+ if (messages_hash == NULL) {
+ LOG("Unable to create hash table");
+ return NSERROR_NOMEM;
+ }
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+
+ strm.next_in = (uint8_t *)data;
+ strm.avail_in = data_size;
+
+ ret = inflateInit2(&strm, 32 + MAX_WBITS);
+ if (ret != Z_OK) {
+ LOG("inflateInit returned %d", ret);
+ return NSERROR_INVALID;
+ }
+
+ do {
+ strm.next_out = s + used;
+ strm.avail_out = sizeof(s) - used;
+
+ ret = inflate(&strm, Z_NO_FLUSH);
+ if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
+ break;
+ }
+
+ used = sizeof(s) - strm.avail_out;
+ while (used > 0) {
+ /* find nl */
+ for (nl = &s[0]; nl < &s[used]; nl++) {
+ if (*nl == '\n') {
+ break;
+ }
+ }
+ if (nl == &s[used]) {
+ /* no nl found */
+ break;
+ }
+ /* found newline */
+ *nl = 0; /* null terminate line */
+ message_process_line(messages_hash, &s[0], nl - &s[0]);
+ memmove(&s[0], nl + 1, used - ((nl + 1) - &s[0]) );
+ used -= ((nl +1) - &s[0]);
+ }
+ if (used == sizeof(s)) {
+ /* entire buffer used and no newline */
+ LOG("Overlength line");
+ used = 0;
+ }
+ } while (ret != Z_STREAM_END);
+
+ inflateEnd(&strm);
+
+ if (ret != Z_STREAM_END) {
+ LOG("inflate returned %d", ret);
+ return NSERROR_INVALID;
+ }
+ return NSERROR_OK;
+}
+
/* exported interface documented in messages.h */
char *messages_get_buff(const char *key, ...)
{
@@ -175,7 +286,7 @@ char *messages_get_buff(const char *key, ...)
if (buff == NULL) {
LOG("malloc failed");
- warn_user("NoMemory", 0);
+ warn_user("NoMemory", 0);
} else {
va_start(ap, key);
vsnprintf(buff, buff_len + 1, msg_fmt, ap);
@@ -262,7 +373,7 @@ const char *messages_get_errorcode(nserror code)
return messages_get_ctx("ParsingFail", messages_hash);
case NSERROR_CSS:
- /* CSS call returned error */
+ /* CSS call returned error */
return messages_get_ctx("CSSGeneric", messages_hash);
case NSERROR_CSS_BASE:
diff --git a/utils/messages.h b/utils/messages.h
index c9946e6..ac1ea98 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -33,18 +33,33 @@
#ifndef _NETSURF_UTILS_MESSAGES_H_
#define _NETSURF_UTILS_MESSAGES_H_
+#include <stdint.h>
+
#include "utils/errors.h"
/**
* Read keys and values from messages file into the standard Messages hash.
*
- * The messages are merged with any previously loaded messages. Any keys which
- * are present already are replaced with the new value.
+ * The messages are merged with any previously loaded messages. Any
+ * keys which are present already are replaced with the new value. The
+ * file may be gzip compressed.
*
* \param path pathname of messages file.
* \return NSERROR_OK on success or error code on faliure.
*/
-nserror messages_load(const char *path);
+nserror messages_add_from_file(const char *path);
+
+/**
+ * Read keys and values from inline message data into the standard Messages hash.
+ *
+ * The messages are merged with any previously loaded messages. Any
+ * keys which are present already are replaced with the new value. The
+ * data may be gzip compressed.
+ *
+ * \param data The inline message data.
+ * \return NSERROR_OK on success or error code on faliure.
+ */
+nserror messages_add_from_inline(const uint8_t *data, size_t data_size);
/**
* Fast lookup of a message by key from the standard Messages hash.
diff --git a/windows/main.c b/windows/main.c
index 1997c85..b9ef44a 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -183,10 +183,13 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
nsoption_read(options_file_location, NULL);
nsoption_commandline(&argc, argv, NULL);
- /* common initialisation */
+ /* message init */
messages = filepath_find(respaths, "messages");
- ret = netsurf_init(messages, NULL);
+ messages_add_from_file(messages);
free(messages);
+
+ /* common initialisation */
+ ret = netsurf_init(NULL);
if (ret != NSERROR_OK) {
free(options_file_location);
LOG("NetSurf failed to initialise");
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-174-gfcadb1f
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/fcadb1f6f884dac419109...
...commit http://git.netsurf-browser.org/netsurf.git/commit/fcadb1f6f884dac41910901...
...tree http://git.netsurf-browser.org/netsurf.git/tree/fcadb1f6f884dac4191090175...
The branch, master has been updated
via fcadb1f6f884dac4191090175655602ed5117127 (commit)
via 451b021c36bff36a388d493b740f7069e3235371 (commit)
from 57ca8bbd21346ad46950ea279743b1064b684aab (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=fcadb1f6f884dac4191...
commit fcadb1f6f884dac4191090175655602ed5117127
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Space ARexx menu items correctly.
diff --git a/amiga/menu.c b/amiga/menu.c
index e2bb795..f4b35f0 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -833,6 +833,7 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
int icon_width = 0;
Object *submenuarrow = NULL;
Object *icon = BitMapObj,
+ IA_Scalable, TRUE,
BITMAP_Screen, scrn,
BITMAP_SourceFile, gwin->menuicon[i],
BITMAP_Masking, TRUE,
@@ -979,7 +980,7 @@ void ami_menu_arexx_scan(struct gui_window_2 *gwin)
else
menu_lab = ead->ed_Name;
- ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL,
+ ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NSA_SPACE,
ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name));
item++;
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=451b021c36bff36a388...
commit 451b021c36bff36a388d493b740f7069e3235371
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Fix the capitalisation of "New tab" to matach "New window" etc.
diff --git a/resources/FatMessages b/resources/FatMessages
index 73e9e18..fa66125 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -709,7 +709,7 @@ de.all.NewWindowNS:Neues Fenster
fr.all.NewWindowNS:Nouvelle fenêtre
it.all.NewWindowNS:Nuova finestra
nl.all.NewWindowNS:Nieuw venster
-en.all.NewTab:New Tab
+en.all.NewTab:New tab
de.all.NewTab:Neuer Tab
fr.all.NewTab:Nouvel onglet
it.all.NewTab:Nuova scheda
-----------------------------------------------------------------------
Summary of changes:
amiga/menu.c | 3 ++-
resources/FatMessages | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/amiga/menu.c b/amiga/menu.c
index e2bb795..f4b35f0 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -833,6 +833,7 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
int icon_width = 0;
Object *submenuarrow = NULL;
Object *icon = BitMapObj,
+ IA_Scalable, TRUE,
BITMAP_Screen, scrn,
BITMAP_SourceFile, gwin->menuicon[i],
BITMAP_Masking, TRUE,
@@ -979,7 +980,7 @@ void ami_menu_arexx_scan(struct gui_window_2 *gwin)
else
menu_lab = ead->ed_Name;
- ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL,
+ ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NSA_SPACE,
ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name));
item++;
diff --git a/resources/FatMessages b/resources/FatMessages
index 73e9e18..fa66125 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -709,7 +709,7 @@ de.all.NewWindowNS:Neues Fenster
fr.all.NewWindowNS:Nouvelle fenêtre
it.all.NewWindowNS:Nuova finestra
nl.all.NewWindowNS:Nieuw venster
-en.all.NewTab:New Tab
+en.all.NewTab:New tab
de.all.NewTab:Neuer Tab
fr.all.NewTab:Nouvel onglet
it.all.NewTab:Nuova scheda
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-172-g57ca8bb
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/57ca8bbd21346ad46950e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/57ca8bbd21346ad46950ea2...
...tree http://git.netsurf-browser.org/netsurf.git/tree/57ca8bbd21346ad46950ea279...
The branch, master has been updated
via 57ca8bbd21346ad46950ea279743b1064b684aab (commit)
from fbbb6d664d2cf1549fb64a980dd829be0553aa12 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=57ca8bbd21346ad4695...
commit 57ca8bbd21346ad46950ea279743b1064b684aab
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Require gadtools 53.7
OS4.1u6 does not cope well with image menus, so insist on a component in FE to ensure the layouting is sane and menu creation is fast.
diff --git a/amiga/menu.c b/amiga/menu.c
index c946fb7..e2bb795 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -826,8 +826,8 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
} while((gwin->menutype[j] != NM_TITLE) && (gwin->menutype[j] != 0));
}
#ifdef __amigaos4__
- if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 6)) {
- /* GadTools 53.6+ only. For now we will only create the menu
+ if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
+ /* GadTools 53.7+ only. For now we will only create the menu
using label.image if there's a bitmap associated with the item. */
if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) {
int icon_width = 0;
-----------------------------------------------------------------------
Summary of changes:
amiga/menu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/amiga/menu.c b/amiga/menu.c
index c946fb7..e2bb795 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -826,8 +826,8 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
} while((gwin->menutype[j] != NM_TITLE) && (gwin->menutype[j] != 0));
}
#ifdef __amigaos4__
- if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 6)) {
- /* GadTools 53.6+ only. For now we will only create the menu
+ if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
+ /* GadTools 53.7+ only. For now we will only create the menu
using label.image if there's a bitmap associated with the item. */
if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) {
int icon_width = 0;
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-171-gfbbb6d6
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/fbbb6d664d2cf1549fb64...
...commit http://git.netsurf-browser.org/netsurf.git/commit/fbbb6d664d2cf1549fb64a9...
...tree http://git.netsurf-browser.org/netsurf.git/tree/fbbb6d664d2cf1549fb64a980...
The branch, master has been updated
via fbbb6d664d2cf1549fb64a980dd829be0553aa12 (commit)
from 8aa04c24473947e2d2496bca1ca17275aee549dc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=fbbb6d664d2cf1549fb...
commit fbbb6d664d2cf1549fb64a980dd829be0553aa12
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Stop unused variable warning when no core image handlers are enabled.
diff --git a/image/image.c b/image/image.c
index 49dc2b8..1dac313 100644
--- a/image/image.c
+++ b/image/image.c
@@ -43,7 +43,7 @@
*/
nserror image_init(void)
{
- nserror error;
+ nserror error = NSERROR_OK;
#ifdef WITH_BMP
error = nsbmp_init();
@@ -93,7 +93,7 @@ nserror image_init(void)
return error;
#endif
- return NSERROR_OK;
+ return error;
}
-----------------------------------------------------------------------
Summary of changes:
image/image.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/image/image.c b/image/image.c
index 49dc2b8..1dac313 100644
--- a/image/image.c
+++ b/image/image.c
@@ -43,7 +43,7 @@
*/
nserror image_init(void)
{
- nserror error;
+ nserror error = NSERROR_OK;
#ifdef WITH_BMP
error = nsbmp_init();
@@ -93,7 +93,7 @@ nserror image_init(void)
return error;
#endif
- return NSERROR_OK;
+ return error;
}
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-170-g8aa04c2
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/8aa04c24473947e2d2496...
...commit http://git.netsurf-browser.org/netsurf.git/commit/8aa04c24473947e2d2496bc...
...tree http://git.netsurf-browser.org/netsurf.git/tree/8aa04c24473947e2d2496bca1...
The branch, master has been updated
via 8aa04c24473947e2d2496bca1ca17275aee549dc (commit)
from 9c6b3e8c32991ac8436afcf8016268eeb8ef24c3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=8aa04c24473947e2d24...
commit 8aa04c24473947e2d2496bca1ca17275aee549dc
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Fix cocoa_bitmap_modified scope error introduced in cleanup
diff --git a/cocoa/bitmap.m b/cocoa/bitmap.m
index bd4e222..6e263a1 100644
--- a/cocoa/bitmap.m
+++ b/cocoa/bitmap.m
@@ -157,7 +157,7 @@ static bool bitmap_save(void *bitmap, const char *path, unsigned flags)
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
}
-static void cocoa_bitmap_modified(void *bitmap)
+void cocoa_bitmap_modified(void *bitmap)
{
NSMapTable *cache = cocoa_get_bitmap_cache();
CGImageRef image = NSMapGet( cache, bitmap );
-----------------------------------------------------------------------
Summary of changes:
cocoa/bitmap.m | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cocoa/bitmap.m b/cocoa/bitmap.m
index bd4e222..6e263a1 100644
--- a/cocoa/bitmap.m
+++ b/cocoa/bitmap.m
@@ -157,7 +157,7 @@ static bool bitmap_save(void *bitmap, const char *path, unsigned flags)
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
}
-static void cocoa_bitmap_modified(void *bitmap)
+void cocoa_bitmap_modified(void *bitmap)
{
NSMapTable *cache = cocoa_get_bitmap_cache();
CGImageRef image = NSMapGet( cache, bitmap );
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-169-g9c6b3e8
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/9c6b3e8c32991ac8436af...
...commit http://git.netsurf-browser.org/netsurf.git/commit/9c6b3e8c32991ac8436afcf...
...tree http://git.netsurf-browser.org/netsurf.git/tree/9c6b3e8c32991ac8436afcf80...
The branch, master has been updated
via 9c6b3e8c32991ac8436afcf8016268eeb8ef24c3 (commit)
from e1bbe4528b479881a1912f96f3160ab6e2fbb2ec (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=9c6b3e8c32991ac8436...
commit 9c6b3e8c32991ac8436afcf8016268eeb8ef24c3
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Fix several warnings in cocoa frontend
diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m
index df57b37..cb6117e 100644
--- a/cocoa/DownloadWindowController.m
+++ b/cocoa/DownloadWindowController.m
@@ -20,6 +20,7 @@
#import "cocoa/gui.h"
#import "utils/log.h"
+#import "utils/nsurl.h"
#import "desktop/download.h"
#import "desktop/gui_download.h"
diff --git a/cocoa/apple_image.h b/cocoa/apple_image.h
index 0874803..11248a6 100644
--- a/cocoa/apple_image.h
+++ b/cocoa/apple_image.h
@@ -25,6 +25,9 @@
#ifdef WITH_APPLE_IMAGE
+/**
+ * Initialise apple image handlers instead of generic core ones.
+ */
nserror apple_image_init(void);
#else
diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m
index c6f9df3..91dfcb4 100644
--- a/cocoa/apple_image.m
+++ b/cocoa/apple_image.m
@@ -9,7 +9,7 @@
*
* 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
+ * 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
@@ -26,29 +26,19 @@
#include "desktop/plotters.h"
#include "utils/utils.h"
-#include "cocoa/schedule.h"
+#import "cocoa/schedule.h"
+#import "cocoa/bitmap.h"
typedef struct apple_image_content {
struct content base;
struct bitmap *bitmap; /**< Created NetSurf bitmap */
- NSUInteger frames;
- NSUInteger currentFrame;
- int *frameTimes;
+ NSUInteger frames;
+ NSUInteger currentFrame;
+ int *frameTimes;
} apple_image_content;
-static nserror apple_image_create(const content_handler *handler,
- lwc_string *imime_type, const http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static bool apple_image_convert(struct content *c);
-static void apple_image_destroy(struct content *c);
-static bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror apple_image_clone(const struct content *old,
- struct content **newc);
-static content_type apple_image_content_type(void);
static void *apple_image_get_internal(const struct content *c, void *context)
{
@@ -57,55 +47,7 @@ static void *apple_image_get_internal(const struct content *c, void *context)
return ai_c->bitmap;
}
-static const content_handler apple_image_content_handler = {
- .create = apple_image_create,
- .data_complete = apple_image_convert,
- .destroy = apple_image_destroy,
- .redraw = apple_image_redraw,
- .clone = apple_image_clone,
- .get_internal = apple_image_get_internal,
- .type = apple_image_content_type,
- .no_share = false
-};
-
-static nserror register_for_type( NSString *mime )
-{
- const char *type = [mime UTF8String];
- /* nsgif has priority since it supports animated GIF */
-#ifdef WITH_GIF
- if (strcmp(type, "image/gif") == 0)
- return NSERROR_OK;
-#endif
-
- nserror error = content_factory_register_handler( type, &apple_image_content_handler );
- if (error != NSERROR_OK) return error;
-
- return NSERROR_OK;
-}
-
-nserror apple_image_init(void)
-{
- NSArray *utis = [NSBitmapImageRep imageTypes];
- for (NSString *uti in utis) {
- NSDictionary *declaration = [(NSDictionary *)UTTypeCopyDeclaration( (CFStringRef)uti ) autorelease];
- id mimeTypes = [[declaration objectForKey: (NSString *)kUTTypeTagSpecificationKey] objectForKey: (NSString *)kUTTagClassMIMEType];
-
- if (mimeTypes == nil) continue;
-
- if (![mimeTypes isKindOfClass: [NSArray class]]) {
- mimeTypes = [NSArray arrayWithObject: mimeTypes];
- }
-
- for (NSString *mime in mimeTypes) {
- nserror error = register_for_type( mime );
- if (error != NSERROR_OK) return error;
- }
- }
-
- return NSERROR_OK;
-}
-
-nserror apple_image_create(const content_handler *handler,
+static nserror apple_image_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -132,30 +74,29 @@ nserror apple_image_create(const content_handler *handler,
static void animate_image_cb( void *ptr )
{
- struct apple_image_content *ai = ptr;
- ++ai->currentFrame;
- if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
-
- [(NSBitmapImageRep *)ai->bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
- bitmap_modified( ai->bitmap );
-
- union content_msg_data data;
- data.redraw.full_redraw = true;
- data.redraw.x = data.redraw.object_x = 0;
- data.redraw.y = data.redraw.object_y = 0;
- data.redraw.width = data.redraw.object_width = ai->base.width;
- data.redraw.height = data.redraw.object_height = ai->base.height;
+ struct apple_image_content *ai = ptr;
+ ++ai->currentFrame;
+ if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
+
+ [(NSBitmapImageRep *)ai->bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
+ cocoa_bitmap_modified( ai->bitmap );
+
+ union content_msg_data data;
+ data.redraw.full_redraw = true;
+ data.redraw.x = data.redraw.object_x = 0;
+ data.redraw.y = data.redraw.object_y = 0;
+ data.redraw.width = data.redraw.object_width = ai->base.width;
+ data.redraw.height = data.redraw.object_height = ai->base.height;
data.redraw.object = &ai->base;
- content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
+ content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
- cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
+ cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
}
/**
* Convert a CONTENT_APPLE_IMAGE for display.
*/
-
-bool apple_image_convert(struct content *c)
+static bool apple_image_convert(struct content *c)
{
apple_image_content *ai_c = (apple_image_content *)c;
unsigned long size;
@@ -170,7 +111,7 @@ bool apple_image_convert(struct content *c)
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
}
-
+
c->width = [image pixelsWide];
c->height = [image pixelsHigh];
ai_c->bitmap = (void *)image;
@@ -178,40 +119,40 @@ bool apple_image_convert(struct content *c)
NSString *url = [NSString stringWithUTF8String: nsurl_access(llcache_handle_get_url( content_get_llcache_handle( c )) )];
NSString *title = [NSString stringWithFormat: @"%@ (%dx%d)", [url lastPathComponent], c->width, c->height];
content__set_title(c, [title UTF8String] );
-
+
content_set_ready(c);
content_set_done(c);
content_set_status(c, "");
-
- struct apple_image_content *ai = (struct apple_image_content *)c;
- NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
- if (frames > 1) {
- ai->frames = frames;
- ai->currentFrame = 0;
- ai->frameTimes = calloc( ai->frames , sizeof(int));
- for (NSUInteger i = 0; i < frames; i++) {
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
- ai->frameTimes[i] = 1000 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
- }
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
- cocoa_schedule( ai->frameTimes[0], animate_image_cb, ai );
- }
-
+
+ struct apple_image_content *ai = (struct apple_image_content *)c;
+ NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
+ if (frames > 1) {
+ ai->frames = frames;
+ ai->currentFrame = 0;
+ ai->frameTimes = calloc( ai->frames , sizeof(int));
+ for (NSUInteger i = 0; i < frames; i++) {
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
+ ai->frameTimes[i] = 1000 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
+ }
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
+ cocoa_schedule( ai->frameTimes[0], animate_image_cb, ai );
+ }
+
return true;
}
-void apple_image_destroy(struct content *c)
+static void apple_image_destroy(struct content *c)
{
apple_image_content *ai_c = (apple_image_content *)c;
[(id)ai_c->bitmap release];
ai_c->bitmap = NULL;
- cocoa_schedule(-1, animate_image_cb, c );
+ cocoa_schedule(-1, animate_image_cb, c );
}
-nserror apple_image_clone(const struct content *old, struct content **newc)
+static nserror apple_image_clone(const struct content *old, struct content **newc)
{
apple_image_content *ai;
apple_image_content *ai_old = (apple_image_content *)old;
@@ -235,11 +176,11 @@ nserror apple_image_clone(const struct content *old, struct content **newc)
}
*newc = (struct content *) ai;
-
+
return NSERROR_OK;
}
-content_type apple_image_content_type(void)
+static content_type apple_image_content_type(void)
{
return CONTENT_IMAGE;
}
@@ -247,8 +188,7 @@ content_type apple_image_content_type(void)
/**
* Redraw a CONTENT_APPLE_IMAGE with appropriate tiling.
*/
-
-bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
+static bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
apple_image_content *ai_c = (apple_image_content *)c;
@@ -263,4 +203,53 @@ bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
ai_c->bitmap, data->background_colour, flags);
}
+static const content_handler apple_image_content_handler = {
+ .create = apple_image_create,
+ .data_complete = apple_image_convert,
+ .destroy = apple_image_destroy,
+ .redraw = apple_image_redraw,
+ .clone = apple_image_clone,
+ .get_internal = apple_image_get_internal,
+ .type = apple_image_content_type,
+ .no_share = false
+};
+
+static nserror register_for_type( NSString *mime )
+{
+ const char *type = [mime UTF8String];
+ /* nsgif has priority since it supports animated GIF */
+#ifdef WITH_GIF
+ if (strcmp(type, "image/gif") == 0)
+ return NSERROR_OK;
+#endif
+
+ nserror error = content_factory_register_handler( type, &apple_image_content_handler );
+ if (error != NSERROR_OK) return error;
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in cocoa/apple_image.h */
+nserror apple_image_init(void)
+{
+ NSArray *utis = [NSBitmapImageRep imageTypes];
+ for (NSString *uti in utis) {
+ NSDictionary *declaration = [(NSDictionary *)UTTypeCopyDeclaration( (CFStringRef)uti ) autorelease];
+ id mimeTypes = [[declaration objectForKey: (NSString *)kUTTypeTagSpecificationKey] objectForKey: (NSString *)kUTTagClassMIMEType];
+
+ if (mimeTypes == nil) continue;
+
+ if (![mimeTypes isKindOfClass: [NSArray class]]) {
+ mimeTypes = [NSArray arrayWithObject: mimeTypes];
+ }
+
+ for (NSString *mime in mimeTypes) {
+ nserror error = register_for_type( mime );
+ if (error != NSERROR_OK) return error;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
#endif /* WITH_APPLE_IMAGE */
diff --git a/cocoa/bitmap.h b/cocoa/bitmap.h
index dc463b8..1eeed17 100644
--- a/cocoa/bitmap.h
+++ b/cocoa/bitmap.h
@@ -21,6 +21,8 @@
CGImageRef cocoa_get_cgimage( void *bitmap );
+void cocoa_bitmap_modified(void *bitmap);
+
struct gui_bitmap_table *cocoa_bitmap_table;
#endif
diff --git a/cocoa/bitmap.m b/cocoa/bitmap.m
index 39a1448..bd4e222 100644
--- a/cocoa/bitmap.m
+++ b/cocoa/bitmap.m
@@ -9,7 +9,7 @@
*
* 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
+ * 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
@@ -44,28 +44,28 @@
static CGImageRef cocoa_prepare_bitmap( void *bitmap );
static NSMapTable *cocoa_get_bitmap_cache( void );
-int bitmap_get_width(void *bitmap)
+static int bitmap_get_width(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp pixelsWide];
}
-int bitmap_get_height(void *bitmap)
+static int bitmap_get_height(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp pixelsHigh];
}
-bool bitmap_get_opaque(void *bitmap)
+static bool bitmap_get_opaque(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp isOpaque];
}
-void bitmap_destroy(void *bitmap)
+static void bitmap_destroy(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
@@ -80,7 +80,7 @@ void bitmap_destroy(void *bitmap)
[bmp release];
}
-void *bitmap_create(int width, int height, unsigned int state)
+static void *bitmap_create(int width, int height, unsigned int state)
{
NSBitmapImageRep *bmp = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL
@@ -98,35 +98,35 @@ void *bitmap_create(int width, int height, unsigned int state)
return bmp;
}
-void bitmap_set_opaque(void *bitmap, bool opaque)
+static void bitmap_set_opaque(void *bitmap, bool opaque)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
[bmp setOpaque: opaque ? YES : NO];
}
-unsigned char *bitmap_get_buffer(void *bitmap)
+static unsigned char *bitmap_get_buffer(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bitmapData];
}
-size_t bitmap_get_rowstride(void *bitmap)
+static size_t bitmap_get_rowstride(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bytesPerRow];
}
-size_t bitmap_get_bpp(void *bitmap)
+static size_t bitmap_get_bpp(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bitsPerPixel] / 8;
}
-bool bitmap_test_opaque(void *bitmap)
+static bool bitmap_test_opaque(void *bitmap)
{
NSCParameterAssert( bitmap_get_bpp( bitmap ) == BYTES_PER_PIXEL );
@@ -148,7 +148,7 @@ bool bitmap_test_opaque(void *bitmap)
return true;
}
-bool bitmap_save(void *bitmap, const char *path, unsigned flags)
+static bool bitmap_save(void *bitmap, const char *path, unsigned flags)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
@@ -157,7 +157,7 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags)
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
}
-void bitmap_modified(void *bitmap)
+static void cocoa_bitmap_modified(void *bitmap)
{
NSMapTable *cache = cocoa_get_bitmap_cache();
CGImageRef image = NSMapGet( cache, bitmap );
@@ -258,7 +258,7 @@ static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *conte
[NSGraphicsContext setCurrentContext: nil];
CGContextRelease( bitmapContext );
- bitmap_modified( bitmap );
+ cocoa_bitmap_modified( bitmap );
return true;
}
@@ -275,7 +275,7 @@ static struct gui_bitmap_table bitmap_table = {
.get_height = bitmap_get_height,
.get_bpp = bitmap_get_bpp,
.save = bitmap_save,
- .modified = bitmap_modified,
+ .modified = cocoa_bitmap_modified,
.render = bitmap_render,
};
-----------------------------------------------------------------------
Summary of changes:
cocoa/DownloadWindowController.m | 1 +
cocoa/apple_image.h | 3 +
cocoa/apple_image.m | 201 ++++++++++++++++++--------------------
cocoa/bitmap.h | 2 +
cocoa/bitmap.m | 30 +++---
5 files changed, 116 insertions(+), 121 deletions(-)
diff --git a/cocoa/DownloadWindowController.m b/cocoa/DownloadWindowController.m
index df57b37..cb6117e 100644
--- a/cocoa/DownloadWindowController.m
+++ b/cocoa/DownloadWindowController.m
@@ -20,6 +20,7 @@
#import "cocoa/gui.h"
#import "utils/log.h"
+#import "utils/nsurl.h"
#import "desktop/download.h"
#import "desktop/gui_download.h"
diff --git a/cocoa/apple_image.h b/cocoa/apple_image.h
index 0874803..11248a6 100644
--- a/cocoa/apple_image.h
+++ b/cocoa/apple_image.h
@@ -25,6 +25,9 @@
#ifdef WITH_APPLE_IMAGE
+/**
+ * Initialise apple image handlers instead of generic core ones.
+ */
nserror apple_image_init(void);
#else
diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m
index c6f9df3..91dfcb4 100644
--- a/cocoa/apple_image.m
+++ b/cocoa/apple_image.m
@@ -9,7 +9,7 @@
*
* 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
+ * 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
@@ -26,29 +26,19 @@
#include "desktop/plotters.h"
#include "utils/utils.h"
-#include "cocoa/schedule.h"
+#import "cocoa/schedule.h"
+#import "cocoa/bitmap.h"
typedef struct apple_image_content {
struct content base;
struct bitmap *bitmap; /**< Created NetSurf bitmap */
- NSUInteger frames;
- NSUInteger currentFrame;
- int *frameTimes;
+ NSUInteger frames;
+ NSUInteger currentFrame;
+ int *frameTimes;
} apple_image_content;
-static nserror apple_image_create(const content_handler *handler,
- lwc_string *imime_type, const http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static bool apple_image_convert(struct content *c);
-static void apple_image_destroy(struct content *c);
-static bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror apple_image_clone(const struct content *old,
- struct content **newc);
-static content_type apple_image_content_type(void);
static void *apple_image_get_internal(const struct content *c, void *context)
{
@@ -57,55 +47,7 @@ static void *apple_image_get_internal(const struct content *c, void *context)
return ai_c->bitmap;
}
-static const content_handler apple_image_content_handler = {
- .create = apple_image_create,
- .data_complete = apple_image_convert,
- .destroy = apple_image_destroy,
- .redraw = apple_image_redraw,
- .clone = apple_image_clone,
- .get_internal = apple_image_get_internal,
- .type = apple_image_content_type,
- .no_share = false
-};
-
-static nserror register_for_type( NSString *mime )
-{
- const char *type = [mime UTF8String];
- /* nsgif has priority since it supports animated GIF */
-#ifdef WITH_GIF
- if (strcmp(type, "image/gif") == 0)
- return NSERROR_OK;
-#endif
-
- nserror error = content_factory_register_handler( type, &apple_image_content_handler );
- if (error != NSERROR_OK) return error;
-
- return NSERROR_OK;
-}
-
-nserror apple_image_init(void)
-{
- NSArray *utis = [NSBitmapImageRep imageTypes];
- for (NSString *uti in utis) {
- NSDictionary *declaration = [(NSDictionary *)UTTypeCopyDeclaration( (CFStringRef)uti ) autorelease];
- id mimeTypes = [[declaration objectForKey: (NSString *)kUTTypeTagSpecificationKey] objectForKey: (NSString *)kUTTagClassMIMEType];
-
- if (mimeTypes == nil) continue;
-
- if (![mimeTypes isKindOfClass: [NSArray class]]) {
- mimeTypes = [NSArray arrayWithObject: mimeTypes];
- }
-
- for (NSString *mime in mimeTypes) {
- nserror error = register_for_type( mime );
- if (error != NSERROR_OK) return error;
- }
- }
-
- return NSERROR_OK;
-}
-
-nserror apple_image_create(const content_handler *handler,
+static nserror apple_image_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -132,30 +74,29 @@ nserror apple_image_create(const content_handler *handler,
static void animate_image_cb( void *ptr )
{
- struct apple_image_content *ai = ptr;
- ++ai->currentFrame;
- if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
-
- [(NSBitmapImageRep *)ai->bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
- bitmap_modified( ai->bitmap );
-
- union content_msg_data data;
- data.redraw.full_redraw = true;
- data.redraw.x = data.redraw.object_x = 0;
- data.redraw.y = data.redraw.object_y = 0;
- data.redraw.width = data.redraw.object_width = ai->base.width;
- data.redraw.height = data.redraw.object_height = ai->base.height;
+ struct apple_image_content *ai = ptr;
+ ++ai->currentFrame;
+ if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
+
+ [(NSBitmapImageRep *)ai->bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
+ cocoa_bitmap_modified( ai->bitmap );
+
+ union content_msg_data data;
+ data.redraw.full_redraw = true;
+ data.redraw.x = data.redraw.object_x = 0;
+ data.redraw.y = data.redraw.object_y = 0;
+ data.redraw.width = data.redraw.object_width = ai->base.width;
+ data.redraw.height = data.redraw.object_height = ai->base.height;
data.redraw.object = &ai->base;
- content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
+ content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
- cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
+ cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
}
/**
* Convert a CONTENT_APPLE_IMAGE for display.
*/
-
-bool apple_image_convert(struct content *c)
+static bool apple_image_convert(struct content *c)
{
apple_image_content *ai_c = (apple_image_content *)c;
unsigned long size;
@@ -170,7 +111,7 @@ bool apple_image_convert(struct content *c)
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
}
-
+
c->width = [image pixelsWide];
c->height = [image pixelsHigh];
ai_c->bitmap = (void *)image;
@@ -178,40 +119,40 @@ bool apple_image_convert(struct content *c)
NSString *url = [NSString stringWithUTF8String: nsurl_access(llcache_handle_get_url( content_get_llcache_handle( c )) )];
NSString *title = [NSString stringWithFormat: @"%@ (%dx%d)", [url lastPathComponent], c->width, c->height];
content__set_title(c, [title UTF8String] );
-
+
content_set_ready(c);
content_set_done(c);
content_set_status(c, "");
-
- struct apple_image_content *ai = (struct apple_image_content *)c;
- NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
- if (frames > 1) {
- ai->frames = frames;
- ai->currentFrame = 0;
- ai->frameTimes = calloc( ai->frames , sizeof(int));
- for (NSUInteger i = 0; i < frames; i++) {
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
- ai->frameTimes[i] = 1000 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
- }
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
- cocoa_schedule( ai->frameTimes[0], animate_image_cb, ai );
- }
-
+
+ struct apple_image_content *ai = (struct apple_image_content *)c;
+ NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
+ if (frames > 1) {
+ ai->frames = frames;
+ ai->currentFrame = 0;
+ ai->frameTimes = calloc( ai->frames , sizeof(int));
+ for (NSUInteger i = 0; i < frames; i++) {
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
+ ai->frameTimes[i] = 1000 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
+ }
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
+ cocoa_schedule( ai->frameTimes[0], animate_image_cb, ai );
+ }
+
return true;
}
-void apple_image_destroy(struct content *c)
+static void apple_image_destroy(struct content *c)
{
apple_image_content *ai_c = (apple_image_content *)c;
[(id)ai_c->bitmap release];
ai_c->bitmap = NULL;
- cocoa_schedule(-1, animate_image_cb, c );
+ cocoa_schedule(-1, animate_image_cb, c );
}
-nserror apple_image_clone(const struct content *old, struct content **newc)
+static nserror apple_image_clone(const struct content *old, struct content **newc)
{
apple_image_content *ai;
apple_image_content *ai_old = (apple_image_content *)old;
@@ -235,11 +176,11 @@ nserror apple_image_clone(const struct content *old, struct content **newc)
}
*newc = (struct content *) ai;
-
+
return NSERROR_OK;
}
-content_type apple_image_content_type(void)
+static content_type apple_image_content_type(void)
{
return CONTENT_IMAGE;
}
@@ -247,8 +188,7 @@ content_type apple_image_content_type(void)
/**
* Redraw a CONTENT_APPLE_IMAGE with appropriate tiling.
*/
-
-bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
+static bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
apple_image_content *ai_c = (apple_image_content *)c;
@@ -263,4 +203,53 @@ bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
ai_c->bitmap, data->background_colour, flags);
}
+static const content_handler apple_image_content_handler = {
+ .create = apple_image_create,
+ .data_complete = apple_image_convert,
+ .destroy = apple_image_destroy,
+ .redraw = apple_image_redraw,
+ .clone = apple_image_clone,
+ .get_internal = apple_image_get_internal,
+ .type = apple_image_content_type,
+ .no_share = false
+};
+
+static nserror register_for_type( NSString *mime )
+{
+ const char *type = [mime UTF8String];
+ /* nsgif has priority since it supports animated GIF */
+#ifdef WITH_GIF
+ if (strcmp(type, "image/gif") == 0)
+ return NSERROR_OK;
+#endif
+
+ nserror error = content_factory_register_handler( type, &apple_image_content_handler );
+ if (error != NSERROR_OK) return error;
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in cocoa/apple_image.h */
+nserror apple_image_init(void)
+{
+ NSArray *utis = [NSBitmapImageRep imageTypes];
+ for (NSString *uti in utis) {
+ NSDictionary *declaration = [(NSDictionary *)UTTypeCopyDeclaration( (CFStringRef)uti ) autorelease];
+ id mimeTypes = [[declaration objectForKey: (NSString *)kUTTypeTagSpecificationKey] objectForKey: (NSString *)kUTTagClassMIMEType];
+
+ if (mimeTypes == nil) continue;
+
+ if (![mimeTypes isKindOfClass: [NSArray class]]) {
+ mimeTypes = [NSArray arrayWithObject: mimeTypes];
+ }
+
+ for (NSString *mime in mimeTypes) {
+ nserror error = register_for_type( mime );
+ if (error != NSERROR_OK) return error;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
#endif /* WITH_APPLE_IMAGE */
diff --git a/cocoa/bitmap.h b/cocoa/bitmap.h
index dc463b8..1eeed17 100644
--- a/cocoa/bitmap.h
+++ b/cocoa/bitmap.h
@@ -21,6 +21,8 @@
CGImageRef cocoa_get_cgimage( void *bitmap );
+void cocoa_bitmap_modified(void *bitmap);
+
struct gui_bitmap_table *cocoa_bitmap_table;
#endif
diff --git a/cocoa/bitmap.m b/cocoa/bitmap.m
index 39a1448..bd4e222 100644
--- a/cocoa/bitmap.m
+++ b/cocoa/bitmap.m
@@ -9,7 +9,7 @@
*
* 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
+ * 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
@@ -44,28 +44,28 @@
static CGImageRef cocoa_prepare_bitmap( void *bitmap );
static NSMapTable *cocoa_get_bitmap_cache( void );
-int bitmap_get_width(void *bitmap)
+static int bitmap_get_width(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp pixelsWide];
}
-int bitmap_get_height(void *bitmap)
+static int bitmap_get_height(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp pixelsHigh];
}
-bool bitmap_get_opaque(void *bitmap)
+static bool bitmap_get_opaque(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp isOpaque];
}
-void bitmap_destroy(void *bitmap)
+static void bitmap_destroy(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
@@ -80,7 +80,7 @@ void bitmap_destroy(void *bitmap)
[bmp release];
}
-void *bitmap_create(int width, int height, unsigned int state)
+static void *bitmap_create(int width, int height, unsigned int state)
{
NSBitmapImageRep *bmp = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL
@@ -98,35 +98,35 @@ void *bitmap_create(int width, int height, unsigned int state)
return bmp;
}
-void bitmap_set_opaque(void *bitmap, bool opaque)
+static void bitmap_set_opaque(void *bitmap, bool opaque)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
[bmp setOpaque: opaque ? YES : NO];
}
-unsigned char *bitmap_get_buffer(void *bitmap)
+static unsigned char *bitmap_get_buffer(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bitmapData];
}
-size_t bitmap_get_rowstride(void *bitmap)
+static size_t bitmap_get_rowstride(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bytesPerRow];
}
-size_t bitmap_get_bpp(void *bitmap)
+static size_t bitmap_get_bpp(void *bitmap)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
return [bmp bitsPerPixel] / 8;
}
-bool bitmap_test_opaque(void *bitmap)
+static bool bitmap_test_opaque(void *bitmap)
{
NSCParameterAssert( bitmap_get_bpp( bitmap ) == BYTES_PER_PIXEL );
@@ -148,7 +148,7 @@ bool bitmap_test_opaque(void *bitmap)
return true;
}
-bool bitmap_save(void *bitmap, const char *path, unsigned flags)
+static bool bitmap_save(void *bitmap, const char *path, unsigned flags)
{
NSCParameterAssert( NULL != bitmap );
NSBitmapImageRep *bmp = (NSBitmapImageRep *)bitmap;
@@ -157,7 +157,7 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags)
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
}
-void bitmap_modified(void *bitmap)
+static void cocoa_bitmap_modified(void *bitmap)
{
NSMapTable *cache = cocoa_get_bitmap_cache();
CGImageRef image = NSMapGet( cache, bitmap );
@@ -258,7 +258,7 @@ static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *conte
[NSGraphicsContext setCurrentContext: nil];
CGContextRelease( bitmapContext );
- bitmap_modified( bitmap );
+ cocoa_bitmap_modified( bitmap );
return true;
}
@@ -275,7 +275,7 @@ static struct gui_bitmap_table bitmap_table = {
.get_height = bitmap_get_height,
.get_bpp = bitmap_get_bpp,
.save = bitmap_save,
- .modified = bitmap_modified,
+ .modified = cocoa_bitmap_modified,
.render = bitmap_render,
};
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-168-ge1bbe45
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/e1bbe4528b479881a1912...
...commit http://git.netsurf-browser.org/netsurf.git/commit/e1bbe4528b479881a1912f9...
...tree http://git.netsurf-browser.org/netsurf.git/tree/e1bbe4528b479881a1912f96f...
The branch, master has been updated
via e1bbe4528b479881a1912f96f3160ab6e2fbb2ec (commit)
via e9b89f776db705ee4403a2235ec21aabab12c8f6 (commit)
via be7a45fefed2736f7ed7f1799e9f2b1cd52235b7 (commit)
via 3e2270482f73528949746fc24a01d0f0c01baee8 (commit)
via 59fbd51a77a684c15b189f666e4359bfd820f627 (commit)
via 61fdc8fd6ffd24abf007598e33cde58fee2b9a83 (commit)
via 8ef292b9caf5cae2197493a87480723138f10344 (commit)
via 16fbb97dbb1688fd9b6f19546792b4173bc30bf1 (commit)
from 3db1e7381ab5cf31f1d47f5aa61ad85e3eafa494 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=e1bbe4528b479881a19...
commit e1bbe4528b479881a1912f96f3160ab6e2fbb2ec
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Add direct resources to GTK
This adds API to obtain direct pointers to arrays of data from
compiled in resources. Additionally it hooks this up to provide data
for the resourece scheme handler.
diff --git a/gtk/fetch.c b/gtk/fetch.c
index f68f203..0e5a37c 100644
--- a/gtk/fetch.c
+++ b/gtk/fetch.c
@@ -34,6 +34,7 @@
#include "desktop/gui_fetch.h"
#include "gtk/gui.h"
+#include "gtk/resources.h"
#include "gtk/fetch.h"
static struct hash_table *mime_hash = NULL;
@@ -172,13 +173,13 @@ const char *fetch_filetype(const char *unix_path)
const char *type;
int l;
- if (stat(unix_path, &statbuf) != 0) {
- /* stat failed */
- return "text/plain";
- }
+ /* stat the path to attempt to determine if the file is special */
+ if (stat(unix_path, &statbuf) == 0) {
+ /* stat suceeded so can check for directory */
- if (S_ISDIR(statbuf.st_mode)) {
- return "application/x-netsurf-directory";
+ if (S_ISDIR(statbuf.st_mode)) {
+ return "application/x-netsurf-directory";
+ }
}
l = strlen(unix_path);
@@ -230,7 +231,7 @@ const char *fetch_filetype(const char *unix_path)
}
-static nsurl *gui_get_resource_url(const char *path)
+static nsurl *nsgtk_get_resource_url(const char *path)
{
char buf[PATH_MAX];
nsurl *url = NULL;
@@ -253,7 +254,8 @@ static nsurl *gui_get_resource_url(const char *path)
static struct gui_fetch_table fetch_table = {
.filetype = fetch_filetype,
- .get_resource_url = gui_get_resource_url,
+ .get_resource_url = nsgtk_get_resource_url,
+ .get_resource_data = nsgtk_data_from_resname,
};
struct gui_fetch_table *nsgtk_fetch_table = &fetch_table;
diff --git a/gtk/gui.c b/gtk/gui.c
index 1df7bfc..4986f42 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -99,14 +99,15 @@ static void die(const char * const error)
exit(EXIT_FAILURE);
}
-/** Create an array of valid paths to search for resources.
+/**
+ * Create an array of valid paths to search for resources.
*
* The idea is that all the complex path computation to find resources
* is performed here, once, rather than every time a resource is
* searched for.
*/
static char **
-nsgtk_init_resource(const char *resource_path)
+nsgtk_init_resource_path(const char *resource_path)
{
const gchar * const *langv;
char **pathv; /* resource path string vector */
@@ -234,13 +235,6 @@ 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 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");
@@ -268,12 +262,15 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
/* Default favicon */
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);
+ favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+ false, 8, 16,16);
}
/* Toolbar inicies file */
- toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
- LOG("Using '%s' as custom toolbar settings file", toolbar_indices_file_location);
+ toolbar_indices_file_location = filepath_find(respath,
+ "toolbarIndices");
+ LOG("Using '%s' as custom toolbar settings file",
+ toolbar_indices_file_location);
/* initialise throbber */
error = nsgtk_throbber_init();
@@ -1011,7 +1008,7 @@ static struct gui_browser_table nsgtk_browser_table = {
.quit = gui_quit,
.launch_url = gui_launch_url,
.cert_verify = gtk_cert_verify,
- .login = gui_401login_open,
+ .login = gui_401login_open,
.pdf_password = nsgtk_pdf_password,
};
@@ -1035,13 +1032,10 @@ int main(int argc, char** argv)
.bitmap = nsgtk_bitmap_table,
};
- ret = netsurf_register(&nsgtk_table);
- if (ret != NSERROR_OK) {
+ ret = netsurf_register(&nsgtk_table);
+ if (ret != NSERROR_OK) {
die("NetSurf operation table failed registration\n");
- }
-
- /* build the common resource path list */
- respaths = nsgtk_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+ }
/* Locate the correct user configuration directory path */
ret = get_config_home(&nsgtk_config_home);
@@ -1062,6 +1056,17 @@ int main(int argc, char** argv)
*/
nslog_init(nslog_stream_configure, &argc, argv);
+ /* build the common resource path list */
+ respaths = nsgtk_init_resource_path("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+
+ /* initialise the gtk resource handling */
+ ret = nsgtk_init_resources(respaths);
+ if (ret != NSERROR_OK) {
+ fprintf(stderr, "GTK resources failed to initialise (%s)\n",
+ messages_get_errorcode(ret));
+ return 1;
+ }
+
/* Initialise user options */
ret = nsgtk_option_init(&argc, argv);
if (ret != NSERROR_OK) {
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
index 55f3a3d..ca4c9e3 100644
--- a/gtk/res/netsurf.gresource.xml
+++ b/gtk/res/netsurf.gresource.xml
@@ -39,5 +39,27 @@
<file preprocess="to-pixdata">throbber/throbber6.png</file>
<file preprocess="to-pixdata">throbber/throbber7.png</file>
<file preprocess="to-pixdata">throbber/throbber8.png</file>
+ <file>credits.html</file>
+ <file>it/credits.html</file>
+ <file>nl/credits.html</file>
+ <file>licence.html</file>
+ <file>it/licence.html</file>
+ <file>nl/licence.html</file>
+ <file>welcome.html</file>
+ <file>de/welcome.html</file>
+ <file>it/welcome.html</file>
+ <file>ja/welcome.html</file>
+ <file>nl/welcome.html</file>
+ <file>maps.html</file>
+ <file>internal.css</file>
+ <file>netsurf.png</file>
+ <file>default.ico</file>
+ <file>icons/arrow-l.png</file>
+ <file>icons/content.png</file>
+ <file>icons/directory2.png</file>
+ <file>icons/directory.png</file>
+ <file>icons/hotlist-add.png</file>
+ <file>icons/hotlist-rmv.png</file>
+ <file>icons/search.png</file>
</gresource>
</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index d1c3c86..1998034 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -36,6 +36,12 @@
#include "gtk/compat.h"
#include "gtk/resources.h"
+/** log contents of gresource /org/netsource */
+#ifdef WITH_GRESOURCE
+#define SHOW_GRESOURCE
+#undef SHOW_GRESOURCE
+#endif
+
#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
@@ -44,12 +50,15 @@ extern const guint8 menu_cursor_pixdata[];
#endif
#endif
+/** type of resource entry */
enum nsgtk_resource_type_e {
- NSGTK_RESOURCE_FILE,
- NSGTK_RESOURCE_GLIB,
- NSGTK_RESOURCE_INLINE,
+ NSGTK_RESOURCE_FILE, /**< entry is a file on disc */
+ NSGTK_RESOURCE_GLIB, /**< entry is a gresource accessed by path */
+ NSGTK_RESOURCE_DIRECT, /**< entry is a gresource accesed by gbytes */
+ NSGTK_RESOURCE_INLINE, /**< entry is compiled in accessed by pointer */
};
+/** resource entry */
struct nsgtk_resource_s {
const char *name;
unsigned int len;
@@ -57,39 +66,63 @@ struct nsgtk_resource_s {
char *path;
};
+#define RES_ENTRY(name) { name, sizeof((name)) - 1, NSGTK_RESOURCE_FILE, NULL }
+
+/** resources that are used for gtk builder */
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 },
+ RES_ENTRY("netsurf"),
+ RES_ENTRY("tabcontents"),
+ RES_ENTRY("password"),
+ RES_ENTRY("login"),
+ RES_ENTRY("ssl"),
+ RES_ENTRY("toolbar"),
+ RES_ENTRY("downloads"),
+ RES_ENTRY("history"),
+ RES_ENTRY("options"),
+ RES_ENTRY("hotlist"),
+ RES_ENTRY("cookies"),
+ RES_ENTRY("viewdata"),
+ RES_ENTRY("warning"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
-static struct nsgtk_resource_s gen_resource[] = {
- { "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
- { "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL },
- { "menu_cursor.png", 15, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber0.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber1.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber2.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber3.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber4.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber5.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber6.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber7.png", 22, NSGTK_RESOURCE_FILE, NULL },
- { "throbber/throbber8.png", 22, NSGTK_RESOURCE_FILE, NULL },
+/** resources that are used as pixbufs */
+static struct nsgtk_resource_s pixbuf_resource[] = {
+ RES_ENTRY("favicon.png"),
+ RES_ENTRY("netsurf.xpm"),
+ RES_ENTRY("menu_cursor.png"),
+ RES_ENTRY("throbber/throbber0.png"),
+ RES_ENTRY("throbber/throbber1.png"),
+ RES_ENTRY("throbber/throbber2.png"),
+ RES_ENTRY("throbber/throbber3.png"),
+ RES_ENTRY("throbber/throbber4.png"),
+ RES_ENTRY("throbber/throbber5.png"),
+ RES_ENTRY("throbber/throbber6.png"),
+ RES_ENTRY("throbber/throbber7.png"),
+ RES_ENTRY("throbber/throbber8.png"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
+/** resources that are used for direct data access */
+static struct nsgtk_resource_s direct_resource[] = {
+ RES_ENTRY("welcome.html"),
+ RES_ENTRY("credits.html"),
+ RES_ENTRY("licence.html"),
+ RES_ENTRY("maps.html"),
+ RES_ENTRY("internal.css"),
+ RES_ENTRY("netsurf.png"),
+ RES_ENTRY("default.ico"),
+ RES_ENTRY("icons/arrow-l.png"),
+ RES_ENTRY("icons/content.png"),
+ RES_ENTRY("icons/directory2.png"),
+ RES_ENTRY("icons/directory.png"),
+ RES_ENTRY("icons/hotlist-add.png"),
+ RES_ENTRY("icons/hotlist-rmv.png"),
+ RES_ENTRY("icons/search.png"),
+ { NULL, 0, NSGTK_RESOURCE_FILE, NULL },
+};
+
+
/* exported interface documented in gtk/resources.h */
GdkCursor *nsgtk_create_menu_cursor(void)
{
@@ -98,7 +131,6 @@ GdkCursor *nsgtk_create_menu_cursor(void)
nserror res;
const char *resname = "menu_cursor.png";
-
res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf);
if (res == NSERROR_OK) {
cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
@@ -110,7 +142,7 @@ GdkCursor *nsgtk_create_menu_cursor(void)
}
-/*
+/**
* locate a resource
*
* The way GTK accesses resource files has changed greatly between
@@ -122,24 +154,48 @@ GdkCursor *nsgtk_create_menu_cursor(void)
* instead.
*
* \param respath A string vector containing the valid resource search paths
- * \param ui_res A resource entry to initialise
+ * \param resource A resource entry to initialise
*/
static nserror
init_resource(char **respath, struct nsgtk_resource_s *resource)
{
char *resname;
-#ifdef WITH_BUILTIN_PIXBUF
- if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) {
- resource->path = (char *)&menu_cursor_pixdata[0];
- resource->type = NSGTK_RESOURCE_INLINE;
- LOG("Found builtin for %s", resource->name);
- return NSERROR_OK;
- }
-#endif
#ifdef WITH_GRESOURCE
int resnamelen;
gboolean present;
+ const gchar * const *langv;
+ int langc = 0;
+
+ langv = g_get_language_names();
+
+ while (langv[langc] != NULL) {
+ resnamelen = snprintf(NULL, 0,
+ "/org/netsurf/%s/%s",
+ langv[langc], resource->name);
+
+ resname = malloc(resnamelen + 1);
+ if (resname == NULL) {
+ return NSERROR_NOMEM;
+ }
+ snprintf(resname, resnamelen + 1,
+ "/org/netsurf/%s/%s",
+ langv[langc], 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_GLIB;
+ LOG("Found gresource path %s", resource->path);
+ return NSERROR_OK;
+ }
+ /*LOG("gresource \"%s\" not found", resname);*/
+ free(resname);
+ langc++;
+ }
resnamelen = snprintf(NULL, 0, "/org/netsurf/%s", resource->name);
resname = malloc(resnamelen + 1);
@@ -158,8 +214,9 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)
LOG("Found gresource path %s", resource->path);
return NSERROR_OK;
}
- LOG("gresource \"%s\" not found", resname);
+ /*LOG("gresource \"%s\" not found", resname);*/
free(resname);
+
#endif
resname = filepath_find(respath, resource->name);
@@ -177,7 +234,61 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)
return NSERROR_OK;
}
-/*
+/**
+ * locate and setup a direct resource
+ *
+ * Direct resources have general type of NSGTK_RESOURCE_GLIB but have
+ * g_resources_lookup_data() applied and the result stored so the data
+ * can be directly accessed without additional processing.
+ *
+ * \param respath A string vector containing the valid resource search paths
+ * \param resource A resource entry to initialise
+ */
+static nserror
+init_direct_resource(char **respath, struct nsgtk_resource_s *resource)
+{
+ nserror res;
+ GBytes *data;
+
+ res = init_resource(respath, resource);
+ if ((res == NSERROR_OK) &&
+ (resource->type == NSGTK_RESOURCE_GLIB)) {
+ /* found gresource we can convert */
+ data = g_resources_lookup_data(resource->path,
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ NULL);
+ if (data != NULL) {
+ resource->type = NSGTK_RESOURCE_DIRECT;
+ resource->path = (char *)data;
+ }
+ }
+
+ return res;
+}
+
+/**
+ * locate a pixbuf resource
+ *
+ * Pixbuf resources can be compiled inline
+ *
+ * \param respath A string vector containing the valid resource search paths
+ * \param resource A resource entry to initialise
+ */
+static nserror
+init_pixbuf_resource(char **respath, struct nsgtk_resource_s *resource)
+{
+#ifdef WITH_BUILTIN_PIXBUF
+ if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) {
+ resource->path = (char *)&menu_cursor_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
+#endif
+ return init_resource(respath, resource);
+}
+
+/**
* locate a ui resource
*
* UI resources need their resource name changing to account for gtk versions
@@ -218,38 +329,67 @@ static nserror init_ui_resource(char **respath, struct nsgtk_resource_s *ui_res)
return res;
}
-#define SHOW_GRESOURCE
-
/**
- * Initialise UI resource table
+ * Find a resource entry by name.
*
+ * \param resname The resource name to match.
+ * \param resource The list of resources entries to search.
*/
-nserror nsgtk_init_resources(char **respath)
+static struct nsgtk_resource_s *
+find_resource_from_name(const char *resname, struct nsgtk_resource_s *resource)
{
- struct nsgtk_resource_s *resource;
- nserror res;
+ /* find resource from name */
+ while ((resource->name != NULL) &&
+ ((resname[0] != resource->name[0]) ||
+ (strncmp(resource->name, resname, resource->len) != 0))) {
+ resource++;
+ }
+ return resource;
+}
#ifdef SHOW_GRESOURCE
+/**
+ * Debug dump of all resources compile din via GResource.
+ */
+static void list_gresource(void)
+{
const char *nspath = "/org/netsurf";
char **reslist;
char **cur;
GError* gerror = NULL;
- reslist = g_resources_enumerate_children(nspath,G_RESOURCE_LOOKUP_FLAGS_NONE, &gerror);
+ 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);
+ 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 */
+/**
+ * Initialise UI resource table
+ *
+ */
+/* exported interface documented in gtk/resources.h */
+nserror nsgtk_init_resources(char **respath)
+{
+ struct nsgtk_resource_s *resource;
+ nserror res;
+
+#ifdef SHOW_GRESOURCE
+ list_gresource();
+#endif
+
+ /* iterate the ui resource table and initialise all its members */
resource = &ui_resource[0];
while (resource->name != NULL) {
res = init_ui_resource(respath, resource);
@@ -259,31 +399,29 @@ nserror nsgtk_init_resources(char **respath)
resource++;
}
- /* walk the general resource table and initialise all its members */
- resource = &gen_resource[0];
+ /* iterate the pixbuf resource table and initialise all its members */
+ resource = &pixbuf_resource[0];
while (resource->name != NULL) {
- res = init_resource(respath, resource);
+ res = init_pixbuf_resource(respath, resource);
if (res != NSERROR_OK) {
return res;
}
resource++;
}
+ /* iterate the direct resource table and initialise all its members */
+ resource = &direct_resource[0];
+ while (resource->name != NULL) {
+ res = init_direct_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
@@ -293,7 +431,7 @@ nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
GdkPixbuf *new_pixbuf = NULL;
GError* error = NULL;
- resource = find_resource_from_name(resname, &gen_resource[0]);
+ resource = find_resource_from_name(resname, &pixbuf_resource[0]);
if (resource->name == NULL) {
return NSERROR_NOT_FOUND;
}
@@ -309,9 +447,13 @@ nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
case NSGTK_RESOURCE_INLINE:
#ifdef WITH_BUILTIN_PIXBUF
- new_pixbuf = gdk_pixbuf_new_from_inline(-1, (const guint8 *)resource->path, FALSE, NULL);
+ new_pixbuf = gdk_pixbuf_new_from_inline(-1, (const guint8 *)resource->path, FALSE, &error);
#endif
break;
+
+ case NSGTK_RESOURCE_DIRECT:
+ /* pixbuf resources are not currently direct */
+ break;
}
if (new_pixbuf == NULL) {
LOG("Unable to create pixbuf from file for %s with path %s \"%s\"",
@@ -365,3 +507,35 @@ nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
return NSERROR_OK;
}
+
+/* exported interface documented in gtk/resources.h */
+nserror
+nsgtk_data_from_resname(const char *resname,
+ const uint8_t ** data_out,
+ size_t *data_size_out)
+{
+ struct nsgtk_resource_s *resource;
+ GBytes *data;
+ const gchar *buffer;
+ gsize buffer_length;
+
+ resource = find_resource_from_name(resname, &direct_resource[0]);
+ if ((resource->name == NULL) ||
+ (resource->type != NSGTK_RESOURCE_DIRECT)) {
+ return NSERROR_NOT_FOUND;
+ }
+
+ data = (GBytes *)resource->path;
+
+ buffer_length = 0;
+ buffer = g_bytes_get_data(data, &buffer_length);
+
+ if (buffer == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ *data_out = (const uint8_t *)buffer;
+ *data_size_out = (size_t)buffer_length;
+
+ return NSERROR_OK;
+}
diff --git a/gtk/resources.h b/gtk/resources.h
index 7c3e73d..dd52f54 100644
--- a/gtk/resources.h
+++ b/gtk/resources.h
@@ -16,18 +16,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Interface to gtk builtin resource handling.
+ *
+ * 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.
+ *
+ */
+
#ifndef NETSURF_GTK_RESOURCES_H
#define NETSURF_GTK_RESOURCES_H 1
/**
- * Creates a menu cursor from internal resources
+ * Initialise GTK resources handling.
+ *
+ * Must be called before attempting to retrieve any resources but
+ * after logging is initialised as it logs.
+ *
+ * \param respath A string vector of paths to search for resources.
+ * \return NSERROR_OK if all resources were located else an
+ * appropriate error code.
*/
-GdkCursor *nsgtk_create_menu_cursor(void);
-
nserror nsgtk_init_resources(char **respath);
/**
- * Create gtk builder object for the named ui resource
+ * Creates a menu cursor from internal resources.
+ *
+ * \return Cursor object or NULL on error.
+ */
+GdkCursor *nsgtk_create_menu_cursor(void);
+
+/**
+ * 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.
@@ -44,7 +66,7 @@ nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder
/**
- * Create gdk pixbuf for the named ui resource
+ * 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
@@ -56,4 +78,20 @@ nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder
*/
nserror nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out);
+/**
+ * Get direct pointer to resource data.
+ *
+ * For a named resource this obtains a direct acesss pointer to the
+ * data and its length.
+ *
+ * The data is read only through this pointer and remains valid until
+ * program exit.
+ *
+ * \param resname The resource name to obtain data for.
+ * \param data_out The resulting data.
+ * \param data_size_out The resulting data size.
+ * \return NSERROR_OK and data_out updated or appropriate error code.
+ */
+nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out);
+
#endif
diff --git a/gtk/throbber.c b/gtk/throbber.c
index 725df46..9392c39 100644
--- a/gtk/throbber.c
+++ b/gtk/throbber.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <gtk/gtk.h>
+#include <stdint.h>
#include "utils/log.h"
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=e9b89f776db705ee440...
commit e9b89f776db705ee4403a2235ec21aabab12c8f6
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Allow the resource scheme to provide data directly.
This allows front ends to provide resources from compiled in data
instead of requiring the resources to be available on disc and forcing
a redirect.
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index 1a439aa..6472dc5 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -52,26 +52,7 @@
#include "content/fetchers/resource.h"
#include "content/urldb.h"
-struct fetch_resource_context;
-
-typedef bool (*fetch_resource_handler)(struct fetch_resource_context *);
-
-/** Context for an resource fetch */
-struct fetch_resource_context {
- struct fetch_resource_context *r_next, *r_prev;
-
- struct fetch *fetchh; /**< Handle for this fetch */
-
- bool aborted; /**< Flag indicating fetch has been aborted */
- bool locked; /**< Flag indicating entry is already entered */
-
- nsurl *url;
- nsurl *redirect_url; /**< The url the fetch redirects to */
-
- fetch_resource_handler handler;
-};
-
-static struct fetch_resource_context *ring = NULL;
+#define DIRECT_ETAG_VALUE 123456
/** Valid resource paths */
static const char *fetch_resource_paths[] = {
@@ -95,11 +76,41 @@ static const char *fetch_resource_paths[] = {
"icons/hotlist-rmv.png",
"icons/search.png"
};
+
+/**
+ * map of resource scheme paths to redirect urls
+ */
static struct fetch_resource_map_entry {
- lwc_string *path;
- nsurl *url;
+ lwc_string *path; /**< resource scheme path */
+ nsurl *redirect_url; /**< url to redirect to */
+ const uint8_t *data; /**< direct pointer to data */
+ size_t data_len; /**< length of direct data */
} fetch_resource_map[NOF_ELEMENTS(fetch_resource_paths)];
+struct fetch_resource_context;
+
+typedef bool (*fetch_resource_handler)(struct fetch_resource_context *);
+
+/** Context for an resource fetch */
+struct fetch_resource_context {
+ struct fetch_resource_context *r_next, *r_prev;
+
+ struct fetch *fetchh; /**< Handle for this fetch */
+
+ bool aborted; /**< Flag indicating fetch has been aborted */
+ bool locked; /**< Flag indicating entry is already entered */
+
+ nsurl *url; /**< requested url */
+
+ struct fetch_resource_map_entry *entry; /**< resource map entry */
+
+ fetch_resource_handler handler;
+
+ int etag;
+};
+
+static struct fetch_resource_context *ring = NULL;
+
static uint32_t fetch_resource_path_count;
/** issue fetch callbacks with locking */
@@ -136,7 +147,9 @@ static bool fetch_resource_send_header(struct fetch_resource_context *ctx,
-
+/**
+ * resource handler that results in a redirect to another url.
+ */
static bool fetch_resource_redirect_handler(struct fetch_resource_context *ctx)
{
fetch_msg msg;
@@ -145,12 +158,65 @@ static bool fetch_resource_redirect_handler(struct fetch_resource_context *ctx)
fetch_set_http_code(ctx->fetchh, 302);
msg.type = FETCH_REDIRECT;
- msg.data.redirect = nsurl_access(ctx->redirect_url);
- fetch_resource_send_callback(&msg, ctx);
+ msg.data.redirect = nsurl_access(ctx->entry->redirect_url);
+ fetch_resource_send_callback(&msg, ctx);
return true;
}
+/* resource handler that returns data directly */
+static bool fetch_resource_data_handler(struct fetch_resource_context *ctx)
+{
+ fetch_msg msg;
+
+ /* Check if we can just return not modified */
+ if (ctx->etag != 0 && ctx->etag == DIRECT_ETAG_VALUE) {
+ fetch_set_http_code(ctx->fetchh, 304);
+ msg.type = FETCH_NOTMODIFIED;
+ fetch_resource_send_callback(&msg, ctx);
+ return true;
+ }
+
+ /* fetch is going to be successful */
+ fetch_set_http_code(ctx->fetchh, 200);
+
+ /* Any callback can result in the fetch being aborted.
+ * Therefore, we _must_ check for this after _every_ call to
+ * fetch_file_send_callback().
+ */
+
+ /* content type */
+ if (fetch_resource_send_header(ctx, "Content-Type: %s",
+ guit->fetch->filetype(lwc_string_data(ctx->entry->path))))
+ goto fetch_resource_data_aborted;
+
+ /* content length */
+ if (fetch_resource_send_header(ctx,
+ "Content-Length: %"SSIZET_FMT,
+ ctx->entry->data_len))
+ goto fetch_resource_data_aborted;
+
+ /* create etag */
+ if (fetch_resource_send_header(ctx,
+ "ETag: \"%10" PRId64 "\"",
+ (int64_t) DIRECT_ETAG_VALUE))
+ goto fetch_resource_data_aborted;
+
+
+ msg.type = FETCH_DATA;
+ msg.data.header_or_data.buf = (const uint8_t *) ctx->entry->data;
+ msg.data.header_or_data.len = ctx->entry->data_len;
+ fetch_resource_send_callback(&msg, ctx);
+
+ if (ctx->aborted == false) {
+ msg.type = FETCH_FINISHED;
+ fetch_resource_send_callback(&msg, ctx);
+ }
+
+fetch_resource_data_aborted:
+
+ return true;
+}
static bool fetch_resource_notfound_handler(struct fetch_resource_context *ctx)
{
@@ -195,6 +261,7 @@ static bool fetch_resource_initialise(lwc_string *scheme)
{
struct fetch_resource_map_entry *e;
uint32_t i;
+ nserror res;
fetch_resource_path_count = 0;
@@ -207,15 +274,26 @@ static bool fetch_resource_initialise(lwc_string *scheme)
while (i > 0) {
i--;
lwc_string_unref(fetch_resource_map[i].path);
- nsurl_unref(fetch_resource_map[i].url);
+ nsurl_unref(fetch_resource_map[i].redirect_url);
}
+ /** \todo should this exit with an error condition? */
}
- e->url = guit->fetch->get_resource_url(fetch_resource_paths[i]);
- if (e->url == NULL) {
- lwc_string_unref(e->path);
- } else {
+ e->data = NULL;
+ res = guit->fetch->get_resource_data(lwc_string_data(e->path),
+ &e->data,
+ &e->data_len);
+ if (res == NSERROR_OK) {
+ LOG("direct data for %s", fetch_resource_paths[i]);
fetch_resource_path_count++;
+ } else {
+ e->redirect_url = guit->fetch->get_resource_url(fetch_resource_paths[i]);
+ if (e->redirect_url == NULL) {
+ lwc_string_unref(e->path);
+ } else {
+ LOG("redirect url for %s", fetch_resource_paths[i]);
+ fetch_resource_path_count++;
+ }
}
}
@@ -229,7 +307,11 @@ static void fetch_resource_finalise(lwc_string *scheme)
for (i = 0; i < fetch_resource_path_count; i++) {
lwc_string_unref(fetch_resource_map[i].path);
- nsurl_unref(fetch_resource_map[i].url);
+ if (fetch_resource_map[i].data != NULL) {
+ guit->fetch->release_resource_data(fetch_resource_map[i].data);
+ } else {
+ nsurl_unref(fetch_resource_map[i].redirect_url);
+ }
}
}
@@ -238,38 +320,44 @@ static bool fetch_resource_can_fetch(const nsurl *url)
return true;
}
-/** callback to set up a resource fetch context. */
+/**
+ * set up a resource fetch context.
+ */
static void *
fetch_resource_setup(struct fetch *fetchh,
- nsurl *url,
- bool only_2xx,
- bool downgrade_tls,
- const char *post_urlenc,
- const struct fetch_multipart_data *post_multipart,
- const char **headers)
+ nsurl *url,
+ bool only_2xx,
+ bool downgrade_tls,
+ const char *post_urlenc,
+ const struct fetch_multipart_data *post_multipart,
+ const char **headers)
{
struct fetch_resource_context *ctx;
lwc_string *path;
+ uint32_t i;
ctx = calloc(1, sizeof(*ctx));
- if (ctx == NULL)
+ if (ctx == NULL) {
return NULL;
+ }
ctx->handler = fetch_resource_notfound_handler;
if ((path = nsurl_get_component(url, NSURL_PATH)) != NULL) {
- uint32_t i;
bool match;
/* Ensure requested path is valid */
for (i = 0; i < fetch_resource_path_count; i++) {
- if (lwc_string_isequal(path,
- fetch_resource_map[i].path,
+ if (lwc_string_isequal(path,
+ fetch_resource_map[i].path,
&match) == lwc_error_ok && match) {
- ctx->redirect_url =
- nsurl_ref(fetch_resource_map[i].url);
- ctx->handler =
- fetch_resource_redirect_handler;
+ /* found a url match, select handler */
+ ctx->entry = &fetch_resource_map[i];
+ if (ctx->entry->data != NULL) {
+ ctx->handler = fetch_resource_data_handler;
+ } else {
+ ctx->handler = fetch_resource_redirect_handler;
+ }
break;
}
}
@@ -279,6 +367,23 @@ fetch_resource_setup(struct fetch *fetchh,
ctx->url = nsurl_ref(url);
+ /* Scan request headers looking for If-None-Match */
+ for (i = 0; headers[i] != NULL; i++) {
+ if (strncasecmp(headers[i], "If-None-Match:",
+ SLEN("If-None-Match:")) == 0) {
+ /* If-None-Match: "12345678" */
+ const char *d = headers[i] + SLEN("If-None-Match:");
+
+ /* Scan to first digit, if any */
+ while (*d != '\0' && (*d < '0' || '9' < *d))
+ d++;
+
+ /* Convert to time_t */
+ if (*d != '\0')
+ ctx->etag = atoi(d);
+ }
+ }
+
ctx->fetchh = fetchh;
RING_INSERT(ring, ctx);
@@ -290,8 +395,6 @@ fetch_resource_setup(struct fetch *fetchh,
static void fetch_resource_free(void *ctx)
{
struct fetch_resource_context *c = ctx;
- if (c->redirect_url != NULL)
- nsurl_unref(c->redirect_url);
if (c->url != NULL)
nsurl_unref(c->url);
RING_REMOVE(ring, c);
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 50244e3..22364ab 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -501,6 +501,16 @@ static nsurl *gui_default_get_resource_url(const char *path)
return NULL;
}
+static nserror gui_default_get_resource_data(const char *path, const uint8_t **data, size_t *data_len)
+{
+ return NSERROR_NOT_FOUND;
+}
+
+static nserror gui_default_release_resource_data(const uint8_t *data)
+{
+ return NSERROR_OK;
+}
+
static char *gui_default_mimetype(const char *path)
{
return strdup(guit->fetch->filetype(path));
@@ -523,6 +533,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
if (gft->get_resource_url == NULL) {
gft->get_resource_url = gui_default_get_resource_url;
}
+ if (gft->get_resource_data == NULL) {
+ gft->get_resource_data = gui_default_get_resource_data;
+ }
+ if (gft->release_resource_data == NULL) {
+ gft->release_resource_data = gui_default_release_resource_data;
+ }
if (gft->mimetype == NULL) {
gft->mimetype = gui_default_mimetype;
}
diff --git a/desktop/gui_fetch.h b/desktop/gui_fetch.h
index 46d31e0..20db39d 100644
--- a/desktop/gui_fetch.h
+++ b/desktop/gui_fetch.h
@@ -47,9 +47,9 @@ struct gui_fetch_table {
/* Optional entries */
/**
- * Callback to translate resource to full url.
+ * Translate resource to full url.
*
- * @note used in resource fetcher
+ * @note Only used in resource fetcher
*
* Transforms a resource: path into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
@@ -62,6 +62,33 @@ struct gui_fetch_table {
struct nsurl* (*get_resource_url)(const char *path);
/**
+ * Translate resource to source data.
+ *
+ * @note Only used in resource fetcher
+ *
+ * Obtains the data for a resource directly
+ *
+ * \param path The path of the resource to locate.
+ * \param data Pointer to recive data into
+ * \param data_len Pointer to length of returned data
+ * \return NSERROR_OK and the data and length values updated
+ * else appropriate error code.
+ */
+ nserror (*get_resource_data)(const char *path, const uint8_t **data, size_t *data_len);
+
+ /**
+ * Releases source data.
+ *
+ * @note Only used in resource fetcher
+ *
+ * Releases source data obtained from get_resource_data()
+ *
+ * \param data The value returned from a previous get_resource_data call
+ * \return NSERROR_OK on success else appropriate error code.
+ */
+ nserror (*release_resource_data)(const uint8_t *data);
+
+ /**
* Find a MIME type for a local file
*
* @note only used in curl fetcher on RISC OS otherwise its a
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=be7a45fefed2736f7ed...
commit be7a45fefed2736f7ed7f1799e9f2b1cd52235b7
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Change gtk to use resource API for throbber
diff --git a/gtk/gui.c b/gtk/gui.c
index 90991da..1df7bfc 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -84,8 +84,6 @@ GdkPixbuf *win_default_icon_pixbuf; /** default window icon pixbuf */
GtkBuilder *warning_builder;
-#define THROBBER_FRAMES 9
-
char **respaths; /** resource search path vector */
/**
@@ -125,36 +123,6 @@ nsgtk_init_resource(const char *resource_path)
return respath;
}
-/* This is an ugly hack to just get the new-style throbber going.
- * It, along with the PNG throbber loader, need making more generic.
- */
-static bool nsgtk_throbber_init(char **respath, int framec)
-{
- char **filenames;
- char targetname[PATH_MAX];
- int frame_num;
- bool ret;
-
- filenames = calloc(framec, sizeof(char *));
- if (filenames == NULL)
- return false;
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num);
- filenames[frame_num] = filepath_find(respath, targetname);
- }
-
- ret = nsgtk_throbber_initialise_from_png(frame_num, filenames);
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- free(filenames[frame_num]);
- }
- free(filenames);
-
- return ret;
-
-}
-
/**
* Set option defaults for gtk frontend.
@@ -307,9 +275,12 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
LOG("Using '%s' as custom toolbar settings file", toolbar_indices_file_location);
- /* load throbber images */
- if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
- die("Unable to load throbber image.\n");
+ /* initialise throbber */
+ error = nsgtk_throbber_init();
+ if (error != NSERROR_OK) {
+ LOG("Unable to initialise throbber.");
+ return error;
+ }
/* Initialise completions - cannot fail */
nsgtk_completion_init();
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
index 09683fa..55f3a3d 100644
--- a/gtk/res/netsurf.gresource.xml
+++ b/gtk/res/netsurf.gresource.xml
@@ -30,5 +30,14 @@
<file preprocess="to-pixdata">favicon.png</file>
<file preprocess="to-pixdata">netsurf.xpm</file>
<file preprocess="to-pixdata">menu_cursor.png</file>
+ <file preprocess="to-pixdata">throbber/throbber0.png</file>
+ <file preprocess="to-pixdata">throbber/throbber1.png</file>
+ <file preprocess="to-pixdata">throbber/throbber2.png</file>
+ <file preprocess="to-pixdata">throbber/throbber3.png</file>
+ <file preprocess="to-pixdata">throbber/throbber4.png</file>
+ <file preprocess="to-pixdata">throbber/throbber5.png</file>
+ <file preprocess="to-pixdata">throbber/throbber6.png</file>
+ <file preprocess="to-pixdata">throbber/throbber7.png</file>
+ <file preprocess="to-pixdata">throbber/throbber8.png</file>
</gresource>
</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index d28414d..d1c3c86 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -78,6 +78,15 @@ static struct nsgtk_resource_s gen_resource[] = {
{ "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
{ "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL },
{ "menu_cursor.png", 15, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber0.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber1.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber2.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber3.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber4.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber5.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber6.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber7.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber8.png", 22, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
diff --git a/gtk/throbber.c b/gtk/throbber.c
index 8726763..725df46 100644
--- a/gtk/throbber.c
+++ b/gtk/throbber.c
@@ -20,76 +20,61 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#ifdef WITH_GIF
-#include <libnsgif.h>
-#endif
+#include <gtk/gtk.h>
+
#include "utils/log.h"
+
+#include "gtk/resources.h"
#include "gtk/throbber.h"
-#include "gtk/bitmap.h"
struct nsgtk_throbber *nsgtk_throbber = NULL;
-/**
- * Creates the throbber using a PNG for each frame.
- *
- * The number of frames must be at least two. The first frame is the
- * inactive frame, others are the active frames.
- *
- * \param frames The number of frames. Must be at least two.
- * \param frame_files Filenames of PNGs containing frames.
- * \return true on success.
- */
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files)
+#define THROBBER_FRAMES 9
+#define THROBBER_FMT "throbber/throbber%d.png"
+
+/* exported interface documented in gtk/throbber.h */
+nserror nsgtk_throbber_init(void)
{
- GError *err = NULL;
struct nsgtk_throbber *throb; /**< structure we generate */
- bool errors_when_loading = false; /**< true if a frame failed */
- int frame_loop;
-
- if (frames < 2) {
- /* we need at least two frames - one for idle, one for active */
- LOG("Insufficent number of frames in throbber animation!");
- LOG("(called with %d frames, where 2 is a minimum.)", frames);
- return false;
- }
-
+ int frame;
+ char resname[] = THROBBER_FMT;
+ nserror res = NSERROR_OK;
+
throb = malloc(sizeof(*throb));
- if (throb == NULL)
- return false;
+ if (throb == NULL) {
+ return NSERROR_NOMEM;
+ }
- throb->nframes = frames;
- throb->framedata = malloc(sizeof(GdkPixbuf *) * throb->nframes);
+ throb->framedata = malloc(sizeof(GdkPixbuf *) * THROBBER_FRAMES);
if (throb->framedata == NULL) {
free(throb);
return false;
}
-
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- throb->framedata[frame_loop] = gdk_pixbuf_new_from_file(frame_files[frame_loop], &err);
- if (err != NULL) {
- LOG("Error when loading %s: %s (%d)", frame_files[frame_loop], err->message, err->code);
- throb->framedata[frame_loop] = NULL;
- errors_when_loading = true;
+
+ for (frame = 0; frame < THROBBER_FRAMES; frame++) {
+ snprintf(resname, sizeof(resname), THROBBER_FMT, frame);
+ res = nsgdk_pixbuf_new_from_resname(resname,
+ throb->framedata + frame);
+ if (res != NSERROR_OK) {
+ break;
}
+ LOG("%s",resname);
}
-
- if (errors_when_loading == true) {
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- if (throb->framedata[frame_loop] != NULL)
- g_object_unref(throb->framedata[frame_loop]);
- }
- free(throb->framedata);
- free(throb);
-
- return false;
+ if (frame < 1) {
+ /* we need at least two frames - one for idle, one for active */
+ LOG("Insufficent number of frames (%d) in throbber animation.", frame);
+ res = NSERROR_INIT_FAILED;
}
-
+
+ throb->nframes = frame;
nsgtk_throbber = throb;
-
- return true;
+ return res;
+
+
}
+
void nsgtk_throbber_finalise(void)
{
int i;
diff --git a/gtk/throbber.h b/gtk/throbber.h
index 1463c9b..e0b47e1 100644
--- a/gtk/throbber.h
+++ b/gtk/throbber.h
@@ -29,7 +29,7 @@ struct nsgtk_throbber
extern struct nsgtk_throbber *nsgtk_throbber;
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files);
+nserror nsgtk_throbber_init(void);
void nsgtk_throbber_finalise(void);
#endif /* __GTK_THROBBER_H__ */
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=3e2270482f735289497...
commit 3e2270482f73528949746fc24a01d0f0c01baee8
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Make GTK resource handling configurable
This makes the GTK resource handling configurable in the same way as
all other pkg-config style feature options.
It is now possible to completely disable compiled in resources if
wanted as well as forcing inline pixdata on if desired.
diff --git a/Docs/BUILDING-GTK b/Docs/BUILDING-GTK
index dab2bef..4ac0fc8 100644
--- a/Docs/BUILDING-GTK
+++ b/Docs/BUILDING-GTK
@@ -168,12 +168,14 @@
Building and executing NetSurf
--------------------------------
- First of all, you should examine the contents of Makefile.defaults
- and enable and disable relevant features as you see fit by creating
- a Makefile.config file. Some of these options can be automatically
- detected and used, and where this is the case they are set to such.
- Others cannot be automatically detected from the Makefile, so you
- will either need to install the dependencies, or set them to NO.
+ First of all, you should examine the options in Makefile.defaults
+ and gtk/Makefile.defaults and enable and disable relevant features
+ as you see fit by editing a Makefile.config file.
+
+ Some of these options can be automatically detected and used, and
+ where this is the case they are set to such. Others cannot be
+ automatically detected from the Makefile, so you will either need to
+ install the dependencies, or set them to NO.
You should then obtain NetSurf's dependencies, keeping in mind which options
you have enabled in the configuration file. See the next section for
@@ -197,6 +199,38 @@
sets up some environment variables which enable NetSurf to find its
resources.
+ Builtin resources
+-------------------
+
+ There are numerous resources that accompany NetSurf, such as the
+ image files for icons, cursors and the ui builder files that
+ construct the browsers interface.
+
+ Some of these resources can be compiled into the browser executable
+ removing the need to install these resources separately. The GLib
+ library on which GTK is based provides this functionality to
+ NetSurf.
+
+ Up until GLib version 2.32 only the GDK pixbuf could be integrated
+ in this way and is controlled with the NETSURF_USE_INLINE_PIXBUF
+ variable (set in makefile.config).
+
+ Glib version 2.32 and later integrated support for any file to be a
+ resource while depreciating the old inline pixbuf interface. NetSurf
+ gtk executables can integrate many resources using this interface,
+ configuration is controlled with the NETSURF_USE_GRESOURCE variable.
+
+ Loading from file is the fallback if a resource has not been
+ compiled in, because of this if both of these features are
+ unavailable (or disabled) NetSurf will automatically fall back to
+ loading all its resources from files.
+
+ The resource initialisation within the browser ensures it can access
+ all the resources at start time, however it does not verify the
+ resources are valid so failures could still occur subsequently. This
+ is especially true for file based resources as they can become
+ inaccessible after initialisation.
+
Note for packagers
====================
diff --git a/gtk/Makefile.defaults b/gtk/Makefile.defaults
index 51aa027..0f229d8 100644
--- a/gtk/Makefile.defaults
+++ b/gtk/Makefile.defaults
@@ -21,6 +21,17 @@ NETSURF_USE_NSSVG := AUTO
# Valid options: YES, NO, AUTO
NETSURF_USE_ROSPRITE := AUTO
+# Enable the use of GLib compiled in resource handling. This requires
+# GLib 2.32 or later
+# Valid options: YES, NO, AUTO
+NETSURF_USE_GRESOURCE := AUTO
+
+# Enable the use of compiled in inline pixbuf. This is depricated
+# since GLib 2.32. The automatic selection is disabled if GRESOURCE
+# handling is enabled
+# Valid options: YES, NO, AUTO
+NETSURF_USE_INLINE_PIXBUF := AUTO
+
# Enable building the source object cache filesystem based backing store.
NETSURF_FS_BACKING_STORE := YES
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index bbe5d5f..cc85162 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -87,13 +87,20 @@ 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.
+# this feature in a way similar to the pkg_config_find_and_add_enabled
+# macro. 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)
+#
+NETSURF_FEATURE_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes)
+ifneq (,$(filter $(NETSURF_USE_GRESOURCE),AUTO YES))
+ifeq ($(NETSURF_FEATURE_GRESOURCE_AVAILABLE),yes)
+
+# Gresource use has been enabled
+NETSURF_FEATURE_GRESOURCE_ENABLED := yes
#resource compiler tool
GLIB_COMPILE_RESOURCES := glib-compile-resources
@@ -106,10 +113,15 @@ 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=$@ $<
+ $(VQ)echo "GRESORCE: $<"
+ $(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+
+endif
+endif
-else
-# No GResource available so build pixbufs as inlines instead
+# Build pixbufs as inlines if enabled
+ifneq (,$(filter $(NETSURF_USE_INLINE_PIXBUF),AUTO YES))
+ifneq ($(NETSURF_FEATURE_GRESOURCE_ENABLED),yes)
CFLAGS += -DWITH_BUILTIN_PIXBUF
@@ -124,6 +136,7 @@ define convert_image
S_RESOURCE += $(2)
$(2): $(1)
+ $(VQ)echo " INLINE: ${3}"
$(Q)echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $(2)
$(Q)gdk-pixbuf-csource --extern --raw --name=$(3) $(1) >> $(2) || \
( rm -f $(2) && false )
@@ -131,7 +144,7 @@ $(2): $(1)
endef
$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
-
+endif
endif
# ----------------------------------------------------------------------------
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
index 03e4be2..09683fa 100644
--- a/gtk/res/netsurf.gresource.xml
+++ b/gtk/res/netsurf.gresource.xml
@@ -27,7 +27,8 @@
<file>password.gtk2.ui</file>
<file>tabcontents.gtk3.ui</file>
<file>warning.gtk2.ui</file>
- <file>favicon.png</file>
- <file>netsurf.xpm</file>
+ <file preprocess="to-pixdata">favicon.png</file>
+ <file preprocess="to-pixdata">netsurf.xpm</file>
+ <file preprocess="to-pixdata">menu_cursor.png</file>
</gresource>
</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index e3e044e..d28414d 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -118,7 +118,6 @@ GdkCursor *nsgtk_create_menu_cursor(void)
static nserror
init_resource(char **respath, struct nsgtk_resource_s *resource)
{
- int resnamelen;
char *resname;
#ifdef WITH_BUILTIN_PIXBUF
if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) {
@@ -129,6 +128,7 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)
}
#endif
#ifdef WITH_GRESOURCE
+ int resnamelen;
gboolean present;
resnamelen = snprintf(NULL, 0, "/org/netsurf/%s", resource->name);
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=59fbd51a77a684c15b1...
commit 59fbd51a77a684c15b189f666e4359bfd820f627
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Add legacy support for inline pixbuf usage
Before GResource it was possible to compile pixbufs as inline
elements. This has historically been done for the menu cursor
only.
This change integrates the inline support and uses it when the
GResource support is not selected.
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index c31cca4..bbe5d5f 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -95,6 +95,7 @@ S_RESOURCE :=
NETSURF_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes)
ifeq ($(NETSURF_GRESOURCE_AVAILABLE),yes)
+#resource compiler tool
GLIB_COMPILE_RESOURCES := glib-compile-resources
CFLAGS += -DWITH_GRESOURCE
@@ -107,11 +108,10 @@ GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
$(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
+else
+# No GResource available so build pixbufs as inlines instead
-# ----------------------------------------------------------------------------
-# Builtin Pixbuf resources
-# ----------------------------------------------------------------------------
+CFLAGS += -DWITH_BUILTIN_PIXBUF
GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
@@ -130,13 +130,14 @@ $(2): $(1)
endef
+$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
+
+endif
+
# ----------------------------------------------------------------------------
# Source file setup
# ----------------------------------------------------------------------------
-
-$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
-
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c plotters.c \
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
diff --git a/gtk/resources.c b/gtk/resources.c
index 981131d..e3e044e 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -36,15 +36,18 @@
#include "gtk/compat.h"
#include "gtk/resources.h"
+#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
#else
extern const guint8 menu_cursor_pixdata[];
#endif
+#endif
enum nsgtk_resource_type_e {
NSGTK_RESOURCE_FILE,
- NSGTK_RESOURCE_BUILTIN,
+ NSGTK_RESOURCE_GLIB,
+ NSGTK_RESOURCE_INLINE,
};
struct nsgtk_resource_s {
@@ -74,6 +77,7 @@ static struct nsgtk_resource_s ui_resource[] = {
static struct nsgtk_resource_s gen_resource[] = {
{ "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
{ "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL },
+ { "menu_cursor.png", 15, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
@@ -82,10 +86,16 @@ GdkCursor *nsgtk_create_menu_cursor(void)
{
GdkCursor *cursor = NULL;
GdkPixbuf *pixbuf;
+ nserror res;
+ const char *resname = "menu_cursor.png";
+
- pixbuf = gdk_pixbuf_new_from_inline(-1, menu_cursor_pixdata, FALSE, NULL);
- cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 0, 3);
- g_object_unref (pixbuf);
+ res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf);
+ if (res == NSERROR_OK) {
+ cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
+ pixbuf, 0, 3);
+ g_object_unref(pixbuf);
+ }
return cursor;
}
@@ -110,7 +120,14 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)
{
int resnamelen;
char *resname;
-
+#ifdef WITH_BUILTIN_PIXBUF
+ if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) {
+ resource->path = (char *)&menu_cursor_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
+#endif
#ifdef WITH_GRESOURCE
gboolean present;
@@ -128,7 +145,7 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)
if (present == TRUE) {
/* found an entry in the resources */
resource->path = resname;
- resource->type = NSGTK_RESOURCE_BUILTIN;
+ resource->type = NSGTK_RESOURCE_GLIB;
LOG("Found gresource path %s", resource->path);
return NSERROR_OK;
}
@@ -264,7 +281,7 @@ nserror
nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
{
struct nsgtk_resource_s *resource;
- GdkPixbuf *new_pixbuf;
+ GdkPixbuf *new_pixbuf = NULL;
GError* error = NULL;
resource = find_resource_from_name(resname, &gen_resource[0]);
@@ -272,10 +289,20 @@ nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
return NSERROR_NOT_FOUND;
}
- if (resource->type == NSGTK_RESOURCE_FILE) {
+ switch (resource->type) {
+ case NSGTK_RESOURCE_FILE:
new_pixbuf = gdk_pixbuf_new_from_file(resource->path, &error);
- } else {
+ break;
+
+ case NSGTK_RESOURCE_GLIB:
new_pixbuf = gdk_pixbuf_new_from_resource(resource->path, &error);
+ break;
+
+ case NSGTK_RESOURCE_INLINE:
+#ifdef WITH_BUILTIN_PIXBUF
+ new_pixbuf = gdk_pixbuf_new_from_inline(-1, (const guint8 *)resource->path, FALSE, NULL);
+#endif
+ break;
}
if (new_pixbuf == NULL) {
LOG("Unable to create pixbuf from file for %s with path %s \"%s\"",
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=61fdc8fd6ffd24abf00...
commit 61fdc8fd6ffd24abf007598e33cde58fee2b9a83
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
update default gtk window icon source to use resources
diff --git a/gtk/gui.c b/gtk/gui.c
index eb7d2a2..90991da 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -79,7 +79,8 @@ char *themelist_file_location;
char *nsgtk_config_home; /* exported global defined in gtk/gui.h */
-GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+GdkPixbuf *favicon_pixbuf; /** favicon default pixbuf */
+GdkPixbuf *win_default_icon_pixbuf; /** default window icon pixbuf */
GtkBuilder *warning_builder;
@@ -281,10 +282,11 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
gtk_builder_connect_signals(warning_builder, NULL);
/* set default icon if its available */
- resource_filename = filepath_find(respath, "netsurf.xpm");
- if (resource_filename != NULL) {
- gtk_window_set_default_icon_from_file(resource_filename, NULL);
- free(resource_filename);
+ error = nsgdk_pixbuf_new_from_resname("netsurf.xpm",
+ &win_default_icon_pixbuf);
+ if (error == NSERROR_OK) {
+ LOG("Seting default window icon");
+ gtk_window_set_default_icon(win_default_icon_pixbuf);
}
/* Search engine sources */
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
index fb384a8..03e4be2 100644
--- a/gtk/res/netsurf.gresource.xml
+++ b/gtk/res/netsurf.gresource.xml
@@ -28,5 +28,6 @@
<file>tabcontents.gtk3.ui</file>
<file>warning.gtk2.ui</file>
<file>favicon.png</file>
+ <file>netsurf.xpm</file>
</gresource>
</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index d4e8b20..981131d 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -73,6 +73,7 @@ static struct nsgtk_resource_s ui_resource[] = {
static struct nsgtk_resource_s gen_resource[] = {
{ "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
+ { "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=8ef292b9caf5cae2197...
commit 8ef292b9caf5cae2197493a87480723138f10344
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
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.
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 01c00c2..c31cca4 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -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
diff --git a/gtk/compat.c b/gtk/compat.c
index 51469b2..4c5524b 100644
--- a/gtk/compat.c
+++ b/gtk/compat.c
@@ -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;
+}
diff --git a/gtk/compat.h b/gtk/compat.h
index 088cd79..9554b0c 100644
--- a/gtk/compat.h
+++ b/gtk/compat.h
@@ -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 */
diff --git a/gtk/cookies.c b/gtk/cookies.c
index cb59d0a..7b21dc9 100644
--- a/gtk/cookies.c
+++ b/gtk/cookies.c
@@ -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.
+ * Connects menu events in the cookies window.
*/
-bool nsgtk_cookies_init(const char *glade_file_location)
+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(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_treeview);
+ }
+ event++;
+ }
+}
+
+/* exported interface documented in gtk/cookies.h */
+nserror nsgtk_cookies_init(void)
{
- GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
+ nserror res;
- 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;
+ 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(gladeFile, NULL);
-
- wndCookies = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndCookies"));
- window = wndCookies;
-
- scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(gladeFile,
+
+ 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(gladeFile,
+ drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(cookie_builder,
"cookiesDrawingArea"));
-
- cookies_window = nsgtk_treeview_create(TREE_COOKIES, window,
- scrolled, drawing_area);
-
- if (cookies_window == NULL)
- return false;
-
+
+ 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(window, "delete_event", gtk_widget_hide_on_delete, NULL);
- CONNECT(window, "hide", nsgtk_tree_window_hide, cookies_window);
-
- nsgtk_cookies_init_menu();
+ g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
- return true;
-}
+ CONNECT(wndCookies, "delete_event", gtk_widget_hide_on_delete, NULL);
+ CONNECT(wndCookies, "hide", nsgtk_tree_window_hide, cookies_treeview);
-/**
- * Connects menu events in the cookies window.
- */
-void nsgtk_cookies_init_menu()
-{
- struct menu_events *event = menu_events;
- GtkWidget *w;
+ nsgtk_cookies_init_menu();
- while (event->widget != NULL) {
- w = GTK_WIDGET(gtk_builder_get_object(gladeFile, 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);
- }
- event++;
- }
+ 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);
}
diff --git a/gtk/cookies.h b/gtk/cookies.h
index db12dfe..2d5c56d 100644
--- a/gtk/cookies.h
+++ b/gtk/cookies.h
@@ -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);
diff --git a/gtk/download.c b/gtk/download.c
index 74b49f6..23832de 100644
--- a/gtk/download.c
+++ b/gtk/download.c
@@ -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();
-
- 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;
+ GtkBuilder* builder;
+ nserror res;
+
+ 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 ()
diff --git a/gtk/download.h b/gtk/download.h
index a6e624f..0b10976 100644
--- a/gtk/download.h
+++ b/gtk/download.h
@@ -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);
diff --git a/gtk/gui.c b/gtk/gui.c
index b8d8fc1..eb7d2a2 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -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;
-
- 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);
+ GtkBuilder *password_builder;
+ nserror res;
+
+ 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();
diff --git a/gtk/gui.h b/gtk/gui.h
index 63832f8..ce234c4 100644
--- a/gtk/gui.h
+++ b/gtk/gui.h
@@ -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;
diff --git a/gtk/history.c b/gtk/history.c
index 2dbedf9..db30c5b 100644
--- a/gtk/history.c
+++ b/gtk/history.c
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Rob Kendrick <rjek(a)rjek.com>
- * Copyright 2009 Paul Blokus <paul_pl(a)users.sourceforge.net>
+ * Copyright 2009 Paul Blokus <paul_pl(a)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,94 +64,102 @@ 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;
+/**
+ * Connects menu events in the global history window.
+ */
+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(history_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,
+ global_history_window);
+ }
+ event++;
+ }
+}
-/* exported interface, documented in gtk_history.h */
-bool nsgtk_history_init(const char *glade_file_location)
+/* exported interface, documented in gtk/history.h */
+nserror nsgtk_history_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
- GError* error = NULL;
+ nserror res;
- 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;
+ 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"));
- 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"));
+ 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;
+ }
- 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))
-
+ 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;
+ return NSERROR_OK;
}
-/**
- * Connects menu events in the global history window.
- */
-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));
- if (w == NULL) {
- LOG("Unable to connect menu widget ""%s""", event->widget);
- } else {
- g_signal_connect(G_OBJECT(w), "activate", event->handler, global_history_window);
- }
- event++;
- }
-}
/**
@@ -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;
diff --git a/gtk/history.h b/gtk/history.h
index ab3c10e..c0f7db2 100644
--- a/gtk/history.h
+++ b/gtk/history.h
@@ -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.
diff --git a/gtk/hotlist.c b/gtk/hotlist.c
index fed6ae7..8258e09 100644
--- a/gtk/hotlist.c
+++ b/gtk/hotlist.c
@@ -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,74 +90,74 @@ 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;
+/**
+ * Connects menu events in the hotlist window.
+ */
+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(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_treeview);
+ }
+ event++;
+ }
+}
-/* exported interface docuemnted in gtk_hotlist.h */
-bool nsgtk_hotlist_init(const char *glade_file_location)
+/* exported interface docuemnted in gtk/hotlist.h */
+nserror nsgtk_hotlist_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
+ nserror res;
- 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;
+ 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(gladeFile, NULL);
-
- wndHotlist = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndHotlist"));
+ 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(gladeFile,
+ scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(hotlist_builder,
"hotlistScrolled"));
- drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(gladeFile,
+ drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(hotlist_builder,
"hotlistDrawingArea"));
tree_hotlist_path = nsoption_charp(hotlist_path);
- hotlist_window = nsgtk_treeview_create(TREE_HOTLIST, window,
+ hotlist_treeview = nsgtk_treeview_create(TREE_HOTLIST, window,
scrolled, drawing_area);
- if (hotlist_window == NULL)
- return false;
+ 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_window);
+ CONNECT(window, "hide", nsgtk_tree_window_hide, hotlist_treeview);
nsgtk_hotlist_init_menu();
- return true;
+ return NSERROR_OK;
}
-/**
- * Connects menu events in the hotlist window.
- */
-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));
- if (w == NULL) {
- LOG("Unable to connect menu widget ""%s""", event->widget); } else {
- g_signal_connect(G_OBJECT(w), "activate", event->handler, hotlist_window);
- }
- event++;
- }
-}
/**
@@ -167,8 +165,8 @@ void nsgtk_hotlist_init_menu(void)
*/
void nsgtk_hotlist_destroy(void)
{
- /* TODO: what about gladeFile? */
- nsgtk_treeview_destroy(hotlist_window);
+ /** \todo what about hotlist_builder? */
+ nsgtk_treeview_destroy(hotlist_treeview);
}
diff --git a/gtk/hotlist.h b/gtk/hotlist.h
index b2477bc..01e5a86 100644
--- a/gtk/hotlist.h
+++ b/gtk/hotlist.h
@@ -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__ */
diff --git a/gtk/login.c b/gtk/login.c
index c237dec..2de2996 100644
--- a/gtk/login.c
+++ b/gtk/login.c
@@ -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"));
diff --git a/gtk/login.h b/gtk/login.h
new file mode 100644
index 0000000..00c2900
--- /dev/null
+++ b/gtk/login.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2015 Vincent Sanders <vince(a)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
diff --git a/gtk/preferences.c b/gtk/preferences.c
index 9ca8eb7..ba58bc9 100644
--- a/gtk/preferences.c
+++ b/gtk/preferences.c
@@ -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) {
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
new file mode 100644
index 0000000..fb384a8
--- /dev/null
+++ b/gtk/res/netsurf.gresource.xml
@@ -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>
diff --git a/gtk/resources.c b/gtk/resources.c
index e6ad951..d4e8b20 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -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;
+}
diff --git a/gtk/resources.h b/gtk/resources.h
index bc08e47..7c3e73d 100644
--- a/gtk/resources.h
+++ b/gtk/resources.h
@@ -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
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c
index 3151ba1..c196242 100644
--- a/gtk/scaffolding.c
+++ b/gtk/scaffolding.c
@@ -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(g->tool_bar, "popup-context-menu",
- nsgtk_window_tool_bar_clicked, 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(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 */
diff --git a/gtk/ssl_cert.c b/gtk/ssl_cert.c
index 3c00d71..742029f 100644
--- a/gtk/ssl_cert.c
+++ b/gtk/ssl_cert.c
@@ -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);
diff --git a/gtk/toolbar.c b/gtk/toolbar.c
index 35ff25c..2345f56 100644
--- a/gtk/toolbar.c
+++ b/gtk/toolbar.c
@@ -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);
}
/**
diff --git a/gtk/viewdata.c b/gtk/viewdata.c
index 94dc5c5..7cd640f 100644
--- a/gtk/viewdata.c
+++ b/gtk/viewdata.c
@@ -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;
- }
-
- 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;
+ return res;
}
+ gtk_builder_connect_signals(newctx->builder, NULL);
- window = GTK_WINDOW(gtk_builder_get_object(newctx->builder, "ViewDataWindow"));
-
+ window = GTK_WINDOW(gtk_builder_get_object(newctx->builder,
+ "ViewDataWindow"));
if (window == NULL) {
LOG("Unable to find window in builder ");
diff --git a/gtk/window.c b/gtk/window.c
index 239c01e..481ae3b 100644
--- a/gtk/window.c
+++ b/gtk/window.c
@@ -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;
-
- /* 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);
+ GtkBuilder* tab_builder;
+
+ 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;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=16fbb97dbb1688fd9b6...
commit 16fbb97dbb1688fd9b6f19546792b4173bc30bf1
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Add links to dutch resources for gtk frontend
diff --git a/gtk/res/nl/credits.html b/gtk/res/nl/credits.html
new file mode 120000
index 0000000..8aed84c
--- /dev/null
+++ b/gtk/res/nl/credits.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/credits.html,faf
\ No newline at end of file
diff --git a/gtk/res/nl/licence.html b/gtk/res/nl/licence.html
new file mode 120000
index 0000000..9378755
--- /dev/null
+++ b/gtk/res/nl/licence.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/licence.html,faf
\ No newline at end of file
diff --git a/gtk/res/nl/welcome.html b/gtk/res/nl/welcome.html
new file mode 120000
index 0000000..05874d2
--- /dev/null
+++ b/gtk/res/nl/welcome.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/welcome.html,faf
\ No newline at end of file
-----------------------------------------------------------------------
Summary of changes:
Docs/BUILDING-GTK | 46 +++-
content/fetchers/resource.c | 199 +++++++++++----
desktop/gui_factory.c | 16 ++
desktop/gui_fetch.h | 31 ++-
gtk/Makefile.defaults | 11 +
gtk/Makefile.target | 63 ++++-
gtk/compat.c | 37 +++
gtk/compat.h | 25 ++
gtk/cookies.c | 116 +++++----
gtk/cookies.h | 9 +-
gtk/download.c | 27 +-
gtk/download.h | 11 +-
gtk/fetch.c | 18 +-
gtk/gui.c | 286 ++++++++--------------
gtk/gui.h | 23 --
gtk/history.c | 133 +++++-----
gtk/history.h | 5 +-
gtk/hotlist.c | 84 ++++---
gtk/hotlist.h | 6 +-
gtk/login.c | 23 +-
desktop/version.c => gtk/login.h | 19 +-
gtk/preferences.c | 14 +-
gtk/res/netsurf.gresource.xml | 65 +++++
gtk/res/nl/credits.html | 1 +
gtk/res/nl/licence.html | 1 +
gtk/res/nl/welcome.html | 1 +
gtk/resources.c | 503 +++++++++++++++++++++++++++++++++++++-
gtk/resources.h | 72 +++++-
gtk/scaffolding.c | 251 ++++++++++---------
gtk/ssl_cert.c | 18 +-
gtk/throbber.c | 86 +++----
gtk/throbber.h | 2 +-
gtk/toolbar.c | 74 +++---
gtk/viewdata.c | 25 +-
gtk/window.c | 37 ++-
35 files changed, 1593 insertions(+), 745 deletions(-)
copy desktop/version.c => gtk/login.h (75%)
create mode 100644 gtk/res/netsurf.gresource.xml
create mode 120000 gtk/res/nl/credits.html
create mode 120000 gtk/res/nl/licence.html
create mode 120000 gtk/res/nl/welcome.html
diff --git a/Docs/BUILDING-GTK b/Docs/BUILDING-GTK
index dab2bef..4ac0fc8 100644
--- a/Docs/BUILDING-GTK
+++ b/Docs/BUILDING-GTK
@@ -168,12 +168,14 @@
Building and executing NetSurf
--------------------------------
- First of all, you should examine the contents of Makefile.defaults
- and enable and disable relevant features as you see fit by creating
- a Makefile.config file. Some of these options can be automatically
- detected and used, and where this is the case they are set to such.
- Others cannot be automatically detected from the Makefile, so you
- will either need to install the dependencies, or set them to NO.
+ First of all, you should examine the options in Makefile.defaults
+ and gtk/Makefile.defaults and enable and disable relevant features
+ as you see fit by editing a Makefile.config file.
+
+ Some of these options can be automatically detected and used, and
+ where this is the case they are set to such. Others cannot be
+ automatically detected from the Makefile, so you will either need to
+ install the dependencies, or set them to NO.
You should then obtain NetSurf's dependencies, keeping in mind which options
you have enabled in the configuration file. See the next section for
@@ -197,6 +199,38 @@
sets up some environment variables which enable NetSurf to find its
resources.
+ Builtin resources
+-------------------
+
+ There are numerous resources that accompany NetSurf, such as the
+ image files for icons, cursors and the ui builder files that
+ construct the browsers interface.
+
+ Some of these resources can be compiled into the browser executable
+ removing the need to install these resources separately. The GLib
+ library on which GTK is based provides this functionality to
+ NetSurf.
+
+ Up until GLib version 2.32 only the GDK pixbuf could be integrated
+ in this way and is controlled with the NETSURF_USE_INLINE_PIXBUF
+ variable (set in makefile.config).
+
+ Glib version 2.32 and later integrated support for any file to be a
+ resource while depreciating the old inline pixbuf interface. NetSurf
+ gtk executables can integrate many resources using this interface,
+ configuration is controlled with the NETSURF_USE_GRESOURCE variable.
+
+ Loading from file is the fallback if a resource has not been
+ compiled in, because of this if both of these features are
+ unavailable (or disabled) NetSurf will automatically fall back to
+ loading all its resources from files.
+
+ The resource initialisation within the browser ensures it can access
+ all the resources at start time, however it does not verify the
+ resources are valid so failures could still occur subsequently. This
+ is especially true for file based resources as they can become
+ inaccessible after initialisation.
+
Note for packagers
====================
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index 1a439aa..6472dc5 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -52,26 +52,7 @@
#include "content/fetchers/resource.h"
#include "content/urldb.h"
-struct fetch_resource_context;
-
-typedef bool (*fetch_resource_handler)(struct fetch_resource_context *);
-
-/** Context for an resource fetch */
-struct fetch_resource_context {
- struct fetch_resource_context *r_next, *r_prev;
-
- struct fetch *fetchh; /**< Handle for this fetch */
-
- bool aborted; /**< Flag indicating fetch has been aborted */
- bool locked; /**< Flag indicating entry is already entered */
-
- nsurl *url;
- nsurl *redirect_url; /**< The url the fetch redirects to */
-
- fetch_resource_handler handler;
-};
-
-static struct fetch_resource_context *ring = NULL;
+#define DIRECT_ETAG_VALUE 123456
/** Valid resource paths */
static const char *fetch_resource_paths[] = {
@@ -95,11 +76,41 @@ static const char *fetch_resource_paths[] = {
"icons/hotlist-rmv.png",
"icons/search.png"
};
+
+/**
+ * map of resource scheme paths to redirect urls
+ */
static struct fetch_resource_map_entry {
- lwc_string *path;
- nsurl *url;
+ lwc_string *path; /**< resource scheme path */
+ nsurl *redirect_url; /**< url to redirect to */
+ const uint8_t *data; /**< direct pointer to data */
+ size_t data_len; /**< length of direct data */
} fetch_resource_map[NOF_ELEMENTS(fetch_resource_paths)];
+struct fetch_resource_context;
+
+typedef bool (*fetch_resource_handler)(struct fetch_resource_context *);
+
+/** Context for an resource fetch */
+struct fetch_resource_context {
+ struct fetch_resource_context *r_next, *r_prev;
+
+ struct fetch *fetchh; /**< Handle for this fetch */
+
+ bool aborted; /**< Flag indicating fetch has been aborted */
+ bool locked; /**< Flag indicating entry is already entered */
+
+ nsurl *url; /**< requested url */
+
+ struct fetch_resource_map_entry *entry; /**< resource map entry */
+
+ fetch_resource_handler handler;
+
+ int etag;
+};
+
+static struct fetch_resource_context *ring = NULL;
+
static uint32_t fetch_resource_path_count;
/** issue fetch callbacks with locking */
@@ -136,7 +147,9 @@ static bool fetch_resource_send_header(struct fetch_resource_context *ctx,
-
+/**
+ * resource handler that results in a redirect to another url.
+ */
static bool fetch_resource_redirect_handler(struct fetch_resource_context *ctx)
{
fetch_msg msg;
@@ -145,12 +158,65 @@ static bool fetch_resource_redirect_handler(struct fetch_resource_context *ctx)
fetch_set_http_code(ctx->fetchh, 302);
msg.type = FETCH_REDIRECT;
- msg.data.redirect = nsurl_access(ctx->redirect_url);
- fetch_resource_send_callback(&msg, ctx);
+ msg.data.redirect = nsurl_access(ctx->entry->redirect_url);
+ fetch_resource_send_callback(&msg, ctx);
return true;
}
+/* resource handler that returns data directly */
+static bool fetch_resource_data_handler(struct fetch_resource_context *ctx)
+{
+ fetch_msg msg;
+
+ /* Check if we can just return not modified */
+ if (ctx->etag != 0 && ctx->etag == DIRECT_ETAG_VALUE) {
+ fetch_set_http_code(ctx->fetchh, 304);
+ msg.type = FETCH_NOTMODIFIED;
+ fetch_resource_send_callback(&msg, ctx);
+ return true;
+ }
+
+ /* fetch is going to be successful */
+ fetch_set_http_code(ctx->fetchh, 200);
+
+ /* Any callback can result in the fetch being aborted.
+ * Therefore, we _must_ check for this after _every_ call to
+ * fetch_file_send_callback().
+ */
+
+ /* content type */
+ if (fetch_resource_send_header(ctx, "Content-Type: %s",
+ guit->fetch->filetype(lwc_string_data(ctx->entry->path))))
+ goto fetch_resource_data_aborted;
+
+ /* content length */
+ if (fetch_resource_send_header(ctx,
+ "Content-Length: %"SSIZET_FMT,
+ ctx->entry->data_len))
+ goto fetch_resource_data_aborted;
+
+ /* create etag */
+ if (fetch_resource_send_header(ctx,
+ "ETag: \"%10" PRId64 "\"",
+ (int64_t) DIRECT_ETAG_VALUE))
+ goto fetch_resource_data_aborted;
+
+
+ msg.type = FETCH_DATA;
+ msg.data.header_or_data.buf = (const uint8_t *) ctx->entry->data;
+ msg.data.header_or_data.len = ctx->entry->data_len;
+ fetch_resource_send_callback(&msg, ctx);
+
+ if (ctx->aborted == false) {
+ msg.type = FETCH_FINISHED;
+ fetch_resource_send_callback(&msg, ctx);
+ }
+
+fetch_resource_data_aborted:
+
+ return true;
+}
static bool fetch_resource_notfound_handler(struct fetch_resource_context *ctx)
{
@@ -195,6 +261,7 @@ static bool fetch_resource_initialise(lwc_string *scheme)
{
struct fetch_resource_map_entry *e;
uint32_t i;
+ nserror res;
fetch_resource_path_count = 0;
@@ -207,15 +274,26 @@ static bool fetch_resource_initialise(lwc_string *scheme)
while (i > 0) {
i--;
lwc_string_unref(fetch_resource_map[i].path);
- nsurl_unref(fetch_resource_map[i].url);
+ nsurl_unref(fetch_resource_map[i].redirect_url);
}
+ /** \todo should this exit with an error condition? */
}
- e->url = guit->fetch->get_resource_url(fetch_resource_paths[i]);
- if (e->url == NULL) {
- lwc_string_unref(e->path);
- } else {
+ e->data = NULL;
+ res = guit->fetch->get_resource_data(lwc_string_data(e->path),
+ &e->data,
+ &e->data_len);
+ if (res == NSERROR_OK) {
+ LOG("direct data for %s", fetch_resource_paths[i]);
fetch_resource_path_count++;
+ } else {
+ e->redirect_url = guit->fetch->get_resource_url(fetch_resource_paths[i]);
+ if (e->redirect_url == NULL) {
+ lwc_string_unref(e->path);
+ } else {
+ LOG("redirect url for %s", fetch_resource_paths[i]);
+ fetch_resource_path_count++;
+ }
}
}
@@ -229,7 +307,11 @@ static void fetch_resource_finalise(lwc_string *scheme)
for (i = 0; i < fetch_resource_path_count; i++) {
lwc_string_unref(fetch_resource_map[i].path);
- nsurl_unref(fetch_resource_map[i].url);
+ if (fetch_resource_map[i].data != NULL) {
+ guit->fetch->release_resource_data(fetch_resource_map[i].data);
+ } else {
+ nsurl_unref(fetch_resource_map[i].redirect_url);
+ }
}
}
@@ -238,38 +320,44 @@ static bool fetch_resource_can_fetch(const nsurl *url)
return true;
}
-/** callback to set up a resource fetch context. */
+/**
+ * set up a resource fetch context.
+ */
static void *
fetch_resource_setup(struct fetch *fetchh,
- nsurl *url,
- bool only_2xx,
- bool downgrade_tls,
- const char *post_urlenc,
- const struct fetch_multipart_data *post_multipart,
- const char **headers)
+ nsurl *url,
+ bool only_2xx,
+ bool downgrade_tls,
+ const char *post_urlenc,
+ const struct fetch_multipart_data *post_multipart,
+ const char **headers)
{
struct fetch_resource_context *ctx;
lwc_string *path;
+ uint32_t i;
ctx = calloc(1, sizeof(*ctx));
- if (ctx == NULL)
+ if (ctx == NULL) {
return NULL;
+ }
ctx->handler = fetch_resource_notfound_handler;
if ((path = nsurl_get_component(url, NSURL_PATH)) != NULL) {
- uint32_t i;
bool match;
/* Ensure requested path is valid */
for (i = 0; i < fetch_resource_path_count; i++) {
- if (lwc_string_isequal(path,
- fetch_resource_map[i].path,
+ if (lwc_string_isequal(path,
+ fetch_resource_map[i].path,
&match) == lwc_error_ok && match) {
- ctx->redirect_url =
- nsurl_ref(fetch_resource_map[i].url);
- ctx->handler =
- fetch_resource_redirect_handler;
+ /* found a url match, select handler */
+ ctx->entry = &fetch_resource_map[i];
+ if (ctx->entry->data != NULL) {
+ ctx->handler = fetch_resource_data_handler;
+ } else {
+ ctx->handler = fetch_resource_redirect_handler;
+ }
break;
}
}
@@ -279,6 +367,23 @@ fetch_resource_setup(struct fetch *fetchh,
ctx->url = nsurl_ref(url);
+ /* Scan request headers looking for If-None-Match */
+ for (i = 0; headers[i] != NULL; i++) {
+ if (strncasecmp(headers[i], "If-None-Match:",
+ SLEN("If-None-Match:")) == 0) {
+ /* If-None-Match: "12345678" */
+ const char *d = headers[i] + SLEN("If-None-Match:");
+
+ /* Scan to first digit, if any */
+ while (*d != '\0' && (*d < '0' || '9' < *d))
+ d++;
+
+ /* Convert to time_t */
+ if (*d != '\0')
+ ctx->etag = atoi(d);
+ }
+ }
+
ctx->fetchh = fetchh;
RING_INSERT(ring, ctx);
@@ -290,8 +395,6 @@ fetch_resource_setup(struct fetch *fetchh,
static void fetch_resource_free(void *ctx)
{
struct fetch_resource_context *c = ctx;
- if (c->redirect_url != NULL)
- nsurl_unref(c->redirect_url);
if (c->url != NULL)
nsurl_unref(c->url);
RING_REMOVE(ring, c);
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 50244e3..22364ab 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -501,6 +501,16 @@ static nsurl *gui_default_get_resource_url(const char *path)
return NULL;
}
+static nserror gui_default_get_resource_data(const char *path, const uint8_t **data, size_t *data_len)
+{
+ return NSERROR_NOT_FOUND;
+}
+
+static nserror gui_default_release_resource_data(const uint8_t *data)
+{
+ return NSERROR_OK;
+}
+
static char *gui_default_mimetype(const char *path)
{
return strdup(guit->fetch->filetype(path));
@@ -523,6 +533,12 @@ static nserror verify_fetch_register(struct gui_fetch_table *gft)
if (gft->get_resource_url == NULL) {
gft->get_resource_url = gui_default_get_resource_url;
}
+ if (gft->get_resource_data == NULL) {
+ gft->get_resource_data = gui_default_get_resource_data;
+ }
+ if (gft->release_resource_data == NULL) {
+ gft->release_resource_data = gui_default_release_resource_data;
+ }
if (gft->mimetype == NULL) {
gft->mimetype = gui_default_mimetype;
}
diff --git a/desktop/gui_fetch.h b/desktop/gui_fetch.h
index 46d31e0..20db39d 100644
--- a/desktop/gui_fetch.h
+++ b/desktop/gui_fetch.h
@@ -47,9 +47,9 @@ struct gui_fetch_table {
/* Optional entries */
/**
- * Callback to translate resource to full url.
+ * Translate resource to full url.
*
- * @note used in resource fetcher
+ * @note Only used in resource fetcher
*
* Transforms a resource: path into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
@@ -62,6 +62,33 @@ struct gui_fetch_table {
struct nsurl* (*get_resource_url)(const char *path);
/**
+ * Translate resource to source data.
+ *
+ * @note Only used in resource fetcher
+ *
+ * Obtains the data for a resource directly
+ *
+ * \param path The path of the resource to locate.
+ * \param data Pointer to recive data into
+ * \param data_len Pointer to length of returned data
+ * \return NSERROR_OK and the data and length values updated
+ * else appropriate error code.
+ */
+ nserror (*get_resource_data)(const char *path, const uint8_t **data, size_t *data_len);
+
+ /**
+ * Releases source data.
+ *
+ * @note Only used in resource fetcher
+ *
+ * Releases source data obtained from get_resource_data()
+ *
+ * \param data The value returned from a previous get_resource_data call
+ * \return NSERROR_OK on success else appropriate error code.
+ */
+ nserror (*release_resource_data)(const uint8_t *data);
+
+ /**
* Find a MIME type for a local file
*
* @note only used in curl fetcher on RISC OS otherwise its a
diff --git a/gtk/Makefile.defaults b/gtk/Makefile.defaults
index 51aa027..0f229d8 100644
--- a/gtk/Makefile.defaults
+++ b/gtk/Makefile.defaults
@@ -21,6 +21,17 @@ NETSURF_USE_NSSVG := AUTO
# Valid options: YES, NO, AUTO
NETSURF_USE_ROSPRITE := AUTO
+# Enable the use of GLib compiled in resource handling. This requires
+# GLib 2.32 or later
+# Valid options: YES, NO, AUTO
+NETSURF_USE_GRESOURCE := AUTO
+
+# Enable the use of compiled in inline pixbuf. This is depricated
+# since GLib 2.32. The automatic selection is disabled if GRESOURCE
+# handling is enabled
+# Valid options: YES, NO, AUTO
+NETSURF_USE_INLINE_PIXBUF := AUTO
+
# Enable building the source object cache filesystem based backing store.
NETSURF_FS_BACKING_STORE := YES
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 01c00c2..cc85162 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -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,11 +77,54 @@ ifeq ($(HOST),Windows_NT)
CFLAGS += -U__STRICT_ANSI__
endif
-
# ----------------------------------------------------------------------------
-# Pixbuf
+# 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 in a way similar to the pkg_config_find_and_add_enabled
+# macro. 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_FEATURE_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes)
+ifneq (,$(filter $(NETSURF_USE_GRESOURCE),AUTO YES))
+ifeq ($(NETSURF_FEATURE_GRESOURCE_AVAILABLE),yes)
+
+# Gresource use has been enabled
+NETSURF_FEATURE_GRESOURCE_ENABLED := yes
+
+#resource compiler tool
+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))
+ $(VQ)echo "GRESORCE: $<"
+ $(Q)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+
+endif
+endif
+
+# Build pixbufs as inlines if enabled
+ifneq (,$(filter $(NETSURF_USE_INLINE_PIXBUF),AUTO YES))
+ifneq ($(NETSURF_FEATURE_GRESOURCE_ENABLED),yes)
+
+CFLAGS += -DWITH_BUILTIN_PIXBUF
+
GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
# 1: input file
@@ -88,24 +132,25 @@ 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)
+ $(VQ)echo " INLINE: ${3}"
$(Q)echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $(2)
$(Q)gdk-pixbuf-csource --extern --raw --name=$(3) $(1) >> $(2) || \
( rm -f $(2) && false )
endef
+$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
+endif
+endif
+
# ----------------------------------------------------------------------------
# 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)))
-
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c plotters.c \
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
@@ -120,7 +165,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
diff --git a/gtk/compat.c b/gtk/compat.c
index 51469b2..4c5524b 100644
--- a/gtk/compat.c
+++ b/gtk/compat.c
@@ -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;
+}
diff --git a/gtk/compat.h b/gtk/compat.h
index 088cd79..9554b0c 100644
--- a/gtk/compat.h
+++ b/gtk/compat.h
@@ -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 */
diff --git a/gtk/cookies.c b/gtk/cookies.c
index cb59d0a..7b21dc9 100644
--- a/gtk/cookies.c
+++ b/gtk/cookies.c
@@ -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.
+ * Connects menu events in the cookies window.
*/
-bool nsgtk_cookies_init(const char *glade_file_location)
+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(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_treeview);
+ }
+ event++;
+ }
+}
+
+/* exported interface documented in gtk/cookies.h */
+nserror nsgtk_cookies_init(void)
{
- GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
+ nserror res;
- 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;
+ 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(gladeFile, NULL);
-
- wndCookies = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndCookies"));
- window = wndCookies;
-
- scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(gladeFile,
+
+ 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(gladeFile,
+ drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(cookie_builder,
"cookiesDrawingArea"));
-
- cookies_window = nsgtk_treeview_create(TREE_COOKIES, window,
- scrolled, drawing_area);
-
- if (cookies_window == NULL)
- return false;
-
+
+ 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(window, "delete_event", gtk_widget_hide_on_delete, NULL);
- CONNECT(window, "hide", nsgtk_tree_window_hide, cookies_window);
-
- nsgtk_cookies_init_menu();
+ g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
- return true;
-}
+ CONNECT(wndCookies, "delete_event", gtk_widget_hide_on_delete, NULL);
+ CONNECT(wndCookies, "hide", nsgtk_tree_window_hide, cookies_treeview);
-/**
- * Connects menu events in the cookies window.
- */
-void nsgtk_cookies_init_menu()
-{
- struct menu_events *event = menu_events;
- GtkWidget *w;
+ nsgtk_cookies_init_menu();
- while (event->widget != NULL) {
- w = GTK_WIDGET(gtk_builder_get_object(gladeFile, 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);
- }
- event++;
- }
+ 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);
}
diff --git a/gtk/cookies.h b/gtk/cookies.h
index db12dfe..2d5c56d 100644
--- a/gtk/cookies.h
+++ b/gtk/cookies.h
@@ -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);
diff --git a/gtk/download.c b/gtk/download.c
index 74b49f6..23832de 100644
--- a/gtk/download.c
+++ b/gtk/download.c
@@ -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();
-
- 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;
+ GtkBuilder* builder;
+ nserror res;
+
+ 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 ()
diff --git a/gtk/download.h b/gtk/download.h
index a6e624f..0b10976 100644
--- a/gtk/download.h
+++ b/gtk/download.h
@@ -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);
diff --git a/gtk/fetch.c b/gtk/fetch.c
index f68f203..0e5a37c 100644
--- a/gtk/fetch.c
+++ b/gtk/fetch.c
@@ -34,6 +34,7 @@
#include "desktop/gui_fetch.h"
#include "gtk/gui.h"
+#include "gtk/resources.h"
#include "gtk/fetch.h"
static struct hash_table *mime_hash = NULL;
@@ -172,13 +173,13 @@ const char *fetch_filetype(const char *unix_path)
const char *type;
int l;
- if (stat(unix_path, &statbuf) != 0) {
- /* stat failed */
- return "text/plain";
- }
+ /* stat the path to attempt to determine if the file is special */
+ if (stat(unix_path, &statbuf) == 0) {
+ /* stat suceeded so can check for directory */
- if (S_ISDIR(statbuf.st_mode)) {
- return "application/x-netsurf-directory";
+ if (S_ISDIR(statbuf.st_mode)) {
+ return "application/x-netsurf-directory";
+ }
}
l = strlen(unix_path);
@@ -230,7 +231,7 @@ const char *fetch_filetype(const char *unix_path)
}
-static nsurl *gui_get_resource_url(const char *path)
+static nsurl *nsgtk_get_resource_url(const char *path)
{
char buf[PATH_MAX];
nsurl *url = NULL;
@@ -253,7 +254,8 @@ static nsurl *gui_get_resource_url(const char *path)
static struct gui_fetch_table fetch_table = {
.filetype = fetch_filetype,
- .get_resource_url = gui_get_resource_url,
+ .get_resource_url = nsgtk_get_resource_url,
+ .get_resource_data = nsgtk_data_from_resname,
};
struct gui_fetch_table *nsgtk_fetch_table = &fetch_table;
diff --git a/gtk/gui.c b/gtk/gui.c
index b8d8fc1..4986f42 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -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;
@@ -77,14 +79,10 @@ char *themelist_file_location;
char *nsgtk_config_home; /* exported global defined in gtk/gui.h */
-GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+GdkPixbuf *favicon_pixbuf; /** favicon default pixbuf */
+GdkPixbuf *win_default_icon_pixbuf; /** default window icon pixbuf */
-struct glade_file_location_s *glade_file_location;
-
-static GtkWindow *nsgtk_warning_window;
-GtkWidget *widWarning;
-
-#define THROBBER_FRAMES 9
+GtkBuilder *warning_builder;
char **respaths; /** resource search path vector */
@@ -101,14 +99,15 @@ static void die(const char * const error)
exit(EXIT_FAILURE);
}
-/** Create an array of valid paths to search for resources.
+/**
+ * Create an array of valid paths to search for resources.
*
* The idea is that all the complex path computation to find resources
* is performed here, once, rather than every time a resource is
* searched for.
*/
static char **
-nsgtk_init_resource(const char *resource_path)
+nsgtk_init_resource_path(const char *resource_path)
{
const gchar * const *langv;
char **pathv; /* resource path string vector */
@@ -125,117 +124,6 @@ nsgtk_init_resource(const char *resource_path)
return respath;
}
-/* This is an ugly hack to just get the new-style throbber going.
- * It, along with the PNG throbber loader, need making more generic.
- */
-static bool nsgtk_throbber_init(char **respath, int framec)
-{
- char **filenames;
- char targetname[PATH_MAX];
- int frame_num;
- bool ret;
-
- filenames = calloc(framec, sizeof(char *));
- if (filenames == NULL)
- return false;
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num);
- filenames[frame_num] = filepath_find(respath, targetname);
- }
-
- ret = nsgtk_throbber_initialise_from_png(frame_num, filenames);
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- free(filenames[frame_num]);
- }
- free(filenames);
-
- return ret;
-
-}
-
-#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,14 +235,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);
+ 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");
- if (resource_filename != NULL) {
- gtk_window_set_default_icon_from_file(resource_filename, NULL);
- free(resource_filename);
+ error = nsgdk_pixbuf_new_from_resname("netsurf.xpm",
+ &win_default_icon_pixbuf);
+ if (error == NSERROR_OK) {
+ LOG("Seting default window icon");
+ gtk_window_set_default_icon(win_default_icon_pixbuf);
}
/* Search engine sources */
@@ -366,23 +260,24 @@ 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 */
- toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
- LOG("Using '%s' as custom toolbar settings file", toolbar_indices_file_location);
-
- /* load throbber images */
- if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
- die("Unable to load throbber image.\n");
+ toolbar_indices_file_location = filepath_find(respath,
+ "toolbarIndices");
+ LOG("Using '%s' as custom toolbar settings file",
+ toolbar_indices_file_location);
+
+ /* initialise throbber */
+ error = nsgtk_throbber_init();
+ if (error != NSERROR_OK) {
+ LOG("Unable to initialise throbber.");
+ return error;
+ }
/* Initialise completions - cannot fail */
nsgtk_completion_init();
@@ -402,17 +297,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 +474,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 +499,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 +541,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 +560,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 +578,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;
-
- 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);
+ GtkBuilder *password_builder;
+ nserror res;
+
+ 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 +600,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);
@@ -1092,7 +1008,7 @@ static struct gui_browser_table nsgtk_browser_table = {
.quit = gui_quit,
.launch_url = gui_launch_url,
.cert_verify = gtk_cert_verify,
- .login = gui_401login_open,
+ .login = gui_401login_open,
.pdf_password = nsgtk_pdf_password,
};
@@ -1116,13 +1032,10 @@ int main(int argc, char** argv)
.bitmap = nsgtk_bitmap_table,
};
- ret = netsurf_register(&nsgtk_table);
- if (ret != NSERROR_OK) {
+ ret = netsurf_register(&nsgtk_table);
+ if (ret != NSERROR_OK) {
die("NetSurf operation table failed registration\n");
- }
-
- /* build the common resource path list */
- respaths = nsgtk_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+ }
/* Locate the correct user configuration directory path */
ret = get_config_home(&nsgtk_config_home);
@@ -1143,6 +1056,17 @@ int main(int argc, char** argv)
*/
nslog_init(nslog_stream_configure, &argc, argv);
+ /* build the common resource path list */
+ respaths = nsgtk_init_resource_path("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res");
+
+ /* initialise the gtk resource handling */
+ ret = nsgtk_init_resources(respaths);
+ if (ret != NSERROR_OK) {
+ fprintf(stderr, "GTK resources failed to initialise (%s)\n",
+ messages_get_errorcode(ret));
+ return 1;
+ }
+
/* Initialise user options */
ret = nsgtk_option_init(&argc, argv);
if (ret != NSERROR_OK) {
@@ -1177,7 +1101,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();
diff --git a/gtk/gui.h b/gtk/gui.h
index 63832f8..ce234c4 100644
--- a/gtk/gui.h
+++ b/gtk/gui.h
@@ -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;
diff --git a/gtk/history.c b/gtk/history.c
index 2dbedf9..db30c5b 100644
--- a/gtk/history.c
+++ b/gtk/history.c
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Rob Kendrick <rjek(a)rjek.com>
- * Copyright 2009 Paul Blokus <paul_pl(a)users.sourceforge.net>
+ * Copyright 2009 Paul Blokus <paul_pl(a)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,94 +64,102 @@ 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;
+/**
+ * Connects menu events in the global history window.
+ */
+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(history_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,
+ global_history_window);
+ }
+ event++;
+ }
+}
-/* exported interface, documented in gtk_history.h */
-bool nsgtk_history_init(const char *glade_file_location)
+/* exported interface, documented in gtk/history.h */
+nserror nsgtk_history_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
- GError* error = NULL;
+ nserror res;
- 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;
+ 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"));
- 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"));
+ 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;
+ }
- 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))
-
+ 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;
+ return NSERROR_OK;
}
-/**
- * Connects menu events in the global history window.
- */
-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));
- if (w == NULL) {
- LOG("Unable to connect menu widget ""%s""", event->widget);
- } else {
- g_signal_connect(G_OBJECT(w), "activate", event->handler, global_history_window);
- }
- event++;
- }
-}
/**
@@ -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;
diff --git a/gtk/history.h b/gtk/history.h
index ab3c10e..c0f7db2 100644
--- a/gtk/history.h
+++ b/gtk/history.h
@@ -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.
diff --git a/gtk/hotlist.c b/gtk/hotlist.c
index fed6ae7..8258e09 100644
--- a/gtk/hotlist.c
+++ b/gtk/hotlist.c
@@ -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,74 +90,74 @@ 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;
+/**
+ * Connects menu events in the hotlist window.
+ */
+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(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_treeview);
+ }
+ event++;
+ }
+}
-/* exported interface docuemnted in gtk_hotlist.h */
-bool nsgtk_hotlist_init(const char *glade_file_location)
+/* exported interface docuemnted in gtk/hotlist.h */
+nserror nsgtk_hotlist_init(void)
{
GtkWindow *window;
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
+ nserror res;
- 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;
+ 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(gladeFile, NULL);
-
- wndHotlist = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndHotlist"));
+ 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(gladeFile,
+ scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(hotlist_builder,
"hotlistScrolled"));
- drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(gladeFile,
+ drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(hotlist_builder,
"hotlistDrawingArea"));
tree_hotlist_path = nsoption_charp(hotlist_path);
- hotlist_window = nsgtk_treeview_create(TREE_HOTLIST, window,
+ hotlist_treeview = nsgtk_treeview_create(TREE_HOTLIST, window,
scrolled, drawing_area);
- if (hotlist_window == NULL)
- return false;
+ 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_window);
+ CONNECT(window, "hide", nsgtk_tree_window_hide, hotlist_treeview);
nsgtk_hotlist_init_menu();
- return true;
+ return NSERROR_OK;
}
-/**
- * Connects menu events in the hotlist window.
- */
-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));
- if (w == NULL) {
- LOG("Unable to connect menu widget ""%s""", event->widget); } else {
- g_signal_connect(G_OBJECT(w), "activate", event->handler, hotlist_window);
- }
- event++;
- }
-}
/**
@@ -167,8 +165,8 @@ void nsgtk_hotlist_init_menu(void)
*/
void nsgtk_hotlist_destroy(void)
{
- /* TODO: what about gladeFile? */
- nsgtk_treeview_destroy(hotlist_window);
+ /** \todo what about hotlist_builder? */
+ nsgtk_treeview_destroy(hotlist_treeview);
}
diff --git a/gtk/hotlist.h b/gtk/hotlist.h
index b2477bc..01e5a86 100644
--- a/gtk/hotlist.h
+++ b/gtk/hotlist.h
@@ -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__ */
diff --git a/gtk/login.c b/gtk/login.c
index c237dec..2de2996 100644
--- a/gtk/login.c
+++ b/gtk/login.c
@@ -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"));
diff --git a/desktop/version.c b/gtk/login.h
similarity index 75%
copy from desktop/version.c
copy to gtk/login.h
index ce62f79..00c2900 100644
--- a/desktop/version.c
+++ b/gtk/login.h
@@ -16,15 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "testament.h"
+/** \file
+ * Login interfaces.
+ */
+
+#ifndef __NSGTK_LOGIN_H__
+#define __NSGTK_LOGIN_H__
-#include "desktop/version.h"
+/**
+ * login window request.
+ */
+extern void gui_401login_open(struct nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw);
-const char * const netsurf_version = "3.4 (Dev"
-#if defined(CI_BUILD)
- " CI #" CI_BUILD
#endif
- ")"
- ;
-const int netsurf_version_major = 3;
-const int netsurf_version_minor = 4;
diff --git a/gtk/preferences.c b/gtk/preferences.c
index 9ca8eb7..ba58bc9 100644
--- a/gtk/preferences.c
+++ b/gtk/preferences.c
@@ -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) {
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
new file mode 100644
index 0000000..ca4c9e3
--- /dev/null
+++ b/gtk/res/netsurf.gresource.xml
@@ -0,0 +1,65 @@
+<?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 preprocess="to-pixdata">favicon.png</file>
+ <file preprocess="to-pixdata">netsurf.xpm</file>
+ <file preprocess="to-pixdata">menu_cursor.png</file>
+ <file preprocess="to-pixdata">throbber/throbber0.png</file>
+ <file preprocess="to-pixdata">throbber/throbber1.png</file>
+ <file preprocess="to-pixdata">throbber/throbber2.png</file>
+ <file preprocess="to-pixdata">throbber/throbber3.png</file>
+ <file preprocess="to-pixdata">throbber/throbber4.png</file>
+ <file preprocess="to-pixdata">throbber/throbber5.png</file>
+ <file preprocess="to-pixdata">throbber/throbber6.png</file>
+ <file preprocess="to-pixdata">throbber/throbber7.png</file>
+ <file preprocess="to-pixdata">throbber/throbber8.png</file>
+ <file>credits.html</file>
+ <file>it/credits.html</file>
+ <file>nl/credits.html</file>
+ <file>licence.html</file>
+ <file>it/licence.html</file>
+ <file>nl/licence.html</file>
+ <file>welcome.html</file>
+ <file>de/welcome.html</file>
+ <file>it/welcome.html</file>
+ <file>ja/welcome.html</file>
+ <file>nl/welcome.html</file>
+ <file>maps.html</file>
+ <file>internal.css</file>
+ <file>netsurf.png</file>
+ <file>default.ico</file>
+ <file>icons/arrow-l.png</file>
+ <file>icons/content.png</file>
+ <file>icons/directory2.png</file>
+ <file>icons/directory.png</file>
+ <file>icons/hotlist-add.png</file>
+ <file>icons/hotlist-rmv.png</file>
+ <file>icons/search.png</file>
+ </gresource>
+</gresources>
diff --git a/gtk/res/nl/credits.html b/gtk/res/nl/credits.html
new file mode 120000
index 0000000..8aed84c
--- /dev/null
+++ b/gtk/res/nl/credits.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/credits.html,faf
\ No newline at end of file
diff --git a/gtk/res/nl/licence.html b/gtk/res/nl/licence.html
new file mode 120000
index 0000000..9378755
--- /dev/null
+++ b/gtk/res/nl/licence.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/licence.html,faf
\ No newline at end of file
diff --git a/gtk/res/nl/welcome.html b/gtk/res/nl/welcome.html
new file mode 120000
index 0000000..05874d2
--- /dev/null
+++ b/gtk/res/nl/welcome.html
@@ -0,0 +1 @@
+../../../!NetSurf/Resources/nl/welcome.html,faf
\ No newline at end of file
diff --git a/gtk/resources.c b/gtk/resources.c
index e6ad951..1998034 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -20,27 +20,522 @@
* \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"
+/** log contents of gresource /org/netsource */
+#ifdef WITH_GRESOURCE
+#define SHOW_GRESOURCE
+#undef SHOW_GRESOURCE
+#endif
+
+#ifdef WITH_BUILTIN_PIXBUF
#ifdef __GNUC__
extern const guint8 menu_cursor_pixdata[] __attribute__ ((__aligned__ (4)));
#else
extern const guint8 menu_cursor_pixdata[];
#endif
+#endif
+
+/** type of resource entry */
+enum nsgtk_resource_type_e {
+ NSGTK_RESOURCE_FILE, /**< entry is a file on disc */
+ NSGTK_RESOURCE_GLIB, /**< entry is a gresource accessed by path */
+ NSGTK_RESOURCE_DIRECT, /**< entry is a gresource accesed by gbytes */
+ NSGTK_RESOURCE_INLINE, /**< entry is compiled in accessed by pointer */
+};
+
+/** resource entry */
+struct nsgtk_resource_s {
+ const char *name;
+ unsigned int len;
+ enum nsgtk_resource_type_e type;
+ char *path;
+};
+
+#define RES_ENTRY(name) { name, sizeof((name)) - 1, NSGTK_RESOURCE_FILE, NULL }
+/** resources that are used for gtk builder */
+static struct nsgtk_resource_s ui_resource[] = {
+ RES_ENTRY("netsurf"),
+ RES_ENTRY("tabcontents"),
+ RES_ENTRY("password"),
+ RES_ENTRY("login"),
+ RES_ENTRY("ssl"),
+ RES_ENTRY("toolbar"),
+ RES_ENTRY("downloads"),
+ RES_ENTRY("history"),
+ RES_ENTRY("options"),
+ RES_ENTRY("hotlist"),
+ RES_ENTRY("cookies"),
+ RES_ENTRY("viewdata"),
+ RES_ENTRY("warning"),
+ { NULL, 0, NSGTK_RESOURCE_FILE, NULL },
+};
+
+/** resources that are used as pixbufs */
+static struct nsgtk_resource_s pixbuf_resource[] = {
+ RES_ENTRY("favicon.png"),
+ RES_ENTRY("netsurf.xpm"),
+ RES_ENTRY("menu_cursor.png"),
+ RES_ENTRY("throbber/throbber0.png"),
+ RES_ENTRY("throbber/throbber1.png"),
+ RES_ENTRY("throbber/throbber2.png"),
+ RES_ENTRY("throbber/throbber3.png"),
+ RES_ENTRY("throbber/throbber4.png"),
+ RES_ENTRY("throbber/throbber5.png"),
+ RES_ENTRY("throbber/throbber6.png"),
+ RES_ENTRY("throbber/throbber7.png"),
+ RES_ENTRY("throbber/throbber8.png"),
+ { NULL, 0, NSGTK_RESOURCE_FILE, NULL },
+};
+
+/** resources that are used for direct data access */
+static struct nsgtk_resource_s direct_resource[] = {
+ RES_ENTRY("welcome.html"),
+ RES_ENTRY("credits.html"),
+ RES_ENTRY("licence.html"),
+ RES_ENTRY("maps.html"),
+ RES_ENTRY("internal.css"),
+ RES_ENTRY("netsurf.png"),
+ RES_ENTRY("default.ico"),
+ RES_ENTRY("icons/arrow-l.png"),
+ RES_ENTRY("icons/content.png"),
+ RES_ENTRY("icons/directory2.png"),
+ RES_ENTRY("icons/directory.png"),
+ RES_ENTRY("icons/hotlist-add.png"),
+ RES_ENTRY("icons/hotlist-rmv.png"),
+ RES_ENTRY("icons/search.png"),
+ { NULL, 0, NSGTK_RESOURCE_FILE, NULL },
+};
+
+
+/* exported interface documented in gtk/resources.h */
GdkCursor *nsgtk_create_menu_cursor(void)
{
GdkCursor *cursor = NULL;
GdkPixbuf *pixbuf;
+ nserror res;
+ const char *resname = "menu_cursor.png";
- pixbuf = gdk_pixbuf_new_from_inline(-1, menu_cursor_pixdata, FALSE, NULL);
- cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 0, 3);
- g_object_unref (pixbuf);
+ res = nsgdk_pixbuf_new_from_resname(resname, &pixbuf);
+ if (res == NSERROR_OK) {
+ cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
+ pixbuf, 0, 3);
+ g_object_unref(pixbuf);
+ }
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 resource A resource entry to initialise
+ */
+static nserror
+init_resource(char **respath, struct nsgtk_resource_s *resource)
+{
+ char *resname;
+#ifdef WITH_GRESOURCE
+ int resnamelen;
+ gboolean present;
+ const gchar * const *langv;
+ int langc = 0;
+
+ langv = g_get_language_names();
+
+ while (langv[langc] != NULL) {
+ resnamelen = snprintf(NULL, 0,
+ "/org/netsurf/%s/%s",
+ langv[langc], resource->name);
+
+ resname = malloc(resnamelen + 1);
+ if (resname == NULL) {
+ return NSERROR_NOMEM;
+ }
+ snprintf(resname, resnamelen + 1,
+ "/org/netsurf/%s/%s",
+ langv[langc], 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_GLIB;
+ LOG("Found gresource path %s", resource->path);
+ return NSERROR_OK;
+ }
+ /*LOG("gresource \"%s\" not found", resname);*/
+ free(resname);
+
+ langc++;
+ }
+ 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_GLIB;
+ 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 and setup a direct resource
+ *
+ * Direct resources have general type of NSGTK_RESOURCE_GLIB but have
+ * g_resources_lookup_data() applied and the result stored so the data
+ * can be directly accessed without additional processing.
+ *
+ * \param respath A string vector containing the valid resource search paths
+ * \param resource A resource entry to initialise
+ */
+static nserror
+init_direct_resource(char **respath, struct nsgtk_resource_s *resource)
+{
+ nserror res;
+ GBytes *data;
+
+ res = init_resource(respath, resource);
+ if ((res == NSERROR_OK) &&
+ (resource->type == NSGTK_RESOURCE_GLIB)) {
+ /* found gresource we can convert */
+ data = g_resources_lookup_data(resource->path,
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ NULL);
+ if (data != NULL) {
+ resource->type = NSGTK_RESOURCE_DIRECT;
+ resource->path = (char *)data;
+ }
+ }
+
+ return res;
+}
+
+/**
+ * locate a pixbuf resource
+ *
+ * Pixbuf resources can be compiled inline
+ *
+ * \param respath A string vector containing the valid resource search paths
+ * \param resource A resource entry to initialise
+ */
+static nserror
+init_pixbuf_resource(char **respath, struct nsgtk_resource_s *resource)
+{
+#ifdef WITH_BUILTIN_PIXBUF
+ if (strncmp(resource->name, "menu_cursor.png", resource->len) == 0) {
+ resource->path = (char *)&menu_cursor_pixdata[0];
+ resource->type = NSGTK_RESOURCE_INLINE;
+ LOG("Found builtin for %s", resource->name);
+ return NSERROR_OK;
+ }
+#endif
+ return init_resource(respath, resource);
+}
+
+/**
+ * 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;
+}
+
+/**
+ * Find a resource entry by name.
+ *
+ * \param resname The resource name to match.
+ * \param resource The list of resources entries to search.
+ */
+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;
+}
+
+#ifdef SHOW_GRESOURCE
+/**
+ * Debug dump of all resources compile din via GResource.
+ */
+static void list_gresource(void)
+{
+ 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
+
+/**
+ * Initialise UI resource table
+ *
+ */
+/* exported interface documented in gtk/resources.h */
+nserror nsgtk_init_resources(char **respath)
+{
+ struct nsgtk_resource_s *resource;
+ nserror res;
+
+#ifdef SHOW_GRESOURCE
+ list_gresource();
+#endif
+
+ /* iterate 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++;
+ }
+
+ /* iterate the pixbuf resource table and initialise all its members */
+ resource = &pixbuf_resource[0];
+ while (resource->name != NULL) {
+ res = init_pixbuf_resource(respath, resource);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ resource++;
+ }
+
+ /* iterate the direct resource table and initialise all its members */
+ resource = &direct_resource[0];
+ while (resource->name != NULL) {
+ res = init_direct_resource(respath, resource);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+ resource++;
+ }
+
+ return NSERROR_OK;
+}
+
+
+/* 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 = NULL;
+ GError* error = NULL;
+
+ resource = find_resource_from_name(resname, &pixbuf_resource[0]);
+ if (resource->name == NULL) {
+ return NSERROR_NOT_FOUND;
+ }
+
+ switch (resource->type) {
+ case NSGTK_RESOURCE_FILE:
+ new_pixbuf = gdk_pixbuf_new_from_file(resource->path, &error);
+ break;
+
+ case NSGTK_RESOURCE_GLIB:
+ new_pixbuf = gdk_pixbuf_new_from_resource(resource->path, &error);
+ break;
+
+ case NSGTK_RESOURCE_INLINE:
+#ifdef WITH_BUILTIN_PIXBUF
+ new_pixbuf = gdk_pixbuf_new_from_inline(-1, (const guint8 *)resource->path, FALSE, &error);
+#endif
+ break;
+
+ case NSGTK_RESOURCE_DIRECT:
+ /* pixbuf resources are not currently direct */
+ break;
+ }
+ 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;
+}
+
+/* exported interface documented in gtk/resources.h */
+nserror
+nsgtk_data_from_resname(const char *resname,
+ const uint8_t ** data_out,
+ size_t *data_size_out)
+{
+ struct nsgtk_resource_s *resource;
+ GBytes *data;
+ const gchar *buffer;
+ gsize buffer_length;
+
+ resource = find_resource_from_name(resname, &direct_resource[0]);
+ if ((resource->name == NULL) ||
+ (resource->type != NSGTK_RESOURCE_DIRECT)) {
+ return NSERROR_NOT_FOUND;
+ }
+
+ data = (GBytes *)resource->path;
+
+ buffer_length = 0;
+ buffer = g_bytes_get_data(data, &buffer_length);
+
+ if (buffer == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ *data_out = (const uint8_t *)buffer;
+ *data_size_out = (size_t)buffer_length;
+
+ return NSERROR_OK;
+}
diff --git a/gtk/resources.h b/gtk/resources.h
index bc08e47..dd52f54 100644
--- a/gtk/resources.h
+++ b/gtk/resources.h
@@ -16,12 +16,82 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Interface to gtk builtin resource handling.
+ *
+ * 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.
+ *
+ */
+
#ifndef NETSURF_GTK_RESOURCES_H
#define NETSURF_GTK_RESOURCES_H 1
/**
- * Creates a menu cursor from internal resources
+ * Initialise GTK resources handling.
+ *
+ * Must be called before attempting to retrieve any resources but
+ * after logging is initialised as it logs.
+ *
+ * \param respath A string vector of paths to search for resources.
+ * \return NSERROR_OK if all resources were located else an
+ * appropriate error code.
+ */
+nserror nsgtk_init_resources(char **respath);
+
+/**
+ * Creates a menu cursor from internal resources.
+ *
+ * \return Cursor object or NULL on error.
*/
GdkCursor *nsgtk_create_menu_cursor(void);
+/**
+ * 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);
+
+/**
+ * Get direct pointer to resource data.
+ *
+ * For a named resource this obtains a direct acesss pointer to the
+ * data and its length.
+ *
+ * The data is read only through this pointer and remains valid until
+ * program exit.
+ *
+ * \param resname The resource name to obtain data for.
+ * \param data_out The resulting data.
+ * \param data_size_out The resulting data size.
+ * \return NSERROR_OK and data_out updated or appropriate error code.
+ */
+nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out);
+
#endif
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c
index 3151ba1..c196242 100644
--- a/gtk/scaffolding.c
+++ b/gtk/scaffolding.c
@@ -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(g->tool_bar, "popup-context-menu",
- nsgtk_window_tool_bar_clicked, 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(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 */
diff --git a/gtk/ssl_cert.c b/gtk/ssl_cert.c
index 3c00d71..742029f 100644
--- a/gtk/ssl_cert.c
+++ b/gtk/ssl_cert.c
@@ -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);
diff --git a/gtk/throbber.c b/gtk/throbber.c
index 8726763..9392c39 100644
--- a/gtk/throbber.c
+++ b/gtk/throbber.c
@@ -20,76 +20,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#ifdef WITH_GIF
-#include <libnsgif.h>
-#endif
+#include <gtk/gtk.h>
+#include <stdint.h>
+
#include "utils/log.h"
+
+#include "gtk/resources.h"
#include "gtk/throbber.h"
-#include "gtk/bitmap.h"
struct nsgtk_throbber *nsgtk_throbber = NULL;
-/**
- * Creates the throbber using a PNG for each frame.
- *
- * The number of frames must be at least two. The first frame is the
- * inactive frame, others are the active frames.
- *
- * \param frames The number of frames. Must be at least two.
- * \param frame_files Filenames of PNGs containing frames.
- * \return true on success.
- */
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files)
+#define THROBBER_FRAMES 9
+#define THROBBER_FMT "throbber/throbber%d.png"
+
+/* exported interface documented in gtk/throbber.h */
+nserror nsgtk_throbber_init(void)
{
- GError *err = NULL;
struct nsgtk_throbber *throb; /**< structure we generate */
- bool errors_when_loading = false; /**< true if a frame failed */
- int frame_loop;
-
- if (frames < 2) {
- /* we need at least two frames - one for idle, one for active */
- LOG("Insufficent number of frames in throbber animation!");
- LOG("(called with %d frames, where 2 is a minimum.)", frames);
- return false;
- }
-
+ int frame;
+ char resname[] = THROBBER_FMT;
+ nserror res = NSERROR_OK;
+
throb = malloc(sizeof(*throb));
- if (throb == NULL)
- return false;
+ if (throb == NULL) {
+ return NSERROR_NOMEM;
+ }
- throb->nframes = frames;
- throb->framedata = malloc(sizeof(GdkPixbuf *) * throb->nframes);
+ throb->framedata = malloc(sizeof(GdkPixbuf *) * THROBBER_FRAMES);
if (throb->framedata == NULL) {
free(throb);
return false;
}
-
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- throb->framedata[frame_loop] = gdk_pixbuf_new_from_file(frame_files[frame_loop], &err);
- if (err != NULL) {
- LOG("Error when loading %s: %s (%d)", frame_files[frame_loop], err->message, err->code);
- throb->framedata[frame_loop] = NULL;
- errors_when_loading = true;
+
+ for (frame = 0; frame < THROBBER_FRAMES; frame++) {
+ snprintf(resname, sizeof(resname), THROBBER_FMT, frame);
+ res = nsgdk_pixbuf_new_from_resname(resname,
+ throb->framedata + frame);
+ if (res != NSERROR_OK) {
+ break;
}
+ LOG("%s",resname);
}
-
- if (errors_when_loading == true) {
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- if (throb->framedata[frame_loop] != NULL)
- g_object_unref(throb->framedata[frame_loop]);
- }
- free(throb->framedata);
- free(throb);
-
- return false;
+ if (frame < 1) {
+ /* we need at least two frames - one for idle, one for active */
+ LOG("Insufficent number of frames (%d) in throbber animation.", frame);
+ res = NSERROR_INIT_FAILED;
}
-
+
+ throb->nframes = frame;
nsgtk_throbber = throb;
-
- return true;
+ return res;
+
+
}
+
void nsgtk_throbber_finalise(void)
{
int i;
diff --git a/gtk/throbber.h b/gtk/throbber.h
index 1463c9b..e0b47e1 100644
--- a/gtk/throbber.h
+++ b/gtk/throbber.h
@@ -29,7 +29,7 @@ struct nsgtk_throbber
extern struct nsgtk_throbber *nsgtk_throbber;
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files);
+nserror nsgtk_throbber_init(void);
void nsgtk_throbber_finalise(void);
#endif /* __GTK_THROBBER_H__ */
diff --git a/gtk/toolbar.c b/gtk/toolbar.c
index 35ff25c..2345f56 100644
--- a/gtk/toolbar.c
+++ b/gtk/toolbar.c
@@ -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);
}
/**
diff --git a/gtk/viewdata.c b/gtk/viewdata.c
index 94dc5c5..7cd640f 100644
--- a/gtk/viewdata.c
+++ b/gtk/viewdata.c
@@ -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;
- }
-
- 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;
+ return res;
}
+ gtk_builder_connect_signals(newctx->builder, NULL);
- window = GTK_WINDOW(gtk_builder_get_object(newctx->builder, "ViewDataWindow"));
-
+ window = GTK_WINDOW(gtk_builder_get_object(newctx->builder,
+ "ViewDataWindow"));
if (window == NULL) {
LOG("Unable to find window in builder ");
diff --git a/gtk/window.c b/gtk/window.c
index 239c01e..481ae3b 100644
--- a/gtk/window.c
+++ b/gtk/window.c
@@ -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;
-
- /* 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);
+ GtkBuilder* tab_builder;
+
+ 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;
}
--
NetSurf Browser
7 years, 7 months
netsurf: branch master updated. release/3.3-160-g3db1e73
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/3db1e7381ab5cf31f1d47...
...commit http://git.netsurf-browser.org/netsurf.git/commit/3db1e7381ab5cf31f1d47f5...
...tree http://git.netsurf-browser.org/netsurf.git/tree/3db1e7381ab5cf31f1d47f5aa...
The branch, master has been updated
via 3db1e7381ab5cf31f1d47f5aa61ad85e3eafa494 (commit)
via d8ce401591add1d03dcee8da63f00ecc07172f16 (commit)
from c4d5393a972bb7ed276ce4bc5c92ba825d0a33f5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=3db1e7381ab5cf31f1d...
commit 3db1e7381ab5cf31f1d47f5aa61ad85e3eafa494
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Prettify pull-down (not context) menu.
diff --git a/amiga/menu.c b/amiga/menu.c
index eae3ccb..c946fb7 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -77,6 +77,7 @@
menu. Defaults to FALSE. */
/**/
+#define NSA_SPACE "blankspace.png"
enum {
NSA_GLYPH_SUBMENU,
@@ -546,7 +547,7 @@ void ami_free_menulabs(struct gui_window_2 *gwin)
}
static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type,
- const char *label, char key, char *icon, void *func, void *hookdata)
+ const char *label, char key, const char *icon, void *func, void *hookdata)
{
char menu_icon[1024];
@@ -570,8 +571,12 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type,
if(hookdata) gwin->menu_hook[num].h_Data = hookdata;
if(icon) {
- if(ami_locate_resource(menu_icon, icon) == true)
+ if(ami_locate_resource(menu_icon, icon) == true) {
gwin->menuicon[num] = (char *)strdup(menu_icon);
+ } else {
+ /* If the requested icon can't be found, put blank space in instead */
+ gwin->menuicon[num] = (char *)strdup(NSA_SPACE);
+ }
}
}
@@ -589,14 +594,14 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
}
ami_menu_alloc_item(gwin, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', NULL,
+ ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', "TBImages:list_app",
ami_menu_item_project_newwin, NULL);
- ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', NULL,
+ ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', "TBImages:list_add",
ami_menu_item_project_newtab, NULL);
ami_menu_alloc_item(gwin, M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', NULL,
+ ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', "TBImages:list_folder_misc",
ami_menu_item_project_open, NULL);
- ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, NULL, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, "TBImages:list_saveas", NULL, NULL);
ami_menu_alloc_item(gwin, M_SAVESRC, NM_SUB, "Source", 'S', NULL,
ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE);
ami_menu_alloc_item(gwin, M_SAVETXT, NM_SUB, "TextNS", 0, NULL,
@@ -610,60 +615,58 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
ami_menu_alloc_item(gwin, M_SAVEIFF, NM_SUB, "IFF", 0, NULL,
ami_menu_item_project_save, (void *)AMINS_SAVE_IFF);
ami_menu_alloc_item(gwin, M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', NULL,
+ ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', "TBImages:list_print",
ami_menu_item_project_print, NULL);
ami_menu_alloc_item(gwin, M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', NULL,
+ ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', "TBImages:list_remove",
ami_menu_item_project_closetab, NULL);
- ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, NULL,
+ ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, "TBImages:list_cancel",
ami_menu_item_project_closewin, NULL);
ami_menu_alloc_item(gwin, M_BAR_P4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', NULL,
+ ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', "TBImages:list_info",
ami_menu_item_project_about, NULL);
ami_menu_alloc_item(gwin, M_BAR_P5, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', NULL,
+ ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', "TBImages:list_warning",
ami_menu_item_project_quit, NULL);
ami_menu_alloc_item(gwin, M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', NULL,
+ ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', "TBImages:list_cut",
ami_menu_item_edit_cut, NULL);
- ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', NULL,
+ ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', "TBImages:list_copy",
ami_menu_item_edit_copy, NULL);
- ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', NULL,
+ ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', "TBImages:list_paste",
ami_menu_item_edit_paste, NULL);
ami_menu_alloc_item(gwin, M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NULL,
+ ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE,
ami_menu_item_edit_selectall, NULL);
- ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE,
ami_menu_item_edit_clearsel, NULL);
ami_menu_alloc_item(gwin, M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', NULL,
+ ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', "TBImages:list_undo",
ami_menu_item_edit_undo, NULL);
- ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', NULL,
+ ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', "TBImages:list_redo",
ami_menu_item_edit_redo, NULL);
ami_menu_alloc_item(gwin, M_BROWSER, NM_TITLE, "Browser", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', NULL,
+ ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', "TBImages:list_search",
ami_menu_item_browser_find, NULL);
ami_menu_alloc_item(gwin, M_BAR_B1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, "TBImages:list_history",
ami_menu_item_browser_localhistory, NULL);
- ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, "TBImages:list_history",
ami_menu_item_browser_globalhistory, NULL);
ami_menu_alloc_item(gwin, M_BAR_B2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, "TBImages:list_internet",
ami_menu_item_browser_cookies, NULL);
ami_menu_alloc_item(gwin, M_BAR_B3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL,
+ ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NSA_SPACE, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', "TBImages:list_zoom_out",
ami_menu_item_browser_scale_decrease, NULL);
- ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', NULL,
+ ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', "TBImages:list_zoom_100",
ami_menu_item_browser_scale_normal, NULL);
- ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL,
- ami_menu_item_browser_scale_decrease, NULL);
- ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', NULL,
+ ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', "TBImages:list_zoom_in",
ami_menu_item_browser_scale_increase, NULL);
- ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, NULL, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, "TBImages:list_image", NULL, NULL);
ami_menu_alloc_item(gwin, M_IMGFORE, NM_SUB, "ForeImg", 0, NULL,
ami_menu_item_browser_foreimg, NULL);
ami_menu_alloc_item(gwin, M_IMGBACK, NM_SUB, "BackImg", 0, NULL,
@@ -673,27 +676,27 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
ami_menu_item_browser_enablejs, NULL);
#endif
ami_menu_alloc_item(gwin, M_BAR_B4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, NULL,
+ ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, "TBImages:list_wand",
ami_menu_item_browser_redraw, NULL);
ami_menu_alloc_item(gwin, M_HOTLIST, NM_TITLE, "Hotlist", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', NULL,
+ ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', "TBImages:list_favouriteadd",
ami_menu_item_hotlist_add, NULL);
- ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', NULL,
+ ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', "TBImages:list_favourite",
ami_menu_item_hotlist_show, NULL);
ami_menu_alloc_item(gwin, M_BAR_H1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
ami_menu_alloc_item(gwin, M_PREFS, NM_TITLE, "Settings", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, NULL,
+ ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, "TBImages:list_prefs",
ami_menu_item_settings_edit, NULL);
ami_menu_alloc_item(gwin, M_BAR_S1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, NULL,
+ ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, "TBImages:list_hold",
ami_menu_item_settings_snapshot, NULL);
- ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, NULL,
+ ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, "TBImages:list_use",
ami_menu_item_settings_save, NULL);
ami_menu_alloc_item(gwin, M_AREXX, NM_TITLE, "ARexx", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', NULL,
+ ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', "TBImages:list_arexx",
ami_menu_item_arexx_execute, NULL);
ami_menu_alloc_item(gwin, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END;
@@ -779,6 +782,14 @@ static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct Ras
item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
/**TODO: take account of the size of other imagery too
*/
+ } else {
+ /* assume worst case - it doesn't really matter if we make menus wider */
+ item_size += TextLength(rp, "M", 1);
+ item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
+ }
+
+ if(gwin->menuicon[j]) {
+ item_size += 16;
}
return item_size;
diff --git a/amiga/resources/blankspace.png b/amiga/resources/blankspace.png
new file mode 100644
index 0000000..1f1e672
Binary files /dev/null and b/amiga/resources/blankspace.png differ
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=d8ce401591add1d03dc...
commit d8ce401591add1d03dcee8da63f00ecc07172f16
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Remove some workarounds to make image menus conform better on OS4.1u6. They never quite matched normal menus so are going to look odd when we add more images anyway.
diff --git a/amiga/menu.c b/amiga/menu.c
index 5ed1e3a..eae3ccb 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -788,7 +788,7 @@ static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct Ras
static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
{
int i, j;
- int txtlen = 0, subtxtlen = 0;
+ int txtlen = 0;
int left_posn;
struct RastPort *rp = &scrn->RastPort;
struct DrawInfo *dri = GetScreenDrawInfo(scrn);
@@ -820,7 +820,6 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
using label.image if there's a bitmap associated with the item. */
if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) {
int icon_width = 0;
- Object *blank_space = NULL;
Object *submenuarrow = NULL;
Object *icon = BitMapObj,
BITMAP_Screen, scrn,
@@ -836,9 +835,7 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
GetAttr(IA_Width, icon, (ULONG *)&icon_width);
- if(gwin->menutype[i] == NM_SUB) {
- left_posn = subtxtlen;
- } else {
+ if(gwin->menutype[i] != NM_SUB) {
left_posn = txtlen;
}
@@ -854,32 +851,8 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
SYSIA_DrawInfo, dri,
IA_Left, left_posn,
TAG_DONE);
-
- j = i + 1;
- subtxtlen = 0;
- do {
- if(gwin->menulab[j] != NM_BARLABEL) {
- if(gwin->menutype[j] == NM_SUB) {
- int item_size = ami_menu_calc_item_width(gwin, j, rp);
- if(item_size > subtxtlen) {
- subtxtlen = item_size;
- }
- }
- }
- j++;
- } while((gwin->menutype[j] == NM_SUB));
}
- /**TODO: Checkmark/MX images and keyboard shortcuts
- */
-
- if(gwin->menutype[i] == NM_SUB) {
- blank_space = NewObject(NULL, "fillrectclass",
- IA_Height, 0,
- IA_Width, left_posn + icon_width,
- TAG_DONE);
- }
-
gwin->menuobj[i] = LabelObj,
LABEL_MenuMode, TRUE,
LABEL_DrawInfo, dri,
@@ -888,8 +861,6 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
LABEL_Text, " ",
LABEL_Text, gwin->menulab[i],
LABEL_DisposeImage, TRUE,
- LABEL_Image, blank_space,
- LABEL_DisposeImage, TRUE,
LABEL_Image, submenuarrow,
LabelEnd;
-----------------------------------------------------------------------
Summary of changes:
amiga/menu.c | 116 +++++++++++++++++-----------------------
amiga/resources/blankspace.png | Bin 0 -> 85 bytes
2 files changed, 49 insertions(+), 67 deletions(-)
create mode 100644 amiga/resources/blankspace.png
diff --git a/amiga/menu.c b/amiga/menu.c
index 5ed1e3a..c946fb7 100644
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -77,6 +77,7 @@
menu. Defaults to FALSE. */
/**/
+#define NSA_SPACE "blankspace.png"
enum {
NSA_GLYPH_SUBMENU,
@@ -546,7 +547,7 @@ void ami_free_menulabs(struct gui_window_2 *gwin)
}
static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type,
- const char *label, char key, char *icon, void *func, void *hookdata)
+ const char *label, char key, const char *icon, void *func, void *hookdata)
{
char menu_icon[1024];
@@ -570,8 +571,12 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type,
if(hookdata) gwin->menu_hook[num].h_Data = hookdata;
if(icon) {
- if(ami_locate_resource(menu_icon, icon) == true)
+ if(ami_locate_resource(menu_icon, icon) == true) {
gwin->menuicon[num] = (char *)strdup(menu_icon);
+ } else {
+ /* If the requested icon can't be found, put blank space in instead */
+ gwin->menuicon[num] = (char *)strdup(NSA_SPACE);
+ }
}
}
@@ -589,14 +594,14 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
}
ami_menu_alloc_item(gwin, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', NULL,
+ ami_menu_alloc_item(gwin, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', "TBImages:list_app",
ami_menu_item_project_newwin, NULL);
- ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', NULL,
+ ami_menu_alloc_item(gwin, M_NEWTAB, NM_ITEM, "NewTab", 'T', "TBImages:list_add",
ami_menu_item_project_newtab, NULL);
ami_menu_alloc_item(gwin, M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', NULL,
+ ami_menu_alloc_item(gwin, M_OPEN, NM_ITEM, "OpenFile", 'O', "TBImages:list_folder_misc",
ami_menu_item_project_open, NULL);
- ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, NULL, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, "TBImages:list_saveas", NULL, NULL);
ami_menu_alloc_item(gwin, M_SAVESRC, NM_SUB, "Source", 'S', NULL,
ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE);
ami_menu_alloc_item(gwin, M_SAVETXT, NM_SUB, "TextNS", 0, NULL,
@@ -610,60 +615,58 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
ami_menu_alloc_item(gwin, M_SAVEIFF, NM_SUB, "IFF", 0, NULL,
ami_menu_item_project_save, (void *)AMINS_SAVE_IFF);
ami_menu_alloc_item(gwin, M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', NULL,
+ ami_menu_alloc_item(gwin, M_PRINT, NM_ITEM, "PrintNS", 'P', "TBImages:list_print",
ami_menu_item_project_print, NULL);
ami_menu_alloc_item(gwin, M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', NULL,
+ ami_menu_alloc_item(gwin, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', "TBImages:list_remove",
ami_menu_item_project_closetab, NULL);
- ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, NULL,
+ ami_menu_alloc_item(gwin, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, "TBImages:list_cancel",
ami_menu_item_project_closewin, NULL);
ami_menu_alloc_item(gwin, M_BAR_P4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', NULL,
+ ami_menu_alloc_item(gwin, M_ABOUT, NM_ITEM, "About", '?', "TBImages:list_info",
ami_menu_item_project_about, NULL);
ami_menu_alloc_item(gwin, M_BAR_P5, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', NULL,
+ ami_menu_alloc_item(gwin, M_QUIT, NM_ITEM, "Quit", 'Q', "TBImages:list_warning",
ami_menu_item_project_quit, NULL);
ami_menu_alloc_item(gwin, M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', NULL,
+ ami_menu_alloc_item(gwin, M_CUT, NM_ITEM, "CutNS", 'X', "TBImages:list_cut",
ami_menu_item_edit_cut, NULL);
- ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', NULL,
+ ami_menu_alloc_item(gwin, M_COPY, NM_ITEM, "CopyNS", 'C', "TBImages:list_copy",
ami_menu_item_edit_copy, NULL);
- ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', NULL,
+ ami_menu_alloc_item(gwin, M_PASTE, NM_ITEM, "PasteNS", 'V', "TBImages:list_paste",
ami_menu_item_edit_paste, NULL);
ami_menu_alloc_item(gwin, M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NULL,
+ ami_menu_alloc_item(gwin, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE,
ami_menu_item_edit_selectall, NULL);
- ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE,
ami_menu_item_edit_clearsel, NULL);
ami_menu_alloc_item(gwin, M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', NULL,
+ ami_menu_alloc_item(gwin, M_UNDO, NM_ITEM, "Undo", 'Z', "TBImages:list_undo",
ami_menu_item_edit_undo, NULL);
- ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', NULL,
+ ami_menu_alloc_item(gwin, M_REDO, NM_ITEM, "Redo", 'Y', "TBImages:list_redo",
ami_menu_item_edit_redo, NULL);
ami_menu_alloc_item(gwin, M_BROWSER, NM_TITLE, "Browser", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', NULL,
+ ami_menu_alloc_item(gwin, M_FIND, NM_ITEM, "FindTextNS", 'F', "TBImages:list_search",
ami_menu_item_browser_find, NULL);
ami_menu_alloc_item(gwin, M_BAR_B1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, "TBImages:list_history",
ami_menu_item_browser_localhistory, NULL);
- ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, "TBImages:list_history",
ami_menu_item_browser_globalhistory, NULL);
ami_menu_alloc_item(gwin, M_BAR_B2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, NULL,
+ ami_menu_alloc_item(gwin, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, "TBImages:list_internet",
ami_menu_item_browser_cookies, NULL);
ami_menu_alloc_item(gwin, M_BAR_B3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL,
+ ami_menu_alloc_item(gwin, M_SCALE, NM_ITEM, "ScaleNS", 0, NSA_SPACE, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', "TBImages:list_zoom_out",
ami_menu_item_browser_scale_decrease, NULL);
- ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', NULL,
+ ami_menu_alloc_item(gwin, M_SCALENRM, NM_SUB, "ScaleNorm", '=', "TBImages:list_zoom_100",
ami_menu_item_browser_scale_normal, NULL);
- ami_menu_alloc_item(gwin, M_SCALEDEC, NM_SUB, "ScaleDec", '-', NULL,
- ami_menu_item_browser_scale_decrease, NULL);
- ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', NULL,
+ ami_menu_alloc_item(gwin, M_SCALEINC, NM_SUB, "ScaleInc", '+', "TBImages:list_zoom_in",
ami_menu_item_browser_scale_increase, NULL);
- ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, NULL, NULL, NULL);
+ ami_menu_alloc_item(gwin, M_IMAGES, NM_ITEM, "Images", 0, "TBImages:list_image", NULL, NULL);
ami_menu_alloc_item(gwin, M_IMGFORE, NM_SUB, "ForeImg", 0, NULL,
ami_menu_item_browser_foreimg, NULL);
ami_menu_alloc_item(gwin, M_IMGBACK, NM_SUB, "BackImg", 0, NULL,
@@ -673,27 +676,27 @@ static void ami_init_menulabs(struct gui_window_2 *gwin)
ami_menu_item_browser_enablejs, NULL);
#endif
ami_menu_alloc_item(gwin, M_BAR_B4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, NULL,
+ ami_menu_alloc_item(gwin, M_REDRAW, NM_ITEM, "Redraw", 0, "TBImages:list_wand",
ami_menu_item_browser_redraw, NULL);
ami_menu_alloc_item(gwin, M_HOTLIST, NM_TITLE, "Hotlist", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', NULL,
+ ami_menu_alloc_item(gwin, M_HLADD, NM_ITEM, "HotlistAdd", 'B', "TBImages:list_favouriteadd",
ami_menu_item_hotlist_add, NULL);
- ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', NULL,
+ ami_menu_alloc_item(gwin, M_HLSHOW, NM_ITEM,"HotlistShowNS",'H', "TBImages:list_favourite",
ami_menu_item_hotlist_show, NULL);
ami_menu_alloc_item(gwin, M_BAR_H1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
ami_menu_alloc_item(gwin, M_PREFS, NM_TITLE, "Settings", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, NULL,
+ ami_menu_alloc_item(gwin, M_PREDIT, NM_ITEM, "SettingsEdit", 0, "TBImages:list_prefs",
ami_menu_item_settings_edit, NULL);
ami_menu_alloc_item(gwin, M_BAR_S1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, NULL,
+ ami_menu_alloc_item(gwin, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, "TBImages:list_hold",
ami_menu_item_settings_snapshot, NULL);
- ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, NULL,
+ ami_menu_alloc_item(gwin, M_PRSAVE, NM_ITEM, "SettingsSave", 0, "TBImages:list_use",
ami_menu_item_settings_save, NULL);
ami_menu_alloc_item(gwin, M_AREXX, NM_TITLE, "ARexx", 0, NULL, NULL, NULL);
- ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', NULL,
+ ami_menu_alloc_item(gwin, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', "TBImages:list_arexx",
ami_menu_item_arexx_execute, NULL);
ami_menu_alloc_item(gwin, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL);
gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END;
@@ -779,6 +782,14 @@ static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct Ras
item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
/**TODO: take account of the size of other imagery too
*/
+ } else {
+ /* assume worst case - it doesn't really matter if we make menus wider */
+ item_size += TextLength(rp, "M", 1);
+ item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
+ }
+
+ if(gwin->menuicon[j]) {
+ item_size += 16;
}
return item_size;
@@ -788,7 +799,7 @@ static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct Ras
static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
{
int i, j;
- int txtlen = 0, subtxtlen = 0;
+ int txtlen = 0;
int left_posn;
struct RastPort *rp = &scrn->RastPort;
struct DrawInfo *dri = GetScreenDrawInfo(scrn);
@@ -820,7 +831,6 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
using label.image if there's a bitmap associated with the item. */
if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) {
int icon_width = 0;
- Object *blank_space = NULL;
Object *submenuarrow = NULL;
Object *icon = BitMapObj,
BITMAP_Screen, scrn,
@@ -836,9 +846,7 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
GetAttr(IA_Width, icon, (ULONG *)&icon_width);
- if(gwin->menutype[i] == NM_SUB) {
- left_posn = subtxtlen;
- } else {
+ if(gwin->menutype[i] != NM_SUB) {
left_posn = txtlen;
}
@@ -854,32 +862,8 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
SYSIA_DrawInfo, dri,
IA_Left, left_posn,
TAG_DONE);
-
- j = i + 1;
- subtxtlen = 0;
- do {
- if(gwin->menulab[j] != NM_BARLABEL) {
- if(gwin->menutype[j] == NM_SUB) {
- int item_size = ami_menu_calc_item_width(gwin, j, rp);
- if(item_size > subtxtlen) {
- subtxtlen = item_size;
- }
- }
- }
- j++;
- } while((gwin->menutype[j] == NM_SUB));
}
- /**TODO: Checkmark/MX images and keyboard shortcuts
- */
-
- if(gwin->menutype[i] == NM_SUB) {
- blank_space = NewObject(NULL, "fillrectclass",
- IA_Height, 0,
- IA_Width, left_posn + icon_width,
- TAG_DONE);
- }
-
gwin->menuobj[i] = LabelObj,
LABEL_MenuMode, TRUE,
LABEL_DrawInfo, dri,
@@ -888,8 +872,6 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
LABEL_Text, " ",
LABEL_Text, gwin->menulab[i],
LABEL_DisposeImage, TRUE,
- LABEL_Image, blank_space,
- LABEL_DisposeImage, TRUE,
LABEL_Image, submenuarrow,
LabelEnd;
diff --git a/amiga/resources/blankspace.png b/amiga/resources/blankspace.png
new file mode 100644
index 0000000..1f1e672
Binary files /dev/null and b/amiga/resources/blankspace.png differ
--
NetSurf Browser
7 years, 7 months