Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Add a subscribe button to empty feed #121

Merged
merged 7 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion data/resources/ui/feed_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,21 @@
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">No Videos Found</property>
<property name="description" translatable="yes">Are you subscribed to channels?</property>
<property name="icon-name">go-home-symbolic</property>
<property name="vexpand">True</property>

<property name="child">
<object class="GtkButton" id="btn_add_subscription">
<style>
<class name="pill"/>
Schmiddiii marked this conversation as resolved.
Show resolved Hide resolved
<class name="suggested-action"/>
</style>

<property name="halign">center</property>
<property name="label" translatable="yes">Subscribe to a Channel…</property>
</object>
</property>

<binding name="visible">
<lookup name="is-empty">
feed_list
Expand Down
13 changes: 12 additions & 1 deletion data/resources/ui/filter_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">No Filters</property>
<property name="description" translatable="yes">How about adding some filters?</property>
<property name="icon-name">funnel-symbolic</property>
<property name="vexpand">True</property>
<binding name="visible">
<lookup name="is-empty">
filter_list
</lookup>
</binding>

<property name="child">
<object class="GtkButton" id="btn_add_filter">
<style>
<class name="pill"/>
<class name="suggested-action"/>
</style>

<property name="halign">center</property>
<property name="label" translatable="yes">Add Filter…</property>
</object>
</property>
</object>
</child>
</object>
Expand Down
13 changes: 12 additions & 1 deletion data/resources/ui/subscription_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,25 @@
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">No Subscriptions</property>
<property name="description" translatable="yes">How about subscribing to some channels?</property>
<property name="icon-name">library-artists-symbolic</property>
<property name="vexpand">True</property>
<binding name="visible">
<lookup name="is-empty">
subscription_list
</lookup>
</binding>

<property name="child">
<object class="GtkButton" id="btn_add_subscription">
<style>
<class name="pill"/>
<class name="suggested-action"/>
</style>

<property name="halign">center</property>
<property name="label" translatable="yes">Subscribe to a Channel…</property>
</object>
</property>
</object>
</child>
</object>
Expand Down
33 changes: 33 additions & 0 deletions src/gui/feed/feed_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ impl FeedPage {
self.imp().joiner.replace(Some(joiner));
self.imp().setup(&self);
}

pub fn reload(&self) {
self.imp().reload();
}
}

pub mod imp {
Expand All @@ -47,6 +51,7 @@ pub mod imp {
use gdk::glib::ParamSpec;
use gdk::glib::ParamSpecBoolean;
use gdk::glib::PRIORITY_DEFAULT;
use gdk_pixbuf::glib::subclass::Signal;
use glib::subclass::InitializingObject;
use gtk::glib;
use gtk::prelude::*;
Expand All @@ -73,6 +78,8 @@ pub mod imp {

#[template_child]
pub(super) btn_reload: TemplateChild<gtk::Button>,
#[template_child]
pub(super) btn_add_subscription: TemplateChild<gtk::Button>,

#[template_child]
pub(super) error_label: TemplateChild<ErrorLabel>,
Expand All @@ -85,6 +92,10 @@ pub mod imp {
}

impl FeedPage {
pub(super) fn reload(&self) {
self.btn_reload.emit_clicked();
}

fn setup_reload(&self, obj: &super::FeedPage) {
let joiner = self
.joiner
Expand Down Expand Up @@ -132,6 +143,13 @@ pub mod imp {
self.joiner.replace(Some(joiner));
}

fn setup_add_subscription(&self, obj: &super::FeedPage) {
self.btn_add_subscription
.connect_clicked(clone!(@weak obj => move |_| {
obj.emit_by_name::<()>("add-subscription", &[]);
}));
}

pub(super) fn setup(&self, obj: &super::FeedPage) {
self.feed_list.set_playlist_manager(
self.playlist_manager
Expand All @@ -140,6 +158,7 @@ pub mod imp {
.expect("PlaylistManager has to be set up"),
);
self.setup_reload(obj);
self.setup_add_subscription(obj);
}
}

Expand Down Expand Up @@ -202,6 +221,20 @@ pub mod imp {
_ => unimplemented!(),
}
}

fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
vec![Signal::builder(
"add-subscription",
// Types of the values which will be sent to the signal handler
&[],
// Type of the value the signal handler sends back
<()>::static_type().into(),
)
.build()]
});
SIGNALS.as_ref()
}
}

