Skip to content

Commit

Permalink
#49 should be fixed. untested changes though...
Browse files Browse the repository at this point in the history
  • Loading branch information
nednoodlehead committed Jul 11, 2024
1 parent c44c62d commit 1712376
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/db/create_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn create_table_defaults() -> Result<(), DatabaseErrors> {
0,
String::from("00:00:00"),
false, // so technically it is 'auto gen', but not in the right sense
1,
0, // hey stupid. indexing starts a zero
"main"
],
)?;
Expand Down
59 changes: 59 additions & 0 deletions src/db/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,62 @@ pub fn move_playlist_down_one(uniqueid: &str, count: u16) -> Result<(), Database

Ok(())
}

pub fn move_song_up_one(
song_uuid: String,
position: usize,
playlist_uuid: String,
) -> Result<(), DatabaseErrors> {
// we must differenciate between a change on 'main' and playlist, since the sql is different
let conn = Connection::open("main.db")?;
if playlist_uuid != "main" {
// set the new number's number to -1
conn.execute("UPDATE playlist_relations SET user_playlist_order = user_playlist_order - 1 WHERE user_playlist_order = ?", params![position])?;
// update the one we are moving up to the new number
conn.execute("UPDATE playlist_relations SET user_playlist_order = ? WHERE song_id = ? AND playlist_id = ?", params![position, &song_uuid, &playlist_uuid])?;
} else {
conn.execute(
"UPDATE main SET user_order = user_order - 1 WHERE user_order = ?",
params![position],
)?;
conn.execute(
"UPDATE main SET user_order = ? WHERE uniqueid = ?",
params![position, song_uuid],
)?;
}
conn.close().map_err(|(_, err)| err)?;
Ok(())
}
// like i guess you could make these ^ & v one function? maybe something to refactor *one* day :)
pub fn move_song_down_one(
song_uuid: String,
position: usize,
playlist_uuid: String,
) -> Result<(), DatabaseErrors> {
// we must differenciate between a change on 'main' and playlist, since the sql is different
let conn = Connection::open("main.db")?;
let position = position + 1;
if playlist_uuid != "main" {
// set the new number's number to +1
conn.execute("UPDATE playlist_relations SET user_playlist_order = user_playlist_order - 1 WHERE user_playlist_order = ? AND playlist_id = ?", params![position, &playlist_uuid])?;
// update the one we are moving up to the new number
conn.execute(
"UPDATE playlist_relations SET user_playlist_order = ",
params![position, &song_uuid, &playlist_uuid],
)?;
} else {
// the one we are affecting but didnt select
println!("{} {} ??", position, &song_uuid);
conn.execute(
// CORRECT!!!
"UPDATE main SET user_order = user_order - 1 WHERE user_order = ?",
params![position],
)?;
conn.execute(
"UPDATE main SET user_order = user_order + 1 WHERE uniqueid = ?",
params![song_uuid],
)?;
}
conn.close().map_err(|(_, err)| err)?;
Ok(())
}
3 changes: 3 additions & 0 deletions src/gui/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ pub enum ProgramCommands {
PlaySong(String), // unqiueid
SelectSong(String, bool, usize), // uniqueid is_checked, row #, used to do stuff to the current song
DeleteSong, // TODO do this interface.. probably want some type of confirmation..
MoveSongUp(String, usize), // song_uuid, current position
MoveSongDown(String, usize), // song_uuid, current position
SyncHeader(scrollable::AbsoluteOffset), // not used, could revamp table tbh..
AddToPlaylist(String), // uuid of playlist choosen song is based on checkboxes, playlist is determined by viewing list
ToggleList,
ToggleEditMode,
CreateBackup,
UpdateWidgetText(TextType, String),
SaveConfig,
Expand Down
40 changes: 37 additions & 3 deletions src/gui/start.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::db::fetch::{get_all_from_playlist, get_all_main, get_all_playlists, get_obj_from_uuid};
use crate::db::insert::{add_to_playlist, create_playlist};
use crate::db::update::{
delete_from_playlist, delete_playlist, update_auth_album, update_song, update_title_auth,
delete_from_playlist, delete_playlist, move_song_down_one, move_song_up_one, update_auth_album,
update_song, update_title_auth,
};
use crate::gui::messages::{
AppEvent, CheckBoxType, ComboBoxType, Context, Page, ProgramCommands, PungeCommand, TextType,
Expand Down Expand Up @@ -102,9 +103,10 @@ pub struct App {
// tarkah table stuff
header: scrollable::Id,
body: scrollable::Id,
_footer: scrollable::Id,
_footer: scrollable::Id, // maybe i should use this one day ...
columns: Vec<Column>,
rows: Vec<Row>,
toggle_table_edit: bool, // used to toggle the 'edit' mode. keeps track of it
}

impl Application for App {
Expand Down Expand Up @@ -193,6 +195,7 @@ impl Application for App {
ischecked: false,
})
.collect(), // get it from the other file lol
toggle_table_edit: false,
},
Command::none(),
)
Expand Down Expand Up @@ -368,6 +371,8 @@ impl Application for App {
// to guarentee that the order is preserved, we add an empty entry with just the uuid
// then, after the downloads have completed, we either update the entry with the data
// or remove the entry afterwards if it fails
let mut count = 0;
let default_count = self.user_playlists[0].songcount;
for song in playlist.videos.clone() {
let full_url = format!("https://youtube.com/watch?v={}", &song.url);
self.download_page
Expand All @@ -378,11 +383,12 @@ impl Application for App {
download_interface(
full_url,
Some(playlist.name.clone()),
self.user_playlists[0].songcount,
default_count + count,
),
|yt_data| ProgramCommands::AddToDownloadFeedback(song.title, yt_data),
);
list_cmd.push(cmd);
count += 1;
}
// add the empty entries!
Command::batch(list_cmd)
Expand Down Expand Up @@ -1083,6 +1089,34 @@ impl Application for App {
self.user_playlists = get_all_playlists().unwrap();
Command::none()
}
ProgramCommands::ToggleEditMode => {
println!("col width: {}", self.columns[4].width);
if self.toggle_table_edit {
if let Some(col) = self.columns.get_mut(4) {
col.width = 35.0;
}
self.toggle_table_edit = false;
self.columns[3].width = 275.0;
} else {
if let Some(col) = self.columns.get_mut(4) {
col.width = 100.0;
}
self.columns[3].width = 210.0;
self.toggle_table_edit = true;
};
Command::none()
}
Self::Message::MoveSongUp(uuid, position) => {
move_song_up_one(uuid, position, self.viewing_playlist.clone()).unwrap();
self.refresh_playlist();
Command::none()
}
Self::Message::MoveSongDown(uuid, position) => {
println!("????");
move_song_down_one(uuid, position, self.viewing_playlist.clone()).unwrap();
self.refresh_playlist();
Command::none()
}

_ => Command::none(),
}
Expand Down
35 changes: 24 additions & 11 deletions src/gui/table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// shoutout to github.com/tarkah for this banger !!!
// and we will sit here praying until https://github.com/iced-rs/iced/issues/160 comes out!
use crate::gui::messages::ProgramCommands;
use iced::widget::{button, checkbox, container, horizontal_space, text};
use iced::widget::{button, checkbox, container, horizontal_space, row, text};
use iced::Element;
use iced::{Length, Renderer, Theme};
use iced_table::table;
Expand All @@ -10,7 +10,7 @@ use iced_table::table;

pub struct Column {
kind: ColumnKind,
width: f32,
pub width: f32,
resize_offset: Option<f32>,
}

Expand Down Expand Up @@ -40,11 +40,17 @@ impl<'a> table::Column<'a, ProgramCommands, Theme, Renderer> for Column {
ColumnKind::Author => text("Author").into(),
ColumnKind::Title => text("Title").into(),
ColumnKind::Album => text("Album").into(),
ColumnKind::Edit => button(text("tog").size(10))
.width(100)
.height(100)
.on_press(ProgramCommands::ToggleList)
.into(),
ColumnKind::Edit => row![
button(text("edit").size(10))
.width(40)
.height(40)
.on_press(ProgramCommands::ToggleEditMode),
button(text(" ").size(10))
.on_press(ProgramCommands::ToggleList)
.width(40)
.height(40)
]
.into(),
};

container(content).height(24).center_y().into()
Expand All @@ -63,11 +69,18 @@ impl<'a> table::Column<'a, ProgramCommands, Theme, Renderer> for Column {
ColumnKind::Author => text(row.author.clone()).into(),
ColumnKind::Title => text(row.title.clone()).into(),
ColumnKind::Album => text(row.album.clone()).into(),
ColumnKind::Edit => checkbox("", row.ischecked)
.on_toggle(move |bol| {
ColumnKind::Edit => row![
checkbox("", row.ischecked).on_toggle(move |bol| {
ProgramCommands::SelectSong(row.uniqueid.clone(), bol, row_index)
})
.into(),
}),
button(text("^"))
.on_press(ProgramCommands::MoveSongUp(row.uniqueid.clone(), row_index)),
button(text("v")).on_press(ProgramCommands::MoveSongDown(
row.uniqueid.clone(),
row_index
))
]
.into(),
};

container(content)
Expand Down

0 comments on commit 1712376

Please sign in to comment.