Implement 401 login window in nsgtk

svn path=/trunk/netsurf/; revision=2817
This commit is contained in:
Rob Kendrick 2006-08-06 22:29:58 +00:00
parent 89f760a3e7
commit 5e1f0332ad
5 changed files with 187 additions and 24 deletions

View File

@ -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) {}

View File

@ -11,5 +11,6 @@
extern bool gui_in_multitask;
extern GladeXML *gladeWindows;
extern char *glade_file_location;
extern char *options_file_location;

163
gtk/gtk_login.c Normal file
View File

@ -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 <rjek@rjek.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#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);
}

View File

@ -2557,9 +2557,8 @@ Fantasy</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton2">
<widget class="GtkButton" id="buttonLoginCan">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
@ -2570,15 +2569,16 @@ Fantasy</property>
</child>
<child>
<widget class="GtkButton" id="okbutton2">
<widget class="GtkButton" id="buttonLoginOK">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
<signal name="clicked" handler="nsgtk_401login_apply" last_modification_time="Sun, 06 Aug 2006 20:48:22 GMT"/>
<signal name="clicked" handler="gtk_widget_hide" last_modification_time="Sun, 06 Aug 2006 20:48:32 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment14">
@ -2658,6 +2658,7 @@ Fantasy</property>
<child>
<widget class="GtkHBox" id="hbox12">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
@ -2668,8 +2669,8 @@ Fantasy</property>
<property name="icon_size">6</property>
<property name="icon_name">gtk-dialog-authentication</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">5</property>
<property name="yalign">0.10000000149</property>
<property name="xpad">12</property>
<property name="ypad">0</property>
</widget>
<packing>
@ -2686,17 +2687,18 @@ Fantasy</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">5</property>
<property name="row_spacing">10</property>
<property name="column_spacing">11</property>
<child>
<widget class="GtkEntry" id="entry2">
<widget class="GtkEntry" id="entryLoginUser">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="text" translatable="yes">sesame</property>
<property name="has_frame">True</property>
<property name="invisible_char">●</property>
<property name="activates_default">False</property>
@ -2711,16 +2713,16 @@ Fantasy</property>
</child>
<child>
<widget class="GtkEntry" id="entry3">
<widget class="GtkEntry" id="entryLoginPass">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="visibility">False</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="text" translatable="yes">opensesame</property>
<property name="has_frame">True</property>
<property name="invisible_char"></property>
<property name="activates_default">False</property>
<property name="invisible_char">*</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
@ -2732,7 +2734,7 @@ Fantasy</property>
</child>
<child>
<widget class="GtkLabel" id="label59">
<widget class="GtkLabel" id="labelLoginRealm">
<property name="visible">True</property>
<property name="label" translatable="yes">my sekr3t area</property>
<property name="use_underline">False</property>
@ -2744,7 +2746,7 @@ Fantasy</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
@ -2867,7 +2869,7 @@ Fantasy</property>
</child>
<child>
<widget class="GtkLabel" id="label58">
<widget class="GtkLabel" id="labelLoginHost">
<property name="visible">True</property>
<property name="label" translatable="yes">moo.yoo.com</property>
<property name="use_underline">False</property>
@ -2879,7 +2881,7 @@ Fantasy</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
@ -2894,7 +2896,7 @@ Fantasy</property>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="padding">1</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>

View File

@ -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