static void read_done_action_load_profile( const NAIFactoryProvider *provider, ReaderData *data, const gchar *path, GSList **messages ) { gchar *id; ReaderData *profile_data; NAObjectProfile *profile = na_object_profile_new(); id = g_path_get_basename( path ); na_object_set_id( profile, id ); g_free( id ); profile_data = g_new0( ReaderData, 1 ); profile_data->parent = data->parent; profile_data->path = ( gchar * ) path; profile_data->entries = na_gconf_utils_get_entries( NAGP_GCONF_PROVIDER( provider )->private->gconf, path ); na_ifactory_provider_read_item( NA_IFACTORY_PROVIDER( provider ), profile_data, NA_IFACTORY_OBJECT( profile ), messages ); na_gconf_utils_free_entries( profile_data->entries ); g_free( profile_data ); }
/* * path is here the full path to an item */ static NAObjectItem * read_item( NagpGConfProvider *provider, const gchar *path, GSList **messages ) { static const gchar *thisfn = "nagp_reader_read_item"; NAObjectItem *item; gchar *full_path; gchar *type; gchar *id; ReaderData *data; g_debug( "%s: provider=%p, path=%s", thisfn, ( void * ) provider, path ); g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider ), NULL ); g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL ); g_return_val_if_fail( !provider->private->dispose_has_run, NULL ); full_path = gconf_concat_dir_and_key( path, NAGP_ENTRY_TYPE ); type = na_gconf_utils_read_string( provider->private->gconf, full_path, TRUE, NAGP_VALUE_TYPE_ACTION ); g_free( full_path ); item = NULL; /* an item may have 'Action' or 'Menu' type; defaults to Action */ if( !type || !strlen( type ) || !strcmp( type, NAGP_VALUE_TYPE_ACTION )){ item = NA_OBJECT_ITEM( na_object_action_new()); } else if( !strcmp( type, NAGP_VALUE_TYPE_MENU )){ item = NA_OBJECT_ITEM( na_object_menu_new()); } else { g_warning( "%s: unknown type '%s' at %s", thisfn, type, path ); } g_free( type ); if( item ){ id = g_path_get_basename( path ); na_object_set_id( item, id ); g_free( id ); data = g_new0( ReaderData, 1 ); data->path = ( gchar * ) path; data->entries = na_gconf_utils_get_entries( provider->private->gconf, path ); na_gconf_utils_dump_entries( data->entries ); na_ifactory_provider_read_item( NA_IFACTORY_PROVIDER( provider ), data, NA_IFACTORY_OBJECT( item ), messages ); na_gconf_utils_free_entries( data->entries ); g_free( data ); } return( item ); }
/* * Returns a newly allocated NAIFactoryObject-derived object, initialized * from the .desktop file */ static NAIFactoryObject * item_from_desktop_file( const NadpDesktopProvider *provider, NadpDesktopFile *ndf, GSList **messages ) { /*static const gchar *thisfn = "nadp_reader_item_from_desktop_file";*/ NAIFactoryObject *item; gchar *type; NadpReaderData *reader_data; gchar *id; item = NULL; type = nadp_desktop_file_get_file_type( ndf ); if( !strcmp( type, NADP_VALUE_TYPE_ACTION )){ item = NA_IFACTORY_OBJECT( na_object_action_new()); } else if( !strcmp( type, NADP_VALUE_TYPE_MENU )){ item = NA_IFACTORY_OBJECT( na_object_menu_new()); } else { /* i18n: 'type' is the nature of the item: Action or Menu */ na_core_utils_slist_add_message( messages, _( "unknown type: %s" ), type ); } if( item ){ id = nadp_desktop_file_get_id( ndf ); na_object_set_id( item, id ); g_free( id ); reader_data = g_new0( NadpReaderData, 1 ); reader_data->ndf = ndf; na_ifactory_provider_read_item( NA_IFACTORY_PROVIDER( provider ), reader_data, item, messages ); na_object_set_provider_data( item, ndf ); g_object_weak_ref( G_OBJECT( item ), ( GWeakNotify ) desktop_weak_notify, ndf ); g_free( reader_data ); } g_free( type ); return( item ); }
/* * actually writes the item to the existing CappDesktopFile * as we have chosen to take advantage of data factory management system * we do not need to enumerate each and every elementary data * * As we want keep comments between through multiple updates, we cannot * just delete the .desktop file and recreate it as we are doing for MateConf. * Instead of that, we delete at end groups that have not been walked through * -> as a side effect, we lose comments inside of these groups :( */ static guint write_item( const NAIIOProvider *provider, const NAObjectItem *item, CappDesktopFile *ndf, GSList **messages ) { static const gchar *thisfn = "cadp_iio_provider_write_item"; guint ret; CappDesktopProvider *self; g_debug( "%s: provider=%p (%s), item=%p (%s), ndf=%p, messages=%p", thisfn, ( void * ) provider, G_OBJECT_TYPE_NAME( provider ), ( void * ) item, G_OBJECT_TYPE_NAME( item ), ( void * ) ndf, ( void * ) messages ); ret = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR; g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), ret ); g_return_val_if_fail( CADP_IS_DESKTOP_PROVIDER( provider ), ret ); g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( provider ), ret ); g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), ret ); g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( item ), ret ); g_return_val_if_fail( CADP_IS_DESKTOP_FILE( ndf ), ret ); self = CADP_DESKTOP_PROVIDER( provider ); if( self->private->dispose_has_run ){ return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN ); } ret = NA_IIO_PROVIDER_CODE_OK; na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( provider ), ndf, NA_IFACTORY_OBJECT( item ), messages ); if( !cadp_desktop_file_write( ndf )){ ret = NA_IIO_PROVIDER_CODE_WRITE_ERROR; } return( ret ); }
static void read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderData *reader_data, const gchar *profile_id, GSList **messages ) { static const gchar *thisfn = "nadp_reader_read_done_action_load_profile"; NAObjectProfile *profile; g_debug( "%s: loading profile=%s", thisfn, profile_id ); profile = na_object_profile_new_with_defaults(); na_object_set_id( profile, profile_id ); if( nadp_desktop_file_has_profile( reader_data->ndf, profile_id )){ na_ifactory_provider_read_item( NA_IFACTORY_PROVIDER( provider ), reader_data, NA_IFACTORY_OBJECT( profile ), messages ); } else { g_warning( "%s: profile '%s' not found in .desktop file", thisfn, profile_id ); na_object_attach_profile( reader_data->action, profile ); } }
/** * cadp_writer_iexporter_export_to_file: * @instance: this #NAIExporter instance. * @parms: a #NAIExporterFileParmsv2 structure. * * Export the specified 'item' to a newly created file. */ guint cadp_writer_iexporter_export_to_file( const NAIExporter *instance, NAIExporterFileParmsv2 *parms ) { static const gchar *thisfn = "cadp_writer_iexporter_export_to_file"; guint code, write_code; gchar *id, *folder_path, *dest_path; ExportFormatFn *fmt; CappDesktopFile *ndf; g_debug( "%s: instance=%p, parms=%p", thisfn, ( void * ) instance, ( void * ) parms ); parms->basename = NULL; code = NA_IEXPORTER_CODE_OK; if( !parms->exported || !NA_IS_OBJECT_ITEM( parms->exported )){ code = NA_IEXPORTER_CODE_INVALID_ITEM; } if( code == NA_IEXPORTER_CODE_OK ){ #ifdef NA_ENABLE_DEPRECATED if( parms->version == 1 ){ fmt = find_export_format_fn_from_quark((( NAIExporterFileParms * ) parms )->format ); } else { fmt = find_export_format_fn( parms->format ); } #else fmt = find_export_format_fn( parms->format ); #endif if( !fmt ){ code = NA_IEXPORTER_CODE_INVALID_FORMAT; } else { id = na_object_get_id( parms->exported ); parms->basename = g_strdup_printf( "%s%s", id, CADP_DESKTOP_FILE_SUFFIX ); g_free( id ); folder_path = g_filename_from_uri( parms->folder, NULL, NULL ); dest_path = g_strdup_printf( "%s/%s", folder_path, parms->basename ); g_free( folder_path ); ndf = cadp_desktop_file_new_for_write( dest_path ); write_code = na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( instance ), ndf, NA_IFACTORY_OBJECT( parms->exported ), &parms->messages ); if( write_code != NA_IIO_PROVIDER_CODE_OK ){ code = NA_IEXPORTER_CODE_ERROR; } else if( !cadp_desktop_file_write( ndf )){ code = NA_IEXPORTER_CODE_UNABLE_TO_WRITE; } g_free( dest_path ); g_object_unref( ndf ); } } g_debug( "%s: returning code=%u", thisfn, code ); return( code ); }
/** * cadp_writer_iexporter_export_to_buffer: * @instance: this #NAIExporter instance. * @parms: a #NAIExporterBufferParmsv2 structure. * * Export the specified 'item' to a newly allocated buffer. */ guint cadp_writer_iexporter_export_to_buffer( const NAIExporter *instance, NAIExporterBufferParmsv2 *parms ) { static const gchar *thisfn = "cadp_writer_iexporter_export_to_buffer"; guint code, write_code; ExportFormatFn *fmt; GKeyFile *key_file; CappDesktopFile *ndf; g_debug( "%s: instance=%p, parms=%p", thisfn, ( void * ) instance, ( void * ) parms ); parms->buffer = NULL; code = NA_IEXPORTER_CODE_OK; if( !parms->exported || !NA_IS_OBJECT_ITEM( parms->exported )){ code = NA_IEXPORTER_CODE_INVALID_ITEM; } if( code == NA_IEXPORTER_CODE_OK ){ #ifdef NA_ENABLE_DEPRECATED if( parms->version == 1 ){ fmt = find_export_format_fn_from_quark((( NAIExporterBufferParms * ) parms )->format ); } else { fmt = find_export_format_fn( parms->format ); } #else fmt = find_export_format_fn( parms->format ); #endif if( !fmt ){ code = NA_IEXPORTER_CODE_INVALID_FORMAT; } else { ndf = cadp_desktop_file_new(); write_code = na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( instance ), ndf, NA_IFACTORY_OBJECT( parms->exported ), &parms->messages ); if( write_code != NA_IIO_PROVIDER_CODE_OK ){ code = NA_IEXPORTER_CODE_ERROR; } else { key_file = cadp_desktop_file_get_key_file( ndf ); parms->buffer = g_key_file_to_data( key_file, NULL, NULL ); } g_object_unref( ndf ); } } g_debug( "%s: returning code=%u", thisfn, code ); return( code ); }