--- fm-properties-window.c	2004-02-12 21:07:21.000000000 +0530
+++ fm-properties-window-aftermodification.c	2004-03-02 11:16:36.000000000 +0530
@@ -81,6 +81,10 @@
 #include <bonobo/bonobo-widget.h>
 #include <bonobo/bonobo-exception.h>
 #include <string.h>
+#include <gnome.h>
+#include <sys/types.h>
+#include <dirent.h>
+
 
 static GHashTable *windows;
 static GHashTable *pending_lists;
@@ -176,6 +180,9 @@ static GtkTargetEntry target_table[] = {
 #define STANDARD_EMBLEM_HEIGHT			52
 #define EMBLEM_LABEL_SPACING			2
 
+char *initial_perm;
+gboolean apply_all;
+
 static void permission_button_update (FMPropertiesWindow *window,
 				      GtkToggleButton *button);
 static void value_field_update (FMPropertiesWindow *window,
@@ -204,6 +211,11 @@ static void append_extension_pages      
 GNOME_CLASS_BOILERPLATE (FMPropertiesWindow, fm_properties_window,
 			 GtkWindow, GTK_TYPE_WINDOW);
 
+static void apply_all_toggled(GtkToggleButton *check_button,
+               gpointer   data);
+
+static void set_recursive_perm(char *path,mode_t perm_add_mask,mode_t perm_delete_mask);
+
 typedef struct {
 	NautilusFile *file;
 	char *name;
@@ -2845,6 +2857,283 @@ get_initial_permissions (GList *file_lis
 }
 
 static void
+window_closed(GtkWidget *window)
+{
+      	GList *file_list,*l;
+      	char *perm,inconsistent_string[5],*name,*path,*location;
+	int i,j;
+	char c1,c2;
+	mode_t perm_add_mask,perm_delete_mask;
+
+	name= (char *)malloc(255);
+        path= (char *)malloc(255);
+	
+        perm_add_mask = 0;
+        perm_delete_mask = 0; 
+
+	file_list = ((FMPropertiesWindow *)window)->details->original_files;
+        location = file_list_get_string_attribute (file_list, 
+					      	   "where",
+					            inconsistent_string);
+
+	perm = file_list_get_string_attribute (file_list, 
+					       "permissions",
+					        inconsistent_string);
+	
+	if(apply_all == 't') {
+    
+                if (strcmp(initial_perm,perm)) {
+		
+		
+			for(i=0;i<3;i++) {
+
+				for(j=1;j<=3;j++) {
+				
+				c1 = initial_perm[((i*3)+j)];
+				c2 = perm[((i*3)+j)];
+
+					if(c1 != c2) {
+						switch(i)
+						{
+						 case 0:
+							switch(j)
+							{
+							 case 1:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IRUSR;
+								}
+								else if(c2=='r') {
+								perm_add_mask=perm_add_mask | S_IRUSR;
+								}
+							 	break;
+
+							 case 2:
+								if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IWUSR;
+								}
+								else if(c2=='w') {
+								perm_add_mask=perm_add_mask | S_IWUSR;
+								}
+							 	break;
+
+							 case 3:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IXUSR;
+								}
+								else if(c2=='x') {
+								perm_add_mask=perm_add_mask | S_IXUSR;
+								}
+								break;	
+							}
+						  break;
+
+						  case 1:
+							switch(j)
+							{
+							 case 1:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IRGRP;
+								}
+								else if(c2=='r') {
+								perm_add_mask=perm_add_mask | S_IRGRP;
+								}
+							 	break;
+
+							 case 2:
+								if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IWGRP;
+								}
+								else if(c2=='w') {
+								perm_add_mask=perm_add_mask | S_IWGRP;
+								}
+							 	break;
+
+							 case 3:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IXGRP;
+								}
+								else if(c2=='x') {
+								perm_add_mask=perm_add_mask | S_IXGRP;
+								}
+								break;	
+							}
+						  break;
+
+						  case 2:
+							switch(j)
+							{
+							 case 1:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IROTH;
+								}
+								else if(c2=='r') {
+								perm_add_mask=perm_add_mask | S_IROTH;
+								}
+							 	break;
+
+							 case 2:
+								if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IWOTH;
+								}
+								else if(c2=='w') {
+								perm_add_mask=perm_add_mask | S_IWOTH;
+								}
+							 	break;
+
+							 case 3:
+							 	if(c2=='-') {
+								perm_delete_mask= perm_delete_mask | S_IXOTH;
+								}
+								else if(c2=='x') {
+								perm_add_mask=perm_add_mask | S_IXOTH;
+								}
+								break;	
+							}
+						  break;		
+						}
+
+					}
+
+				}
+
+			}
+
+			for (l = file_list; l != NULL; l = l->next) {
+
+			NautilusFile *file;
+		
+			file = NAUTILUS_FILE (l->data);
+			name = nautilus_file_get_name (file);
+			path = (char *)malloc(strlen(location)+strlen(name));
+
+         		strcpy(path,location);
+
+         		if (strcmp(location,"/")) {
+         			strcat(path,"/");
+         		}
+
+			strcat(path,name);
+			set_recursive_perm(path,perm_add_mask,perm_delete_mask);              
+		
+			}
+
+		}
+	}
+
+ 	gtk_widget_destroy(window);
+}
+
+
+static void
+apply_all_toggled(GtkToggleButton *check_button,
+                  gpointer window)
+{ 
+ 	
+    	GList *file_list,*l;
+        char *location,inconsistent_string[5];  
+	char *name,*path;
+	name= (char *)malloc(255);
+        path= (char *)malloc(255);  
+        l=file_list;
+
+     
+	file_list = ((FMPropertiesWindow *)window)->details->original_files;
+	location = file_list_get_string_attribute (file_list, 
+					      	   "where",
+					            inconsistent_string);
+        initial_perm = file_list_get_string_attribute (file_list, 
+					      		"permissions",
+					        	inconsistent_string);
+      
+       /* If control reaches here, the toggle button is down */   
+
+	if (gtk_toggle_button_get_active (check_button)) {
+ 
+	apply_all = 't';
+
+	} 
+
+	else {
+  
+	apply_all='f';
+
+	}
+           
+
+}
+
+static void
+set_recursive_perm(char *path,mode_t perm_add_mask,mode_t perm_delete_mask)
+{
+ 
+        DIR *curdir;			
+	struct dirent *current;
+	char buff[255];
+        struct stat buf; 
+    
+	curdir=opendir(path);
+		
+        for (;(current=readdir(curdir));) {
+          	if(strcmp(current->d_name,".") && strcmp(current->d_name,"..")){
+			strcpy(buff,path);
+			strcat(buff,"/");  
+			strcat(buff,current->d_name);
+                	stat(buff,&buf);
+
+			if(S_ISDIR(buf.st_mode)) {
+                    	set_recursive_perm(buff,perm_add_mask,perm_delete_mask);
+                 	}
+		}
+
+	  	chmod(buff,(buf.st_mode | perm_add_mask) & ~perm_delete_mask);
+	}
+
+        
+}
+
+
+static void 
+append_apply_all(GtkTable *table,FMPropertiesWindow *window)
+{
+	guint last_row;
+	GtkLabel *apply_all_label;
+	GtkWidget *check_button;
+	GList *file_list;
+        gchar *label;
+        char *type,inconsistent_string[5];  
+
+	apply_all = 'f';
+        file_list = window->details->original_files;
+
+	type = file_list_get_string_attribute (file_list, 
+					     "type",
+					      inconsistent_string);
+
+        if (!strcmp(type,"Folder")) {
+
+		append_separator (table);
+
+		last_row = append_title_field (table, _("Apply To Folder Contents:"), &apply_all_label);
+                 
+		label = _("_Apply Changed Permissions");
+                
+		check_button = gtk_check_button_new_with_mnemonic (label);
+		
+		gtk_widget_show (check_button);
+
+        	gtk_table_attach_defaults (table, check_button,
+			           	   1,2,last_row, 
+					   last_row+1);
+
+		g_signal_connect (G_OBJECT (check_button), "toggled",
+		          	  G_CALLBACK (apply_all_toggled), window);
+       
+	}
+
+}
+
+
+static void
 create_permissions_page (FMPropertiesWindow *window)
 {
 	GtkWidget *vbox;
@@ -2922,6 +3211,7 @@ create_permissions_page (FMPropertiesWin
 					    FALSE); 
 		}
 
+		append_apply_all(page_table,window);
 		append_separator (page_table);
 		
 		checkbox_titles_row = append_title_field (page_table, _("Owner:"), &owner_perm_label);
@@ -3309,7 +3599,7 @@ create_properties_window (StartupData *s
 	gtk_box_pack_end (GTK_BOX (hbox), GTK_WIDGET (button),
 			    FALSE, TRUE, 0);
 	g_signal_connect_swapped (button, "clicked",
-				  G_CALLBACK (gtk_widget_destroy),
+				  G_CALLBACK (window_closed),
 				  window);
 
 	/* Update from initial state */
