Пример #1
0
gboolean playlist_read_info_selection(void)
{
    GList *node;
    gboolean retval = FALSE;

    PL_LOCK();
    for (node = get_playlist(); node; node = node->next)
    {
        PlaylistEntry *entry = node->data;
        if (entry->selected)
        {
            retval = TRUE;
            if (entry->title)
                g_free(entry->title);
            entry->title = NULL;
            entry->length = -1;
            if (!playlist_get_info_entry(entry))
            {
                if (g_list_index(get_playlist(), entry) == -1)
                    /* Entry disapeared while we
                       looked it up.  Restart. */
                    node = get_playlist();
            }
        }
    }
    PL_UNLOCK();
    playlistwin_update_list();
    return retval;
}
Пример #2
0
void on_properties_activate(GtkAction * action, gpointer user_data)
{
    if (sidebar_has_focus(get_sidebar(app))) {
	LaPlaylist *playlist;
	PlaylistDialog *dialog;
	playlist = sidebar_get_cursor_playlist(get_sidebar(app));
	if (playlist) {
	    dialog = playlist_dialog_new(get_window(app));
	    playlist_dialog_show(dialog, playlist);
	}
    } else {
	/*
	LaTrack *track;
	TrackDialog *dialog;
	track = playlist_get_cursor_track(get_playlist(app));
	if (track) {
	    dialog = track_dialog_new(get_window(app));
	    track_dialog_show(dialog, track);
	}
	*/
	TrackDialog *dialog;
	GSList *tracks = playlist_get_selected_tracks(get_playlist(app));
	if (tracks) {
	    dialog = track_dialog_new(get_window(app));
	    track_dialog_show(dialog, tracks);
	}
    }
}
Пример #3
0
void on_import_activate(GtkAction * action, gpointer user_data)
{
    GtkFileSelection *fs;
    GtkResponseType response;
    const gchar *filename;
    gchar last_dir[PATH_MAX];

    g_strlcpy(last_dir, prefs.last_dir, sizeof(last_dir));
    if (!la_str_has_suffix_case(prefs.last_dir, G_DIR_SEPARATOR_S))
	g_strlcat(last_dir, "/", sizeof(last_dir));

    fs = GTK_FILE_SELECTION(gtk_file_selection_new
			    (_("Select .pls Files to Import...")));
    gtk_file_selection_set_select_multiple(fs, FALSE);
    gtk_file_selection_set_filename(fs, last_dir);
    gtk_widget_show_all(GTK_WIDGET(fs));

    response = gtk_dialog_run(GTK_DIALOG(fs));

    if (response == GTK_RESPONSE_OK) {
	filename = gtk_file_selection_get_filename(fs);
	playlist_import_pls(get_playlist(app), filename);

	g_free(prefs.last_dir);
	prefs.last_dir = g_path_get_dirname(filename);
    }

    gtk_widget_destroy(GTK_WIDGET(fs));
}
Пример #4
0
void playlist_get_total_time(gulong *total_time, gulong *selection_time, gboolean *total_more, gboolean *selection_more)
{
    GList *list;
    PlaylistEntry *entry;

    *total_time = 0;
    *selection_time = 0;
    *total_more = FALSE;
    *selection_more = FALSE;

    PL_LOCK();
    list = get_playlist();
    while (list)
    {
        entry = list->data;
        if (entry->length != -1)
            *total_time += entry->length / 1000;
        else
            *total_more = TRUE;
        if (entry->selected)
        {
            if (entry->length != -1)
                *selection_time += entry->length / 1000;
            else
                *selection_more = TRUE;
        }
        list = g_list_next(list);
    }
    PL_UNLOCK();
}
Пример #5
0
void playlist_list_move_down(PlayList_List *pl)
{
	GList *list;

	PL_LOCK();
	if ((list = g_list_last(get_playlist())) == NULL)
	{
		PL_UNLOCK();
		return;
	}
	if (((PlaylistEntry *) list->data)->selected)
	{
		/* We are at the bottom */
		PL_UNLOCK();
		return;
	}
	while (list)
	{
		if (((PlaylistEntry *) list->data)->selected)
			glist_movedown(list);
		list = g_list_previous(list);
	}
	PL_UNLOCK();
	if (pl->pl_prev_selected != -1)
		pl->pl_prev_selected++;
	if (pl->pl_prev_min != -1)
		pl->pl_prev_min++;
	if (pl->pl_prev_max != -1)
		pl->pl_prev_max++;
}
Пример #6
0
static gboolean playlist_get_info_entry(PlaylistEntry *entry)
{
    /*
     * Caller need to hold playlist mutex.
     * Note that this function temporarily drops the playlist mutex.
     * If it returns false, the entry might no longer be valid.
     */
    char *temp_filename, *temp_title;
    int temp_length;

    temp_filename = g_strdup(entry->filename);
    temp_title = NULL;
    temp_length = -1;

    /* We don't want to lock the playlist while reading info */
    PL_UNLOCK();
    input_get_song_info(temp_filename, &temp_title, &temp_length);
    PL_LOCK();
    g_free(temp_filename);

    if (!temp_title && temp_length == -1)
        return FALSE;

    /* Make sure entry is still around */
    if (g_list_index(get_playlist(), entry) == -1)
        return FALSE;

    /* entry is still around */
    entry->title = temp_title;
    entry->length = temp_length;

    return TRUE;
}
Пример #7
0
void playlist_list_move_up(PlayList_List *pl)
{
	GList *list;

	PL_LOCK();
	if ((list = get_playlist()) == NULL)
	{
		PL_UNLOCK();
		return;
	}
	if (((PlaylistEntry *) list->data)->selected)
	{
		/* We are at the top */
		PL_UNLOCK();
		return;
	}
	while (list)
	{
		if (((PlaylistEntry *) list->data)->selected)
			glist_moveup(list);
		list = g_list_next(list);
	}
	PL_UNLOCK();
	if (pl->pl_prev_selected != -1)
		pl->pl_prev_selected--;
	if (pl->pl_prev_min != -1)
		pl->pl_prev_min--;
	if (pl->pl_prev_max != -1)
		pl->pl_prev_max--;
}
Пример #8
0
void on_add_file_activate(GtkAction * action, gpointer user_data)
{
    GtkWidget *dialog;
    GtkResponseType response;
    gchar last_dir[PATH_MAX];
    GSList *filenames;
    gchar *filename;

    g_strlcpy(last_dir, prefs.last_dir, sizeof(last_dir));

    dialog = gtk_file_chooser_dialog_new(_("Add Files"),
					  get_window(app),
					  GTK_FILE_CHOOSER_ACTION_OPEN,
					  GTK_STOCK_ADD, 1,
					  GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
					  NULL);
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), last_dir);

    gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
    gtk_widget_show_all(dialog);

    while((response = gtk_dialog_run(GTK_DIALOG(dialog))) == 1) {

	filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
	while(filenames) {
	    filename = (gchar*)filenames->data;
	    if (filename) {
		playlist_add_file(get_playlist(app), filename, TRUE);
		g_free(filename);
	    }
	    filenames = g_slist_next(filenames);
	}
	g_slist_free(filenames);

	playlist_write(get_playlist(app));
    }

    gtk_widget_destroy(dialog);
}
Пример #9
0
static void begin_add (const char * path)
{
    int list = get_playlist (FALSE, FALSE);

    if (list < 0)
        list = create_playlist ();

    aud_set_str ("search-tool", "path", path);

    char * uri = filename_to_uri (path);
    g_return_if_fail (uri);

    if (! g_str_has_suffix (uri, "/"))
    {
        SCONCAT2 (temp, uri, "/");
        str_unref (uri);
        uri = str_get (temp);
    }

    destroy_added_table ();

    added_table = g_hash_table_new_full ((GHashFunc) str_hash, (GEqualFunc)
     str_equal, (GDestroyNotify) str_unref, NULL);

    int entries = aud_playlist_entry_count (list);

    for (int entry = 0; entry < entries; entry ++)
    {
        char * filename = aud_playlist_entry_get_filename (list, entry);

        if (g_str_has_prefix (filename, uri) && ! g_hash_table_contains (added_table, filename))
        {
            aud_playlist_entry_set_selected (list, entry, FALSE);
            g_hash_table_insert (added_table, filename, NULL);
        }
        else
        {
            aud_playlist_entry_set_selected (list, entry, TRUE);
            str_unref (filename);
        }
    }

    aud_playlist_delete_selected (list);
    aud_playlist_remove_failed (list);

    Index * add = index_new ();
    index_insert (add, -1, uri);
    aud_playlist_entry_insert_filtered (list, -1, add, NULL, filter_cb, NULL, FALSE);

    adding = TRUE;
}
Пример #10
0
static void handle_user_request(struct evhttp_request *request,
                                char *action,
                                const char *canonical_username,
                                sp_session *session) {
  if (action == NULL) {
    evhttp_send_error(request, HTTP_BADREQUEST, "Bad Request");
    return;
  }

  int http_method = evhttp_request_get_command(request);

  switch (http_method) {
    case EVHTTP_REQ_GET:
      if (strncmp(action, "playlists", 9) == 0) {
        sp_playlistcontainer *pc = sp_session_publishedcontainer_for_user_create(
            session, canonical_username);

        if (sp_playlistcontainer_is_loaded(pc)) {
          get_user_playlists(pc, request, session);
        } else {
          register_playlistcontainer_callbacks(pc, request,
              &get_user_playlists,
              &playlistcontainer_loaded_callbacks,
              session);
        }
      } else if (strncmp(action, "starred", 7) == 0) {
        sp_playlist *playlist = sp_session_starred_for_user_create(session,
            canonical_username);

        if (sp_playlist_is_loaded(playlist)) {
          get_playlist(playlist, request, session);
        } else {
          register_playlist_callbacks(playlist, request, &get_playlist,
              &playlist_state_changed_callbacks,
              session);
        }
      }
      break;

    case EVHTTP_REQ_PUT:
    case EVHTTP_REQ_POST:
      if (strncmp(action, "inbox", 5) == 0) {
        put_user_inbox(canonical_username, request, session);
      }
      break;

    default:
      evhttp_send_error(request, HTTP_BADREQUEST, "Bad Request");
      break;
  }
}
Пример #11
0
void on_export_activate(GtkAction * action, gpointer user_data)
{
    LaPlaylist *playlist;
    gchar *title;
    GtkFileSelection *fs;
    GtkResponseType response;
    const gchar *filename;

    playlist = playlist_get_playlist(get_playlist(app));
    if (playlist) {
	title =
	    g_strdup_printf(_("Export the playlist \"%s\" as..."),
			    la_playlist_get_name(playlist));
	filename =
	    g_strdup_printf("%s.pls", la_playlist_get_name(playlist));
    } else {
	title = g_strdup(_("Export the library as..."));
	filename = g_strdup("liteamp-library.pls");
    }

    fs = GTK_FILE_SELECTION(gtk_file_selection_new(title));
    gtk_file_selection_set_filename(fs, filename);
    gtk_file_selection_set_select_multiple(fs, FALSE);
    gtk_widget_show_all(GTK_WIDGET(fs));

    response = gtk_dialog_run(GTK_DIALOG(fs));

    if (response == GTK_RESPONSE_OK) {
	filename = gtk_file_selection_get_filename(fs);
	playlist_export_pls(get_playlist(app), filename);

	g_free(prefs.last_dir);
	prefs.last_dir = g_path_get_dirname(filename);
    }

    gtk_widget_destroy(GTK_WIDGET(fs));
    g_free(title);
}
Пример #12
0
void playlist_select_invert_all(void)
{
    GList *list;

    PL_LOCK();
    list = get_playlist();
    while (list)
    {
        PlaylistEntry *entry = list->data;
        entry->selected = !entry->selected;
        list = list->next;
    }
    PL_UNLOCK();
}
Пример #13
0
void playlist_select_all(gboolean set)
{
    GList *list;

    PL_LOCK();
    list = get_playlist();
    while (list)
    {
        PlaylistEntry *entry = list->data;
        entry->selected = set;
        list = list->next;
    }
    PL_UNLOCK();
}
Пример #14
0
void playlist_fileinfo_current(void)
{
    char *path = NULL;
    PL_LOCK();

    if (get_playlist() && playlist_position)
        path = g_strdup(playlist_position->filename);
    PL_UNLOCK();
    if (path)
    {
        input_file_info_box(path);
        g_free(path);
    }
}
Пример #15
0
static void playlist_update_cb (void * data, void * unused)
{
    if (! database)
        update_database ();
    else
    {
        int list = get_playlist (TRUE, TRUE);
        int at, count;

        if (list < 0 || aud_playlist_updated_range (list, & at, & count) >=
         PLAYLIST_UPDATE_METADATA)
            update_database ();
    }
}
Пример #16
0
int playlist_get_num_selected(void)
{
    GList *node;
    int num = 0;

    PL_LOCK();
    for (node = get_playlist(); node != 0; node = g_list_next(node))
    {
        PlaylistEntry *entry = node->data;
        if (entry->selected)
            num++;
    }
    PL_UNLOCK();
    return num;
}
Пример #17
0
GList * playlist_get_selected(void)
{
    GList *node, *list = NULL;
    int i = 0;

    PL_LOCK();
    for (node = get_playlist(); node != 0; node = g_list_next(node), i++)
    {
        PlaylistEntry *entry = node->data;
        if (entry->selected)
            list = g_list_prepend(list, GINT_TO_POINTER(i));
    }
    PL_UNLOCK();
    return g_list_reverse(list);
}
Пример #18
0
void on_add_directory_activate(GtkAction * action, gpointer user_data)
{
    GtkWidget *dialog;
    GtkResponseType response;
    gchar last_dir[PATH_MAX];
    const gchar *filename;

    g_strlcpy(last_dir, prefs.last_dir, sizeof(last_dir));

    dialog = gtk_file_chooser_dialog_new(_("Add Directories"),
					  get_window(app),
					  GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
					  GTK_STOCK_ADD, 1,
					  GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
					  NULL);
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);

    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), last_dir);

    gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
    gtk_widget_show_all(dialog);

    while ((response = gtk_dialog_run(GTK_DIALOG(dialog))) == 1) {

	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));

	playlist_add_directory(get_playlist(app), filename, TRUE, TRUE);

	g_free(prefs.last_dir);
	prefs.last_dir = g_path_get_dirname(filename);

	playlist_write(get_playlist(app));
    }

    gtk_widget_destroy(dialog);
}
Пример #19
0
gboolean playlist_select_invert(int num)
{
    GList *list;
    gboolean retv = FALSE;

    PL_LOCK();
    if ((list = g_list_nth(get_playlist(), num)) != NULL)
    {
        PlaylistEntry *entry = list->data;
        entry->selected = !entry->selected;
        retv = TRUE;
    }
    PL_UNLOCK();

    return retv;
}
Пример #20
0
static void add_complete_cb (void * unused, void * unused2)
{
    if (adding)
    {
        int list = get_playlist (TRUE, FALSE);

        if (list >= 0 && ! aud_playlist_add_in_progress (list))
        {
            adding = FALSE;
            destroy_added_table ();
            aud_playlist_sort_by_scheme (list, PLAYLIST_SORT_PATH);
        }
    }

    if (! database && ! aud_playlist_update_pending ())
        update_database ();
}
Пример #21
0
static void update_database (void)
{
    int list = get_playlist (TRUE, TRUE);

    if (list >= 0)
    {
        create_database (list);
        schedule_search ();
    }
    else
        destroy_database ();

    if (results_list)
        audgui_list_delete_rows (results_list, 0, audgui_list_row_count (results_list));

    show_hide_widgets ();
}
Пример #22
0
void playlist_fileinfo(int pos)
{
    char *path = NULL;
    GList *node;

    PL_LOCK();
    if ((node = g_list_nth(get_playlist(), pos)) != NULL)
    {
        PlaylistEntry *entry = node->data;
        path = g_strdup(entry->filename);
    }
    PL_UNLOCK();
    if (path)
    {
        input_file_info_box(path);
        g_free(path);
    }
}
Пример #23
0
void playlist_read_info(int pos)
{
    GList *node;

    PL_LOCK();
    if ((node = g_list_nth(get_playlist(), pos)) != NULL)
    {
        PlaylistEntry *entry = node->data;

        if (entry->title)
            g_free(entry->title);
        entry->title = NULL;
        entry->length = -1;
        playlist_get_info_entry(entry);
    }
    PL_UNLOCK();
    playlistwin_update_list();
}
Пример #24
0
void playlist_queue_selected(void)
{
    GList *node;

    PL_LOCK();
    for (node = get_playlist(); node; node = node->next)
    {
        PlaylistEntry *entry = node->data;

        if (!entry->selected)
            continue;

        playlist_queue_toggle(entry);
    }
    PL_UNLOCK();

    playlistwin_update_list();
}
Пример #25
0
void on_remove_playlist_activate(GtkAction * action, gpointer user_data)
{
    LaPlaylist *playlist;
    GtkResponseType response;

    playlist = playlist_get_playlist(get_playlist(app));
    if (!playlist) {
	la_message_box(get_window(app), _("Choose a playlist to delete!"));
	return;
    }

    response = la_prompt_boxv(get_window(app),
			      GTK_MESSAGE_QUESTION,
			      GTK_BUTTONS_YES_NO,
			      _("Remove the playlist \"%s\"?"),
			      la_playlist_get_name(playlist));

    if (response = GTK_RESPONSE_YES) {
	sidebar_remove_playlist(get_sidebar(app), playlist);
    }
}
Пример #26
0
void playlist_select_range(int min, int max, gboolean sel)
{
    GList *list;
    int i;

    if (min > max)
    {
        int tmp = min;
        min = max;
        max = tmp;
    }

    PL_LOCK();
    list = g_list_nth(get_playlist(), min);
    for (i = min; i <= max && list; i++)
    {
        PlaylistEntry *entry = list->data;
        entry->selected = sel;
        list = list->next;
    }
    PL_UNLOCK();
}
Пример #27
0
void on_refresh_activate(GtkAction * action, gpointer user_data)
{
    playlist_refresh(get_playlist(app));
}
Пример #28
0
void on_jump_to_activate(GtkAction * action, gpointer user_data)
{
    playlist_jump_to(get_playlist(app));
}
Пример #29
0
void on_shuffle_activate(GtkToggleAction * action, gpointer user_data)
{
    prefs.shuffle = gtk_toggle_action_get_active(action);
    update_ui_shuffle(app);
    playlist_shuffle(get_playlist(app));
}
Пример #30
0
void on_next_activate(GtkAction * action, gpointer user_data)
{
    playlist_next(get_playlist(app));
}