2010-10-05 23:14:46 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Cookies (implementation).
|
|
|
|
*/
|
|
|
|
|
2015-04-12 22:26:53 +03:00
|
|
|
#include <gtk/gtk.h>
|
2016-07-01 16:27:04 +03:00
|
|
|
#include <stdint.h>
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2015-04-12 22:26:53 +03:00
|
|
|
#include "utils/log.h"
|
2016-07-01 16:27:04 +03:00
|
|
|
#include "netsurf/keypress.h"
|
2013-09-03 01:41:04 +04:00
|
|
|
#include "desktop/cookie_manager.h"
|
2016-05-04 17:20:53 +03:00
|
|
|
#include "desktop/plot_style.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/tree.h"
|
2015-04-12 22:26:53 +03:00
|
|
|
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/cookies.h"
|
|
|
|
#include "gtk/plotters.h"
|
|
|
|
#include "gtk/scaffolding.h"
|
|
|
|
#include "gtk/treeview.h"
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "gtk/resources.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2016-07-25 23:55:03 +03:00
|
|
|
static struct nsgtk_treeview *cookies_treeview;
|
|
|
|
static GtkBuilder *cookie_builder;
|
|
|
|
static GtkWindow *wndCookies = NULL;
|
|
|
|
|
|
|
|
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
|
2010-10-05 23:14:46 +04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* edit menu */
|
|
|
|
MENUPROTO(delete_selected);
|
|
|
|
MENUPROTO(delete_all);
|
|
|
|
MENUPROTO(select_all);
|
|
|
|
MENUPROTO(clear_selection);
|
|
|
|
|
|
|
|
/* view menu*/
|
|
|
|
MENUPROTO(expand_all);
|
|
|
|
MENUPROTO(expand_domains);
|
|
|
|
MENUPROTO(expand_cookies);
|
|
|
|
MENUPROTO(collapse_all);
|
|
|
|
MENUPROTO(collapse_domains);
|
|
|
|
MENUPROTO(collapse_cookies);
|
|
|
|
|
|
|
|
|
|
|
|
static struct menu_events menu_events[] = {
|
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_domains),
|
2015-06-13 13:31:23 +03:00
|
|
|
MENUEVENT(expand_cookies),
|
2010-10-05 23:14:46 +04:00
|
|
|
MENUEVENT(collapse_all),
|
|
|
|
MENUEVENT(collapse_domains),
|
|
|
|
MENUEVENT(collapse_cookies),
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2016-07-25 23:55:03 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
/**
|
2015-06-13 13:31:23 +03:00
|
|
|
* Connects menu events in the cookies window.
|
2010-10-05 23:14:46 +04:00
|
|
|
*/
|
2015-06-13 13:31:23 +03:00
|
|
|
static void nsgtk_cookies_init_menu(void)
|
|
|
|
{
|
|
|
|
struct menu_events *event = menu_events;
|
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
while (event->widget != NULL) {
|
|
|
|
w = GTK_WIDGET(gtk_builder_get_object(cookie_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, cookies_treeview);
|
|
|
|
}
|
|
|
|
event++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 23:55:03 +03:00
|
|
|
/**
|
|
|
|
* Creates the window for the cookies tree.
|
|
|
|
*
|
|
|
|
* \return NSERROR_OK on success else appropriate error code on faliure.
|
|
|
|
*/
|
|
|
|
static nserror nsgtk_cookies_init(void)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
GtkScrolledWindow *scrolled;
|
|
|
|
GtkDrawingArea *drawing_area;
|
2015-06-13 13:31:23 +03:00
|
|
|
nserror res;
|
2010-12-14 21:54:20 +03:00
|
|
|
|
2016-07-25 23:55:03 +03:00
|
|
|
if (wndCookies != NULL) {
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
res = nsgtk_builder_new_from_resname("cookies", &cookie_builder);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
LOG("Cookie 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(cookie_builder, NULL);
|
|
|
|
|
|
|
|
wndCookies = GTK_WINDOW(gtk_builder_get_object(cookie_builder,
|
|
|
|
"wndCookies"));
|
|
|
|
|
|
|
|
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(cookie_builder,
|
2010-10-05 23:14:46 +04:00
|
|
|
"cookiesScrolled"));
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(cookie_builder,
|
2010-10-05 23:14:46 +04:00
|
|
|
"cookiesDrawingArea"));
|
2015-06-13 13:31:23 +03:00
|
|
|
|
|
|
|
cookies_treeview = nsgtk_treeview_create(TREE_COOKIES,
|
|
|
|
wndCookies,
|
|
|
|
scrolled,
|
2016-07-12 02:29:58 +03:00
|
|
|
drawing_area,
|
|
|
|
NULL);
|
2015-06-13 13:31:23 +03:00
|
|
|
if (cookies_treeview == NULL) {
|
|
|
|
return NSERROR_INIT_FAILED;
|
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +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-12-14 21:54:20 +03:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
CONNECT(wndCookies, "delete_event", gtk_widget_hide_on_delete, NULL);
|
|
|
|
CONNECT(wndCookies, "hide", nsgtk_tree_window_hide, cookies_treeview);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
nsgtk_cookies_init_menu();
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
return NSERROR_OK;
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* edit menu */
|
|
|
|
MENUHANDLER(delete_selected)
|
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
cookie_manager_keypress(NS_KEY_DELETE_LEFT);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(delete_all)
|
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
cookie_manager_keypress(NS_KEY_SELECT_ALL);
|
|
|
|
cookie_manager_keypress(NS_KEY_DELETE_LEFT);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(select_all)
|
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
cookie_manager_keypress(NS_KEY_SELECT_ALL);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(clear_selection)
|
|
|
|
{
|
2015-03-27 12:36:19 +03:00
|
|
|
cookie_manager_keypress(NS_KEY_CLEAR_SELECTION);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* view menu*/
|
|
|
|
MENUHANDLER(expand_all)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(expand_domains)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_expand(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(expand_cookies)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(collapse_all)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_contract(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(collapse_domains)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_contract(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MENUHANDLER(collapse_cookies)
|
|
|
|
{
|
2013-09-03 15:36:55 +04:00
|
|
|
cookie_manager_contract(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-07-25 23:55:03 +03:00
|
|
|
|
|
|
|
/* exported function documented gtk/cookies.h */
|
|
|
|
nserror nsgtk_cookies_present(void)
|
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
|
|
|
|
res = nsgtk_cookies_init();
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
gtk_window_present(wndCookies);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported function documented gtk/cookies.h */
|
|
|
|
void nsgtk_cookies_destroy(void)
|
|
|
|
{
|
|
|
|
/** \todo what about cookie_builder? */
|
|
|
|
if (wndCookies != NULL) {
|
|
|
|
nsgtk_treeview_destroy(cookies_treeview);
|
|
|
|
}
|
|
|
|
}
|