Ejemplo n.º 1
0
static void activate_temp (void)
{
    gint playlists = playlist_count ();
    const gchar * title = _("Temporary Playlist");

    for (gint playlist = 0; playlist < playlists; playlist ++)
    {
        gchar * title2 = playlist_get_title (playlist);
        if (! strcmp (title2, title))
        {
            playlist_set_active (playlist);
            g_free (title2);
            return;
        }
        g_free (title2);
    }

    if (! playlist_entry_count (playlist_get_active ()))
        playlist_set_title (playlist_get_active (), title);
    else
    {
        playlist_insert (playlists);
        playlist_set_title (playlists, title);
        playlist_set_active (playlists);
    }
}
Ejemplo n.º 2
0
/* Fix me:  This considers empty fields as duplicates. */
void playlist_remove_duplicates_by_scheme (int playlist, int scheme)
{
    int entries = playlist_entry_count (playlist);
    int count;

    if (entries < 1)
        return;

    playlist_select_all (playlist, FALSE);

    if (filename_comparisons[scheme] != NULL)
    {
        int (* compare) (const char * a, const char * b) =
         filename_comparisons[scheme];

        playlist_sort_by_filename (playlist, compare);
        char * last = playlist_entry_get_filename (playlist, 0);

        for (count = 1; count < entries; count ++)
        {
            char * current = playlist_entry_get_filename (playlist, count);

            if (compare (last, current) == 0)
                playlist_entry_set_selected (playlist, count, TRUE);

            str_unref (last);
            last = current;
        }

        str_unref (last);
    }
    else if (tuple_comparisons[scheme] != NULL)
    {
        int (* compare) (const Tuple * a, const Tuple * b) =
         tuple_comparisons[scheme];

        playlist_sort_by_tuple (playlist, compare);
        Tuple * last = playlist_entry_get_tuple (playlist, 0, FALSE);

        for (count = 1; count < entries; count ++)
        {
            Tuple * current = playlist_entry_get_tuple (playlist, count, FALSE);

            if (last != NULL && current != NULL && compare (last, current) == 0)
                playlist_entry_set_selected (playlist, count, TRUE);

            if (last)
                tuple_unref (last);
            last = current;
        }

        if (last)
            tuple_unref (last);
    }

    playlist_delete_selected (playlist);
}
Ejemplo n.º 3
0
static gboolean get_position_cb(void *data)
{
    struct PositionRequest *request = data;

    g_mutex_lock(info_mutex);

    real_position(&request->playlist, &request->entry);
    request->entry_count = playlist_entry_count(request->playlist);
    request->queue_count = playlist_queue_count(request->playlist);

    g_cond_signal(info_cond);
    g_mutex_unlock(info_mutex);
    return FALSE;
}
Ejemplo n.º 4
0
bool_t playlist_save (int list, const char * filename)
{
    AUDDBG ("Saving playlist %s.\n", filename);

    PluginHandle * plugin = get_plugin (filename, TRUE);
    if (! plugin)
        return FALSE;

    PlaylistPlugin * pp = plugin_get_header (plugin);
    g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE);

    bool_t fast = get_bool (NULL, "metadata_on_play");

    VFSFile * file = vfs_fopen (filename, "w");
    if (! file)
        return FALSE;

    char * title = playlist_get_title (list);

    int entries = playlist_entry_count (list);
    Index * filenames = index_new ();
    index_allocate (filenames, entries);
    Index * tuples = index_new ();
    index_allocate (tuples, entries);

    for (int i = 0; i < entries; i ++)
    {
        index_append (filenames, playlist_entry_get_filename (list, i));
        index_append (tuples, playlist_entry_get_tuple (list, i, fast));
    }

    bool_t success = pp->save (filename, file, title, filenames, tuples);

    vfs_fclose (file);
    str_unref (title);

    for (int i = 0; i < entries; i ++)
    {
        str_unref (index_get (filenames, i));
        Tuple * tuple = index_get (tuples, i);
        if (tuple)
            tuple_unref (tuple);
    }

    index_free (filenames);
    index_free (tuples);

    return success;
}
Ejemplo n.º 5
0
bool_t playlist_insert_playlist_raw (int list, int at,
 const char * filename)
{
    char * title = NULL;
    Index * filenames, * tuples;

    if (! playlist_load (filename, & title, & filenames, & tuples))
        return FALSE;

    if (title && ! playlist_entry_count (list))
        playlist_set_title (list, title);

    playlist_entry_insert_batch_raw (list, at, filenames, tuples, NULL);

    str_unref (title);
    return TRUE;
}
Ejemplo n.º 6
0
static void add_list (Index * filenames, int at, bool_t to_temp, bool_t play)
{
    if (to_temp)
        playlist_set_active (playlist_get_temporary ());

    int playlist = playlist_get_active ();

    if (play)
    {
        if (get_bool (NULL, "clear_playlist"))
            playlist_entry_delete (playlist, 0, playlist_entry_count (playlist));
        else
            playlist_queue_delete (playlist, 0, playlist_queue_count (playlist));
    }

    playlist_entry_insert_batch (playlist, at, filenames, NULL, play);
}
Ejemplo n.º 7
0
static void add_list (Index * filenames, int at, bool_t to_temp, bool_t play)
{
    if (to_temp)
        playlist_set_active (playlist_get_temporary ());

    int playlist = playlist_get_active ();

    /* queue the new entries before deleting the old ones */
    /* this is to avoid triggering the --quit-after-play condition */
    playlist_entry_insert_batch (playlist, at, filenames, NULL, play);

    if (play)
    {
        if (get_bool (NULL, "clear_playlist"))
            playlist_entry_delete (playlist, 0, playlist_entry_count (playlist));
        else
            playlist_queue_delete (playlist, 0, playlist_queue_count (playlist));
    }
}
Ejemplo n.º 8
0
static gboolean add_cb(void *data)
{
    struct AddRequest *request = data;
    gint playlist = playlist_get_active();

    if (request->position < 0)
        request->position = playlist_entry_count (playlist);

    drct_pl_add (request->filename, request->position);

    if (request->play)
    {
        playlist_set_playing(playlist);
        playlist_set_position(playlist, request->position);
        playback_play (0, FALSE);
    }

    g_free(request);
    return FALSE;
}
Ejemplo n.º 9
0
void playlist_select_by_patterns (int playlist, const Tuple * patterns)
{
    const int fields[] = {FIELD_TITLE, FIELD_ALBUM, FIELD_ARTIST,
     FIELD_FILE_NAME};

    int entries = playlist_entry_count (playlist);
    int field, entry;

    playlist_select_all (playlist, TRUE);

    for (field = 0; field < G_N_ELEMENTS (fields); field ++)
    {
        char * pattern = tuple_get_str (patterns, fields[field], NULL);
        regex_t regex;

        if (! pattern || ! pattern[0] || regcomp (& regex, pattern, REG_ICASE))
        {
            str_unref (pattern);
            continue;
        }

        for (entry = 0; entry < entries; entry ++)
        {
            if (! playlist_entry_get_selected (playlist, entry))
                continue;

            Tuple * tuple = playlist_entry_get_tuple (playlist, entry, FALSE);
            char * string = tuple ? tuple_get_str (tuple, fields[field], NULL) : NULL;

            if (! string || regexec (& regex, string, 0, NULL, 0))
                playlist_entry_set_selected (playlist, entry, FALSE);

            str_unref (string);
            if (tuple)
                tuple_unref (tuple);
        }

        regfree (& regex);
        str_unref (pattern);
    }
}
Ejemplo n.º 10
0
static void add_list (GList * list, gint at, gboolean to_temp, gboolean play)
{
    if (to_temp)
        activate_temp ();

    gint playlist = playlist_get_active ();

    if (play)
    {
        if (get_bool (NULL, "clear_playlist"))
            playlist_entry_delete (playlist, 0, playlist_entry_count (playlist));
        else
            playlist_queue_delete (playlist, 0, playlist_queue_count (playlist));
    }

    struct index * filenames = index_new ();
    for (; list != NULL; list = list->next)
        index_append (filenames, g_strdup (list->data));

    playlist_entry_insert_batch (playlist, at, filenames, NULL, play);
}
Ejemplo n.º 11
0
void playlist_remove_failed (int playlist)
{
    int entries = playlist_entry_count (playlist);
    int count;

    playlist_select_all (playlist, FALSE);

    for (count = 0; count < entries; count ++)
    {
        char * filename = playlist_entry_get_filename (playlist, count);

        /* vfs_file_test() only works for file:// URIs currently */
        if (! strncmp (filename, "file://", 7) && ! vfs_file_test (filename,
         G_FILE_TEST_EXISTS))
            playlist_entry_set_selected (playlist, count, TRUE);

        str_unref (filename);
    }

    playlist_delete_selected (playlist);
}
Ejemplo n.º 12
0
void drct_pl_clear (void)
{
    gint playlist = playlist_get_active ();
    playlist_entry_delete (playlist, 0, playlist_entry_count (playlist));
}
Ejemplo n.º 13
0
gint drct_pl_get_length (void)
{
    return playlist_entry_count (playlist_get_active ());
}
Ejemplo n.º 14
0
// MPRIS /TrackList
gboolean mpris_emit_tracklist_change(MprisTrackList * obj, gint playlist)
{
    g_signal_emit(obj, tracklist_signals[TRACKLIST_CHANGE_SIG], 0, playlist_entry_count(playlist));
    return TRUE;
}