| 1 |
// Fragments - settings_manager.rs |
| 2 |
// Copyright (C) 2022 Felix Häcker <[email protected]> |
| 3 |
// |
| 4 |
// This program is free software: you can redistribute it and/or modify |
| 5 |
// it under the terms of the GNU General Public License as published by |
| 6 |
// the Free Software Foundation, either version 3 of the License, or |
| 7 |
// (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU General Public License |
| 15 |
// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
use gtk::gio::prelude::*; |
| 18 |
use gtk::{gio, glib}; |
| 19 |
|
| 20 |
use crate::config; |
| 21 |
use crate::settings::Key; |
| 22 |
|
| 23 |
pub fn settings() -> gio::Settings { |
| 24 |
gio::Settings::new(config::APP_ID) |
| 25 |
} |
| 26 |
|
| 27 |
pub fn bind_property<P: IsA<glib::Object>>(key: Key, object: &P, property: &str) { |
| 28 |
let settings = settings(); |
| 29 |
settings |
| 30 |
.bind(&key.to_string(), object, property) |
| 31 |
.flags(gio::SettingsBindFlags::DEFAULT) |
| 32 |
.build(); |
| 33 |
} |
| 34 |
|
| 35 |
#[allow(dead_code)] |
| 36 |
pub fn string(key: Key) -> String { |
| 37 |
let settings = settings(); |
| 38 |
settings.string(&key.to_string()).to_string() |
| 39 |
} |
| 40 |
|
| 41 |
#[allow(dead_code)] |
| 42 |
pub fn set_string(key: Key, value: String) { |
| 43 |
let settings = settings(); |
| 44 |
settings.set_string(&key.to_string(), &value).unwrap(); |
| 45 |
} |
| 46 |
|
| 47 |
#[allow(dead_code)] |
| 48 |
pub fn boolean(key: Key) -> bool { |
| 49 |
let settings = settings(); |
| 50 |
settings.boolean(&key.to_string()) |
| 51 |
} |
| 52 |
|
| 53 |
#[allow(dead_code)] |
| 54 |
pub fn set_boolean(key: Key, value: bool) { |
| 55 |
let settings = settings(); |
| 56 |
settings.set_boolean(&key.to_string(), value).unwrap(); |
| 57 |
} |
| 58 |
|
| 59 |
#[allow(dead_code)] |
| 60 |
pub fn integer(key: Key) -> i32 { |
| 61 |
let settings = settings(); |
| 62 |
settings.int(&key.to_string()) |
| 63 |
} |
| 64 |
|
| 65 |
#[allow(dead_code)] |
| 66 |
pub fn set_integer(key: Key, value: i32) { |
| 67 |
let settings = settings(); |
| 68 |
settings.set_int(&key.to_string(), value).unwrap(); |
| 69 |
} |
| 70 |
|
| 71 |
#[allow(dead_code)] |
| 72 |
pub fn double(key: Key) -> f64 { |
| 73 |
let settings = settings(); |
| 74 |
settings.double(&key.to_string()) |
| 75 |
} |
| 76 |
|
| 77 |
#[allow(dead_code)] |
| 78 |
pub fn set_double(key: Key, value: f64) { |
| 79 |
let settings = settings(); |
| 80 |
settings.set_double(&key.to_string(), value).unwrap(); |
| 81 |
} |