From 5e1f0332add2458c4eb142bff4becdebe197325a Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 6 Aug 2006 22:29:58 +0000 Subject: Implement 401 login window in nsgtk svn path=/trunk/netsurf/; revision=2817 --- gtk/gtk_gui.c | 3 - gtk/gtk_gui.h | 1 + gtk/gtk_login.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gtk/netsurf.glade | 42 +++++++------- makefile | 2 +- 5 files changed, 187 insertions(+), 24 deletions(-) create mode 100644 gtk/gtk_login.c diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index 6a44c54db..37fcea4e9 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -303,9 +303,6 @@ void hotlist_visited(struct content *content) { } - -void gui_401login_open(struct browser_window *bw, struct content *c, - const char *realm) {} void gui_cert_verify(struct browser_window *bw, struct content *c, const struct ssl_cert_info *certs, unsigned long num) {} diff --git a/gtk/gtk_gui.h b/gtk/gtk_gui.h index 91c2bb3eb..3b8850445 100644 --- a/gtk/gtk_gui.h +++ b/gtk/gtk_gui.h @@ -11,5 +11,6 @@ extern bool gui_in_multitask; extern GladeXML *gladeWindows; +extern char *glade_file_location; extern char *options_file_location; diff --git a/gtk/gtk_login.c b/gtk/gtk_login.c new file mode 100644 index 000000000..9400a0699 --- /dev/null +++ b/gtk/gtk_login.c @@ -0,0 +1,163 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Rob Kendrick + */ + +#include +#include +#include +#include +#include +#include +#include "netsurf/utils/log.h" +#include "netsurf/gtk/gtk_gui.h" +#include "netsurf/content/content.h" +#include "netsurf/content/urldb.h" +#include "netsurf/desktop/browser.h" +#include "netsurf/desktop/401login.h" +#include "netsurf/desktop/gui.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/url.h" +#include "netsurf/utils/utils.h" + +struct session_401 { + char *url; /**< URL being fetched */ + char *host; /**< Host for user display */ + char *realm; /**< Authentication realm */ + struct browser_window *bw; /**< Browser window handle */ + GladeXML *x; /**< Our glade windows */ + GtkWindow *wnd; /**< The login window itself */ + GtkEntry *user; /**< Widget with username */ + GtkEntry *pass; /**< Widget with password */ +}; + +static void create_login_window(struct browser_window *bw, const char *host, + const char *realm, const char *fetchurl); +static void destroy_login_window(struct session_401 *session); +static void nsgtk_login_next(GtkWidget *w, gpointer data); +static void nsgtk_login_ok_clicked(GtkButton *w, gpointer data); +static void nsgtk_login_cancel_clicked(GtkButton *w, gpointer data); + +void gui_401login_open(struct browser_window *bw, struct content *c, + const char *realm) +{ + char *host; + url_func_result res; + + res = url_host(c->url, &host); + assert(res == URL_FUNC_OK); + + create_login_window(bw, host, realm, c->url); + + free(host); +} + +void create_login_window(struct browser_window *bw, const char *host, + const char *realm, const char *fetchurl) +{ + struct session_401 *session; + + /* create a new instance of the login window, and get handles to all + * the widgets we're interested in. + */ + + GladeXML *x = glade_xml_new(glade_file_location, NULL, NULL); + GtkWindow *wnd = GTK_WINDOW(glade_xml_get_widget(x, "wndLogin")); + GtkLabel *lhost, *lrealm; + GtkEntry *euser, *epass; + GtkButton *bok, *bcan; + + lhost = GTK_LABEL(glade_xml_get_widget(x, "labelLoginHost")); + lrealm = GTK_LABEL(glade_xml_get_widget(x, "labelLoginRealm")); + euser = GTK_ENTRY(glade_xml_get_widget(x, "entryLoginUser")); + epass = GTK_ENTRY(glade_xml_get_widget(x, "entryLoginPass")); + bok = GTK_BUTTON(glade_xml_get_widget(x, "buttonLoginOK")); + bcan = GTK_BUTTON(glade_xml_get_widget(x, "buttonLoginCan")); + + /* create and fill in our session structure */ + + session = calloc(1, sizeof(struct session_401)); + session->url = strdup(fetchurl); + session->host = strdup(host); + session->realm = strdup(realm ? realm : "Secure Area"); + session->bw = bw; + session->x = x; + session->wnd = wnd; + session->user = euser; + session->pass = epass; + + /* fill in our new login window */ + + gtk_label_set_text(GTK_LABEL(lhost), host); + gtk_label_set_text(lrealm, realm); + gtk_entry_set_text(euser, ""); + gtk_entry_set_text(epass, ""); + + /* attach signal handlers to the Login and Cancel buttons in our new + * window to call functions in this file to process the login + */ + g_signal_connect(G_OBJECT(bok), "clicked", + G_CALLBACK(nsgtk_login_ok_clicked), (gpointer)session); + g_signal_connect(G_OBJECT(bcan), "clicked", + G_CALLBACK(nsgtk_login_cancel_clicked), + (gpointer)session); + + /* attach signal handlers to the entry boxes such that pressing + * enter in one progresses the focus onto the next widget. + */ + + g_signal_connect(G_OBJECT(euser), "activate", + G_CALLBACK(nsgtk_login_next), (gpointer)epass); + g_signal_connect(G_OBJECT(epass), "activate", + G_CALLBACK(nsgtk_login_next), (gpointer)bok); + + /* make sure the username entry box currently has the focus */ + gtk_widget_grab_focus(GTK_WIDGET(euser)); + + /* finally, show the window */ + gtk_widget_show(GTK_WIDGET(wnd)); +} + +void destroy_login_window(struct session_401 *session) +{ + free(session->url); + free(session->host); + free(session->realm); + gtk_widget_destroy(GTK_WIDGET(session->wnd)); + g_object_unref(G_OBJECT(session->x)); + free(session); +} + +void nsgtk_login_next(GtkWidget *w, gpointer data) +{ + gtk_widget_grab_focus(GTK_WIDGET(data)); +} + +void nsgtk_login_ok_clicked(GtkButton *w, gpointer data) +{ + /* close the window and destroy it, having continued the fetch + * assoicated with it. + */ + + struct session_401 *session = (struct session_401 *)data; + const gchar *user = gtk_entry_get_text(session->user); + const gchar *pass = gtk_entry_get_text(session->pass); + char *auth; + + auth = malloc(strlen(user) + strlen(pass) + 2); + sprintf(auth, "%s:%s", user, pass); + urldb_set_auth_details(session->url, session->realm, auth); + free(auth); + + browser_window_go(session->bw, session->url, 0, true); + + destroy_login_window(session); +} + +void nsgtk_login_cancel_clicked(GtkButton *w, gpointer data) +{ + /* just close and destroy the window */ + destroy_login_window((struct session_401 *)data); +} diff --git a/gtk/netsurf.glade b/gtk/netsurf.glade index 921bdd9f4..697b282e6 100644 --- a/gtk/netsurf.glade +++ b/gtk/netsurf.glade @@ -2557,9 +2557,8 @@ Fantasy GTK_BUTTONBOX_END - + True - True True gtk-cancel True @@ -2570,15 +2569,16 @@ Fantasy - + True True True True - True GTK_RELIEF_NORMAL True -5 + + @@ -2658,6 +2658,7 @@ Fantasy + 3 True False 0 @@ -2668,8 +2669,8 @@ Fantasy 6 gtk-dialog-authentication 0.5 - 0 - 5 + 0.10000000149 + 12 0 @@ -2686,17 +2687,18 @@ Fantasy 4 2 False - 0 - 5 + 10 + 11 - + True True + True True True 0 - + sesame True False @@ -2711,16 +2713,16 @@ Fantasy - + True True True - True + False 0 - + opensesame True - - False + * + True 1 @@ -2732,7 +2734,7 @@ Fantasy - + True my sekr3t area False @@ -2744,7 +2746,7 @@ Fantasy 0.5 0 0 - PANGO_ELLIPSIZE_MIDDLE + PANGO_ELLIPSIZE_NONE -1 False 0 @@ -2867,7 +2869,7 @@ Fantasy - + True moo.yoo.com False @@ -2879,7 +2881,7 @@ Fantasy 0.5 0 0 - PANGO_ELLIPSIZE_MIDDLE + PANGO_ELLIPSIZE_NONE -1 False 0 @@ -2894,7 +2896,7 @@ Fantasy - 0 + 1 True True diff --git a/makefile b/makefile index 4e7203e9f..6e05d0aef 100644 --- a/makefile +++ b/makefile @@ -69,7 +69,7 @@ OBJECTS_GTK += browser.o history_core.o netsurf.o selection.o textinput.o \ OBJECTS_GTK += font_pango.o gtk_bitmap.o gtk_gui.o \ gtk_schedule.o gtk_thumbnail.o gtk_options.o \ gtk_plotters.o gtk_treeview.o gtk_window.o \ - gtk_completion.o # gtk/ + gtk_completion.o gtk_login.o # gtk/ OBJDIR_RISCOS = arm-riscos-aof -- cgit v1.2.3