mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Hook up library manager
This commit is contained in:
parent
e4940d693b
commit
19670da538
6 changed files with 88 additions and 2 deletions
|
|
@ -156,6 +156,10 @@ template $MusicusHomePage : Adw.NavigationPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
menu primary_menu {
|
menu primary_menu {
|
||||||
|
item {
|
||||||
|
label: _("_Library manager");
|
||||||
|
action: "win.library";
|
||||||
|
}
|
||||||
item {
|
item {
|
||||||
label: _("_Preferences");
|
label: _("_Preferences");
|
||||||
action: "app.preferences";
|
action: "app.preferences";
|
||||||
|
|
|
||||||
12
data/ui/library_manager.blp
Normal file
12
data/ui/library_manager.blp
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
using Adw 1;
|
||||||
|
|
||||||
|
template $MusicusLibraryManager : Adw.NavigationPage {
|
||||||
|
title: _("Music Library");
|
||||||
|
tag: "library";
|
||||||
|
|
||||||
|
Adw.ToolbarView {
|
||||||
|
[top]
|
||||||
|
Adw.HeaderBar {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
data/ui/home_page.blp
|
data/ui/home_page.blp
|
||||||
|
data/ui/library_manager.blp
|
||||||
data/ui/player_bar.blp
|
data/ui/player_bar.blp
|
||||||
data/ui/playlist_page.blp
|
data/ui/playlist_page.blp
|
||||||
data/ui/playlist_tile.blp
|
data/ui/playlist_tile.blp
|
||||||
|
|
|
||||||
53
src/library_manager.rs
Normal file
53
src/library_manager.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
use crate::library::MusicusLibrary;
|
||||||
|
use adw::{
|
||||||
|
prelude::*,
|
||||||
|
subclass::{navigation_page::NavigationPageImpl, prelude::*},
|
||||||
|
};
|
||||||
|
use gtk::glib::{self, Properties};
|
||||||
|
use std::cell::OnceCell;
|
||||||
|
|
||||||
|
mod imp {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Properties, Debug, Default, gtk::CompositeTemplate)]
|
||||||
|
#[properties(wrapper_type = super::LibraryManager)]
|
||||||
|
#[template(file = "data/ui/library_manager.blp")]
|
||||||
|
pub struct LibraryManager {
|
||||||
|
#[property(get, construct_only)]
|
||||||
|
pub library: OnceCell<MusicusLibrary>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for LibraryManager {
|
||||||
|
const NAME: &'static str = "MusicusLibraryManager";
|
||||||
|
type Type = super::LibraryManager;
|
||||||
|
type ParentType = adw::NavigationPage;
|
||||||
|
|
||||||
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
klass.bind_template();
|
||||||
|
klass.bind_template_instance_callbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||||
|
obj.init_template();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::derived_properties]
|
||||||
|
impl ObjectImpl for LibraryManager {}
|
||||||
|
|
||||||
|
impl WidgetImpl for LibraryManager {}
|
||||||
|
impl NavigationPageImpl for LibraryManager {}
|
||||||
|
}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct LibraryManager(ObjectSubclass<imp::LibraryManager>)
|
||||||
|
@extends gtk::Widget, adw::NavigationPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gtk::template_callbacks]
|
||||||
|
impl LibraryManager {
|
||||||
|
pub fn new(library: &MusicusLibrary) -> Self {
|
||||||
|
glib::Object::builder().property("library", library).build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod application;
|
mod application;
|
||||||
mod config;
|
mod config;
|
||||||
mod home_page;
|
mod home_page;
|
||||||
|
mod library_manager;
|
||||||
mod library;
|
mod library;
|
||||||
mod player;
|
mod player;
|
||||||
mod player_bar;
|
mod player_bar;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
home_page::MusicusHomePage, library::MusicusLibrary, player::MusicusPlayer,
|
home_page::MusicusHomePage, library::MusicusLibrary, library_manager::LibraryManager,
|
||||||
player_bar::PlayerBar, playlist_page::MusicusPlaylistPage, welcome_page::MusicusWelcomePage,
|
player::MusicusPlayer, player_bar::PlayerBar, playlist_page::MusicusPlaylistPage,
|
||||||
|
welcome_page::MusicusWelcomePage,
|
||||||
};
|
};
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use gtk::{gio, glib, glib::clone, prelude::*};
|
use gtk::{gio, glib, glib::clone, prelude::*};
|
||||||
|
|
@ -44,6 +45,15 @@ mod imp {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
self.obj().load_window_state();
|
self.obj().load_window_state();
|
||||||
|
|
||||||
|
let navigation_view = self.navigation_view.get().to_owned();
|
||||||
|
let library_action = gio::ActionEntry::builder("library")
|
||||||
|
.activate(move |_: &super::MusicusWindow, _, _| {
|
||||||
|
navigation_view.push_by_tag("library")
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
self.obj().add_action_entries([library_action]);
|
||||||
|
|
||||||
let player_bar = PlayerBar::new(&self.player);
|
let player_bar = PlayerBar::new(&self.player);
|
||||||
self.player_bar_revealer.set_child(Some(&player_bar));
|
self.player_bar_revealer.set_child(Some(&player_bar));
|
||||||
|
|
||||||
|
|
@ -144,8 +154,13 @@ impl MusicusWindow {
|
||||||
|
|
||||||
fn load_library(&self, path: impl AsRef<Path>) {
|
fn load_library(&self, path: impl AsRef<Path>) {
|
||||||
let library = MusicusLibrary::new(path);
|
let library = MusicusLibrary::new(path);
|
||||||
|
|
||||||
self.imp()
|
self.imp()
|
||||||
.navigation_view
|
.navigation_view
|
||||||
.replace(&[MusicusHomePage::new(&library, &self.imp().player).into()]);
|
.replace(&[MusicusHomePage::new(&library, &self.imp().player).into()]);
|
||||||
|
|
||||||
|
self.imp()
|
||||||
|
.navigation_view
|
||||||
|
.add(&LibraryManager::new(&library));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue