Re: [Nautilus-list] PATCH: add 'edit launcher' button to properties window



Attached the patches. Duh! :)

- Frank


On Mon, 2002-04-22 at 00:22, Frank Worsley wrote:
> Hi, 
> 
> attached is a patch that adds an "Edit Launcher" button to the properies
> window when viewing properties for a file of type
> 'application/x-gnome-app-info'.
> 
> It makes it a lot easier to edit the desktop items or making changes to
> the "applications:///" uri items.
> 
> One problem right now is that Nautilus doesn't always refresh the file's
> icon/name after the file has been edited with gnome-desktop-item-edit
> (which is launched by the button). Not sure how to fix that.
> 
> The other patch is for eel and adds two convenience functions that I
> used in the nautilus patch.
> 
> If ok, please commit.
> 
> - Frank
> 
> 
> 
> 
> _______________________________________________
> nautilus-list mailing list
> nautilus-list lists eazel com
> http://lists.eazel.com/mailman/listinfo/nautilus-list

Index: fm-properties-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-properties-window.c,v
retrieving revision 1.151
diff -u -r1.151 fm-properties-window.c
--- fm-properties-window.c	2002/04/20 21:11:31	1.151
+++ fm-properties-window.c	2002/04/22 07:20:34
@@ -65,6 +65,7 @@
 #include <libnautilus-private/nautilus-link.h>
 #include <libnautilus-private/nautilus-metadata.h>
 #include <libnautilus-private/nautilus-undo-signal-handlers.h>
+#include <libnautilus-private/nautilus-program-choosing.h>
 #include <libnautilus/nautilus-undo.h>
 #include <string.h>
 
@@ -159,6 +160,8 @@
 						   FMPropertiesWindow *properties_window);
 static void remove_image_button_callback          (GtkWidget               *widget,
 						   FMPropertiesWindow      *properties_window);
+static void edit_launcher_button_callback         (GtkWidget               *widget,
+						   FMPropertiesWindow      *properties_window);
 static void remove_pending_file                   (StartupData             *data,
 						   gboolean                 cancel_call_when_ready,
 						   gboolean                 cancel_timed_wait,
@@ -1462,6 +1465,16 @@
 }
 
 static gboolean
+should_show_edit_launcher_button (FMPropertiesWindow *window)
+{
+	if (nautilus_file_is_mime_type (window->details->target_file, "application/x-gnome-app-info")) {
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+static gboolean
 should_show_file_type (FMPropertiesWindow *window) 
 {
 	/* The trash on the desktop is one-of-a-kind */
@@ -1623,12 +1636,21 @@
 		append_title_value_pair (table, _("Accessed:"), target_file, "date_accessed");
 	}
 
-	if (should_show_custom_icon_buttons (window)) {
-		/* add command buttons for setting and clearing custom icons */
+	/* get around a warning for button box not being initialized.
+	 * we do initialize it below if it ever gets used, the compiler just 
+	 * get's confused.
+	 */
+	button_box = NULL;
+	
+	if (should_show_custom_icon_buttons (window) || should_show_edit_launcher_button (window)) {
+		/* button box to hold extra buttons. */
 		button_box = gtk_hbox_new (FALSE, 0);
 		gtk_widget_show (button_box);
 		gtk_box_pack_end (GTK_BOX(container), button_box, FALSE, FALSE, 4);  
-		
+	}
+	
+	if (should_show_custom_icon_buttons (window)) {
+		/* add command buttons for setting and clearing custom icons */		
 	 	temp_button = gtk_button_new_with_mnemonic (_("_Select Custom Icon..."));
 		gtk_widget_show (temp_button);
 		gtk_box_pack_start (GTK_BOX (button_box), temp_button, FALSE, FALSE, 4);  
@@ -1649,6 +1671,20 @@
 		gtk_widget_set_sensitive (temp_button, image_uri != NULL);
 		g_free (image_uri);
 	}
+	
+	if (should_show_edit_launcher_button (window)) {
+		/* add an edit launcher button for launchers */
+	 	temp_button = gtk_button_new_with_mnemonic (_("_Edit Launcher..."));
+		gtk_widget_show (temp_button);
+		gtk_box_pack_start (GTK_BOX(button_box), temp_button, FALSE, FALSE, 4);  
+
+	 	g_signal_connect_object (temp_button, "clicked", G_CALLBACK (edit_launcher_button_callback), window, 0);
+
+	    	if (!eel_uri_is_writable (nautilus_file_get_uri (window->details->target_file))
+	    	    || !eel_uri_is_readable (nautilus_file_get_uri (window->details->target_file))) {
+		    	gtk_widget_set_sensitive (temp_button, FALSE);
+		}
+	}
 }
 
 static void
@@ -2486,6 +2522,17 @@
 				    NULL, NULL);
 	
 	gtk_widget_set_sensitive (widget, FALSE);
+}
+
+static void
+edit_launcher_button_callback (GtkWidget *widget, FMPropertiesWindow *properties_window)
+{
+	g_assert (FM_IS_PROPERTIES_WINDOW (properties_window));
+	
+	nautilus_launch_application_from_command ("gnome-desktop-item-edit", 
+						  "gnome-desktop-item-edit",
+						  nautilus_file_get_uri (properties_window->details->original_file), 
+						  FALSE);
 }
 
 static void
