NetSurf
|
Implementation of gtk builtin resource handling. More...
#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"
Go to the source code of this file.
Data Structures | |
struct | nsgtk_resource_s |
resource entry More... | |
Macros | |
#define | RES_ENTRY(name) { name, sizeof((name)) - 1, NSGTK_RESOURCE_FILE, NULL } |
Enumerations | |
enum | nsgtk_resource_type_e { NSGTK_RESOURCE_FILE , NSGTK_RESOURCE_GLIB , NSGTK_RESOURCE_DIRECT , NSGTK_RESOURCE_INLINE } |
log contents of gresource /org/netsource More... | |
Functions | |
GdkCursor * | nsgtk_create_menu_cursor (void) |
Creates a menu cursor from internal resources. More... | |
static nserror | init_resource (char **respath, struct nsgtk_resource_s *resource) |
locate a resource More... | |
static nserror | init_direct_resource (char **respath, struct nsgtk_resource_s *resource) |
locate and setup a direct resource More... | |
static nserror | init_pixbuf_resource (char **respath, struct nsgtk_resource_s *resource) |
locate a pixbuf resource More... | |
static nserror | init_ui_resource (char **respath, struct nsgtk_resource_s *ui_res) |
locate a ui resource More... | |
static struct nsgtk_resource_s * | find_resource_from_name (const char *resname, struct nsgtk_resource_s *resource) |
Find a resource entry by name. More... | |
nserror | nsgtk_init_resources (char **respath) |
Initialise UI resource table. More... | |
nserror | nsgdk_pixbuf_new_from_resname (const char *resname, GdkPixbuf **pixbuf_out) |
Create gdk pixbuf for the named ui resource. More... | |
nserror | nsgtk_builder_new_from_resname (const char *resname, GtkBuilder **builder_out) |
Create gtk builder object for the named ui resource. More... | |
nserror | nsgtk_data_from_resname (const char *resname, const uint8_t **data_out, size_t *data_size_out) |
Get direct pointer to resource data. More... | |
nserror | nsgtk_path_from_resname (const char *resname, const char **path_out) |
Get path to resource data. More... | |
Variables | |
static struct nsgtk_resource_s | ui_resource [] |
resources that are used for gtk builder More... | |
static struct nsgtk_resource_s | pixbuf_resource [] |
resources that are used as pixbufs More... | |
static struct nsgtk_resource_s | direct_resource [] |
resources that are used for direct data access More... | |
Implementation of 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.
Definition in file resources.c.
#define RES_ENTRY | ( | name | ) | { name, sizeof((name)) - 1, NSGTK_RESOURCE_FILE, NULL } |
Definition at line 73 of file resources.c.
log contents of gresource /org/netsource
type of resource entry
Definition at line 58 of file resources.c.
|
static |
Find a resource entry by name.
resname | The resource name to match. |
resource | The list of resources entries to search. |
Definition at line 381 of file resources.c.
References nsgtk_resource_s::len, and nsgtk_resource_s::name.
Referenced by nsgdk_pixbuf_new_from_resname(), nsgtk_builder_new_from_resname(), nsgtk_data_from_resname(), and nsgtk_path_from_resname().
|
static |
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.
respath | A string vector containing the valid resource search paths |
resource | A resource entry to initialise |
Definition at line 277 of file resources.c.
References init_resource(), NSERROR_OK, NSGTK_RESOURCE_DIRECT, NSGTK_RESOURCE_GLIB, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by nsgtk_init_resources().
|
static |
locate a pixbuf resource
Pixbuf resources can be compiled inline
respath | A string vector containing the valid resource search paths |
resource | A resource entry to initialise |
Definition at line 311 of file resources.c.
References init_resource(), nsgtk_resource_s::len, nsgtk_resource_s::name, NSERROR_OK, NSGTK_RESOURCE_INLINE, NSLOG, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by nsgtk_init_resources().
|
static |
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.
respath | A string vector containing the valid resource search paths |
resource | A resource entry to initialise |
Definition at line 180 of file resources.c.
References filepath_find(), nsgtk_resource_s::name, NSERROR_NOMEM, NSERROR_NOT_FOUND, NSERROR_OK, NSGTK_RESOURCE_FILE, NSGTK_RESOURCE_GLIB, NSLOG, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by init_direct_resource(), init_pixbuf_resource(), and init_ui_resource().
|
static |
locate a ui resource
UI resources need their resource name changing to account for gtk versions
respath | A string vector containing the valid resource search paths |
ui_res | A resource entry to initialise |
Definition at line 346 of file resources.c.
References init_resource(), nsgtk_resource_s::len, nsgtk_resource_s::name, NSERROR_NOMEM, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by nsgtk_init_resources().
nserror nsgdk_pixbuf_new_from_resname | ( | const char * | resname, |
GdkPixbuf ** | pixbuf_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()
resname | The resource name to construct for |
pixbuf_out | The pixbuf result |
Definition at line 470 of file resources.c.
References find_resource_from_name(), nsgtk_resource_s::name, NSERROR_INIT_FAILED, NSERROR_NOT_FOUND, NSERROR_OK, NSGTK_RESOURCE_DIRECT, NSGTK_RESOURCE_FILE, NSGTK_RESOURCE_GLIB, NSGTK_RESOURCE_INLINE, NSLOG, nsgtk_resource_s::path, pixbuf_resource, and nsgtk_resource_s::type.
Referenced by add_builtin_icon(), nsgtk_create_menu_cursor(), nsgtk_setup(), and nsgtk_throbber_init().
nserror nsgtk_builder_new_from_resname | ( | const char * | resname, |
GtkBuilder ** | builder_out | ||
) |
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()
resname | The resource name to construct for |
builder_out | The builder result |
Definition at line 526 of file resources.c.
References find_resource_from_name(), nsgtk_resource_s::name, NSERROR_INIT_FAILED, NSERROR_NOT_FOUND, NSERROR_OK, nsgtk_builder_add_from_resource(), NSGTK_RESOURCE_FILE, NSLOG, nsgtk_resource_s::path, nsgtk_resource_s::type, and ui_resource.
Referenced by cutomize_button_clicked_cb(), gui_window_create(), nsgtk_cookies_init(), nsgtk_download_init(), nsgtk_global_history_init(), nsgtk_hotlist_init(), nsgtk_local_history_init(), nsgtk_new_scaffolding(), nsgtk_page_info(), nsgtk_pdf_password(), nsgtk_preferences(), nsgtk_setup(), and window_init().
GdkCursor * nsgtk_create_menu_cursor | ( | void | ) |
Creates a menu cursor from internal resources.
Definition at line 148 of file resources.c.
References NSERROR_OK, and nsgdk_pixbuf_new_from_resname().
Referenced by gui_window_set_pointer().
nserror nsgtk_data_from_resname | ( | const char * | resname, |
const uint8_t ** | data_out, | ||
size_t * | data_size_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.
resname | The resource name to obtain data for. |
data_out | The resulting data. |
data_size_out | The resulting data size. |
Definition at line 574 of file resources.c.
References buffer, direct_resource, find_resource_from_name(), nsgtk_resource_s::name, NSERROR_NOMEM, NSERROR_NOT_FOUND, NSERROR_OK, NSGTK_RESOURCE_DIRECT, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by nsgtk_accelerator_init(), nsgtk_messages_init(), and nsgtk_preferences_comboboxLanguage_realize().
nserror nsgtk_init_resources | ( | char ** | respath | ) |
Initialise UI resource table.
Initialise GTK resources handling.
Definition at line 425 of file resources.c.
References direct_resource, init_direct_resource(), init_pixbuf_resource(), init_ui_resource(), nsgtk_resource_s::name, NSERROR_OK, pixbuf_resource, and ui_resource.
Referenced by nsgtk_init().
nserror nsgtk_path_from_resname | ( | const char * | resname, |
const char ** | path_out | ||
) |
Get path to resource data.
For a named resource this obtains the on-disc path to that resource.
The path is read only and remains valid untill program exit.
resname | The resource name to obtain path for. |
path_out | The resulting data. |
Definition at line 613 of file resources.c.
References direct_resource, find_resource_from_name(), nsgtk_resource_s::name, NSERROR_NOT_FOUND, NSERROR_OK, NSGTK_RESOURCE_FILE, nsgtk_resource_s::path, and nsgtk_resource_s::type.
Referenced by nsgtk_accelerator_init(), nsgtk_messages_init(), and nsgtk_preferences_comboboxLanguage_realize().
|
static |
resources that are used for direct data access
Definition at line 123 of file resources.c.
Referenced by nsgtk_data_from_resname(), nsgtk_init_resources(), and nsgtk_path_from_resname().
|
static |
resources that are used as pixbufs
Definition at line 94 of file resources.c.
Referenced by nsgdk_pixbuf_new_from_resname(), and nsgtk_init_resources().
|
static |
resources that are used for gtk builder
Definition at line 76 of file resources.c.
Referenced by nsgtk_builder_new_from_resname(), and nsgtk_init_resources().