Пример #1
0
static void
write_done_write_subitems_list( CappDesktopFile *ndp, NAObjectItem *item )
{
	static const gchar *thisfn = "cadp_writer_write_done_write_subitems_list";
	GSList *subitems;
	GSList *profile_groups, *ip;
	gchar *tmp;

	subitems = na_object_get_items_slist( item );
	tmp = g_strdup_printf( "%s (written subitems)", thisfn );
	na_core_utils_slist_dump( tmp, subitems );
	g_free( tmp );

	cadp_desktop_file_set_string_list(
			ndp,
			CADP_GROUP_DESKTOP,
			NA_IS_OBJECT_ACTION( item ) ? CADP_KEY_PROFILES : CADP_KEY_ITEMS_LIST,
			subitems );

	profile_groups = cadp_desktop_file_get_profiles( ndp );
	tmp = g_strdup_printf( "%s (existing profiles)", thisfn );
	na_core_utils_slist_dump( tmp, profile_groups );
	g_free( tmp );

	for( ip = profile_groups ; ip ; ip = ip->next ){
		if( na_core_utils_slist_count( subitems, ( const gchar * ) ip->data ) == 0 ){
			g_debug( "%s: deleting (removed) profile %s", thisfn, ( const gchar * ) ip->data );
			cadp_desktop_file_remove_profile( ndp, ( const gchar * ) ip->data );
		}
	}

	na_core_utils_slist_free( profile_groups );
	na_core_utils_slist_free( subitems );
}
Пример #2
0
/*
 * 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 );
}
Пример #3
0
/*
 * Each NAIImporter interface may return some messages, specially if it
 * recognized but is not able to import the provided URI. But as long
 * we do not have yet asked to all available interfaces, we are not sure
 * of whether this URI is eventually importable or not.
 *
 * We so let each interface push its messages in the list, but be ready to
 * only keep the messages provided by the interface which has successfully
 * imported the item.
 */
static NAImporterResult *
import_from_uri( const NAPivot *pivot, GList *modules, const gchar *uri )
{
	NAImporterResult *result;
	NAIImporterImportFromUriParmsv2 provider_parms;
	GList *im;
	guint code;
	GSList *all_messages;
	NAIImporter *provider;

	result = NULL;
	all_messages = NULL;
	provider = NULL;
	code = IMPORTER_CODE_NOT_WILLING_TO;

	memset( &provider_parms, '\0', sizeof( NAIImporterImportFromUriParmsv2 ));
	provider_parms.version = 2;
	provider_parms.content = 1;
	provider_parms.uri = uri;

	for( im = modules ;
			im && ( code == IMPORTER_CODE_NOT_WILLING_TO || code == IMPORTER_CODE_NOT_LOADABLE ) ;
			im = im->next ){

		code = na_iimporter_import_from_uri( NA_IIMPORTER( im->data ), &provider_parms );

		if( code == IMPORTER_CODE_NOT_WILLING_TO ){
			all_messages = g_slist_concat( all_messages, provider_parms.messages );
			provider_parms.messages = NULL;

		} else if( code == IMPORTER_CODE_NOT_LOADABLE ){
			na_core_utils_slist_free( all_messages );
			all_messages = NULL;
			na_core_utils_slist_free( provider_parms.messages );
			provider_parms.messages = NULL;
			na_core_utils_slist_add_message( &all_messages, ERR_NOT_LOADABLE, ( const gchar * ) uri );

		} else {
			na_core_utils_slist_free( all_messages );
			all_messages = provider_parms.messages;
			provider = NA_IIMPORTER( im->data );
		}
	}

	result = g_new0( NAImporterResult, 1 );
	result->uri = g_strdup( uri );
	result->imported = provider_parms.imported;
	result->importer = provider;
	result->messages = all_messages;

	return( result );
}
Пример #4
0
/*
 * Read and attach profiles in the specified order
 * - profiles which may exist in .desktop files, but are not referenced
 *   in the 'Profiles' string list are just ignored
 * - profiles which may be referenced in the action string list, but are not
 *   found in the .desktop file are recreated with default values (plus a warning)
 * - ensure that there is at least one profile attached to the action
 */
static void
read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *reader_data, GSList **messages )
{
	static const gchar *thisfn = "nadp_reader_read_done_action_read_profiles";
	GSList *order;
	GSList *ip;
	gchar *profile_id;
	NAObjectId *found;
	NAObjectProfile *profile;

	reader_data->action = action;
	order = na_object_get_items_slist( action );

	for( ip = order ; ip ; ip = ip->next ){
		profile_id = ( gchar * ) ip->data;
		found = na_object_get_item( action, profile_id );
		if( !found ){
			read_done_action_load_profile( provider, reader_data, profile_id, messages );
		}
	}

	na_core_utils_slist_free( order );

	if( !na_object_get_items_count( action )){
		g_warning( "%s: no profile found in .desktop file", thisfn );
		profile = na_object_profile_new_with_defaults();
		na_object_attach_profile( action, profile );
	}
}
Пример #5
0
/*
 * na_importer_free_result:
 * @result: the #NAImporterResult structure to be released.
 *
 * Release the structure.
 */
