From 1f289ecf1e6ad20a308353d142b5b5eeb13e8f84 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 29 Oct 2024 15:46:33 +0100 Subject: [PATCH] gir --- resources/play_queue.blp | 6 ++-- resources/play_queue_song.blp | 14 ++++---- resources/playbar.blp | 26 +++++++------- resources/setup.blp | 2 +- resources/window.blp | 6 ++-- src/meson.build | 1 + src/mpris.vala | 4 +-- src/playbin.rs | 2 ++ src/playbin.vala | 8 ++--- src/playbin/song.rs | 14 ++++++++ src/subsonic.vala | 12 +++---- src/ui/play_queue.rs | 2 ++ src/ui/play_queue.vala | 4 +-- src/ui/play_queue/song.rs | 65 +++++++++++++++++++++++++++++++++++ src/ui/playbar.vala | 2 +- src/ui/setup.vala | 2 +- src/ui/window.rs | 14 ++++---- src/ui/window.vala | 6 ++-- 18 files changed, 137 insertions(+), 53 deletions(-) create mode 100644 src/playbin.rs create mode 100644 src/playbin/song.rs create mode 100644 src/ui/play_queue.rs create mode 100644 src/ui/play_queue/song.rs diff --git a/resources/play_queue.blp b/resources/play_queue.blp index 58eb6fc..62f21e1 100644 --- a/resources/play_queue.blp +++ b/resources/play_queue.blp @@ -1,11 +1,11 @@ using Gtk 4.0; using Adw 1; -template $UiPlayQueue: Adw.Bin { +template $AudreyUiPlayQueue: Adw.Bin { name: "play-queue"; child: Stack { - visible-child-name: bind $visible_child_name (template.playbin as <$Playbin>.play-queue-length) as ; + visible-child-name: bind $visible_child_name (template.playbin as <$AudreyPlaybin>.play-queue-length) as ; StackPage { name: "empty"; @@ -31,7 +31,7 @@ template $UiPlayQueue: Adw.Bin { activate => $on_row_activated (); model: NoSelection { - model: bind template.playbin as <$Playbin>.play_queue; + model: bind template.playbin as <$AudreyPlaybin>.play_queue; }; factory: SignalListItemFactory { diff --git a/resources/play_queue_song.blp b/resources/play_queue_song.blp index d6603d6..7ddb3fe 100644 --- a/resources/play_queue_song.blp +++ b/resources/play_queue_song.blp @@ -1,6 +1,6 @@ using Gtk 4.0; -template $UiPlayQueueSong: Box { +template $AudreyUiPlayQueueSong: Box { height-request: 48; spacing: 12; margin-start: 6; @@ -35,7 +35,7 @@ template $UiPlayQueueSong: Box { margin-top: 1; margin-bottom: 1; pixel-size: 50; - paintable: bind template.song as <$PlaybinSong>.thumbnail; + paintable: bind template.song as <$AudreyPlaybinSong>.thumbnail; } Box title_box { @@ -58,7 +58,7 @@ template $UiPlayQueueSong: Box { max-width-chars: 90; justify: fill; - label: bind template.song as <$PlaybinSong>.title; + label: bind template.song as <$AudreyPlaybinSong>.title; } Label { @@ -71,7 +71,7 @@ template $UiPlayQueueSong: Box { max-width-chars: 90; justify: fill; - label: bind template.song as <$PlaybinSong>.artist; + label: bind template.song as <$AudreyPlaybinSong>.artist; } } } @@ -83,12 +83,12 @@ template $UiPlayQueueSong: Box { single-line-mode: true; styles [ "numeric", "dim-label" ] - label: bind $format_duration (template.song as <$PlaybinSong>.duration) as ; + label: bind $format_duration (template.song as <$AudreyPlaybinSong>.duration) as ; } Button { focusable: true; - // TODO icon-name: bind $star_button_icon_name (template.song as <$PlaybinSong>.starred) as ; + // TODO icon-name: bind $star_button_icon_name (template.song as <$AudreyPlaybinSong>.starred) as ; icon-name: bind $star_button_icon_name () as ; styles [ "flat" ] valign: center; @@ -116,7 +116,7 @@ template $UiPlayQueueSong: Box { DropTarget { actions: move; - formats: "UiPlayQueueSong"; + formats: "AudreyUiPlayQueueSong"; preload: true; drop => $on_drop (); diff --git a/resources/playbar.blp b/resources/playbar.blp index 0a2e10b..890ab67 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -1,7 +1,7 @@ using Gtk 4.0; using Adw 1; -template $UiPlaybar: Adw.Bin { +template $AudreyUiPlaybar: Adw.Bin { child: CenterBox { hexpand: true; styles [ @@ -66,7 +66,7 @@ template $UiPlaybar: Adw.Bin { "numeric", ] - label: bind $format_timestamp (template.playbin as <$Playbin>.position) as ; + label: bind $format_timestamp (template.playbin as <$AudreyPlaybin>.position) as ; } [center] @@ -74,12 +74,12 @@ template $UiPlaybar: Adw.Bin { name: "seek-scale"; orientation: horizontal; width-request: 400; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; adjustment: Adjustment { lower: 0; - value: bind template.playbin as <$Playbin>.position; - upper: bind template.playbin as <$Playbin>.duration; + value: bind template.playbin as <$AudreyPlaybin>.position; + upper: bind template.playbin as <$AudreyPlaybin>.duration; }; change-value => $on_play_position_seek (); @@ -92,7 +92,7 @@ template $UiPlaybar: Adw.Bin { "numeric", ] - label: bind $format_timestamp (template.playbin as <$Playbin>.duration) as ; + label: bind $format_timestamp (template.playbin as <$AudreyPlaybin>.duration) as ; } } @@ -103,7 +103,7 @@ template $UiPlaybar: Adw.Bin { Button { icon-name: "media-skip-backward"; valign: center; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; clicked => $on_skip_backward_clicked (); } @@ -111,15 +111,15 @@ template $UiPlaybar: Adw.Bin { Button { icon-name: "media-seek-backward"; valign: center; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; clicked => $seek_backward (); } Button { - icon-name: bind $play_pause_icon_name (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + icon-name: bind $play_pause_icon_name (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; valign: center; - sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play-queue-length) as ; + sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as ; clicked => $on_play_pause_clicked (); } @@ -127,7 +127,7 @@ template $UiPlaybar: Adw.Bin { Button { icon-name: "media-seek-forward"; valign: center; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; clicked => $seek_forward (); } @@ -135,7 +135,7 @@ template $UiPlaybar: Adw.Bin { Button { icon-name: "media-skip-forward"; valign: center; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; clicked => $on_skip_forward_clicked (); } @@ -150,7 +150,7 @@ template $UiPlaybar: Adw.Bin { } Button { - icon-name: bind $mute_button_icon_name (template.playbin as <$Playbin>.mute) as ; + icon-name: bind $mute_button_icon_name (template.playbin as <$AudreyPlaybin>.mute) as ; valign: center; clicked => $on_mute_toggle (); diff --git a/resources/setup.blp b/resources/setup.blp index c2d2716..5bb1855 100644 --- a/resources/setup.blp +++ b/resources/setup.blp @@ -1,7 +1,7 @@ using Gtk 4.0; using Adw 1; -template $UiSetup: Adw.PreferencesDialog { +template $AudreyUiSetup: Adw.PreferencesDialog { title: _("Setup"); Adw.ToolbarView { diff --git a/resources/window.blp b/resources/window.blp index b5d5408..fe3cb13 100644 --- a/resources/window.blp +++ b/resources/window.blp @@ -1,7 +1,7 @@ using Gtk 4.0; using Adw 1; -template $UiWindow: Adw.ApplicationWindow { +template $AudreyUiWindow: Adw.ApplicationWindow { title: _("audrey"); default-width: 800; default-height: 600; @@ -109,7 +109,7 @@ template $UiWindow: Adw.ApplicationWindow { } } - $UiPlayQueue play_queue { + $AudreyUiPlayQueue play_queue { hexpand: true; halign: fill; @@ -126,7 +126,7 @@ template $UiWindow: Adw.ApplicationWindow { }; [bottom] - $UiPlaybar playbar { + $AudreyUiPlaybar playbar { song: bind template.song; playbin: bind template.playbin; playing_cover_art: bind template.playing_cover_art; diff --git a/src/meson.build b/src/meson.build index a2bfe06..c98f0ab 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,4 +34,5 @@ audrey_c = static_library( '--gresources', meson.project_source_root() / 'resources/audrey.gresource.xml', ], + vala_gir: 'audrey-0.gir', ) diff --git a/src/mpris.vala b/src/mpris.vala index fa7e8b5..3ae6307 100644 --- a/src/mpris.vala +++ b/src/mpris.vala @@ -1,5 +1,5 @@ [DBus (name = "org.mpris.MediaPlayer2")] -class Mpris : Object { +class Audrey.Mpris : Object { internal signal void on_raise (); internal signal void on_quit (); @@ -32,7 +32,7 @@ class Mpris : Object { } [DBus (name = "org.mpris.MediaPlayer2.Player")] -class MprisPlayer : Object { +class Audrey.MprisPlayer : Object { internal signal void on_next (); internal signal void on_previous (); internal signal void on_pause (); diff --git a/src/playbin.rs b/src/playbin.rs new file mode 100644 index 0000000..e3ebdf1 --- /dev/null +++ b/src/playbin.rs @@ -0,0 +1,2 @@ +mod song; +pub use song::Song; diff --git a/src/playbin.vala b/src/playbin.vala index 424f3ab..11630a3 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -1,15 +1,15 @@ -public enum PlaybinState { +public enum Audrey.PlaybinState { STOPPED, PAUSED, PLAYING, } -private struct CommandCallback { +private struct Audrey.CommandCallback { unowned SourceFunc callback; int error; } -public class PlaybinSong : Object { +public class Audrey.PlaybinSong : Object { private Subsonic.Song inner; public string id { get { return inner.id; } } public string title { get { return inner.title; } } @@ -59,7 +59,7 @@ public class PlaybinSong : Object { } } -public class Playbin : GLib.Object { +public class Audrey.Playbin : GLib.Object { private Mpv.Handle mpv = new Mpv.Handle (); private int _volume = 100; private bool _mute = false; diff --git a/src/playbin/song.rs b/src/playbin/song.rs new file mode 100644 index 0000000..9d6ada3 --- /dev/null +++ b/src/playbin/song.rs @@ -0,0 +1,14 @@ +mod imp { + #[derive(gtk::Properties, Default)] + #[properties(wrapper_type = super::Song)] + pub struct Song { + inner: RefCell, + + #[property(get = |song| song.inner.borrow().id)] + id: &'static str, + } +} + +glib::wrapper! { + pub struct Song(ObjectSubclass); +} diff --git a/src/subsonic.vala b/src/subsonic.vala index b9d553c..4f416b1 100644 --- a/src/subsonic.vala +++ b/src/subsonic.vala @@ -1,11 +1,11 @@ -public errordomain Subsonic.Error { +public errordomain Audrey.Subsonic.Error { BAD_AUTHN, ERROR, } -public delegate void Subsonic.SongCallback (Song song); +public delegate void Audrey.Subsonic.SongCallback (Song song); -public class Subsonic.Artist : Object { +public class Audrey.Subsonic.Artist : Object { public string index; public string id; public string name { get; private set; } @@ -38,7 +38,7 @@ public class Subsonic.Artist : Object { } } -public class Subsonic.Album : Object { +public class Audrey.Subsonic.Album : Object { public string id; public string name; @@ -53,7 +53,7 @@ public class Subsonic.Album : Object { } } -public struct Subsonic.Song { +public struct Audrey.Subsonic.Song { public string id; public string title; public string album; @@ -109,7 +109,7 @@ public struct Subsonic.Song { } } -public class Subsonic.Client : Object { +public class Audrey.Subsonic.Client : Object { private Soup.Session session; private string url; private string parameters; diff --git a/src/ui/play_queue.rs b/src/ui/play_queue.rs new file mode 100644 index 0000000..e3ebdf1 --- /dev/null +++ b/src/ui/play_queue.rs @@ -0,0 +1,2 @@ +mod song; +pub use song::Song; diff --git a/src/ui/play_queue.vala b/src/ui/play_queue.vala index 98d02df..132382a 100644 --- a/src/ui/play_queue.vala +++ b/src/ui/play_queue.vala @@ -1,7 +1,7 @@ // song widget+drag behavior taken from gnome music [GtkTemplate (ui = "/eu/callcc/audrey/play_queue_song.ui")] -class Ui.PlayQueueSong : Gtk.Box { +class Audrey.Ui.PlayQueueSong : Gtk.Box { public bool draggable { get; set; default = false; } public bool show_position { get; set; default = false; } public bool show_artist { get; set; default = false; } @@ -112,7 +112,7 @@ class Ui.PlayQueueSong : Gtk.Box { } [GtkTemplate (ui = "/eu/callcc/audrey/play_queue.ui")] -public class Ui.PlayQueue : Adw.Bin { +public class Audrey.Ui.PlayQueue : Adw.Bin { private weak Playbin _playbin; public Playbin playbin { get { return _playbin; } diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs new file mode 100644 index 0000000..e1bd87b --- /dev/null +++ b/src/ui/play_queue/song.rs @@ -0,0 +1,65 @@ +mod imp { + use std::cell::RefCell; + //use crate::playbin; + use gtk::{glib, prelude::*, subclass::prelude::*}; + + #[derive(gtk::CompositeTemplate, glib::Properties, Default)] + #[template(resource = "/eu/callcc/audrey/play_queue_song.ui")] + #[properties(wrapper_type = super::Song)] + pub struct Song { + #[property(get, set, default = false)] + draggable: RefCell, + #[property(get, set, default = false)] + show_position: RefCell, + #[property(get, set, default = false)] + show_artist: RefCell, + #[property(get, set, default = false)] + show_cover: RefCell, + #[property(get, set = Self::set_current, default = false)] + current: RefCell, + #[property(get, set)] + displayed_position: RefCell, + //#[property(get, set)] + //song: playbin::Song, + + //playbin: playbin::Playbin, + connection: RefCell, + drag_x: RefCell, + drag_y: RefCell, + drag_widget: RefCell>, + } + + #[glib::object_subclass] + impl ObjectSubclass for Song { + const NAME: &'static str = "AudreyUiPlayQueueSong"; + type Type = super::Song; + type ParentType = gtk::Box; + } + + #[glib::derived_properties] + impl ObjectImpl for Song {} + + impl WidgetImpl for Song {} + + impl BoxImpl for Song {} + + #[gtk::template_callbacks] + impl Song { + fn set_current(&self, value: bool) { + *self.current.borrow_mut() = value; + if value { + self.obj().add_css_class("playing"); + } else { + self.obj().remove_css_class("playing"); + } + } + } +} + +use gtk::glib; + +glib::wrapper! { + pub struct Song(ObjectSubclass) + @extends gtk::Box, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; +} diff --git a/src/ui/playbar.vala b/src/ui/playbar.vala index 62ac634..eedfbaa 100644 --- a/src/ui/playbar.vala +++ b/src/ui/playbar.vala @@ -1,5 +1,5 @@ [GtkTemplate (ui = "/eu/callcc/audrey/playbar.ui")] -class Ui.Playbar : Adw.Bin { +class Audrey.Ui.Playbar : Adw.Bin { public PlaybinSong? song { get; set; } public Gdk.Paintable? playing_cover_art { get; set; } public weak Playbin playbin { get; set; } diff --git a/src/ui/setup.vala b/src/ui/setup.vala index e38b1d7..9a0f776 100644 --- a/src/ui/setup.vala +++ b/src/ui/setup.vala @@ -17,7 +17,7 @@ static void salt_password (string password, out string token, out string salt) { } [GtkTemplate (ui = "/eu/callcc/audrey/setup.ui")] -public class Ui.Setup : Adw.PreferencesDialog { +public class Audrey.Ui.Setup : Adw.PreferencesDialog { public string status { get; private set; default = _("Not connected"); } public bool authn_can_edit { get; private set; default = true; } diff --git a/src/ui/window.rs b/src/ui/window.rs index 12eb3d5..337e2b9 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -2,18 +2,18 @@ mod ffi { use gtk::glib; #[repr(C)] - pub struct UiWindow { + pub struct AudreyUiWindow { parent_instance: adw::ffi::AdwApplicationWindow, } #[repr(C)] - pub struct UiWindowClass { + pub struct AudreyUiWindowClass { parent_class: adw::ffi::AdwApplicationWindowClass, } extern "C" { - pub fn ui_window_get_type() -> glib::ffi::GType; - pub fn ui_window_new(app: *mut gtk::ffi::GtkApplication) -> *mut UiWindow; + pub fn audrey_ui_window_get_type() -> glib::ffi::GType; + pub fn audrey_ui_window_new(app: *mut gtk::ffi::GtkApplication) -> *mut AudreyUiWindow; } } @@ -21,12 +21,12 @@ use adw::prelude::*; use gtk::{gio, glib}; glib::wrapper! { - pub struct Window(Object) + pub struct Window(Object) @extends adw::ApplicationWindow, gtk::ApplicationWindow, gtk::Window, gtk::Widget, @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager; match fn { - type_ => || ffi::ui_window_get_type(), + type_ => || ffi::audrey_ui_window_get_type(), } } @@ -34,6 +34,6 @@ impl Window { pub fn new(app: &impl IsA) -> Self { use glib::translate::*; - unsafe { from_glib_none(ffi::ui_window_new(app.as_ref().to_glib_none().0)) } + unsafe { from_glib_none(ffi::audrey_ui_window_new(app.as_ref().to_glib_none().0)) } } } diff --git a/src/ui/window.vala b/src/ui/window.vala index df40afc..d500442 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -1,7 +1,7 @@ [GtkTemplate (ui = "/eu/callcc/audrey/window.ui")] -class Ui.Window : Adw.ApplicationWindow { - [GtkChild] public unowned Ui.PlayQueue play_queue; - [GtkChild] public unowned Ui.Playbar playbar; +class Audrey.Ui.Window : Adw.ApplicationWindow { + [GtkChild] public unowned PlayQueue play_queue; + [GtkChild] public unowned Playbar playbar; //[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks; private Setup setup;