mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-02-08 02:24:41 +03:00
make gtk cookies manager use core window API
This commit is contained in:
parent
ca5b165c85
commit
51725592c9
@ -16,28 +16,34 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Cookies (implementation).
|
||||
/**
|
||||
* \file
|
||||
* Implementation of GTK cookie manager.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "utils/log.h"
|
||||
#include "netsurf/keypress.h"
|
||||
#include "netsurf/plotters.h"
|
||||
#include "desktop/cookie_manager.h"
|
||||
#include "desktop/plot_style.h"
|
||||
#include "desktop/tree.h"
|
||||
#include "desktop/treeview.h"
|
||||
|
||||
#include "gtk/cookies.h"
|
||||
#include "gtk/plotters.h"
|
||||
#include "gtk/scaffolding.h"
|
||||
#include "gtk/treeview.h"
|
||||
#include "gtk/resources.h"
|
||||
#include "gtk/corewindow.h"
|
||||
|
||||
static struct nsgtk_treeview *cookies_treeview;
|
||||
static GtkBuilder *cookie_builder;
|
||||
static GtkWindow *wndCookies = NULL;
|
||||
struct nsgtk_cookie_window {
|
||||
struct nsgtk_corewindow core;
|
||||
GtkBuilder *builder;
|
||||
GtkWindow *wnd;
|
||||
};
|
||||
|
||||
static struct nsgtk_cookie_window *cookie_window = NULL;
|
||||
|
||||
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
|
||||
GtkMenuItem *widget, gpointer g)
|
||||
@ -85,80 +91,6 @@ static struct menu_events menu_events[] = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connects menu events in the cookies window.
|
||||
*/
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the window for the cookies tree.
|
||||
*
|
||||
* \return NSERROR_OK on success else appropriate error code on faliure.
|
||||
*/
|
||||
static nserror nsgtk_cookies_init(void)
|
||||
{
|
||||
GtkScrolledWindow *scrolled;
|
||||
GtkDrawingArea *drawing_area;
|
||||
nserror res;
|
||||
|
||||
if (wndCookies != NULL) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
res = nsgtk_builder_new_from_resname("cookies", &cookie_builder);
|
||||
if (res != NSERROR_OK) {
|
||||
LOG("Cookie UI builder init failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
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,
|
||||
"cookiesScrolled"));
|
||||
|
||||
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(cookie_builder,
|
||||
"cookiesDrawingArea"));
|
||||
|
||||
cookies_treeview = nsgtk_treeview_create(TREE_COOKIES,
|
||||
wndCookies,
|
||||
scrolled,
|
||||
drawing_area,
|
||||
NULL);
|
||||
if (cookies_treeview == NULL) {
|
||||
return NSERROR_INIT_FAILED;
|
||||
}
|
||||
|
||||
#define CONNECT(obj, sig, callback, ptr) \
|
||||
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
|
||||
|
||||
CONNECT(wndCookies, "delete_event", gtk_widget_hide_on_delete, NULL);
|
||||
CONNECT(wndCookies, "hide", nsgtk_tree_window_hide, cookies_treeview);
|
||||
|
||||
nsgtk_cookies_init_menu();
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* edit menu */
|
||||
MENUHANDLER(delete_selected)
|
||||
{
|
||||
@ -222,6 +154,162 @@ MENUHANDLER(collapse_cookies)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects menu events in the cookies window.
|
||||
*/
|
||||
static void nsgtk_cookies_init_menu(struct nsgtk_cookie_window *ncwin)
|
||||
{
|
||||
struct menu_events *event = menu_events;
|
||||
GtkWidget *w;
|
||||
|
||||
while (event->widget != NULL) {
|
||||
w = GTK_WIDGET(gtk_builder_get_object(ncwin->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,
|
||||
ncwin);
|
||||
}
|
||||
event++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
|
||||
browser_mouse_state mouse_state,
|
||||
int x, int y)
|
||||
{
|
||||
cookie_manager_mouse_action(mouse_state, x, y);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
|
||||
{
|
||||
if (cookie_manager_keypress(nskey)) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
return NSERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
|
||||
{
|
||||
struct redraw_context ctx = {
|
||||
.interactive = true,
|
||||
.background_images = true,
|
||||
.plot = &nsgtk_plotters
|
||||
};
|
||||
|
||||
cookie_manager_redraw(0, 0, r, &ctx);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the window for the cookies tree.
|
||||
*
|
||||
* \return NSERROR_OK on success else appropriate error code on faliure.
|
||||
*/
|
||||
static nserror nsgtk_cookies_init(void)
|
||||
{
|
||||
struct nsgtk_cookie_window *ncwin;
|
||||
nserror res;
|
||||
|
||||
if (cookie_window != NULL) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
res = treeview_init(0);
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ncwin = malloc(sizeof(struct nsgtk_cookie_window));
|
||||
if (ncwin == NULL) {
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
res = nsgtk_builder_new_from_resname("cookies", &ncwin->builder);
|
||||
if (res != NSERROR_OK) {
|
||||
LOG("Cookie 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,
|
||||
"wndCookies"));
|
||||
|
||||
ncwin->core.scrolled = GTK_SCROLLED_WINDOW(
|
||||
gtk_builder_get_object(ncwin->builder, "cookiesScrolled"));
|
||||
|
||||
ncwin->core.drawing_area = GTK_DRAWING_AREA(
|
||||
gtk_builder_get_object(ncwin->builder, "cookiesDrawingArea"));
|
||||
|
||||
/* 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_cookies_init_menu(ncwin);
|
||||
|
||||
ncwin->core.draw = nsgtk_cookies_draw;
|
||||
ncwin->core.key = nsgtk_cookies_key;
|
||||
ncwin->core.mouse = nsgtk_cookies_mouse;
|
||||
|
||||
res = nsgtk_corewindow_init(&ncwin->core);
|
||||
if (res != NSERROR_OK) {
|
||||
free(ncwin);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = cookie_manager_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.
|
||||
*/
|
||||
cookie_window = ncwin;
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/* exported function documented gtk/cookies.h */
|
||||
nserror nsgtk_cookies_present(void)
|
||||
{
|
||||
@ -229,16 +317,29 @@ nserror nsgtk_cookies_present(void)
|
||||
|
||||
res = nsgtk_cookies_init();
|
||||
if (res == NSERROR_OK) {
|
||||
gtk_window_present(wndCookies);
|
||||
gtk_window_present(cookie_window->wnd);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* exported function documented gtk/cookies.h */
|
||||
void nsgtk_cookies_destroy(void)
|
||||
nserror nsgtk_cookies_destroy(void)
|
||||
{
|
||||
/** \todo what about cookie_builder? */
|
||||
if (wndCookies != NULL) {
|
||||
nsgtk_treeview_destroy(cookies_treeview);
|
||||
nserror res;
|
||||
|
||||
if (cookie_window == NULL) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
res = cookie_manager_fini();
|
||||
if (res == NSERROR_OK) {
|
||||
res = nsgtk_corewindow_fini(&cookie_window->core);
|
||||
gtk_widget_destroy(GTK_WIDGET(cookie_window->wnd));
|
||||
g_object_unref(G_OBJECT(cookie_window->builder));
|
||||
free(cookie_window);
|
||||
cookie_window = NULL;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ nserror nsgtk_cookies_present(void);
|
||||
*
|
||||
* \return NSERROR_OK on success else appropriate error code on faliure.
|
||||
*/
|
||||
void nsgtk_cookies_destroy(void);
|
||||
nserror nsgtk_cookies_destroy(void);
|
||||
|
||||
|
||||
#endif /* __NSGTK_COOKIES_H__ */
|
||||
|
@ -434,13 +434,21 @@ static void nsgtk_main(void)
|
||||
|
||||
static void gui_quit(void)
|
||||
{
|
||||
nserror res;
|
||||
|
||||
LOG("Quitting GUI");
|
||||
|
||||
/* Ensure all scaffoldings are destroyed before we go into exit */
|
||||
nsgtk_download_destroy();
|
||||
urldb_save_cookies(nsoption_charp(cookie_jar));
|
||||
urldb_save(nsoption_charp(url_file));
|
||||
nsgtk_cookies_destroy();
|
||||
|
||||
res = nsgtk_cookies_destroy();
|
||||
if (res != NSERROR_OK) {
|
||||
LOG("Error finalising cookie viewer: %s",
|
||||
messages_get_errorcode(res));
|
||||
}
|
||||
|
||||
nsgtk_history_destroy();
|
||||
nsgtk_hotlist_destroy();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user