Commit 4e7705d9 authored by Felix Häcker's avatar Felix Häcker

Add initial settings backend

parent 8484bf15
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "aho-corasick"
version = "0.7.6"
......@@ -1744,6 +1753,7 @@ dependencies = [
name = "shortwave"
version = "0.0.0"
dependencies = [
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cairo-rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -2260,6 +2270,7 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
"checksum atk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "86b7499272acf036bb5820c6e346bbfb5acc5dceb104bc2c4fd7e6e33dfcde6a"
......
......@@ -41,3 +41,4 @@ indexmap = { git = "https://github.com/bluss/indexmap.git", rev = "380e55c6a330b
gettext-rs= { version = "0.4", features = ["gettext-system"] }
failure = "0.1.5"
failure_derive = "0.1.5"
Inflector = "0.11.4"
......@@ -12,11 +12,7 @@
],
"desktop-file-name-suffix" : " (Devel)",
"finish-args" : [
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--filesystem=xdg-music",
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf",
"--share=network",
"--share=ipc",
"--socket=x11",
......
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema path="/de/haeckerfelix/Shortwave/" id="de.haeckerfelix.Shortwave" gettext-domain="shortwave">
</schema>
<schema path="/de/haeckerfelix/Shortwave/" id="de.haeckerfelix.Shortwave" gettext-domain="shortwave">
<key name="api-server" type="s">
<default>"https://www.radio-browser.info/webservice/"</default>
</key>
<key name="dark-mode" type="b">
<default>false</default>
</key>
</schema>
</schemalist>
......@@ -17,6 +17,7 @@ use crate::database::Library;
use crate::discover::StoreFront;
use crate::ui::{View, Window, Notification};
use crate::utils::{Order, Sorting};
use crate::settings;
#[derive(Debug, Clone)]
pub enum Action {
......@@ -270,7 +271,7 @@ impl App {
self.sender.send(Action::ViewShowNotification(spinner_notification.clone())).unwrap();
// Get actual stations from identifiers
let client = Client::new(Url::parse("http://www.radio-browser.info/webservice/").unwrap());
let client = Client::new(Url::parse(&settings::get_string(settings::Key::ApiServer)).unwrap());
let sender = self.sender.clone();
let fut = client.get_stations_by_identifiers(ids).map(move |stations| {
spinner_notification.hide();
......
......@@ -17,6 +17,7 @@ use crate::audio::{PlaybackState, Song, SongBackend};
use crate::ui::Notification;
use crate::path;
use crate::utils;
use crate::settings;
/////////////////////////////////////////////////////////////////////////////////////////////////
// //
......@@ -113,7 +114,7 @@ impl Player {
let gst_backend = self.gst_backend.clone();
let sender = self.sender.clone();
let client = Client::new(Url::parse("http://www.radio-browser.info/webservice/").unwrap());
let client = Client::new(Url::parse(&settings::get_string(settings::Key::ApiServer)).unwrap());
// get asynchronously the stream url and play it
let fut = client.get_stream_url(station).map(move |station_url| {
match station_url {
......
......@@ -14,6 +14,7 @@ use crate::database::queries;
use crate::database::StationIdentifier;
use crate::ui::{StationFlowBox, Notification};
use crate::utils::{Order, Sorting};
use crate::settings;
pub struct Library {
pub widget: gtk::Box,
......@@ -39,7 +40,7 @@ impl Library {
flowbox.set_sorting(Sorting::Name, Order::Ascending);
content_box.add(&flowbox.widget);
let client = Client::new(Url::parse("http://www.radio-browser.info/webservice/").unwrap());
let client = Client::new(Url::parse(&settings::get_string(settings::Key::ApiServer)).unwrap());
let library = Self {
widget: library,
......
......@@ -9,6 +9,7 @@ use std::rc::Rc;
use crate::api::{Client, StationRequest};
use crate::app::Action;
use crate::ui::{StationFlowBox, Notification};
use crate::settings;
pub struct Search {
pub widget: gtk::Box,
......@@ -26,7 +27,7 @@ impl Search {
let builder = gtk::Builder::new_from_resource("/de/haeckerfelix/Shortwave/gtk/search.ui");
get_widget!(builder, gtk::Box, search);
let client = Client::new(Url::parse("http://www.radio-browser.info/webservice/").unwrap());
let client = Client::new(Url::parse(&settings::get_string(settings::Key::ApiServer)).unwrap());
get_widget!(builder, gtk::Box, results_box);
let flowbox = Rc::new(StationFlowBox::new(sender.clone()));
......
......@@ -24,6 +24,7 @@ mod api;
mod audio;
mod database;
mod discover;
mod settings;
mod ui;
mod app;
......
......@@ -72,6 +72,8 @@ sources = files(
'discover/storefront.rs',
'discover/tile_button.rs',
'settings/mod.rs',
'ui/mod.rs',
'ui/notification.rs',
'ui/song_listbox.rs',
......
use gio::prelude::*;
use inflector::Inflector;
use crate::config;
#[derive(Debug)]
pub enum Key {
ApiServer,
DarkMode,
}
impl Key{
pub fn to_string(&self) -> String{
let string = format!("{:?}", self);
string.to_kebab_case()
}
}
fn get_settings() -> gio::Settings{
let app_id = config::APP_ID.trim_end_matches(".Devel");
gio::Settings::new(app_id)
}
pub fn get_string(key: Key) -> String {
let settings = get_settings();
settings.get_string(&key.to_string()).unwrap().to_string()
}
pub fn set_string(key: Key, value: String) {
let settings = get_settings();
settings.set_string(&key.to_string(), &value);
}
pub fn get_boolean(key: Key) -> bool {
let settings = get_settings();
settings.get_boolean(&key.to_string())
}
pub fn set_boolean(key: Key, value: bool) {
let settings = get_settings();
settings.set_boolean(&key.to_string(), value);
}
pub fn get_integer(key: Key) -> i32 {
let settings = get_settings();
settings.get_int(&key.to_string())
}
pub fn set_integer(key: Key, value: i32) {
let settings = get_settings();
settings.set_int(&key.to_string(), value);
}
......@@ -8,6 +8,7 @@ use std::rc::Rc;
use crate::app::Action;
use crate::config;
use crate::ui::Notification;
use crate::settings;
#[derive(Debug, Clone, PartialEq)]
pub enum View {
......@@ -78,6 +79,10 @@ impl Window {
ctx.add_class("devel");
}
// Dark mode
let gtk_settings = gtk::Settings::get_default().unwrap();
gtk_settings.set_property_gtk_application_prefer_dark_theme(settings::get_boolean(settings::Key::DarkMode));
window.setup_signals();
window
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment