NetSurf
Functions | Variables
gui.c File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <gtk/gtk.h>
#include "utils/filepath.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/file.h"
#include "utils/nsoption.h"
#include "netsurf/keypress.h"
#include "netsurf/url_db.h"
#include "netsurf/cookie_db.h"
#include "netsurf/browser.h"
#include "netsurf/browser_window.h"
#include "netsurf/netsurf.h"
#include "netsurf/bitmap.h"
#include "content/fetch.h"
#include "content/backing_store.h"
#include "desktop/save_complete.h"
#include "desktop/searchweb.h"
#include "desktop/hotlist.h"
#include "gtk/compat.h"
#include "gtk/warn.h"
#include "gtk/completion.h"
#include "gtk/cookies.h"
#include "gtk/download.h"
#include "gtk/fetch.h"
#include "gtk/gui.h"
#include "gtk/local_history.h"
#include "gtk/global_history.h"
#include "gtk/hotlist.h"
#include "gtk/throbber.h"
#include "gtk/toolbar_items.h"
#include "gtk/scaffolding.h"
#include "gtk/window.h"
#include "gtk/schedule.h"
#include "gtk/selection.h"
#include "gtk/search.h"
#include "gtk/bitmap.h"
#include "gtk/misc.h"
#include "gtk/resources.h"
#include "gtk/layout_pango.h"
#include "gtk/accelerator.h"
Include dependency graph for gui.c:

Go to the source code of this file.

Functions

nserror nsgtk_warning (const char *warning, const char *detail)
 Warn the user of an event. More...
 
uint32_t gtk_gui_gdkkey_to_nskey (GdkEventKey *key)
 input conversion. More...
 
static char ** nsgtk_init_resource_path (const char *config_home)
 Create an array of valid paths to search for resources. More...
 
static nserror check_dirname (const char *path, const char *leaf, char **dirname_out)
 create directory name and check it is acessible and a directory. More...
 
static nserror get_config_home (char **config_home_out)
 Get the path to the config directory. More...
 
static nserror create_config_home (char **config_home_out)
 
static bool nslog_stream_configure (FILE *fptr)
 Ensures output logging stream is correctly configured. More...
 
static nserror set_defaults (struct nsoption_s *defaults)
 Set option defaults for gtk frontend. More...
 
static nserror nsgtk_option_init (int *pargc, char **argv)
 Initialise user options. More...
 
static nserror nsgtk_messages_init (char **respaths)
 initialise message translation More...
 
static nserror get_cache_home (char **cache_home_out)
 Get the path to the cache directory. More...
 
static nserror create_cache_home (char **cache_home_out)
 create a cache directory More...
 
static nserror nsgtk_init (int *pargc, char ***pargv, char **cache_home)
 GTK specific initialisation. More...
 
static nserror add_builtin_icon (const char *prefix, const char *name, int x, int y)
 
static nserror nsgtk_add_named_icons_to_theme (void)
 adds named icons into gtk theme More...
 
static nserror nsgtk_setup (int argc, char **argv, char **respath)
 setup GTK specific parts of the browser. More...
 
static void nsgtk_main (void)
 Run the gtk event loop. More...
 
static void nsgtk_finalise (void)
 finalise the browser More...
 
int main (int argc, char **argv)
 Main entry point from OS. More...
 

Variables

bool nsgtk_complete = false
 set when no windows remain open. More...
 
char * nsgtk_config_home
 Directory where all configuration files are held. More...
 
GdkPixbuf * favicon_pixbuf
 favicon default pixbuf More...
 
GdkPixbuf * win_default_icon_pixbuf
 default window icon pixbuf More...
 
GtkBuilder * warning_builder
 
char ** respaths
 resource search path vector More...
 

Function Documentation

◆ add_builtin_icon()

static nserror add_builtin_icon ( const char *  prefix,
const char *  name,
int  x,
int  y 
)
static

Definition at line 849 of file gui.c.

References NSERROR_NOMEM, NSERROR_OK, nsgdk_pixbuf_new_from_resname(), and NSLOG.

Referenced by nsgtk_add_named_icons_to_theme().

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

◆ check_dirname()

static nserror check_dirname ( const char *  path,
const char *  leaf,
char **  dirname_out 
)
static

create directory name and check it is acessible and a directory.

Definition at line 318 of file gui.c.

References netsurf_mkpath(), NSERROR_NOT_DIRECTORY, NSERROR_NOT_FOUND, NSERROR_OK, NSERROR_PERMISSION, and path().

Referenced by get_cache_home(), and get_config_home().

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

◆ create_cache_home()

static nserror create_cache_home ( char **  cache_home_out)
static

create a cache directory

Definition at line 709 of file gui.c.

References netsurf_mkdir_all(), netsurf_mkpath(), NSERROR_NOT_DIRECTORY, NSERROR_OK, and NSLOG.

Referenced by nsgtk_init().

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

◆ create_config_home()

static nserror create_config_home ( char **  config_home_out)
static

Definition at line 421 of file gui.c.

References netsurf_mkdir_all(), netsurf_mkpath(), NSERROR_NOT_DIRECTORY, NSERROR_OK, and NSLOG.

