/* * nagp_iio_provider_read_items: * * Note that whatever be the version of the read action, it will be * stored as a #NAObjectAction and its set of #NAObjectProfile of the same, * latest, version of these classes. */ GList * nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages ) { static const gchar *thisfn = "nagp_reader_nagp_iio_provider_read_items"; NagpGConfProvider *self; GList *items_list = NULL; GSList *listpath, *ip; NAObjectItem *item; g_debug( "%s: provider=%p, messages=%p", thisfn, ( void * ) provider, ( void * ) messages ); g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL ); g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider ), NULL ); self = NAGP_GCONF_PROVIDER( provider ); if( !self->private->dispose_has_run ){ listpath = na_gconf_utils_get_subdirs( self->private->gconf, NAGP_CONFIGURATIONS_PATH ); for( ip = listpath ; ip ; ip = ip->next ){ item = read_item( self, ( const gchar * ) ip->data, messages ); if( item ){ items_list = g_list_prepend( items_list, item ); na_object_dump( item ); } } na_gconf_utils_free_subdirs( listpath ); } g_debug( "%s: count=%d", thisfn, g_list_length( items_list )); return( items_list ); }
/* * Implementation of NAIIOProvider::duplicate_data * Add a ref on CappDesktopFile data, so that unreffing origin object in CACT * does not invalid duplicated pointer */ guint cadp_iio_provider_duplicate_data( const NAIIOProvider *provider, NAObjectItem *dest, const NAObjectItem *source, GSList **messages ) { static const gchar *thisfn = "cadp_iio_provider_duplicate_data"; guint ret; CappDesktopProvider *self; CappDesktopFile *ndf; g_debug( "%s: provider=%p (%s), dest=%p (%s), source=%p (%s), messages=%p", thisfn, ( void * ) provider, G_OBJECT_TYPE_NAME( provider ), ( void * ) dest, G_OBJECT_TYPE_NAME( dest ), ( void * ) source, G_OBJECT_TYPE_NAME( source ), ( 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_OBJECT_ITEM( dest ), ret ); g_return_val_if_fail( NA_IS_OBJECT_ITEM( source ), ret ); self = CADP_DESKTOP_PROVIDER( provider ); if( self->private->dispose_has_run ){ return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN ); } ndf = ( CappDesktopFile * ) na_object_get_provider_data( source ); g_return_val_if_fail( ndf && CADP_IS_DESKTOP_FILE( ndf ), ret ); na_object_set_provider_data( dest, g_object_ref( ndf )); g_object_weak_ref( G_OBJECT( dest ), ( GWeakNotify ) desktop_weak_notify, ndf ); return( NA_IIO_PROVIDER_CODE_OK ); }
/* * Returns an unordered list of NAIFactoryObject-derived objects * * This is implementation of NAIIOProvider::read_items method */ GList * nadp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages ) { static const gchar *thisfn = "nadp_iio_provider_read_items"; GList *items; GList *desktop_paths, *ip; NAIFactoryObject *item; g_debug( "%s: provider=%p (%s), messages=%p", thisfn, ( void * ) provider, G_OBJECT_TYPE_NAME( provider ), ( void * ) messages ); g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL ); items = NULL; nadp_desktop_provider_release_monitors( NADP_DESKTOP_PROVIDER( provider )); desktop_paths = get_list_of_desktop_paths( NADP_DESKTOP_PROVIDER( provider ), messages ); for( ip = desktop_paths ; ip ; ip = ip->next ){ item = item_from_desktop_path( NADP_DESKTOP_PROVIDER( provider ), ( DesktopPath * ) ip->data, messages ); if( item ){ items = g_list_prepend( items, item ); na_object_dump( item ); } } free_desktop_paths( desktop_paths ); g_debug( "%s: count=%d", thisfn, g_list_length( items )); return( items ); }
/* * 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 ); }
guint cadp_iio_provider_delete_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages ) { static const gchar *thisfn = "cadp_iio_provider_delete_item"; guint ret; CappDesktopProvider *self; CappDesktopFile *ndf; gchar *uri; g_debug( "%s: provider=%p (%s), item=%p (%s), messages=%p", thisfn, ( void * ) provider, G_OBJECT_TYPE_NAME( provider ), ( void * ) item, G_OBJECT_TYPE_NAME( item ), ( 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_OBJECT_ITEM( item ), ret ); self = CADP_DESKTOP_PROVIDER( provider ); if( self->private->dispose_has_run ){ return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN ); } ndf = ( CappDesktopFile * ) na_object_get_provider_data( item ); if( ndf ){ g_return_val_if_fail( CADP_IS_DESKTOP_FILE( ndf ), ret ); uri = cadp_desktop_file_get_key_file_uri( ndf ); if( cadp_utils_uri_delete( uri )){ ret = NA_IIO_PROVIDER_CODE_OK; } g_free( uri ); } else { g_warning( "%s: CappDesktopFile is null", thisfn ); ret = NA_IIO_PROVIDER_CODE_OK; } return( ret ); }
/* * 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 ); }