Exemplo n.º 1
0
/*
 * 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 );
}
Exemplo n.º 2
0
void
nagp_reader_read_done( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, GSList **messages  )
{
	static const gchar *thisfn = "nagp_reader_read_done";
	gboolean writable;

	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( provider ));
	g_return_if_fail( NAGP_IS_GCONF_PROVIDER( provider ));
	g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));

	if( !NAGP_GCONF_PROVIDER( provider )->private->dispose_has_run ){

		g_debug( "%s: provider=%p (%s), reader_data=%p, object=%p (%s), messages=%p",
				thisfn,
				( void * ) provider, G_OBJECT_TYPE_NAME( provider ),
				( void * ) reader_data,
				( void * ) object, G_OBJECT_TYPE_NAME( object ),
				( void * ) messages );

		if( NA_IS_OBJECT_ITEM( object )){
			writable = read_done_item_is_writable( provider, NA_OBJECT_ITEM( object ), ( ReaderData * ) reader_data, messages );
			na_object_set_readonly( object, !writable );
		}

		if( NA_IS_OBJECT_ACTION( object )){
			read_done_action_read_profiles( provider, NA_OBJECT_ACTION( object ), ( ReaderData * ) reader_data, messages );
		}

		g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
	}
}
Exemplo n.º 3
0
/*
 * write the new item as a .desktop file
 */
static gboolean
output_to_desktop( NAObjectAction *action, GSList **msgs )
{
	NAUpdater *updater;
	NAIOProvider *provider;
	guint ret;
	gboolean code;

	updater = na_updater_new();
	provider = na_io_provider_find_io_provider_by_id( NA_PIVOT( updater ), "na-desktop" );

	if( provider ){
		na_object_set_provider( action, provider );
		ret = na_updater_write_item( updater, NA_OBJECT_ITEM( action ), msgs );
		code = ( ret == NA_IIO_PROVIDER_CODE_OK );

	} else {
		/* i18n: 'na-desktop' is a plugin identifier - do not translate */
		*msgs = g_slist_append( *msgs, _( "Error: unable to find 'na-desktop' i/o provider." ));
		code = FALSE;
	}

	g_object_unref( updater );

	return( code );
}
Exemplo n.º 4
0
/*
 * called when each NAIFactoryObject object has been read
 */
void
nadp_reader_ifactory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
{
	static const gchar *thisfn = "nadp_reader_ifactory_provider_read_done";
	gboolean writable;

	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));

	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){

		g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
				thisfn,
				( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
				( void * ) reader_data,
				( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
				( void * ) messages );

		if( NA_IS_OBJECT_ITEM( serializable )){
			writable = read_done_item_is_writable( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
			na_object_set_readonly( serializable, !writable );
		}

		if( NA_IS_OBJECT_ACTION( serializable )){
			read_done_action_read_profiles( reader, NA_OBJECT_ACTION( serializable ), ( NadpReaderData * ) reader_data, messages );
		}

		g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( serializable ), ( void * ) serializable );
	}
}
Exemplo n.º 5
0
/*
 * at this time, the object has been allocated and its id has been set
 * read here the subitems key, which may be 'Profiles' or 'ItemsList'
 * depending of the exact class of the NAObjectItem
 */
void
nadp_reader_ifactory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
{
	static const gchar *thisfn = "nadp_reader_ifactory_provider_read_start";

	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));

	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){

		g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
				thisfn,
				( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
				( void * ) reader_data,
				( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
				( void * ) messages );

		if( NA_IS_OBJECT_ITEM( serializable )){
			read_start_read_subitems_key( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
			na_object_set_iversion( serializable, 3 );
		}

		if( NA_IS_OBJECT_PROFILE( serializable )){
			read_start_profile_attach_profile( reader, NA_OBJECT_PROFILE( serializable ), ( NadpReaderData * ) reader_data, messages );
		}
	}
}
Exemplo n.º 6
0
guint
cadp_writer_ifactory_provider_write_done( const NAIFactoryProvider *provider, void *writer_data,
							const NAIFactoryObject *object, GSList **messages  )
{
	if( NA_IS_OBJECT_ITEM( object )){
		write_done_write_subitems_list( CADP_DESKTOP_FILE( writer_data ), NA_OBJECT_ITEM( object ));
	}

	return( NA_IIO_PROVIDER_CODE_OK );
}
Exemplo n.º 7
0
static void
read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages )
{
	static const gchar *thisfn = "nagp_reader_read_done_action_read_profiles";
	GSList *order;
	GSList *list_profiles;
	GSList *ip;
	gchar *profile_id;
	gchar *profile_path;
	NAObjectId *found;
	NAObjectProfile *profile;

	data->parent = NA_OBJECT_ITEM( action );
	order = na_object_get_items_slist( action );
	list_profiles = na_gconf_utils_get_subdirs( NAGP_GCONF_PROVIDER( provider )->private->gconf, data->path );

	/* read profiles in the specified order
	 * as a protection against bugs in NACT, we check that profile has not
	 * already been loaded
	 */
	for( ip = order ; ip ; ip = ip->next ){
		profile_id = ( gchar * ) ip->data;
		found = na_object_get_item( action, profile_id );
		if( !found ){
			g_debug( "nagp_reader_read_done_action: loading profile=%s", profile_id );
			profile_path = gconf_concat_dir_and_key( data->path, profile_id );
			read_done_action_load_profile( provider, data, profile_path, messages );
			g_free( profile_path );
		}
	}

	/* append other profiles
	 * this is mandatory for pre-2.29 actions which introduced order of profiles
	 */
	for( ip = list_profiles ; ip ; ip = ip->next ){
		profile_id = g_path_get_basename(( const gchar * ) ip->data );
		found = na_object_get_item( action, profile_id );
		if( !found ){
			g_debug( "nagp_reader_read_done_action: loading profile=%s", profile_id );
			read_done_action_load_profile( provider, data, ( const gchar * ) ip->data, messages );
		}
		g_free( profile_id );
	}

	/* make sure we have at least one profile
	 */
	if( !na_object_get_items_count( action )){
		g_warning( "%s: no profile found in GConf backend", thisfn );
		profile = na_object_profile_new_with_defaults();
		na_object_attach_profile( action, profile );
	}
}
Exemplo n.º 8
0
static gboolean
output_to_stdout( const NAObjectAction *action, GSList **msgs )
{
	gboolean ret;
	NAUpdater *updater;
	gchar *buffer;

	updater = na_updater_new();
	buffer = na_exporter_to_buffer( NA_PIVOT( updater ), NA_OBJECT_ITEM( action ), "Desktop1", msgs );
	ret = ( buffer != NULL );

	if( buffer ){
		g_printf( "%s", buffer );
		g_free( buffer );
	}

	g_object_unref( updater );

	return( ret );
}
Exemplo n.º 9
0
/*
 * First check here for duplicates inside of imported population,
 * then delegates to the caller-provided check function the rest of work...
 */
static NAObjectItem *
is_importing_already_exists( NAImporterParms *parms, GList *results, NAImporterResult *result )
{
	static const gchar *thisfn = "na_importer_is_importing_already_exists";
	NAObjectItem *exists;
	GList *ip;

	exists = NULL;

	gchar *importing_id = na_object_get_id( result->imported );
	g_debug( "%s: importing=%p, id=%s", thisfn, ( void * ) result->imported, importing_id );

	/* is the importing item already in the current importation list ?
	 * (only tries previous items of the list)
	 */
	for( ip = results ; ip && !exists && ip->data != result ; ip = ip->next ){
		NAImporterResult *try_result = ( NAImporterResult * ) ip->data;

		if( try_result->imported ){
			g_return_val_if_fail( NA_IS_OBJECT_ITEM( try_result->imported ), NULL );

			gchar *id = na_object_get_id( try_result->imported );
			if( !strcmp( importing_id, id )){
				exists = NA_OBJECT_ITEM( try_result->imported );
			}
			g_free( id );
		}
	}

	g_free( importing_id );

	/* if not found in our current importation list,
	 * then check the existence via provided function and data
	 */
	if( !exists ){
		exists = parms->check_fn( result->imported, parms->check_fn_data );
	}

	return( exists );
}