2006-08-18 15:44:24 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
|
2015-06-13 13:31:23 +03:00
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@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/>.
|
2006-08-18 15:44:24 +04:00
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "utils/utils.h"
|
2013-09-03 01:41:04 +04:00
|
|
|
#include "desktop/global_history.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "desktop/tree.h"
|
2013-09-03 01:41:04 +04:00
|
|
|
#include "desktop/textinput.h"
|
2015-04-09 00:21:30 +03:00
|
|
|
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/plotters.h"
|
|
|
|
#include "gtk/scaffolding.h"
|
|
|
|
#include "gtk/treeview.h"
|
2015-04-09 00:21:30 +03:00
|
|
|
#include "gtk/compat.h"
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "gtk/resources.h"
|
|
|
|
#include "gtk/history.h"
|
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
|
|
|
};
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
static struct nsgtk_treeview *global_history_window;
|
2015-06-13 13:31:23 +03:00
|
|
|
static GtkBuilder *history_builder;
|
2010-10-05 23:14:46 +04:00
|
|
|
GtkWindow *wndHistory;
|
2008-08-24 14:31:38 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
/**
|
|
|
|
* Connects menu events in the global history window.
|
|
|
|
*/
|
|
|
|
static void nsgtk_history_init_menu(void)
|
|
|
|
{
|
|
|
|
struct menu_events *event = menu_events;
|
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
while (event->widget != NULL) {
|
|
|
|
w = GTK_WIDGET(gtk_builder_get_object(history_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,
|
|
|
|
global_history_window);
|
|
|
|
}
|
|
|
|
event++;
|
|
|
|
}
|
|
|
|
}
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
/* exported interface, documented in gtk/history.h */
|
|
|
|
nserror nsgtk_history_init(void)
|
2006-08-18 15:44:24 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
GtkWindow *window;
|
|
|
|
GtkScrolledWindow *scrolled;
|
|
|
|
GtkDrawingArea *drawing_area;
|
2015-06-13 13:31:23 +03:00
|
|
|
nserror res;
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
res = nsgtk_builder_new_from_resname("history", &history_builder);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
LOG("History UI builder init failed");
|
|
|
|
return res;
|
2012-05-16 23:57:43 +04:00
|
|
|
}
|
2015-06-13 13:31:23 +03:00
|
|
|
gtk_builder_connect_signals(history_builder, NULL);
|
|
|
|
|
|
|
|
wndHistory = GTK_WINDOW(gtk_builder_get_object(history_builder,
|
|
|
|
"wndHistory"));
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
window = wndHistory;
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(history_builder,
|
|
|
|
"globalHistoryScrolled"));
|
|
|
|
|
|
|
|
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(history_builder,
|
|
|
|
"globalHistoryDrawingArea"));
|
|
|
|
|
|
|
|
global_history_window = nsgtk_treeview_create(TREE_HISTORY,
|
|
|
|
window,
|
|
|
|
scrolled,
|
|
|
|
drawing_area);
|
|
|
|
if (global_history_window == NULL) {
|
|
|
|
return NSERROR_INIT_FAILED;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
#define CONNECT(obj, sig, callback, ptr) \
|
2015-06-13 13:31:23 +03:00
|
|
|
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
|
|
|
|
CONNECT(window, "hide", nsgtk_tree_window_hide, global_history_window);
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
nsgtk_history_init_menu();
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
return NSERROR_OK;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/**
|
|
|
|
* Destroys the global history window and performs any other necessary cleanup
|
|
|
|
* actions.
|
|
|
|
*/
|
|
|
|
void nsgtk_history_destroy(void)
|
|
|
|
{
|
2015-06-13 13:31:23 +03:00
|
|
|
/** \todo what about history_builder? */
|
2010-10-05 23:14:46 +04:00
|
|
|
nsgtk_treeview_destroy(global_history_window);
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
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
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
GtkWidget *save_dialog;
|
|
|
|
save_dialog = gtk_file_chooser_dialog_new("Save File",
|
|
|
|
wndHistory,
|
|
|
|
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
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* edit menu */
|
|
|
|
MENUHANDLER(delete_selected)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
global_history_keypress(NS_KEY_DELETE_LEFT);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(delete_all)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
global_history_keypress(NS_KEY_SELECT_ALL);
|
|
|
|
global_history_keypress(NS_KEY_DELETE_LEFT);
|
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
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(select_all)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
global_history_keypress(NS_KEY_SELECT_ALL);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(clear_selection)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
global_history_keypress(NS_KEY_CLEAR_SELECTION);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2006-08-18 15:44:24 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* view menu*/
|
|
|
|
MENUHANDLER(expand_all)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(expand_directories)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_expand(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(expand_addresses)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(collapse_all)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_contract(true);
|
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
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(collapse_directories)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_contract(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2006-08-18 15:44:24 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(collapse_addresses)
|
2008-08-24 14:31:38 +04:00
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
global_history_contract(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2008-08-24 14:31:38 +04:00
|
|
|
}
|
2006-08-18 15:44:24 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUHANDLER(launch)
|
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
global_history_keypress(NS_KEY_CR);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
2006-08-18 15:44:24 +04:00
|
|
|
}
|