/* * returns a list of DesktopPath items * * we get the ordered list of XDG_DATA_DIRS, and the ordered list of * subdirs to add; then for each item of each list, we search for * .desktop files in the resulted built path * * the returned list is so a list of DesktopPath struct, in * the ordered of preference (most preferred first) */ static GList * get_list_of_desktop_paths( NadpDesktopProvider *provider, GSList **messages ) { GList *files; GSList *xdg_dirs, *idir; GSList *subdirs, *isub; gchar *dir; files = NULL; xdg_dirs = nadp_xdg_dirs_get_data_dirs(); subdirs = na_core_utils_slist_from_split( NADP_DESKTOP_PROVIDER_SUBDIRS, G_SEARCHPATH_SEPARATOR_S ); /* explore each directory from XDG_DATA_DIRS */ for( idir = xdg_dirs ; idir ; idir = idir->next ){ /* explore each N-A candidate subdirectory for each XDG dir */ for( isub = subdirs ; isub ; isub = isub->next ){ dir = g_build_filename(( gchar * ) idir->data, ( gchar * ) isub->data, NULL ); nadp_desktop_provider_add_monitor( provider, dir ); get_list_of_desktop_files( provider, &files, dir, messages ); g_free( dir ); } } na_core_utils_slist_free( subdirs ); na_core_utils_slist_free( xdg_dirs ); return( files ); }
/* * This is implementation of NAIIOProvider::write_item method */ guint cadp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages ) { static const gchar *thisfn = "cadp_iio_provider_write_item"; guint ret; CappDesktopFile *ndf; gchar *path; gchar *userdir; gchar *id; gchar *bname; GSList *subdirs; gchar *fulldir; gboolean dir_ok; ret = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR; g_return_val_if_fail( CADP_IS_DESKTOP_PROVIDER( provider ), ret ); g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), ret ); if( na_object_is_readonly( item )){ g_warning( "%s: item=%p is read-only", thisfn, ( void * ) item ); return( ret ); } ndf = ( CappDesktopFile * ) na_object_get_provider_data( item ); /* write into the current key file and write it to current path */ if( ndf ){ g_return_val_if_fail( CADP_IS_DESKTOP_FILE( ndf ), ret ); } else { userdir = cadp_xdg_dirs_get_user_data_dir(); subdirs = na_core_utils_slist_from_split( CADP_DESKTOP_PROVIDER_SUBDIRS, G_SEARCHPATH_SEPARATOR_S ); fulldir = g_build_filename( userdir, ( gchar * ) subdirs->data, NULL ); dir_ok = TRUE; if( !g_file_test( fulldir, G_FILE_TEST_IS_DIR )){ if( g_mkdir_with_parents( fulldir, 0750 )){ g_warning( "%s: %s: %s", thisfn, userdir, g_strerror( errno )); dir_ok = FALSE; } else { na_core_utils_dir_list_perms( userdir, thisfn ); } } g_free( userdir ); na_core_utils_slist_free( subdirs ); if( dir_ok ){ id = na_object_get_id( item ); bname = g_strdup_printf( "%s%s", id, CADP_DESKTOP_FILE_SUFFIX ); g_free( id ); path = g_build_filename( fulldir, bname, NULL ); g_free( bname ); } g_free( fulldir ); if( dir_ok ){ ndf = cadp_desktop_file_new_for_write( path ); na_object_set_provider_data( item, ndf ); g_object_weak_ref( G_OBJECT( item ), ( GWeakNotify ) desktop_weak_notify, ndf ); g_free( path ); } } if( ndf ){ ret = write_item( provider, item, ndf, messages ); } return( ret ); }