impl WidgetImpl for FeedPage {}
Expand Down
33 changes: 21 additions & 12 deletions src/gui/filter/filter_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub mod imp {
#[template_child]
pub(super) btn_toggle_add_filter: TemplateChild<gtk::Button>,
#[template_child]
pub(super) btn_add_filter: TemplateChild<gtk::Button>,
#[template_child]
pub(super) entry_title: TemplateChild<gtk::Entry>,
#[template_child]
pub(super) entry_channel: TemplateChild<gtk::Entry>,
Expand All @@ -88,19 +90,26 @@ pub mod imp {

#[gtk::template_callbacks]
impl FilterPage {
fn present_filter(&self) {
self.entry_channel.set_text("");
self.entry_title.set_text("");

// Theoretically only needs to be done once, but when setting up the page does
// not yet have a root.
let window = self.instance().window();
self.dialog_add.set_transient_for(Some(&window));
self.dialog_add.present();
}

fn setup_toggle_add_filter(&self, obj: &super::FilterPage) {
self.btn_toggle_add_filter.connect_clicked(
clone!(@strong obj as s, @strong self.dialog_add as dialog, @strong self.entry_title as in_title, @strong self.entry_channel as in_channel => move |_| {
in_title.set_text("");
in_channel.set_text("");

// Theoretically only needs to be done once, but when setting up the page does
// not yet have a root.
let window = s.window();
dialog.set_transient_for(Some(&window));
dialog.present();
}),
);
self.btn_toggle_add_filter
.connect_clicked(clone!(@strong obj as s => move |_| {
s.imp().present_filter();
}));
self.btn_add_filter
.connect_clicked(clone!(@strong obj as s => move |_| {
s.imp().present_filter();
}));
}

#[template_callback]
Expand Down
64 changes: 47 additions & 17 deletions src/gui/subscription/subscription_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ gtk::glib::wrapper! {
}

impl SubscriptionPage {
pub fn present_subscribe(&self) {
log::trace!("Subscription page got request to present the subscription window");
self.imp().present_subscribe();
}

pub fn set_subscription_list(
&self,
subscription_list: AnySubscriptionList,
Expand Down Expand Up @@ -67,6 +72,7 @@ pub mod imp {
use gdk::glib::Object;
use gdk::glib::ParamSpec;
use gdk::glib::PRIORITY_DEFAULT;
use gdk_pixbuf::glib::subclass::Signal;
use glib::subclass::InitializingObject;
use gtk::glib;
use gtk::prelude::*;
Expand Down Expand Up @@ -99,6 +105,8 @@ pub mod imp {
#[template_child]
pub(super) btn_toggle_add_subscription: TemplateChild<gtk::Button>,
#[template_child]
pub(super) btn_add_subscription: TemplateChild<gtk::Button>,
#[template_child]
pub(super) dropdown_platform: TemplateChild<gtk::DropDown>,
#[template_child]
pub(super) entry_url: TemplateChild<gtk::Entry>,
Expand All @@ -116,23 +124,29 @@ pub mod imp {
}

impl SubscriptionPage {
pub(super) fn present_subscribe(&self) {
self.dropdown_platform.set_selected(0);
self.entry_url.set_text("");
self.entry_name_id.set_text("");

// Theoretically only needs to be done once, but when setting up the page does
// not yet have a root.
let window = self.instance().window();
self.dialog_add.set_transient_for(Some(&window));
self.dialog_add.present();
}

fn setup_toggle_add_subscription(&self, obj: &super::SubscriptionPage) {
self.btn_toggle_add_subscription.connect_clicked(clone!(@strong obj as s,
@strong self.dialog_add as dialog,
@strong self.entry_url as in_url,
@strong self.entry_name_id as in_name_id,
@strong self.dropdown_platform as dropdown_platform,
=> move |_| {
dropdown_platform.set_selected(0);
in_url.set_text("");
in_name_id.set_text("");

// Theoretically only needs to be done once, but when setting up the page does
// not yet have a root.
let window = s.window();
dialog.set_transient_for(Some(&window));
dialog.present();
}));
self.btn_toggle_add_subscription
.connect_clicked(clone!(@strong obj as s,
=> move |_| {
s.present_subscribe();
}));
self.btn_add_subscription
.connect_clicked(clone!(@strong obj as s,
=> move |_| {
s.present_subscribe();
}));
}

fn setup_platform_dropdown(&self) {
Expand Down Expand Up @@ -203,11 +217,13 @@ pub mod imp {
}
});

let obj = self.instance();
receiver.attach(
None,
clone!(@strong self.any_subscription_list as list =>
clone!(@strong self.any_subscription_list as list, @strong obj =>
move |sub| {
list.borrow().as_ref().expect("SubscriptionList should be set up").add(sub);
obj.emit_by_name::<()>("subscription-added", &[]);
Continue(true)
}
)
Expand Down Expand Up @@ -311,6 +327,20 @@ pub mod imp {
fn property(&self, _obj: &Self::Type, _id: usize, _pspec: &glib::ParamSpec) -> glib::Value {
unimplemented!()
}

fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
vec![Signal::builder(
"subscription-added",
// Types of the values which will be sent to the signal handler
&[],
// Type of the value the signal handler sends back
<()>::static_type().into(),
)
.build()]
});
SIGNALS.as_ref()
}
}

impl WidgetImpl for SubscriptionPage {}
Expand Down
21 changes: 21 additions & 0 deletions src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub mod imp {
use std::sync::Arc;
use std::sync::Mutex;

use gdk_pixbuf::glib::clone;
use glib::subclass::InitializingObject;
use gtk::glib;
use gtk::prelude::*;
Expand Down Expand Up @@ -163,6 +164,16 @@ pub mod imp {
}

impl Window {
fn setup_feed(&self) {
self.feed_page.connect_local(
"add-subscription",
true,
clone!(@strong self.subscription_page as s => move |_| {
s.present_subscribe();
None
}),
);
}
fn setup_watch_later(&self) {
let joiner = setup_joiner();
self.joiner.replace(Some(joiner.clone()));
Expand Down Expand Up @@ -238,6 +249,15 @@ pub mod imp {
.expect("PlaylistManager should be set up"),
joiner,
);

self.subscription_page.connect_local(
"subscription-added",
true,
clone!(@strong self.feed_page as f => move |_| {
f.reload();
None
}),
);
}

fn setup_filter(&self) {
Expand Down Expand Up @@ -296,6 +316,7 @@ pub mod imp {
impl ObjectImpl for Window {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
self.setup_feed();
self.setup_watch_later();
self.setup_subscriptions();
self.setup_filter();
Expand Down