[nautilus-actions: 10/30] Merge common/na-utils.{c, h} into runtime/na-utils.{c, h}
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions: 10/30] Merge common/na-utils.{c, h} into runtime/na-utils.{c, h}
- Date: Sat, 21 Nov 2009 18:02:06 +0000 (UTC)
commit e978768a3aba7778cde4d66f7c15585ddfde52fe
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Nov 18 23:36:15 2009 +0100
Merge common/na-utils.{c,h} into runtime/na-utils.{c,h}
ChangeLog | 27 ++
nautilus-actions/common/Makefile.am | 2 -
nautilus-actions/common/na-utils.c | 447 ---------------------
nautilus-actions/common/na-utils.h | 72 ----
nautilus-actions/common/na-xml-writer.c | 2 +-
nautilus-actions/nact/base-builder.c | 2 +-
nautilus-actions/nact/nact-assistant-export.c | 2 +-
nautilus-actions/nact/nact-assistant-import.c | 3 +-
nautilus-actions/nact/nact-clipboard.c | 2 +-
nautilus-actions/nact/nact-iadvanced-tab.c | 4 +-
nautilus-actions/nact/nact-ibackground-tab.c | 3 +-
nautilus-actions/nact/nact-icommand-tab.c | 3 +-
nautilus-actions/nact/nact-iconditions-tab.c | 4 +-
nautilus-actions/nact/nact-tree-model.c | 2 +-
nautilus-actions/nact/nact-window.c | 3 +-
nautilus-actions/nact/nact-xml-reader.c | 2 +-
nautilus-actions/private/Makefile.am | 1 -
nautilus-actions/private/na-object-profile.c | 2 +-
nautilus-actions/runtime/na-utils.c | 408 +++++++++++++++++++
nautilus-actions/runtime/na-utils.h | 18 +
nautilus-actions/utils/nautilus-actions-new.c | 2 +-
nautilus-actions/utils/nautilus-actions-schemas.c | 2 +-
22 files changed, 470 insertions(+), 543 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cc219d2..ecd8acb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
2009-11-18 Pierre Wieser <pwieser trychlos org>
+ Merge common/na-utils.{c,h} into runtime/na-utils.{c,h}.
+
+ * nautilus-actions/common/na-utils.c:
+ * nautilus-actions/common/na-utils.h:
+ Merged into runtime/na-utils.{c,h}, thus deleted from common/.
+
+ * nautilus-actions/common/Makefile.am:
+ * nautilus-actions/common/na-xml-writer.c:
+ * nautilus-actions/nact/base-builder.c:
+ * nautilus-actions/nact/nact-assistant-export.c:
+ * nautilus-actions/nact/nact-assistant-import.c:
+ * nautilus-actions/nact/nact-clipboard.c:
+ * nautilus-actions/nact/nact-iadvanced-tab.c:
+ * nautilus-actions/nact/nact-ibackground-tab.c:
+ * nautilus-actions/nact/nact-icommand-tab.c:
+ * nautilus-actions/nact/nact-iconditions-tab.c:
+ * nautilus-actions/nact/nact-tree-model.c:
+ * nautilus-actions/nact/nact-window.c:
+ * nautilus-actions/nact/nact-xml-reader.c:
+ * nautilus-actions/private/Makefile.am:
+ * nautilus-actions/private/na-object-profile.c:
+ * nautilus-actions/runtime/na-utils.c:
+ * nautilus-actions/runtime/na-utils.h:
+ * nautilus-actions/utils/nautilus-actions-new.c:
+ * nautilus-actions/utils/nautilus-actions-schemas.c:
+ Updated accordingly.
+
Merge common/na-iprefs.{c,h} into runtime/na-iprefs.{c,h}.
* nautilus-actions/common/na-iprefs.c:
diff --git a/nautilus-actions/common/Makefile.am b/nautilus-actions/common/Makefile.am
index e5ad27f..3187dad 100644
--- a/nautilus-actions/common/Makefile.am
+++ b/nautilus-actions/common/Makefile.am
@@ -37,8 +37,6 @@ AM_CPPFLAGS += \
$(NULL)
libna_common_la_SOURCES = \
- na-utils.c \
- na-utils.h \
na-xml-names.h \
na-xml-writer.c \
na-xml-writer.h \
diff --git a/nautilus-actions/common/na-xml-writer.c b/nautilus-actions/common/na-xml-writer.c
index 920e715..f1a4d6b 100644
--- a/nautilus-actions/common/na-xml-writer.c
+++ b/nautilus-actions/common/na-xml-writer.c
@@ -39,8 +39,8 @@
#include <runtime/na-gconf-provider-keys.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
-#include "na-utils.h"
#include "na-xml-names.h"
#include "na-xml-writer.h"
diff --git a/nautilus-actions/nact/base-builder.c b/nautilus-actions/nact/base-builder.c
index 24a39b3..f7f620b 100644
--- a/nautilus-actions/nact/base-builder.c
+++ b/nautilus-actions/nact/base-builder.c
@@ -32,7 +32,7 @@
#include <config.h>
#endif
-#include <common/na-utils.h>
+#include <runtime/na-utils.h>
#include "base-builder.h"
diff --git a/nautilus-actions/nact/nact-assistant-export.c b/nautilus-actions/nact/nact-assistant-export.c
index 85b0b0d..af0b2a6 100644
--- a/nautilus-actions/nact/nact-assistant-export.c
+++ b/nautilus-actions/nact/nact-assistant-export.c
@@ -36,7 +36,6 @@
#include <gtk/gtk.h>
#include <string.h>
-#include <common/na-utils.h>
#include <common/na-xml-names.h>
#include <common/na-xml-writer.h>
@@ -45,6 +44,7 @@
#include <runtime/na-iprefs.h>
#include <runtime/na-pivot.h>
+#include <runtime/na-utils.h>
#include "base-iprefs.h"
#include "nact-application.h"
diff --git a/nautilus-actions/nact/nact-assistant-import.c b/nautilus-actions/nact/nact-assistant-import.c
index 25f68c3..c8b78a7 100644
--- a/nautilus-actions/nact/nact-assistant-import.c
+++ b/nautilus-actions/nact/nact-assistant-import.c
@@ -37,12 +37,11 @@
#include <gtk/gtk.h>
#include <string.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
#include <runtime/na-pivot.h>
+#include <runtime/na-utils.h>
#include "nact-application.h"
#include "nact-iactions-list.h"
diff --git a/nautilus-actions/nact/nact-clipboard.c b/nautilus-actions/nact/nact-clipboard.c
index 888ecd8..f66f162 100644
--- a/nautilus-actions/nact/nact-clipboard.c
+++ b/nautilus-actions/nact/nact-clipboard.c
@@ -37,12 +37,12 @@
#include <common/na-xml-names.h>
#include <common/na-xml-writer.h>
-#include <common/na-utils.h>
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
#include <runtime/na-pivot.h>
+#include <runtime/na-utils.h>
#include "nact-application.h"
#include "nact-assistant-export-ask.h"
diff --git a/nautilus-actions/nact/nact-iadvanced-tab.c b/nautilus-actions/nact/nact-iadvanced-tab.c
index 58b1760..5f21744 100644
--- a/nautilus-actions/nact/nact-iadvanced-tab.c
+++ b/nautilus-actions/nact/nact-iadvanced-tab.c
@@ -36,10 +36,10 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
+#include <runtime/na-utils.h>
+
#include "base-window.h"
#include "base-iprefs.h"
#include "nact-main-tab.h"
diff --git a/nautilus-actions/nact/nact-ibackground-tab.c b/nautilus-actions/nact/nact-ibackground-tab.c
index a83f392..0661a49 100644
--- a/nautilus-actions/nact/nact-ibackground-tab.c
+++ b/nautilus-actions/nact/nact-ibackground-tab.c
@@ -36,12 +36,11 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
#include <runtime/na-pivot.h>
+#include <runtime/na-utils.h>
#include "base-iprefs.h"
#include "base-window.h"
diff --git a/nautilus-actions/nact/nact-icommand-tab.c b/nautilus-actions/nact/nact-icommand-tab.c
index a2e7b25..df5449b 100644
--- a/nautilus-actions/nact/nact-icommand-tab.c
+++ b/nautilus-actions/nact/nact-icommand-tab.c
@@ -35,12 +35,11 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
#include <runtime/na-pivot.h>
+#include <runtime/na-utils.h>
#include "base-window.h"
#include "base-iprefs.h"
diff --git a/nautilus-actions/nact/nact-iconditions-tab.c b/nautilus-actions/nact/nact-iconditions-tab.c
index 36803ff..0213616 100644
--- a/nautilus-actions/nact/nact-iconditions-tab.c
+++ b/nautilus-actions/nact/nact-iconditions-tab.c
@@ -35,10 +35,10 @@
#include <glib/gi18n.h>
#include <string.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
+#include <runtime/na-utils.h>
+
#include "base-iprefs.h"
#include "nact-main-window.h"
#include "nact-main-tab.h"
diff --git a/nautilus-actions/nact/nact-tree-model.c b/nautilus-actions/nact/nact-tree-model.c
index 2b96d41..102881b 100644
--- a/nautilus-actions/nact/nact-tree-model.c
+++ b/nautilus-actions/nact/nact-tree-model.c
@@ -34,12 +34,12 @@
#include <string.h>
-#include <common/na-utils.h>
#include <common/na-xml-writer.h>
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
#include "egg-tree-multi-dnd.h"
#include "nact-application.h"
diff --git a/nautilus-actions/nact/nact-window.c b/nautilus-actions/nact/nact-window.c
index 5207952..0f7ec00 100644
--- a/nautilus-actions/nact/nact-window.c
+++ b/nautilus-actions/nact/nact-window.c
@@ -37,11 +37,10 @@
#include <api/na-iio-provider.h>
-#include <common/na-utils.h>
-
#include <private/na-object-api.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
#include "nact-application.h"
#include "nact-window.h"
diff --git a/nautilus-actions/nact/nact-xml-reader.c b/nautilus-actions/nact/nact-xml-reader.c
index 99c4154..25e5f42 100644
--- a/nautilus-actions/nact/nact-xml-reader.c
+++ b/nautilus-actions/nact/nact-xml-reader.c
@@ -38,7 +38,6 @@
#include <string.h>
#include <uuid/uuid.h>
-#include <common/na-utils.h>
#include <common/na-xml-names.h>
#include <private/na-object-api.h>
@@ -46,6 +45,7 @@
#include <runtime/na-gconf-provider-keys.h>
#include <runtime/na-gconf-utils.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
#include "nact-application.h"
#include "nact-main-window.h"
diff --git a/nautilus-actions/private/Makefile.am b/nautilus-actions/private/Makefile.am
index 1fa9a08..a9c5bb8 100644
--- a/nautilus-actions/private/Makefile.am
+++ b/nautilus-actions/private/Makefile.am
@@ -75,7 +75,6 @@ libna_private_la_SOURCES = \
$(NULL)
libna_private_la_LIBADD = \
- $(top_builddir)/nautilus-actions/common/libna-common.la \
$(NULL)
VERSION_INFO = 1:0:0
diff --git a/nautilus-actions/private/na-object-profile.c b/nautilus-actions/private/na-object-profile.c
index 6c000ab..9d5cfab 100644
--- a/nautilus-actions/private/na-object-profile.c
+++ b/nautilus-actions/private/na-object-profile.c
@@ -36,7 +36,7 @@
#include <libnautilus-extension/nautilus-file-info.h>
-#include <common/na-utils.h>
+#include <runtime/na-utils.h>
#include "na-iduplicable.h"
#include "na-object-api.h"
diff --git a/nautilus-actions/runtime/na-utils.c b/nautilus-actions/runtime/na-utils.c
index 1c48b34..47f9b0b 100644
--- a/nautilus-actions/runtime/na-utils.c
+++ b/nautilus-actions/runtime/na-utils.c
@@ -38,6 +38,28 @@
#include "na-utils.h"
+static GSList *text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value );
+
+/**
+ * na_utils_dump_string_list:
+ * @list: a list of strings.
+ *
+ * Dumps the content of a list of strings.
+ */
+void
+na_utils_dump_string_list( GSList *list )
+{
+ static const gchar *thisfn = "na_utils_dump_string_list";
+ GSList *i;
+ int c;
+
+ g_debug( "%s: list at %p has %d elements", thisfn, ( void * ) list, g_slist_length( list ));
+ for( i=list, c=0 ; i ; i=i->next, c++ ){
+ gchar *s = ( gchar * ) i->data;
+ g_debug( "%s: %2d - %s", thisfn, c, s );
+ }
+}
+
/**
* na_utils_duplicate_string_list:
* @list: the GSList to be duplicated.
@@ -99,6 +121,43 @@ na_utils_free_string_list( GSList *list )
}
/**
+ * na_utils_lines_to_string_list:
+ * @text: a buffer which contains embedded newlines.
+ *
+ * Returns: a list of strings from the buffer.
+ *
+ * The returned list should be na_utils_free_string_list() by the caller.
+ */
+GSList *
+na_utils_lines_to_string_list( const gchar *text )
+{
+ return( text_to_string_list( text, "\n", NULL ));
+}
+
+/**
+ * na_utils_remove_ascii_from_string_list:
+ * @list: the GSList to be updated.
+ * @text: string to remove.
+ *
+ * Removes a string from a GSList of strings.
+ *
+ * Returns the new list after update.
+ */
+GSList *
+na_utils_remove_ascii_from_string_list( GSList *list, const gchar *text )
+{
+ GSList *il;
+ for( il = list ; il ; il = il->next ){
+ const gchar *istr = ( const gchar * ) il->data;
+ if( !g_ascii_strcasecmp( text, istr )){
+ list = g_slist_remove( list, ( gconstpointer ) istr );
+ return( list );
+ }
+ }
+ return( list );
+}
+
+/**
* na_utils_remove_from_string_list:
* @list: the GSList to be updated.
* @str: the string to be removed.
@@ -157,6 +216,84 @@ na_utils_string_lists_are_equal( GSList *first, GSList *second )
}
/**
+ * na_utils_string_list_to_text:
+ * @strlist: a list of strings.
+ *
+ * Concatenates a string list to a semi-colon-separated text
+ * suitable for an entry in the user interface
+ *
+ * Returns: a newly allocated string, which should be g_free() by the
+ * caller.
+ */
+gchar *
+na_utils_string_list_to_text( GSList *strlist )
+{
+ GSList *ib;
+ gchar *tmp;
+ gchar *text = g_strdup( "" );
+
+ for( ib = strlist ; ib ; ib = ib->next ){
+ if( strlen( text )){
+ tmp = g_strdup_printf( "%s; ", text );
+ g_free( text );
+ text = tmp;
+ }
+ tmp = g_strdup_printf( "%s%s", text, ( gchar * ) ib->data );
+ g_free( text );
+ text = tmp;
+ }
+
+ return( text );
+}
+
+/**
+ * na_utils_text_to_string_list:
+ * @text: a semi-colon-separated string.
+ *
+ * Returns: a list of strings from a semi-colon-separated text
+ * (entry text in the user interface).
+ *
+ * The returned list should be na_utils_free_string_list() by the caller.
+ */
+GSList *
+na_utils_text_to_string_list( const gchar *text )
+{
+ return( text_to_string_list( text, ";", NULL ));
+}
+
+/*
+ * split a text buffer in lines
+ */
+static GSList *
+text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value )
+{
+ GSList *strlist = NULL;
+ gchar **tokens, **iter;
+ gchar *tmp;
+ gchar *source = g_strdup( text );
+
+ tmp = g_strstrip( source );
+ if( !strlen( tmp ) && default_value ){
+ strlist = g_slist_append( strlist, g_strdup( default_value ));
+
+ } else {
+ tokens = g_strsplit( source, separator, -1 );
+ iter = tokens;
+
+ while( *iter ){
+ tmp = g_strstrip( *iter );
+ strlist = g_slist_append( strlist, g_strdup( tmp ));
+ iter++;
+ }
+
+ g_strfreev( tokens );
+ }
+
+ g_free( source );
+ return( strlist );
+}
+
+/**
* na_utils_gslist_to_schema:
* @list: a list of strings.
*
@@ -191,6 +328,138 @@ na_utils_gslist_to_schema( GSList *list )
}
/**
+ * na_utils_schema_to_gslist:
+ * @value: a string of the form [xxx,yyy,...] as read from GConf.
+ *
+ * Converts a string representing a list of strings in a GConf format
+ * to a list of strings.
+ *
+ * Returns: a newly allocated list of strings, which should be
+ * na_utils_free_string_list() by the caller.
+ */
+GSList *
+na_utils_schema_to_gslist( const gchar *value )
+{
+ GSList *list = NULL;
+ const gchar *ptr = value;
+ const gchar *start = NULL;
+ gchar *str_list = NULL;
+ gchar **str_list_splited = NULL;
+ int i;
+
+ /* first remove the surrounding brackets [] */
+ while( *ptr != '[' ){
+ ptr++;
+ }
+
+ if( *ptr == '[' ){
+ ptr++;
+ start = ptr;
+ i = 0;
+ while( *ptr != ']' ){
+ i++;
+ ptr++;
+ }
+ if( *ptr == ']' ){
+ str_list = g_strndup( start, i );
+ }
+ }
+
+ /* split the result and fill the list */
+ if( str_list != NULL ){
+
+ str_list_splited = g_strsplit( str_list, ",", -1 );
+ i = 0;
+ while( str_list_splited[i] != NULL ){
+ list = g_slist_append( list, g_strdup( str_list_splited[i] ));
+ i++;
+ }
+ g_strfreev( str_list_splited );
+ }
+
+ return( list );
+}
+
+/**
+ * na_utils_boolean_to_schema:
+ * @b: a boolean to be written.
+ *
+ * Converts a boolean to the suitable string for a GConf schema
+ *
+ * Returns: a newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_utils_boolean_to_schema( gboolean b )
+{
+ gchar *text = g_strdup_printf( "%s", b ? "true" : "false" );
+ return( text );
+}
+
+/**
+ * na_utils_schema_to_boolean:
+ * @value: a string which should contains a boolean value.
+ * @default_value: the default value to be used.
+ *
+ * Converts a string to a boolean.
+ *
+ * The conversion is not case sensitive, and accepts abbreviations.
+ * The default value is used if we cannot parse the provided string.
+ *
+ * Returns: the boolean.
+ *
+ */
+gboolean
+na_utils_schema_to_boolean( const gchar *value, gboolean default_value )
+{
+ if( !g_ascii_strcasecmp( value, "true" )){
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning TRUE", value );*/
+ return( TRUE );
+ }
+ if( !g_ascii_strcasecmp( value, "false" )){
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning FALSE", value );*/
+ return( FALSE );
+ }
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning default_value", value );*/
+ return( default_value );
+}
+
+/**
+ * na_utils_gstring_joinv:
+ * @start: a prefix to be written at the beginning of the output string.
+ * @separator: a string to be used as separator.
+ * @list: the list of strings to be concatenated.
+ *
+ * Concatenates a gchar **list of strings to a new string.
+ *
+ * Returns: a newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list )
+{
+ GString *tmp_string = g_string_new( "" );
+ int i;
+
+ g_return_val_if_fail( list != NULL, NULL );
+
+ if( start != NULL ){
+ tmp_string = g_string_append( tmp_string, start );
+ }
+
+ if( list[0] != NULL ){
+ tmp_string = g_string_append( tmp_string, list[0] );
+ }
+
+ for( i = 1 ; list[i] != NULL ; i++ ){
+ if( separator ){
+ tmp_string = g_string_append( tmp_string, separator );
+ }
+ tmp_string = g_string_append( tmp_string, list[i] );
+ }
+
+ return( g_string_free( tmp_string, FALSE ));
+}
+
+/**
* na_utils_get_first_word:
* @string: a space-separated string.
*
@@ -221,6 +490,108 @@ na_utils_get_first_word( const gchar *string )
}
/**
+ * na_utils_prefix_strings:
+ * @prefix: the prefix to be prepended.
+ * @str: a multiline string.
+ *
+ * Appends a prefix to each line of the string.
+ *
+ * Returns: a new string which should be g_free() by the caller.
+ */
+gchar *
+na_utils_prefix_strings( const gchar *prefix, const gchar *str )
+{
+ GSList *list, *il;
+ GString *result;
+
+ list = text_to_string_list( str, "\n", NULL );
+ result = g_string_new( "" );
+
+ for( il = list ; il ; il = il->next ){
+ g_string_append_printf( result, "%s%s\n", prefix, ( gchar * ) il->data );
+ }
+
+ na_utils_free_string_list( list );
+
+ return( g_string_free( result, FALSE ));
+}
+
+/**
+ * na_utils_exist_file:
+ * @uri: an uri which points to a file.
+ *
+ * Returns: %TRUE if the specified file exists, %FALSE else.
+ *
+ * Race condition: cf. na_utils_is_writable_dir() comment.
+ */
+gboolean
+na_utils_exist_file( const gchar *uri )
+{
+ GFile *file;
+ gboolean exists;
+
+ file = g_file_new_for_uri( uri );
+ exists = g_file_query_exists( file, NULL );
+ g_object_unref( file );
+
+ return( exists );
+}
+
+/**
+ * na_utils_is_writable_dir:
+ * @uri: an uri which points to a directory.
+ *
+ * Returns: %TRUE if the directory is writable, %FALSE else.
+ *
+ * Please note that this type of test is subject to race conditions,
+ * as the directory may become unwritable after a successfull test,
+ * but before the caller has been able to actually write into it.
+ *
+ * There is no "super-test". Just try...
+ */
+gboolean
+na_utils_is_writable_dir( const gchar *uri )
+{
+ static const gchar *thisfn = "na_utils_is_writable_dir";
+ GFile *file;
+ GError *error = NULL;
+ GFileInfo *info;
+ GFileType type;
+ gboolean writable;
+
+ if( !uri || !strlen( uri )){
+ return( FALSE );
+ }
+
+ file = g_file_new_for_uri( uri );
+ info = g_file_query_info( file,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NONE, NULL, &error );
+
+ if( error ){
+ g_warning( "%s: g_file_query_info error: %s", thisfn, error->message );
+ g_error_free( error );
+ g_object_unref( file );
+ return( FALSE );
+ }
+
+ type = g_file_info_get_file_type( info );
+ if( type != G_FILE_TYPE_DIRECTORY ){
+ g_warning( "%s: %s is not a directory", thisfn, uri );
+ g_object_unref( info );
+ return( FALSE );
+ }
+
+ writable = g_file_info_get_attribute_boolean( info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE );
+ if( !writable ){
+ g_warning( "%s: %s is not writable", thisfn, uri );
+ }
+ g_object_unref( info );
+
+ return( writable );
+}
+
+/**
* na_utils_path_extract_last_dir:
* @path: a full path.
*
@@ -237,3 +608,40 @@ na_utils_path_extract_last_dir( const gchar *path )
g_strfreev( split );
return( lastdir );
}
+
+/**
+ * na_utils_remove_last_level_from_path:
+ * @path: a full path.
+ *
+ * Removes last level from path (mostly a 'dirname').
+ *
+ * Returns: a newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_utils_remove_last_level_from_path( const gchar *path )
+{
+ int p;
+ const char *ptr = path;
+ char *new_path;
+
+ if( path == NULL ){
+ return( NULL );
+ }
+
+ p = strlen( path ) - 1;
+ if( p < 0 ){
+ return( NULL );
+ }
+
+ while(( p > 0 ) && ( ptr[p] != '/' )){
+ p--;
+ }
+
+ if(( p == 0 ) && ( ptr[p] == '/' )){
+ p++;
+ }
+
+ new_path = g_strndup( path, ( guint ) p );
+
+ return( new_path );
+}
diff --git a/nautilus-actions/runtime/na-utils.h b/nautilus-actions/runtime/na-utils.h
index 7de40a3..1016e04 100644
--- a/nautilus-actions/runtime/na-utils.h
+++ b/nautilus-actions/runtime/na-utils.h
@@ -37,23 +37,41 @@ G_BEGIN_DECLS
/* some functions to ease the GSList list manipulations
*/
+void na_utils_dump_string_list( GSList *list );
GSList *na_utils_duplicate_string_list( GSList *list );
gboolean na_utils_find_in_list( GSList *list, const gchar *str );
void na_utils_free_string_list( GSList *list );
+GSList *na_utils_lines_to_string_list( const gchar *text );
+GSList *na_utils_remove_ascii_from_string_list( GSList *list, const gchar *text );
GSList *na_utils_remove_from_string_list( GSList *list, const gchar *str );
gboolean na_utils_string_lists_are_equal( GSList *first, GSList *second );
+gchar *na_utils_string_list_to_text( GSList *list );
+GSList *na_utils_text_to_string_list( const gchar *text );
/* a GSList to a string [aaaa,bbbb,cccc]
*/
gchar *na_utils_gslist_to_schema( GSList *list );
+GSList *na_utils_schema_to_gslist( const gchar *value );
+
+gchar *na_utils_boolean_to_schema( gboolean b );
+gboolean na_utils_schema_to_boolean( const gchar *value, gboolean default_value );
+
+/*
+ * Some functions for GString manipulations.
+ */
+gchar *na_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list );
/* string manipulations
*/
gchar *na_utils_get_first_word( const gchar *string );
+gchar *na_utils_prefix_strings( const gchar *prefix, const gchar *str );
/* path manipulations
*/
+gboolean na_utils_exist_file( const gchar *uri );
+gboolean na_utils_is_writable_dir( const gchar *uri );
gchar *na_utils_path_extract_last_dir( const gchar *path );
+gchar *na_utils_remove_last_level_from_path( const gchar *path );
G_END_DECLS
diff --git a/nautilus-actions/utils/nautilus-actions-new.c b/nautilus-actions/utils/nautilus-actions-new.c
index daa9362..46eb39a 100644
--- a/nautilus-actions/utils/nautilus-actions-new.c
+++ b/nautilus-actions/utils/nautilus-actions-new.c
@@ -40,13 +40,13 @@
#include <common/na-xml-names.h>
#include <common/na-xml-writer.h>
-#include <common/na-utils.h>
#include <private/na-object-api.h>
#include <runtime/na-gconf-provider.h>
#include <runtime/na-io-provider.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
#include "console-utils.h"
diff --git a/nautilus-actions/utils/nautilus-actions-schemas.c b/nautilus-actions/utils/nautilus-actions-schemas.c
index bad0933..ba1d7b4 100644
--- a/nautilus-actions/utils/nautilus-actions-schemas.c
+++ b/nautilus-actions/utils/nautilus-actions-schemas.c
@@ -40,9 +40,9 @@
#include <common/na-xml-names.h>
#include <common/na-xml-writer.h>
-#include <common/na-utils.h>
#include <runtime/na-iprefs.h>
+#include <runtime/na-utils.h>
#include "console-utils.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]