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 utils;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Action {
|
||||
@ -28,8 +28,8 @@ pub enum Action {
|
||||
pub struct App {
|
||||
app_instance: gtk::Application,
|
||||
window: gtk::Window,
|
||||
header: Rc<Header>,
|
||||
content: Rc<Content>,
|
||||
header: Arc<Header>,
|
||||
content: Arc<Content>,
|
||||
receiver: Receiver<Action>,
|
||||
sender: Sender<Action>,
|
||||
}
|
||||
|
||||
@ -11,19 +11,19 @@ use views::episodes::EpisodesView;
|
||||
use widgets::show::ShowWidget;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Content {
|
||||
stack: gtk::Stack,
|
||||
shows: Rc<ShowStack>,
|
||||
episodes: Rc<EpisodeStack>,
|
||||
shows: Arc<ShowStack>,
|
||||
episodes: Arc<EpisodeStack>,
|
||||
sender: Sender<Action>,
|
||||
}
|
||||
|
||||
impl Content {
|
||||
pub fn new(sender: Sender<Action>) -> Rc<Content> {
|
||||
pub fn new(sender: Sender<Action>) -> Arc<Content> {
|
||||
let stack = gtk::Stack::new();
|
||||
let episodes = EpisodeStack::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(&shows.stack, "shows", "Shows");
|
||||
|
||||
Rc::new(Content {
|
||||
Arc::new(Content {
|
||||
stack,
|
||||
shows,
|
||||
episodes,
|
||||
@ -62,7 +62,7 @@ impl Content {
|
||||
self.stack.clone()
|
||||
}
|
||||
|
||||
pub fn get_shows(&self) -> Rc<ShowStack> {
|
||||
pub fn get_shows(&self) -> Arc<ShowStack> {
|
||||
self.shows.clone()
|
||||
}
|
||||
}
|
||||
@ -74,10 +74,10 @@ pub struct ShowStack {
|
||||
}
|
||||
|
||||
impl ShowStack {
|
||||
fn new(sender: Sender<Action>) -> Rc<ShowStack> {
|
||||
fn new(sender: Sender<Action>) -> Arc<ShowStack> {
|
||||
let stack = gtk::Stack::new();
|
||||
|
||||
let show = Rc::new(ShowStack {
|
||||
let show = Arc::new(ShowStack {
|
||||
stack,
|
||||
sender: sender.clone(),
|
||||
});
|
||||
@ -112,7 +112,7 @@ impl ShowStack {
|
||||
let vis = self.stack.get_visible_child_name().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.add_named(&pop.container, "podcasts");
|
||||
@ -130,7 +130,7 @@ impl ShowStack {
|
||||
|
||||
pub fn replace_widget(&self, pd: &Podcast) {
|
||||
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.add_named(&new.container, "widget");
|
||||
@ -175,7 +175,7 @@ pub struct EpisodeStack {
|
||||
}
|
||||
|
||||
impl EpisodeStack {
|
||||
fn new(sender: Sender<Action>) -> Rc<EpisodeStack> {
|
||||
fn new(sender: Sender<Action>) -> Arc<EpisodeStack> {
|
||||
let episodes = EpisodesView::new(sender.clone());
|
||||
let empty = EmptyView::new();
|
||||
let stack = gtk::Stack::new();
|
||||
@ -189,12 +189,7 @@ impl EpisodeStack {
|
||||
stack.set_visible_child_name("episodes");
|
||||
}
|
||||
|
||||
Rc::new(EpisodeStack {
|
||||
// empty,
|
||||
// populated: pop,
|
||||
stack,
|
||||
sender,
|
||||
})
|
||||
Arc::new(EpisodeStack { stack, sender })
|
||||
}
|
||||
|
||||
pub fn update(&self) {
|
||||
|
||||
@ -3,10 +3,10 @@ use gtk::prelude::*;
|
||||
|
||||
use hammond_data::Source;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use app::Action;
|
||||
use std::sync::Arc;
|
||||
|
||||
use app::Action;
|
||||
use content::Content;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -49,13 +49,13 @@ impl Default for Header {
|
||||
|
||||
impl Header {
|
||||
#[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();
|
||||
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 add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
||||
|
||||
@ -7,8 +7,7 @@ use hammond_downloader::downloader;
|
||||
|
||||
use std::thread;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Mutex;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use headerbar::Header;
|
||||
@ -17,7 +16,7 @@ use app::Action;
|
||||
/// Update the rss feed(s) originating from `source`.
|
||||
/// 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.
|
||||
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();
|
||||
|
||||
thread::spawn(move || {
|
||||
|
||||
@ -9,8 +9,8 @@ use widgets::episode::EpisodeWidget;
|
||||
use utils::get_pixbuf_from_path;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum ListSplit {
|
||||
@ -72,7 +72,7 @@ impl Default for EpisodesView {
|
||||
|
||||
// TODO: REFACTOR ME
|
||||
impl EpisodesView {
|
||||
pub fn new(sender: Sender<Action>) -> Rc<EpisodesView> {
|
||||
pub fn new(sender: Sender<Action>) -> Arc<EpisodesView> {
|
||||
let view = EpisodesView::default();
|
||||
let episodes = dbqueries::get_episodes_widgets_with_limit(100).unwrap();
|
||||
let now_utc = Utc::now();
|
||||
@ -121,7 +121,7 @@ impl EpisodesView {
|
||||
}
|
||||
|
||||
view.container.show_all();
|
||||
Rc::new(view)
|
||||
Arc::new(view)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
|
||||
@ -9,8 +9,8 @@ use utils::get_pixbuf_from_path;
|
||||
use content::ShowStack;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ShowsPopulated {
|
||||
@ -35,13 +35,13 @@ impl Default for 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();
|
||||
pop.init(show, sender);
|
||||
pop
|
||||
}
|
||||
|
||||
pub fn init(&self, show: Rc<ShowStack>, sender: Sender<Action>) {
|
||||
pub fn init(&self, show: Arc<ShowStack>, sender: Sender<Action>) {
|
||||
use gtk::WidgetExt;
|
||||
|
||||
// TODO: handle unwraps.
|
||||
|
||||
@ -14,8 +14,8 @@ use utils::get_pixbuf_from_path;
|
||||
use content::ShowStack;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -54,13 +54,13 @@ impl Default for 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();
|
||||
pdw.init(shows, pd, sender);
|
||||
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`.
|
||||
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
||||
|
||||
@ -107,7 +107,7 @@ impl ShowWidget {
|
||||
}
|
||||
|
||||
fn on_unsub_button_clicked(
|
||||
shows: Rc<ShowStack>,
|
||||
shows: Arc<ShowStack>,
|
||||
pd: &Podcast,
|
||||
unsub_button: >k::Button,
|
||||
sender: Sender<Action>,
|
||||
@ -132,7 +132,7 @@ fn on_unsub_button_clicked(
|
||||
}
|
||||
|
||||
#[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);
|
||||
|
||||
shows.update_widget();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user