/* the menu logic for the ncurses interface, much simpler than it looks... */ void ninterface() { menu_parameters artists_menu, albums_menu, tracks_menu; char *sections[] = {"Artists", "Albums", "Tracks" }; /* Section titles, used in the menu */ artist art; album alb; track song; list np; int art_choice, alb_choice, trak_choice; /* ---===[ ARTISTS MENU ]===--- */ artists_menu = (menu_parameters)malloc(sizeof(struct menu_parameters_str)); artists_menu->list = get_artist_list(); artists_menu->list_len = num_artists; artists_menu->title = "Artists:"; artists_menu->sections = sections; artists_menu->num_sections = 3; artists_menu->curr_section = 1; artists_menu->commands = COMMANDS; artists_menu->select = 0; artists_menu->scroll = 0; artists_menu->height = LINES; artists_menu->width = COLS; while(1) { art_choice = nmenu(artists_menu); /* draw artist menu */ artists_menu->select = art_choice; if(artists_menu->entered == QUIT_BACK) /* exit artist menu (and function) */ break; else if(artists_menu->entered == APPEND_PLAYLIST || artists_menu->entered == REPLACE_PLAYLIST) { /* play an artist (XMMS2) */ if(artists_menu->entered == REPLACE_PLAYLIST) { player_stop(); player_clear_playlist(); } art = ((artist)(lookup(artists_menu->list[art_choice])->contents)); player_add_artist(art); player_play(); } else if(artists_menu->entered == TOGGLE_PLAY_PAUSE) { player_toggle(); } else if(artists_menu->entered == NOWPLAYING) { now_playing(); } else if(artists_menu->entered == NEXT) { player_next(); } else if(artists_menu->entered == PREVIOUS) { player_previous(); } /* ---===[ ALBUMS MENU ]===--- */ else if(artists_menu->entered == '\n') { /* enter this menu */ art = ((artist)(lookup(artists_menu->list[art_choice])->contents)); albums_menu = (menu_parameters)malloc(sizeof(struct menu_parameters_str)); albums_menu->list = get_album_list(art); albums_menu->list_len = art->num_albums; albums_menu->title = art->name; albums_menu->sections = sections; albums_menu->num_sections = 3; albums_menu->curr_section = 2; albums_menu->commands = COMMANDS; albums_menu->select = 0; albums_menu->scroll = 0; albums_menu->height = LINES; albums_menu->width = COLS; while(1) { alb_choice = nmenu(albums_menu); /* draw album menu */ if(albums_menu->entered == KEY_LEFT || albums_menu->entered == QUIT_BACK) /* exit albums menu */ break; else if(albums_menu->entered == APPEND_PLAYLIST || albums_menu->entered == REPLACE_PLAYLIST) { /* play an album (XMMS2) */ if(albums_menu->entered == REPLACE_PLAYLIST) { player_stop(); player_clear_playlist(); } for(np = art->albums; np != NULL; np = np->next) if(strcmp(albums_menu->list[alb_choice], np->name) == 0) break; alb = (album)np->contents; player_add_album(alb); player_play(); } else if(albums_menu->entered == TOGGLE_PLAY_PAUSE) { player_toggle(); } else if(albums_menu->entered == NOWPLAYING) { now_playing(); } else if(albums_menu->entered == NEXT) { player_next(); } else if(albums_menu->entered == PREVIOUS) { player_previous(); } /* ---===[ TRACKS MENU ]===--- */ else if(albums_menu->entered == '\n') { /* enter this menu */ for(np = art->albums; np != NULL; np = np->next) if(strcmp(albums_menu->list[alb_choice], np->name) == 0) break; alb = (album)np->contents; tracks_menu = (menu_parameters)malloc(sizeof(struct menu_parameters_str)); tracks_menu->list = get_track_list(alb); tracks_menu->list_len = alb->num_songs; tracks_menu->title = alb->name; tracks_menu->sections = sections; tracks_menu->num_sections = 3; tracks_menu->curr_section = 3; tracks_menu->commands = COMMANDS; tracks_menu->select = 0; tracks_menu->scroll = 0; tracks_menu->height = LINES; tracks_menu->width = COLS; while(1) { trak_choice = nmenu(tracks_menu); /* draw track menu */ /* play a track (XMMS2) */ if(tracks_menu->entered == APPEND_PLAYLIST || tracks_menu->entered == REPLACE_PLAYLIST) { /* play a track (XMMS2) */ if(tracks_menu->entered == REPLACE_PLAYLIST) { player_stop(); player_clear_playlist(); } for(song = alb->songs; song != NULL; song = song->next) if(strcmp(tracks_menu->list[trak_choice], song->name) == 0) break; player_add_track(song); player_play(); } else if(tracks_menu->entered == TOGGLE_PLAY_PAUSE) { player_toggle(); } else if(tracks_menu->entered == NOWPLAYING) { now_playing(); } else if(tracks_menu->entered == KEY_LEFT || tracks_menu->entered == QUIT_BACK) { /* exit tracks menu */ break; } else if(tracks_menu->entered == NEXT) { player_next(); } else if(tracks_menu->entered == PREVIOUS) { player_previous(); } } /* drop out of tracks here */ destroy_menu_params(tracks_menu); } } /* drop out of albums here */ destroy_menu_params(albums_menu); } } /* drop out of artists here */ destroy_menu_params(artists_menu); return; }
static gboolean run_task (RBMtpThread *thread, RBMtpThreadTask *task) { char *name = task_name (task); rb_debug ("running task: %s", name); g_free (name); switch (task->task) { case OPEN_DEVICE: open_device (thread, task); break; case CLOSE_DEVICE: return TRUE; case SET_DEVICE_NAME: if (LIBMTP_Set_Friendlyname (thread->device, task->name)) { rb_mtp_thread_report_errors (thread, TRUE); } break; case THREAD_CALLBACK: { RBMtpThreadCallback cb = (RBMtpThreadCallback)task->callback; cb (thread->device, task->user_data); } break; case ADD_TO_ALBUM: add_track_to_album_and_update (thread, task); break; case REMOVE_FROM_ALBUM: remove_track_from_album (thread, task); break; case SET_ALBUM_IMAGE: set_album_image (thread, task); break; case GET_TRACK_LIST: get_track_list (thread, task); break; case DELETE_TRACK: if (LIBMTP_Delete_Object (thread->device, task->track_id)) { rb_mtp_thread_report_errors (thread, TRUE); } break; case UPLOAD_TRACK: upload_track (thread, task); break; case DOWNLOAD_TRACK: download_track (thread, task); break; default: g_assert_not_reached (); } return FALSE; }