Compare commits

..

No commits in common. "0320e12206547a665aab4a734110afb0aa847917" and "118b2d6f7e5c17f143dc3595ffedad30785d5c45" have entirely different histories.

10 changed files with 160 additions and 100 deletions

View file

@ -28,16 +28,16 @@ template $AudreyUiPlayQueue: Adw.Bin {
show-separators: true;
single-click-activate: true;
activate => $on_row_activated () swapped;
activate => $on_row_activated ();
model: NoSelection {
model: bind template.playbin as <$AudreyPlaybin>.play_queue;
};
factory: SignalListItemFactory {
setup => $on_song_list_setup () swapped;
bind => $on_song_list_bind () swapped;
unbind => $on_song_list_unbind () swapped;
setup => $on_song_list_setup ();
bind => $on_song_list_bind ();
unbind => $on_song_list_unbind ();
};
}
};

View file

@ -1,6 +0,0 @@
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
include!(concat!(env!("OUT_DIR"), "/audrey_ffi.rs"));

View file

@ -29,7 +29,6 @@ fn main() -> glib::ExitCode {
gio::resources_register_include!("audrey.gresource").expect("could not register resources");
ui::Playbar::ensure_type();
ui::PlayQueue::ensure_type();
gtk::disable_setlocale();
bindtextdomain("audrey", meson_config::LOCALEDIR).expect("failed to bind text domain");

View file

@ -5,6 +5,7 @@ audrey_sources = [
'playbin.vala',
'rust.vapi',
'subsonic.vala',
'ui/play_queue.vala',
'ui/setup.vala',
'ui/window.vala',
]

View file

@ -40,7 +40,6 @@ pub mod ffi {
to: std::ffi::c_uint,
);
pub fn audrey_playbin_remove_track(self_: *mut AudreyPlaybin, position: std::ffi::c_uint);
pub fn audrey_playbin_select_track(self_: *mut AudreyPlaybin, position: std::ffi::c_uint);
}
}
@ -117,8 +116,4 @@ impl Playbin {
pub fn remove_track(&self, position: u32) {
unsafe { ffi::audrey_playbin_remove_track(self.to_glib_none().0, position) }
}
pub fn select_track(&self, position: u32) {
unsafe { ffi::audrey_playbin_select_track(self.to_glib_none().0, position) }
}
}

View file

@ -15,6 +15,3 @@ void audrey_ui_play_queue_song_set_show_artist(AudreyUiPlayQueueSong *self, gboo
void audrey_ui_play_queue_song_set_show_cover(AudreyUiPlayQueueSong *self, gboolean show_cover);
void audrey_ui_play_queue_song_bind(AudreyUiPlayQueueSong *self, guint position, void *song);
void audrey_ui_play_queue_song_unbind(AudreyUiPlayQueueSong *self);
// ui::PlayQueue
typedef void AudreyUiPlayQueue;

View file

@ -23,9 +23,4 @@ namespace Audrey {
public void unbind ();
}
public class Ui.PlayQueue : Adw.Bin {
public Playbin playbin { get; set; }
public bool can_clear_all { get; }
}
}

View file