Referenced by nsgtk_init().

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

◆ get_cache_home()

static nserror get_cache_home ( char **  cache_home_out)
static

Get the path to the cache directory.

Parameters
cache_home_outPath to cache directory.
Returns
NSERROR_OK on sucess and cache_home_out updated else error code.

Definition at line 663 of file gui.c.

References check_dirname(), NSERROR_NOT_DIRECTORY, NSERROR_OK, and NSLOG.

Referenced by nsgtk_init().

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

◆ get_config_home()

static nserror get_config_home ( char **  config_home_out)
static

Get the path to the config directory.

Parameters
config_home_outPath to configuration directory.
Returns
NSERROR_OK on sucess and config_home_out updated else error code.
Todo:
the meaning of empty is never defined so I am assuming it is a zero length string but is it supposed to mean "whitespace" and if so what counts as whitespace? (are tabs etc. counted or should isspace() be used)

Definition at line 359 of file gui.c.

References check_dirname(), NSERROR_NOT_DIRECTORY, NSERROR_OK, and NSLOG.

Referenced by nsgtk_init().

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

◆ gtk_gui_gdkkey_to_nskey()

uint32_t gtk_gui_gdkkey_to_nskey ( GdkEventKey *  key)

◆ main()

int main ( int  argc,
char **  argv 
)

Main entry point from OS.

Normal entry point from OS.

Todo:
logging file descriptor update belongs in a nslog_init callback

Definition at line 1180 of file gui.c.

References filesystem_llcache_table, messages_get_errorcode(), netsurf_table::misc, netsurf_init(), netsurf_register(), NSERROR_OK, nsgtk_bitmap_table, nsgtk_clipboard_table, nsgtk_download_table, nsgtk_fetch_table, nsgtk_finalise(), nsgtk_init(), nsgtk_layout_table, nsgtk_main(), nsgtk_misc_table, nsgtk_search_table, nsgtk_search_web_table, nsgtk_setup(), nsgtk_window_table, and respaths.

Here is the call graph for this function:

◆ nsgtk_add_named_icons_to_theme()

static nserror nsgtk_add_named_icons_to_theme ( void  )
static

adds named icons into gtk theme

Definition at line 879 of file gui.c.

References add_builtin_icon(), and NSERROR_OK.

Referenced by nsgtk_setup().

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

◆ nsgtk_finalise()

static void nsgtk_finalise ( void  )
static

finalise the browser

Definition at line 1112 of file gui.c.

References gtk_fetch_filetype_fin(), hotlist_fini(), messages_get_errorcode(), netsurf_exit(), NSERROR_OK, nsgtk_config_home, nsgtk_cookies_destroy(), nsgtk_download_destroy(), nsgtk_global_history_destroy(), nsgtk_hotlist_destroy(), nsgtk_local_history_destroy(), NSLOG, nslog_finalise(), nsoption_charp, nsoption_finalise(), nsoptions, nsoptions_default, save_complete_finalise(), urldb_save(), and urldb_save_cookies().

Referenced by main().

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

◆ nsgtk_init()

static nserror nsgtk_init ( int *  pargc,
char ***  pargv,
char **  cache_home 
)
static

GTK specific initialisation.

Todo:
decide if message load faliure should be fatal

Definition at line 763 of file gui.c.

References create_cache_home(), create_config_home(), get_cache_home(), get_config_home(), messages_get_errorcode(), NSERROR_NOT_FOUND, NSERROR_OK, nsgtk_config_home, nsgtk_init_resource_path(), nsgtk_init_resources(), nsgtk_messages_init(), nsgtk_option_init(), NSLOG, nslog_init(), nslog_stream_configure(), and respaths.

Referenced by main().

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

◆ nsgtk_init_resource_path()

static char ** nsgtk_init_resource_path ( const char *  config_home)
static

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.

Definition at line 265 of file gui.c.

References filepath_free_strvec(), filepath_generate(), and filepath_path_to_strvec().

Referenced by nsgtk_init().

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

◆ nsgtk_main()

static void nsgtk_main ( void  )
static

Run the gtk event loop.

The same as the standard gtk_main loop except this ensures active FD are added to the gtk poll event set.

Definition at line 1055 of file gui.c.

References fetch_fdset(), nsgtk_complete, and schedule_run().

Referenced by main().

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

◆ nsgtk_messages_init()

static nserror nsgtk_messages_init ( char **  respaths)
static

initialise message translation

Definition at line 636 of file gui.c.

References messages_add_from_file(), messages_add_from_inline(), NSERROR_OK, nsgtk_data_from_resname(), and nsgtk_path_from_resname().

Referenced by nsgtk_init().

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

◆ nsgtk_option_init()

static nserror nsgtk_option_init ( int *  pargc,
char **  argv 
)
static

Initialise user options.

Initialise the browser configuration options. These are set by:

  • set generic defaults suitable for the gtk frontend
  • user choices loaded from Choices file
  • command line parameters

Definition at line 596 of file gui.c.