void
na_importer_free_result( NAImporterResult *result )
{
	g_free( result->uri );
	na_core_utils_slist_free( result->messages );

	g_free( result );
}
Пример #6
0
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 );
}
Пример #7
0
/**
 * na_core_utils_str_add_prefix:
 * @prefix: the prefix to be prepended.
 * @str: a multiline string.
 *
 * Appends a prefix to each line of the string.
 *
 * Returns: a new string which should be g_free() by the caller.
 *
 * Since: 2.30
 * Deprecated: 3.2
 */
gchar *
na_core_utils_str_add_prefix( const gchar *prefix, const gchar *str )
{
	GSList *list, *il;
	GString *result;

	list = text_to_string_list( str, "\n", NULL );
	result = g_string_new( "" );

	for( il = list ; il ; il = il->next ){
		g_string_append_printf( result, "%s%s\n", prefix, ( gchar * ) il->data );
	}

	na_core_utils_slist_free( list );

	return( g_string_free( result, FALSE ));
}
/*
 * displays the specified item on stdout, in the specified export format
 */
static void
export_item( const NAObjectItem *item, const gchar *format )
{
	GSList *messages = NULL;
	GSList *it;

	gchar *buffer = na_exporter_to_buffer( pivot, item, format, &messages );

	for( it = messages ; it ; it = it->next ){
		g_printerr( "%s\n", ( const gchar * ) it->data );
	}
	na_core_utils_slist_free( messages );

	if( buffer ){
		g_printf( "%s\n", buffer );
		g_free( buffer );
	}
}
Пример #9
0
static void
read_start_read_subitems_key( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages )
{
	GSList *subitems;
	gboolean key_found;

	subitems = nadp_desktop_file_get_string_list( reader_data->ndf,
			NADP_GROUP_DESKTOP,
			NA_IS_OBJECT_ACTION( item ) ? NADP_KEY_PROFILES : NADP_KEY_ITEMS_LIST,
			&key_found,
			NULL );

	if( key_found ){
		na_object_set_items_slist( item, subitems );
	}

	na_core_utils_slist_free( subitems );
}
Пример #10
0
/**
 * cact_providers_list_save:
 * @window: the #BaseWindow which embeds this treeview.
 *
 * Save the I/O provider status as a user preference.
 */
void
cact_providers_list_save( BaseWindow *window )
{
	static const gchar *thisfn = "cact_providers_list_save";
	GtkTreeView *treeview;
	GtkTreeModel *model;
	ProvidersListSaveData *plsd;

	g_debug( "%s: window=%p", thisfn, ( void * ) window );

	plsd = g_new0( ProvidersListSaveData, 1 );
	plsd->order = NULL;

	treeview = GTK_TREE_VIEW( g_object_get_data( G_OBJECT( window ), PROVIDERS_LIST_TREEVIEW ));
	model = gtk_tree_view_get_model( treeview );
	gtk_tree_model_foreach( model, ( GtkTreeModelForeachFunc ) providers_list_save_iter, plsd );

	plsd->order = g_slist_reverse( plsd->order );
	na_settings_set_string_list( NA_IPREFS_IO_PROVIDERS_WRITE_ORDER, plsd->order );

	na_core_utils_slist_free( plsd->order );
	g_free( plsd );
}
Пример #11
0
int
main( int argc, char **argv )
{
	NAImporterParms parms;
	GList *import_results;
	NAImporterResult *result;

#if !GLIB_CHECK_VERSION( 2,36, 0 )
	g_type_init();
#endif

	GOptionContext *context = init_options();
	check_options( argc, argv, context );

	NAPivot *pivot = na_pivot_new();
	na_pivot_set_loadable( pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID );
	na_pivot_load_items( pivot );

	parms.uris = g_slist_prepend( NULL, uri );
	parms.check_fn = NULL;
	parms.check_fn_data = NULL;
	parms.preferred_mode = IMPORTER_MODE_ASK;
	parms.parent_toplevel = NULL;

	import_results = na_importer_import_from_uris( pivot, &parms );

	result = import_results->data;
	if( result->imported ){
		na_object_dump( result->imported );
		g_object_unref( result->imported );
	}

	na_core_utils_slist_dump( NULL, result->messages );
	na_core_utils_slist_free( result->messages );

	return( 0 );
}
Пример #12
0
/*
 * allocate a new action, and fill it with values read from command-line
 */