@ -1,92 +1,32 @@
pub mod song;
pub use song::Song;
mod imp {
use adw::{glib, prelude::*, subclass::prelude::*};
use glib::{subclass::InitializingObject, WeakRef};
mod ffi {
use gtk::glib;
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
#[template(resource = "/eu/callcc/audrey/play_queue.ui")]
#[properties(wrapper_type = super::PlayQueue)]
pub struct PlayQueue {
#[property(get, set)]
playbin: WeakRef<crate::Playbin>,
#[repr(C)]
pub struct AudreyUiPlayQueue {
_data: [u8; 0],
}
#[glib::object_subclass]
impl ObjectSubclass for PlayQueue {
const NAME: &'static str = "AudreyUiPlayQueue";
type Type = super::PlayQueue;
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.bind_template_callbacks();
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
#[repr(C)]
pub struct AudreyUiPlayQueueClass {
_data: [u8; 0],
}
#[glib::derived_properties]
impl ObjectImpl for PlayQueue {}
impl WidgetImpl for PlayQueue {}
impl BinImpl for PlayQueue {}
#[gtk::template_callbacks]
impl PlayQueue {
#[template_callback]
fn visible_child_name(&self, n_items: u32) -> &'static str {
if n_items > 0 {
"not-empty"
} else {
"empty"
}
}
#[template_callback]
fn on_song_list_setup(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = super::Song::new(&self.playbin.upgrade().unwrap());
child.set_draggable(true);
child.set_show_position(true);
child.set_show_artist(true);
child.set_show_cover(true);
item.set_child(Some(&child));
}
#[template_callback]
fn on_song_list_bind(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = item.child().and_downcast::<super::Song>().unwrap();
child.bind(
item.position(),
item.item().unwrap().downcast_ref::<crate::playbin::Song>().unwrap(),
);
}
#[template_callback]
fn on_song_list_unbind(&self, item: &gtk::ListItem, _factory: &gtk::SignalListItemFactory) {
let child = item.child().and_downcast::<super::Song>().unwrap();
child.unbind();
}
#[template_callback]
fn on_row_activated(&self, position: u32) {
self.obj().playbin().unwrap().select_track(position);
}
extern "C" {
pub fn audrey_ui_play_queue_get_type() -> glib::ffi::GType;
}
}
use gtk::glib;
glib::wrapper! {
pub struct PlayQueue(ObjectSubclass<imp::PlayQueue>)
pub struct PlayQueue(Object<ffi::AudreyUiPlayQueue, ffi::AudreyUiPlayQueueClass>)
@extends adw::Bin, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
match fn {
type_ => || ffi::audrey_ui_play_queue_get_type(),
}
}

63
src/ui/play_queue.vala Normal file
View file

@ -0,0 +1,63 @@
/*
[GtkTemplate (ui = "/eu/callcc/audrey/play_queue.ui")]
public class Audrey.Ui.PlayQueue : Adw.Bin {
private weak Playbin _playbin;
public Playbin playbin {
get { return _playbin; }
set {
assert (_playbin == null); // only set once
_playbin = value;
_playbin.play_queue.items_changed.connect (this.on_store_items_changed);
this.can_clear_all = _playbin.play_queue.get_n_items () > 0;
}
}
public bool can_clear_all { get; private set; }
/*[GtkCallback] private void on_clear () {
this.playbin.clear ();
}*/
private void on_store_items_changed (GLib.ListModel store, uint position, uint removed, uint added) {
this.can_clear_all = store.get_n_items () > 0;
}
[GtkCallback] private void on_song_list_setup (Gtk.SignalListItemFactory factory, Object object) {
var item = object as Gtk.ListItem;
var child = new PlayQueueSong (this.playbin);
child.draggable = true;
child.show_position = true;
child.show_artist = true;
child.show_cover = true;
item.child = child;
}
[GtkCallback] private void on_song_list_bind (Gtk.SignalListItemFactory factory, Object object) {
var item = object as Gtk.ListItem;
var child = item.child as PlayQueueSong;
child.bind (item.position, item.item as PlaybinSong);
}
[GtkCallback] private void on_song_list_unbind (Gtk.SignalListItemFactory factory, Object object) {
var item = object as Gtk.ListItem;
var child = item.child as PlayQueueSong;
child.unbind ();
}
[GtkCallback] private void on_row_activated (uint position) {
playbin.select_track (position);
}
[GtkCallback] private string visible_child_name (uint n_items) {
return n_items > 0 ? "not-empty" : "empty";
}
~PlayQueue () {
debug ("destroying play queue widget");
}
}

View file

@ -1,7 +1,7 @@
mod imp {
use glib::{subclass::InitializingObject, WeakRef};
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*};
use std::cell::{Cell, RefCell};
use std::cell::{RefCell, Cell};
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
#[template(resource = "/eu/callcc/audrey/play_queue_song.ui")]
@ -208,3 +208,79 @@ impl Song {
.disconnect(self.imp().connection.take().unwrap());
}
}
pub mod ffi {
use adw::prelude::*;
use glib::ffi::{gboolean, GType};
use glib::subclass::basic::InstanceStruct;
use glib::translate::{from_glib, from_glib_none, IntoGlib, IntoGlibPtr};
use gtk::glib;
use std::ffi::c_uint;
type AudreyUiPlayQueueSong = InstanceStruct<super::imp::Song>;
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_get_type() -> GType {
super::Song::static_type().into_glib()
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_new(
playbin: *mut crate::playbin::ffi::AudreyPlaybin,
) -> *mut AudreyUiPlayQueueSong {
unsafe { super::Song::new(&from_glib_none(playbin)).into_glib_ptr() }
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_set_draggable(
self_: *mut AudreyUiPlayQueueSong,
draggable: gboolean,
) {
let self_: super::Song = unsafe { from_glib_none(self_) };
self_.set_draggable(unsafe { from_glib::<_, bool>(draggable) });
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_set_show_position(
self_: *mut AudreyUiPlayQueueSong,
show_position: gboolean,
) {
let self_: super::Song = unsafe { from_glib_none(self_) };
self_.set_show_position(unsafe { from_glib::<_, bool>(show_position) });
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_set_show_artist(
self_: *mut AudreyUiPlayQueueSong,
show_artist: gboolean,
) {
let self_: super::Song = unsafe { from_glib_none(self_) };
self_.set_show_artist(unsafe { from_glib::<_, bool>(show_artist) });
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_set_show_cover(
self_: *mut AudreyUiPlayQueueSong,
show_cover: gboolean,
) {
let self_: super::Song = unsafe { from_glib_none(self_) };
self_.set_show_cover(unsafe { from_glib::<_, bool>(show_cover) });
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_bind(
self_: *mut AudreyUiPlayQueueSong,
position: c_uint,
song: *mut crate::playbin::song::ffi::AudreyPlaybinSong,
) {
let self_: super::Song = unsafe { from_glib_none(self_) };
let song: crate::playbin::Song = unsafe { from_glib_none(song) };
self_.bind(position, &song);
}
#[no_mangle]
extern "C" fn audrey_ui_play_queue_song_unbind(self_: *mut AudreyUiPlayQueueSong) {
let self_: super::Song = unsafe { from_glib_none(self_) };
self_.unbind();
}
}