References netsurf_mkpath(), NSERROR_OK, nsgtk_config_home, nsoption_commandline(), nsoption_init(), nsoption_int, nsoption_read(), nsoption_set_int, nsoptions, nsoptions_default, and set_defaults().

Referenced by nsgtk_init().

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

◆ nsgtk_setup()

static nserror nsgtk_setup ( int  argc,
char **  argv,
char **  respath 
)
static

setup GTK specific parts of the browser.

Parameters
argcThe number of arguments on the command line
argvA string vector of command line arguments. \respath A string vector of the path elements of resources

Definition at line 910 of file gui.c.

References BITMAP_LAYOUT_ARGB8888, bitmap_set_format(), browser_get_dpi(), browser_set_dpi(), browser_window_create(), BW_CREATE_HISTORY, favicon_pixbuf, filepath_find(), filepath_sfinddef(), gtk_fetch_filetype_init(), hotlist_init(), NSERROR_OK, nsgdk_pixbuf_new_from_resname(), nsgtk_accelerator_init(), nsgtk_add_named_icons_to_theme(), nsgtk_builder_new_from_resname(), nsgtk_completion_init(), nsgtk_download_init(), nsgtk_throbber_init(), NSLOG, nsoption_charp, nsoption_int, nsurl_create(), nsurl_unref(), PATH_MAX, realpath(), respaths, save_complete_init(), search_web_init(), search_web_select_provider(), SLEN, urldb_load(), urldb_load_cookies(), warning_builder, and win_default_icon_pixbuf.

Referenced by main().

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

◆ nsgtk_warning()

nserror nsgtk_warning ( const char *  warning,
const char *  detail 
)

Warn the user of an event.

Parameters
[in]warningA warning looked up in the message translation table
[in]detailAdditional text to be displayed or NULL.
Returns
NSERROR_OK on success or error code if there was a faliure displaying the message to the user.

Definition at line 95 of file gui.c.

References messages_get(), NSERROR_OK, NSLOG, and warning_builder.

Referenced by about_open(), contents_button_clicked_cb(), customisation_toolbar_drag_drop_cb(), debugboxtree_button_clicked_cb(), debugdomtree_button_clicked_cb(), editor_init(), gui_launch_url(), gui_window_create(), guide_button_clicked_cb(), home_button_clicked_cb(), info_button_clicked_cb(), newtab_button_clicked_cb(), newwindow_button_clicked_cb(), nsgtk_completion_match_select(), nsgtk_download_dialog_show(), nsgtk_menu_developer_submenu(), nsgtk_menu_edit_submenu(), nsgtk_menu_export_submenu(), nsgtk_menu_file_submenu(), nsgtk_menu_help_submenu(), nsgtk_menu_nav_submenu(), nsgtk_menu_scaleview_submenu(), nsgtk_menu_tabs_submenu(), nsgtk_menu_toolbars_submenu(), nsgtk_menu_tools_submenu(), nsgtk_menu_view_submenu(), nsgtk_on_link_opentab_activate_menu(), nsgtk_on_link_openwin_activate_menu(), nsgtk_on_savelink_activate_menu(), openfile_button_clicked_cb(), print_button_clicked_cb(), savepage_button_clicked_cb(), tab_init(), url_entry_activate_cb(), viewsource_button_clicked_cb(), and websearch_entry_activate_cb().

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

◆ nslog_stream_configure()

static bool nslog_stream_configure ( FILE *  fptr)
static

Ensures output logging stream is correctly configured.

Definition at line 475 of file gui.c.

Referenced by nsgtk_init().

Here is the caller graph for this function:

◆ set_defaults()

static nserror set_defaults ( struct nsoption_s defaults)
static

Set option defaults for gtk frontend.

Parameters
defaultsThe option table to update.
Returns
error status.

Definition at line 490 of file gui.c.

References netsurf_mkpath(), NSERROR_BAD_PARAMETER, NSERROR_OK, nsgtk_config_home, NSLOG, nsoption_charp, nsoption_set_charp, nsoption_set_int, nsoption_setnull_charp, and settings.

Referenced by nsgtk_option_init().

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

Variable Documentation

◆ favicon_pixbuf

GdkPixbuf* favicon_pixbuf

favicon default pixbuf

Definition at line 83 of file gui.c.

Referenced by cutomize_button_clicked_cb(), gui_window_create(), gui_window_set_icon(), and nsgtk_setup().

◆ nsgtk_complete

bool nsgtk_complete = false

set when no windows remain open.

Definition at line 77 of file gui.c.

Referenced by nsgtk_main(), and scaffolding_window_destroy().

◆ nsgtk_config_home

char* nsgtk_config_home

◆ respaths

char** respaths

resource search path vector

Definition at line 91 of file gui.c.

Referenced by main(), nsgtk_init(), and nsgtk_setup().

◆ warning_builder

GtkBuilder* warning_builder

Definition at line 88 of file gui.c.

Referenced by nsgtk_setup(), and nsgtk_warning().

◆ win_default_icon_pixbuf

GdkPixbuf* win_default_icon_pixbuf

default window icon pixbuf

Definition at line 86 of file gui.c.

Referenced by nsgtk_setup().