summaryrefslogtreecommitdiff
path: root/gtk/hotlist.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-06-13 11:31:23 +0100
committerVincent Sanders <vince@kyllikki.org>2015-06-17 21:35:40 +0100
commit8ef292b9caf5cae2197493a87480723138f10344 (patch)
treefa39583104ab806b81f382eb85bc9f5a05331dfd /gtk/hotlist.c
parent16fbb97dbb1688fd9b6f19546792b4173bc30bf1 (diff)
downloadnetsurf-8ef292b9caf5cae2197493a87480723138f10344.tar.gz
netsurf-8ef292b9caf5cae2197493a87480723138f10344.tar.bz2
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.
Diffstat (limited to 'gtk/hotlist.c')
-rw-r--r--gtk/hotlist.c84
1 files changed, 41 insertions, 43 deletions
diff --git a/gtk/hotlist.c b/gtk/hotlist.c
index fed6ae735..8258e0990 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);
}