static NADataBoxed * get_boxed_from_path( const NagpGConfProvider *provider, const gchar *path, ReaderData *reader_data, const NADataDef *def ) { static const gchar *thisfn = "nagp_reader_get_boxed_from_path"; NADataBoxed *boxed; gboolean have_entry; gchar *str_value; gboolean bool_value; GSList *slist_value; gint int_value; boxed = NULL; have_entry = na_gconf_utils_has_entry( reader_data->entries, def->gconf_entry ); g_debug( "%s: entry=%s, have_entry=%s", thisfn, def->gconf_entry, have_entry ? "True":"False" ); if( have_entry ){ gchar *entry_path = gconf_concat_dir_and_key( path, def->gconf_entry ); boxed = na_data_boxed_new( def ); switch( def->type ){ case NA_DATA_TYPE_STRING: case NA_DATA_TYPE_LOCALE_STRING: str_value = na_gconf_utils_read_string( provider->private->gconf, entry_path, TRUE, NULL ); na_boxed_set_from_string( NA_BOXED( boxed ), str_value ); g_free( str_value ); break; case NA_DATA_TYPE_BOOLEAN: bool_value = na_gconf_utils_read_bool( provider->private->gconf, entry_path, TRUE, FALSE ); na_boxed_set_from_void( NA_BOXED( boxed ), GUINT_TO_POINTER( bool_value )); break; case NA_DATA_TYPE_STRING_LIST: slist_value = na_gconf_utils_read_string_list( provider->private->gconf, entry_path ); na_boxed_set_from_void( NA_BOXED( boxed ), slist_value ); na_core_utils_slist_free( slist_value ); break; case NA_DATA_TYPE_UINT: int_value = na_gconf_utils_read_int( provider->private->gconf, entry_path, TRUE, 0 ); na_boxed_set_from_void( NA_BOXED( boxed ), GUINT_TO_POINTER( int_value )); break; default: g_warning( "%s: unknown type=%u for %s", thisfn, def->type, def->name ); g_free( boxed ); boxed = NULL; } g_free( entry_path ); } return( boxed ); }
/* * when writing to .desktop file a profile which has both a path and parameters, * then concatenate these two fields to the 'Exec' key */ guint cadp_writer_ifactory_provider_write_data( const NAIFactoryProvider *provider, void *writer_data, const NAIFactoryObject *object, const NADataBoxed *boxed, GSList **messages ) { static const gchar *thisfn = "cadp_writer_ifactory_provider_write_data"; CappDesktopFile *ndf; guint code; const NADataDef *def; gchar *profile_id; gchar *group_name; gchar *str_value; gboolean bool_value; GSList *slist_value; guint uint_value; gchar *parms, *tmp; g_return_val_if_fail( CADP_IS_DESKTOP_FILE( writer_data ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR ); /*g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));*/ code = NA_IIO_PROVIDER_CODE_OK; ndf = CADP_DESKTOP_FILE( writer_data ); def = na_data_boxed_get_data_def( boxed ); if( def->desktop_entry && strlen( def->desktop_entry )){ if( NA_IS_OBJECT_PROFILE( object )){ profile_id = na_object_get_id( object ); group_name = g_strdup_printf( "%s %s", CADP_GROUP_PROFILE, profile_id ); g_free( profile_id ); } else { group_name = g_strdup( CADP_GROUP_DESKTOP ); } if( !na_data_boxed_is_default( boxed ) || def->write_if_default ){ switch( def->type ){ case NA_DATA_TYPE_STRING: str_value = na_boxed_get_string( NA_BOXED( boxed )); if( !strcmp( def->name, NAFO_DATA_PATH )){ parms = na_object_get_parameters( object ); tmp = g_strdup_printf( "%s %s", str_value, parms ); g_free( str_value ); g_free( parms ); str_value = tmp; } cadp_desktop_file_set_string( ndf, group_name, def->desktop_entry, str_value ); g_free( str_value ); break; case NA_DATA_TYPE_LOCALE_STRING: str_value = na_boxed_get_string( NA_BOXED( boxed )); cadp_desktop_file_set_locale_string( ndf, group_name, def->desktop_entry, str_value ); g_free( str_value ); break; case NA_DATA_TYPE_BOOLEAN: bool_value = GPOINTER_TO_UINT( na_boxed_get_as_void( NA_BOXED( boxed ))); cadp_desktop_file_set_boolean( ndf, group_name, def->desktop_entry, bool_value ); break; case NA_DATA_TYPE_STRING_LIST: slist_value = ( GSList * ) na_boxed_get_as_void( NA_BOXED( boxed )); cadp_desktop_file_set_string_list( ndf, group_name, def->desktop_entry, slist_value ); na_core_utils_slist_free( slist_value ); break; case NA_DATA_TYPE_UINT: uint_value = GPOINTER_TO_UINT( na_boxed_get_as_void( NA_BOXED( boxed ))); cadp_desktop_file_set_uint( ndf, group_name, def->desktop_entry, uint_value ); break; default: g_warning( "%s: unknown type=%u for %s", thisfn, def->type, def->name ); code = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR; } } else { cadp_desktop_file_remove_key( ndf, group_name, def->desktop_entry ); } g_free( group_name ); } return( code ); }
/* * reading any data from a desktop file requires: * - a NadpDesktopFile object which has been initialized with the .desktop file * -> has been attached to the NAObjectItem in get_item() above * - the data type (+ reading default value) * - group and key names * * Returns: NULL if the key has not been found * letting the caller deal with default values */ NADataBoxed * nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *object, const NADataDef *def, GSList **messages ) { static const gchar *thisfn = "nadp_reader_ifactory_provider_read_data"; NADataBoxed *boxed; gboolean found; NadpReaderData *nrd; gchar *group, *id; gchar *msg; gchar *str_value; gboolean bool_value; GSList *slist_value; guint uint_value; g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( reader ), NULL ); g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ), NULL ); g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL ); boxed = NULL; if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){ nrd = ( NadpReaderData * ) reader_data; g_return_val_if_fail( NADP_IS_DESKTOP_FILE( nrd->ndf ), NULL ); if( def->desktop_entry ){ if( NA_IS_OBJECT_ITEM( object )){ group = g_strdup( NADP_GROUP_DESKTOP ); } else { g_return_val_if_fail( NA_IS_OBJECT_PROFILE( object ), NULL ); id = na_object_get_id( object ); group = g_strdup_printf( "%s %s", NADP_GROUP_PROFILE, id ); g_free( id ); } switch( def->type ){ case NA_DATA_TYPE_LOCALE_STRING: str_value = nadp_desktop_file_get_locale_string( nrd->ndf, group, def->desktop_entry, &found, def->default_value ); if( found ){ boxed = na_data_boxed_new( def ); na_boxed_set_from_void( NA_BOXED( boxed ), str_value ); } g_free( str_value ); break; case NA_DATA_TYPE_STRING: str_value = nadp_desktop_file_get_string( nrd->ndf, group, def->desktop_entry, &found, def->default_value ); if( found ){ boxed = na_data_boxed_new( def ); na_boxed_set_from_void( NA_BOXED( boxed ), str_value ); } g_free( str_value ); break; case NA_DATA_TYPE_BOOLEAN: bool_value = nadp_desktop_file_get_boolean( nrd->ndf, group, def->desktop_entry, &found, na_core_utils_boolean_from_string( def->default_value )); if( found ){ boxed = na_data_boxed_new( def ); na_boxed_set_from_void( NA_BOXED( boxed ), GUINT_TO_POINTER( bool_value )); } break; case NA_DATA_TYPE_STRING_LIST: slist_value = nadp_desktop_file_get_string_list( nrd->ndf, group, def->desktop_entry, &found, def->default_value ); if( found ){ boxed = na_data_boxed_new( def ); na_boxed_set_from_void( NA_BOXED( boxed ), slist_value ); } na_core_utils_slist_free( slist_value ); break; case NA_DATA_TYPE_UINT: uint_value = nadp_desktop_file_get_uint( nrd->ndf, group, def->desktop_entry, &found, atoi( def->default_value )); if( found ){ boxed = na_data_boxed_new( def ); na_boxed_set_from_void( NA_BOXED( boxed ), GUINT_TO_POINTER( uint_value )); } break; default: msg = g_strdup_printf( "%s: %d: invalid data type.", thisfn, def->type ); g_warning( "%s", msg ); *messages = g_slist_append( *messages, msg ); } g_free( group ); } } return( boxed ); }