mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	augment-properties: support XDG_DATA_DIRS when find desktop files
This commit is contained in:
		
							parent
							
								
									f5f44950c2
								
							
						
					
					
						commit
						10010f81e8
					
				
					 1 changed files with 54 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -131,8 +131,44 @@ static int catch_all(pa_config_parser_state *state) {
 | 
			
		|||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static char * find_desktop_file_in_dir(struct rule *r, const char *desktop_file_dir, struct stat *st) {
 | 
			
		||||
    char *fn = NULL;
 | 
			
		||||
 | 
			
		||||
    pa_assert(st);
 | 
			
		||||
 | 
			
		||||
    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, r->process_name);
 | 
			
		||||
    if (stat(fn, st) == 0) {
 | 
			
		||||
        return fn;
 | 
			
		||||
    } else {
 | 
			
		||||
#ifdef DT_DIR
 | 
			
		||||
        DIR *desktopfiles_dir;
 | 
			
		||||
        struct dirent *dir;
 | 
			
		||||
 | 
			
		||||
        /* Let's try a more aggressive search, but only one level */
 | 
			
		||||
        if ((desktopfiles_dir = opendir(desktop_file_dir))) {
 | 
			
		||||
            while ((dir = readdir(desktopfiles_dir))) {
 | 
			
		||||
                if (dir->d_type != DT_DIR
 | 
			
		||||
                    || pa_streq(dir->d_name, ".")
 | 
			
		||||
                    || pa_streq(dir->d_name, ".."))
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                pa_xfree(fn);
 | 
			
		||||
                fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, dir->d_name, r->process_name);
 | 
			
		||||
 | 
			
		||||
                if (stat(fn, st) == 0) {
 | 
			
		||||
                    closedir(desktopfiles_dir);
 | 
			
		||||
                    return fn;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            closedir(desktopfiles_dir);
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void update_rule(struct rule *r) {
 | 
			
		||||
    char *fn;
 | 
			
		||||
    char *fn = NULL;
 | 
			
		||||
    struct stat st;
 | 
			
		||||
    static pa_config_item table[] = {
 | 
			
		||||
        { "Name", pa_config_parse_string,              NULL, "Desktop Entry" },
 | 
			
		||||
| 
						 | 
				
			
			@ -143,41 +179,33 @@ static void update_rule(struct rule *r) {
 | 
			
		|||
        { NULL,  catch_all, NULL, NULL },
 | 
			
		||||
        { NULL, NULL, NULL, NULL },
 | 
			
		||||
    };
 | 
			
		||||
    bool found = false;
 | 
			
		||||
    const char *state = NULL;
 | 
			
		||||
    const char *xdg_data_dirs = NULL;
 | 
			
		||||
    char *data_dir = NULL;
 | 
			
		||||
    char *desktop_file_dir = NULL;
 | 
			
		||||
 | 
			
		||||
    pa_assert(r);
 | 
			
		||||
    fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s.desktop", r->process_name);
 | 
			
		||||
 | 
			
		||||
    if (stat(fn, &st) == 0)
 | 
			
		||||
        found = true;
 | 
			
		||||
    else {
 | 
			
		||||
#ifdef DT_DIR
 | 
			
		||||
        DIR *desktopfiles_dir;
 | 
			
		||||
        struct dirent *dir;
 | 
			
		||||
 | 
			
		||||
        /* Let's try a more aggressive search, but only one level */
 | 
			
		||||
        if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) {
 | 
			
		||||
            while ((dir = readdir(desktopfiles_dir))) {
 | 
			
		||||
                if (dir->d_type != DT_DIR
 | 
			
		||||
                    || pa_streq(dir->d_name, ".")
 | 
			
		||||
                    || pa_streq(dir->d_name, ".."))
 | 
			
		||||
                    continue;
 | 
			
		||||
    if ((xdg_data_dirs = getenv("XDG_DATA_DIRS"))) {
 | 
			
		||||
        while ((data_dir = pa_split(xdg_data_dirs, ":", &state))) {
 | 
			
		||||
            desktop_file_dir = pa_sprintf_malloc("%s" PA_PATH_SEP "applications", data_dir);
 | 
			
		||||
 | 
			
		||||
            pa_xfree(fn);
 | 
			
		||||
                fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", dir->d_name, r->process_name);
 | 
			
		||||
            fn = find_desktop_file_in_dir(r, desktop_file_dir, &st);
 | 
			
		||||
 | 
			
		||||
                if (stat(fn, &st) == 0) {
 | 
			
		||||
                    found = true;
 | 
			
		||||
            pa_xfree(desktop_file_dir);
 | 
			
		||||
            pa_xfree(data_dir);
 | 
			
		||||
 | 
			
		||||
            if (fn) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            closedir(desktopfiles_dir);
 | 
			
		||||
    } else {
 | 
			
		||||
        fn = find_desktop_file_in_dir(r, DESKTOPFILEDIR, &st);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
    if (!found) {
 | 
			
		||||
 | 
			
		||||
    if (!fn) {
 | 
			
		||||
        r->good = false;
 | 
			
		||||
        pa_xfree(fn);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue