void gui_input_playlist(int c) { int j; switch (c) { case '-': // Move selected forward in playlist if (playlist->selected != playlist->head) { controller_playlist_move_up(); gui_update_playlist(); } break; case '+': case '=': // Move selected backwards in playlist if (playlist->selected != playlist->tail) { controller_playlist_move_down(); gui_update_playlist(); } break; case KEY_ENTER: case '\n': case '\r': if (playlist->playing) { playlist->selected = songdata_next_valid(playlist, playlist->head, KEY_HOME); playlist->where = 1; playlist->wheretop = 0; for (j = 0; playlist->selected->next && playlist->selected != playlist->playing; j++) { playlist->selected = songdata_next_valid(playlist, playlist->selected->next, KEY_DOWN); playlist->where++; } gui_update_playlist(); } break; case KEY_DC: // remove selected from playlist if (playlist->selected) { if (playlist->playing == playlist->selected && playlist->playing->next != NULL) { controller_next(playlist); } else if (playlist->playing == playlist->selected && playlist->playing->next == NULL) { controller_stop(); } songdata_del(playlist, playlist->selected); gui_update_playlist(); gui_update_info(); } break; default: window_input(playlist_window, c); break; } }
void http_delete_playlist() { controller_stop(); songdata_clear ( playlist ); gui_update_playlist(); gui_update_info(); update_panels (); }
void controller_shuffle_playlist(){ if (gui_ask_yes_no(SHUFFLE)) { songdata_randomize(playlist); gui_update_playlist(); gui_update_info(); } }
void controller_stop() { if ( playlist->playing ) { playlist->playing->flags &= ~F_PAUSED; playlist->playing = NULL; gui_update_playlist(); } engine_stop(); gui_update_playback(); controller_update_statefile(); }
void controller_clear_playlist() { if (gui_ask_yes_no(CLEARPLAYLIST)) { controller_stop(); songdata_clear ( playlist ); gui_update_playlist(); gui_update_info(); update_panels (); } }
char * controller_process_to_next_song ( void ) { if ( !playlist->playing->next ) return NULL; char * return_path = playlist->playing->next->fullpath; playlist->playing = playlist->playing->next; // if( playlist->playing->next) // { // return_path = playlist->playing->next->fullpath; // } /* GUI stuff */ gui_update_playlist(); gui_update_info(); gui_update_playback(); controller_update_whereplaying(); controller_update_statefile(); return return_path; }
void controller_play_pause(void) { if(engine_is_paused()){ playlist->playing->flags &= ~F_PAUSED; engine_resume_playback(); }else if(engine_is_playing()){ playlist->playing->flags |= F_PAUSED; engine_pause_playback(); }else{ if ( !playlist->selected ){ playlist->selected = songdata_next_valid ( playlist, playlist->top, KEY_DOWN ); } controller_jump_to_song ( playlist->selected ); // Play } /* GUI stuff */ gui_update_playlist(); gui_update_info(); gui_update_playback(); }
void controller_jump_to_song ( songdata_song *next ) { if ( !next ) return; if ( playlist->playing != next ) { //It's really a jump.... engine_stop(); } char * current = next->fullpath; playlist->playing = next; engine_jump_to(current); /* GUI stuff */ gui_update_playlist(); gui_update_info(); gui_update_playback(); controller_update_whereplaying(); controller_update_statefile(); }
int http_controller_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { char *page = NULL; if(!strcmp(method, "GET")) { if(!strcmp(url, "/")) page = http_get_index(); else if (!strcmp(url, "/playlist")) page = http_get_playlist(); else if (!strcmp(url, "/status")) page = http_get_status(); else if (!strcmp(url, "/current")) page = http_get_current(); else if (!strncmp(url, "/playlist/", 10)) { char *request = strdup(url); page = http_get_playlist_item(request); free(request); } } else if(!strcmp(method, "POST")) { //Calculate content_length int content_length = 0; MHD_get_connection_values(connection, MHD_HEADER_KIND, http_controller_headers, &content_length); //We need more post data if(content_length > *upload_data_size) return MHD_YES; //Create string from upload_data char *strdata = malloc(content_length + 1); strncpy(strdata, upload_data, content_length); strdata[content_length] = 0; //Parse JSON json_value *data = json_parse(strdata); free(strdata); strdata = NULL; //Ignore malformed JSON if(data) { //Execute commands if(!strcmp(url, "/status")) page = http_post_status(data); else if(!strcmp(url, "/current")) page = http_post_current(data); else if(!strcmp(url, "/playlist")) page = http_post_playlist(data); else if (!strncmp(url, "/playlist/", 10)) { char *request = strdup(url); page = http_post_playlist_item(request, data); free(request); } json_value_free(data); gui_update_playlist(); } } else if(!strcmp(method, "DELETE")) { if(!strcmp(url, "/playlist")) http_delete_playlist(); else if(!strncmp(url, "/playlist/", 10)) { char *request = strdup(url); page = http_delete_playlist_item(request); free(request); } gui_update_playlist(); } if(page == NULL) page = strdup("404 Not Found!"); struct MHD_Response *response; response = MHD_create_response_from_data (strlen (page), (void*) page, true, false); int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; }
void gui_input_filelist(int c) { int alt = 0; int n; songdata_song *ftmp; if (c == 27) { alt = 1; c = getch(); } switch (c) { case KEY_ENTER: case '\n': case '\r': typed_letters[0] = '\0'; if ((mp3list->selected->flags & F_DIR)) { if (!alt) { // change to another directory if (!strcmp("../", mp3list->selected->filename)) { char * filename = strdup(dirstack_filename()); char * fullpath = strdup(dirstack_fullpath()); dirstack_pop(); songdata_read_mp3_list(mp3list, fullpath, L_NEW); while (strcmp(mp3list->selected->filename, filename)) window_input(filelist_window, KEY_DOWN); free(filename); free(fullpath); } else { if (!(mp3list->flags & F_VIRTUAL)) dirstack_push(mp3list->from, mp3list->selected->filename); songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW); } gui_update_filelist(); } else { // add songs from directory if (previous_selected) free(previous_selected); previous_selected = strdup(mp3list->selected->fullpath); if ((!(mp3list->flags & F_VIRTUAL)) & (strcmp("../", mp3list->selected->fullpath))) { add_to_playlist_recursive(playlist, playlist->tail, mp3list->selected); gui_update_playlist(); } } } else if (mp3list->selected->flags & F_PLAYLIST) { if (!alt) { dirstack_push(mp3list->from, mp3list->selected->filename); songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW); gui_update_filelist(); } else { add_to_playlist_recursive(playlist, playlist->tail, mp3list->selected); gui_update_playlist(); } } else // normal mp3 if (strcmp(previous_selected, mp3list->selected->fullpath)) { if (previous_selected) free(previous_selected); previous_selected = strdup(mp3list->selected->fullpath); if (!alt) add_to_playlist(playlist, playlist->tail, mp3list->selected); else add_to_playlist(playlist, playlist->selected, mp3list->selected); gui_update_playlist(); if (conf->c_flags & C_FADVANCE) { window_input(filelist_window, KEY_DOWN); } } break; case KEY_LEFT: // leave directory if (!dirstack_empty()) { char *filename = strdup(dirstack_filename()); char *fullpath = strdup(dirstack_fullpath()); dirstack_pop(); songdata_read_mp3_list(mp3list, fullpath, L_NEW); while (strcmp(mp3list->selected->filename, filename)) { window_input_list(filelist_window, KEY_DOWN); } gui_update_filelist(); gui_update_info(); free(filename); free(fullpath); } break; case KEY_RIGHT: // enter directory if ((mp3list->selected->flags & (F_DIR | F_PLAYLIST)) && (strncmp(mp3list->selected->filename, "../", 3))) { if (!(mp3list->flags & F_VIRTUAL)) { dirstack_push(mp3list->from, mp3list->selected->filename); } songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW); if (mp3list->head) { window_input_list(filelist_window, KEY_DOWN); } } gui_update_filelist(); gui_update_info(); break; case KEY_IC: if (!((mp3list->selected->flags & F_DIR) | (mp3list->selected->flags & F_PLAYLIST))) if (strcmp(previous_selected, mp3list->selected->fullpath)) { // we dont want to add the last file multiple times if (previous_selected) free(previous_selected); previous_selected = strdup(mp3list->selected->fullpath); if (playlist->playing) add_to_playlist(playlist, playlist->playing, mp3list->selected); else add_to_playlist(playlist, playlist->selected, mp3list->selected); if (conf->c_flags & C_FADVANCE) { window_input(filelist_window, KEY_DOWN); gui_update_filelist(); gui_update_info(); } gui_update_playlist(); } break; case 'a'...'z': case 'A'...'Z': case '0'...'9': case '.': case ' ': ftmp = mp3list->head; n = 0; time_t time_now = time(NULL); if (difftime(time_now, typed_letters_last_activity) > 10) { typed_letters[0] = '\0'; } if (strlen(typed_letters) < 4) { // add the letter to the string and reset the timeout strcat(typed_letters, (char *) &c); } while (strncasecmp(ftmp->filename, typed_letters, strlen(typed_letters)) != 0) { if (ftmp == mp3list->tail) { ftmp = NULL; break; } ftmp = ftmp->next; n++; } if (ftmp) { // match found mp3list->selected = ftmp; mp3list->where = n; gui_update_filelist(); } typed_letters_last_activity = time_now; break; case KEY_BACKSPACE: if (strlen(typed_letters) >= 1) { typed_letters[strlen(typed_letters) - 1] = '\0'; typed_letters_last_activity = time(NULL); } break; default: window_input(filelist_window, c); break; } }