Re: GtkFilesystemGnomeVFS and authentication



On Tue, 2004-03-16 at 21:37, Federico Mena Quintero wrote:
> Hi, Alex,
> 
> These are some disconnected thoughts on GtkFileSystemGnomeVFS and
> authentication.
> 
> * The file system backend does nothing with respect to authentication
> right now.  Should we blindly call gnome_authentication_manager_init()
> when the module is loaded, or something like that?

After some research and talk with owen I've ended up with the patch
below. It adds some new private API that could potentially be useful for
other apps, but for now its not exposed.

It seems to work.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeui/ChangeLog,v
retrieving revision 1.402
diff -u -p -r1.402 ChangeLog
--- ChangeLog	15 Mar 2004 22:56:05 -0000	1.402
+++ ChangeLog	18 Mar 2004 16:02:54 -0000
@@ -1,3 +1,11 @@
+2004-03-18  Alexander Larsson  <alexl redhat com>
+
+	* libgnomeui/gnome-authentication-manager.c (present_authentication_dialog_nonblocking):
+	Make auth dialog modal if there is a grab.
+
+	* file-chooser/gtkfilesystemgnomevfs.c:
+	Use the new auth push/pop api
+	
 2004-03-15  Anders Carlsson  <andersca gnome org>
 
 	* configure.in: Release 2.5.92
Index: file-chooser/gtkfilesystemgnomevfs.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/file-chooser/gtkfilesystemgnomevfs.c,v
retrieving revision 1.35
diff -u -p -r1.35 gtkfilesystemgnomevfs.c
--- file-chooser/gtkfilesystemgnomevfs.c	15 Mar 2004 05:36:44 -0000	1.35
+++ file-chooser/gtkfilesystemgnomevfs.c	18 Mar 2004 16:02:54 -0000
@@ -525,12 +525,14 @@ load_dir (GtkFileFolderGnomeVFS *folder_
 
   g_hash_table_foreach_remove (folder_vfs->children,
 			       remove_all, NULL);
+  gnome_authentication_manager_push_async ();
   gnome_vfs_async_load_directory (&folder_vfs->async_handle,
 				  folder_vfs->uri,
 				  get_options (folder_vfs->types),
 				  ITEMS_PER_NOTIFICATION,
 				  GNOME_VFS_PRIORITY_DEFAULT,
 				  directory_load_callback, folder_vfs);
+  gnome_authentication_manager_pop_async ();
 }
 
 static char *
