Exemple #1
0
/**
   Find at most one file relative to the XDG data directories.
*/
static char *get_filename( char *f )
{
    array_list_t list;
    char *first = NULL;

    al_init( &list );
    append_filenames( &list, f, 0 );
    first = al_pop( &list );
    al_destroy( &list );
    return first;
}
Exemple #2
0
/**
   Find at most one file relative to the XDG data directories; returns the empty string on failure
*/
static std::string get_filename( char *f )
{
    string_list_t list;

	append_filenames( list, f, 0 );
    if (list.empty()) {
        return "";
    } else {
        return list.back();
    }
}
Exemple #3
0
/**
   Get default action for a specified mimetype.
*/
static char *get_action( const char *mimetype )
{
    char *res=0;
    int i;

    char *launcher;
    char *end;
    array_list_t mime_filenames;

    char *launcher_str = NULL;
    char *launcher_filename, *launcher_command_str, *launcher_command;
    char *launcher_full;

    al_init( &mime_filenames );
    if( !append_filenames( &mime_filenames, DESKTOP_DEFAULT, 1 ) )
    {
        al_destroy( &mime_filenames );
        return 0;
    }

    for ( i = 0; i < al_get_count( &mime_filenames ); i++ )
    {
        launcher_str = search_ini( al_get( &mime_filenames, i ), mimetype );
        if ( launcher_str )
            break;
    }

    al_foreach( &mime_filenames, free );
    al_destroy( &mime_filenames );

    if( !launcher_str )
    {
        /*
          This type does not have a launcher. Try the supertype!
        */
//		fprintf( stderr, "mimedb: %s does not have launcher, try supertype\n", mimetype );
        const char ** parents = xdg_mime_get_mime_parents(mimetype);

        const char **p;
        if( parents )
        {
            for( p=parents; *p; p++ )
            {
                char *a = get_action(*p);
                if( a != 0 )
                    return a;
            }
        }
        /*
          Just in case subclassing doesn't work, (It doesn't on Fedora
          Core 3) we also test some common subclassings.
        */

        if( strncmp( mimetype, "text/plain", 10) != 0 && strncmp( mimetype, "text/", 5 ) == 0 )
            return get_action( "text/plain" );

        return 0;
    }

//	fprintf( stderr, "WOOT %s\n", launcher_str );
    launcher = strchr( launcher_str, '=' );

    if( !launcher )
    {
        fprintf( stderr, _("%s: Could not parse launcher string '%s'\n"), MIMEDB, launcher_str );
        error=1;
        return 0;
    }

    /* Skip the = */
    launcher++;

    /* Only use first launcher */
    end = strchr( launcher, ';' );
    if( end )
        *end = '\0';

    launcher_full = my_malloc( strlen( launcher) + strlen( APPLICATIONS_DIR)+1 );
    if( !launcher_full )
    {
        free( launcher_str );
        return 0;
    }

    strcpy( launcher_full, APPLICATIONS_DIR );
    strcat( launcher_full, launcher );
    free( launcher_str );

    launcher_filename = get_filename( launcher_full );

    free( launcher_full );

    launcher_command_str = search_ini( launcher_filename, "Exec" );

    if( !launcher_command_str )
    {
        fprintf( stderr,
                 _( "%s: Default launcher '%s' does not specify how to start\n"), MIMEDB,
                 launcher_filename );
        free( launcher_filename );
        return 0;
    }

    free( launcher_filename );

    launcher_command = strchr( launcher_command_str, '=' );
    launcher_command++;

    res = my_strdup( launcher_command );

    free( launcher_command_str );

    return res;
}
Exemple #4
0
/**
   Get default action for a specified mimetype. 
*/
static char *get_action( const char *mimetype )
{
	char *res=0;
	
	const char *launcher, *end;
	string_list_t mime_filenames;
	
	const char *launcher_str = NULL;
	const char *launcher_command_str, *launcher_command;
	char *launcher_full;
	
	if( !append_filenames( mime_filenames, DESKTOP_DEFAULT, 1 ) )
	{
		return 0;
	}
	
	for ( size_t i = 0; i < mime_filenames.size(); i++ )
	{
		launcher_str = search_ini( mime_filenames.at(i).c_str(), mimetype );
		if ( launcher_str )
			break;
	}

	
	if( !launcher_str )
	{
		/*
		  This type does not have a launcher. Try the supertype!
		*/
//		fprintf( stderr, "mimedb: %s does not have launcher, try supertype\n", mimetype );	
		const char ** parents = xdg_mime_get_mime_parents(mimetype);
		
		const char **p;
		if( parents )
		{
			for( p=parents; *p; p++ )
			{
				char *a = get_action(*p);
				if( a != 0 )
					return a;
			}
		}
		/*
		  Just in case subclassing doesn't work, (It doesn't on Fedora
		  Core 3) we also test some common subclassings.
		*/
		
		if( strncmp( mimetype, "text/plain", 10) != 0 && strncmp( mimetype, "text/", 5 ) == 0 )
			return get_action( "text/plain" );

		return 0;
	}
	
//	fprintf( stderr, "WOOT %s\n", launcher_str );	
	launcher = const_cast<char*>(strchr( launcher_str, '=' ));
		
	if( !launcher )
	{
		fprintf( stderr, _("%s: Could not parse launcher string '%s'\n"), MIMEDB, launcher_str );	
		error=1;
		return 0;
	}
	
	/* Skip the = */
	launcher++;
    
	/* Make one we can change */
	std::string mut_launcher = launcher;
    
	/* Only use first launcher */
	end = strchr( launcher, ';' );
	if( end )
		mut_launcher.resize(end - launcher);

	launcher_full = (char *)my_malloc( mut_launcher.size() + strlen( APPLICATIONS_DIR)+1 );
	if( !launcher_full )
	{
		free( (void *)launcher_str );
		return 0;
	}
	
	strcpy( launcher_full, APPLICATIONS_DIR );
	strcat( launcher_full, mut_launcher.c_str() );
	free( (void *)launcher_str );
	
	std::string launcher_filename = get_filename( launcher_full );
	
	free( launcher_full );
		
	launcher_command_str = search_ini( launcher_filename.c_str(), "Exec" );
	
	if( !launcher_command_str )
	{
		fprintf( stderr, 
				 _( "%s: Default launcher '%s' does not specify how to start\n"), MIMEDB, 
				 launcher_filename.c_str() );
		return 0;	
	}
	
	launcher_command = strchr( launcher_command_str, '=' );
	launcher_command++;
	
	res = my_strdup( launcher_command );
	
	free( (void *)launcher_command_str );	

	return res;
}