Fix Rust 2018 edition warnings

This commit is contained in:
Jordan Petridis 2018-08-05 10:12:42 +03:00
parent bcd739da76
commit f6c7731377
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
27 changed files with 159 additions and 150 deletions

View File

@ -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

View File

@ -38,7 +38,7 @@ fn download_into(
dir: &str,
file_title: &str,
url: &str,
progress: Option<Arc<Mutex<DownloadProgress>>>,
progress: Option<Arc<Mutex<dyn DownloadProgress>>>,
) -> Result<String, DownloadError> {
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<u64>,
progress: Option<Arc<Mutex<DownloadProgress>>>,
progress: Option<Arc<Mutex<dyn DownloadProgress>>>,
) -> 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<Arc<Mutex<DownloadProgress>>>,
progress: Option<Arc<Mutex<dyn DownloadProgress>>>,
) -> Result<(), DownloadError> {
// Check if its alrdy downloaded
if ep.local_uri().is_some() {

View File

@ -1,3 +1,5 @@
#![allow(bare_trait_objects)]
use podcasts_data::errors::DataError;
use reqwest;
use std::io;

View File

@ -24,7 +24,7 @@ fn main() {
let globals = format!(
"
pub static LOCALEDIR: &'static str = \"{}\";
pub(crate) static LOCALEDIR: &'static str = \"{}\";
",
localedir
);

View File

@ -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: &gtk::Application) -> Rc<Self> {
pub(crate) fn new(application: &gtk::Application) -> Rc<Self> {
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);

View File

@ -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<Action>) -> Rc<Self> {
pub(crate) fn new(content: &Content, sender: &Sender<Action>) -> Rc<Self> {
let h = Rc::new(Header::default());
Self::init(&h, content, &sender);
h
}
pub fn init(s: &Rc<Self>, content: &Content, sender: &Sender<Action>) {
pub(crate) fn init(s: &Rc<Self>, content: &Content, sender: &Sender<Action>) {
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: &gtk::PopoverMenu) {
pub(crate) fn set_secondary_menu(&self, pop: &gtk::PopoverMenu) {
self.dots.set_popover(Some(pop));
}
}

View File

@ -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)
}

View File

@ -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<RwLock<HashMap<i32, Arc<Mutex<Progress>>>>> =
pub(crate) static ref ACTIVE_DOWNLOADS: Arc<RwLock<HashMap<i32, Arc<Mutex<Progress>>>>> =
{ 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()));

View File

@ -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: &gtk::ApplicationWindow) {
pub(crate) fn show(&self, parent: &gtk::ApplicationWindow) {
self.dialog.set_transient_for(Some(parent));
self.dialog.set_modal(true);
self.dialog.show_all();

View File

@ -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: &gtk::ApplicationWindow) -> WindowGeometry {
pub(crate) fn from_window(window: &gtk::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: &gtk::ApplicationWindow) {
pub(crate) fn apply(&self, window: &gtk::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<Utc> {
pub(crate) fn get_cleanup_date(settings: &Settings) -> DateTime<Utc> {
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> {
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),

View File

@ -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<RefCell<ShowStack>>,
home: Rc<RefCell<HomeStack>>,
@ -21,7 +21,7 @@ pub struct Content {
}
impl Content {
pub fn new(sender: &Sender<Action>) -> Result<Rc<Content>, Error> {
pub(crate) fn new(sender: &Sender<Action>) -> Result<Rc<Content>, 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<RefCell<ShowStack>> {
pub(crate) fn get_shows(&self) -> Rc<RefCell<ShowStack>> {
self.shows.clone()
}
}

View File

@ -19,7 +19,7 @@ enum State {
}
#[derive(Debug, Clone)]
pub struct HomeStack {
pub(crate) struct HomeStack {
empty: EmptyView,
episodes: Rc<HomeView>,
stack: gtk::Stack,
@ -28,7 +28,7 @@ pub struct HomeStack {
}
impl HomeStack {
pub fn new(sender: Sender<Action>) -> Result<HomeStack, Error> {
pub(crate) fn new(sender: Sender<Action>) -> Result<HomeStack, Error> {
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()

View File

@ -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;

View File

@ -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<ShowsView>,
show: Rc<ShowWidget>,
@ -31,7 +31,7 @@ pub struct PopulatedStack {
}
impl PopulatedStack {
pub fn new(sender: Sender<Action>) -> PopulatedStack {
pub(crate) fn new(sender: Sender<Action>) -> 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<Show>) -> Result<(), Error> {
pub(crate) fn replace_widget(&mut self, pd: Arc<Show>) -> 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 {

View File

@ -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<RefCell<PopulatedStack>>,
stack: gtk::Stack,
@ -29,7 +29,7 @@ pub struct ShowStack {
}
impl ShowStack {
pub fn new(sender: Sender<Action>) -> Self {
pub(crate) fn new(sender: Sender<Action>) -> 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<RefCell<PopulatedStack>> {
pub(crate) fn populated(&self) -> Rc<RefCell<PopulatedStack>> {
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()
}

View File

@ -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");

View File

@ -64,7 +64,7 @@ use i18n::i18n;
/// let list = gtk::ListBox::new();
/// lazy_load(widgets, list, |w| w, || {});
/// ```
pub fn lazy_load<T, C, F, W, U>(data: T, container: C, mut contructor: F, callback: U)
pub(crate) fn lazy_load<T, C, F, W, U>(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<T, F, U>(data: T, mut func: F, finish_callback: U)
pub(crate) fn lazy_load_full<T, F, U>(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: &gtk::ScrolledWindow, target: &gtk::Adjustment) {
pub(crate) fn smooth_scroll_to(view: &gtk::ScrolledWindow, target: &gtk::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<Mutex<HashSet<i32>>> = Arc::new(Mutex::new(HashSet::new()));
}
pub fn ignore_show(id: i32) -> Result<bool, Error> {
pub(crate) fn ignore_show(id: i32) -> Result<bool, Error> {
IGNORESHOWS
.lock()
.map(|mut guard| guard.insert(id))
.map_err(|err| format_err!("{}", err))
}
pub fn uningore_show(id: i32) -> Result<bool, Error> {
pub(crate) fn uningore_show(id: i32) -> Result<bool, Error> {
IGNORESHOWS
.lock()
.map(|mut guard| guard.remove(&id))
.map_err(|err| format_err!("{}", err))
}
pub fn get_ignored_shows() -> Result<Vec<i32>, Error> {
pub(crate) fn get_ignored_shows() -> Result<Vec<i32>, Error> {
IGNORESHOWS
.lock()
.map(|guard| guard.iter().cloned().collect::<Vec<_>>())
.map_err(|err| format_err!("{}", err))
}
pub fn cleanup(cleanup_date: DateTime<Utc>) {
pub(crate) fn cleanup(cleanup_date: DateTime<Utc>) {
checkup(cleanup_date)
.map_err(|err| error!("Check up failed: {}", err))
.ok();
}
pub fn refresh<S>(source: Option<S>, sender: Sender<Action>)
pub(crate) fn refresh<S>(source: Option<S>, sender: Sender<Action>)
where
S: IntoIterator<Item = Source> + 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: &gtk::Image, show_id: i32, size: u32) -> Result<(), Error> {
pub(crate) fn set_image_from_path(
image: &gtk::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: &gtk::Image, show_id: i32, size: u32) -> Resul
}
// FIXME: the signature should be `fn foo(s: Url) -> Result<Url, Error>`
pub fn itunes_to_rss(url: &str) -> Result<String, Error> {
pub(crate) fn itunes_to_rss(url: &str) -> Result<String, Error> {
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<String, Error> {
.ok_or_else(|| format_err!("Failed to get url from itunes response"))
}
pub fn on_import_clicked(window: &gtk::ApplicationWindow, sender: &Sender<Action>) {
pub(crate) fn on_import_clicked(window: &gtk::ApplicationWindow, sender: &Sender<Action>) {
use glib::translate::ToGlib;
use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType};

View File

@ -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: &gtk::ApplicationWindow) {
pub(crate) fn about_dialog(window: &gtk::ApplicationWindow) {
// Feel free to add yourself if you contribured.
let authors = &[
"Carlos Soriano",

View File

@ -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<F, U>(text: &str, mut callback: F, undo_callback: U, show_undo: UndoState) -> Self
pub(crate) fn new<F, U>(
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: &gtk::Overlay) {
pub(crate) fn show(&self, overlay: &gtk::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.

View File

@ -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()
}
}

View File

@ -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<Action>) -> Rc<Self> {
pub(crate) fn new(episode: EpisodeWidgetModel, sender: &Sender<Action>) -> Rc<Self> {
let widget = Rc::new(Self::default());
let episode = RefCell::new(Some(episode));
let weak = Rc::downgrade(&widget);

View File

@ -18,7 +18,7 @@ use std::rc::Rc;
use std::sync::Mutex;
lazy_static! {
pub static ref EPISODES_VIEW_VALIGNMENT: Mutex<Option<Fragile<gtk::Adjustment>>> =
pub(crate) static ref EPISODES_VIEW_VALIGNMENT: Mutex<Option<Fragile<gtk::Adjustment>>> =
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<Action>) -> Result<Rc<HomeView>, Error> {
pub(crate) fn new(sender: Sender<Action>) -> Result<Rc<HomeView>, 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

View File

@ -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;

View File

@ -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<Action>) -> Rc<Self> {
pub(crate) fn new(sender: &Sender<Action>) -> Rc<Self> {
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())?;

View File

@ -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<Show>, sender: Sender<Action>) -> Rc<ShowWidget> {
pub(crate) fn new(pd: Arc<Show>, sender: Sender<Action>) -> Rc<ShowWidget> {
let mut pdw = ShowWidget::default();
pdw.init(&pd);
@ -69,7 +69,7 @@ impl ShowWidget {
pdw
}
pub fn init(&mut self, pd: &Arc<Show>) {
pub(crate) fn init(&mut self, pd: &Arc<Show>) {
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<i32> {
pub(crate) fn show_id(&self) -> Option<i32> {
self.show_id
}
}

View File

@ -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<Show>, episodes: &gtk::ListBox, sender: &Sender<Action>) -> Self {
pub(crate) fn new(pd: &Arc<Show>, episodes: &gtk::ListBox, sender: &Sender<Action>) -> Self {
let s = Self::default();
s.init(pd, episodes, sender);
s
@ -129,7 +129,7 @@ fn mark_all_watched(pd: &Show, sender: &Sender<Action>) -> Result<(), Error> {
Ok(())
}
pub fn mark_all_notif(pd: Arc<Show>, sender: &Sender<Action>) -> InAppNotification {
pub(crate) fn mark_all_notif(pd: Arc<Show>, sender: &Sender<Action>) -> 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<Show>, sender: &Sender<Action>) -> InAppNotificati
InAppNotification::new(&text, callback, undo_callback, UndoState::Shown)
}
pub fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppNotification {
pub(crate) fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppNotification {
let text = i18n_f("Unsubscribed from {}", &[pd.title()]);
let res = utils::ignore_show(pd.id());

View File

@ -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<Action>) -> Rc<Self> {
pub(crate) fn new(sender: Sender<Action>) -> Rc<Self> {
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<Action>) {
pub(crate) fn init(&self, sender: Sender<Action>) {
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