| 1 | use mpd::Song; |
| 2 | |
| 3 | #[derive(Debug)] |
| 4 | pub struct Queue { |
| 5 | pub list: Vec<Song>, |
| 6 | pub index: usize, |
| 7 | } |
| 8 | |
| 9 | impl Queue { |
| 10 | pub fn new() -> Self { |
| 11 | Queue { |
| 12 | list: Vec::new(), |
| 13 | index: 0, |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | // Go to next item in list |
| 18 | pub fn next(&mut self) { |
| 19 | let len = self.list.len(); |
| 20 | if len != 0 && self.index < len - 1 { |
| 21 | self.index += 1; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /// Go to previous item in list |
| 26 | pub fn prev(&mut self) { |
| 27 | if self.index != 0 { |
| 28 | self.index -= 1; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | pub fn reset_index(&mut self) { |
| 33 | self.index = 0; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl Default for Queue { |
| 38 | fn default() -> Self { |
| 39 | Self::new() |
| 40 | } |
| 41 | } |