[Nautilus-list] Some RH patches.



Ok, I've started to look at merging the redhat branch.

Here is a bunch on uncontroversial, small changes.

Is this ok to check in?

/ Alex

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.4748
diff -u -p -r1.4748 ChangeLog
--- ChangeLog	2001/09/02 02:56:46	1.4748
+++ ChangeLog	2001/09/03 19:10:30
@@ -1,3 +1,30 @@
+2001-09-03  Alex Larsson  <alexl redhat com>
+
+	Merge some stuff from the redhat-outstanding-patches branch
+
+	* components/mozilla/nautilus-mozilla-embed-extensions.cpp
+	(mozilla_get_document_title): add this from Galeon
+	
+	* components/mozilla/nautilus-mozilla-embed-extensions.cpp
+	(mozilla_unicode_to_locale): copy code from Galeon to use Mozilla
+	conversion features to convert unicode to locale encoding
+
+	* components/mozilla/nautilus-mozilla-content-view.c
+	(mozilla_title_changed_callback): set title in locale encoding
+	
+	* libnautilus-private/nautilus-directory-metafile.c
+	(get_metafile): print error and exit if we fail to open the
+	metafile factory; somewhat cleaner than segfaulting.
+	
+	* libnautilus-private/nautilus-file.c:
+	Cache user information to avoid many getpwuid calls etc.
+
+	* src/nautilus-complex-search-bar.c (load_find_them_pixmap_widget):
+	Don't leak pixmap and mask.
+
+	* libnautilus-private/nautilus-icon-container.c (lay_down_icons_tblr):
+	64bit clean. Use sizeof (int *), not sizeof (int). 
+
 2001-09-01  Maciej Stachowiak  <mjs noisehavoc org>
 
 	* libnautilus-private/nautilus-authn-manager.h,
Index: components/mozilla/nautilus-mozilla-content-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/components/mozilla/nautilus-mozilla-content-view.c,v
retrieving revision 1.99
diff -u -p -r1.99 nautilus-mozilla-content-view.c
--- components/mozilla/nautilus-mozilla-content-view.c	2001/07/15 08:54:10	1.99
+++ components/mozilla/nautilus-mozilla-content-view.c	2001/09/03 19:10:32
@@ -809,7 +809,7 @@ mozilla_title_changed_callback (GtkMozEm
 
 	g_assert (GTK_MOZ_EMBED (mozilla) == view->details->mozilla);
 
-	new_title = gtk_moz_embed_get_title (view->details->mozilla);
+	new_title = mozilla_get_document_title (view->details->mozilla);
 
 	DEBUG_MSG (("=%s : new title='%s'\n", __FUNCTION__, new_title));
 
Index: components/mozilla/nautilus-mozilla-embed-extensions.cpp
===================================================================
RCS file: /cvs/gnome/nautilus/components/mozilla/nautilus-mozilla-embed-extensions.cpp,v
retrieving revision 1.7
diff -u -p -r1.7 nautilus-mozilla-embed-extensions.cpp
--- components/mozilla/nautilus-mozilla-embed-extensions.cpp	2001/08/07 17:30:18	1.7
+++ components/mozilla/nautilus-mozilla-embed-extensions.cpp	2001/09/03 19:10:32
@@ -326,3 +326,71 @@ convert_ns_string_to_c_string (const nsS
 
 	return c_string;
 }
+
+/* This is from Galeon */
+static char*
+mozilla_unicode_to_locale (const PRUnichar *uniStr)
+{
+	PRInt32 sSize;
+	wchar_t *wide;
+	gchar *output;
+	gint i, count;
+
+	/* sanity */
+	if (uniStr == NULL) {
+		return NULL;
+	}
+
+	const nsString str (uniStr);
+	sSize = str.Length ();
+
+	/* allocate a wide string big enough to hold the unicode string,
+	 * this is necessary since wchar_t is 32-bits with glibc */
+	wide = g_new0 (wchar_t, sSize + 1);
+	for (i = 0; i < sSize + 1; i++) {
+		wide[i] = uniStr[i];
+	}
+
+	/* use glibc function to determine the size of this string once
+	 * encoded to a locale specfic multibyte string */
+	count = wcstombs (NULL, wide, 0);
+
+	/* check for success */
+	if (count == -1) {
+		/* let Mozilla do a (lossy) conversion then */
+		nsCString str;
+		str.AssignWithConversion (uniStr);
+		g_free (wide);
+		return g_strdup (str.get ()); /* FIXME strdup needed? */
+					      /* Phil: Oh Yes! indeed. */
+	}
+
+	/* allocate a string big enough and do the actual conversion */
+	output = g_new0 (gchar, count + 1);
+	count = wcstombs (output, wide, count + 1);
+	g_assert (count != -1);
+
+	/* free wide version and return */
+	g_free (wide);
+	return output;
+}
+
+extern "C" char * 
+mozilla_get_document_title (const GtkMozEmbed *mozilla_embed)
+{
+	PRUnichar *unicode_title;
+	gchar *title;
+
+	/* get the title in unicode */
+	unicode_title = gtk_moz_embed_get_title_unichar ((GtkMozEmbed *) mozilla_embed);
+	
+	/* attempt conversion */
+	title = mozilla_unicode_to_locale (unicode_title);
+
+	/* free unicode version */
+	g_free (unicode_title);
+
+	/* return it */
+	return title;
+}
+
Index: components/mozilla/nautilus-mozilla-embed-extensions.h
===================================================================
RCS file: /cvs/gnome/nautilus/components/mozilla/nautilus-mozilla-embed-extensions.h,v
retrieving revision 1.2
diff -u -p -r1.2 nautilus-mozilla-embed-extensions.h
--- components/mozilla/nautilus-mozilla-embed-extensions.h	2001/02/22 12:40:40	1.2
+++ components/mozilla/nautilus-mozilla-embed-extensions.h	2001/09/03 19:10:32
@@ -50,6 +50,8 @@ char *   mozilla_charset_encoding_group_
 							    const char        *encoding);
 int      mozilla_charset_get_encoding_group_index          (const GtkMozEmbed *mozilla_embed,
 							    const char        *encoding_group);
