Commit 7dd3c07e authored by Felix Häcker's avatar Felix Häcker

wip: use mdl app state, create new window/app_cache/app_state struct. many...

wip: use mdl app state, create new window/app_cache/app_state struct. many things are broken right now.
parent 1862b2c2
......@@ -81,6 +81,15 @@ dependencies = [
"safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bincode"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.9.1"
......@@ -484,10 +493,13 @@ dependencies = [
"gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libhandy 0.1.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mdl 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rusqlite 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustio 0.1.0",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -745,6 +757,26 @@ name = "linked-hash-map"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lmdb"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"lmdb-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lmdb-sys"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.3.9"
......@@ -793,6 +825,18 @@ name = "matches"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mdl"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lmdb 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.0.1"
......@@ -1060,7 +1104,7 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "0.3.8"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1078,10 +1122,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.5.2"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -1167,7 +1211,7 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1202,8 +1246,8 @@ dependencies = [
"gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -1253,27 +1297,17 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.45"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive_internals"
version = "0.23.1"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -1283,7 +1317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -1293,7 +1327,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -1329,11 +1363,11 @@ dependencies = [
[[package]]
name = "syn"
version = "0.13.5"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -1712,6 +1746,7 @@ dependencies = [
"checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9263aa6a38da271eec5c91a83ce1e800f093c8535788d403d626d8d5c3f8f007"
"checksum bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
......@@ -1780,12 +1815,15 @@ dependencies = [
"checksum libhandy-sys 0.1.0 (git+https://gitlab.gnome.org/jsparber/libhandy-sys-rs)" = "<none>"
"checksum libsqlite3-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9eb7b8e152b6a01be6a4a2917248381875758250dc3df5d46caf9250341dda"
"checksum linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7860ec297f7008ff7a1e3382d7f7e1dcd69efc94751a2284bafc3d013c2aa939"
"checksum lmdb 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b0908efb5d6496aa977d96f91413da2635a902e5e31dbef0bfb88986c248539"
"checksum lmdb-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5b392838cfe8858e86fac37cf97a0e8c55cc60ba0a18365cadc33092f128ce9"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d06ff7ff06f729ce5f4e227876cb88d10bc59cd4ae1e09fbb2bde15c850dc21"
"checksum mac-notification-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a3639b6caa2db7443e5df80e12c450982f77fc3c140f53d6e48be91f965ea66"
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
"checksum mdl 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3ff321a65f48cb670e0890d9a04fd28145c4927555ac6336a99925e68de9852"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e00e17be181010a91dbfefb01660b17311059dc8c7f48b9017677721e732bd"
......@@ -1815,10 +1853,10 @@ dependencies = [
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
"checksum pretty_env_logger 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fd5c507cd6729e967cdbd3912bea44f2920e4ffa170f1242706e67a657eeddf0"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6"
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b71f9f575d55555aa9c06188be9d4e2bfc83ed02537948ac0d520c24d0419f1a"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
......@@ -1836,9 +1874,8 @@ dependencies = [
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332"
"checksum security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "5421621e836278a0b139268f36eee0dc7e389b784dc3f79d8f11aabadf41bead"
"checksum serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "6a49d806123bcdaacdefe7aab3721c64ec11d05921bf64d888a857d3a92024a0"
"checksum serde_derive 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "0409f5130e9b06444e07d4c71f55d6a2c4d1290d79faa612d9b0b540a9703fcd"
"checksum serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d30c4596450fd7bbda79ef15559683f9a79ac0193ea819db90000d7e1cae794"
"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
"checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124"
"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1"
"checksum serde_urlencoded 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce0fd303af908732989354c6f02e05e2e6d597152870f2c6990efb0577137480"
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
......@@ -1846,7 +1883,7 @@ dependencies = [
"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d"
"checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aadff791b6c1677eabf79679c6bf8798541dedef6caf0cf9334746799d1df275"
"checksum syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4bad7abdf6633f07c7046b90484f1d9dc055eca39f8c991177b1046ce61dba9a"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5"
......
......@@ -17,6 +17,10 @@ gstreamer = "0.11.1"
dbus = "0.6.1"
dbus-macros = "0.2.3"
libhandy = { git = "https://gitlab.gnome.org/jsparber/libhandy-rs" }
mdl = "1.0.2"
serde_derive = "1.0.70"
serde = "1.0.70"
[dependencies.gtk]
version = "0.4.0"
......
#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Station {
pub name: String,
pub language: String,
......@@ -28,4 +28,4 @@ pub struct Station {
pub clicktrend: String,
}
impl Station{}
\ No newline at end of file
impl Station{}
extern crate glib;
extern crate gtk;
use gtk::prelude::*;
use mdl::cache::Cache;
use mdl::signal::SignalerSync;
use mdl::signal::SigType;
use mdl::Signaler;
use std::sync::Mutex;
use std::sync::MutexGuard;
use std::sync::Arc;
use std::io;
use std::fs;
use std::fs::File;
#[derive(Clone)]
pub struct AppCache {
cache: Arc<Mutex<Cache>>,
pub signaler: SignalerSync,
}
impl AppCache {
pub fn new() -> Self {
let c = Cache::new(&Self::get_database_path().expect("Cannot access database")).expect("Cannot open/create cache");
info!("Loaded database from {}", c.path);
let cache = Arc::new(Mutex::new(c));
let signaler = SignalerSync::new();
// signal loop
let s = signaler.clone();
gtk::timeout_add(50, move || {
gtk::Continue(s.signal_loop_sync())
});
Self { cache, signaler }
}
pub fn get_cache(&self) -> MutexGuard<Cache> {
self.cache.lock().unwrap()
}
pub fn emit_signal(&self, signal: String){
self.signaler.emit(SigType::Update, &signal);
}
fn get_database_path() -> io::Result<String> {
let mut path = glib::get_user_data_dir().unwrap();
debug!("User data dir: {:?}", path);
if !path.exists() {
info!("Create new user data directory...");
fs::create_dir(&path.to_str().unwrap())?;
}
path.push("gradio");
if !path.exists() {
info!("Create new data directory...");
fs::create_dir(&path.to_str().unwrap())?;
}
path.push("gradio.lmdb");
return Ok(path.to_str().unwrap().to_string());
}
}
use rustio::station::Station;
use library::NewLibrary;
use audioplayer::PlaybackState;
use mdl::model::Model;
// The AppState contains all important data that must
// be available in the complete application
#[derive(Serialize, Deserialize, Debug)]
pub struct AppState{
pub library: NewLibrary,
// Audio playback (ap)
pub ap_station: Option<Station>,
pub ap_title: Option<String>,
pub ap_state: PlaybackState,
}
impl Model for AppState {
fn key(&self) -> String { "app".to_string() }
}
impl AppState{
pub fn new() -> Self {
let library = NewLibrary::new();
let ap_station = None;
let ap_title = None;
let ap_state = PlaybackState::Stopped;
AppState{
library,
ap_station,
ap_title,
ap_state,
}
}
}
......@@ -11,119 +11,120 @@ use std::cell::RefCell;
use std::sync::mpsc::{channel, Sender, Receiver};
use rustio::client::Client;
use app_cache::AppCache;
use app_state::AppState;
use mdl::Model;
pub struct AudioPlayer{
app_cache: AppCache,
playbin: Element,
client: Client,
station: Option<Station>,
update_callbacks: Rc<RefCell<Vec<Rc<RefCell<FnMut(Update)>>>>>,
stream: Rc<RefCell<String>>,
}
#[derive(Clone)]
pub enum State{
#[derive(Clone, Serialize, Deserialize, Debug)]
pub enum PlaybackState{
Playing,
Stopped,
Loading,
}
#[derive(Clone)]
pub enum Update{
Playback(State),
Station(Station),
Title(String),
}
impl AudioPlayer{
pub fn new() -> AudioPlayer{
pub fn new(app_cache: AppCache) -> AudioPlayer{
gstreamer::init();
let playbin = ElementFactory::make("playbin", "playbin").unwrap();
let bus = playbin.get_bus().expect("Unable to get playbin bus");
let client = Client::new();
let station = None;
let update_callbacks = Rc::new(RefCell::new(Vec::new()));
let stream = Rc::new(RefCell::new("".to_string()));
Self::new_bus_messages(update_callbacks.clone(), bus);
//Self::new_bus_messages(update_callbacks.clone(), bus);
AudioPlayer{
let player = AudioPlayer{
app_cache,
playbin,
client,
station,
update_callbacks,
}
}
pub fn set_playback(&mut self, play: bool){
if play {
debug!("Start playback...");
self.playbin.set_state(gstreamer::State::Playing);
}else{
debug!("Stop playback...");
self.playbin.set_state(gstreamer::State::Ready);
stream,
};
}
pub fn set_station(&mut self, station: Station){
Self::update(&self.update_callbacks, Update::Station(station.clone()));
Self::update(&self.update_callbacks, Update::Title("".to_string()));
self.station = Some(station.clone());
player.connect_signals();
player
}
self.playbin.set_state(gstreamer::State::Null);
fn connect_signals(&self){
let app_cache = self.app_cache.clone();
let playbin = self.playbin.clone();
thread::spawn(move||{
let station_url = Client::get_playable_station_url(&station);
playbin.set_property("uri", &station_url);
playbin.set_state(gstreamer::State::Playing);
});
}
let stream = self.stream.clone();
self.app_cache.signaler.subscribe("ap", Box::new(move |sig| {
debug!("subscribed signal for ap");
let c = &*app_cache.get_cache();
let app_state = AppState::get(c, "app").unwrap();
pub fn register_update_callback<F: FnMut(Update)+'static>(&mut self, callback: F) {
let cell = Rc::new(RefCell::new(callback));
self.update_callbacks.borrow_mut().push(cell);
}
// Playback
match app_state.ap_state{
PlaybackState::Playing => { playbin.set_state(gstreamer::State::Playing); },
PlaybackState::Stopped => { playbin.set_state(gstreamer::State::Ready); },
PlaybackState::Loading => (),
};
// Station
app_state.ap_station.map(|s| {
if(*stream.borrow() == s.url) { Continue; } // TODO: Test!
*stream.borrow_mut() = s.clone().url;
fn update(update_callbacks: &Rc<RefCell<Vec<Rc<RefCell<FnMut(Update)>>>>>, val: Update) {
for callback in update_callbacks.borrow_mut().iter() {
let mut closure = callback.borrow_mut();
(&mut *closure)(val.clone());
}
//let c = &*app_cache.get_cache();
//AppState::get(c, "app").map(|mut a|{
// a.ap_title = Some("".to_string());
// a.store(c);
//});
//app_cache.emit_signal("ap".to_string());
playbin.set_state(gstreamer::State::Null);
let p = playbin.clone();
thread::spawn(move||{
let station_url = Client::get_playable_station_url(&s);
p.set_property("uri", &station_url);
p.set_state(gstreamer::State::Playing);
});
});
}));
}
fn parse_message(message: &Message) -> Option<Update> {
fn parse_message(message: &Message, app_cache: AppCache){
match message.view(){
MessageView::Tag(tag) => {
let taglist = tag.get_tags();
match taglist.get::<gstreamer::tags::Title>(){
Some(title) => Some(Update::Title(title.get().unwrap().to_string())),
None => None
}
tag.get_tags().get::<gstreamer::tags::Title>().map(|title| {
let c = &*app_cache.get_cache();
AppState::get(c, "app").map(|mut a|{
a.ap_title = Some(title.get().unwrap().to_string());
a.store(c);
});
app_cache.emit_signal("ap".to_string());
});
},
MessageView::StateChanged(sc) => {
info!("State: {:?}", sc.get_current());
info!("PlaybackState: {:?}", sc.get_current());
let c = &*app_cache.get_cache();
let mut app_state = AppState::get(c, "app").unwrap();
match sc.get_current(){
gstreamer::State::Playing => Some(Update::Playback(State::Playing)),
gstreamer::State::Paused => Some(Update::Playback(State::Loading)),
_ => Some(Update::Playback(State::Stopped)),
}
gstreamer::State::Playing => app_state.ap_state = PlaybackState::Playing,
gstreamer::State::Paused => app_state.ap_state = PlaybackState::Loading,
_ => app_state.ap_state = PlaybackState::Stopped,
};
app_state.store(c);
app_cache.emit_signal("ap".to_string());
}
_ => None,
}
_ => (),
};
}
fn new_bus_messages (update_callbacks: Rc<RefCell<Vec<Rc<RefCell<FnMut(Update)>>>>>, bus: gstreamer::Bus){
fn new_bus_messages (app_cache: AppCache, bus: gstreamer::Bus){
gtk::timeout_add(250, move ||{
while(bus.have_pending()){
match bus.pop(){
Some(message) => {
match Self::parse_message(&message){
Some(update) => Self::update(&update_callbacks, update),
None => (),
};
}
None => (),
};
bus.pop().map(|message| Self::parse_message(&message, app_cache.clone()) );
}
Continue(true)
});
......
extern crate gdk;
extern crate gio;
extern crate glib;
extern crate gtk;
use rustio::{client::Client};
use app_state::AppState;
use app_cache::AppCache;
use window::Window;
use audioplayer::AudioPlayer;
use mdl::Model;
use gtk::prelude::*;
use gio::ApplicationExt;
use gio::ApplicationExtManual;
pub struct GradioApp{
app_cache: AppCache,
player: AudioPlayer,
gtk_app: gtk::Application,
window: Window,
}
impl GradioApp{
pub fn new() -> Self {
// Setup cache
let app_cache = AppCache::new();
// Initialize AppState if necessary, and store it in AppCache
let ac = app_cache.clone();
let c = &*ac.get_cache();
match AppState::get(c, "app") {
Ok(a) => debug!("Current application state:\n {:?}", a),
Err(_) => {
info!("Create new app state..");
let app_state = AppState::new();
app_state.store(c);
}
};
let player = AudioPlayer::new(app_cache.clone());
let gtk_app = gtk::Application::new("de.haeckerfelix.gradio", gio::ApplicationFlags::empty()).expect("Failed to initialize GtkApplication");
let window = Window::new(app_cache.clone());
GradioApp {
app_cache,
player,
gtk_app,
window,
}
}
pub fn run(&self) {
self.connect_signals();
self.gtk_app.run(&[]);
}
fn connect_signals(&self) {
let window_clone = self.window.widget.clone();
self.gtk_app.connect_activate(move |app| {
app.add_window(&window_clone);
debug!("gtk application activate");
});
}
}
......@@ -10,6 +10,27 @@ use std::io;
use std::cell::RefCell;
use std::rc::Rc;
use mdl::model::Model;
#[derive(Serialize, Deserialize, Debug)]
pub struct NewLibrary{
pub library: HashMap<u64, u64> // station_id, collection_id
}
impl Model for NewLibrary {
fn key(&self) -> String { "library".to_string() }
}
impl NewLibrary{
pub fn new() -> Self {
let library = HashMap::new();
NewLibrary{ library }
}
}
pub struct Library {
connection: Connection,
client: Client,
......
......@@ -2,6 +2,10 @@
extern crate log;
extern crate pretty_env_logger;
#[macro_use]
extern crate serde_derive;
extern crate gdk;
extern crate gdk_pixbuf;
extern crate gio;
......@@ -13,12 +17,16 @@ extern crate rusqlite;
extern crate rustio;
extern crate url;
extern crate libhandy;
extern crate mdl;
#[macro_use]
extern crate dbus_macros;
extern crate dbus;
mod app;
mod gradio;
mod app_cache;
mod app_state;
mod window;
mod audioplayer;
mod favicon_downloader;
mod library;
......@@ -26,7 +34,7 @@ mod page;
mod widgets;
mod mpris;
use app::GradioApp;
use gradio::GradioApp;
fn main() {
// Init Logger
......@@ -38,7 +46,7 @@ fn main() {
return;
}
// Run App
// Start Gradio itself
let app = GradioApp::new();
app.run();
}
extern crate dbus_macros;
// extern crate dbus_macros;
extern crate dbus;
use dbus::{Connection, BusType, BusName, Path, NameFlag};
// extern crate dbus;
// use dbus::{Connection, BusType, BusName, Path, NameFlag};
use app::AppState;
use std::cell::RefCell;
use std::rc::Rc;
// use app::AppState;
// use std::cell::RefCell;
// use std::rc::Rc;
use rustio::station::Station;
use audioplayer::{Update, State};
use favicon_downloader::FaviconDownloader;
// use rustio::station::Station;
// use audioplayer::{Update, PlaybackState};
// use favicon_downloader::FaviconDownloader;
//
// WIP!
//
dbus_class!("org.mpris.MediaPlayer2", class MprisRoot (variable: i32) {
fn Raise(&this) {}
fn CanRaise(&this) -> bool { true }
// dbus_class!("org.mpris.MediaPlayer2", class MprisRoot (variable: i32) {
// fn Raise(&this) {}
// fn CanRaise(&this) -> bool { true }
fn Quit(&this) {}
fn CanQuit(&this) -> bool { true }
// fn Quit(&this) {}
// fn CanQuit(&this) -> bool { true }
fn Fullscreen(&this) {}
fn CanSetFullscreen(&this) -> bool { false }
// fn Fullscreen(&this) {}
// fn CanSetFullscreen(&this) -> bool { false }
fn HasTrackList(&this) -> bool { false }
fn Identity(&this) -> String { "Gradio" }
fn DesktopEntry(&this) -> String { "de.haeckerfelix.gradio" }
fn SupportedUriSchemes(&this) -> String { "" }