Ejemplo n.º 1
0
gchar * get_associated_image_file (const gchar * filename)
{
    if (strncmp (filename, "file://", 7))
        return NULL;

    gchar * unesc = uri_to_filename (filename);
    if (! unesc)
        return NULL;

    gchar * path = g_path_get_dirname (unesc);
    gchar * base = g_path_get_basename (unesc);
    gchar * image_file = fileinfo_recursive_get_image (path, base, 0);

    g_free (unesc);
    g_free (path);
    g_free (base);
    return image_file;
}
Ejemplo n.º 2
0
char * get_associated_image_file (const char * filename)
{
    char * image_uri = NULL;

    char * local = uri_to_filename (filename);
    char * base = local ? last_path_element (local) : NULL;

    if (local && base)
    {
        char * include = get_str (NULL, "cover_name_include");
        char * exclude = get_str (NULL, "cover_name_exclude");

        SearchParams params = {
            .basename = base,
            .include = str_list_to_index (include, ", "),
            .exclude = str_list_to_index (exclude, ", ")
        };

        str_unref (include);
        str_unref (exclude);

        SNCOPY (path, local, base - 1 - local);

        char * image_local = fileinfo_recursive_get_image (path, & params, 0);
        if (image_local)
            image_uri = filename_to_uri (image_local);

        str_unref (image_local);

        index_free_full (params.include, (IndexFreeFunc) str_unref);
        index_free_full (params.exclude, (IndexFreeFunc) str_unref);
    }

    str_unref (local);

    return image_uri;
}
Ejemplo n.º 3
0
static char * fileinfo_recursive_get_image (const char * path,
 const SearchParams * params, int depth)
{
    DIR * d = opendir (path);
    if (! d)
        return NULL;

    struct dirent * entry;

    if (get_bool (NULL, "use_file_cover") && ! depth)
    {
        /* Look for images matching file name */
        while ((entry = readdir (d)))
        {
            if (entry->d_name[0] == '.')
                continue;

            char * newpath = filename_build (path, entry->d_name);

            if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) &&
             has_front_cover_extension (entry->d_name) &&
             is_file_image (entry->d_name, params->basename))
            {
                closedir (d);
                return newpath;
            }

            str_unref (newpath);
        }

        rewinddir (d);
    }

    /* Search for files using filter */
    while ((entry = readdir (d)))
    {
        if (entry->d_name[0] == '.')
            continue;

        char * newpath = filename_build (path, entry->d_name);

        if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) &&
         has_front_cover_extension (entry->d_name) &&
         cover_name_filter (entry->d_name, params->include, TRUE) &&
         ! cover_name_filter (entry->d_name, params->exclude, FALSE))
        {
            closedir (d);
            return newpath;
        }

        str_unref (newpath);
    }

    rewinddir (d);

    if (get_bool (NULL, "recurse_for_cover") && depth < get_int (NULL, "recurse_for_cover_depth"))
    {
        /* Descend into directories recursively. */
        while ((entry = readdir (d)))
        {
            if (entry->d_name[0] == '.')
                continue;

            char * newpath = filename_build (path, entry->d_name);

            if (g_file_test (newpath, G_FILE_TEST_IS_DIR))
            {
                char * tmp = fileinfo_recursive_get_image (newpath, params, depth + 1);

                if (tmp)
                {
                    str_unref (newpath);
                    closedir (d);
                    return tmp;
                }
            }

            str_unref (newpath);
        }
    }

    closedir (d);
    return NULL;
}
Ejemplo n.º 4
0
static gchar * fileinfo_recursive_get_image (const gchar * path, const gchar *
 file_name, gint depth)
{
    GDir *d;

    if (get_bool (NULL, "recurse_for_cover") && depth > get_int (NULL, "recurse_for_cover_depth"))
        return NULL;

    d = g_dir_open(path, 0, NULL);

    if (d) {
        const gchar *f;

        if (get_bool (NULL, "use_file_cover") && file_name)
        {
            /* Look for images matching file name */
            while((f = g_dir_read_name(d))) {
                gchar *newpath = g_strconcat(path, "/", f, NULL);

                if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
                    has_front_cover_extension(f) &&
                    is_file_image(f, file_name)) {
                    g_dir_close(d);
                    return newpath;
                }

                g_free(newpath);
            }
            g_dir_rewind(d);
        }

        /* Search for files using filter */
        while ((f = g_dir_read_name(d))) {
            gchar *newpath = g_strconcat(path, "/", f, NULL);

            if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
                has_front_cover_extension(f) &&
                is_front_cover_image(f)) {
                g_dir_close(d);
                return newpath;
            }

            g_free(newpath);
        }
        g_dir_rewind(d);

        /* checks whether recursive or not. */
        if (! get_bool (NULL, "recurse_for_cover"))
        {
            g_dir_close(d);
            return NULL;
        }

        /* Descend into directories recursively. */
        while ((f = g_dir_read_name(d))) {
            gchar *newpath = g_strconcat(path, "/", f, NULL);

            if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) {
                gchar *tmp = fileinfo_recursive_get_image(newpath,
                    NULL, depth + 1);
                if(tmp) {
                    g_free(newpath);
                    g_dir_close(d);
                    return tmp;
                }
            }

            g_free(newpath);
        }

        g_dir_close(d);
    }

    return NULL;
}