Skip to content

Commit

Permalink
update deprecated clone! calls
Browse files Browse the repository at this point in the history
  • Loading branch information
xou816 committed Nov 29, 2024
1 parent 1708e56 commit 9b443ac
Show file tree
Hide file tree
Showing 41 changed files with 837 additions and 775 deletions.
293 changes: 99 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ edition = "2018"
license = "MIT"

[dependencies.gtk]
version = "^0.8"
version = "^0.9"
package = "gtk4"
features = ["gnome_46", "blueprint"]
features = ["gnome_47", "blueprint"]

[dependencies.libadwaita]
version = "^0.6"
features = ["v1_5"]
version = "^0.7"
features = ["v1_6"]

[dependencies.gdk]
version = "^0.8"
version = "^0.9"
package = "gdk4"

[dependencies.gio]
version = "^0.19"
version = "^0.20"
features = []

[dependencies.glib]
version = "^0.19"
features = ["v2_60"]
version = "^0.20"
features = []

[dependencies.librespot]
version = "0.6.0"
Expand Down Expand Up @@ -61,7 +61,7 @@ version = "3.0.1"
features = ["rt-async-io-crypto-rust"]

[dependencies]
gdk-pixbuf = "^0.19"
gdk-pixbuf = "^0.20"
ref_filter_map = "1.0.1"
regex = "1.8.3"
async-std = "1.12.0"
Expand Down
340 changes: 105 additions & 235 deletions cargo-sources.json

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions src/app/components/album/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl AlbumWidget {

fn set_image(&self, pixbuf: &gdk_pixbuf::Pixbuf) {
let texture = gdk::Texture::for_pixbuf(pixbuf);
self.imp().cover_image.set_from_paintable(Some(&texture));
self.imp().cover_image.set_paintable(Some(&texture));
}

fn bind(&self, album_model: &AlbumModel, worker: Worker) {
Expand Down Expand Up @@ -122,11 +122,9 @@ impl AlbumWidget {
}
}

pub fn connect_album_pressed<F: Fn(&Self) + 'static>(&self, f: F) {
self.imp()
.cover_btn
.connect_clicked(clone!(@weak self as _self => move |_| {
f(&_self);
}));
pub fn connect_album_pressed<F: Fn() + 'static>(&self, f: F) {
self.imp().cover_btn.connect_clicked(move |_| {
f();
});
}
}
10 changes: 4 additions & 6 deletions src/app/components/artist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ impl ArtistWidget {
_self
}

pub fn connect_artist_pressed<F: Fn(&Self) + 'static>(&self, f: F) {
self.imp()
.avatar_btn
.connect_clicked(clone!(@weak self as _self => move |_| {
f(&_self);
}));
pub fn connect_artist_pressed<F: Fn() + 'static>(&self, f: F) {
self.imp().avatar_btn.connect_clicked(move |_| {
f();
});
}

fn bind(&self, model: &ArtistModel, worker: Worker) {
Expand Down
30 changes: 21 additions & 9 deletions src/app/components/artist_details/artist_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ impl ArtistDetailsWidget {
let child = gtk::FlowBoxChild::new();
let album = AlbumWidget::for_model(item, worker.clone());
let f = on_album_pressed.clone();
album.connect_album_pressed(clone!(@weak item => move |_| {
f(item.uri());
}));
album.connect_album_pressed(clone!(
#[weak]
item,
move || {
f(item.uri());
}
));
child.set_child(Some(&album));
child.upcast::<gtk::Widget>()
});
Expand All @@ -115,17 +119,25 @@ impl ArtistDetails {

let widget = ArtistDetailsWidget::new();

widget.connect_bottom_edge(clone!(@weak model => move || {
model.load_more();
}));
widget.connect_bottom_edge(clone!(
#[weak]
model,
move || {
model.load_more();
}
));

if let Some(store) = model.get_list_store() {
widget.bind_artist_releases(
worker.clone(),
&store,
clone!(@weak model => move |id| {
model.open_album(id);
}),
clone!(
#[weak]
model,
move |id| {
model.open_album(id);
}
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/details/album_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl AlbumHeaderWidget {

pub fn set_artwork(&self, pixbuf: &gdk_pixbuf::Pixbuf) {
let texture = gdk::Texture::for_pixbuf(pixbuf);
self.imp().album_art.set_from_paintable(Some(&texture));
self.imp().album_art.set_paintable(Some(&texture));
}

pub fn set_album_and_artist_and_year(&self, album: &str, artist: &str, year: Option<u32>) {
Expand Down
86 changes: 52 additions & 34 deletions src/app/components/details/details.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use libadwaita::prelude::AdwDialogExt;
use std::rc::Rc;

use super::album_header::AlbumHeaderWidget;
use super::release_details::ReleaseDetailsWindow;
use super::release_details::ReleaseDetailsDialog;
use super::DetailsModel;

use crate::app::components::{
Expand Down Expand Up @@ -85,11 +86,15 @@ impl AlbumDetailsWidget {

fn connect_header(&self) {
self.set_header_visible(false);
self.imp().scrolling_header.connect_header_visibility(
clone!(@weak self as _self => move |visible| {
_self.set_header_visible(visible);
}),
);
self.imp()
.scrolling_header
.connect_header_visibility(clone!(
#[weak(rename_to = _self)]
self,
move |visible| {
_self.set_header_visible(visible);
}
));
}

fn connect_bottom_edge<F>(&self, f: F)
Expand Down Expand Up @@ -129,9 +134,13 @@ impl AlbumDetailsWidget {

fn connect_info<F>(&self, f: F)
where
F: Fn() + 'static,
F: Fn(&Self) + 'static,
{
self.imp().header_widget.connect_info(f);
self.imp().header_widget.connect_info(clone!(
#[weak(rename_to = _self)]
self,
move || f(&_self)
));
}

fn set_liked(&self, is_liked: bool) {
Expand Down Expand Up @@ -165,15 +174,12 @@ pub struct Details {
model: Rc<DetailsModel>,
worker: Worker,
widget: AlbumDetailsWidget,
modal: ReleaseDetailsWindow,
modal: ReleaseDetailsDialog,
children: Vec<Box<dyn EventListener>>,
}

impl Details {
pub fn new(
model: Rc<DetailsModel>,
worker: Worker,
) -> Self {
pub fn new(model: Rc<DetailsModel>, worker: Worker) -> Self {
if model.get_album_info().is_none() {
model.load_album_info();
}
Expand All @@ -192,29 +198,39 @@ impl Details {
model.to_headerbar_model(),
));

let modal = ReleaseDetailsWindow::new();
let modal = ReleaseDetailsDialog::new();

widget.connect_liked(clone!(@weak model => move || model.toggle_save_album()));
widget.connect_liked(clone!(
#[weak]
model,
move || model.toggle_save_album()
));

widget.connect_play(clone!(@weak model => move || model.toggle_play_album()));
widget.connect_play(clone!(
#[weak]
model,
move || model.toggle_play_album()
));

widget.connect_header();

widget.connect_bottom_edge(clone!(@weak model => move || {
model.load_more();
}));

widget.connect_info(clone!(@weak modal, @weak widget => move || {
let modal = modal.upcast_ref::<libadwaita::Window>();
modal.set_modal(true);
modal.set_transient_for(
widget
.root()
.and_then(|r| r.downcast::<gtk::Window>().ok())
.as_ref(),
);
modal.set_visible(true);
}));
widget.connect_bottom_edge(clone!(
#[weak]
model,
move || {
model.load_more();
}
));

widget.connect_info(clone!(
#[weak]
modal,
move |w| {
let modal = modal.upcast_ref::<libadwaita::Dialog>();
let parent = w.root().and_then(|r| r.downcast::<gtk::Window>().ok());
modal.present(parent.as_ref());
}
));

Self {
model,
Expand Down Expand Up @@ -254,9 +270,11 @@ impl Details {
album.year(),
);

self.widget.connect_artist_clicked(
clone!(@weak self.model as model => move || model.view_artist()),
);
self.widget.connect_artist_clicked(clone!(
#[weak(rename_to = model)]
self.model,
move || model.view_artist()
));

self.modal.set_details(
&album.title,
Expand Down
5 changes: 1 addition & 4 deletions src/app/components/details/release_details.blp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Gtk 4.0;
using Adw 1;

template $ReleaseDetailsWindow : Adw.Window {
modal: true;
hide-on-close: true;
default-width: 360;
template $ReleaseDetailsDialog : Adw.Dialog {

Box {
orientation: vertical;
Expand Down
28 changes: 11 additions & 17 deletions src/app/components/details/release_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod imp {

#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/dev/alextren/Spot/components/release_details.ui")]
pub struct ReleaseDetailsWindow {
pub struct ReleaseDetailsDialog {
#[template_child]
pub album_artist: TemplateChild<libadwaita::WindowTitle>,

Expand All @@ -28,10 +28,10 @@ mod imp {
}

#[glib::object_subclass]
impl ObjectSubclass for ReleaseDetailsWindow {
const NAME: &'static str = "ReleaseDetailsWindow";
type Type = super::ReleaseDetailsWindow;
type ParentType = libadwaita::Window;
impl ObjectSubclass for ReleaseDetailsDialog {
const NAME: &'static str = "ReleaseDetailsDialog";
type Type = super::ReleaseDetailsDialog;
type ParentType = libadwaita::Dialog;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
Expand All @@ -42,23 +42,17 @@ mod imp {
}
}

impl ObjectImpl for ReleaseDetailsWindow {}
impl WidgetImpl for ReleaseDetailsWindow {}
impl AdwWindowImpl for ReleaseDetailsWindow {}
impl WindowImpl for ReleaseDetailsWindow {}
impl ObjectImpl for ReleaseDetailsDialog {}
impl WidgetImpl for ReleaseDetailsDialog {}
impl AdwDialogImpl for ReleaseDetailsDialog {}
}

glib::wrapper! {
pub struct ReleaseDetailsWindow(ObjectSubclass<imp::ReleaseDetailsWindow>) @extends gtk::Widget, libadwaita::Window;
pub struct
ReleaseDetailsDialog(ObjectSubclass<imp::ReleaseDetailsDialog>) @extends gtk::Widget, libadwaita::Dialog;
}

impl Default for ReleaseDetailsWindow {
fn default() -> Self {
Self::new()
}
}

impl ReleaseDetailsWindow {
impl ReleaseDetailsDialog {
pub fn new() -> Self {
glib::Object::new()
}
Expand Down
20 changes: 14 additions & 6 deletions src/app/components/device_selector/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ impl DeviceSelector {
pub fn new(widget: DeviceSelectorWidget, model: DeviceSelectorModel) -> Self {
let model = Rc::new(model);

widget.connect_refresh(clone!(@weak model => move || {
model.refresh_available_devices();
}));
widget.connect_refresh(clone!(
#[weak]
model,
move || {
model.refresh_available_devices();
}
));

widget.connect_switch_device(clone!(@weak model => move |id| {
model.set_current_device(id);
}));
widget.connect_switch_device(clone!(
#[weak]
model,
move |id| {
model.set_current_device(id);
}
));

Self { widget, model }
}
Expand Down
Loading

0 comments on commit 9b443ac

Please sign in to comment.