98 static GtkWindow *nsgtk_warning_window;
99 GtkLabel *WarningLabel;
101 NSLOG(netsurf, INFO,
"%s %s", warning, detail ? detail :
"");
104 nsgtk_warning_window = GTK_WINDOW(gtk_builder_get_object(
warning_builder,
"wndWarning"));
108 snprintf(buf,
sizeof(buf),
"%s %s",
messages_get(warning),
109 detail ? detail :
"");
110 buf[
sizeof(buf) - 1] = 0;
112 gtk_label_set_text(WarningLabel, buf);
114 gtk_widget_show_all(GTK_WIDGET(nsgtk_warning_window));
127 switch (key->keyval) {
133 if (key->state & GDK_SHIFT_MASK)
135 else if (key->state & GDK_CONTROL_MASK)
141 if (key->state & GDK_SHIFT_MASK)
143 else if (key->state & GDK_CONTROL_MASK)
156 if (key->state & GDK_CONTROL_MASK)
162 if (key->state & GDK_CONTROL_MASK)
176 if (key->state & GDK_CONTROL_MASK)
183 if (key->state & GDK_CONTROL_MASK)
197 if (key->state & GDK_CONTROL_MASK)
199 return gdk_keyval_to_unicode(key->keyval);
202 if (key->state & GDK_CONTROL_MASK)
204 return gdk_keyval_to_unicode(key->keyval);
207 if (key->state & GDK_CONTROL_MASK)
209 return gdk_keyval_to_unicode(key->keyval);
212 if (key->state & GDK_CONTROL_MASK)
214 return gdk_keyval_to_unicode(key->keyval);
217 if (key->state & GDK_CONTROL_MASK)
219 return gdk_keyval_to_unicode(key->keyval);
223 if (key->state & GDK_CONTROL_MASK)
225 return gdk_keyval_to_unicode(key->keyval);
228 if (key->state & GDK_CONTROL_MASK)
230 return gdk_keyval_to_unicode(key->keyval);
253 return gdk_keyval_to_unicode(key->keyval);
268 int resource_path_len;
269 const gchar *
const *langv;
273 if (config_home != NULL) {
274 resource_path_len = snprintf(NULL, 0,
275 "%s:${NETSURFRES}:%s",
278 resource_path = malloc(resource_path_len + 1);
279 if (resource_path == NULL) {
282 snprintf(resource_path, resource_path_len + 1,
283 "%s:${NETSURFRES}:%s",
287 resource_path_len = snprintf(NULL, 0,
290 resource_path = malloc(resource_path_len + 1);
291 if (resource_path == NULL) {
294 snprintf(resource_path,
295 resource_path_len + 1,
302 langv = g_get_language_names();
321 char *dirname = NULL;
322 struct stat dirname_stat;
332 if (stat(dirname, &dirname_stat) == 0) {
333 if (S_ISDIR(dirname_stat.st_mode)) {
334 if (access(dirname, R_OK | W_OK) == 0) {
335 *dirname_out = dirname;
363 char *xdg_config_dir;
366 home_dir = getenv(
"HOME");
371 if (home_dir != NULL) {
374 NSLOG(netsurf, INFO,
"\"%s\"", config_home);
375 *config_home_out = config_home;
384 xdg_config_dir = getenv(
"XDG_CONFIG_HOME");
386 if ((xdg_config_dir == NULL) || (*xdg_config_dir == 0)) {
399 if (home_dir == NULL) {
403 ret =
check_dirname(home_dir,
".config/netsurf", &config_home);
408 ret =
check_dirname(xdg_config_dir,
"netsurf", &config_home);
414 NSLOG(netsurf, INFO,
"\"%s\"", config_home);
416 *config_home_out = config_home;
423 char *config_home = NULL;
425 char *xdg_config_dir;
428 NSLOG(netsurf, INFO,
"Attempting to create configuration directory");
434 xdg_config_dir = getenv(
"XDG_CONFIG_HOME");
436 if ((xdg_config_dir == NULL) || (*xdg_config_dir == 0)) {
437 home_dir = getenv(
"HOME");
439 if ((home_dir == NULL) || (*home_dir == 0)) {
443 ret =
netsurf_mkpath(&config_home, NULL, 4, home_dir,
".config",
"netsurf",
"/");
448 ret =
netsurf_mkpath(&config_home, NULL, 3, xdg_config_dir,
"netsurf",
"/");
462 config_home[strlen(config_home) - 1] = 0;
464 NSLOG(netsurf, INFO,
"\"%s\"", config_home);
466 *config_home_out = config_home;
494 GtkIconSize tooliconsize;
495 GtkToolbarStyle toolbarstyle;
526 fname = getenv(
"HOME");
537 "Failed initialising default resource paths");
550 settings = gtk_settings_get_default();
552 "gtk-toolbar-icon-size", &tooliconsize,
553 "gtk-toolbar-style", &toolbarstyle, NULL);
555 switch (toolbarstyle) {
556 case GTK_TOOLBAR_ICONS:
557 if (tooliconsize == GTK_ICON_SIZE_SMALL_TOOLBAR) {
564 case GTK_TOOLBAR_TEXT:
568 case GTK_TOOLBAR_BOTH:
569 case GTK_TOOLBAR_BOTH_HORIZ:
579 strdup(
"back/history/forward/reloadstop/url_bar/websearch/openmenu"));
599 char *choices = NULL;
638 const char *messages;
674 xdg_cache_dir = getenv(
"XDG_CACHE_HOME");
676 if ((xdg_cache_dir == NULL) || (*xdg_cache_dir == 0)) {
681 home_dir = getenv(
"HOME");
684 if (home_dir == NULL) {
688 ret =
check_dirname(home_dir,
".cache/netsurf", &cache_home);
699 NSLOG(netsurf, INFO,
"\"%s\"", cache_home);
701 *cache_home_out = cache_home;
711 char *cache_home = NULL;
716 NSLOG(netsurf, INFO,
"Attempting to create cache directory");
722 xdg_cache_dir = getenv(
"XDG_CACHE_HOME");
724 if ((xdg_cache_dir == NULL) || (*xdg_cache_dir == 0)) {
725 home_dir = getenv(
"HOME");
727 if ((home_dir == NULL) || (*home_dir == 0)) {
731 ret =
netsurf_mkpath(&cache_home, NULL, 4, home_dir,
".cache",
"netsurf",
"/");
736 ret =
netsurf_mkpath(&cache_home, NULL, 3, xdg_cache_dir,
"netsurf",
"/");
750 cache_home[strlen(cache_home) - 1] = 0;
752 NSLOG(netsurf, INFO,
"\"%s\"", cache_home);
754 *cache_home_out = cache_home;
775 "Unable to locate a configuration directory.");
780 gtk_init(pargc, pargv);
790 fprintf(stderr,
"Unable to locate resources\n");
797 fprintf(stderr,
"GTK resources failed to initialise (%s)\n",
805 fprintf(stderr,
"Options failed to initialise (%s)\n",
813 fprintf(stderr,
"Unable to load translated messages (%s)\n",
815 NSLOG(netsurf, INFO,
"Unable to load translated messages");
826 NSLOG(netsurf, INFO,
"Unable to locate a cache directory.");
834#if GTK_CHECK_VERSION(3,14,0)
841 gtk_icon_theme_add_resource_path(gtk_icon_theme_get_default(),
842 "/org/netsurf/icons");
857 resnamelen = strlen(prefix) + strlen(name) + 5 + 1 + 4 + 1;
858 resname = malloc(resnamelen);
859 if (resname == NULL) {
862 snprintf(resname, resnamelen,
"icons%s/%s.png", prefix, name);
865 NSLOG(netsurf, DEEPDEBUG,
"%d %s", res, resname);
868 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
false, 8, x, y);
870 gtk_icon_theme_add_builtin_icon(name, y, pixbuf);
913 char *resource_filename;
922 "Unable to load gtk accelerator configuration");
929 NSLOG(netsurf, INFO,
"Unable to initialise warning dialog");
939 NSLOG(netsurf, INFO,
"Seting default window icon");
946 if (resource_filename != NULL) {
947 NSLOG(netsurf, INFO,
"Using '%s' as Search Engines file",
949 free(resource_filename);
963 NSLOG(netsurf, INFO,
"Unable to add named icons to GTK theme.");
970 NSLOG(netsurf, INFO,
"Unable to initialise throbber.");
1002 NSLOG(netsurf, INFO,
"Unable to initialise download window.");
1009 if (stat(argv[1], &fs) == 0) {
1011 char *rp =
realpath(argv[1], NULL);
1015 addrlen =
SLEN(
"file://") + strlen(rp) + 1;
1016 addr = malloc(addrlen);
1017 assert(addr != NULL);
1018 snprintf(addr, addrlen,
"file://%s", rp);
1021 addr = strdup(argv[1]);
1029 addr = strdup(NETSURF_HOMEPAGE);
1057 fd_set read_fd_set, write_fd_set, exc_fd_set;
1059 GPollFD *fd_list[1000];
1060 unsigned int fd_count;
1065 FD_ZERO(&read_fd_set);
1066 FD_ZERO(&write_fd_set);
1067 FD_ZERO(&exc_fd_set);
1069 while (gtk_events_pending())
1070 gtk_main_iteration_do(TRUE);
1074 fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
1075 for (
int i = 0; i <= max_fd; i++) {
1076 if (FD_ISSET(i, &read_fd_set)) {
1077 GPollFD *fd = malloc(
sizeof *fd);
1079 fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
1080 g_main_context_add_poll(0, fd, 0);
1081 fd_list[fd_count++] = fd;
1083 if (FD_ISSET(i, &write_fd_set)) {
1084 GPollFD *fd = malloc(
sizeof *fd);
1086 fd->events = G_IO_OUT | G_IO_ERR;
1087 g_main_context_add_poll(0, fd, 0);
1088 fd_list[fd_count++] = fd;
1090 if (FD_ISSET(i, &exc_fd_set)) {
1091 GPollFD *fd = malloc(
sizeof *fd);
1093 fd->events = G_IO_ERR;
1094 g_main_context_add_poll(0, fd, 0);
1095 fd_list[fd_count++] = fd;
1099 gtk_main_iteration();
1101 for (
unsigned int i = 0; i != fd_count; i++) {
1102 g_main_context_remove_poll(0, fd_list[i]);
1116 NSLOG(netsurf, INFO,
"Quitting GUI");
1125 NSLOG(netsurf, INFO,
"Error finalising cookie viewer: %s",
1131 NSLOG(netsurf, INFO,
1132 "Error finalising local history viewer: %s",
1138 NSLOG(netsurf, INFO,
1139 "Error finalising global history viewer: %s",
1145 NSLOG(netsurf, INFO,
"Error finalising hotlist viewer: %s",
1151 NSLOG(netsurf, INFO,
"Error finalising hotlist: %s",
1157 NSLOG(netsurf, INFO,
"Error finalising save complete: %s",
1183 char *cache_home = NULL;
1200 "NetSurf operation table failed registration (%s)\n",
1208 fprintf(stderr,
"NetSurf gtk failed to initialise (%s)\n",
1217 fprintf(stderr,
"NetSurf core failed to initialise (%s)\n",
1226 fprintf(stderr,
"NetSurf gtk setup failed (%s)\n",
nserror nsgtk_accelerator_init(char **respaths)
int main(int argc, char **argv)
Normal entry point from OS.
int schedule_run(void)
Process events up to current time.
Low-level source data cache backing store interface.
struct gui_llcache_table * filesystem_llcache_table
Browser window creation and manipulation interface.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
Compatibility functions for older GTK versions (interface)
void nsgtk_completion_init(void)
initialise completion list store
Interface to url entry completion.
nserror fetch_fdset(fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *maxfd_out)
Get the set of file descriptors the fetchers are currently using.
Fetching of data from a URL (interface).
Unified cookie database public interface.
void urldb_save_cookies(const char *filename)
Save persistent cookies to file.
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
nserror hotlist_fini(void)
Finalise the hotlist.
nserror hotlist_init(const char *load_path, const char *save_path)
Initialise the hotlist.
nserror search_web_init(const char *provider_fname)
Initialise the web search operations.
nserror search_web_select_provider(int selection)
Change the currently selected web search provider.
nserror
Enumeration of error codes.
@ NSERROR_PERMISSION
Permission error.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NOT_DIRECTORY
Missing directory.
@ NSERROR_NOMEM
Memory exhaustion.
char ** filepath_path_to_strvec(const char *path)
Convert a colon separated list of path elements into a string vector.
char * filepath_find(char **respathv, const char *filename)
Searches an array of resource paths for a file.
char * filepath_sfinddef(char **respathv, char *filepath, const char *filename, const char *def)
Searches an array of resource paths for a file optionally forcing a default.
void filepath_free_strvec(char **pathv)
Free a string vector.
char ** filepath_generate(char *const *pathv, const char *const *langv)
Merge two string vectors into a resource search path vector.
Utility routines to obtain paths to file resources.
struct gui_bitmap_table * nsgtk_bitmap_table
void nsgtk_download_destroy(void)
Destroy download window.
nserror nsgtk_download_init(void)
Initialise download window ready for use.
struct gui_download_table * nsgtk_download_table
download operation table for gtk
void gtk_fetch_filetype_fin(void)
void gtk_fetch_filetype_init(const char *mimefile)
struct gui_fetch_table * nsgtk_fetch_table
nserror nsgtk_global_history_destroy(void)
Destroys the global history window and performs any other necessary cleanup actions.
Interface to GTK global history manager.
nserror nsgtk_hotlist_destroy(void)
Free any resources allocated for the hotlist window.
Interface to GTK bookmarks (hotlist).
nserror nsgtk_local_history_destroy(void)
Destroys the local history window and performs any other necessary cleanup actions.
Interface to GTK local history manager.
static struct print_settings * settings
struct gui_search_table * nsgtk_search_table
free text page search for gtk interface
struct gui_clipboard_table * nsgtk_clipboard_table
nserror nsgtk_cookies_destroy(void)
Free any resources allocated for the cookie window.
static void nsgtk_main(void)
Run the gtk event loop.
char ** respaths
resource search path vector
static nserror create_config_home(char **config_home_out)
GdkPixbuf * win_default_icon_pixbuf
default window icon pixbuf
GtkBuilder * warning_builder
bool nsgtk_complete
set when no windows remain open.
static nserror nsgtk_init(int *pargc, char ***pargv, char **cache_home)
GTK specific initialisation.
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for gtk frontend.
nserror nsgtk_warning(const char *warning, const char *detail)
Warn the user of an event.
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
static nserror nsgtk_messages_init(char **respaths)
initialise message translation
static nserror nsgtk_add_named_icons_to_theme(void)
adds named icons into gtk theme
static nserror check_dirname(const char *path, const char *leaf, char **dirname_out)
create directory name and check it is acessible and a directory.
static nserror get_cache_home(char **cache_home_out)
Get the path to the cache directory.
GdkPixbuf * favicon_pixbuf
favicon default pixbuf
char * nsgtk_config_home
Directory where all configuration files are held.
static nserror add_builtin_icon(const char *prefix, const char *name, int x, int y)
static void nsgtk_finalise(void)
finalise the browser
static nserror create_cache_home(char **cache_home_out)
create a cache directory
static nserror nsgtk_setup(int argc, char **argv, char **respath)
setup GTK specific parts of the browser.
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
input conversion.
static char ** nsgtk_init_resource_path(const char *config_home)
Create an array of valid paths to search for resources.
static nserror nsgtk_option_init(int *pargc, char **argv)
Initialise user options.
static nserror get_config_home(char **config_home_out)
Get the path to the config directory.
struct gui_misc_table * nsgtk_misc_table
nserror nsgtk_throbber_init(void)
Initialise global throbber context.
struct gui_window_table * nsgtk_window_table
struct gui_search_web_table * nsgtk_search_web_table
char * realpath(const char *f, char *buf)
Generic bitmap handling interface.
void bitmap_set_format(const bitmap_fmt_t *bitmap_format)
Set client bitmap format.
@ BITMAP_LAYOUT_ARGB8888
32-bit ARGB (0xAARRGGBB).
int browser_get_dpi(void)
Get the browser DPI.
nserror browser_set_dpi(int dpi)
Set the DPI of the browser.
Interface to key press operations.
@ NS_KEY_DELETE_WORD_RIGHT
@ NS_KEY_DELETE_LINE_START
@ NS_KEY_DELETE_WORD_LEFT
struct gui_layout_table * nsgtk_layout_table
Interface to GTK layout handling using pango.
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
void nslog_finalise(void)
Shut down the logging system.
#define NSLOG(catname, level, logmsg, args...)
nserror messages_add_from_inline(const uint8_t *data, size_t size)
Read keys and values from inline message data into the standard Messages hash.
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
NetSurf core interface registration, construction and destruction.
void netsurf_exit(void)
Finalise NetSurf core.
nserror netsurf_init(const char *store_path)
Initialise netsurf core.
nserror netsurf_register(struct netsurf_table *table)
Register operation table.
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out)
Get direct pointer to resource data.
nserror nsgtk_init_resources(char **respath)
Initialise UI resource table.
nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
Create gtk builder object for the named ui resource.
nserror nsgdk_pixbuf_new_from_resname(const char *resname, GdkPixbuf **pixbuf_out)
Create gdk pixbuf for the named ui resource.
nserror nsgtk_path_from_resname(const char *resname, const char **path_out)
Get path to resource data.
Interface to gtk builtin resource handling.
void save_complete_init(void)
Initialise save complete module.
nserror save_complete_finalise(void)
Finalise save complete module.
Save HTML document with dependencies (interface).
core web search facilities interface.
Interface to utility string handling.
NetSurf operation function table.
struct gui_misc_table * misc
Browser table.
Unified URL information database public interface.
nserror urldb_save(const char *filename)
Export the current database to file.
nserror urldb_load(const char *filename)
Import an URL database from file, replacing any existing database.
nserror netsurf_mkdir_all(const char *fname)
Ensure that all directory elements needed to store a filename exist.
nserror netsurf_mkpath(char **str, size_t *size, size_t nelm,...)
Generate a path from one or more component elemnts.
Default operations table for files.
struct nsoption_s * nsoptions_default
global default option table.
static struct nsoption_s defaults[]
The table of compiled in default options.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
struct nsoption_s * nsoptions
global active option table.
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset
#define nsoption_int(OPTION)
Get the value of an integer option.
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Interface to a number of general purpose functionality.
#define SLEN(x)
Calculate length of constant C string.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.