Database: Rename the tables to better match the userfacing strings

This commit is contained in:
Jordan Petridis
2018-06-30 21:47:49 +03:00
parent 79bb9bdde8
commit f3fb27005a
18 changed files with 262 additions and 217 deletions
+4 -6
View File
@@ -93,9 +93,7 @@ impl PopulatedStack {
let old = self.show.container.clone();
// save the ShowWidget vertical scrollabar alignment
self.show
.podcast_id()
.map(|id| self.show.save_vadjustment(id));
self.show.show_id().map(|id| self.show.save_vadjustment(id));
let new = ShowWidget::new(pd, self.sender.clone());
self.show = new;
@@ -113,7 +111,7 @@ impl PopulatedStack {
pub fn update_widget(&mut self) -> Result<(), Error> {
let old = self.show.container.clone();
let id = self.show.podcast_id();
let id = self.show.show_id();
if id.is_none() {
return Ok(());
}
@@ -131,9 +129,9 @@ impl PopulatedStack {
Ok(())
}
// Only update widget if its podcast_id is equal to pid.
// Only update widget if its show_id is equal to pid.
pub fn update_widget_if_same(&mut self, pid: i32) -> Result<(), Error> {
if self.show.podcast_id() != Some(pid) {
if self.show.show_id() != Some(pid) {
debug!("Different widget. Early return");
return Ok(());
}
+8 -8
View File
@@ -226,15 +226,15 @@ 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, podcast_id: i32, size: u32) -> Result<(), Error> {
pub 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
// If it fails another download will be scheduled.
if let Ok(guard) = COVER_DL_REGISTRY.read() {
if guard.contains(&podcast_id) {
if guard.contains(&show_id) {
let callback = clone!(image => move || {
let _ = set_image_from_path(&image, podcast_id, size);
let _ = set_image_from_path(&image, show_id, size);
glib::Continue(false)
});
gtk::timeout_add(250, callback);
@@ -245,7 +245,7 @@ pub fn set_image_from_path(image: &gtk::Image, podcast_id: i32, size: u32) -> Re
if let Ok(hashmap) = CACHED_PIXBUFS.read() {
// Check if the requested (cover + size) is already in the chache
// and if so do an early return after that.
if let Some(guard) = hashmap.get(&(podcast_id, size)) {
if let Some(guard) = hashmap.get(&(show_id, size)) {
guard
.lock()
.map_err(|err| format_err!("SendCell Mutex: {}", err))
@@ -263,11 +263,11 @@ pub fn set_image_from_path(image: &gtk::Image, podcast_id: i32, size: u32) -> Re
let (sender, receiver) = unbounded();
THREADPOOL.spawn(move || {
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
guard.insert(podcast_id);
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(podcast_id) {
guard.insert(show_id);
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) {
sender.send(downloader::cache_image(&pd));
}
guard.remove(&podcast_id);
guard.remove(&show_id);
}
});
@@ -278,7 +278,7 @@ pub fn set_image_from_path(image: &gtk::Image, podcast_id: i32, size: u32) -> Re
if let Ok(path) = path {
if let Ok(px) = Pixbuf::new_from_file_at_scale(&path, s, s, true) {
if let Ok(mut hashmap) = CACHED_PIXBUFS.write() {
hashmap.insert((podcast_id, size), Mutex::new(SendCell::new(px.clone())));
hashmap.insert((show_id, size), Mutex::new(SendCell::new(px.clone())));
image.set_from_pixbuf(&px);
}
}
+1 -1
View File
@@ -429,7 +429,7 @@ impl EpisodeWidget {
}
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: &Sender<Action>) -> Result<(), Error> {
let pd = dbqueries::get_podcast_from_id(ep.podcast_id())?;
let pd = dbqueries::get_podcast_from_id(ep.show_id())?;
let download_fold = get_download_folder(&pd.title())?;
// Start a new download.
+5 -5
View File
@@ -202,7 +202,7 @@ impl HomeEpisode {
gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/episodes_view_widget.ui");
let container: gtk::Box = builder.get_object("container").unwrap();
let image: gtk::Image = builder.get_object("cover").unwrap();
let pid = episode.podcast_id();
let pid = episode.show_id();
let ep = EpisodeWidget::new(episode, sender);
let view = HomeEpisode {
@@ -215,15 +215,15 @@ impl HomeEpisode {
view
}
fn init(&self, podcast_id: i32) {
self.set_cover(podcast_id)
fn init(&self, show_id: i32) {
self.set_cover(show_id)
.map_err(|err| error!("Failed to set a cover: {}", err))
.ok();
self.container.pack_start(&self.episode, true, true, 6);
}
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
utils::set_image_from_path(&self.image, podcast_id, 64)
fn set_cover(&self, show_id: i32) -> Result<(), Error> {
utils::set_image_from_path(&self.image, show_id, 64)
}
}
+1 -1
View File
@@ -357,7 +357,7 @@ impl PlayerWidget {
pub 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.podcast_id())?;
let pd = dbqueries::get_podcast_cover_from_id(ep.show_id())?;
self.info.init(&ep, &pd);
// Currently that will always be the case since the play button is
+5 -5
View File
@@ -36,7 +36,7 @@ pub struct ShowWidget {
settings: gtk::MenuButton,
unsub: gtk::Button,
episodes: gtk::ListBox,
podcast_id: Option<i32>,
show_id: Option<i32>,
}
impl Default for ShowWidget {
@@ -61,7 +61,7 @@ impl Default for ShowWidget {
link,
settings,
episodes,
podcast_id: None,
show_id: None,
}
}
}
@@ -87,7 +87,7 @@ impl ShowWidget {
}));
self.set_description(pd.description());
self.podcast_id = Some(pd.id());
self.show_id = Some(pd.id());
self.set_cover(&pd)
.map_err(|err| error!("Failed to set a cover: {}", err))
@@ -166,8 +166,8 @@ impl ShowWidget {
Ok(())
}
pub fn podcast_id(&self) -> Option<i32> {
self.podcast_id
pub fn show_id(&self) -> Option<i32> {
self.show_id
}
}
+2 -2
View File
@@ -162,7 +162,7 @@ impl ShowsChild {
.ok();
}
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
set_image_from_path(&self.cover, podcast_id, 256)
fn set_cover(&self, show_id: i32) -> Result<(), Error> {
set_image_from_path(&self.cover, show_id, 256)
}
}