diff --git a/migrations/.keep b/migrations/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/2023-06-10-132201_collection/down.sql b/migrations/2023-06-10-132201_collection/down.sql deleted file mode 100644 index 03b11f2..0000000 --- a/migrations/2023-06-10-132201_collection/down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table collections; diff --git a/migrations/2023-06-10-132201_collection/up.sql b/migrations/2023-06-10-132201_collection/up.sql deleted file mode 100644 index ed08b3c..0000000 --- a/migrations/2023-06-10-132201_collection/up.sql +++ /dev/null @@ -1,11 +0,0 @@ -create table collections -( - id integer not null - constraint collections_pk - primary key autoincrement, - path TEXT not null -); - --- noinspection SpellCheckingInspection @ index/"collections_path_uindex" -create unique index collections_path_uindex - on collections (path); diff --git a/migrations/2023-06-18-135123_config/down.sql b/migrations/2023-06-18-135123_config/down.sql deleted file mode 100644 index 3492d18..0000000 --- a/migrations/2023-06-18-135123_config/down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table config; diff --git a/migrations/2023-06-18-135123_config/up.sql b/migrations/2023-06-18-135123_config/up.sql deleted file mode 100644 index 1718d61..0000000 --- a/migrations/2023-06-18-135123_config/up.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table config -( - volume REAL not null - constraint config_pk - primary key -); - -insert into config(volume) -values (0.5); diff --git a/migrations/2023-06-20-124758_collection_id_to_row/down.sql b/migrations/2023-06-20-124758_collection_id_to_row/down.sql deleted file mode 100644 index 3b4caf2..0000000 --- a/migrations/2023-06-20-124758_collection_id_to_row/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table collections - drop column row; diff --git a/migrations/2023-06-20-124758_collection_id_to_row/up.sql b/migrations/2023-06-20-124758_collection_id_to_row/up.sql deleted file mode 100644 index 653f904..0000000 --- a/migrations/2023-06-20-124758_collection_id_to_row/up.sql +++ /dev/null @@ -1,3 +0,0 @@ --- noinspection SqlAddNotNullColumn -alter table collections - add row integer not null; diff --git a/migrations/2023-06-23-095534_songs/down.sql b/migrations/2023-06-23-095534_songs/down.sql deleted file mode 100644 index 404acc6..0000000 --- a/migrations/2023-06-23-095534_songs/down.sql +++ /dev/null @@ -1,4 +0,0 @@ -drop table songs; - -alter table collections - drop modified; diff --git a/migrations/2023-06-23-095534_songs/up.sql b/migrations/2023-06-23-095534_songs/up.sql deleted file mode 100644 index c72ea4a..0000000 --- a/migrations/2023-06-23-095534_songs/up.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table songs -( - id integer not null - constraint songs_pk - primary key autoincrement, - path TEXT not null, - collection_id integer not null - constraint songs_collections_id_fk - references collections - on update cascade on delete cascade -); - --- noinspection SpellCheckingInspection @ index/"songs_path_uindex" -create unique index songs_path_uindex - on songs (path); - -alter table collections - add modified sqlite_uint64; diff --git a/migrations/2023-06-24-134554_add_song_tags/down.sql b/migrations/2023-06-24-134554_add_song_tags/down.sql deleted file mode 100644 index ca7e803..0000000 --- a/migrations/2023-06-24-134554_add_song_tags/down.sql +++ /dev/null @@ -1,20 +0,0 @@ -alter table songs - drop title; - -alter table songs - drop artist; - -alter table songs - drop album; - -alter table songs - drop datetime; - -alter table songs - drop genre; - -alter table songs - drop track_number; - -alter table songs - drop album_artist; diff --git a/migrations/2023-06-24-134554_add_song_tags/up.sql b/migrations/2023-06-24-134554_add_song_tags/up.sql deleted file mode 100644 index dee76e3..0000000 --- a/migrations/2023-06-24-134554_add_song_tags/up.sql +++ /dev/null @@ -1,22 +0,0 @@ --- noinspection SqlAddNotNullColumnForFile - -alter table songs - add title TEXT; - -alter table songs - add artist TEXT; - -alter table songs - add album TEXT; - -alter table songs - add datetime sqlite_uint64; - -alter table songs - add genre TEXT; - -alter table songs - add track_number integer; - -alter table songs - add album_artist TEXT; diff --git a/migrations/2023-06-26-153154_current_song_id/down.sql b/migrations/2023-06-26-153154_current_song_id/down.sql deleted file mode 100644 index 1f42e41..0000000 --- a/migrations/2023-06-26-153154_current_song_id/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table config - drop column current_song_id; diff --git a/migrations/2023-06-26-153154_current_song_id/up.sql b/migrations/2023-06-26-153154_current_song_id/up.sql deleted file mode 100644 index 8893b82..0000000 --- a/migrations/2023-06-26-153154_current_song_id/up.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table config - add column current_song_id integer - constraint config_songs_id_fk - references songs - on update cascade on delete set null; diff --git a/migrations/2023-07-02-084052_add_duration_to_song/down.sql b/migrations/2023-07-02-084052_add_duration_to_song/down.sql deleted file mode 100644 index a15c3b5..0000000 --- a/migrations/2023-07-02-084052_add_duration_to_song/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table songs - drop column duration; diff --git a/migrations/2023-07-02-084052_add_duration_to_song/up.sql b/migrations/2023-07-02-084052_add_duration_to_song/up.sql deleted file mode 100644 index 1e01084..0000000 --- a/migrations/2023-07-02-084052_add_duration_to_song/up.sql +++ /dev/null @@ -1,10 +0,0 @@ --- noinspection SqlWithoutWhere -delete -from songs; --- noinspection SqlWithoutWhere -delete -from collections; - --- noinspection SqlAddNotNullColumn -alter table songs - add duration sqlite_uint64 not null; diff --git a/migrations/2023-07-12-084641_add_window_width_height/down.sql b/migrations/2023-07-12-084641_add_window_width_height/down.sql deleted file mode 100644 index 9399f8f..0000000 --- a/migrations/2023-07-12-084641_add_window_width_height/down.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table config - drop column window_width; - -alter table config - drop column window_height; diff --git a/migrations/2023-07-12-084641_add_window_width_height/up.sql b/migrations/2023-07-12-084641_add_window_width_height/up.sql deleted file mode 100644 index dd1f8aa..0000000 --- a/migrations/2023-07-12-084641_add_window_width_height/up.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table config - add window_width integer default 0 not null; - -alter table config - add window_height integer default 0 not null; diff --git a/migrations/2023-07-12-091353_add_window_maximized/down.sql b/migrations/2023-07-12-091353_add_window_maximized/down.sql deleted file mode 100644 index b5e7793..0000000 --- a/migrations/2023-07-12-091353_add_window_maximized/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table config - drop column maximized; diff --git a/migrations/2023-07-12-091353_add_window_maximized/up.sql b/migrations/2023-07-12-091353_add_window_maximized/up.sql deleted file mode 100644 index 792268e..0000000 --- a/migrations/2023-07-12-091353_add_window_maximized/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table config - add maximized integer default 0 not null; diff --git a/migrations/2023-07-15-083145_add_song_indexes/down.sql b/migrations/2023-07-15-083145_add_song_indexes/down.sql deleted file mode 100644 index b7368f3..0000000 --- a/migrations/2023-07-15-083145_add_song_indexes/down.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop index songs_artist_index; - -drop index songs_collection_id_index; diff --git a/migrations/2023-07-15-083145_add_song_indexes/up.sql b/migrations/2023-07-15-083145_add_song_indexes/up.sql deleted file mode 100644 index 533bfa2..0000000 --- a/migrations/2023-07-15-083145_add_song_indexes/up.sql +++ /dev/null @@ -1,5 +0,0 @@ -create index songs_artist_index - on songs (artist); - -create index songs_collection_id_index - on songs (collection_id); diff --git a/migrations/2023-07-17-095420_add_current_song_position/down.sql b/migrations/2023-07-17-095420_add_current_song_position/down.sql deleted file mode 100644 index 86e9564..0000000 --- a/migrations/2023-07-17-095420_add_current_song_position/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table config - drop column current_song_position; diff --git a/migrations/2023-07-17-095420_add_current_song_position/up.sql b/migrations/2023-07-17-095420_add_current_song_position/up.sql deleted file mode 100644 index 52f24f1..0000000 --- a/migrations/2023-07-17-095420_add_current_song_position/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table config - add current_song_position sqlite_uint64 default 0 not null; diff --git a/migrations/2023-07-19-141303_history_bodies/down.sql b/migrations/2023-07-19-141303_history_bodies/down.sql deleted file mode 100644 index 2ebce8e..0000000 --- a/migrations/2023-07-19-141303_history_bodies/down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table history_bodies; diff --git a/migrations/2023-07-19-141303_history_bodies/up.sql b/migrations/2023-07-19-141303_history_bodies/up.sql deleted file mode 100644 index dbf062c..0000000 --- a/migrations/2023-07-19-141303_history_bodies/up.sql +++ /dev/null @@ -1,8 +0,0 @@ -create table history_bodies -( - id integer not null - constraint history_bodies_pk - primary key autoincrement, - query TEXT, - body_type TEXT not null -); diff --git a/migrations/2023-07-20-061919_last_scroll_adjustment/down.sql b/migrations/2023-07-20-061919_last_scroll_adjustment/down.sql deleted file mode 100644 index 1bbabbc..0000000 --- a/migrations/2023-07-20-061919_last_scroll_adjustment/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table history_bodies - drop column scroll_adjustment; diff --git a/migrations/2023-07-20-061919_last_scroll_adjustment/up.sql b/migrations/2023-07-20-061919_last_scroll_adjustment/up.sql deleted file mode 100644 index 414b00d..0000000 --- a/migrations/2023-07-20-061919_last_scroll_adjustment/up.sql +++ /dev/null @@ -1,29 +0,0 @@ -create table config_dg_tmp -( - volume REAL not null, - current_song_id integer - constraint config_pk - primary key - constraint config_songs_id_fk - references songs - on update cascade on delete set null, - window_width integer default 0 not null, - window_height integer default 0 not null, - maximized integer default 0 not null, - current_song_position sqlite_uint64 default 0 not null -); - -insert into config_dg_tmp(volume, current_song_id, window_width, window_height, maximized, current_song_position) -select volume, current_song_id, window_width, window_height, maximized, current_song_position -from config; - -drop table config; - -alter table config_dg_tmp - rename to config; - -alter table config - drop column volume; - -alter table history_bodies - add scroll_adjustment REAL; diff --git a/migrations/2023-07-24-135519_song_selected_body/down.sql b/migrations/2023-07-24-135519_song_selected_body/down.sql deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/2023-07-24-135519_song_selected_body/up.sql b/migrations/2023-07-24-135519_song_selected_body/up.sql deleted file mode 100644 index 93ebe2b..0000000 --- a/migrations/2023-07-24-135519_song_selected_body/up.sql +++ /dev/null @@ -1,12 +0,0 @@ -create table bodies -( - id integer not null - constraint bodies_pk - primary key autoincrement, - query TEXT, - body_type TEXT not null, - scroll_adjustment REAL, - navigation_type TEXT not null -); - -drop table history_bodies; diff --git a/migrations/2023-07-25-072251_query2/down.sql b/migrations/2023-07-25-072251_query2/down.sql deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/2023-07-25-072251_query2/up.sql b/migrations/2023-07-25-072251_query2/up.sql deleted file mode 100644 index 43d95ff..0000000 --- a/migrations/2023-07-25-072251_query2/up.sql +++ /dev/null @@ -1,20 +0,0 @@ -create table bodies_dg_tmp -( - id integer not null - constraint bodies_pk - primary key autoincrement, - query1 TEXT, - body_type TEXT not null, - scroll_adjustment REAL, - navigation_type TEXT not null, - query2 TEXT -); - -insert into bodies_dg_tmp(id, query1, body_type, scroll_adjustment, navigation_type) -select id, query, body_type, scroll_adjustment, navigation_type -from bodies; - -drop table bodies; - -alter table bodies_dg_tmp - rename to bodies; diff --git a/migrations/2023-08-02-074132_remove_collection_row/up.sql b/migrations/2023-08-02-074132_remove_collection_row/up.sql deleted file mode 100644 index 3b4caf2..0000000 --- a/migrations/2023-08-02-074132_remove_collection_row/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table collections - drop column row; diff --git a/migrations/2023-08-02-074132_remove_collection_row/down.sql b/migrations/2023-08-06-122201_init/down.sql similarity index 100% rename from migrations/2023-08-02-074132_remove_collection_row/down.sql rename to migrations/2023-08-06-122201_init/down.sql diff --git a/migrations/2023-08-06-122201_init/up.sql b/migrations/2023-08-06-122201_init/up.sql new file mode 100644 index 0000000..59f125e --- /dev/null +++ b/migrations/2023-08-06-122201_init/up.sql @@ -0,0 +1,70 @@ +create table bodies +( + id integer not null + constraint bodies_pk + primary key autoincrement, + query1 TEXT, + body_type TEXT not null, + scroll_adjustment REAL, + navigation_type TEXT not null, + query2 TEXT +); + +create table collections +( + id integer not null + constraint collections_pk + primary key autoincrement, + path TEXT not null, + modified sqlite_uint64 +); + +create unique index collections_path_uindex + on collections (path); + +create table songs +( + id integer not null + constraint songs_pk + primary key autoincrement, + path TEXT not null, + collection_id integer not null + constraint songs_collections_id_fk + references collections + on update cascade on delete cascade, + title TEXT, + artist TEXT, + album TEXT, + datetime sqlite_uint64, + genre TEXT, + track_number integer, + album_artist TEXT, + duration sqlite_uint64 not null +); + +create table config +( + current_song_position sqlite_uint64 not null + constraint config_pk + primary key, + current_song_id integer + constraint config_songs_id_fk + references songs + on update cascade on delete set null, + window_width integer default 0 not null, + window_height integer default 0 not null, + maximized integer default 0 not null, + now_playing_body_realized integer default 0 not null +); + +insert into config(current_song_position) +VALUES (0); + +create index songs_artist_index + on songs (artist); + +create index songs_collection_id_index + on songs (collection_id); + +create unique index songs_path_uindex + on songs (path); diff --git a/src/config/mod.rs b/src/config/mod.rs index de41007..66a82e9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,12 +1,22 @@ use diesel::prelude::*; +use diesel::update; +use crate::db::get_connection; +use crate::schema::config::dsl::config; +use crate::schema::config::now_playing_body_realized; #[derive(Queryable, Selectable, Debug)] #[diesel(table_name = crate::schema::config)] #[diesel(check_for_backend(diesel::sqlite::Sqlite))] pub struct Config { + pub current_song_position: i64, pub current_song_id: Option, pub window_width: i32, pub window_height: i32, pub maximized: i32, - pub current_song_position: i64, + pub now_playing_body_realized: i32, +} + +pub fn update_now_playing_body_realized(realized: bool) { + update(config).set(now_playing_body_realized.eq(if realized { 1 } else { 0 })).execute(&mut get_connection()) + .unwrap(); } diff --git a/src/main.rs b/src/main.rs index 294e00e..8ae9fed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,13 +64,13 @@ fn main() -> Result { let back_button = Button::builder().icon_name(BACK_ICON).tooltip_text("Home").visible(history_bodies.len() > 1) .build(); header_bar.pack_start(&back_button); - let now_playing = now_playing::create(song_selected_body.clone(), &window_title, &scrolled_window, - history.clone(), &back_button, &header_body, &body); - body.append(&now_playing); + let (now_playing_body, wrapper, now_playing) = now_playing::create(song_selected_body.clone(), &window_title, + &scrolled_window, history.clone(), &back_button, &header_body, &body); + body.append(&wrapper); *song_selected_body.borrow_mut() = bodies.filter(navigation_type.eq(SongSelected)).limit(1) .get_result::(&mut get_connection()).ok().map(|body_table| { let body = Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(), - &now_playing, &back_button, &window); + &wrapper, &back_button, &window); body.scroll_adjustment.set(body_table.scroll_adjustment); Rc::new(body) }); @@ -96,12 +96,12 @@ fn main() -> Result { } }); for body_table in history_bodies { - Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(), &now_playing, + Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(), &wrapper, &back_button, &window, ).put_to_history(body_table.scroll_adjustment, history.clone()); } if empty_history { - Rc::new(Body::artists(&window_title, &scrolled_window, history.clone(), &now_playing, + Rc::new(Body::artists(&window_title, &scrolled_window, history.clone(), &wrapper, &Some(back_button.clone())) ).set(&window_title, &scrolled_window, history.clone(), &None); } else if let Some((body, _)) = history.borrow().last() { @@ -110,6 +110,9 @@ fn main() -> Result { scrolled_window.set_child(Some((**widget).as_ref())); scrolled_window.adjust(&body_scroll_adjustment); } + if config.now_playing_body_realized == 1 { + now_playing.borrow().realize_body(&window_title, &back_button, &header_body, &now_playing_body); + } window.connect_close_request({ let history = history.clone(); let scrolled_window = scrolled_window.clone(); diff --git a/src/now_playing/mod.rs b/src/now_playing/mod.rs index f09f4c6..72a2783 100644 --- a/src/now_playing/mod.rs +++ b/src/now_playing/mod.rs @@ -20,7 +20,7 @@ use crate::common::AdjustableScrolledWindow; use crate::common::constant::BACK_ICON; use crate::common::util::or_none; use crate::common::wrapper::{SONG_SELECTED, STREAM_STARTED, Wrapper}; -use crate::config::Config; +use crate::config::{Config, update_now_playing_body_realized}; use crate::db::get_connection; use crate::now_playing::mpris::mpris_player; use crate::now_playing::now_playing::{NowPlaying, Playable}; @@ -42,7 +42,7 @@ mod body; pub fn create(song_selected_body: Rc>>>, window_title: &WindowTitle, scrolled_window: &ScrolledWindow, history: Rc, bool)>>>, back_button: &Button, - header_body: >k::Box, body: >k::Box) -> Wrapper { + header_body: >k::Box, body: >k::Box) -> (gtk::Box, Wrapper, Rc>) { let now_playing = Rc::new(RefCell::new(NowPlaying::new())); let (now_playing_body, body_skip_song_gesture) = body::create(now_playing.clone()); let (bottom_widget, bottom_skip_song_gesture, image_click) = bottom_widget::create( @@ -64,7 +64,8 @@ pub fn create(song_selected_body: Rc>>>, window_title: & let now_playing_body = now_playing_body.clone(); move |gesture, _, _, _| { gesture.set_state(EventSequenceState::Claimed); - now_playing.borrow().update_other(&window_title, &back_button, "go-down", &header_body, &now_playing_body); + now_playing.borrow().realize_body(&window_title, &back_button, &header_body, &now_playing_body); + update_now_playing_body_realized(true); } }); let wrapper = Wrapper::new(&bottom_widget); @@ -77,6 +78,7 @@ pub fn create(song_selected_body: Rc>>>, window_title: & let scrolled_window = scrolled_window.clone(); let wrapper = wrapper.clone(); move |back_button| { + update_now_playing_body_realized(false); if history.borrow().is_empty() { back_button.set_visible(false); Rc::new(Body::artists(&window_title, &scrolled_window, history.clone(), &wrapper, @@ -239,5 +241,5 @@ pub fn create(song_selected_body: Rc>>>, window_title: & Continue(true) } }).unwrap(); - wrapper + (now_playing_body, wrapper, now_playing) } diff --git a/src/now_playing/now_playing.rs b/src/now_playing/now_playing.rs index 4aef145..b7035ec 100644 --- a/src/now_playing/now_playing.rs +++ b/src/now_playing/now_playing.rs @@ -166,6 +166,10 @@ impl NowPlaying { header_body.remove(&header_body.last_child().unwrap()); header_body.append(body); } + pub fn realize_body(&self, window_title: &WindowTitle, back_button: &Button, header_body: >k::Box, + body: >k::Box) { + self.update_other(window_title, back_button, "go-down", header_body, body); + } pub fn set_album_image(&mut self, cover: PathBuf) -> Option { let result = if cover.exists() { cover.to_str().map(|it| { format!("file:{}", it) }) } else { None }; self.cover = Some(cover); diff --git a/src/schema.rs b/src/schema.rs index 24a723b..490f78f 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -20,12 +20,13 @@ diesel::table! { } diesel::table! { - config (current_song_id) { + config (current_song_position) { + current_song_position -> BigInt, current_song_id -> Nullable, window_width -> Integer, window_height -> Integer, maximized -> Integer, - current_song_position -> BigInt, + now_playing_body_realized -> Integer, } }