@@ -585,10 +587,12 @@ gtk_file_system_gnome_vfs_get_folder (Gt
 
   folder_vfs = g_object_new (GTK_TYPE_FILE_FOLDER_GNOME_VFS, NULL);
 
+  gnome_authentication_manager_push_sync ();
   result = gnome_vfs_monitor_add (&monitor,
 				  uri,
 				  GNOME_VFS_MONITOR_DIRECTORY,
 				  monitor_callback, folder_vfs);
+  gnome_authentication_manager_pop_sync ();
   if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_NOT_SUPPORTED)
     {
       g_free (uri);
@@ -627,9 +631,11 @@ gtk_file_system_gnome_vfs_get_folder (Gt
 	  FolderChild *child;
 
 	  vfs_info = gnome_vfs_file_info_new ();
+	  gnome_authentication_manager_push_sync ();
 	  result = gnome_vfs_get_file_info (folder_vfs->uri,
 					    vfs_info,
 					    get_options (parent_folder->types));
+	  gnome_authentication_manager_pop_sync ();
 	  if (result != GNOME_VFS_OK)
 	    {
 	      gnome_vfs_file_info_unref (vfs_info);
@@ -661,10 +667,12 @@ gtk_file_system_gnome_vfs_create_folder 
   const gchar *uri = gtk_file_path_get_string (path);
   GnomeVFSResult result;
 
+  gnome_authentication_manager_push_sync ();
   result = gnome_vfs_make_directory (uri,
 				     GNOME_VFS_PERM_USER_ALL |
 				     GNOME_VFS_PERM_GROUP_ALL |
 				     GNOME_VFS_PERM_OTHER_READ);
+  gnome_authentication_manager_pop_sync ();
 
   if (result != GNOME_VFS_OK)
     {
@@ -764,7 +772,9 @@ gtk_file_system_gnome_vfs_volume_mount (
 
       closure.system_vfs = system_vfs;
       closure.loop = g_main_loop_new (NULL, FALSE);
+      gnome_authentication_manager_push_sync ();
       gnome_vfs_drive_mount (GNOME_VFS_DRIVE (volume), volume_mount_cb, &closure);
+      gnome_authentication_manager_pop_sync ();
 
       GDK_THREADS_LEAVE ();
       g_main_loop_run (closure.loop);
@@ -1290,7 +1300,9 @@ get_vfs_info (GtkFileSystem     *file_sy
     {
       info = gnome_vfs_file_info_new ();
       uri = gtk_file_path_get_string (path);
+      gnome_authentication_manager_push_sync ();
       gnome_vfs_get_file_info (uri, info, get_options (types));
+      gnome_authentication_manager_pop_sync ();
     }
   
   gtk_file_path_free (parent_path);
@@ -1794,7 +1806,9 @@ lookup_vfs_info_in_folder (GtkFileFolder
       GnomeVFSResult result;
       
       vfs_info = gnome_vfs_file_info_new ();
+      gnome_authentication_manager_push_sync ();
       result = gnome_vfs_get_file_info (uri, vfs_info, get_options (folder_vfs->types));
+      gnome_authentication_manager_pop_sync ();
       
       if (result != GNOME_VFS_OK)
 	set_vfs_error (result, uri, error);
@@ -1841,7 +1855,9 @@ gtk_file_folder_gnome_vfs_get_info (GtkF
       gnome_vfs_uri_unref (vfs_uri);
 
       info = gnome_vfs_file_info_new ();
+      gnome_authentication_manager_push_sync ();
       result = gnome_vfs_get_file_info (folder_vfs->uri, info, get_options (GTK_FILE_INFO_ALL));
+      gnome_authentication_manager_pop_sync ();
       if (result != GNOME_VFS_OK)
 	{
 	  file_info = NULL;
@@ -2120,7 +2136,9 @@ monitor_callback (GnomeVFSMonitorHandle 
 	GnomeVFSFileInfo *vfs_info;
 
 	vfs_info = gnome_vfs_file_info_new ();
+	gnome_authentication_manager_push_sync ();
 	result = gnome_vfs_get_file_info (info_uri, vfs_info, get_options (folder_vfs->types));
+	gnome_authentication_manager_pop_sync ();
 
 	if (result == GNOME_VFS_OK)
 	  {
Index: libgnomeui/Makefile.am
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/Makefile.am,v
retrieving revision 1.338
diff -u -p -r1.338 Makefile.am
--- libgnomeui/Makefile.am	7 Feb 2004 19:46:29 -0000	1.338
+++ libgnomeui/Makefile.am	18 Mar 2004 16:02:54 -0000
@@ -91,6 +91,7 @@ libgnomeui_2_la_SOURCES = \
 	gnome-password-dialog.h         \
 	gnome-authentication-manager.c  \
 	gnome-authentication-manager.h  \
+	gnome-authentication-manager-private.h  \
 	gnome-client.c
 
 ## this lists all the non-generated headers
Index: libgnomeui/gnome-authentication-manager-private.h
===================================================================
RCS file: libgnomeui/gnome-authentication-manager-private.h
diff -N libgnomeui/gnome-authentication-manager-private.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libgnomeui/gnome-authentication-manager-private.h	18 Mar 2004 16:02:54 -0000
@@ -0,0 +1,39 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* gnome-authn-manager-private.h - machinary for handling authentication to URI's
+
+   Copyright (C) 2004 Red Hat, Inc.
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+
+   Authors: Alexander Larsson <alexl redhat com>
+*/
+
+#ifndef GNOME_AUTHENTICATION_MANAGER_PRIVATE_H
+#define GNOME_AUTHENTICATION_MANAGER_PRIVATE_H
+
+/* TODO: These are just private to avoid breaking code freeze.
+ * they should probably be exported later, as they could be
+ * useful to others
+ */
+   
+void 	gnome_authentication_manager_push_sync (void);
+void 	gnome_authentication_manager_pop_sync (void);
+
+void 	gnome_authentication_manager_push_async (void);
+void 	gnome_authentication_manager_pop_async (void);
+
+#endif /* GNOME_AUTHENTICATION_MANAGER_PRIVATE_H */
Index: libgnomeui/gnome-authentication-manager.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-authentication-manager.c,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-authentication-manager.c
--- libgnomeui/gnome-authentication-manager.c	8 Jan 2004 18:33:58 -0000	1.4
+++ libgnomeui/gnome-authentication-manager.c	18 Mar 2004 16:02:54 -0000
@@ -34,6 +34,7 @@
 
 #include <config.h>
 #include "gnome-authentication-manager.h"
+#include "gnome-authentication-manager-private.h"
 
 #include <gnome.h>
 #include <libgnome/gnome-i18n.h>
@@ -154,11 +155,23 @@ static gint /* GtkFunction */
 present_authentication_dialog_nonblocking (CallbackInfo *info)
 {
 	GnomePasswordDialog *dialog;
+	GtkWidget *toplevel;
 
 	g_return_val_if_fail (info != NULL, 0);
 
 	dialog = construct_password_dialog (info->is_proxy_authentication, info->in_args);
 
+	toplevel = gtk_widget_get_toplevel (gtk_grab_get_current ());
+	if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel)) {
+		/* There is a modal window, so we need to be modal too in order to
+		 * get input. We set the other modal dialog as parent, which
+		 * hopefully gives us better window management.
+		 */
+		gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+	} else {
+		gtk_window_set_modal (GTK_WINDOW (dialog), FALSE);
+	}
+
 	gtk_window_set_modal (GTK_WINDOW (dialog), FALSE);
 
 	g_signal_connect (dialog, "response", 
@@ -368,12 +381,22 @@ static gint /* GtkFunction */
 present_full_authentication_dialog_nonblocking (FullCallbackInfo *info)
 {
 	GnomePasswordDialog *dialog;
+	GtkWidget *toplevel;
 
 	g_return_val_if_fail (info != NULL, 0);
 
 	dialog = construct_full_password_dialog (info->in_args);
 
-	gtk_window_set_modal (GTK_WINDOW (dialog), FALSE);
+	toplevel = gtk_widget_get_toplevel (gtk_grab_get_current ());
+	if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel)) {
+		/* There is a modal window, so we need to be modal too in order to
+		 * get input. We set the other modal dialog as parent, which
+		 * hopefully gives us better window management.
+		 */
+		gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+	} else {
+		gtk_window_set_modal (GTK_WINDOW (dialog), FALSE);
+	}
 
 	g_signal_connect (dialog, "response", 
 			  G_CALLBACK (full_authentication_dialog_button_clicked), info);
@@ -730,3 +753,77 @@ gnome_authentication_manager_init (void)
 					       NULL);
 
 }
+
+void
+gnome_authentication_manager_push_async (void)
+{
+	gnome_vfs_async_module_callback_push (GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION,
+					      vfs_async_authentication_callback, 
+					      GINT_TO_POINTER (0),
+					      NULL);
+	gnome_vfs_async_module_callback_push (GNOME_VFS_MODULE_CALLBACK_HTTP_PROXY_AUTHENTICATION, 
+					      vfs_async_authentication_callback, 
+					      GINT_TO_POINTER (1),
+					      NULL);
+	
+	gnome_vfs_async_module_callback_push (GNOME_VFS_MODULE_CALLBACK_FILL_AUTHENTICATION,
+					      vfs_async_fill_authentication_callback, 
+					      GINT_TO_POINTER (0),
+					      NULL);
+	gnome_vfs_async_module_callback_push (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION,
+					      vfs_async_full_authentication_callback, 
+					      GINT_TO_POINTER (0),
+					      NULL);
+	gnome_vfs_async_module_callback_push (GNOME_VFS_MODULE_CALLBACK_SAVE_AUTHENTICATION,
+					      vfs_async_save_authentication_callback, 
+					      GINT_TO_POINTER (0),
+					      NULL);
+}
+
+void
+gnome_authentication_manager_pop_async (void)
+{
+	gnome_vfs_async_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION);
+	gnome_vfs_async_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_HTTP_PROXY_AUTHENTICATION);
+	gnome_vfs_async_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_FILL_AUTHENTICATION);
+	gnome_vfs_async_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION);
+	gnome_vfs_async_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_SAVE_AUTHENTICATION);
+}
+
+void
+gnome_authentication_manager_push_sync (void)
+{
+	
+	gnome_vfs_module_callback_push (GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION,
+					vfs_authentication_callback, 
+					GINT_TO_POINTER (0),
+					NULL);
+	gnome_vfs_module_callback_push (GNOME_VFS_MODULE_CALLBACK_HTTP_PROXY_AUTHENTICATION, 
+					vfs_authentication_callback, 
+					GINT_TO_POINTER (1),
+					NULL);
+	
+	gnome_vfs_module_callback_push (GNOME_VFS_MODULE_CALLBACK_FILL_AUTHENTICATION,
+					vfs_fill_authentication_callback, 
+					GINT_TO_POINTER (0),
+					NULL);
+	gnome_vfs_module_callback_push (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION,
+					vfs_full_authentication_callback, 
+					GINT_TO_POINTER (0),
+					NULL);
+	gnome_vfs_module_callback_push (GNOME_VFS_MODULE_CALLBACK_SAVE_AUTHENTICATION,
+					vfs_save_authentication_callback, 
+					GINT_TO_POINTER (0),
+					NULL);
+}
+
+void
+gnome_authentication_manager_pop_sync (void)
+{
+	gnome_vfs_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION);
+	gnome_vfs_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_HTTP_PROXY_AUTHENTICATION);
+	gnome_vfs_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_FILL_AUTHENTICATION);
+	gnome_vfs_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION);
+	gnome_vfs_module_callback_pop (GNOME_VFS_MODULE_CALLBACK_SAVE_AUTHENTICATION);
+}
+


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a genetically engineered Jewish vampire hunter with no name. She's a 
radical gold-digging mermaid on her way to prison for a murder she didn't 
commit. They fight crime! 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]