From f6c7731377896731b715f759374cbb1641ff7adc Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sun, 5 Aug 2018 10:12:42 +0300 Subject: [PATCH] Fix Rust 2018 edition warnings --- podcasts-data/src/lib.rs | 11 ++--------- podcasts-downloader/src/downloader.rs | 6 +++--- podcasts-downloader/src/errors.rs | 2 ++ podcasts-gtk/build.rs | 2 +- podcasts-gtk/src/app.rs | 10 +++++----- podcasts-gtk/src/headerbar.rs | 22 ++++++++++----------- podcasts-gtk/src/i18n.rs | 17 ++++++++++------ podcasts-gtk/src/manager.rs | 14 ++++++------- podcasts-gtk/src/prefs.rs | 10 +++++----- podcasts-gtk/src/settings.rs | 16 +++++++-------- podcasts-gtk/src/stacks/content.rs | 18 ++++++++--------- podcasts-gtk/src/stacks/home.rs | 8 ++++---- podcasts-gtk/src/stacks/mod.rs | 8 ++++---- podcasts-gtk/src/stacks/populated.rs | 22 ++++++++++----------- podcasts-gtk/src/stacks/show.rs | 12 ++++++------ podcasts-gtk/src/static_resource.rs | 2 +- podcasts-gtk/src/utils.rs | 26 ++++++++++++++----------- podcasts-gtk/src/widgets/aboutdialog.rs | 2 +- podcasts-gtk/src/widgets/appnotif.rs | 13 +++++++++---- podcasts-gtk/src/widgets/empty.rs | 6 +++--- podcasts-gtk/src/widgets/episode.rs | 6 +++--- podcasts-gtk/src/widgets/home_view.rs | 10 +++++----- podcasts-gtk/src/widgets/mod.rs | 20 +++++++++---------- podcasts-gtk/src/widgets/player.rs | 12 ++++++------ podcasts-gtk/src/widgets/show.rs | 12 ++++++------ podcasts-gtk/src/widgets/show_menu.rs | 10 +++++----- podcasts-gtk/src/widgets/shows_view.rs | 12 ++++++------ 27 files changed, 159 insertions(+), 150 deletions(-) diff --git a/podcasts-data/src/lib.rs b/podcasts-data/src/lib.rs index 84165b9..45a7444 100644 --- a/podcasts-data/src/lib.rs +++ b/podcasts-data/src/lib.rs @@ -23,13 +23,8 @@ ) )] // Enable lint group collections -#![warn( - nonstandard_style, - edition_2018, - rust_2018_idioms, - bad_style, - unused -)] +#![warn(nonstandard_style, bad_style, unused)] +#![allow(edition_2018, rust_2018_idioms)] // standalone lints #![warn( const_err, @@ -51,8 +46,6 @@ missing_copy_implementations )] #![deny(warnings)] -// warn when code is not using dyn Trait syntax. req rustc 1.27 -// #![deny(bare_trait_object)] //! FIXME: Docs diff --git a/podcasts-downloader/src/downloader.rs b/podcasts-downloader/src/downloader.rs index 8dce05b..f566324 100644 --- a/podcasts-downloader/src/downloader.rs +++ b/podcasts-downloader/src/downloader.rs @@ -38,7 +38,7 @@ fn download_into( dir: &str, file_title: &str, url: &str, - progress: Option>>, + progress: Option>>, ) -> Result { info!("GET request to: {}", url); // Haven't included the loop check as @@ -122,7 +122,7 @@ fn save_io( file: &str, resp: &mut reqwest::Response, content_lenght: Option, - progress: Option>>, + progress: Option>>, ) -> Result<(), DownloadError> { info!("Downloading into: {}", file); let chunk_size = match content_lenght { @@ -163,7 +163,7 @@ fn save_io( pub fn get_episode( ep: &mut EpisodeWidgetModel, download_folder: &str, - progress: Option>>, + progress: Option>>, ) -> Result<(), DownloadError> { // Check if its alrdy downloaded if ep.local_uri().is_some() { diff --git a/podcasts-downloader/src/errors.rs b/podcasts-downloader/src/errors.rs index b8dc4e7..5750ac5 100644 --- a/podcasts-downloader/src/errors.rs +++ b/podcasts-downloader/src/errors.rs @@ -1,3 +1,5 @@ +#![allow(bare_trait_objects)] + use podcasts_data::errors::DataError; use reqwest; use std::io; diff --git a/podcasts-gtk/build.rs b/podcasts-gtk/build.rs index 80b6c81..ab9e977 100644 --- a/podcasts-gtk/build.rs +++ b/podcasts-gtk/build.rs @@ -24,7 +24,7 @@ fn main() { let globals = format!( " -pub static LOCALEDIR: &'static str = \"{}\"; +pub(crate) static LOCALEDIR: &'static str = \"{}\"; ", localedir ); diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index f3510ca..7336de5 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -25,7 +25,7 @@ use std::env; use std::rc::Rc; use std::sync::Arc; -pub const APP_ID: &str = "org.gnome.Podcasts"; +pub(crate) const APP_ID: &str = "org.gnome.Podcasts"; include!(concat!(env!("OUT_DIR"), "/build_globals.rs")); @@ -44,7 +44,7 @@ where } #[derive(Debug, Clone)] -pub enum Action { +pub(crate) enum Action { RefreshAllViews, RefreshEpisodesView, RefreshEpisodesViewBGR, @@ -65,7 +65,7 @@ pub enum Action { } #[derive(Debug, Clone)] -pub struct App { +pub(crate) struct App { instance: gtk::Application, window: gtk::ApplicationWindow, overlay: gtk::Overlay, @@ -78,7 +78,7 @@ pub struct App { } impl App { - pub fn new(application: >k::Application) -> Rc { + pub(crate) fn new(application: >k::Application) -> Rc { let settings = gio::Settings::new(APP_ID); let (sender, receiver) = unbounded(); @@ -307,7 +307,7 @@ impl App { glib::Continue(true) } - pub fn run() { + pub(crate) fn run() { // Set up the textdomain for gettext setlocale(LocaleCategory::LcAll, ""); bindtextdomain("gnome-podcasts", LOCALEDIR); diff --git a/podcasts-gtk/src/headerbar.rs b/podcasts-gtk/src/headerbar.rs index 6c9bd09..63263f6 100644 --- a/podcasts-gtk/src/headerbar.rs +++ b/podcasts-gtk/src/headerbar.rs @@ -20,8 +20,8 @@ use i18n::i18n; #[derive(Debug, Clone)] // TODO: Factor out the hamburger menu // TODO: Make a proper state machine for the headerbar states -pub struct Header { - pub container: gtk::HeaderBar, +pub(crate) struct Header { + pub(crate) container: gtk::HeaderBar, switch: gtk::StackSwitcher, back: gtk::Button, show_title: gtk::Label, @@ -196,13 +196,13 @@ impl Default for Header { // TODO: Make a proper state machine for the headerbar states impl Header { - pub fn new(content: &Content, sender: &Sender) -> Rc { + pub(crate) fn new(content: &Content, sender: &Sender) -> Rc { let h = Rc::new(Header::default()); Self::init(&h, content, &sender); h } - pub fn init(s: &Rc, content: &Content, sender: &Sender) { + pub(crate) fn init(s: &Rc, content: &Content, sender: &Sender) { let weak = Rc::downgrade(s); s.switch.set_stack(&content.get_stack()); @@ -225,7 +225,7 @@ impl Header { })); } - pub fn switch_to_back(&self, title: &str) { + pub(crate) fn switch_to_back(&self, title: &str) { self.switch.hide(); self.add.toggle.hide(); self.back.show(); @@ -235,7 +235,7 @@ impl Header { self.dots.show(); } - pub fn switch_to_normal(&self) { + pub(crate) fn switch_to_normal(&self) { self.switch.show(); self.add.toggle.show(); self.back.hide(); @@ -244,23 +244,23 @@ impl Header { self.dots.hide(); } - pub fn set_show_title(&self, title: &str) { + pub(crate) fn set_show_title(&self, title: &str) { self.show_title.set_text(title) } - pub fn show_update_notification(&self) { + pub(crate) fn show_update_notification(&self) { self.updater.show(); } - pub fn hide_update_notification(&self) { + pub(crate) fn hide_update_notification(&self) { self.updater.hide(); } - pub fn open_menu(&self) { + pub(crate) fn open_menu(&self) { self.hamburger.clicked(); } - pub fn set_secondary_menu(&self, pop: >k::PopoverMenu) { + pub(crate) fn set_secondary_menu(&self, pop: >k::PopoverMenu) { self.dots.set_popover(Some(pop)); } } diff --git a/podcasts-gtk/src/i18n.rs b/podcasts-gtk/src/i18n.rs index d4fc98d..35d488c 100644 --- a/podcasts-gtk/src/i18n.rs +++ b/podcasts-gtk/src/i18n.rs @@ -30,35 +30,40 @@ fn kreplace(input: String, kwargs: &[(&str, &str)]) -> String { } #[allow(dead_code)] -pub fn i18n(format: &str) -> String { +pub(crate) fn i18n(format: &str) -> String { gettext(format) } #[allow(dead_code)] -pub fn i18n_f(format: &str, args: &[&str]) -> String { +pub(crate) fn i18n_f(format: &str, args: &[&str]) -> String { let s = gettext(format); freplace(s, args) } #[allow(dead_code)] -pub fn i18n_k(format: &str, kwargs: &[(&str, &str)]) -> String { +pub(crate) fn i18n_k(format: &str, kwargs: &[(&str, &str)]) -> String { let s = gettext(format); kreplace(s, kwargs) } #[allow(dead_code)] -pub fn ni18n(single: &str, multiple: &str, number: u32) -> String { +pub(crate) fn ni18n(single: &str, multiple: &str, number: u32) -> String { ngettext(single, multiple, number) } #[allow(dead_code)] -pub fn ni18n_f(single: &str, multiple: &str, number: u32, args: &[&str]) -> String { +pub(crate) fn ni18n_f(single: &str, multiple: &str, number: u32, args: &[&str]) -> String { let s = ngettext(single, multiple, number); freplace(s, args) } #[allow(dead_code)] -pub fn ni18n_k(single: &str, multiple: &str, number: u32, kwargs: &[(&str, &str)]) -> String { +pub(crate) fn ni18n_k( + single: &str, + multiple: &str, + number: u32, + kwargs: &[(&str, &str)], +) -> String { let s = ngettext(single, multiple, number); kreplace(s, kwargs) } diff --git a/podcasts-gtk/src/manager.rs b/podcasts-gtk/src/manager.rs index fb8f7c5..9065389 100644 --- a/podcasts-gtk/src/manager.rs +++ b/podcasts-gtk/src/manager.rs @@ -14,7 +14,7 @@ use std::sync::{Arc, Mutex, RwLock}; // I am terrible at writting downloaders and download managers. #[derive(Debug)] -pub struct Progress { +pub(crate) struct Progress { total_bytes: u64, downloaded_bytes: u64, cancel: bool, @@ -31,7 +31,7 @@ impl Default for Progress { } impl Progress { - pub fn get_fraction(&self) -> f64 { + pub(crate) fn get_fraction(&self) -> f64 { let ratio = self.downloaded_bytes as f64 / self.total_bytes as f64; debug!("{:?}", self); debug!("Ratio completed: {}", ratio); @@ -42,15 +42,15 @@ impl Progress { ratio } - pub fn get_total_size(&self) -> u64 { + pub(crate) fn get_total_size(&self) -> u64 { self.total_bytes } - pub fn get_downloaded(&self) -> u64 { + pub(crate) fn get_downloaded(&self) -> u64 { self.downloaded_bytes } - pub fn cancel(&mut self) { + pub(crate) fn cancel(&mut self) { self.cancel = true; } } @@ -70,12 +70,12 @@ impl DownloadProgress for Progress { } lazy_static! { - pub static ref ACTIVE_DOWNLOADS: Arc>>>> = + pub(crate) static ref ACTIVE_DOWNLOADS: Arc>>>> = { Arc::new(RwLock::new(HashMap::new())) }; static ref DLPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap(); } -pub fn add(id: i32, directory: String) -> Result<(), Error> { +pub(crate) fn add(id: i32, directory: String) -> Result<(), Error> { // Create a new `Progress` struct to keep track of dl progress. let prog = Arc::new(Mutex::new(Progress::default())); diff --git a/podcasts-gtk/src/prefs.rs b/podcasts-gtk/src/prefs.rs index cc2b5db..b52dac6 100644 --- a/podcasts-gtk/src/prefs.rs +++ b/podcasts-gtk/src/prefs.rs @@ -6,7 +6,7 @@ use gtk::prelude::*; use i18n::i18n; #[derive(Debug, Clone)] -pub struct Prefs { +pub(crate) struct Prefs { dialog: gtk::Window, dark_toggle: gtk::Switch, cleanup_value: gtk::SpinButton, @@ -33,13 +33,13 @@ impl Default for Prefs { // TODO: Refactor components into smaller state machines impl Prefs { - pub fn new(settings: &Settings) -> Prefs { + pub(crate) fn new(settings: &Settings) -> Prefs { let h = Prefs::default(); h.init(settings); h } - pub fn init(&self, settings: &Settings) { + pub(crate) fn init(&self, settings: &Settings) { settings.bind( "dark-theme", &self.dark_toggle, @@ -65,7 +65,7 @@ impl Prefs { .iter() .enumerate() { - let row: &[&ToValue] = &[item]; + let row: &[&dyn ToValue] = &[item]; if item.to_lowercase() == cleanup_p { cleanup_pos = i as i32; } @@ -93,7 +93,7 @@ impl Prefs { }); } - pub fn show(&self, parent: >k::ApplicationWindow) { + pub(crate) fn show(&self, parent: >k::ApplicationWindow) { self.dialog.set_transient_for(Some(parent)); self.dialog.set_modal(true); self.dialog.show_all(); diff --git a/podcasts-gtk/src/settings.rs b/podcasts-gtk/src/settings.rs index f725448..1bbcfda 100644 --- a/podcasts-gtk/src/settings.rs +++ b/podcasts-gtk/src/settings.rs @@ -6,7 +6,7 @@ use gtk::GtkWindowExt; use chrono::prelude::*; use chrono::Duration; -pub struct WindowGeometry { +pub(crate) struct WindowGeometry { left: i32, top: i32, width: i32, @@ -15,7 +15,7 @@ pub struct WindowGeometry { } impl WindowGeometry { - pub fn from_window(window: >k::ApplicationWindow) -> WindowGeometry { + pub(crate) fn from_window(window: >k::ApplicationWindow) -> WindowGeometry { let position = window.get_position(); let size = window.get_size(); let left = position.0; @@ -33,7 +33,7 @@ impl WindowGeometry { } } - pub fn from_settings(settings: &gio::Settings) -> WindowGeometry { + pub(crate) fn from_settings(settings: &gio::Settings) -> WindowGeometry { let top = settings.get_int("persist-window-geometry-top"); let left = settings.get_int("persist-window-geometry-left"); let width = settings.get_int("persist-window-geometry-width"); @@ -49,7 +49,7 @@ impl WindowGeometry { } } - pub fn apply(&self, window: >k::ApplicationWindow) { + pub(crate) fn apply(&self, window: >k::ApplicationWindow) { if self.width > 0 && self.height > 0 { window.resize(self.width, self.height); } @@ -61,7 +61,7 @@ impl WindowGeometry { } } - pub fn write(&self, settings: &gio::Settings) { + pub(crate) fn write(&self, settings: &gio::Settings) { settings.set_int("persist-window-geometry-left", self.left); settings.set_int("persist-window-geometry-top", self.top); settings.set_int("persist-window-geometry-width", self.width); @@ -70,14 +70,14 @@ impl WindowGeometry { } } -pub fn get_refresh_interval(settings: &Settings) -> Duration { +pub(crate) fn get_refresh_interval(settings: &Settings) -> Duration { let time = i64::from(settings.get_int("refresh-interval-time")); let period = settings.get_string("refresh-interval-period").unwrap(); time_period_to_duration(time, period.as_str()) } -pub fn get_cleanup_date(settings: &Settings) -> DateTime { +pub(crate) fn get_cleanup_date(settings: &Settings) -> DateTime { let time = i64::from(settings.get_int("cleanup-age-time")); let period = settings.get_string("cleanup-age-period").unwrap(); let duration = time_period_to_duration(time, period.as_str()); @@ -85,7 +85,7 @@ pub fn get_cleanup_date(settings: &Settings) -> DateTime { Utc::now() - duration } -pub fn time_period_to_duration(time: i64, period: &str) -> Duration { +pub(crate) fn time_period_to_duration(time: i64, period: &str) -> Duration { match period { "weeks" => Duration::weeks(time), "days" => Duration::days(time), diff --git a/podcasts-gtk/src/stacks/content.rs b/podcasts-gtk/src/stacks/content.rs index 9fdc383..506fd32 100644 --- a/podcasts-gtk/src/stacks/content.rs +++ b/podcasts-gtk/src/stacks/content.rs @@ -13,7 +13,7 @@ use std::rc::Rc; use i18n::i18n; #[derive(Debug, Clone)] -pub struct Content { +pub(crate) struct Content { stack: gtk::Stack, shows: Rc>, home: Rc>, @@ -21,7 +21,7 @@ pub struct Content { } impl Content { - pub fn new(sender: &Sender) -> Result, Error> { + pub(crate) fn new(sender: &Sender) -> Result, Error> { let stack = gtk::Stack::new(); let home = Rc::new(RefCell::new(HomeStack::new(sender.clone())?)); let shows = Rc::new(RefCell::new(ShowStack::new(sender.clone()))); @@ -38,12 +38,12 @@ impl Content { Ok(Rc::new(con)) } - pub fn update(&self) { + pub(crate) fn update(&self) { self.update_home(); self.update_shows(); } - pub fn update_home(&self) { + pub(crate) fn update_home(&self) { self.home .borrow_mut() .update() @@ -51,7 +51,7 @@ impl Content { .ok(); } - pub fn update_home_if_background(&self) { + pub(crate) fn update_home_if_background(&self) { if self.stack.get_visible_child_name() != Some("home".into()) { self.update_home(); } @@ -65,7 +65,7 @@ impl Content { .ok(); } - pub fn update_shows_view(&self) { + pub(crate) fn update_shows_view(&self) { self.shows .borrow_mut() .update() @@ -73,7 +73,7 @@ impl Content { .ok(); } - pub fn update_widget_if_same(&self, pid: i32) { + pub(crate) fn update_widget_if_same(&self, pid: i32) { let pop = self.shows.borrow().populated(); pop.borrow_mut() .update_widget_if_same(pid) @@ -81,11 +81,11 @@ impl Content { .ok(); } - pub fn get_stack(&self) -> gtk::Stack { + pub(crate) fn get_stack(&self) -> gtk::Stack { self.stack.clone() } - pub fn get_shows(&self) -> Rc> { + pub(crate) fn get_shows(&self) -> Rc> { self.shows.clone() } } diff --git a/podcasts-gtk/src/stacks/home.rs b/podcasts-gtk/src/stacks/home.rs index df73b86..ec3492c 100644 --- a/podcasts-gtk/src/stacks/home.rs +++ b/podcasts-gtk/src/stacks/home.rs @@ -19,7 +19,7 @@ enum State { } #[derive(Debug, Clone)] -pub struct HomeStack { +pub(crate) struct HomeStack { empty: EmptyView, episodes: Rc, stack: gtk::Stack, @@ -28,7 +28,7 @@ pub struct HomeStack { } impl HomeStack { - pub fn new(sender: Sender) -> Result { + pub(crate) fn new(sender: Sender) -> Result { let episodes = HomeView::new(sender.clone())?; let empty = EmptyView::new(); let stack = gtk::Stack::new(); @@ -49,11 +49,11 @@ impl HomeStack { Ok(home) } - pub fn get_stack(&self) -> gtk::Stack { + pub(crate) fn get_stack(&self) -> gtk::Stack { self.stack.clone() } - pub fn update(&mut self) -> Result<(), Error> { + pub(crate) fn update(&mut self) -> Result<(), Error> { // Copy the vertical scrollbar adjustment from the old view. self.episodes .save_alignment() diff --git a/podcasts-gtk/src/stacks/mod.rs b/podcasts-gtk/src/stacks/mod.rs index abab9f8..2855610 100644 --- a/podcasts-gtk/src/stacks/mod.rs +++ b/podcasts-gtk/src/stacks/mod.rs @@ -3,7 +3,7 @@ mod home; mod populated; mod show; -pub use self::content::Content; -pub use self::home::HomeStack; -pub use self::populated::{PopulatedStack, PopulatedState}; -pub use self::show::{ShowStack, ShowState}; +pub(crate) use self::content::Content; +pub(crate) use self::home::HomeStack; +pub(crate) use self::populated::{PopulatedStack, PopulatedState}; +pub(crate) use self::show::ShowStack; diff --git a/podcasts-gtk/src/stacks/populated.rs b/podcasts-gtk/src/stacks/populated.rs index 1ebeb93..e99bf5b 100644 --- a/podcasts-gtk/src/stacks/populated.rs +++ b/podcasts-gtk/src/stacks/populated.rs @@ -15,13 +15,13 @@ use std::rc::Rc; use std::sync::Arc; #[derive(Debug, Clone, Copy)] -pub enum PopulatedState { +pub(crate) enum PopulatedState { View, Widget, } #[derive(Debug, Clone)] -pub struct PopulatedStack { +pub(crate) struct PopulatedStack { container: gtk::Box, populated: Rc, show: Rc, @@ -31,7 +31,7 @@ pub struct PopulatedStack { } impl PopulatedStack { - pub fn new(sender: Sender) -> PopulatedStack { + pub(crate) fn new(sender: Sender) -> PopulatedStack { let stack = gtk::Stack::new(); let state = PopulatedState::View; let populated = ShowsView::new(sender.clone()); @@ -53,12 +53,12 @@ impl PopulatedStack { } } - pub fn update(&mut self) { + pub(crate) fn update(&mut self) { self.update_widget().map_err(|err| format!("{}", err)).ok(); self.update_shows().map_err(|err| format!("{}", err)).ok(); } - pub fn update_shows(&mut self) -> Result<(), Error> { + pub(crate) fn update_shows(&mut self) -> Result<(), Error> { // The current visible child might change depending on // removal and insertion in the gtk::Stack, so we have // to make sure it will stay the same. @@ -69,7 +69,7 @@ impl PopulatedStack { Ok(()) } - pub fn replace_shows(&mut self) -> Result<(), Error> { + pub(crate) fn replace_shows(&mut self) -> Result<(), Error> { let old = &self.populated.container.clone(); debug!("Name: {:?}", WidgetExt::get_name(old)); @@ -87,7 +87,7 @@ impl PopulatedStack { Ok(()) } - pub fn replace_widget(&mut self, pd: Arc) -> Result<(), Error> { + pub(crate) fn replace_widget(&mut self, pd: Arc) -> Result<(), Error> { let old = self.show.container.clone(); // save the ShowWidget vertical scrollabar alignment @@ -107,7 +107,7 @@ impl PopulatedStack { Ok(()) } - pub fn update_widget(&mut self) -> Result<(), Error> { + pub(crate) fn update_widget(&mut self) -> Result<(), Error> { let old = self.show.container.clone(); let id = self.show.show_id(); if id.is_none() { @@ -128,7 +128,7 @@ impl PopulatedStack { } // Only update widget if its show_id is equal to pid. - pub fn update_widget_if_same(&mut self, pid: i32) -> Result<(), Error> { + pub(crate) fn update_widget_if_same(&mut self, pid: i32) -> Result<(), Error> { if self.show.show_id() != Some(pid) { debug!("Different widget. Early return"); return Ok(()); @@ -137,11 +137,11 @@ impl PopulatedStack { self.update_widget() } - pub fn container(&self) -> gtk::Box { + pub(crate) fn container(&self) -> gtk::Box { self.container.clone() } - pub fn switch_visible(&mut self, state: PopulatedState, animation: StackTransitionType) { + pub(crate) fn switch_visible(&mut self, state: PopulatedState, animation: StackTransitionType) { use self::PopulatedState::*; match state { diff --git a/podcasts-gtk/src/stacks/show.rs b/podcasts-gtk/src/stacks/show.rs index 040afb6..cb2076b 100644 --- a/podcasts-gtk/src/stacks/show.rs +++ b/podcasts-gtk/src/stacks/show.rs @@ -14,13 +14,13 @@ use std::cell::RefCell; use std::rc::Rc; #[derive(Debug, Clone, Copy)] -pub enum ShowState { +pub(crate) enum ShowState { Populated, Empty, } #[derive(Debug, Clone)] -pub struct ShowStack { +pub(crate) struct ShowStack { empty: EmptyView, populated: Rc>, stack: gtk::Stack, @@ -29,7 +29,7 @@ pub struct ShowStack { } impl ShowStack { - pub fn new(sender: Sender) -> Self { + pub(crate) fn new(sender: Sender) -> Self { let populated = Rc::new(RefCell::new(PopulatedStack::new(sender.clone()))); let empty = EmptyView::new(); let stack = gtk::Stack::new(); @@ -51,15 +51,15 @@ impl ShowStack { show } - pub fn get_stack(&self) -> gtk::Stack { + pub(crate) fn get_stack(&self) -> gtk::Stack { self.stack.clone() } - pub fn populated(&self) -> Rc> { + pub(crate) fn populated(&self) -> Rc> { self.populated.clone() } - pub fn update(&mut self) -> Result<(), Error> { + pub(crate) fn update(&mut self) -> Result<(), Error> { self.populated.borrow_mut().update(); self.determine_state() } diff --git a/podcasts-gtk/src/static_resource.rs b/podcasts-gtk/src/static_resource.rs index 25deef7..774c048 100644 --- a/podcasts-gtk/src/static_resource.rs +++ b/podcasts-gtk/src/static_resource.rs @@ -1,7 +1,7 @@ use gio::{resources_register, Error, Resource}; use glib::Bytes; -pub fn init() -> Result<(), Error> { +pub(crate) fn init() -> Result<(), Error> { // load the gresource binary at build time and include/link it into the final // binary. let res_bytes = include_bytes!("../resources/resources.gresource"); diff --git a/podcasts-gtk/src/utils.rs b/podcasts-gtk/src/utils.rs index a0eac16..4eaf060 100644 --- a/podcasts-gtk/src/utils.rs +++ b/podcasts-gtk/src/utils.rs @@ -64,7 +64,7 @@ use i18n::i18n; /// let list = gtk::ListBox::new(); /// lazy_load(widgets, list, |w| w, || {}); /// ``` -pub fn lazy_load(data: T, container: C, mut contructor: F, callback: U) +pub(crate) fn lazy_load(data: T, container: C, mut contructor: F, callback: U) where T: IntoIterator + 'static, T::Item: 'static, @@ -88,7 +88,7 @@ where /// If you just want to lazy add `widgets` to a `container` check if /// `lazy_load` fits your needs first. #[cfg_attr(feature = "cargo-clippy", allow(redundant_closure))] -pub fn lazy_load_full(data: T, mut func: F, finish_callback: U) +pub(crate) fn lazy_load_full(data: T, mut func: F, finish_callback: U) where T: IntoIterator + 'static, T::Item: 'static, @@ -110,7 +110,7 @@ where // Kudos to Julian Sparber // https://blogs.gnome.org/jsparber/2018/04/29/animate-a-scrolledwindow/ #[cfg_attr(feature = "cargo-clippy", allow(float_cmp))] -pub fn smooth_scroll_to(view: >k::ScrolledWindow, target: >k::Adjustment) { +pub(crate) fn smooth_scroll_to(view: >k::ScrolledWindow, target: >k::Adjustment) { if let Some(adj) = view.get_vadjustment() { if let Some(clock) = view.get_frame_clock() { let duration = 200; @@ -147,34 +147,34 @@ lazy_static! { static ref IGNORESHOWS: Arc>> = Arc::new(Mutex::new(HashSet::new())); } -pub fn ignore_show(id: i32) -> Result { +pub(crate) fn ignore_show(id: i32) -> Result { IGNORESHOWS .lock() .map(|mut guard| guard.insert(id)) .map_err(|err| format_err!("{}", err)) } -pub fn uningore_show(id: i32) -> Result { +pub(crate) fn uningore_show(id: i32) -> Result { IGNORESHOWS .lock() .map(|mut guard| guard.remove(&id)) .map_err(|err| format_err!("{}", err)) } -pub fn get_ignored_shows() -> Result, Error> { +pub(crate) fn get_ignored_shows() -> Result, Error> { IGNORESHOWS .lock() .map(|guard| guard.iter().cloned().collect::>()) .map_err(|err| format_err!("{}", err)) } -pub fn cleanup(cleanup_date: DateTime) { +pub(crate) fn cleanup(cleanup_date: DateTime) { checkup(cleanup_date) .map_err(|err| error!("Check up failed: {}", err)) .ok(); } -pub fn refresh(source: Option, sender: Sender) +pub(crate) fn refresh(source: Option, sender: Sender) where S: IntoIterator + Send + 'static, { @@ -228,7 +228,11 @@ lazy_static! { // GObjects do not implement Send trait, so SendCell is a way around that. // Also lazy_static requires Sync trait, so that's what the mutexes are. // TODO: maybe use something that would just scale to requested size? -pub fn set_image_from_path(image: >k::Image, show_id: i32, size: u32) -> Result<(), Error> { +pub(crate) fn set_image_from_path( + image: >k::Image, + show_id: i32, + size: u32, +) -> Result<(), Error> { // Check if there's an active download about this show cover. // If there is, a callback will be set so this function will be called again. // If the download succedes, there should be a quick return from the pixbuf cache_image @@ -294,7 +298,7 @@ pub fn set_image_from_path(image: >k::Image, show_id: i32, size: u32) -> Resul } // FIXME: the signature should be `fn foo(s: Url) -> Result` -pub fn itunes_to_rss(url: &str) -> Result { +pub(crate) fn itunes_to_rss(url: &str) -> Result { let id = itunes_id_from_url(url).ok_or_else(|| format_err!("Failed to find an Itunes ID."))?; lookup_id(id) } @@ -319,7 +323,7 @@ fn lookup_id(id: u32) -> Result { .ok_or_else(|| format_err!("Failed to get url from itunes response")) } -pub fn on_import_clicked(window: >k::ApplicationWindow, sender: &Sender) { +pub(crate) fn on_import_clicked(window: >k::ApplicationWindow, sender: &Sender) { use glib::translate::ToGlib; use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType}; diff --git a/podcasts-gtk/src/widgets/aboutdialog.rs b/podcasts-gtk/src/widgets/aboutdialog.rs index 1961c27..c022175 100644 --- a/podcasts-gtk/src/widgets/aboutdialog.rs +++ b/podcasts-gtk/src/widgets/aboutdialog.rs @@ -7,7 +7,7 @@ use i18n::i18n; // Totally copied it from fractal. // https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912 /// Given a `window` create and attach an `gtk::AboutDialog` to it. -pub fn about_dialog(window: >k::ApplicationWindow) { +pub(crate) fn about_dialog(window: >k::ApplicationWindow) { // Feel free to add yourself if you contribured. let authors = &[ "Carlos Soriano", diff --git a/podcasts-gtk/src/widgets/appnotif.rs b/podcasts-gtk/src/widgets/appnotif.rs index a5a1da9..0a365ee 100644 --- a/podcasts-gtk/src/widgets/appnotif.rs +++ b/podcasts-gtk/src/widgets/appnotif.rs @@ -6,13 +6,13 @@ use std::cell::RefCell; use std::rc::Rc; #[derive(Debug, Clone, Copy)] -pub enum UndoState { +pub(crate) enum UndoState { Shown, Hidden, } #[derive(Debug, Clone)] -pub struct InAppNotification { +pub(crate) struct InAppNotification { revealer: gtk::Revealer, text: gtk::Label, undo: gtk::Button, @@ -38,7 +38,12 @@ impl Default for InAppNotification { } impl InAppNotification { - pub fn new(text: &str, mut callback: F, undo_callback: U, show_undo: UndoState) -> Self + pub(crate) fn new( + text: &str, + mut callback: F, + undo_callback: U, + show_undo: UndoState, + ) -> Self where F: FnMut() -> glib::Continue + 'static, U: Fn() + 'static, @@ -85,7 +90,7 @@ impl InAppNotification { // the revealer should be attached to something that displays it. // Previously we where doing it in the constructor, which had the result // of the animation being skipped cause there was no parent widget to display it. - pub fn show(&self, overlay: >k::Overlay) { + pub(crate) fn show(&self, overlay: >k::Overlay) { overlay.add_overlay(&self.revealer); // We need to display the notification after the widget is added to the overlay // so there will be a nice animation. diff --git a/podcasts-gtk/src/widgets/empty.rs b/podcasts-gtk/src/widgets/empty.rs index 9a19e1c..186d875 100644 --- a/podcasts-gtk/src/widgets/empty.rs +++ b/podcasts-gtk/src/widgets/empty.rs @@ -1,8 +1,8 @@ use gtk; #[derive(Debug, Clone)] -pub struct EmptyView { - pub container: gtk::Box, +pub(crate) struct EmptyView { + pub(crate) container: gtk::Box, } impl Default for EmptyView { @@ -15,7 +15,7 @@ impl Default for EmptyView { } impl EmptyView { - pub fn new() -> EmptyView { + pub(crate) fn new() -> EmptyView { EmptyView::default() } } diff --git a/podcasts-gtk/src/widgets/episode.rs b/podcasts-gtk/src/widgets/episode.rs index a1c0577..06f7f44 100644 --- a/podcasts-gtk/src/widgets/episode.rs +++ b/podcasts-gtk/src/widgets/episode.rs @@ -42,8 +42,8 @@ lazy_static! { } #[derive(Clone, Debug)] -pub struct EpisodeWidget { - pub container: gtk::Box, +pub(crate) struct EpisodeWidget { + pub(crate) container: gtk::Box, info: InfoLabels, buttons: Buttons, progressbar: gtk::ProgressBar, @@ -210,7 +210,7 @@ impl Default for EpisodeWidget { } impl EpisodeWidget { - pub fn new(episode: EpisodeWidgetModel, sender: &Sender) -> Rc { + pub(crate) fn new(episode: EpisodeWidgetModel, sender: &Sender) -> Rc { let widget = Rc::new(Self::default()); let episode = RefCell::new(Some(episode)); let weak = Rc::downgrade(&widget); diff --git a/podcasts-gtk/src/widgets/home_view.rs b/podcasts-gtk/src/widgets/home_view.rs index e5106d1..442b016 100644 --- a/podcasts-gtk/src/widgets/home_view.rs +++ b/podcasts-gtk/src/widgets/home_view.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use std::sync::Mutex; lazy_static! { - pub static ref EPISODES_VIEW_VALIGNMENT: Mutex>> = + pub(crate) static ref EPISODES_VIEW_VALIGNMENT: Mutex>> = Mutex::new(None); } @@ -32,8 +32,8 @@ enum ListSplit { } #[derive(Debug, Clone)] -pub struct HomeView { - pub container: gtk::Box, +pub(crate) struct HomeView { + pub(crate) container: gtk::Box, scrolled_window: gtk::ScrolledWindow, frame_parent: gtk::Box, today_box: gtk::Box, @@ -85,7 +85,7 @@ impl Default for HomeView { // TODO: REFACTOR ME impl HomeView { - pub fn new(sender: Sender) -> Result, Error> { + pub(crate) fn new(sender: Sender) -> Result, Error> { use self::ListSplit::*; let view = Rc::new(HomeView::default()); @@ -141,7 +141,7 @@ impl HomeView { } /// Save the vertical scrollbar position. - pub fn save_alignment(&self) -> Result<(), Error> { + pub(crate) fn save_alignment(&self) -> Result<(), Error> { if let Ok(mut guard) = EPISODES_VIEW_VALIGNMENT.lock() { let adj = self .scrolled_window diff --git a/podcasts-gtk/src/widgets/mod.rs b/podcasts-gtk/src/widgets/mod.rs index 1cc8f9c..7ff0246 100644 --- a/podcasts-gtk/src/widgets/mod.rs +++ b/podcasts-gtk/src/widgets/mod.rs @@ -1,17 +1,17 @@ mod aboutdialog; -pub mod appnotif; +pub(crate) mod appnotif; mod empty; mod episode; mod home_view; -pub mod player; +pub(crate) mod player; mod show; -pub mod show_menu; +pub(crate) mod show_menu; mod shows_view; -pub use self::aboutdialog::about_dialog; -pub use self::empty::EmptyView; -pub use self::episode::EpisodeWidget; -pub use self::home_view::HomeView; -pub use self::show::ShowWidget; -pub use self::show_menu::ShowMenu; -pub use self::shows_view::ShowsView; +pub(crate) use self::aboutdialog::about_dialog; +pub(crate) use self::empty::EmptyView; +pub(crate) use self::episode::EpisodeWidget; +pub(crate) use self::home_view::HomeView; +pub(crate) use self::show::ShowWidget; +pub(crate) use self::show_menu::ShowMenu; +pub(crate) use self::shows_view::ShowsView; diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index 8e4b42e..11105b7 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -106,7 +106,7 @@ impl Deref for Position { impl PlayerTimes { /// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`. - pub fn on_duration_changed(&self, duration: Duration) { + pub(crate) fn on_duration_changed(&self, duration: Duration) { let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0); self.slider.block_signal(&self.slider_update); @@ -117,7 +117,7 @@ impl PlayerTimes { } /// Update the `gtk::SclaeBar` when the pipeline position is changed. - pub fn on_position_updated(&self, position: Position) { + pub(crate) fn on_position_updated(&self, position: Position) { let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0); self.slider.block_signal(&self.slider_update); @@ -158,8 +158,8 @@ struct PlayerControls { } #[derive(Debug, Clone)] -pub struct PlayerWidget { - pub action_bar: gtk::ActionBar, +pub(crate) struct PlayerWidget { + pub(crate) action_bar: gtk::ActionBar, player: gst_player::Player, controls: PlayerControls, timer: PlayerTimes, @@ -252,7 +252,7 @@ impl Default for PlayerWidget { } impl PlayerWidget { - pub fn new(sender: &Sender) -> Rc { + pub(crate) fn new(sender: &Sender) -> Rc { let w = Rc::new(Self::default()); Self::init(&w, sender); w @@ -358,7 +358,7 @@ impl PlayerWidget { self.action_bar.show(); } - pub fn initialize_episode(&self, rowid: i32) -> Result<(), Error> { + pub(crate) fn initialize_episode(&self, rowid: i32) -> Result<(), Error> { let ep = dbqueries::get_episode_widget_from_rowid(rowid)?; let pd = dbqueries::get_podcast_cover_from_id(ep.show_id())?; diff --git a/podcasts-gtk/src/widgets/show.rs b/podcasts-gtk/src/widgets/show.rs index 05ef772..542fb94 100644 --- a/podcasts-gtk/src/widgets/show.rs +++ b/podcasts-gtk/src/widgets/show.rs @@ -24,8 +24,8 @@ lazy_static! { } #[derive(Debug, Clone)] -pub struct ShowWidget { - pub container: gtk::Box, +pub(crate) struct ShowWidget { + pub(crate) container: gtk::Box, scrolled_window: gtk::ScrolledWindow, cover: gtk::Image, description: gtk::Label, @@ -55,7 +55,7 @@ impl Default for ShowWidget { } impl ShowWidget { - pub fn new(pd: Arc, sender: Sender) -> Rc { + pub(crate) fn new(pd: Arc, sender: Sender) -> Rc { let mut pdw = ShowWidget::default(); pdw.init(&pd); @@ -69,7 +69,7 @@ impl ShowWidget { pdw } - pub fn init(&mut self, pd: &Arc) { + pub(crate) fn init(&mut self, pd: &Arc) { self.set_description(pd.description()); self.show_id = Some(pd.id()); @@ -89,7 +89,7 @@ impl ShowWidget { } /// Save the scrollabar vajustment to the cache. - pub fn save_vadjustment(&self, oldid: i32) -> Result<(), Error> { + pub(crate) fn save_vadjustment(&self, oldid: i32) -> Result<(), Error> { if let Ok(mut guard) = SHOW_WIDGET_VALIGNMENT.lock() { let adj = self .scrolled_window @@ -130,7 +130,7 @@ impl ShowWidget { Ok(()) } - pub fn show_id(&self) -> Option { + pub(crate) fn show_id(&self) -> Option { self.show_id } } diff --git a/podcasts-gtk/src/widgets/show_menu.rs b/podcasts-gtk/src/widgets/show_menu.rs index 2be4fd5..0b302d3 100644 --- a/podcasts-gtk/src/widgets/show_menu.rs +++ b/podcasts-gtk/src/widgets/show_menu.rs @@ -20,8 +20,8 @@ use std::sync::Arc; use i18n::{i18n, i18n_f}; #[derive(Debug, Clone)] -pub struct ShowMenu { - pub container: gtk::PopoverMenu, +pub(crate) struct ShowMenu { + pub(crate) container: gtk::PopoverMenu, website: gtk::ModelButton, played: gtk::ModelButton, unsub: gtk::ModelButton, @@ -45,7 +45,7 @@ impl Default for ShowMenu { } impl ShowMenu { - pub fn new(pd: &Arc, episodes: >k::ListBox, sender: &Sender) -> Self { + pub(crate) fn new(pd: &Arc, episodes: >k::ListBox, sender: &Sender) -> Self { let s = Self::default(); s.init(pd, episodes, sender); s @@ -129,7 +129,7 @@ fn mark_all_watched(pd: &Show, sender: &Sender) -> Result<(), Error> { Ok(()) } -pub fn mark_all_notif(pd: Arc, sender: &Sender) -> InAppNotification { +pub(crate) fn mark_all_notif(pd: Arc, sender: &Sender) -> InAppNotification { let id = pd.id(); let callback = clone!(sender => move || { let res = mark_all_watched(&pd, &sender); @@ -142,7 +142,7 @@ pub fn mark_all_notif(pd: Arc, sender: &Sender) -> InAppNotificati InAppNotification::new(&text, callback, undo_callback, UndoState::Shown) } -pub fn remove_show_notif(pd: Arc, sender: Sender) -> InAppNotification { +pub(crate) fn remove_show_notif(pd: Arc, sender: Sender) -> InAppNotification { let text = i18n_f("Unsubscribed from {}", &[pd.title()]); let res = utils::ignore_show(pd.id()); diff --git a/podcasts-gtk/src/widgets/shows_view.rs b/podcasts-gtk/src/widgets/shows_view.rs index 8eac935..db8d74e 100644 --- a/podcasts-gtk/src/widgets/shows_view.rs +++ b/podcasts-gtk/src/widgets/shows_view.rs @@ -21,8 +21,8 @@ lazy_static! { } #[derive(Debug, Clone)] -pub struct ShowsView { - pub container: gtk::Box, +pub(crate) struct ShowsView { + pub(crate) container: gtk::Box, scrolled_window: gtk::ScrolledWindow, flowbox: gtk::FlowBox, } @@ -43,7 +43,7 @@ impl Default for ShowsView { } impl ShowsView { - pub fn new(sender: Sender) -> Rc { + pub(crate) fn new(sender: Sender) -> Rc { let pop = Rc::new(ShowsView::default()); pop.init(sender); // Populate the flowbox with the Shows. @@ -52,7 +52,7 @@ impl ShowsView { pop } - pub fn init(&self, sender: Sender) { + pub(crate) fn init(&self, sender: Sender) { self.flowbox.connect_child_activated(move |_, child| { let res = on_child_activate(child, &sender); debug_assert!(res.is_ok()); @@ -80,7 +80,7 @@ impl ShowsView { } /// Save the vertical scrollbar position. - pub fn save_alignment(&self) -> Result<(), Error> { + pub(crate) fn save_alignment(&self) -> Result<(), Error> { if let Ok(mut guard) = SHOWS_VIEW_VALIGNMENT.lock() { let adj = self .scrolled_window @@ -151,7 +151,7 @@ impl Default for ShowsChild { } impl ShowsChild { - pub fn new(pd: &Show) -> ShowsChild { + pub(crate) fn new(pd: &Show) -> ShowsChild { let child = ShowsChild::default(); child.init(pd); child