Removed the multiple declarations of the clone macro.
This commit is contained in:
parent
9787ce7979
commit
72ac709cda
@ -7,24 +7,6 @@ use hammond_data::index_feed::Database;
|
|||||||
use podcasts_view::update_podcasts_view;
|
use podcasts_view::update_podcasts_view;
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
|
||||||
macro_rules! clone {
|
|
||||||
(@param _) => ( _ );
|
|
||||||
(@param $x:ident) => ( $x );
|
|
||||||
($($n:ident),+ => move || $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move || $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move |$(clone!(@param $p),)+| $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_headerbar(db: &Database, stack: >k::Stack) -> gtk::HeaderBar {
|
pub fn get_headerbar(db: &Database, stack: >k::Stack) -> gtk::HeaderBar {
|
||||||
let builder = include_str!("../gtk/headerbar.ui");
|
let builder = include_str!("../gtk/headerbar.ui");
|
||||||
let builder = gtk::Builder::new_from_string(builder);
|
let builder = gtk::Builder::new_from_string(builder);
|
||||||
|
|||||||
@ -21,6 +21,25 @@ use std::sync::{Arc, Mutex};
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gio::{ActionMapExt, ApplicationExt, MenuExt, SimpleActionExt};
|
use gio::{ActionMapExt, ApplicationExt, MenuExt, SimpleActionExt};
|
||||||
|
|
||||||
|
// http://gtk-rs.org/tuto/closures
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! clone {
|
||||||
|
(@param _) => ( _ );
|
||||||
|
(@param $x:ident) => ( $x );
|
||||||
|
($($n:ident),+ => move || $body:expr) => (
|
||||||
|
{
|
||||||
|
$( let $n = $n.clone(); )+
|
||||||
|
move || $body
|
||||||
|
}
|
||||||
|
);
|
||||||
|
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
||||||
|
{
|
||||||
|
$( let $n = $n.clone(); )+
|
||||||
|
move |$(clone!(@param $p),)+| $body
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
mod views;
|
mod views;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
mod headerbar;
|
mod headerbar;
|
||||||
@ -62,18 +81,15 @@ fn build_ui(app: >k::Application) {
|
|||||||
app.add_action(&quit);
|
app.add_action(&quit);
|
||||||
|
|
||||||
// Setup the dbcheckup in the app menu.
|
// Setup the dbcheckup in the app menu.
|
||||||
let db2 = Arc::clone(&db);
|
|
||||||
let check = gio::SimpleAction::new("check", None);
|
let check = gio::SimpleAction::new("check", None);
|
||||||
check.connect_activate(move |_, _| {
|
check.connect_activate(clone!(db => move |_, _| {
|
||||||
let _ = dbcheckup::run(&db2);
|
let _ = dbcheckup::run(&db);
|
||||||
});
|
}));
|
||||||
app.add_action(&check);
|
app.add_action(&check);
|
||||||
|
|
||||||
// Get the headerbar
|
// Get the headerbar
|
||||||
let header = headerbar::get_headerbar(&db, &stack);
|
let header = headerbar::get_headerbar(&db, &stack);
|
||||||
|
|
||||||
// TODO: add delay, cause else there's lock contention for the db obj.
|
|
||||||
// utils::refresh_db(db.clone(), stack.clone());
|
|
||||||
window.set_titlebar(&header);
|
window.set_titlebar(&header);
|
||||||
|
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
|||||||
@ -13,24 +13,6 @@ use std::sync::mpsc::{channel, Receiver};
|
|||||||
|
|
||||||
use views::podcasts_view;
|
use views::podcasts_view;
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
|
||||||
macro_rules! clone {
|
|
||||||
(@param _) => ( _ );
|
|
||||||
(@param $x:ident) => ( $x );
|
|
||||||
($($n:ident),+ => move || $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move || $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move |$(clone!(@param $p),)+| $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a thread local storage that will store the arguments to be transfered.
|
// Create a thread local storage that will store the arguments to be transfered.
|
||||||
thread_local!(
|
thread_local!(
|
||||||
static GLOBAL: RefCell<Option<(Database,
|
static GLOBAL: RefCell<Option<(Database,
|
||||||
@ -68,10 +50,9 @@ pub fn refresh_feed(db: &Database, stack: >k::Stack, source: &mut Source) {
|
|||||||
*global.borrow_mut() = Some((db, stack, receiver));
|
*global.borrow_mut() = Some((db, stack, receiver));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let mut source = source.clone();
|
|
||||||
// TODO: add timeout option and error reporting.
|
// TODO: add timeout option and error reporting.
|
||||||
thread::spawn(clone!(db => move || {
|
thread::spawn(clone!(db, source => move || {
|
||||||
let foo_ = hammond_data::index_feed::refresh_source(&db, &mut source);
|
let foo_ = hammond_data::index_feed::refresh_source(&db, &mut source.clone());
|
||||||
|
|
||||||
if let Ok(x) = foo_ {
|
if let Ok(x) = foo_ {
|
||||||
let Feed(mut req, s) = x;
|
let Feed(mut req, s) = x;
|
||||||
|
|||||||
@ -6,24 +6,6 @@ use hammond_data::index_feed::Database;
|
|||||||
|
|
||||||
use widgets::podcast::*;
|
use widgets::podcast::*;
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
|
||||||
macro_rules! clone {
|
|
||||||
(@param _) => ( _ );
|
|
||||||
(@param $x:ident) => ( $x );
|
|
||||||
($($n:ident),+ => move || $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move || $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move |$(clone!(@param $p),)+| $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_empty_view(stack: >k::Stack) {
|
fn show_empty_view(stack: >k::Stack) {
|
||||||
let builder = include_str!("../../gtk/empty_view.ui");
|
let builder = include_str!("../../gtk/empty_view.ui");
|
||||||
let builder = gtk::Builder::new_from_string(builder);
|
let builder = gtk::Builder::new_from_string(builder);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
use open;
|
use open;
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
use hammond_data::models::Episode;
|
use hammond_data::models::{Episode, Podcast};
|
||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
use hammond_data::index_feed::Database;
|
use hammond_data::index_feed::Database;
|
||||||
use hammond_data::dbcheckup::*;
|
use hammond_data::dbcheckup::*;
|
||||||
@ -19,26 +19,6 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{ContainerExt, TextBufferExt};
|
use gtk::{ContainerExt, TextBufferExt};
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
|
||||||
// FIXME: Atm this macro is copied into every module.
|
|
||||||
// Figure out how to propely define once and export it instead.
|
|
||||||
macro_rules! clone {
|
|
||||||
(@param _) => ( _ );
|
|
||||||
(@param $x:ident) => ( $x );
|
|
||||||
($($n:ident),+ => move || $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move || $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move |$(clone!(@param $p),)+| $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local!(
|
thread_local!(
|
||||||
static GLOBAL: RefCell<Option<((
|
static GLOBAL: RefCell<Option<((
|
||||||
gtk::Button, gtk::Button, gtk::Button, Receiver<bool>,
|
gtk::Button, gtk::Button, gtk::Button, Receiver<bool>,
|
||||||
@ -218,15 +198,14 @@ fn receive() -> glib::Continue {
|
|||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn episodes_listbox(db: &Database, pd_title: &str) -> Result<gtk::ListBox> {
|
pub fn episodes_listbox(db: &Database, pd: &Podcast) -> Result<gtk::ListBox> {
|
||||||
let conn = db.lock().unwrap();
|
let conn = db.lock().unwrap();
|
||||||
let pd = dbqueries::load_podcast_from_title(&conn, pd_title)?;
|
|
||||||
let mut episodes = dbqueries::get_pd_episodes(&conn, &pd)?;
|
let mut episodes = dbqueries::get_pd_episodes(&conn, &pd)?;
|
||||||
drop(conn);
|
drop(conn);
|
||||||
|
|
||||||
let list = gtk::ListBox::new();
|
let list = gtk::ListBox::new();
|
||||||
episodes.iter_mut().for_each(|ep| {
|
episodes.iter_mut().for_each(|ep| {
|
||||||
let w = epidose_widget(db, ep, pd_title);
|
let w = epidose_widget(db, ep, pd.title());
|
||||||
list.add(&w)
|
list.add(&w)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -12,24 +12,6 @@ use hammond_data::dbqueries;
|
|||||||
use widgets::episode::episodes_listbox;
|
use widgets::episode::episodes_listbox;
|
||||||
use podcasts_view::update_podcasts_view;
|
use podcasts_view::update_podcasts_view;
|
||||||
|
|
||||||
// http://gtk-rs.org/tuto/closures
|
|
||||||
macro_rules! clone {
|
|
||||||
(@param _) => ( _ );
|
|
||||||
(@param $x:ident) => ( $x );
|
|
||||||
($($n:ident),+ => move || $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move || $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
|
|
||||||
{
|
|
||||||
$( let $n = $n.clone(); )+
|
|
||||||
move |$(clone!(@param $p),)+| $body
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) -> gtk::Box {
|
fn podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) -> gtk::Box {
|
||||||
// Adapted from gnome-music AlbumWidget
|
// Adapted from gnome-music AlbumWidget
|
||||||
let pd_widget_source = include_str!("../../gtk/podcast_widget.ui");
|
let pd_widget_source = include_str!("../../gtk/podcast_widget.ui");
|
||||||
@ -52,7 +34,7 @@ fn podcast_widget(db: &Database, stack: >k::Stack, pd: &Podcast) -> gtk::Box {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
title_label.set_text(pd.title());
|
title_label.set_text(pd.title());
|
||||||
let listbox = episodes_listbox(db, pd.title());
|
let listbox = episodes_listbox(db, &pd);
|
||||||
if let Ok(l) = listbox {
|
if let Ok(l) = listbox {
|
||||||
view.add(&l);
|
view.add(&l);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user