+char *   mozilla_get_document_title                        (const GtkMozEmbed *mozilla_embed);
+
 
 #ifdef __cplusplus
 }
Index: libnautilus-private/nautilus-directory-metafile.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-metafile.c,v
retrieving revision 1.33
diff -u -p -r1.33 nautilus-directory-metafile.c
--- libnautilus-private/nautilus-directory-metafile.c	2001/06/30 07:21:53	1.33
+++ libnautilus-private/nautilus-directory-metafile.c	2001/09/03 19:10:32
@@ -51,6 +51,52 @@ free_factory (void)
 	bonobo_object_release_unref (factory, NULL);
 }
 
+
+static void
+die_on_failed_activation (const char        *server_name,
+			  CORBA_Environment *ev)
+{
+	/* This isn't supposed to happen. So do some core-dumping action,
+	 * and don't bother translating the error message.
+	 */
+	const char *extra;
+
+	extra = NULL;
+	
+	switch (ev->_major) {
+	case CORBA_NO_EXCEPTION:
+		break;
+
+	case CORBA_SYSTEM_EXCEPTION:
+		extra = CORBA_exception_id (ev);
+		break;
+
+	case CORBA_USER_EXCEPTION:
+		{
+			const gchar* id = CORBA_exception_id (ev);
+		  
+			if (strcmp (id, "IDL:OAF/GeneralError:1.0") == 0) {
+				OAF_GeneralError* ge = CORBA_exception_value (ev);
+
+				extra = ge->description;
+			} else {
+				extra = id;
+			}
+		}
+		break;
+
+	default:
+		g_assert_not_reached ();
+		break;
+	}
+
+	g_error ("Failed to activate the server %s; this may indicate a broken\n"
+		 "Nautilus or OAF installation, or may reflect a bug in something,\n"
+		 "or may mean that your PATH or LD_LIBRARY_PATH or the like is\n"
+		 "incorrect. Nautilus will dump core and exit.\n"
+		 "Details: '%s'", server_name, extra);
+}
+
 static Nautilus_MetafileFactory
 get_factory (void)
 {
@@ -58,7 +104,19 @@ get_factory (void)
 
 	if (factory == CORBA_OBJECT_NIL) {
 		if (get_factory_from_oaf) {
-			factory = oaf_activate_from_id (METAFILE_FACTORY_IID, 0, NULL, NULL);
+			CORBA_Environment ev;
+			
+			CORBA_exception_init (&ev);
+
+			factory = oaf_activate_from_id (METAFILE_FACTORY_IID, 0,
+							NULL, &ev);
+
+			if (factory == CORBA_OBJECT_NIL) {
+				die_on_failed_activation ("Nautilus_MetafileFactory",
+							  &ev);
+			}
+
+			CORBA_exception_free (&ev);
 		} else {
 			instance = nautilus_metafile_factory_get_instance ();
 			factory = bonobo_object_dup_ref (bonobo_object_corba_objref (BONOBO_OBJECT (instance)), NULL);
@@ -83,12 +141,19 @@ get_metafile (NautilusDirectory *directo
 
 		directory->details->metafile_corba_object = Nautilus_MetafileFactory_open (get_factory (), uri, &ev);
 
-		/* FIXME bugzilla.eazel.com 6664: examine ev for errors */
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_error ("%s: CORBA error opening MetafileFactory: %s\n",
+				 g_get_prgname (),
+				 CORBA_exception_id (&ev));
+		}
+		
 		CORBA_exception_free (&ev);
 	
 		g_free (uri);
 	}
 
+	g_assert (directory->details->metafile_corba_object != CORBA_OBJECT_NIL);
+	
 	return bonobo_object_dup_ref (directory->details->metafile_corba_object, NULL);	
 }
 
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.251
diff -u -p -r1.251 nautilus-file.c
--- libnautilus-private/nautilus-file.c	2001/08/24 20:10:22	1.251
+++ libnautilus-private/nautilus-file.c	2001/09/03 19:10:33
@@ -59,7 +59,11 @@
 #include <pwd.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/time.h>
 
+/* Time in seconds to cache getpwuid results */
+#define GETPWUID_CACHE_TIME (5*60)
+
 #undef NAUTILUS_FILE_DEBUG_REF
 
 #ifdef NAUTILUS_FILE_DEBUG_REF
@@ -560,6 +564,48 @@ get_file_for_parent_directory (NautilusF
 	return result;
 }
 
+struct NautilusUserInfo {
+	uid_t user_id;
+	
+	gboolean has_primary_group;
+	gid_t primary_group;
+	
+	int num_supplementary_groups;
+	gid_t supplementary_groups[NGROUPS_MAX];
+};
+
+/* Returns a pointer to the cached info, does not need freeing */
+static struct NautilusUserInfo *
+nautilus_file_get_user_info (void)
+{
+	static struct timeval cached_time;
+	static struct NautilusUserInfo info;
+	static gboolean has_cached_info = FALSE;
+	struct passwd *password_info;
+	struct timeval now;
+
+	gettimeofday (&now, NULL);
+	
+	if (!has_cached_info ||
+	    ((now.tv_sec - cached_time.tv_sec) > GETPWUID_CACHE_TIME)) {
+		cached_time = now;
+		has_cached_info = TRUE;
+
+		info.user_id = geteuid ();
+		
+		info.has_primary_group = FALSE;
+		/* No need to free result of getpwuid. */
+		password_info = getpwuid (info.user_id);
+		if (password_info) {
+			info.has_primary_group = TRUE;
+			info.primary_group = password_info->pw_gid;
+		}
+		info.num_supplementary_groups = getgroups (NGROUPS_MAX, info.supplementary_groups);
+	}
+
+	return &info;
+}
+
 /**
  * nautilus_file_denies_access_permission:
  * 
@@ -582,10 +628,7 @@ nautilus_file_denies_access_permission (
 				        GnomeVFSFilePermissions group_permission,
 				        GnomeVFSFilePermissions other_permission)
 {
-	uid_t user_id;
-	struct passwd *password_info;
-	gid_t supplementary_groups[NGROUPS_MAX];
-	int num_supplementary_groups;
+	struct NautilusUserInfo *user_info;
 	int i;
 
 	g_assert (NAUTILUS_IS_FILE (file));
@@ -602,11 +645,14 @@ nautilus_file_denies_access_permission (
 		return FALSE;
 	}
 
-	/* Check the user. */
-	user_id = geteuid ();
+	/* This is called often. Cache the user information for five minutes */
 
+	user_info = nautilus_file_get_user_info ();
+
+	/* Check the user. */
+	
 	/* Root is not forbidden to do anything. */
-	if (user_id == 0) {
+	if (user_info->user_id == 0) {
 		return FALSE;
 	}
 
@@ -615,26 +661,23 @@ nautilus_file_denies_access_permission (
 	 * Can we trust the uid in the file info? Might
 	 * there be garbage there? What will it do for non-local files?
 	 */
-	if (user_id == (uid_t) file->details->info->uid) {
+	if (user_info->user_id == (uid_t) file->details->info->uid) {
 		return (file->details->info->permissions & owner_permission) == 0;
 	}
 
-	/* No need to free result of getpwuid. */
-	password_info = getpwuid (user_id);
 
 	/* Group member's access is governed by the group bits. */
 	/* FIXME bugzilla.eazel.com 644: 
 	 * Can we trust the gid in the file info? Might
 	 * there be garbage there? What will it do for non-local files?
 	 */
-	if (password_info != NULL
-	    && password_info->pw_gid == (gid_t) file->details->info->gid) {
+	if (user_info->has_primary_group
+	    && user_info->primary_group == (gid_t) file->details->info->gid) {
 		return (file->details->info->permissions & group_permission) == 0;
 	}
 	/* Check supplementary groups */
-	num_supplementary_groups = getgroups (NGROUPS_MAX, supplementary_groups);
-	for (i = 0; i < num_supplementary_groups; i++) {
-		if ((gid_t) file->details->info->gid == supplementary_groups[i]) {
+	for (i = 0; i < user_info->num_supplementary_groups; i++) {
+		if ((gid_t) file->details->info->gid == user_info->supplementary_groups[i]) {
 			return (file->details->info->permissions & group_permission) == 0;
 		}
 	}
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.216
diff -u -p -r1.216 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	2001/07/19 21:35:13	1.216
+++ libnautilus-private/nautilus-icon-container.c	2001/09/03 19:10:33
@@ -1069,7 +1069,7 @@ lay_down_icons_tblr (NautilusIconContain
 		g_assert (grid_memory);
 
 		/* Allocate room for the pointers to the rows */
-		icon_grid = malloc (num_rows * sizeof (int));
+		icon_grid = malloc (num_rows * sizeof (int *));
 		g_assert (icon_grid);
 
 		/* Point to array pointers */
 2001-09-03  Stanislav Visnovsky  <visnovsky nenya ms mff cuni cz>
 
 	* sk.po: Updated Slovak translation.
Index: src/nautilus-complex-search-bar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-complex-search-bar.c,v
retrieving revision 1.53
diff -u -p -r1.53 nautilus-complex-search-bar.c
--- src/nautilus-complex-search-bar.c	2001/08/31 22:19:08	1.53
+++ src/nautilus-complex-search-bar.c	2001/09/03 19:10:33
@@ -453,12 +453,18 @@ load_find_them_pixmap_widget (void)
 	GdkPixbuf *pixbuf;
 	GdkPixmap *pixmap;
 	GdkBitmap *mask;
+	GtkWidget *widget;
 	
 	pixbuf = gdk_pixbuf_new_from_file (NAUTILUS_PIXMAPDIR "/search.png");
 	if (pixbuf != NULL) {
 		gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, EEL_STANDARD_ALPHA_THRESHHOLD);
 		gdk_pixbuf_unref (pixbuf);
-		return gtk_pixmap_new (pixmap, mask);
+		widget = gtk_pixmap_new (pixmap, mask);
+
+		gdk_pixmap_unref (pixmap);
+		gdk_pixmap_unref (mask);
+ 
+		return widget;
 	} else {
 		return NULL;
 	}





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