From dd7c1b89e43c16c6ba7df6b5d9e0b03e7340ebee Mon Sep 17 00:00:00 2001 From: Schmiddiii Date: Wed, 28 Sep 2022 11:30:45 +0200 Subject: [PATCH] :zap: Bulk Piped feed loading --- .gitignore | 1 + Cargo.lock | 24 +++++----- Cargo.toml | 10 ++--- data/resources/ui/about.ui | 16 ------- src/csv_file_manager.rs | 1 + .../subscription/subscription_item_object.rs | 45 ++++--------------- src/gui/subscription/subscription_list.rs | 22 +++++++-- 7 files changed, 46 insertions(+), 73 deletions(-) delete mode 100644 data/resources/ui/about.ui diff --git a/.gitignore b/.gitignore index ebe535c..cfa6fed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target *~* src/config.rs +data/resources/ui/about.ui diff --git a/Cargo.lock b/Cargo.lock index da3df22..bacbef8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1496,9 +1496,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piped" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c29ef6b3e30e1a0615ee5edd2bfc50c463bd8006eb32a04f80b5f701453bb005" +checksum = "21e709be7af7873661b3fa335f5a1b41173771337d724f0ae1644cea759f9473" dependencies = [ "reqwest", "serde", @@ -1965,9 +1965,9 @@ dependencies = [ [[package]] name = "tf_core" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb1a1d0484257ccf48c9065fdcba72cd0e5bc1e5c658caa868c29e50bb320b" +checksum = "4657045cd6ba9e81321902c01f66cd28eeabfa3582edf4e8dd49acac059a8cf4" dependencies = [ "async-trait", "chrono", @@ -1990,9 +1990,9 @@ dependencies = [ [[package]] name = "tf_join" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1be9691db0445e486c16e56ada217e3527c9a41cb1401de83bac6d9c79892a9" +checksum = "470c28b78ab49e4461fa1322766e916731fa2996441a4c9fb12b234714b4ae02" dependencies = [ "async-trait", "chrono", @@ -2016,9 +2016,9 @@ checksum = "d4b6ad18484d102602e33fe5c8c032d593740a3d3984f621bb891b40a5e2a2b7" [[package]] name = "tf_platform_lbry" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5226d37b88cd09f0179867daac27d3f127fb1cb9aa5852d6f3e0654f963f933e" +checksum = "f178faf946151fab4f1f325b4571534c1f8657eeac9da4757a30804762d0aba7" dependencies = [ "async-trait", "chrono", @@ -2029,9 +2029,9 @@ dependencies = [ [[package]] name = "tf_platform_peertube" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b766ca9e18fa3626d7ee5b2d08c9bf041ee73eef8f7a568cbd2acffe9a21000" +checksum = "6f82d57d2c174177effb9b71ba6487e5109baa2ce7e9e0edf8d67afd3c743624" dependencies = [ "async-trait", "chrono", @@ -2042,9 +2042,9 @@ dependencies = [ [[package]] name = "tf_platform_youtube" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e38da0106301825d8e18e4ce647494cba5258ab8996891ee82e882fa548fc2aa" +checksum = "28d9520d0edb9a4da26fddbf154e5d8ded532bd390540de1ee6021679607b60f" dependencies = [ "async-trait", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 99049d3..83c0b1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,11 +33,11 @@ gettext-rs = "0.7.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tf_core = "0.1.2" -tf_join = "0.1.4" +tf_core = "0.1.3" +tf_join = "0.1.5" tf_filter = "0.1.2" tf_observer = "0.1.2" tf_playlist = "0.1.3" -tf_yt = { package = "tf_platform_youtube", version = "0.1.4" } -tf_pt = { package = "tf_platform_peertube", version = "0.1.1" } -tf_lbry = { package = "tf_platform_lbry", version = "0.1.1" } +tf_yt = { package = "tf_platform_youtube", version = "0.1.5" } +tf_pt = { package = "tf_platform_peertube", version = "0.1.2" } +tf_lbry = { package = "tf_platform_lbry", version = "0.1.2" } diff --git a/data/resources/ui/about.ui b/data/resources/ui/about.ui deleted file mode 100644 index 5a38d4f..0000000 --- a/data/resources/ui/about.ui +++ /dev/null @@ -1,16 +0,0 @@ - - - - icon - Tubefeeder - A Youtube, Lbry and Peertube client made for the Pinephone - © 2022 Julian Schmidhuber - Julian Schmidhuber - https://github.com/Tubefeeder/Tubefeeder/issues - GTK_LICENSE_GPL_3_0 - https://matrix.to/#/%23tubefeeder:matrix.org - translators - https://tubefeeder.de - 1.9.1-a3641b8 - - diff --git a/src/csv_file_manager.rs b/src/csv_file_manager.rs index 1466dab..8d8135e 100644 --- a/src/csv_file_manager.rs +++ b/src/csv_file_manager.rs @@ -111,6 +111,7 @@ impl TryFrom for CsvEvent { match e { SubscriptionEvent::Add(i) => Ok(CsvEvent::Add(i)), SubscriptionEvent::Remove(i) => Ok(CsvEvent::Remove(i)), + SubscriptionEvent::Update(i) => Ok(CsvEvent::Add(i)), } } } diff --git a/src/gui/subscription/subscription_item_object.rs b/src/gui/subscription/subscription_item_object.rs index 73df04f..9da64e0 100644 --- a/src/gui/subscription/subscription_item_object.rs +++ b/src/gui/subscription/subscription_item_object.rs @@ -22,6 +22,8 @@ use std::cell::RefCell; use gdk::glib::Object; use gdk::subclass::prelude::ObjectSubclassIsExt; +use gdk_pixbuf::prelude::ObjectExt; +use tf_core::Subscription; use tf_join::AnySubscription; macro_rules! str_prop { @@ -73,13 +75,16 @@ impl SubscriptionObject { ]) .expect("Failed to create `SubscriptionObject`."); s.imp().subscription.swap(&RefCell::new(Some(subscription))); - s.imp().setup_name(&s); s } pub fn subscription(&self) -> Option { self.imp().subscription.borrow().clone() } + + pub fn update_name(&self, sub: &AnySubscription) { + self.set_property("name", sub.name()); + } } mod imp { @@ -88,10 +93,8 @@ mod imp { use tf_join::AnySubscription; use gdk::{ - glib::{ - clone, MainContext, ParamFlags, ParamSpec, ParamSpecString, Value, PRIORITY_DEFAULT, - }, - prelude::{Continue, ObjectExt, ToValue}, + glib::{ParamFlags, ParamSpec, ParamSpecString, Value}, + prelude::ToValue, subclass::prelude::{ObjectImpl, ObjectSubclass}, }; use once_cell::sync::Lazy; @@ -104,38 +107,6 @@ mod imp { pub(super) subscription: RefCell>, } - impl SubscriptionObject { - pub(super) fn setup_name(&self, obj: &super::SubscriptionObject) { - let sub_clone = self - .subscription - .borrow() - .clone() - .expect("Subscription for the item should be set up"); - - let (sender, receiver) = MainContext::channel(PRIORITY_DEFAULT); - - tokio::spawn(async move { - let client = reqwest::Client::new(); - let name = match &sub_clone { - AnySubscription::Youtube(sub) => sub.update_name(&client).await, - AnySubscription::Peertube(sub) => sub.update_name(&client).await, - AnySubscription::Lbry(sub) => sub.update_name(&client).await, - }; - if name.is_some() { - let _ = sender.send(name); - } - }); - - receiver.attach( - None, - clone!(@strong obj => move |name| { - obj.set_property("name", name.to_value()); - Continue(true) - }), - ); - } - } - #[glib::object_subclass] impl ObjectSubclass for SubscriptionObject { const NAME: &'static str = "TFSubscriptionObject"; diff --git a/src/gui/subscription/subscription_list.rs b/src/gui/subscription/subscription_list.rs index 7a65967..5a1d213 100644 --- a/src/gui/subscription/subscription_list.rs +++ b/src/gui/subscription/subscription_list.rs @@ -23,7 +23,7 @@ use gdk::{ subclass::prelude::ObjectSubclassIsExt, }; use gtk::{traits::SorterExt, SorterChange}; -use tf_join::AnySubscriptionList; +use tf_join::{AnySubscription, AnySubscriptionList}; use super::subscription_item_object::SubscriptionObject; @@ -70,6 +70,21 @@ impl SubscriptionList { } } + pub fn update(&self, sub: AnySubscription) { + let imp = self.imp(); + let model = imp.model.borrow(); + + model + .snapshot() + .into_iter() + .map(|i| { + i.downcast::() + .expect("Items should be of type SubscriptionObject") + }) + .filter(|i| i.subscription().as_ref() == Some(&sub)) + .for_each(|i| i.update_name(&sub)) + } + pub fn set_subscription_list(&self, subscription_list: AnySubscriptionList) { self.imp() .any_subscription_list @@ -160,6 +175,9 @@ pub mod imp { let subscription = SubscriptionObject::new(s); obj.remove(subscription); } + SubscriptionEvent::Update(s) => { + obj.update(s); + } } Continue(true) }), @@ -186,7 +204,6 @@ pub mod imp { .unwrap_or_else(|| "".to_string()) .to_lowercase(); - log::trace!("Re-sorting"); name_1.cmp(&name_2).into() }); @@ -223,7 +240,6 @@ pub mod imp { let item: Option = s.property("subscription"); if let Some(item) = item { item.connect_notify_local(Some("name"), clone!(@strong sorter => move |_, _| { - log::trace!("Got a name change"); sorter.changed(SorterChange::Different); })); }