[nautilus-actions] Fix writing dynamic to desktop file



commit 5748ce52c043c17ac2a0a374e34a9788d778f016
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Dec 1 23:01:42 2009 +0100

    Fix writing dynamic to desktop file

 ChangeLog                                          |   15 ++++++
 .../io-provider-desktop/nadp-desktop-file.c        |   12 ++++-
 .../io-provider-desktop/nadp-desktop-provider.c    |    5 +-
 .../io-provider-desktop/nadp-desktop-provider.h    |    8 ++-
 nautilus-actions/io-provider-desktop/nadp-utils.h  |    8 ---
 nautilus-actions/io-provider-desktop/nadp-write.c  |   50 ++++++++++++++------
 6 files changed, 68 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 286f701..636cb8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2009-12-01 Pierre Wieser <pwieser trychlos org>
 
+	* nautilus-actions/io-provider-desktop/nadp-desktop-file.c
+	(nadp_desktop_file_set_label, nadp_desktop_file_set_tooltip):
+	Fix locale.
+
+	* nautilus-actions/io-provider-desktop/nadp-desktop-provider.c:
+	* nautilus-actions/io-provider-desktop/nadp-desktop-provider.h:
+	Fix NadpDesktopProviderPrivate typedef definition.
+
+	* nautilus-actions/io-provider-desktop/nadp-utils.h:
+	Remove egg-desktop-file.h include.
+
+	* nautilus-actions/io-provider-desktop/nadp-write.c
+	(nadp_iio_provider_is_willing_to_write): Fix permissions.
+	(nadp_iio_provider_write_item): Create directory if it doesn't exist.
+
 	* nautilus-actions/private/na-object-item-priv.h: Fix typo.
 
 	* nautilus-actions/io-provider-desktop/nadp-desktop-provider.h:
diff --git a/nautilus-actions/io-provider-desktop/nadp-desktop-file.c b/nautilus-actions/io-provider-desktop/nadp-desktop-file.c
index 122d30c..1ff0b8b 100644
--- a/nautilus-actions/io-provider-desktop/nadp-desktop-file.c
+++ b/nautilus-actions/io-provider-desktop/nadp-desktop-file.c
@@ -404,11 +404,15 @@ nadp_desktop_file_get_tooltip( const NadpDesktopFile *ndf )
 void
 nadp_desktop_file_set_label( NadpDesktopFile *ndf, const gchar *label )
 {
+	char **locales;
+
 	g_return_if_fail( NADP_IS_DESKTOP_FILE( ndf ));
 
 	if( !ndf->private->dispose_has_run ){
+
+		locales = ( char ** ) g_get_language_names();
 		g_key_file_set_locale_string(
-				ndf->private->key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, label );
+				ndf->private->key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, locales[0], label );
 	}
 }
 
@@ -422,11 +426,15 @@ nadp_desktop_file_set_label( NadpDesktopFile *ndf, const gchar *label )
 void
 nadp_desktop_file_set_tooltip( NadpDesktopFile *ndf, const gchar *tooltip )
 {
+	char **locales;
+
 	g_return_if_fail( NADP_IS_DESKTOP_FILE( ndf ));
 
 	if( !ndf->private->dispose_has_run ){
+
+		locales = ( char ** ) g_get_language_names();
 		g_key_file_set_locale_string(
-				ndf->private->key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, tooltip );
+				ndf->private->key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, locales[0], tooltip );
 	}
 }
 
