[nautilus-actions] Refactoring: rename src/core/na-gconf-utils.h to src/api/na-gconf-utils.h
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Refactoring: rename src/core/na-gconf-utils.h to src/api/na-gconf-utils.h
- Date: Fri, 19 Feb 2010 02:23:37 +0000 (UTC)
commit 43363a4b510a4f39c0b2f653619338a99d0c274a
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Feb 15 17:23:53 2010 +0100
Refactoring: rename src/core/na-gconf-utils.h to src/api/na-gconf-utils.h
ChangeLog | 1 +
src/api/Makefile.am | 1 +
src/{core => api}/na-gconf-utils.h | 36 +++---
src/core/Makefile.am | 3 +-
src/core/na-gconf-utils.c | 267 ++++++++++++++++++++----------------
5 files changed, 168 insertions(+), 140 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bd4bbf8..9e80d7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
2009-02-15 Pierre Wieser <pwieser trychlos org>
+ Rename src/core/na-gconf-utils.h to src/api/na-gconf-utils.h
Rename src/api/na-iio-provider.c to src/core/na-iio-provider.c
* src/api/na-dbus.h: Update defined name.
diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index 533c4f5..1a7c7c4 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -36,6 +36,7 @@ api_include_HEADERS = \
\
na-core-utils.h \
na-gconf-monitor.h \
+ na-gconf-utils.h \
na-gconf-keys.h \
na-object-api.h \
$(NULL)
diff --git a/src/core/na-gconf-utils.h b/src/api/na-gconf-utils.h
similarity index 55%
rename from src/core/na-gconf-utils.h
rename to src/api/na-gconf-utils.h
index 9b5ee9f..08f6973 100644
--- a/src/core/na-gconf-utils.h
+++ b/src/api/na-gconf-utils.h
@@ -28,8 +28,8 @@
* ... and many others (see AUTHORS)
*/
-#ifndef __NA_RUNTIME_GCONF_UTILS_H__
-#define __NA_RUNTIME_GCONF_UTILS_H__
+#ifndef __NAUTILUS_ACTIONS_API_NA_GCONF_UTILS_H__
+#define __NAUTILUS_ACTIONS_API_NA_GCONF_UTILS_H__
/**
* SECTION: na_gconf_utils
@@ -37,32 +37,32 @@
* @include: runtime/na-gconf-utils.h
*/
-#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
-GSList *na_gconf_utils_get_entries( GConfClient *gconf, const gchar *path );
-void na_gconf_utils_free_entries( GSList *entries );
-gboolean na_gconf_utils_get_bool_from_entries( GSList *entries, const gchar *entry, gboolean *value );
-gboolean na_gconf_utils_get_string_from_entries( GSList *entries, const gchar *entry, gchar **value );
-gboolean na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry, GSList **value );
+G_BEGIN_DECLS
GSList *na_gconf_utils_get_subdirs( GConfClient *gconf, const gchar *path );
void na_gconf_utils_free_subdirs( GSList *subdirs );
-gchar *na_gconf_utils_path_to_key( const gchar *path );
+gboolean na_gconf_utils_has_entry ( GConfClient *gconf, const gchar *path, const gchar *entry );
+GSList *na_gconf_utils_get_entries( GConfClient *gconf, const gchar *path );
+gboolean na_gconf_utils_get_bool_from_entries ( GSList *entries, const gchar *entry, gboolean *value );
+gboolean na_gconf_utils_get_string_from_entries ( GSList *entries, const gchar *entry, gchar **value );
+gboolean na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry, GSList **value );
+void na_gconf_utils_free_entries ( GSList *entries );
-gboolean na_gconf_utils_read_bool( GConfClient *gconf, const gchar *path, gboolean use_schema, gboolean default_value );
-gint na_gconf_utils_read_int( GConfClient *gconf, const gchar *path, gboolean use_schema, gint default_value );
-gchar *na_gconf_utils_read_string( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value );
-GSList *na_gconf_utils_read_string_list( GConfClient *gconf, const gchar *path );
+gboolean na_gconf_utils_read_bool ( GConfClient *gconf, const gchar *path, gboolean use_schema, gboolean default_value );
+gint na_gconf_utils_read_int ( GConfClient *gconf, const gchar *path, gboolean use_schema, gint default_value );
+gchar *na_gconf_utils_read_string ( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value );
+GSList *na_gconf_utils_read_string_list ( GConfClient *gconf, const gchar *path );
-gboolean na_gconf_utils_write_bool( GConfClient *gconf, const gchar *path, gboolean value, gchar **message );
-gboolean na_gconf_utils_write_int( GConfClient *gconf, const gchar *path, gint value, gchar **message );
-gboolean na_gconf_utils_write_string( GConfClient *gconf, const gchar *path, const gchar *value, gchar **message );
+gboolean na_gconf_utils_write_bool ( GConfClient *gconf, const gchar *path, gboolean value, gchar **message );
+gboolean na_gconf_utils_write_int ( GConfClient *gconf, const gchar *path, gint value, gchar **message );
+gboolean na_gconf_utils_write_string ( GConfClient *gconf, const gchar *path, const gchar *value, gchar **message );
gboolean na_gconf_utils_write_string_list( GConfClient *gconf, const gchar *path, GSList *value, gchar **message );
-gboolean na_gconf_utils_remove_entry( GConfClient *gconf, const gchar *path, gchar **message );
+gboolean na_gconf_utils_remove_entry ( GConfClient *gconf, const gchar *path, gchar **message );
G_END_DECLS
-#endif /* __NA_RUNTIME_GCONF_UTILS_H__ */
+#endif /* __NAUTILUS_ACTIONS_API_NA_GCONF_UTILS_H__ */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 10b1b69..4bcd66b 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -39,10 +39,9 @@ AM_CPPFLAGS += \
libna_core_la_SOURCES = \
na-core-utils.c \
na-gconf-monitor.c \
+ na-gconf-utils.c \
na-iio-provider.c \
\
- na-gconf-utils.c \
- na-gconf-utils.h \
na-iabout.c \
na-iabout.h \
na-io-provider.h \
diff --git a/src/core/na-gconf-utils.c b/src/core/na-gconf-utils.c
index d1343f9..bbdfea7 100644
--- a/src/core/na-gconf-utils.c
+++ b/src/core/na-gconf-utils.c
@@ -34,13 +34,93 @@
#include <string.h>
-#include "na-utils.h"
-#include "na-gconf-utils.h"
+#include <api/na-core-utils.h>
+#include <api/na-gconf-utils.h>
static GConfValue *read_value( GConfClient *gconf, const gchar *path, gboolean use_schema, GConfValueType type );
static gboolean sync_gconf( GConfClient *gconf, gchar **message );
/**
+ * na_gconf_utils_get_subdirs:
+ * @gconf: a #GConfClient instance.
+ * @path: a full path to be readen.
+ *
+ * Returns: a list of full path subdirectories.
+ *
+ * The returned list should be #na_gconf_utils_free_subdirs() by the caller.
+ */
+GSList *
+na_gconf_utils_get_subdirs( GConfClient *gconf, const gchar *path )
+{
+ static const gchar *thisfn = "na_gconf_utils_get_subdirs";
+ GError *error = NULL;
+ GSList *list_subdirs;
+
+ list_subdirs = gconf_client_all_dirs( gconf, path, &error );
+
+ if( error ){
+ g_warning( "%s: path=%s, error=%s", thisfn, path, error->message );
+ g_error_free( error );
+ return(( GSList * ) NULL );
+ }
+
+ return( list_subdirs );
+}
+
+/**
+ * na_gconf_utils_free_subdirs:
+ * @subdirs: the subdirectory list as returned from #na_gconf_utils_get_subdirs().
+ *
+ * Release the list.
+ */
+void
+na_gconf_utils_free_subdirs( GSList *subdirs )
+{
+ na_core_utils_slist_free( subdirs );
+}
+
+/**
+ * na_gconf_utils_has_entry:
+ * @gconf: a #GConfClient instance.
+ * @path: the full path of a key.
+ * @entry: the entry to be tested.
+ *
+ * Returns: %TRUE if the given @entry exists for the given @path,
+ * %FALSE else.
+ */
+gboolean
+na_gconf_utils_has_entry( GConfClient *gconf, const gchar *path, const gchar *entry )
+{
+ static const gchar *thisfn = "na_gconf_utils_has_entry";
+ gboolean have_entry = FALSE;
+ GError *error = NULL;
+ gchar *key;
+ GConfValue *value;
+
+ key = g_strdup_printf( "%s/%s", path, entry );
+
+ value = gconf_client_get_without_default( gconf, key, &error );
+
+ if( error ){
+ g_warning( "%s: key=%s, error=%s", thisfn, key, error->message );
+ g_error_free( error );
+ if( value ){
+ gconf_value_free( value );
+ value = NULL;
+ }
+ }
+
+ if( value ){
+ have_entry = TRUE;
+ gconf_value_free( value );
+ }
+
+ g_free( key );
+
+ return( have_entry );
+}
+
+/**
* na_gconf_utils_get_entries:
* @gconf: a #GConfClient instance.
* @path: a full path to be readen.
@@ -72,19 +152,6 @@ na_gconf_utils_get_entries( GConfClient *gconf, const gchar *path )
}
/**
- * na_gconf_utils_free_entries:
- * @list: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
- *
- * Releases the provided list.
- */
-void
-na_gconf_utils_free_entries( GSList *list )
-{
- g_slist_foreach( list, ( GFunc ) gconf_entry_unref, NULL );
- g_slist_free( list );
-}
-
-/**
* na_gconf_utils_get_bool_from_entries:
* @entries: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
* @entry: the searched entry.
@@ -111,7 +178,7 @@ na_gconf_utils_get_bool_from_entries( GSList *entries, const gchar *entry, gbool
for( ip = entries ; ip && !found ; ip = ip->next ){
gconf_entry = ( GConfEntry * ) ip->data;
- key = na_gconf_utils_path_to_key( gconf_entry_get_key( gconf_entry ));
+ key = g_path_get_basename( gconf_entry_get_key( gconf_entry ));
if( !strcmp( key, entry )){
gconf_value = gconf_entry_get_value( gconf_entry );
@@ -158,7 +225,7 @@ na_gconf_utils_get_string_from_entries( GSList *entries, const gchar *entry, gch
for( ip = entries ; ip && !found ; ip = ip->next ){
gconf_entry = ( GConfEntry * ) ip->data;
- key = na_gconf_utils_path_to_key( gconf_entry_get_key( gconf_entry ));
+ key = g_path_get_basename( gconf_entry_get_key( gconf_entry ));
if( !strcmp( key, entry )){
gconf_value = gconf_entry_get_value( gconf_entry );
@@ -207,7 +274,7 @@ na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry
for( ip = entries ; ip && !found ; ip = ip->next ){
gconf_entry = ( GConfEntry * ) ip->data;
- key = na_gconf_utils_path_to_key( gconf_entry_get_key( gconf_entry ));
+ key = g_path_get_basename( gconf_entry_get_key( gconf_entry ));
if( !strcmp( key, entry )){
gconf_value = gconf_entry_get_value( gconf_entry );
@@ -229,56 +296,81 @@ na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry
}
/**
- * na_gconf_utils_get_subdirs:
- * @gconf: a #GConfClient instance.
- * @path: a full path to be readen.
+ * na_gconf_utils_free_entries:
+ * @list: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
*
- * Returns: a list of full path subdirectories.
+ * Releases the provided list.
+ */
+void
+na_gconf_utils_free_entries( GSList *list )
+{
+ g_slist_foreach( list, ( GFunc ) gconf_entry_unref, NULL );
+ g_slist_free( list );
+}
+
+/**
+ * na_gconf_utils_read_string:
+ * @gconf: a #GConfClient instance.
+ * @path: the full path to the key.
+ * @use_schema: whether to use the default value from schema, or not.
+ * @default_value: default value to be used if schema is not used or
+ * doesn't exist.
*
- * The returned list should be na_gconf_utils_free_subdirs() by the caller.
+ * Returns: the required string value in a newly allocated string which
+ * should be g_free() by the caller.
*/
-GSList *
-na_gconf_utils_get_subdirs( GConfClient *gconf, const gchar *path )
+gchar *
+na_gconf_utils_read_string( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value )
{
- static const gchar *thisfn = "na_gconf_utils_get_subdirs";
+ GConfValue *value = NULL;
+ gchar *result;
+
+ g_return_val_if_fail( GCONF_IS_CLIENT( gconf ), NULL );
+
+ result = g_strdup( default_value );
+
+ value = read_value( gconf, path, use_schema, GCONF_VALUE_STRING );
+
+ if( value ){
+ g_free( result );
+ result = g_strdup( gconf_value_get_string( value ));
+ gconf_value_free( value );
+ }
+
+ return( result );
+}
+
+static GConfValue *
+read_value( GConfClient *gconf, const gchar *path, gboolean use_schema, GConfValueType type )
+{
+ static const gchar *thisfn = "na_gconf_utils_read_value";
GError *error = NULL;
- GSList *list_subdirs;
+ GConfValue *value = NULL;
- list_subdirs = gconf_client_all_dirs( gconf, path, &error );
+ if( use_schema ){
+ value = gconf_client_get( gconf, path, &error );
+ } else {
+ value = gconf_client_get_without_default( gconf, path, &error );
+ }
if( error ){
g_warning( "%s: path=%s, error=%s", thisfn, path, error->message );
g_error_free( error );
- return(( GSList * ) NULL );
+ if( value ){
+ gconf_value_free( value );
+ value = NULL;
+ }
}
- return( list_subdirs );
-}
-
-/**
- * na_gconf_utils_free_subdirs:
- * @subdirs: the subdirectory list as returned from #na_gconf_utils_get_subdirs().
- *
- * Release the list.
- */
-void
-na_gconf_utils_free_subdirs( GSList *subdirs )
-{
- na_utils_free_string_list( subdirs );
-}
+ if( value ){
+ if( value->type != type ){
+ g_warning( "%s: path=%s, found type '%u' while waiting for type '%u'", thisfn, path, value->type, type );
+ gconf_value_free( value );
+ value = NULL;
+ }
+ }
-/**
- * na_gconf_utils_path_to_key:
- * @path: the full path of a key.
- *
- * Returns: the key itself, i.e. the last part of the @path.
- *
- * The returned string should be g_free() by the caller.
- */
-gchar *
-na_gconf_utils_path_to_key( const gchar *path )
-{
- return( na_utils_path_extract_last_dir( path ));
+ return( value );
}
/**
@@ -341,38 +433,6 @@ na_gconf_utils_read_int( GConfClient *gconf, const gchar *path, gboolean use_sch
}
/**
- * na_gconf_utils_read_string:
- * @gconf: a #GConfClient instance.
- * @path: the full path to the key.
- * @use_schema: whether to use the default value from schema, or not.
- * @default_value: default value to be used if schema is not used or
- * doesn't exist.
- *
- * Returns: the required string value in a newly allocated string which
- * should be g_free() by the caller.
- */
-gchar *
-na_gconf_utils_read_string( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value )
-{
- GConfValue *value = NULL;
- gchar *result;
-
- g_return_val_if_fail( GCONF_IS_CLIENT( gconf ), NULL );
-
- result = g_strdup( default_value );
-
- value = read_value( gconf, path, use_schema, GCONF_VALUE_STRING );
-
- if( value ){
- g_free( result );
- result = g_strdup( gconf_value_get_string( value ));
- gconf_value_free( value );
- }
-
- return( result );
-}
-
-/**
* na_gconf_utils_read_string_list:
* @gconf: a #GConfClient instance.
* @path: the full path to the key to be read.
@@ -580,39 +640,6 @@ na_gconf_utils_remove_entry( GConfClient *gconf, const gchar *path, gchar **mess
return( ret );
}
-static GConfValue *
-read_value( GConfClient *gconf, const gchar *path, gboolean use_schema, GConfValueType type )
-{
- static const gchar *thisfn = "na_gconf_utils_read_value";
- GError *error = NULL;
- GConfValue *value = NULL;
-
- if( use_schema ){
- value = gconf_client_get( gconf, path, &error );
- } else {
- value = gconf_client_get_without_default( gconf, path, &error );
- }
-
- if( error ){
- g_warning( "%s: path=%s, error=%s", thisfn, path, error->message );
- g_error_free( error );
- if( value ){
- gconf_value_free( value );
- value = NULL;
- }
- }
-
- if( value ){
- if( value->type != type ){
- g_warning( "%s: path=%s, found type '%u' while waiting for type '%u'", thisfn, path, value->type, type );
- gconf_value_free( value );
- value = NULL;
- }
- }
-
- return( value );
-}
-
static gboolean
sync_gconf( GConfClient *gconf, gchar **message )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]