/* Restore state */ static gboolean really_restore_state(gpointer data) { saved_state* s = (saved_state*) data; sp_track* tr; /* Check if all tracks are loaded */ size_t i; for (i=0; i < s->tracks->len; i++) { tr = g_array_index(s->tracks, sp_track*, i); if (!sp_track_is_loaded(tr)) return TRUE; } /* All tracks are loaded: restore them */ g_debug("savestate: restoring saved state..."); queue_clear(FALSE); for (i=0; i < s->tracks->len; i++) { tr = g_array_index(s->tracks, sp_track*, i); if (track_available(tr)) queue_add_track(FALSE, tr); else { g_info("savestate: track %zu is no longer available", i); if (s->cur_track == i) { s->cur_track = -1; s->qs = STOPPED; } else if (s->cur_track > i) s->cur_track -= 1; } sp_track_release(tr); } queue_set_repeat(FALSE, s->repeat); queue_set_shuffle(FALSE, s->shuffle); if (s->cur_track >= 0) queue_goto(FALSE, s->cur_track, TRUE); if (s->qs == PLAYING) queue_play(FALSE); /* Done! */ queue_notify(); g_array_free(s->tracks, TRUE); g_free(s); g_debug("savestate: state restored!"); return FALSE; }
void command_link(sp_session *session, const struct command * const command) { sp_link *l = sp_link_create_from_string(command->search_string); if(l == NULL || sp_link_type(l) == SP_LINKTYPE_INVALID) { sock_send_str(command->sockfd, "Not a valid link.\n"); return; } else if(sp_link_type(l) == SP_LINKTYPE_TRACK) { sp_track *t = sp_link_as_track(l); queue_add_track(t); sock_send_str(command->sockfd, "Added track to queue.\n"); } else { sock_send_str(command->sockfd, "Link is valid but its type is not supported. Only links to tracks are supported.\n"); } sp_link_release(l); }