diff --git a/nautilus-actions/io-provider-desktop/nadp-desktop-provider.c b/nautilus-actions/io-provider-desktop/nadp-desktop-provider.c
index 8410378..adf9be6 100644
--- a/nautilus-actions/io-provider-desktop/nadp-desktop-provider.c
+++ b/nautilus-actions/io-provider-desktop/nadp-desktop-provider.c
@@ -48,10 +48,9 @@ struct NadpDesktopProviderClassPrivate {
 
 /* private instance data
  */
-typedef struct NadpDesktopProviderPrivate {
+struct NadpDesktopProviderPrivate {
 	gboolean dispose_has_run;
-}
-	NadpDesktopProviderPrivate;
+};
 
 static GType         st_module_type = 0;
 static GObjectClass *st_parent_class = NULL;
diff --git a/nautilus-actions/io-provider-desktop/nadp-desktop-provider.h b/nautilus-actions/io-provider-desktop/nadp-desktop-provider.h
index 79c4af9..481152e 100644
--- a/nautilus-actions/io-provider-desktop/nadp-desktop-provider.h
+++ b/nautilus-actions/io-provider-desktop/nadp-desktop-provider.h
@@ -55,6 +55,8 @@ G_BEGIN_DECLS
 #define NADP_IS_DESKTOP_PROVIDER_CLASS( klass )		( G_TYPE_CHECK_CLASS_TYPE(( klass ), NADP_DESKTOP_PROVIDER_TYPE ))
 #define NADP_DESKTOP_PROVIDER_GET_CLASS( object )	( G_TYPE_INSTANCE_GET_CLASS(( object ), NADP_DESKTOP_PROVIDER_TYPE, NadpDesktopProviderClass ))
 
+typedef struct NadpDesktopProviderPrivate NadpDesktopProviderPrivate;
+
 typedef struct {
 	GObject                     parent;
 	NadpDesktopProviderPrivate *private;
@@ -69,10 +71,12 @@ typedef struct {
 }
 	NadpDesktopProviderClass;
 
-/* this is a ':'-separated list of subdirs searched for actions desktop
- * files.
+/* this is a ':'-separated list of subdirs searched for actions desktop files.
  */
 #define NADP_DESKTOP_PROVIDER_SUBDIRS		"file-manager/actions"
+
+/* standard suffix for action desktop files
+ */
 #define NADP_DESKTOP_SUFFIX					".desktop"
 
 GType nadp_desktop_provider_get_type     ( void );
diff --git a/nautilus-actions/io-provider-desktop/nadp-utils.h b/nautilus-actions/io-provider-desktop/nadp-utils.h
index 9ff091c..50ac35d 100644
--- a/nautilus-actions/io-provider-desktop/nadp-utils.h
+++ b/nautilus-actions/io-provider-desktop/nadp-utils.h
@@ -28,19 +28,11 @@
  *   ... and many others (see AUTHORS)
  */
 
-#include "egg-desktop-file.h"
-
 #ifndef __NADP_UTILS_H__
 #define __NADP_UTILS_H__
 
 G_BEGIN_DECLS
 
-typedef struct {
-	gchar          *id;
-	EggDesktopFile *edf;
-}
-	NadpPropertiesStruct;
-
 GSList  *nadp_utils_split_path_list( const gchar *path_list );
 
 void     nadp_utils_gslist_free( GSList *list );
diff --git a/nautilus-actions/io-provider-desktop/nadp-write.c b/nautilus-actions/io-provider-desktop/nadp-write.c
index da3cfdc..e981a00 100644
--- a/nautilus-actions/io-provider-desktop/nadp-write.c
+++ b/nautilus-actions/io-provider-desktop/nadp-write.c
@@ -64,7 +64,7 @@ nadp_iio_provider_is_willing_to_write( const NAIIOProvider *provider )
 	if( g_file_test( userdir, G_FILE_TEST_IS_DIR )){
 		willing_to = nadp_utils_is_writable_dir( userdir );
 
-	} else if( g_mkdir_with_parents( userdir, 700 )){
+	} else if( g_mkdir_with_parents( userdir, 0700 )){
 		g_warning( "%s: %s: %s", thisfn, userdir, g_strerror( errno ));
 
 	} else {
@@ -119,14 +119,17 @@ nadp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
 	gchar *userdir;
 	gchar *id;
 	gchar *bname;
+	GSList *subdirs;
+	gchar *fulldir;
+	gboolean dir_ok;
 
-	ret = NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE;
+	ret = NA_IIO_PROVIDER_NOT_WRITABLE;
 	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( provider ), ret );
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), ret );
 
 	if( na_object_is_readonly( item )){
 		g_warning( "%s: item=%p is read-only", thisfn, ( void * ) item );
-		return( NA_IIO_PROVIDER_NOT_WRITABLE );
+		return( ret );
 	}
 
 	ndf = ( NadpDesktopFile * ) g_object_get_data( G_OBJECT( item ), "nadp-desktop-file" );
@@ -137,21 +140,38 @@ nadp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
 
 	} else {
 		userdir = nadp_xdg_data_dirs_get_user_dir( NADP_DESKTOP_PROVIDER( provider ), messages );
-		id = na_object_get_id( item );
-		bname = g_strdup_printf( "%s%s", id, NADP_DESKTOP_SUFFIX );
-		g_free( id );
-		path = g_build_filename( userdir, NADP_DESKTOP_PROVIDER_SUBDIRS, bname, NULL );
-		g_free( bname );
+		subdirs = nadp_utils_split_path_list( NADP_DESKTOP_PROVIDER_SUBDIRS );
+		fulldir = g_build_filename( userdir, ( gchar * ) subdirs->data, NULL );
+		dir_ok = TRUE;
+		if( !g_file_test( fulldir, G_FILE_TEST_IS_DIR )){
+			if( g_mkdir_with_parents( fulldir, 0700 )){
+				g_warning( "%s: %s: %s", thisfn, userdir, g_strerror( errno ));
+				dir_ok = FALSE;
+			}
+		}
 		g_free( userdir );
+		nadp_utils_gslist_free( subdirs );
+
+		if( dir_ok ){
+			id = na_object_get_id( item );
+			bname = g_strdup_printf( "%s%s", id, NADP_DESKTOP_SUFFIX );
+			g_free( id );
+			path = g_build_filename( fulldir, bname, NULL );
+			g_free( bname );
+		}
+		g_free( fulldir );
 
-		ndf = nadp_desktop_file_new_for_write( path );
-		g_object_set_data( G_OBJECT( item ), "nadp-desktop-file", ndf );
-		g_object_weak_ref( G_OBJECT( item ), ( GWeakNotify ) g_object_unref, ndf );
-
-		g_free( path );
+		if( dir_ok ){
+			ndf = nadp_desktop_file_new_for_write( path );
+			g_object_set_data( G_OBJECT( item ), "nadp-desktop-file", ndf );
+			g_object_weak_ref( G_OBJECT( item ), ( GWeakNotify ) g_object_unref, ndf );
+			g_free( path );
+		}
 	}
 
-	ret = write_item( provider, item, ndf, messages );
+	if( ndf ){
+		ret = write_item( provider, item, ndf, messages );
+	}
 
 	return( ret );
 }



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