2011-03-12 18:08:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "monkey/filetype.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2011-03-12 20:27:18 +03:00
|
|
|
#include "monkey/poll.h"
|
|
|
|
#include "monkey/dispatch.h"
|
|
|
|
#include "monkey/browser.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "content/fetchers/resource.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/netsurf.h"
|
2013-05-23 15:13:53 +04:00
|
|
|
#include "utils/log.h"
|
2011-03-17 14:26:30 +03:00
|
|
|
#include "utils/filepath.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
#include "utils/url.h"
|
|
|
|
|
|
|
|
static char **respaths; /** resource search path vector */
|
|
|
|
|
|
|
|
/* Stolen from gtk/gui.c */
|
|
|
|
static char **
|
|
|
|
nsmonkey_init_resource(const char *resource_path)
|
|
|
|
{
|
|
|
|
const gchar * const *langv;
|
|
|
|
char **pathv; /* resource path string vector */
|
|
|
|
char **respath; /* resource paths vector */
|
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
pathv = filepath_path_to_strvec(resource_path);
|
2011-03-12 18:08:07 +03:00
|
|
|
|
|
|
|
langv = g_get_language_names();
|
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
respath = filepath_generate(pathv, langv);
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
filepath_free_strvec(pathv);
|
2011-03-12 18:08:07 +03:00
|
|
|
|
|
|
|
return respath;
|
|
|
|
}
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
static void gui_quit(void)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
urldb_save_cookies(nsoption_charp(cookie_jar));
|
|
|
|
urldb_save(nsoption_charp(url_file));
|
2013-08-12 14:27:12 +04:00
|
|
|
free(nsoption_charp(cookie_file));
|
|
|
|
free(nsoption_charp(cookie_jar));
|
|
|
|
gtk_fetch_filetype_fin();
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2011-10-05 12:32:52 +04:00
|
|
|
nsurl *gui_get_resource_url(const char *path)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2011-10-05 12:32:52 +04:00
|
|
|
char *raw;
|
|
|
|
nsurl *url = NULL;
|
|
|
|
|
|
|
|
raw = path_to_url(filepath_sfind(respaths, buf, path));
|
|
|
|
if (raw != NULL) {
|
|
|
|
nsurl_create(raw, &url);
|
|
|
|
free(raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
void
|
|
|
|
gui_launch_url(const char *url)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "GENERIC LAUNCH URL %s\n", url);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void quit_handler(int argc, char **argv)
|
|
|
|
{
|
|
|
|
netsurf_quit = true;
|
|
|
|
}
|
|
|
|
|
2013-05-27 20:27:56 +04:00
|
|
|
/**
|
|
|
|
* Set option defaults for monkey frontend
|
|
|
|
*
|
|
|
|
* @param defaults The option table to update.
|
|
|
|
* @return error status.
|
|
|
|
*/
|
|
|
|
static nserror set_defaults(struct nsoption_s *defaults)
|
2012-10-17 17:20:18 +04:00
|
|
|
{
|
2013-05-27 20:27:56 +04:00
|
|
|
/* currently no default overrides */
|
|
|
|
return NSERROR_OK;
|
2012-10-17 17:20:18 +04:00
|
|
|
}
|
|
|
|
|
2013-05-23 14:50:57 +04:00
|
|
|
/**
|
|
|
|
* Ensures output logging stream is correctly configured
|
|
|
|
*/
|
|
|
|
static bool nslog_stream_configure(FILE *fptr)
|
|
|
|
{
|
|
|
|
/* set log stream to be non-buffering */
|
|
|
|
setbuf(fptr, NULL);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
static struct gui_table monkey_gui_table = {
|
|
|
|
.poll = &monkey_poll,
|
|
|
|
.quit = &gui_quit,
|
|
|
|
};
|
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *messages;
|
|
|
|
char *options;
|
|
|
|
char buf[PATH_MAX];
|
2013-05-27 20:27:56 +04:00
|
|
|
nserror ret;
|
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
/* Unbuffer stdin/out/err */
|
|
|
|
setbuf(stdin, NULL);
|
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
|
|
|
|
|
|
|
/* Prep the search paths */
|
|
|
|
respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res");
|
|
|
|
|
2013-05-23 14:50:57 +04:00
|
|
|
/* initialise logging. Not fatal if it fails but not much we can do
|
|
|
|
* about it either.
|
|
|
|
*/
|
|
|
|
nslog_init(nslog_stream_configure, &argc, argv);
|
|
|
|
|
2013-05-27 20:27:56 +04:00
|
|
|
/* user options setup */
|
|
|
|
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
die("Options failed to initialise");
|
|
|
|
}
|
|
|
|
options = filepath_find(respaths, "Choices");
|
2013-06-01 18:49:17 +04:00
|
|
|
nsoption_read(options, nsoptions);
|
2011-03-12 18:08:07 +03:00
|
|
|
free(options);
|
2013-06-01 18:49:17 +04:00
|
|
|
nsoption_commandline(&argc, argv, nsoptions);
|
2013-05-27 20:27:56 +04:00
|
|
|
|
|
|
|
/* common initialisation */
|
|
|
|
messages = filepath_find(respaths, "Messages");
|
2014-01-11 18:20:30 +04:00
|
|
|
ret = netsurf_init(messages, &monkey_gui_table);
|
2013-05-27 20:27:56 +04:00
|
|
|
free(messages);
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
die("NetSurf failed to initialise");
|
|
|
|
}
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
|
2011-03-12 18:08:07 +03:00
|
|
|
gtk_fetch_filetype_init(buf);
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
urldb_load(nsoption_charp(url_file));
|
|
|
|
urldb_load_cookies(nsoption_charp(cookie_file));
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
monkey_prepare_input();
|
|
|
|
monkey_register_handler("QUIT", quit_handler);
|
|
|
|
monkey_register_handler("WINDOW", monkey_window_handle_command);
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
fprintf(stdout, "GENERIC STARTED\n");
|
2011-03-12 18:08:07 +03:00
|
|
|
netsurf_main_loop();
|
2011-03-12 20:27:18 +03:00
|
|
|
fprintf(stdout, "GENERIC CLOSING_DOWN\n");
|
2011-03-12 20:54:02 +03:00
|
|
|
monkey_kill_browser_windows();
|
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
netsurf_exit();
|
2011-03-12 20:27:18 +03:00
|
|
|
fprintf(stdout, "GENERIC FINISHED\n");
|
2013-06-01 18:49:17 +04:00
|
|
|
|
|
|
|
/* finalise options */
|
|
|
|
nsoption_finalise(nsoptions, nsoptions_default);
|
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|