Skip to content

Commit

Permalink
Update dependencies & adapt code to newer gtk-rs version
Browse files Browse the repository at this point in the history
  • Loading branch information
d-k-bo committed Oct 13, 2024
1 parent b0ea99a commit 42fea4e
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 362 deletions.
483 changes: 239 additions & 244 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ edition = "2021"
publish = false

[dependencies]
adw = { package = "libadwaita", version = "0.6.0", features = ["v1_5"] }
adw = { package = "libadwaita", version = "0.7.0", features = ["v1_5"] }
eyre = "0.6.12"
futures-util = "0.3.30"
futures-util = "0.3.31"
gettext-rs = { version = "0.7", features = ["gettext-system"] }
gsettings-macro = "0.2.0"
gtk = { version = "0.8.2", package = "gtk4", features = ["gnome_46", "blueprint"] }
gvdb-macros = "0.1.12"
gsettings-macro = "0.2.1"
gtk = { version = "0.9.2", package = "gtk4", features = ["gnome_46", "blueprint"] }
gvdb-macros = "0.1.13"
html2pango = "0.6.0"
indexmap = { version = "2.2.6", features = ["serde"] }
mediathekviewweb = { version = "0.3.1" }
once_cell = "1.19.0"
indexmap = { version = "2.6.0", features = ["serde"] }
mediathekviewweb = { version = "0.4.0" }
once_cell = "1.20.2"
phf = { version = "0.11.2", features = ["macros"] }
reqwest = { version = "0.12.5", features = ["json"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
reqwest = { version = "0.12.8", features = ["json"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
smart-default = "0.7.1"
time = { version = "0.3.36", features = ["parsing", "serde"] }
tokio = { version = "1.38.0", features = ["time", "rt-multi-thread", "macros"] }
tokio = { version = "1.40.0", features = ["time", "rt-multi-thread", "macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
zbus = { version = "4.3.0", default-features = false, features = ["tokio"] }
zbus = { version = "4.4.0", default-features = false, features = ["tokio"] }
6 changes: 4 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ impl TvApplication {
.activate(move |app: &Self, _, _| app.show_about())
.build();
let preferences_action = gio::ActionEntry::builder("preferences")
.activate(move |app: &Self, _, _| TvPreferencesDialog::new().present(&app.window()))
.activate(move |app: &Self, _, _| {
TvPreferencesDialog::new().present(Some(&app.window()))
})
.build();
let play_action = gio::ActionEntry::builder("play")
.parameter_type(Some(glib::VariantTy::STRING))
Expand Down Expand Up @@ -280,6 +282,6 @@ impl TvApplication {
.license_type(gtk::License::Gpl30)
.build();

about.present(&self.window());
about.present(Some(&self.window()));
}
}
10 changes: 6 additions & 4 deletions src/channel_icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ pub fn load_channel_icon(channel_id: Option<&str>, image: &gtk::Image, size: i32

set_icon(&style_manager, image, icon_name, size);

style_manager.connect_dark_notify(glib::clone!(@weak image => move |style_manager| {
set_icon(style_manager, &image, icon_name, size)
}));
style_manager.connect_dark_notify(glib::clone!(
#[weak]
image,
move |style_manager| set_icon(style_manager, &image, icon_name, size)
));

fn set_icon(style_manager: &adw::StyleManager, image: &gtk::Image, icon_name: &str, size: i32) {
match load_icon(
icon_name,
size,
ColorScheme::for_style_manager(style_manager),
) {
Ok(texture) => image.set_from_paintable(Some(&texture)),
Ok(texture) => image.set_paintable(Some(&texture)),
Err(e) => {
error!("{e:?}");
image.set_icon_name(Some("image-missing-symbolic"));
Expand Down
16 changes: 10 additions & 6 deletions src/launcher/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,15 @@ mod imp {
btn.connect_activate({
let id = program.id.clone();

glib::clone!(@weak self as slf => move |_| {
spawn_clone!(slf, id => async {
slf.set_program(id).await
})
})
glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| {
spawn_clone!(slf, id => async {
slf.set_program(id).await
})
}
)
});

let row = adw::ActionRow::builder()
Expand Down Expand Up @@ -283,7 +287,7 @@ impl ProgramSelector {
.set(program_type)
.expect("already initialized");
slf.imp().load().await;
slf.present(&parent);
slf.present(Some(&parent));

ProgramSelectFuture(slf.imp().future_data.clone()).await
}
Expand Down
10 changes: 7 additions & 3 deletions src/live/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ mod imp {
let slf = self.to_owned();
spawn(async move { slf.reload().await });

settings.connect_live_channels_changed(glib::clone!(@weak self as slf => move |_| {
spawn(async move { slf.reload().await });
}));
settings.connect_live_channels_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| {
spawn(async move { slf.reload().await });
}
));
}
}
impl WidgetImpl for TvLiveView {}
Expand Down
126 changes: 75 additions & 51 deletions src/mediathek/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,42 @@ impl TvMediathekCard {
macro_rules! video_url_action {
( $name:literal, $method:ident, $quality:expr) => {{
let action = gio::SimpleAction::new($name, None);
action.connect_activate(
glib::clone!(@weak self as slf => move |_,_| slf.$method($quality)),
);
self.connect_show_notify(glib::clone!(@weak action => move |slf| {
action.set_enabled(
slf.show()
.and_then(|show| show.video_url($quality))
.is_some()
action.connect_activate(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_, _| slf.$method($quality)
));
self.connect_show_notify(glib::clone!(
#[weak]
action,
move |slf| {
action.set_enabled(
slf.show()
.and_then(|show| show.video_url($quality))
.is_some(),
);
}));
}
));
actions.add_action(&action);
action
}};
}

let play_default =
video_url_action!("play-default", play, VideoQuality::default_playback());
TvSettings::get().connect_default_playback_quality_changed(
glib::clone!(@weak self as slf, @weak play_default => move |_| {
TvSettings::get().connect_default_playback_quality_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
#[weak]
play_default,
move |_| {
play_default.set_enabled(
slf.show()
.and_then(|show| show.video_url(VideoQuality::default_playback()))
.is_some()
);
}),
);
.is_some(),
);
}
));
video_url_action!("play-high", play, VideoQuality::High);
video_url_action!("play-medium", play, VideoQuality::Medium);
video_url_action!("play-low", play, VideoQuality::Low);
Expand All @@ -174,49 +184,63 @@ impl TvMediathekCard {
video_url_action!("copy-url-low", copy_video_url, VideoQuality::Low);

let copy_subtitles_url = gio::SimpleAction::new("copy-subtitles-url", None);
copy_subtitles_url.connect_activate(
glib::clone!(@weak self as slf => move |_,_| slf.copy_subtitles_url()),
);
self.connect_show_notify(glib::clone!(@weak copy_subtitles_url => move |slf| {
copy_subtitles_url.set_enabled(
slf.show()
.and_then(|show| show.subtitle_url())
.is_some()
);
}));
copy_subtitles_url.connect_activate(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_, _| slf.copy_subtitles_url()
));
self.connect_show_notify(glib::clone!(
#[weak]
copy_subtitles_url,
move |slf| {
copy_subtitles_url
.set_enabled(slf.show().and_then(|show| show.subtitle_url()).is_some());
}
));
actions.add_action(&copy_subtitles_url);

let download = gio::SimpleAction::new("download", None);
download.connect_activate(glib::clone!(@weak self as slf => move |_,_| slf.download()));
self.connect_show_notify(glib::clone!(@weak download => move |slf| {
download.set_enabled(
slf.show()
.and_then(|show| show.website_url())
.is_some()
);
}));
download.connect_activate(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_, _| slf.download()
));
self.connect_show_notify(glib::clone!(
#[weak]
download,
move |slf| {
download.set_enabled(slf.show().and_then(|show| show.website_url()).is_some());
}
));
actions.add_action(&download);

let open_website = gio::SimpleAction::new("open-website", None);
open_website.connect_activate(glib::clone!(@weak self as slf => move |_,_| spawn(async move {
let url = slf
.show()
.and_then(|show| show.website_url())
.expect("action must only be enabled if url is not None");
if let Err(e) = gtk::UriLauncher::new(&url).launch_future(slf.root().and_downcast_ref::<adw::Window>()).await {
show_error(
eyre::Report::msg(e.to_string())
.wrap_err(gettext("Failed to open website in browser"))
);
}
})));
self.connect_show_notify(glib::clone!(@weak open_website => move |slf| {
open_website.set_enabled(
slf.show()
open_website.connect_activate(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_, _| spawn(async move {
let url = slf
.show()
.and_then(|show| show.website_url())
.is_some()
);
}));
.expect("action must only be enabled if url is not None");
if let Err(e) = gtk::UriLauncher::new(&url)
.launch_future(slf.root().and_downcast_ref::<adw::Window>())
.await
{
show_error(
eyre::Report::msg(e.to_string())
.wrap_err(gettext("Failed to open website in browser")),
);
}
})
));
self.connect_show_notify(glib::clone!(
#[weak]
open_website,
move |slf| {
open_website.set_enabled(slf.show().and_then(|show| show.website_url()).is_some());
}
));
actions.add_action(&open_website);

self.insert_action_group("card", Some(&actions));
Expand Down
2 changes: 1 addition & 1 deletion src/mediathek/shows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod imp {
#[property(
name = "duration",
type = String,
get = |show: &ShowObject| format_duration(&show.inner.get().unwrap().duration),
get = |show: &ShowObject| show.inner.get().unwrap().duration.as_ref().map(format_duration).unwrap_or_default(),
)]
#[property(
name = "video-url-high",
Expand Down
21 changes: 13 additions & 8 deletions src/mediathek/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,29 @@ mod imp {
spawn_clone!(slf => slf.load())
}

self.search_entry.connect_search_changed(
glib::clone!(@weak slf => move |_| spawn(async move { slf.load().await })),
);
self.search_entry.connect_search_changed(glib::clone!(
#[weak]
slf,
move |_| spawn(async move { slf.load().await })
));
slf.connect_search_everywhere_notify(load);
slf.connect_include_future_notify(load);
slf.connect_sort_by_notify(load);
slf.connect_sort_order_notify(load);

self.shows_model().connect_items_changed(
glib::clone!(@weak self as slf => move |results, _, _, _| {
self.shows_model().connect_items_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |results, _, _, _| {
if results.n_items() == 0 {
slf.stack.set_visible_child(&*slf.nothing_found_view);
} else {
slf.stack.set_visible_child(&*slf.results_view);
}
slf.obj().set_more_available((results.n_items() as u64) < slf.total_results.get());
}),
);
slf.obj()
.set_more_available((results.n_items() as u64) < slf.total_results.get());
}
));

slf.connect_map(|slf| {
slf.imp().search_entry.grab_focus();
Expand Down
35 changes: 23 additions & 12 deletions src/preferences/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,31 @@ mod imp {
self.parent_constructed();

self.update_video_player_display_name();
self.settings.connect_video_player_name_changed(
glib::clone!(@weak self as slf => move |_| slf.update_video_player_display_name()),
);
self.settings.connect_video_player_id_changed(
glib::clone!(@weak self as slf => move |_| slf.update_video_player_display_name()),
);
self.settings
.connect_video_player_name_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| slf.update_video_player_display_name()
));
self.settings.connect_video_player_id_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| slf.update_video_player_display_name()
));

self.update_video_downloader_display_name();
self.settings.connect_video_downloader_name_changed(
glib::clone!(@weak self as slf => move |_| slf.update_video_downloader_display_name()),
);
self.settings.connect_video_downloader_id_changed(
glib::clone!(@weak self as slf => move |_| slf.update_video_downloader_display_name()),
);
self.settings
.connect_video_downloader_name_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| slf.update_video_downloader_display_name()
));
self.settings
.connect_video_downloader_id_changed(glib::clone!(
#[weak(rename_to = slf)]
self,
move |_| slf.update_video_downloader_display_name()
));
}
}
impl WidgetImpl for TvPreferencesDialog {}
Expand Down
Loading

0 comments on commit 42fea4e

Please sign in to comment.