Index: eel-vfs-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-vfs-extensions.c,v
retrieving revision 1.7
diff -u -r1.7 eel-vfs-extensions.c
--- eel-vfs-extensions.c	2002/03/18 04:24:50	1.7
+++ eel-vfs-extensions.c	2002/04/22 07:22:05
@@ -28,6 +28,8 @@
 
 #include <config.h>
 
+#include <unistd.h>
+
 #include "eel-vfs-extensions.h"
 #include "eel-lib-self-check-functions.h"
 
@@ -1537,6 +1539,152 @@
 	gnome_vfs_uri_unref (real_dest_uri);
 		
 	return  result;
+}
+
+gboolean
+eel_uri_is_writable (const char *uri) 
+{
+	GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+
+	g_return_val_if_fail (uri != NULL, FALSE);
+
+	if (gnome_vfs_get_file_info
+	    (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
+		
+		gnome_vfs_file_info_unref (info);
+		return FALSE;
+	}
+
+	if ( ! (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)) {
+		gnome_vfs_file_info_unref (info);
+		/* assume writable, if no permissions */
+		return TRUE;
+	} 
+
+	if (info->permissions & GNOME_VFS_PERM_OTHER_WRITE) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->gid == getgid () &&
+	    info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->uid == getuid () &&
+	    info->permissions & GNOME_VFS_PERM_USER_WRITE) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->gid == getgid () &&
+	    info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->permissions & GNOME_VFS_PERM_GROUP_WRITE) {
+		gid_t *groups;
+		int i, n;
+
+		/* get size */
+		n = getgroups (0, NULL);
+
+		if (n == 0) {
+			/* no more groups */
+			gnome_vfs_file_info_unref (info);
+			return FALSE;
+		}
+
+		groups = g_new0 (gid_t, n);
+
+		n = getgroups (n, groups);
+		for (i = 0; i < n; i++) {
+			if (info->gid == groups[i]) {
+				/* ok */
+				gnome_vfs_file_info_unref (info);
+				return TRUE;
+			}
+		}
+	}
+
+	/* no more perimission stuff to try */
+	gnome_vfs_file_info_unref (info);
+	return FALSE;
+}
+
+gboolean
+eel_uri_is_readable (const char *uri) 
+{
+	GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+
+	g_return_val_if_fail (uri != NULL, FALSE);
+
+	if (gnome_vfs_get_file_info
+	    (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
+		
+		gnome_vfs_file_info_unref (info);
+		return FALSE;
+	}
+
+	if ( ! (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)) {
+		gnome_vfs_file_info_unref (info);
+		/* assume readable, if no permissions */
+		return TRUE;
+	} 
+
+	if (info->permissions & GNOME_VFS_PERM_OTHER_READ) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->gid == getgid () &&
+	    info->permissions & GNOME_VFS_PERM_GROUP_READ) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->uid == getuid () &&
+	    info->permissions & GNOME_VFS_PERM_USER_READ) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->gid == getgid () &&
+	    info->permissions & GNOME_VFS_PERM_GROUP_READ) {
+		gnome_vfs_file_info_unref (info);
+		return TRUE;
+	}
+
+	if (info->permissions & GNOME_VFS_PERM_GROUP_READ) {
+		gid_t *groups;
+		int i, n;
+
+		/* get size */
+		n = getgroups (0, NULL);
+
+		if (n == 0) {
+			/* no more groups */
+			gnome_vfs_file_info_unref (info);
+			return FALSE;
+		}
+
+		groups = g_new0 (gid_t, n);
+
+		n = getgroups (n, groups);
+		for (i = 0; i < n; i++) {
+			if (info->gid == groups[i]) {
+				/* ok */
+				gnome_vfs_file_info_unref (info);
+				return TRUE;
+			}
+		}
+	}
+
+	/* no more perimission stuff to try */
+	gnome_vfs_file_info_unref (info);
+	return FALSE;
 }
 
 #if !defined (EEL_OMIT_SELF_CHECK)
Index: eel-vfs-extensions.h
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-vfs-extensions.h,v
retrieving revision 1.5
diff -u -r1.5 eel-vfs-extensions.h
--- eel-vfs-extensions.h	2001/10/19 23:17:33	1.5
+++ eel-vfs-extensions.h	2002/04/22 07:22:05
@@ -79,6 +79,8 @@
 char *             eel_uri_get_scheme                    (const char           *uri);
 char *             eel_uri_make_full_from_relative       (const char           *base_uri,
 							  const char           *uri);
+gboolean	   eel_uri_is_writable			 (const char	       *uri);
+gboolean	   eel_uri_is_readable			 (const char	       *uri);
 
 /* Convenience routine for simple file copying using text-based uris */
 GnomeVFSResult     eel_copy_uri_simple                   (const char           *source_uri,


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