NetSurf
Data Structures | Macros | Enumerations | Functions | Variables
resources.c File Reference

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"
Include dependency graph for resources.c:

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_sfind_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...
 

Detailed Description

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.

Macro Definition Documentation

◆ RES_ENTRY

#define RES_ENTRY (   name)    { name, sizeof((name)) - 1, NSGTK_RESOURCE_FILE, NULL }

Definition at line 73 of file resources.c.

Enumeration Type Documentation

◆ nsgtk_resource_type_e

log contents of gresource /org/netsource

type of resource entry

Enumerator
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

Definition at line 58 of file resources.c.

Function Documentation

◆ find_resource_from_name()

static struct nsgtk_resource_s * find_resource_from_name ( const char *  resname,
struct nsgtk_resource_s resource 
)
static

Find a resource entry by name.

Parameters
resnameThe resource name to match.
resourceThe 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().

Here is the caller graph for this function:

◆ init_direct_resource()

static nserror init_direct_resource ( char **  respath,
struct nsgtk_resource_s resource 
)
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.

Parameters
respathA string vector containing the valid resource search paths
resourceA 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_pixbuf_resource()

static nserror init_pixbuf_resource ( char **  respath,
struct nsgtk_resource_s resource 
)
static

locate a pixbuf resource

Pixbuf resources can be compiled inline

Parameters
respathA string vector containing the valid resource search paths
resourceA 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_resource()

static nserror init_resource ( char **  respath,
struct nsgtk_resource_s resource 
)
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.

Parameters
respathA string vector containing the valid resource search paths
resourceA 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_ui_resource()

static nserror init_ui_resource ( char **  respath,
struct nsgtk_resource_s ui_res 
)
static

locate a ui resource

UI resources need their resource name changing to account for gtk versions

Parameters
respathA string vector containing the valid resource search paths
ui_resA 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgdk_pixbuf_new_from_resname()

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()

Parameters
resnameThe resource name to construct for
pixbuf_outThe pixbuf result
Returns
NSERROR_OK and pixbuf_out updated or appropriate error code

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_builder_new_from_resname()

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()

Parameters
resnameThe resource name to construct for
builder_outThe builder result
Returns
NSERROR_OK and builder_out updated or appropriate error code

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_create_menu_cursor()

GdkCursor * nsgtk_create_menu_cursor ( void  )

Creates a menu cursor from internal resources.

Returns
Cursor object or NULL on error.

Definition at line 148 of file resources.c.

References NSERROR_OK, and nsgdk_pixbuf_new_from_resname().

Referenced by gui_window_set_pointer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_data_from_resname()

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.

Parameters
resnameThe resource name to obtain data for.
data_outThe resulting data.
data_size_outThe resulting data size.
Returns
NSERROR_OK and data_out updated or appropriate error code.
Todo:
consider adding compiled inline resources for things other than pixbufs.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_init_resources()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_path_from_resname()

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.

Parameters
resnameThe resource name to obtain path for.
path_outThe resulting data.
Returns
NSERROR_OK and path_out updated or appropriate error code.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ direct_resource

struct nsgtk_resource_s direct_resource[]
static
Initial value:
= {
RES_ENTRY("welcome.html"),
RES_ENTRY("credits.html"),
RES_ENTRY("licence.html"),
RES_ENTRY("default.css"),
RES_ENTRY("adblock.css"),
RES_ENTRY("internal.css"),
RES_ENTRY("quirks.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"),
RES_ENTRY("languages"),
RES_ENTRY("accelerators"),
RES_ENTRY("Messages"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
}
@ NSGTK_RESOURCE_FILE
entry is a file on disc
Definition: resources.c:59
#define RES_ENTRY(name)
Definition: resources.c:73

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().

◆ pixbuf_resource

struct nsgtk_resource_s pixbuf_resource[]
static
Initial value:
= {
RES_ENTRY("favicon.png"),
RES_ENTRY("netsurf.xpm"),
RES_ENTRY("menu_cursor.png"),
RES_ENTRY("icons/local-history.png"),
RES_ENTRY("icons/show-cookie.png"),
RES_ENTRY("icons/24x24/actions/page-info-insecure.png"),
RES_ENTRY("icons/24x24/actions/page-info-internal.png"),
RES_ENTRY("icons/24x24/actions/page-info-local.png"),
RES_ENTRY("icons/24x24/actions/page-info-secure.png"),
RES_ENTRY("icons/24x24/actions/page-info-warning.png"),
RES_ENTRY("icons/48x48/actions/page-info-insecure.png"),
RES_ENTRY("icons/48x48/actions/page-info-internal.png"),
RES_ENTRY("icons/48x48/actions/page-info-local.png"),
RES_ENTRY("icons/48x48/actions/page-info-secure.png"),
RES_ENTRY("icons/48x48/actions/page-info-warning.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 as pixbufs

Definition at line 94 of file resources.c.

Referenced by nsgdk_pixbuf_new_from_resname(), and nsgtk_init_resources().

◆ ui_resource

struct nsgtk_resource_s ui_resource[]
static
Initial value:
= {
RES_ENTRY("netsurf"),
RES_ENTRY("tabcontents"),
RES_ENTRY("password"),
RES_ENTRY("toolbar"),
RES_ENTRY("downloads"),
RES_ENTRY("globalhistory"),
RES_ENTRY("localhistory"),
RES_ENTRY("options"),
RES_ENTRY("hotlist"),
RES_ENTRY("cookies"),
RES_ENTRY("viewdata"),
RES_ENTRY("warning"),
RES_ENTRY("pageinfo"),
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
}

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().