Default to using Arc instead of Rc with composite structs of GtkWidgets.
This commit is contained in:
parent
750abb519b
commit
29837ad39a
@ -11,8 +11,8 @@ use headerbar::Header;
|
|||||||
use content::Content;
|
use content::Content;
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
@ -28,8 +28,8 @@ pub enum Action {
|
|||||||
pub struct App {
|
pub struct App {
|
||||||
app_instance: gtk::Application,
|
app_instance: gtk::Application,
|
||||||
window: gtk::Window,
|
window: gtk::Window,
|
||||||
header: Rc<Header>,
|
header: Arc<Header>,
|
||||||
content: Rc<Content>,
|
content: Arc<Content>,
|
||||||
receiver: Receiver<Action>,
|
receiver: Receiver<Action>,
|
||||||
sender: Sender<Action>,
|
sender: Sender<Action>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,19 +11,19 @@ use views::episodes::EpisodesView;
|
|||||||
use widgets::show::ShowWidget;
|
use widgets::show::ShowWidget;
|
||||||
use app::Action;
|
use app::Action;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
stack: gtk::Stack,
|
stack: gtk::Stack,
|
||||||
shows: Rc<ShowStack>,
|
shows: Arc<ShowStack>,
|
||||||
episodes: Rc<EpisodeStack>,
|
episodes: Arc<EpisodeStack>,
|
||||||
sender: Sender<Action>,
|
sender: Sender<Action>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
pub fn new(sender: Sender<Action>) -> Rc<Content> {
|
pub fn new(sender: Sender<Action>) -> Arc<Content> {
|
||||||
let stack = gtk::Stack::new();
|
let stack = gtk::Stack::new();
|
||||||
let episodes = EpisodeStack::new(sender.clone());
|
let episodes = EpisodeStack::new(sender.clone());
|
||||||
let shows = ShowStack::new(sender.clone());
|
let shows = ShowStack::new(sender.clone());
|
||||||
@ -31,7 +31,7 @@ impl Content {
|
|||||||
stack.add_titled(&episodes.stack, "episodes", "Episodes");
|
stack.add_titled(&episodes.stack, "episodes", "Episodes");
|
||||||
stack.add_titled(&shows.stack, "shows", "Shows");
|
stack.add_titled(&shows.stack, "shows", "Shows");
|
||||||
|
|
||||||
Rc::new(Content {
|
Arc::new(Content {
|
||||||
stack,
|
stack,
|
||||||
shows,
|
shows,
|
||||||
episodes,
|
episodes,
|
||||||
@ -62,7 +62,7 @@ impl Content {
|
|||||||
self.stack.clone()
|
self.stack.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_shows(&self) -> Rc<ShowStack> {
|
pub fn get_shows(&self) -> Arc<ShowStack> {
|
||||||
self.shows.clone()
|
self.shows.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,10 +74,10 @@ pub struct ShowStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ShowStack {
|
impl ShowStack {
|
||||||
fn new(sender: Sender<Action>) -> Rc<ShowStack> {
|
fn new(sender: Sender<Action>) -> Arc<ShowStack> {
|
||||||
let stack = gtk::Stack::new();
|
let stack = gtk::Stack::new();
|
||||||
|
|
||||||
let show = Rc::new(ShowStack {
|
let show = Arc::new(ShowStack {
|
||||||
stack,
|
stack,
|
||||||
sender: sender.clone(),
|
sender: sender.clone(),
|
||||||
});
|
});
|
||||||
@ -112,7 +112,7 @@ impl ShowStack {
|
|||||||
let vis = self.stack.get_visible_child_name().unwrap();
|
let vis = self.stack.get_visible_child_name().unwrap();
|
||||||
let old = self.stack.get_child_by_name("podcasts").unwrap();
|
let old = self.stack.get_child_by_name("podcasts").unwrap();
|
||||||
|
|
||||||
let pop = ShowsPopulated::new(Rc::new(self.clone()), self.sender.clone());
|
let pop = ShowsPopulated::new(Arc::new(self.clone()), self.sender.clone());
|
||||||
|
|
||||||
self.stack.remove(&old);
|
self.stack.remove(&old);
|
||||||
self.stack.add_named(&pop.container, "podcasts");
|
self.stack.add_named(&pop.container, "podcasts");
|
||||||
@ -130,7 +130,7 @@ impl ShowStack {
|
|||||||
|
|
||||||
pub fn replace_widget(&self, pd: &Podcast) {
|
pub fn replace_widget(&self, pd: &Podcast) {
|
||||||
let old = self.stack.get_child_by_name("widget").unwrap();
|
let old = self.stack.get_child_by_name("widget").unwrap();
|
||||||
let new = ShowWidget::new(Rc::new(self.clone()), pd, self.sender.clone());
|
let new = ShowWidget::new(Arc::new(self.clone()), pd, self.sender.clone());
|
||||||
|
|
||||||
self.stack.remove(&old);
|
self.stack.remove(&old);
|
||||||
self.stack.add_named(&new.container, "widget");
|
self.stack.add_named(&new.container, "widget");
|
||||||
@ -175,7 +175,7 @@ pub struct EpisodeStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeStack {
|
impl EpisodeStack {
|
||||||
fn new(sender: Sender<Action>) -> Rc<EpisodeStack> {
|
fn new(sender: Sender<Action>) -> Arc<EpisodeStack> {
|
||||||
let episodes = EpisodesView::new(sender.clone());
|
let episodes = EpisodesView::new(sender.clone());
|
||||||
let empty = EmptyView::new();
|
let empty = EmptyView::new();
|
||||||
let stack = gtk::Stack::new();
|
let stack = gtk::Stack::new();
|
||||||
@ -189,12 +189,7 @@ impl EpisodeStack {
|
|||||||
stack.set_visible_child_name("episodes");
|
stack.set_visible_child_name("episodes");
|
||||||
}
|
}
|
||||||
|
|
||||||
Rc::new(EpisodeStack {
|
Arc::new(EpisodeStack { stack, sender })
|
||||||
// empty,
|
|
||||||
// populated: pop,
|
|
||||||
stack,
|
|
||||||
sender,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
|
|||||||
@ -3,10 +3,10 @@ use gtk::prelude::*;
|
|||||||
|
|
||||||
use hammond_data::Source;
|
use hammond_data::Source;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use app::Action;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
use content::Content;
|
use content::Content;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -49,13 +49,13 @@ impl Default for Header {
|
|||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new(content: Rc<Content>, sender: Sender<Action>) -> Rc<Header> {
|
pub fn new(content: Arc<Content>, sender: Sender<Action>) -> Arc<Header> {
|
||||||
let h = Header::default();
|
let h = Header::default();
|
||||||
h.init(content, sender);
|
h.init(content, sender);
|
||||||
Rc::new(h)
|
Arc::new(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self, content: Rc<Content>, sender: Sender<Action>) {
|
pub fn init(&self, content: Arc<Content>, sender: Sender<Action>) {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||||
|
|
||||||
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
||||||
|
|||||||
@ -7,8 +7,7 @@ use hammond_downloader::downloader;
|
|||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::Mutex;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::rc::Rc;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use headerbar::Header;
|
use headerbar::Header;
|
||||||
@ -17,7 +16,7 @@ use app::Action;
|
|||||||
/// Update the rss feed(s) originating from `source`.
|
/// Update the rss feed(s) originating from `source`.
|
||||||
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
||||||
/// When It's done,it queues up a `RefreshViews` action.
|
/// When It's done,it queues up a `RefreshViews` action.
|
||||||
pub fn refresh_feed(headerbar: Rc<Header>, source: Option<Vec<Source>>, sender: Sender<Action>) {
|
pub fn refresh_feed(headerbar: Arc<Header>, source: Option<Vec<Source>>, sender: Sender<Action>) {
|
||||||
headerbar.show_update_notification();
|
headerbar.show_update_notification();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|||||||
@ -9,8 +9,8 @@ use widgets::episode::EpisodeWidget;
|
|||||||
use utils::get_pixbuf_from_path;
|
use utils::get_pixbuf_from_path;
|
||||||
use app::Action;
|
use app::Action;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum ListSplit {
|
enum ListSplit {
|
||||||
@ -72,7 +72,7 @@ impl Default for EpisodesView {
|
|||||||
|
|
||||||
// TODO: REFACTOR ME
|
// TODO: REFACTOR ME
|
||||||
impl EpisodesView {
|
impl EpisodesView {
|
||||||
pub fn new(sender: Sender<Action>) -> Rc<EpisodesView> {
|
pub fn new(sender: Sender<Action>) -> Arc<EpisodesView> {
|
||||||
let view = EpisodesView::default();
|
let view = EpisodesView::default();
|
||||||
let episodes = dbqueries::get_episodes_widgets_with_limit(100).unwrap();
|
let episodes = dbqueries::get_episodes_widgets_with_limit(100).unwrap();
|
||||||
let now_utc = Utc::now();
|
let now_utc = Utc::now();
|
||||||
@ -121,7 +121,7 @@ impl EpisodesView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
view.container.show_all();
|
view.container.show_all();
|
||||||
Rc::new(view)
|
Arc::new(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
|
|||||||
@ -9,8 +9,8 @@ use utils::get_pixbuf_from_path;
|
|||||||
use content::ShowStack;
|
use content::ShowStack;
|
||||||
use app::Action;
|
use app::Action;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ShowsPopulated {
|
pub struct ShowsPopulated {
|
||||||
@ -35,13 +35,13 @@ impl Default for ShowsPopulated {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ShowsPopulated {
|
impl ShowsPopulated {
|
||||||
pub fn new(show: Rc<ShowStack>, sender: Sender<Action>) -> ShowsPopulated {
|
pub fn new(show: Arc<ShowStack>, sender: Sender<Action>) -> ShowsPopulated {
|
||||||
let pop = ShowsPopulated::default();
|
let pop = ShowsPopulated::default();
|
||||||
pop.init(show, sender);
|
pop.init(show, sender);
|
||||||
pop
|
pop
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self, show: Rc<ShowStack>, sender: Sender<Action>) {
|
pub fn init(&self, show: Arc<ShowStack>, sender: Sender<Action>) {
|
||||||
use gtk::WidgetExt;
|
use gtk::WidgetExt;
|
||||||
|
|
||||||
// TODO: handle unwraps.
|
// TODO: handle unwraps.
|
||||||
|
|||||||
@ -14,8 +14,8 @@ use utils::get_pixbuf_from_path;
|
|||||||
use content::ShowStack;
|
use content::ShowStack;
|
||||||
use app::Action;
|
use app::Action;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -54,13 +54,13 @@ impl Default for ShowWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ShowWidget {
|
impl ShowWidget {
|
||||||
pub fn new(shows: Rc<ShowStack>, pd: &Podcast, sender: Sender<Action>) -> ShowWidget {
|
pub fn new(shows: Arc<ShowStack>, pd: &Podcast, sender: Sender<Action>) -> ShowWidget {
|
||||||
let pdw = ShowWidget::default();
|
let pdw = ShowWidget::default();
|
||||||
pdw.init(shows, pd, sender);
|
pdw.init(shows, pd, sender);
|
||||||
pdw
|
pdw
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self, shows: Rc<ShowStack>, pd: &Podcast, sender: Sender<Action>) {
|
pub fn init(&self, shows: Arc<ShowStack>, pd: &Podcast, sender: Sender<Action>) {
|
||||||
// Hacky workaround so the pd.id() can be retrieved from the `ShowStack`.
|
// Hacky workaround so the pd.id() can be retrieved from the `ShowStack`.
|
||||||
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ impl ShowWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_unsub_button_clicked(
|
fn on_unsub_button_clicked(
|
||||||
shows: Rc<ShowStack>,
|
shows: Arc<ShowStack>,
|
||||||
pd: &Podcast,
|
pd: &Podcast,
|
||||||
unsub_button: >k::Button,
|
unsub_button: >k::Button,
|
||||||
sender: Sender<Action>,
|
sender: Sender<Action>,
|
||||||
@ -132,7 +132,7 @@ fn on_unsub_button_clicked(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn on_played_button_clicked(shows: Rc<ShowStack>, pd: &Podcast) {
|
fn on_played_button_clicked(shows: Arc<ShowStack>, pd: &Podcast) {
|
||||||
let _ = dbqueries::update_none_to_played_now(pd);
|
let _ = dbqueries::update_none_to_played_now(pd);
|
||||||
|
|
||||||
shows.update_widget();
|
shows.update_widget();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user