2004-06-22 22:48:33 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2005-12-20 01:50:23 +03:00
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
2004-06-22 22:48:33 +04:00
|
|
|
*/
|
|
|
|
|
2005-12-20 00:54:51 +03:00
|
|
|
#define _GNU_SOURCE /* for strndup */
|
2005-07-16 18:35:25 +04:00
|
|
|
#include <assert.h>
|
2004-06-22 22:48:33 +04:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-12-20 00:54:51 +03:00
|
|
|
#include <curl/curl.h>
|
2004-06-22 22:48:33 +04:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "netsurf/content/content.h"
|
2005-12-20 00:54:51 +03:00
|
|
|
#include "netsurf/content/fetch.h"
|
2006-01-08 04:51:33 +03:00
|
|
|
#include "netsurf/content/url_store.h"
|
2004-08-15 23:10:08 +04:00
|
|
|
#include "netsurf/desktop/401login.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
#include "netsurf/desktop/browser.h"
|
2004-07-22 16:03:37 +04:00
|
|
|
#include "netsurf/desktop/gui.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
#include "netsurf/desktop/netsurf.h"
|
2004-10-18 02:13:35 +04:00
|
|
|
#include "netsurf/desktop/options.h"
|
2005-12-20 01:50:23 +03:00
|
|
|
#include "netsurf/gtk/gtk_gui.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
#include "netsurf/render/box.h"
|
|
|
|
#include "netsurf/render/form.h"
|
2004-10-18 02:13:35 +04:00
|
|
|
#include "netsurf/render/html.h"
|
2005-12-20 00:54:51 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
#include "netsurf/utils/messages.h"
|
2005-07-16 18:35:25 +04:00
|
|
|
#include "netsurf/utils/utf8.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
bool gui_in_multitask = false;
|
|
|
|
|
2004-10-18 02:13:35 +04:00
|
|
|
char *default_stylesheet_url;
|
|
|
|
char *adblock_stylesheet_url;
|
|
|
|
|
2005-04-17 07:30:35 +04:00
|
|
|
struct gui_window *search_current_window = 0;
|
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
|
|
|
|
void gui_init(int argc, char** argv)
|
|
|
|
{
|
2004-10-18 02:13:35 +04:00
|
|
|
char *home;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
/* All our resources are stored in ~/.netsurf/ */
|
|
|
|
home = getenv("HOME");
|
|
|
|
if (!home)
|
|
|
|
die("Couldn't find HOME");
|
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
gtk_init(&argc, &argv);
|
2004-10-18 02:13:35 +04:00
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "%s/.netsurf/Choices", home);
|
|
|
|
options_read(buf);
|
|
|
|
|
2006-01-08 04:51:33 +03:00
|
|
|
if (!option_cookie_file) {
|
2006-02-20 05:29:19 +03:00
|
|
|
snprintf(buf, sizeof buf, "%s/.netsurf/Cookies", home);
|
2006-01-08 04:51:33 +03:00
|
|
|
option_cookie_file = strdup(buf);
|
|
|
|
}
|
|
|
|
if (!option_cookie_jar) {
|
2006-02-20 05:29:19 +03:00
|
|
|
snprintf(buf, sizeof buf, "%s/.netsurf/Cookies", home);
|
2006-01-08 04:51:33 +03:00
|
|
|
option_cookie_jar = strdup(buf);
|
|
|
|
}
|
|
|
|
if (!option_cookie_file || !option_cookie_jar)
|
|
|
|
die("Failed initialising cookie options");
|
|
|
|
|
2004-10-18 02:13:35 +04:00
|
|
|
snprintf(buf, sizeof buf, "%s/.netsurf/messages", home);
|
|
|
|
messages_load(buf);
|
|
|
|
|
|
|
|
/* set up stylesheet urls */
|
2006-02-23 20:27:30 +03:00
|
|
|
snprintf(buf, sizeof buf, "file://%s/.netsurf/Default.css", home);
|
2004-10-18 02:13:35 +04:00
|
|
|
default_stylesheet_url = strdup(buf);
|
2006-02-23 20:27:30 +03:00
|
|
|
snprintf(buf, sizeof buf, "file://%s/.netsurf/AdBlock.css", home);
|
2004-10-18 02:13:35 +04:00
|
|
|
adblock_stylesheet_url = strdup(buf);
|
2006-01-08 04:51:33 +03:00
|
|
|
if (!default_stylesheet_url || !adblock_stylesheet_url)
|
|
|
|
die("Failed duplicating stylesheet strings");
|
2004-06-22 22:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-27 09:21:00 +04:00
|
|
|
void gui_init2(int argc, char** argv)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
2006-03-19 19:03:02 +03:00
|
|
|
const char *addr = "http://netsurf.sourceforge.net/";
|
|
|
|
if (argc > 1) addr = argv[1];
|
|
|
|
browser_window_create(addr, 0, 0);
|
2004-07-29 03:14:04 +04:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
|
2004-07-29 03:14:04 +04:00
|
|
|
void gui_poll(bool active)
|
|
|
|
{
|
2005-12-20 00:54:51 +03:00
|
|
|
CURLMcode code;
|
|
|
|
fd_set read_fd_set, write_fd_set, exc_fd_set;
|
|
|
|
int max_fd;
|
|
|
|
GPollFD *fd_list[1000];
|
|
|
|
unsigned int fd_count = 0;
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
fetch_poll();
|
|
|
|
FD_ZERO(&read_fd_set);
|
|
|
|
FD_ZERO(&write_fd_set);
|
|
|
|
FD_ZERO(&exc_fd_set);
|
|
|
|
code = curl_multi_fdset(fetch_curl_multi,
|
|
|
|
&read_fd_set,
|
|
|
|
&write_fd_set,
|
|
|
|
&exc_fd_set,
|
|
|
|
&max_fd);
|
|
|
|
assert(code == CURLM_OK);
|
|
|
|
for (int i = 0; i <= max_fd; i++) {
|
|
|
|
if (FD_ISSET(i, &read_fd_set)) {
|
|
|
|
GPollFD *fd = malloc(sizeof *fd);
|
|
|
|
fd->fd = i;
|
|
|
|
fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
|
|
|
|
g_main_context_add_poll(0, fd, 0);
|
|
|
|
fd_list[fd_count++] = fd;
|
|
|
|
}
|
|
|
|
if (FD_ISSET(i, &write_fd_set)) {
|
|
|
|
GPollFD *fd = malloc(sizeof *fd);
|
|
|
|
fd->fd = i;
|
|
|
|
fd->events = G_IO_OUT | G_IO_ERR;
|
|
|
|
g_main_context_add_poll(0, fd, 0);
|
|
|
|
fd_list[fd_count++] = fd;
|
|
|
|
}
|
|
|
|
if (FD_ISSET(i, &exc_fd_set)) {
|
|
|
|
GPollFD *fd = malloc(sizeof *fd);
|
|
|
|
fd->fd = i;
|
|
|
|
fd->events = G_IO_ERR;
|
|
|
|
g_main_context_add_poll(0, fd, 0);
|
|
|
|
fd_list[fd_count++] = fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_main_iteration_do(true);
|
|
|
|
for (unsigned int i = 0; i != fd_count; i++) {
|
|
|
|
g_main_context_remove_poll(0, fd_list[i]);
|
|
|
|
free(fd_list[i]);
|
|
|
|
}
|
2004-06-22 22:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gui_multitask(void)
|
|
|
|
{
|
|
|
|
gui_in_multitask = true;
|
|
|
|
while (gtk_events_pending())
|
2004-10-18 01:51:06 +04:00
|
|
|
gtk_main_iteration();
|
2004-06-22 22:48:33 +04:00
|
|
|
gui_in_multitask = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gui_quit(void)
|
|
|
|
{
|
2004-10-18 02:13:35 +04:00
|
|
|
free(default_stylesheet_url);
|
|
|
|
free(adblock_stylesheet_url);
|
2004-06-22 22:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
struct gui_download_window *gui_download_window_create(const char *url,
|
|
|
|
const char *mime_type, struct fetch *fetch,
|
|
|
|
unsigned int total_size)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void gui_download_window_data(struct gui_download_window *dw, const char *data,
|
|
|
|
unsigned int size)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void gui_download_window_error(struct gui_download_window *dw,
|
|
|
|
const char *error_msg)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void gui_download_window_done(struct gui_download_window *dw)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void gui_create_form_select_menu(struct browser_window *bw,
|
|
|
|
struct form_control *control)
|
2004-06-22 22:48:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gui_launch_url(const char *url)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-20 05:29:19 +03:00
|
|
|
bool gui_search_term_highlighted(struct gui_window *g,
|
|
|
|
unsigned start_offset, unsigned end_offset,
|
2005-04-17 07:30:35 +04:00
|
|
|
unsigned *start_idx, unsigned *end_idx)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
void warn_user(const char *warning, const char *detail)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void die(const char * const error)
|
|
|
|
{
|
|
|
|
fprintf(stderr, error);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void hotlist_visited(struct content *content)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
void gui_401login_open(struct browser_window *bw, struct content *c,
|
2006-02-23 20:27:30 +03:00
|
|
|
const char *realm) {}
|
|
|
|
void gui_cert_verify(struct browser_window *bw, struct content *c,
|
|
|
|
const struct ssl_cert_info *certs, unsigned long num) {}
|
2004-09-04 02:44:48 +04:00
|
|
|
|
2006-01-08 04:51:33 +03:00
|
|
|
void global_history_add(struct url_content *data) {}
|
2005-04-17 07:30:35 +04:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len,
|
|
|
|
char **result)
|
|
|
|
{
|
|
|
|
assert(string && result);
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
len = strlen(string);
|
|
|
|
|
|
|
|
*result = strndup(string, len);
|
|
|
|
if (!(*result))
|
|
|
|
return UTF8_CONVERT_NOMEM;
|
|
|
|
|
|
|
|
return UTF8_CONVERT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len,
|
|
|
|
char **result)
|
|
|
|
{
|
|
|
|
assert(string && result);
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
len = strlen(string);
|
|
|
|
|
|
|
|
*result = strndup(string, len);
|
|
|
|
if (!(*result))
|
|
|
|
return UTF8_CONVERT_NOMEM;
|
|
|
|
|
|
|
|
return UTF8_CONVERT_OK;
|
|
|
|
}
|