2004-06-22 22:48:33 +04:00
|
|
|
/*
|
2005-12-20 01:50:23 +03:00
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
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>
|
2006-03-27 17:19:08 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
2007-01-30 01:27:15 +03:00
|
|
|
#include <sys/select.h>
|
2006-08-24 21:24:36 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.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>
|
2006-07-19 17:41:57 +04:00
|
|
|
#include <glade/glade.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetch.h"
|
2007-06-10 21:46:44 +04:00
|
|
|
#include "content/fetchers/fetch_curl.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/401login.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/cookies.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/netsurf.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "gtk/gtk_gui.h"
|
|
|
|
#include "gtk/gtk_options.h"
|
|
|
|
#include "gtk/gtk_completion.h"
|
2007-08-12 01:41:34 +04:00
|
|
|
#include "gtk/gtk_window.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "gtk/options.h"
|
|
|
|
#include "gtk/gtk_throbber.h"
|
|
|
|
#include "gtk/gtk_history.h"
|
|
|
|
#include "gtk/gtk_filetype.h"
|
2007-10-03 02:22:17 +04:00
|
|
|
#include "gtk/gtk_download.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
2004-06-22 22:48:33 +04:00
|
|
|
|
2006-03-27 17:19:08 +04:00
|
|
|
/* Where to search for shared resources. Must have trailing / */
|
|
|
|
#define RESPATH "/usr/share/netsurf/"
|
2004-06-22 22:48:33 +04:00
|
|
|
|
|
|
|
bool gui_in_multitask = false;
|
|
|
|
|
2004-10-18 02:13:35 +04:00
|
|
|
char *default_stylesheet_url;
|
|
|
|
char *adblock_stylesheet_url;
|
2006-07-23 22:26:11 +04:00
|
|
|
char *options_file_location;
|
|
|
|
char *glade_file_location;
|
2004-10-18 02:13:35 +04:00
|
|
|
|
2005-04-17 07:30:35 +04:00
|
|
|
struct gui_window *search_current_window = 0;
|
|
|
|
|
2006-11-05 02:38:18 +03:00
|
|
|
GtkWindow *wndAbout;
|
2007-05-06 20:39:34 +04:00
|
|
|
GtkWindow *wndWarning;
|
2006-07-19 17:41:57 +04:00
|
|
|
GladeXML *gladeWindows;
|
2006-11-05 02:38:18 +03:00
|
|
|
GtkWindow *wndTooltip;
|
|
|
|
GtkLabel *labelTooltip;
|
2007-06-22 19:16:48 +04:00
|
|
|
GtkDialog *wndOpenFile;
|
2006-07-19 17:41:57 +04:00
|
|
|
|
2007-09-26 22:07:32 +04:00
|
|
|
static GtkWidget *select_menu;
|
|
|
|
static struct browser_window *select_menu_bw;
|
|
|
|
static struct form_control *select_menu_control;
|
|
|
|
|
2007-08-12 03:14:33 +04:00
|
|
|
static void nsgtk_create_ssl_verify_window(struct browser_window *bw,
|
|
|
|
struct content *c, const struct ssl_cert_info *certs,
|
|
|
|
unsigned long num);
|
|
|
|
static void nsgtk_ssl_accept(GtkButton *w, gpointer data);
|
|
|
|
static void nsgtk_ssl_reject(GtkButton *w, gpointer data);
|
2007-09-26 22:07:32 +04:00
|
|
|
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
|
|
|
|
gpointer user_data);
|
2007-08-12 03:14:33 +04:00
|
|
|
|
2006-03-27 17:19:08 +04:00
|
|
|
/**
|
|
|
|
* Locate a shared resource file by searching known places in order.
|
|
|
|
*
|
|
|
|
* \param buf buffer to write to. must be at least PATH_MAX chars
|
|
|
|
* \param filename file to look for
|
|
|
|
* \param def default to return if file not found
|
|
|
|
* \return buf
|
|
|
|
*
|
|
|
|
* Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an
|
|
|
|
* environment variable), and finally the path specified by the #define
|
|
|
|
* at the top of this file.
|
|
|
|
*/
|
2004-06-22 22:48:33 +04:00
|
|
|
|
2006-03-27 17:19:08 +04:00
|
|
|
static char *find_resource(char *buf, const char *filename, const char *def)
|
|
|
|
{
|
|
|
|
char *cdir = getenv("HOME");
|
2006-08-24 21:24:36 +04:00
|
|
|
char t[PATH_MAX];
|
2006-03-27 17:19:08 +04:00
|
|
|
|
|
|
|
if (cdir != NULL) {
|
2006-08-24 21:24:36 +04:00
|
|
|
strcpy(t, cdir);
|
|
|
|
strcat(t, "/.netsurf/");
|
|
|
|
strcat(t, filename);
|
|
|
|
realpath(t, buf);
|
2006-03-27 17:19:08 +04:00
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdir = getenv("NETSURFRES");
|
|
|
|
|
|
|
|
if (cdir != NULL) {
|
2006-08-24 21:24:36 +04:00
|
|
|
realpath(cdir, buf);
|
2006-03-27 17:19:08 +04:00
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, filename);
|
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
strcpy(t, RESPATH);
|
|
|
|
strcat(t, filename);
|
|
|
|
realpath(t, buf);
|
2006-03-27 17:19:08 +04:00
|
|
|
if (access(buf, R_OK) == 0)
|
|
|
|
return buf;
|
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
if (def[0] == '~') {
|
|
|
|
snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
|
|
|
|
realpath(t, buf);
|
|
|
|
} else {
|
|
|
|
realpath(def, buf);
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-03-27 17:19:08 +04:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
/**
|
|
|
|
* Check that ~/.netsurf/ exists, and if it doesn't, create it.
|
|
|
|
*/
|
|
|
|
static void check_homedir(void)
|
|
|
|
{
|
|
|
|
char *hdir = getenv("HOME");
|
|
|
|
char buf[BUFSIZ];
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
if (hdir == NULL) {
|
|
|
|
/* we really can't continue without a home directory. */
|
|
|
|
LOG(("HOME is not set - nowhere to store state!"));
|
|
|
|
die("NetSurf requires HOME to be set in order to run.\n");
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
snprintf(buf, BUFSIZ, "%s/.netsurf", hdir);
|
|
|
|
if (access(buf, F_OK) != 0) {
|
|
|
|
LOG(("You don't have a ~/.netsurf - creating one for you."));
|
|
|
|
if (mkdir(buf, 0777) == -1) {
|
2006-08-24 22:34:08 +04:00
|
|
|
LOG(("Unable to create %s", buf));
|
2006-08-24 21:24:36 +04:00
|
|
|
die("NetSurf requires ~/.netsurf to exist, but it cannot be created.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:19:08 +04:00
|
|
|
void gui_init(int argc, char** argv)
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2007-02-02 14:34:13 +03:00
|
|
|
PangoFontDescription *fontdesc;
|
2004-10-18 02:13:35 +04:00
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
gtk_init(&argc, &argv);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
check_homedir();
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2007-02-10 04:56:27 +03:00
|
|
|
find_resource(buf, "netsurf.glade", "./gtk/res/netsurf.glade");
|
2006-07-28 19:42:43 +04:00
|
|
|
LOG(("Using '%s' as Glade template file", buf));
|
|
|
|
glade_file_location = strdup(buf);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-23 22:26:11 +04:00
|
|
|
glade_init();
|
|
|
|
gladeWindows = glade_xml_new(glade_file_location, NULL, NULL);
|
2006-08-22 18:02:07 +04:00
|
|
|
if (gladeWindows == NULL)
|
|
|
|
die("Unable to load Glade window definitions.\n");
|
2006-07-19 17:41:57 +04:00
|
|
|
glade_xml_signal_autoconnect(gladeWindows);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2007-02-10 04:56:27 +03:00
|
|
|
find_resource(buf, "netsurf.xpm", "./gtk/res/netsurf.xpm");
|
|
|
|
gtk_window_set_default_icon_from_file(buf, NULL);
|
|
|
|
|
2007-02-10 05:21:32 +03:00
|
|
|
wndTooltip = GTK_WINDOW(glade_xml_get_widget(gladeWindows, "wndTooltip"));
|
|
|
|
labelTooltip = GTK_LABEL(glade_xml_get_widget(gladeWindows, "tooltip"));
|
2006-07-19 17:41:57 +04:00
|
|
|
|
2006-11-27 18:35:18 +03:00
|
|
|
nsgtk_completion_init();
|
2006-07-26 00:55:10 +04:00
|
|
|
|
2007-02-10 04:56:27 +03:00
|
|
|
find_resource(buf, "throbber.gif", "./gtk/res/throbber.gif");
|
2006-08-22 18:02:07 +04:00
|
|
|
nsgtk_throbber_initialise(buf);
|
|
|
|
if (nsgtk_throbber == NULL)
|
|
|
|
die("Unable to load throbber image.\n");
|
2006-08-16 01:29:20 +04:00
|
|
|
|
2006-08-24 21:24:36 +04:00
|
|
|
find_resource(buf, "Choices", "~/.netsurf/Choices");
|
2008-03-21 01:53:39 +03:00
|
|
|
LOG(("Using '%s' as Preferences file", buf));
|
2006-07-23 22:26:11 +04:00
|
|
|
options_file_location = strdup(buf);
|
2004-10-18 02:13:35 +04:00
|
|
|
options_read(buf);
|
|
|
|
|
2006-08-24 21:39:41 +04:00
|
|
|
/* check what the font settings are, setting them to a default font
|
|
|
|
* if they're not set - stops Pango whinging
|
|
|
|
*/
|
|
|
|
#define SETFONTDEFAULT(x,y) (x) = ((x) != NULL) ? (x) : strdup((y))
|
|
|
|
SETFONTDEFAULT(option_font_sans, "Sans");
|
|
|
|
SETFONTDEFAULT(option_font_serif, "Serif");
|
|
|
|
SETFONTDEFAULT(option_font_mono, "Monospace");
|
|
|
|
SETFONTDEFAULT(option_font_cursive, "Serif");
|
|
|
|
SETFONTDEFAULT(option_font_fantasy, "Serif");
|
|
|
|
|
2006-07-23 22:26:11 +04:00
|
|
|
nsgtk_options_init();
|
|
|
|
|
2006-01-08 04:51:33 +03:00
|
|
|
if (!option_cookie_file) {
|
2006-08-24 21:24:36 +04:00
|
|
|
find_resource(buf, "Cookies", "~/.netsurf/Cookies");
|
2006-03-27 17:19:08 +04:00
|
|
|
LOG(("Using '%s' as Cookies file", buf));
|
2006-01-08 04:51:33 +03:00
|
|
|
option_cookie_file = strdup(buf);
|
|
|
|
}
|
|
|
|
if (!option_cookie_jar) {
|
2006-08-24 21:24:36 +04:00
|
|
|
find_resource(buf, "Cookies", "~/.netsurf/Cookies");
|
2006-03-27 17:19:08 +04:00
|
|
|
LOG(("Using '%s' as Cookie Jar file", buf));
|
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");
|
|
|
|
|
2006-07-28 20:31:23 +04:00
|
|
|
if (!option_url_file) {
|
2006-08-24 21:24:36 +04:00
|
|
|
find_resource(buf, "URLs", "~/.netsurf/URLs");
|
2006-07-28 20:31:23 +04:00
|
|
|
LOG(("Using '%s' as URL file", buf));
|
|
|
|
option_url_file = strdup(buf);
|
|
|
|
}
|
2007-06-28 20:14:05 +04:00
|
|
|
|
2007-06-27 19:43:51 +04:00
|
|
|
if (!option_ca_path) {
|
|
|
|
find_resource(buf, "certs", "/etc/ssl/certs");
|
|
|
|
LOG(("Using '%s' as certificate path", buf));
|
|
|
|
option_ca_path = strdup(buf);
|
|
|
|
}
|
2007-06-28 20:14:05 +04:00
|
|
|
|
2007-02-10 04:56:27 +03:00
|
|
|
find_resource(buf, "messages", "./gtk/res/messages");
|
2006-03-27 17:19:08 +04:00
|
|
|
LOG(("Using '%s' as Messages file", buf));
|
2004-10-18 02:13:35 +04:00
|
|
|
messages_load(buf);
|
|
|
|
|
2007-05-30 03:53:35 +04:00
|
|
|
find_resource(buf, "mime.types", "/etc/mime.types");
|
|
|
|
gtk_fetch_filetype_init(buf);
|
|
|
|
|
2004-10-18 02:13:35 +04:00
|
|
|
/* set up stylesheet urls */
|
2008-01-29 17:00:56 +03:00
|
|
|
find_resource(buf, "gtkdefault.css", "./gtk/res/gtkdefault.css");
|
2006-03-27 17:19:08 +04:00
|
|
|
default_stylesheet_url = path_to_url(buf);
|
|
|
|
LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
|
2006-04-10 03:21:13 +04:00
|
|
|
|
2007-02-10 04:56:27 +03:00
|
|
|
find_resource(buf, "adblock.css", "./gtk/res/adblock.css");
|
2006-03-27 17:19:08 +04:00
|
|
|
adblock_stylesheet_url = path_to_url(buf);
|
|
|
|
LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
|
2006-04-10 03:21:13 +04:00
|
|
|
|
2006-07-28 20:31:23 +04:00
|
|
|
urldb_load(option_url_file);
|
2006-06-27 22:24:22 +04:00
|
|
|
urldb_load_cookies(option_cookie_file);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-11-05 02:38:18 +03:00
|
|
|
wndAbout = GTK_WINDOW(glade_xml_get_widget(gladeWindows, "wndAbout"));
|
|
|
|
gtk_label_set_text(GTK_LABEL(
|
|
|
|
glade_xml_get_widget(gladeWindows, "labelVersion")),
|
|
|
|
netsurf_version);
|
|
|
|
gtk_image_set_from_file(GTK_IMAGE(
|
|
|
|
glade_xml_get_widget(gladeWindows, "imageLogo")),
|
|
|
|
find_resource(buf, "netsurf-logo.png", "netsurf-logo.png"));
|
2007-02-02 14:34:13 +03:00
|
|
|
fontdesc = pango_font_description_from_string("Monospace 8");
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(
|
|
|
|
glade_xml_get_widget(gladeWindows, "textviewGPL")), fontdesc);
|
2007-06-28 20:14:05 +04:00
|
|
|
|
2007-05-06 20:39:34 +04:00
|
|
|
wndWarning = GTK_WINDOW(glade_xml_get_widget(gladeWindows, "wndWarning"));
|
2007-06-22 19:16:48 +04:00
|
|
|
wndOpenFile = GTK_DIALOG(glade_xml_get_widget(gladeWindows, "wndOpenFile"));
|
2007-05-06 20:39:34 +04:00
|
|
|
|
2006-08-18 15:44:24 +04:00
|
|
|
nsgtk_history_init();
|
2007-10-03 02:22:17 +04:00
|
|
|
nsgtk_download_initialise();
|
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
|
|
|
{
|
2008-03-20 02:20:28 +03:00
|
|
|
const char *addr = "http://netsurf-browser.org/welcome/";
|
2006-04-10 03:21:13 +04:00
|
|
|
|
2007-06-28 20:14:05 +04:00
|
|
|
if (option_homepage_url != NULL && option_homepage_url[0] != '\0')
|
2006-03-29 19:26:54 +04:00
|
|
|
addr = option_homepage_url;
|
|
|
|
|
2006-03-19 19:03:02 +03:00
|
|
|
if (argc > 1) addr = argv[1];
|
2006-04-23 02:10:08 +04:00
|
|
|
browser_window_create(addr, 0, 0, true);
|
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;
|
2007-08-07 07:55:18 +04:00
|
|
|
bool block = true;
|
|
|
|
|
|
|
|
if (browser_reformat_pending)
|
|
|
|
block = false;
|
2005-12-20 00:54:51 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-07 07:55:18 +04:00
|
|
|
|
|
|
|
gtk_main_iteration_do(block);
|
|
|
|
|
2005-12-20 00:54:51 +03:00
|
|
|
for (unsigned int i = 0; i != fd_count; i++) {
|
|
|
|
g_main_context_remove_poll(0, fd_list[i]);
|
|
|
|
free(fd_list[i]);
|
|
|
|
}
|
2007-08-07 07:55:18 +04:00
|
|
|
|
|
|
|
schedule_run();
|
|
|
|
|
|
|
|
if (browser_reformat_pending)
|
|
|
|
nsgtk_window_process_reformats();
|
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)
|
|
|
|
{
|
2006-06-27 22:24:22 +04:00
|
|
|
urldb_save_cookies(option_cookie_jar);
|
2006-07-28 20:31:23 +04:00
|
|
|
urldb_save(option_url_file);
|
2004-10-18 02:13:35 +04:00
|
|
|
free(default_stylesheet_url);
|
|
|
|
free(adblock_stylesheet_url);
|
2006-03-27 17:19:08 +04:00
|
|
|
free(option_cookie_file);
|
|
|
|
free(option_cookie_jar);
|
2007-05-30 03:53:35 +04:00
|
|
|
gtk_fetch_filetype_fin();
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-26 22:07:32 +04:00
|
|
|
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
browser_window_form_select(select_menu_bw, select_menu_control,
|
2007-10-03 02:22:17 +04:00
|
|
|
(intptr_t)user_data);
|
2007-09-26 22:07:32 +04:00
|
|
|
}
|
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
|
|
|
{
|
2006-11-05 02:38:18 +03:00
|
|
|
|
2007-10-03 02:22:17 +04:00
|
|
|
intptr_t i;
|
2006-11-05 02:38:18 +03:00
|
|
|
struct form_option *option;
|
2007-09-26 22:07:32 +04:00
|
|
|
|
|
|
|
GtkWidget *menu_item;
|
2006-11-05 02:38:18 +03:00
|
|
|
|
2007-09-26 22:07:32 +04:00
|
|
|
/* control->data.select.multiple is true if multiple selections
|
|
|
|
* are allowable. We ignore this, as the core handles it for us.
|
|
|
|
* Yay. \o/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (select_menu != NULL)
|
|
|
|
gtk_widget_destroy(select_menu);
|
|
|
|
|
|
|
|
select_menu = gtk_menu_new();
|
|
|
|
select_menu_bw = bw;
|
|
|
|
select_menu_control = control;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-11-05 02:38:18 +03:00
|
|
|
for (i = 0, option = control->data.select.items; option;
|
|
|
|
i++, option = option->next) {
|
2007-09-26 22:07:32 +04:00
|
|
|
menu_item = gtk_check_menu_item_new_with_label(option->text);
|
|
|
|
if (option->selected)
|
|
|
|
gtk_check_menu_item_set_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(menu_item), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect(menu_item, "toggled",
|
|
|
|
G_CALLBACK(nsgtk_select_menu_clicked), (gpointer)i);
|
|
|
|
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(select_menu), menu_item);
|
2006-11-05 02:38:18 +03:00
|
|
|
}
|
2007-09-26 22:07:32 +04:00
|
|
|
|
|
|
|
gtk_widget_show_all(select_menu);
|
|
|
|
|
|
|
|
gtk_menu_popup(GTK_MENU(select_menu), NULL, NULL, NULL,
|
|
|
|
NULL /* data */, 0, gtk_get_current_event_time());
|
2006-11-05 02:38:18 +03:00
|
|
|
|
2004-06-22 22:48:33 +04:00
|
|
|
}
|
|
|
|
|
2006-07-04 23:56:37 +04:00
|
|
|
void gui_window_save_as_link(struct gui_window *g, struct content *c)
|
|
|
|
{
|
|
|
|
}
|
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)
|
|
|
|
{
|
2007-05-06 20:39:34 +04:00
|
|
|
char buf[300]; /* 300 is the size the RISC OS GUI uses */
|
|
|
|
|
2007-06-16 02:07:11 +04:00
|
|
|
LOG(("%s %s", warning, detail ? detail : ""));
|
2007-05-06 23:27:04 +04:00
|
|
|
fflush(stdout);
|
2007-05-06 20:39:34 +04:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s %s", messages_get(warning),
|
|
|
|
detail ? detail : "");
|
|
|
|
buf[sizeof(buf) - 1] = 0;
|
|
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, "labelWarning")), buf);
|
|
|
|
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(wndWarning));
|
2004-06-22 22:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void die(const char * const error)
|
|
|
|
{
|
2006-06-29 02:29:45 +04:00
|
|
|
fprintf(stderr, "%s", error);
|
2004-06-22 22:48:33 +04:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-22 16:03:37 +04:00
|
|
|
void hotlist_visited(struct content *content)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-23 20:27:30 +03:00
|
|
|
void gui_cert_verify(struct browser_window *bw, struct content *c,
|
2007-06-27 20:06:42 +04:00
|
|
|
const struct ssl_cert_info *certs, unsigned long num)
|
|
|
|
{
|
2007-08-12 03:14:33 +04:00
|
|
|
nsgtk_create_ssl_verify_window(bw, c, certs, num);
|
|
|
|
}
|
2007-06-27 20:06:42 +04:00
|
|
|
|
2007-08-12 03:14:33 +04:00
|
|
|
static void nsgtk_create_ssl_verify_window(struct browser_window *bw,
|
|
|
|
struct content *c, const struct ssl_cert_info *certs,
|
|
|
|
unsigned long num)
|
|
|
|
{
|
|
|
|
GladeXML *x = glade_xml_new(glade_file_location, NULL, NULL);
|
|
|
|
GtkWindow *wnd = GTK_WINDOW(glade_xml_get_widget(x, "wndSSLProblem"));
|
|
|
|
GtkButton *accept, *reject;
|
|
|
|
void **session = calloc(sizeof(void *), 4);
|
|
|
|
|
|
|
|
session[0] = bw;
|
2007-08-12 03:22:10 +04:00
|
|
|
session[1] = strdup(c->url);
|
2007-08-12 03:14:33 +04:00
|
|
|
session[2] = x;
|
|
|
|
session[3] = wnd;
|
|
|
|
|
|
|
|
accept = GTK_BUTTON(glade_xml_get_widget(x, "sslaccept"));
|
|
|
|
reject = GTK_BUTTON(glade_xml_get_widget(x, "sslreject"));
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(accept), "clicked",
|
|
|
|
G_CALLBACK(nsgtk_ssl_accept), (gpointer)session);
|
|
|
|
g_signal_connect(G_OBJECT(reject), "clicked",
|
|
|
|
G_CALLBACK(nsgtk_ssl_reject), (gpointer)session);
|
|
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(wnd));
|
|
|
|
}
|
2007-06-27 20:06:42 +04:00
|
|
|
|
2007-08-12 03:14:33 +04:00
|
|
|
static void nsgtk_ssl_accept(GtkButton *w, gpointer data)
|
|
|
|
{
|
|
|
|
void **session = data;
|
|
|
|
struct browser_window *bw = session[0];
|
2007-08-12 03:22:10 +04:00
|
|
|
char *url = session[1];
|
2007-08-12 03:14:33 +04:00
|
|
|
GladeXML *x = session[2];
|
|
|
|
GtkWindow *wnd = session[3];
|
|
|
|
|
2007-08-12 03:22:10 +04:00
|
|
|
urldb_set_cert_permissions(url, true);
|
|
|
|
browser_window_go(bw, url, 0, true);
|
2007-08-12 03:14:33 +04:00
|
|
|
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(wnd));
|
|
|
|
g_object_unref(G_OBJECT(x));
|
2007-08-12 03:22:10 +04:00
|
|
|
free(url);
|
2007-08-12 03:14:33 +04:00
|
|
|
free(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nsgtk_ssl_reject(GtkButton *w, gpointer data)
|
|
|
|
{
|
|
|
|
void **session = data;
|
|
|
|
GladeXML *x = session[2];
|
|
|
|
GtkWindow *wnd = session[3];
|
|
|
|
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(wnd));
|
|
|
|
g_object_unref(G_OBJECT(x));
|
2007-08-12 03:22:10 +04:00
|
|
|
free(session[1]);
|
2007-08-12 03:14:33 +04:00
|
|
|
free(session);
|
2007-06-27 20:06:42 +04:00
|
|
|
}
|
2004-09-04 02:44:48 +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;
|
|
|
|
}
|
2006-07-06 14:34:15 +04:00
|
|
|
|
2006-07-15 15:59:25 +04:00
|
|
|
char *path_to_url(const char *path)
|
|
|
|
{
|
|
|
|
char *r = malloc(strlen(path) + 7 + 1);
|
|
|
|
|
|
|
|
strcpy(r, "file://");
|
|
|
|
strcat(r, path);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-07-06 14:34:15 +04:00
|
|
|
char *url_to_path(const char *url)
|
|
|
|
{
|
|
|
|
return strdup(url + 5);
|
|
|
|
}
|
|
|
|
|
2006-07-16 20:11:12 +04:00
|
|
|
bool cookies_update(const char *domain, const struct cookie_data *data)
|
2006-07-13 16:46:02 +04:00
|
|
|
{
|
2006-07-15 15:59:25 +04:00
|
|
|
return true;
|
2006-07-13 16:46:02 +04:00
|
|
|
}
|