2006-08-18 15:44:24 +04:00
|
|
|
/*
|
2016-08-06 19:08:21 +03:00
|
|
|
* Copyright 2010 John Mark Bell <jmb@netsurf-browser.org>
|
|
|
|
* Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
|
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/>.
|
2006-08-18 15:44:24 +04:00
|
|
|
*/
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Implementation of GTK global history manager.
|
|
|
|
*/
|
|
|
|
|
2016-07-01 16:27:04 +03:00
|
|
|
#include <stdint.h>
|
2016-08-05 01:41:22 +03:00
|
|
|
#include <stdlib.h>
|
2015-04-12 22:26:53 +03:00
|
|
|
#include <gtk/gtk.h>
|
2009-03-29 16:49:17 +04:00
|
|
|
|
2015-04-09 00:21:30 +03:00
|
|
|
#include "utils/log.h"
|
2016-07-01 16:27:04 +03:00
|
|
|
#include "netsurf/keypress.h"
|
2016-08-05 01:41:22 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2013-09-03 01:41:04 +04:00
|
|
|
#include "desktop/global_history.h"
|
2015-04-09 00:21:30 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
#include "gtk/compat.h"
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/plotters.h"
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "gtk/resources.h"
|
2016-08-05 01:41:22 +03:00
|
|
|
#include "gtk/corewindow.h"
|
2016-08-05 01:50:06 +03:00
|
|
|
#include "gtk/global_history.h"
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
struct nsgtk_global_history_window {
|
|
|
|
struct nsgtk_corewindow core;
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWindow *wnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct nsgtk_global_history_window *global_history_window = NULL;
|
2008-08-24 14:31:38 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
|
|
|
|
GtkMenuItem *widget, gpointer g)
|
2015-06-13 13:31:23 +03:00
|
|
|
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
|
2010-10-05 23:14:46 +04:00
|
|
|
#define MENUHANDLER(x) gboolean nsgtk_on_##x##_activate(GtkMenuItem *widget, \
|
|
|
|
gpointer g)
|
|
|
|
|
|
|
|
struct menu_events {
|
|
|
|
const char *widget;
|
|
|
|
GCallback handler;
|
2008-08-24 14:31:38 +04:00
|
|
|
};
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* file menu*/
|
|
|
|
MENUPROTO(export);
|
|
|
|
|
|
|
|
/* edit menu */
|
|
|
|
MENUPROTO(delete_selected);
|
|
|
|
MENUPROTO(delete_all);
|
|
|
|
MENUPROTO(select_all);
|
|
|
|
MENUPROTO(clear_selection);
|
|
|
|
|
|
|
|
/* view menu*/
|
|
|
|
MENUPROTO(expand_all);
|
|
|
|
MENUPROTO(expand_directories);
|
2015-06-13 13:31:23 +03:00
|
|
|
MENUPROTO(expand_addresses);
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUPROTO(collapse_all);
|
|
|
|
MENUPROTO(collapse_directories);
|
|
|
|
MENUPROTO(collapse_addresses);
|
|
|
|
|
|
|
|
MENUPROTO(launch);
|
|
|
|
|
|
|
|
static struct menu_events menu_events[] = {
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* file menu*/
|
|
|
|
MENUEVENT(export),
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* edit menu */
|
|
|
|
MENUEVENT(delete_selected),
|
|
|
|
MENUEVENT(delete_all),
|
|
|
|
MENUEVENT(select_all),
|
|
|
|
MENUEVENT(clear_selection),
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* view menu*/
|
|
|
|
MENUEVENT(expand_all),
|
|
|
|
MENUEVENT(expand_directories),
|
2015-06-13 13:31:23 +03:00
|
|
|
MENUEVENT(expand_addresses),
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUEVENT(collapse_all),
|
|
|
|
MENUEVENT(collapse_directories),
|
|
|
|
MENUEVENT(collapse_addresses),
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUEVENT(launch),
|
|
|
|
{NULL, NULL}
|
2006-08-18 15:44:24 +04:00
|
|
|
};
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/* edit menu */
|
|
|
|
MENUHANDLER(delete_selected)
|
2015-06-13 13:31:23 +03:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
global_history_keypress(NS_KEY_DELETE_LEFT);
|
|
|
|
return TRUE;
|
2015-06-13 13:31:23 +03:00
|
|
|
}
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(delete_all)
|
2006-08-18 15:44:24 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
global_history_keypress(NS_KEY_SELECT_ALL);
|
|
|
|
global_history_keypress(NS_KEY_DELETE_LEFT);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(select_all)
|
|
|
|
{
|
|
|
|
global_history_keypress(NS_KEY_SELECT_ALL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(clear_selection)
|
|
|
|
{
|
|
|
|
global_history_keypress(NS_KEY_CLEAR_SELECTION);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/* view menu*/
|
|
|
|
MENUHANDLER(expand_all)
|
|
|
|
{
|
|
|
|
global_history_expand(false);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(expand_directories)
|
|
|
|
{
|
|
|
|
global_history_expand(true);
|
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(expand_addresses)
|
|
|
|
{
|
|
|
|
global_history_expand(false);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-24 14:31:38 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(collapse_all)
|
|
|
|
{
|
|
|
|
global_history_contract(true);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(collapse_directories)
|
|
|
|
{
|
|
|
|
global_history_contract(true);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(collapse_addresses)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
global_history_contract(false);
|
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
MENUHANDLER(launch)
|
|
|
|
{
|
|
|
|
global_history_keypress(NS_KEY_CR);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
/* file menu */
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(export)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
struct nsgtk_global_history_window *ghwin;
|
2010-10-05 23:14:46 +04:00
|
|
|
GtkWidget *save_dialog;
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
ghwin = (struct nsgtk_global_history_window *)g;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
save_dialog = gtk_file_chooser_dialog_new("Save File",
|
2016-08-05 01:41:22 +03:00
|
|
|
ghwin->wnd,
|
2010-10-05 23:14:46 +04:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
2015-04-09 00:21:30 +03:00
|
|
|
NSGTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
NSGTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
|
2010-10-05 23:14:46 +04:00
|
|
|
NULL);
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(save_dialog),
|
|
|
|
getenv("HOME") ? getenv("HOME") : "/");
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_dialog),
|
|
|
|
"history.html");
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (gtk_dialog_run(GTK_DIALOG(save_dialog)) == GTK_RESPONSE_ACCEPT) {
|
|
|
|
gchar *filename = gtk_file_chooser_get_filename(
|
|
|
|
GTK_FILE_CHOOSER(save_dialog));
|
2015-06-13 13:31:23 +03:00
|
|
|
|
|
|
|
global_history_export(filename, NULL);
|
2010-10-05 23:14:46 +04:00
|
|
|
g_free(filename);
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
gtk_widget_destroy(save_dialog);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/**
|
|
|
|
* Connects menu events in the global history window.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nsgtk_global_history_init_menu(struct nsgtk_global_history_window *ghwin)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
struct menu_events *event = menu_events;
|
|
|
|
GtkWidget *w;
|
2008-08-24 14:31:38 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
while (event->widget != NULL) {
|
|
|
|
w = GTK_WIDGET(gtk_builder_get_object(ghwin->builder,
|
|
|
|
event->widget));
|
|
|
|
if (w == NULL) {
|
|
|
|
LOG("Unable to connect menu widget ""%s""",
|
|
|
|
event->widget);
|
|
|
|
} else {
|
|
|
|
g_signal_connect(G_OBJECT(w),
|
|
|
|
"activate",
|
|
|
|
event->handler,
|
|
|
|
ghwin);
|
|
|
|
}
|
|
|
|
event++;
|
|
|
|
}
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2008-08-24 14:31:38 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/**
|
|
|
|
* callback for mouse action on cookie window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param mouse_state netsurf mouse state on event
|
|
|
|
* \param x location of event
|
|
|
|
* \param y location of event
|
|
|
|
* \return NSERROR_OK on success otherwise apropriate error code
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
nsgtk_global_history_mouse(struct nsgtk_corewindow *nsgtk_cw,
|
|
|
|
browser_mouse_state mouse_state,
|
|
|
|
int x, int y)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
global_history_mouse_action(mouse_state, x, y);
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
return NSERROR_OK;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/**
|
|
|
|
* callback for keypress on cookie window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param nskey The netsurf key code
|
|
|
|
* \return NSERROR_OK on success otherwise apropriate error code
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
nsgtk_global_history_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
if (global_history_keypress(nskey)) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
return NSERROR_NOT_IMPLEMENTED;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* callback on draw event for cookie window
|
|
|
|
*
|
|
|
|
* \param nsgtk_cw The nsgtk core window structure.
|
|
|
|
* \param r The rectangle of the window that needs updating.
|
|
|
|
* \return NSERROR_OK on success otherwise apropriate error code
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
nsgtk_global_history_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.background_images = true,
|
|
|
|
.plot = &nsgtk_plotters
|
|
|
|
};
|
|
|
|
|
|
|
|
global_history_redraw(0, 0, r, &ctx);
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
/**
|
|
|
|
* Creates the window for the global history tree.
|
|
|
|
*
|
|
|
|
* \return NSERROR_OK on success else appropriate error code on faliure.
|
|
|
|
*/
|
|
|
|
static nserror nsgtk_global_history_init(void)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
struct nsgtk_global_history_window *ncwin;
|
|
|
|
nserror res;
|
|
|
|
|
|
|
|
if (global_history_window != NULL) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ncwin = malloc(sizeof(struct nsgtk_global_history_window));
|
|
|
|
if (ncwin == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = nsgtk_builder_new_from_resname("history", &ncwin->builder);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
LOG("History UI builder init failed");
|
|
|
|
free(ncwin);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_builder_connect_signals(ncwin->builder, NULL);
|
|
|
|
|
|
|
|
ncwin->wnd = GTK_WINDOW(gtk_builder_get_object(ncwin->builder,
|
|
|
|
"wndHistory"));
|
|
|
|
|
|
|
|
ncwin->core.scrolled = GTK_SCROLLED_WINDOW(
|
|
|
|
gtk_builder_get_object(ncwin->builder,
|
|
|
|
"globalHistoryScrolled"));
|
|
|
|
|
|
|
|
ncwin->core.drawing_area = GTK_DRAWING_AREA(
|
|
|
|
gtk_builder_get_object(ncwin->builder,
|
|
|
|
"globalHistoryDrawingArea"));
|
|
|
|
|
|
|
|
/* make the delete event hide the window */
|
|
|
|
g_signal_connect(G_OBJECT(ncwin->wnd),
|
|
|
|
"delete_event",
|
|
|
|
G_CALLBACK(gtk_widget_hide_on_delete),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
nsgtk_global_history_init_menu(ncwin);
|
|
|
|
|
|
|
|
ncwin->core.draw = nsgtk_global_history_draw;
|
|
|
|
ncwin->core.key = nsgtk_global_history_key;
|
|
|
|
ncwin->core.mouse = nsgtk_global_history_mouse;
|
|
|
|
|
|
|
|
res = nsgtk_corewindow_init(&ncwin->core);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
free(ncwin);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = global_history_init(ncwin->core.cb_table,
|
|
|
|
(struct core_window *)ncwin);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
free(ncwin);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* memoise window so it can be represented when necessary
|
|
|
|
* instead of recreating every time.
|
|
|
|
*/
|
|
|
|
global_history_window = ncwin;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2006-08-18 15:44:24 +04:00
|
|
|
}
|
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
/* exported function documented gtk/history.h */
|
|
|
|
nserror nsgtk_global_history_present(void)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
nserror res;
|
|
|
|
|
|
|
|
res = nsgtk_global_history_init();
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
gtk_window_present(global_history_window->wnd);
|
|
|
|
}
|
|
|
|
return res;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
/* exported function documented gtk/history.h */
|
|
|
|
nserror nsgtk_global_history_destroy(void)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
2016-08-05 01:41:22 +03:00
|
|
|
nserror res;
|
|
|
|
|
|
|
|
if (global_history_window == NULL) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = global_history_fini();
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
res = nsgtk_corewindow_fini(&global_history_window->core);
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(global_history_window->wnd));
|
|
|
|
g_object_unref(G_OBJECT(global_history_window->builder));
|
|
|
|
free(global_history_window);
|
|
|
|
global_history_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2006-08-18 15:44:24 +04:00
|
|
|
}
|
2016-08-05 01:41:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|