diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | embed/mozilla/GtkNSSClientAuthDialogs.cpp | 251 | ||||
-rw-r--r-- | embed/mozilla/GtkNSSClientAuthDialogs.h | 32 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 2 | ||||
-rw-r--r-- | embed/mozilla/MozRegisterComponents.cpp | 8 | ||||
-rw-r--r-- | lib/ephy-state.c | 56 | ||||
-rw-r--r-- | lib/ephy-state.h | 4 |
7 files changed, 368 insertions, 1 deletions
@@ -1,3 +1,19 @@ +2003-11-17 Christian Persch <chpe@cvs.gnome.org> + + * embed/mozilla/GtkNSSClientAuthDialogs.cpp: + * embed/mozilla/GtkNSSClientAuthDialogs.h: + * embed/mozilla/Makefile.am: + * embed/mozilla/MozRegisterComponents.cpp: + * lib/ephy-state.c: (ephy_state_add_paned), (expander_activate_cb), + (ephy_state_add_expander): + * lib/ephy-state.h: + + Ported the Crispin's GtkNSSClientAuthDialogs from galeon. + Changes: + - use GtkExpander instead of the CDDB disclosure thingy + - persist state in ephy-state + - assing a mnemonic to expander label. + 2003-11-17 Marco Pesenti Gritti <marco@gnome.org> * embed/mozilla/EphyBrowser.cpp: diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp new file mode 100644 index 000000000..2625af1d6 --- /dev/null +++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp @@ -0,0 +1,251 @@ +/* + * GtkNSSClientAuthDialogs.cpp + * + * Copyright (C) 2003 Crispin Flowerday <gnome@flowerday.cx> + * + * This program 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; either version 2, or (at your option) + * any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_MOZILLA_PSM + +#include "MozillaPrivate.h" + +#include "nsIServiceManager.h" +#include "nsIInterfaceRequestor.h" +#include "nsIInterfaceRequestorUtils.h" + +#include <gtk/gtkdialog.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkstock.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> +#include <gtk/gtktextbuffer.h> +#include <gtk/gtktextview.h> +#include <gtk/gtkprogressbar.h> +#include <gtk/gtkoptionmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkscrolledwindow.h> +#include <gtk/gtktogglebutton.h> +#include <gtk/gtkexpander.h> +#include <glib/gi18n.h> + +#include "GtkNSSClientAuthDialogs.h" + +#include "ephy-state.h" + +GtkNSSClientAuthDialogs::GtkNSSClientAuthDialogs() +{ +} + + +GtkNSSClientAuthDialogs::~GtkNSSClientAuthDialogs() +{ +} + +NS_IMPL_THREADSAFE_ISUPPORTS1 (GtkNSSClientAuthDialogs, + nsIClientAuthDialogs) + +/** + * Indent a widget according the HIG + * + * @returns: The new indented widget + */ +static GtkWidget* +higgy_indent_widget (GtkWidget *widget) +{ + GtkWidget *hbox; + GtkWidget *label; + + hbox = gtk_hbox_new (FALSE, 6); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, TRUE, 6); + gtk_widget_show (label); + + gtk_box_pack_start (GTK_BOX(hbox), widget, TRUE, TRUE, 0); + + return hbox; +} + + +static void +option_menu_changed_cb (GtkOptionMenu *optionmenu, GtkTextView *textview) +{ + GtkWidget *menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (optionmenu));; + GtkWidget *item = gtk_menu_get_active (GTK_MENU (menu)); + GtkTextBuffer *buffer = gtk_text_view_get_buffer (textview); + PRUnichar *details; + + if (item == 0) + { + gtk_text_buffer_set_text (buffer, "", -1); + return; + } + + details = (PRUnichar*)g_object_get_data (G_OBJECT (item), "details"); + g_return_if_fail (details); + + const nsACString &certnick = NS_ConvertUCS2toUTF8(details); + gtk_text_buffer_set_text (buffer, PromiseFlatCString(certnick).get(), -1); +} + +NS_IMETHODIMP +GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, + const PRUnichar *cn, + const PRUnichar *organization, + const PRUnichar *issuer, + const PRUnichar **certNickList, + const PRUnichar **certDetailsList, + PRUint32 count, PRInt32 *selectedIndex, + PRBool *canceled) +{ + GtkWidget *dialog, *label, *vbox, *optionmenu, *textview, *menu; + GtkWidget *details, *expander, *hbox, *image; + char *msg, *tt_cn, *markup_text; + PRUint32 i; + gboolean showDetails; + + nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); + GtkWidget *gparent = MozillaFindGtkParent (parent); + + dialog = gtk_dialog_new_with_buttons ("", + GTK_WINDOW (gparent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + _("_Select Certificate"), + GTK_RESPONSE_OK, + NULL); + + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX(GTK_DIALOG (dialog)->action_area), 6); + gtk_box_set_spacing (GTK_BOX(GTK_DIALOG (dialog)->vbox), 12); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, + GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_widget_show (image); + + vbox = gtk_vbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + gtk_widget_show (vbox); + + label = gtk_label_new (NULL); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_selectable (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + + + const nsACString &utf8_cn = NS_ConvertUCS2toUTF8(cn); + tt_cn = g_strdup_printf (_("\"<tt>%s</tt>\""), + PromiseFlatCString(utf8_cn).get()); + + msg = g_strdup_printf (_("Choose a certificate to present as identification to %s."), + tt_cn); + markup_text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", + _("Select a certificate to identify yourself."), + msg); + gtk_label_set_markup (GTK_LABEL (label), markup_text); + g_free (msg); + g_free (tt_cn); + g_free (markup_text); + + /* Create and populate the option menu */ + optionmenu = gtk_option_menu_new (); + menu = gtk_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); + gtk_box_pack_start (GTK_BOX (vbox), optionmenu, FALSE, TRUE, 0); + gtk_widget_show (menu); + gtk_widget_show (optionmenu); + + for (i = 0 ; i < count ; i++) + { + const nsACString &certnick = NS_ConvertUCS2toUTF8(certNickList[i]); + GtkWidget *item = gtk_menu_item_new_with_label (PromiseFlatCString(certnick).get()); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_object_set_data (G_OBJECT (item), "details", (void*)certDetailsList[i]); + gtk_widget_show (item); + } + + + expander = gtk_expander_new_with_mnemonic (_("Certificate _Details")); + ephy_state_add_expander (GTK_WIDGET (expander), "client-auth-dialog-expander", FALSE); + + gtk_widget_show (expander); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), expander, FALSE, FALSE, 0); + + /* Create the text box */ + textview = gtk_text_view_new (); + gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD); + gtk_widget_set_size_request (GTK_WIDGET (textview), -1, 100); + gtk_widget_show (textview); + + details = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (details), GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (details), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (details), textview); + gtk_widget_show (details); + + details = higgy_indent_widget (details); + gtk_container_set_border_width (GTK_CONTAINER (details), 5); + gtk_widget_show (details); + + gtk_container_add (GTK_CONTAINER (expander), details); + + g_signal_connect (G_OBJECT (optionmenu), "changed", + G_CALLBACK (option_menu_changed_cb), + textview); + + gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 0); + + /* run the dialog */ + int res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_OK) + { + *canceled = PR_FALSE; + *selectedIndex = gtk_option_menu_get_history (GTK_OPTION_MENU (optionmenu)); + } + else + { + *canceled = PR_TRUE; + } + + gtk_widget_destroy (dialog); + return NS_OK; +} + + + +#endif diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.h b/embed/mozilla/GtkNSSClientAuthDialogs.h new file mode 100644 index 000000000..5b0187c26 --- /dev/null +++ b/embed/mozilla/GtkNSSClientAuthDialogs.h @@ -0,0 +1,32 @@ +/* + * GtkNSSClientAuthDialogs.h + * + * Copyright (C) 2003 Crispin Flowerday <gnome@flowerday.cx> + * Available under the terms of the GNU General Public License version 2. + */ + +#ifndef GTKNSSCLIENTAUTHDIALOGS_H +#define GTKNSSCLIENTAUTHDIALOGS_H 1 + +#include <nsError.h> +#include "nsIClientAuthDialogs.h" + +// 55b3837e-dbde-4c24-9247-f328e3012485 +#define GTK_NSSCLIENTAUTHDIALOGS_CID \ + {0x55b3837e, 0xdbde, 0x4c24, {0x92, 0x47, 0xf3, 0x28, 0xe3, 0x01, 0x24, 0x85}} + +#define GTK_NSSCLIENTAUTHDIALOGS_CLASSNAME "Gtk NSS Client Auth Dialogs" + +class GtkNSSClientAuthDialogs +: public nsIClientAuthDialogs +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSICLIENTAUTHDIALOGS + + GtkNSSClientAuthDialogs(); + virtual ~GtkNSSClientAuthDialogs(); +}; + + +#endif /* GTKNSSCLIENTAUTHDIALOGS_H */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index ab823f6ca..2b58a2df5 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -71,6 +71,8 @@ libephymozillaembed_la_SOURCES = \ FilePicker.h \ GlobalHistory.cpp \ GlobalHistory.h \ + GtkNSSClientAuthDialogs.cpp \ + GtkNSSClientAuthDialogs.h \ GtkNSSDialogs.cpp \ GtkNSSDialogs.h \ GtkNSSKeyPairDialogs.cpp \ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index 6718d3056..b359a7b9f 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -30,6 +30,7 @@ #include "EphyAboutRedirector.h" #ifdef HAVE_MOZILLA_PSM +#include "GtkNSSClientAuthDialogs.h" #include "GtkNSSDialogs.h" #include "GtkNSSKeyPairDialogs.h" #endif @@ -53,6 +54,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(GNewsProtocolHandler) NS_GENERIC_FACTORY_CONSTRUCTOR(GExternalProtocolService) #ifdef HAVE_MOZILLA_PSM +NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSClientAuthDialogs) NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSDialogs) NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSKeyPairDialogs) #endif @@ -78,6 +80,12 @@ static const nsModuleComponentInfo sAppComps[] = { }, #ifdef HAVE_MOZILLA_PSM { + GTK_NSSCLIENTAUTHDIALOGS_CLASSNAME, + GTK_NSSCLIENTAUTHDIALOGS_CID, + NS_CLIENTAUTHDIALOGS_CONTRACTID, + GtkNSSClientAuthDialogsConstructor + }, + { GTK_NSSDIALOGS_CLASSNAME, GTK_NSSDIALOGS_CID, NS_BADCERTLISTENER_CONTRACTID, diff --git a/lib/ephy-state.c b/lib/ephy-state.c index 33edb87a5..fb214775f 100644 --- a/lib/ephy-state.c +++ b/lib/ephy-state.c @@ -27,6 +27,7 @@ #include <string.h> #include <gtk/gtkwindow.h> #include <gtk/gtkpaned.h> +#include <gtk/gtkexpander.h> #define EPHY_STATES_XML_FILE "states.xml" #define EPHY_STATES_XML_ROOT "ephy_states" @@ -41,7 +42,8 @@ enum EPHY_NODE_STATE_PROP_POSITION_X = 6, EPHY_NODE_STATE_PROP_POSITION_Y = 7, EPHY_NODE_STATE_PROP_SIZE = 8, - EPHY_NODE_STATE_PROP_POSITION = 9 + EPHY_NODE_STATE_PROP_POSITION = 9, + EPHY_NODE_STATE_PROP_EXPANDED = 10 }; static EphyNode *states = NULL; @@ -433,6 +435,58 @@ ephy_state_add_paned (GtkWidget *paned, G_CALLBACK (paned_size_allocate_cb), node); } +static void +expander_activate_cb (GtkExpander *expander, + EphyNode *node) +{ + GValue value = { 0, }; + + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, gtk_expander_get_expanded (expander)); + ephy_node_set_property (node, EPHY_NODE_STATE_PROP_EXPANDED, &value); + g_value_unset (&value); +} + +void +ephy_state_add_expander (GtkWidget *expander, + const char *name, + gboolean default_state) +{ + EphyNode *node; + gboolean expanded; + + ensure_states (); + + node = find_by_name (name); + if (node == NULL) + { + GValue value = { 0, }; + + node = ephy_node_new (states_db); + ephy_node_add_child (states, node); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, name); + ephy_node_set_property (node, EPHY_NODE_STATE_PROP_NAME, + &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, default_state); + ephy_node_set_property + (node, EPHY_NODE_STATE_PROP_EXPANDED, &value); + g_value_unset (&value); + } + + expanded = ephy_node_get_property_boolean + (node, EPHY_NODE_STATE_PROP_EXPANDED); + + gtk_expander_set_expanded (GTK_EXPANDER (expander), expanded); + + g_signal_connect (expander, "activate", + G_CALLBACK (expander_activate_cb), node); +} + void ephy_state_save (void) { diff --git a/lib/ephy-state.h b/lib/ephy-state.h index 55cd4fa5a..bc01e2eea 100644 --- a/lib/ephy-state.h +++ b/lib/ephy-state.h @@ -43,6 +43,10 @@ void ephy_state_add_paned (GtkWidget *paned, const char *name, int default_width); +void ephy_state_add_expander (GtkWidget *expander, + const char *name, + gboolean default_state); + void ephy_state_save (void); G_END_DECLS |