static NAObjectAction *
get_action_from_cmdline( void )
{
	NAObjectAction *action;
	NAObjectProfile *profile;
	int i;
	GSList *basenames;
	GSList *mimetypes;
	GSList *schemes;
	GSList *folders;
	gboolean toolbar_same_label;
	gchar *msg;
	GSList *only_show_in;
	GSList *not_show_in;
	GSList *capabilities;

	action = na_object_action_new_with_defaults();
	profile = NA_OBJECT_PROFILE(( GList * ) na_object_get_items( action )->data );

	na_object_set_label( action, label );
	if( tooltip && g_utf8_strlen( tooltip, -1 )){
		na_object_set_tooltip( action, tooltip );
	}
	if( icon && g_utf8_strlen( icon, -1 )){
		na_object_set_icon( action, icon );
	}
	na_object_set_enabled( action, enabled );
	na_object_set_target_selection( action, target_selection );
	na_object_set_target_location( action, target_location );
	na_object_set_target_toolbar( action, target_toolbar );

	toolbar_same_label = FALSE;
	if( !label_toolbar || !g_utf8_strlen( label_toolbar, -1 )){
		label_toolbar = g_strdup( label );
		toolbar_same_label = TRUE;
	}
	na_object_set_toolbar_same_label( action, toolbar_same_label );
	na_object_set_toolbar_label( action, label_toolbar );

	na_object_set_path( profile, command );
	na_object_set_parameters( profile, parameters );

	i = 0;
	basenames = NULL;
	while( basenames_array != NULL && basenames_array[i] != NULL ){
		basenames = g_slist_append( basenames, g_strdup( basenames_array[i] ));
		i++;
	}
	if( basenames && g_slist_length( basenames )){
		na_object_set_basenames( profile, basenames );
		na_core_utils_slist_free( basenames );
	}

	na_object_set_matchcase( profile, matchcase );

	mimetypes = NULL;
	if( isfile ){
		msg = g_strdup_printf( DEPRECATED, "accept-files", "mimetype" );
		g_warning( "%s", msg );
		g_free( msg );
	}
	if( isdir ){
		msg = g_strdup_printf( DEPRECATED, "accept-dirs", "mimetype" );
		g_warning( "%s", msg );
		g_free( msg );
	}
	if( isfile && !isdir ){
		mimetypes = g_slist_prepend( mimetypes, g_strdup( "all/allfiles" ));
	} else if( isdir && !isfile ){
		mimetypes = g_slist_prepend( mimetypes, g_strdup( "inode/directory" ));
	}
	i = 0;
	while( mimetypes_array != NULL && mimetypes_array[i] != NULL ){
		mimetypes = g_slist_append( mimetypes, g_strdup( mimetypes_array[i] ));
		i++;
	}
	if( mimetypes && g_slist_length( mimetypes )){
		na_object_set_mimetypes( profile, mimetypes );
		na_core_utils_slist_free( mimetypes );
	}

	if( accept_multiple ){
		msg = g_strdup_printf( DEPRECATED, "accept-multiple", "selection-count" );
		g_warning( "%s", msg );
		g_free( msg );
		selection_count = g_strdup( ">0" );
	}
	if( strlen( selection_count )){
		na_object_set_selection_count( profile, selection_count );
	}

	i = 0;
	schemes = NULL;
	while( schemes_array != NULL && schemes_array[i] != NULL ){
		schemes = g_slist_append( schemes, g_strdup( schemes_array[i] ));
		i++;
	}
	if( schemes && g_slist_length( schemes )){
		na_object_set_schemes( profile, schemes );
		na_core_utils_slist_free( schemes );
	}

	i = 0;
	folders = NULL;
	while( folders_array != NULL && folders_array[i] != NULL ){
		folders = g_slist_append( folders, g_strdup( folders_array[i] ));
		i++;
	}
	if( folders && g_slist_length( folders )){
		na_object_set_folders( profile, folders );
		na_core_utils_slist_free( folders );
	}

	if( onlyshow_array ){
		only_show_in = NULL;
		for( i = 0 ; onlyshow_array[i] && strlen( onlyshow_array[i] ) ; ++i ){
			only_show_in = g_slist_append( only_show_in, g_strdup( onlyshow_array[i] ));
		}
		if( only_show_in && g_slist_length( only_show_in )){
			na_object_set_only_show_in( profile, only_show_in );
			na_core_utils_slist_free( only_show_in );
		}
	}

	if( notshow_array ){
		not_show_in = NULL;
		for( i = 0 ; notshow_array[i] && strlen( notshow_array[i] ) ; ++i ){
			not_show_in = g_slist_append( not_show_in, g_strdup( notshow_array[i] ));
		}
		if( not_show_in && g_slist_length( not_show_in )){
			na_object_set_not_show_in( profile, not_show_in );
			na_core_utils_slist_free( not_show_in );
		}
	}

	if( try_exec && strlen( try_exec )){
		na_object_set_try_exec( profile, try_exec );
	}

	if( show_registered && strlen( show_registered )){
		na_object_set_show_if_registered( profile, show_registered );
	}

	if( show_true && strlen( show_true )){
		na_object_set_show_if_true( profile, show_true );
	}

	if( show_running && strlen( show_running )){
		na_object_set_show_if_running( profile, show_running );
	}

	if( capability_array ){
		capabilities = NULL;
		for( i = 0 ; capability_array[i] && strlen( capability_array[i] ) ; ++i ){
			const gchar *cap = ( const gchar * ) capability_array[i];
			/* 'Owner', 'Readable', 'Writable', 'Executable' and 'Local' */
			if( strcmp( cap, "Owner" ) &&
				strcmp( cap, "Readable" ) &&
				strcmp( cap, "Writable" ) &&
				strcmp( cap, "Executable" ) &&
				strcmp( cap, "Local" )){
					g_warning( "%s: unknown capability", cap );
			}  else {
				capabilities = g_slist_append( capabilities, g_strdup( capability_array[i] ));
			}
		}
		if( capabilities && g_slist_length( capabilities )){
			na_object_set_capabilities( profile, capabilities );
			na_core_utils_slist_free( capabilities );
		}
	}

	return( action );
}
Пример #13
0
int
main( int argc, char** argv )
{
	int status = EXIT_SUCCESS;
	GOptionContext *context;
	GError *error = NULL;
	NAObjectAction *action;
	GSList *msg = NULL;
	GSList *im;
	gchar *help;
	gint errors;

#if !GLIB_CHECK_VERSION( 2,36, 0 )
	g_type_init();
#endif

	setlocale( LC_ALL, "" );
	console_init_log_handler();

	context = init_options();

	if( argc == 1 ){
		g_set_prgname( argv[0] );
		help = g_option_context_get_help( context, FALSE, NULL );
		g_print( "\n%s", help );
		g_free( help );
		exit( status );
	}

	if( !g_option_context_parse( context, &argc, &argv, &error )){
		g_printerr( _( "Syntax error: %s\n" ), error->message );
		g_error_free (error);
		exit_with_usage();
	}

	if( version ){
		na_core_utils_print_version();
		exit( status );
	}

	errors = 0;

	if( !label || !g_utf8_strlen( label, -1 )){
		g_printerr( _( "Error: an action label is mandatory.\n" ));
		errors += 1;
	}

	if( enabled && disabled ){
		g_printerr( CANNOT_BOTH, "--enabled", "--disabled" );
		errors += 1;
	} else if( !disabled ){
		enabled = TRUE;
	}

	if( target_selection && nocontext ){
		g_printerr( CANNOT_BOTH, "--context", "--nocontext" );
		errors += 1;
	} else if( !nocontext ){
		target_selection = TRUE;
	}

	if( target_location && nolocation ){
		g_printerr( CANNOT_BOTH, "--location", "--nolocation" );
		errors += 1;
	}

	if( target_toolbar && notoolbar ){
		g_printerr( CANNOT_BOTH, "--toolbar", "--notoolbar" );
		errors += 1;
	}

	if( matchcase && nocase ){
		g_printerr( CANNOT_BOTH, "--match-case", "--nocase" );
		errors += 1;
	} else if( !nocase ){
		matchcase = TRUE;
	}

	if( accept_multiple && strlen( selection_count )){
		g_printerr( CANNOT_BOTH, "--accept-multiple", "--selection-count" );
		errors += 1;
	}

	if( onlyshow_array && notshow_array ){
		g_printerr( CANNOT_BOTH, "--only-show-in", "--not-show-in" );
		errors += 1;
	}

	if( output_stdout && output_desktop ){
		g_printerr( _( "Error: only one output option may be specified.\n" ));
		errors += 1;
	}

	if( errors ){
		exit_with_usage();
	}

	action = get_action_from_cmdline();

	if( output_desktop ){
		output_to_desktop( action, &msg );
	} else {
		output_to_stdout( action, &msg );
	}

	if( msg ){
		for( im = msg ; im ; im = im->next ){
			g_printerr( "%s\n", ( gchar * ) im->data );
		}
		na_core_utils_slist_free( msg );
		status = EXIT_FAILURE;
	}

	g_object_unref( action );
	g_option_context_free( context );

	exit( status );
}
Пример #14
0
/*
 * 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 );
}
Пример #15
0
/*
 * 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 );
}
Пример #16
0
/*
 * 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 );
}