mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-21 03:32:35 +03:00
8ef292b9ca
GTK UI builder resources have till now been exclusively stored on disc requiring netsurf to ship numerous additional resource files. This requires going to disc every time a UI action is performed which can become a lot of unwanted file handling. GLib/GTK has moved towards GResource handling for such resources instead. It now seems that migrating to this style of usage is expected and indeed the only portable way to include pixbufs. This introduces an API to hide the various implementation details of how resources are handled from the rest of the codebase.
136 lines
3.7 KiB
C
136 lines
3.7 KiB
C
/*
|
|
* Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "utils/log.h"
|
|
#include "utils/nsurl.h"
|
|
#include "desktop/tree.h"
|
|
#include "desktop/sslcert_viewer.h"
|
|
|
|
#include "gtk/treeview.h"
|
|
#include "gtk/scaffolding.h"
|
|
#include "gtk/resources.h"
|
|
#include "gtk/ssl_cert.h"
|
|
|
|
|
|
static void nsgtk_ssl_accept(GtkButton *w, gpointer data)
|
|
{
|
|
void **session = data;
|
|
GtkBuilder *x = session[0];
|
|
struct nsgtk_treeview *wnd = session[1];
|
|
struct sslcert_session_data *ssl_data = session[2];
|
|
|
|
sslcert_viewer_accept(ssl_data);
|
|
|
|
nsgtk_treeview_destroy(wnd);
|
|
g_object_unref(G_OBJECT(x));
|
|
free(session);
|
|
}
|
|
|
|
static void nsgtk_ssl_reject(GtkWidget *w, gpointer data)
|
|
{
|
|
void **session = data;
|
|
GtkBuilder *x = session[0];
|
|
struct nsgtk_treeview *wnd = session[1];
|
|
struct sslcert_session_data *ssl_data = session[2];
|
|
|
|
sslcert_viewer_reject(ssl_data);
|
|
|
|
nsgtk_treeview_destroy(wnd);
|
|
g_object_unref(G_OBJECT(x));
|
|
free(session);
|
|
}
|
|
|
|
static gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
|
|
{
|
|
nsgtk_ssl_reject(w, data);
|
|
return FALSE;
|
|
}
|
|
|
|
void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
|
|
unsigned long num, nserror (*cb)(bool proceed, void *pw),
|
|
void *cbpw)
|
|
{
|
|
static struct nsgtk_treeview *ssl_window;
|
|
struct sslcert_session_data *data;
|
|
GtkButton *accept, *reject;
|
|
void **session;
|
|
GtkDialog *dlg;
|
|
GtkScrolledWindow *scrolled;
|
|
GtkDrawingArea *drawing_area;
|
|
GtkBuilder *builder;
|
|
GtkWindow *gtk_parent;
|
|
nserror res;
|
|
|
|
/* state while dlg is open */
|
|
session = calloc(sizeof(void *), 3);
|
|
if (session == NULL) {
|
|
return;
|
|
}
|
|
|
|
res = nsgtk_builder_new_from_resname("ssl", &builder);
|
|
if (res != NSERROR_OK) {
|
|
LOG("SSL UI builder init failed");
|
|
free(session);
|
|
cb(false, cbpw);
|
|
return;
|
|
}
|
|
|
|
gtk_builder_connect_signals(builder, NULL);
|
|
|
|
sslcert_viewer_create_session_data(num, url, cb, cbpw, certs, &data);
|
|
ssl_current_session = data;
|
|
|
|
dlg = GTK_DIALOG(gtk_builder_get_object(builder, "wndSSLProblem"));
|
|
|
|
/* set parent for transient dialog */
|
|
gtk_parent = nsgtk_scaffolding_window(nsgtk_current_scaffolding());
|
|
gtk_window_set_transient_for(GTK_WINDOW(dlg), gtk_parent);
|
|
|
|
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(builder, "SSLScrolled"));
|
|
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "SSLDrawingArea"));
|
|
|
|
ssl_window = nsgtk_treeview_create(TREE_SSLCERT, GTK_WINDOW(dlg), scrolled,
|
|
drawing_area);
|
|
|
|
if (ssl_window == NULL) {
|
|
free(session);
|
|
g_object_unref(G_OBJECT(dlg));
|
|
return;
|
|
}
|
|
|
|
accept = GTK_BUTTON(gtk_builder_get_object(builder, "sslaccept"));
|
|
reject = GTK_BUTTON(gtk_builder_get_object(builder, "sslreject"));
|
|
|
|
session[0] = builder;
|
|
session[1] = ssl_window;
|
|
session[2] = data;
|
|
|
|
#define CONNECT(obj, sig, callback, ptr) \
|
|
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
|
|
|
|
CONNECT(accept, "clicked", nsgtk_ssl_accept, session);
|
|
CONNECT(reject, "clicked", nsgtk_ssl_reject, session);
|
|
CONNECT(dlg, "delete_event", G_CALLBACK(nsgtk_ssl_delete_event),
|
|
(gpointer)session);
|
|
|
|
gtk_widget_show(GTK_WIDGET(dlg));
|
|
}
|