preferences: add a preference dialog

Add a dialog to set user preference such
as gtk4paintablesink usage.
This commit is contained in:
Stéphane Cerveau 2022-02-01 15:58:26 +01:00
parent 247cf2c844
commit c101ea6a37
6 changed files with 115 additions and 2 deletions

View file

@ -271,6 +271,8 @@ impl GPSApp {
application.add_action(&gio::SimpleAction::new("delete", None));
application.set_accels_for_action("app.delete", &["<primary>d", "Delete"]);
application.add_action(&gio::SimpleAction::new("preferences", None));
application.set_accels_for_action("app.preferences", &["<primary>p"]);
application.add_action(&gio::SimpleAction::new("quit", None));
application.set_accels_for_action("app.quit", &["<primary>q"]);
@ -505,6 +507,12 @@ impl GPSApp {
});
});
let app_weak = self.downgrade();
self.connect_app_menu_action("preferences", move |_, _| {
let app = upgrade_weak!(app_weak);
GPSUI::preferences::display_settings(&app);
});
let app_weak = self.downgrade();
self.connect_app_menu_action("delete", move |_, _| {
let app = upgrade_weak!(app_weak);

View file

@ -22,6 +22,7 @@ use crate::graphmanager::{GraphView, Node, NodeType, PortDirection, PropertyExt}
use crate::gps::ElementInfo;
use crate::logger;
use crate::settings;
use crate::GPS_INFO;
use gst::glib;
@ -85,7 +86,6 @@ impl Pipeline {
#[cfg(feature = "gtk4-plugin")]
{
gstgtk4::plugin_register_static().expect("Failed to register gstgtk4 plugin");
ElementInfo::element_update_rank("gtk4paintablesink", gst::Rank::Primary);
}
Ok(pipeline)
@ -98,6 +98,18 @@ impl Pipeline {
pub fn create_pipeline(&self, description: &str) -> anyhow::Result<gst::Pipeline> {
GPS_INFO!("Creating pipeline {}", description);
if settings::Settings::load_settings()
.preferences
.get("use_gtk4_sink")
.unwrap_or(&"true".to_string())
.parse::<bool>()
.expect("Should a boolean value")
{
ElementInfo::element_update_rank("gtk4paintablesink", gst::Rank::Primary);
} else {
ElementInfo::element_update_rank("gtk4paintablesink", gst::Rank::Marginal);
}
// Create pipeline from the description
let pipeline = gst::parse_launch(&description.to_string())?;
let pipeline = pipeline.downcast::<gst::Pipeline>();

View file

@ -10,11 +10,14 @@ use crate::logger;
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Settings {
pub favorites: Vec<String>,
pub app_maximized: bool,
pub app_width: i32,
pub app_height: i32,
// values must be emitted before tables
pub favorites: Vec<String>,
pub paned_positions: HashMap<String, i32>,
pub preferences: HashMap<String, String>,
}
impl Settings {

View file

@ -18,6 +18,11 @@
<attribute name="action">app.save_as</attribute>
<attribute name="accel">&lt;primary&gt;n</attribute>
</item>
<item>
<attribute name="label" translatable="yes" comments="Primary menu entry that open the preferences">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
<attribute name="accel">&lt;primary&gt;p</attribute>
</item>
<item>
<attribute name="label" translatable="yes" comments="Primary menu entry that opens the About dialog.">_About GstPipelineStudio</attribute>
<attribute name="action">app.about</attribute>

View file

@ -20,5 +20,6 @@ pub mod about;
pub mod elements;
pub mod logger;
pub mod message;
pub mod preferences;
pub mod properties;
pub mod treeview;

84
src/ui/preferences.rs Normal file
View file

@ -0,0 +1,84 @@
// preferences.rs
//
// Copyright 2022 Stéphane Cerveau <scerveau@collabora.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: GPL-3.0-only
use crate::app::GPSApp;
use crate::settings;
use gtk::glib;
use gtk::prelude::*;
pub fn display_settings(app: &GPSApp) {
let dialog = gtk::Dialog::with_buttons(
Some("GPS settings"),
Some(&app.window),
gtk::DialogFlags::MODAL,
&[("Close", gtk::ResponseType::Close)],
);
dialog.set_default_size(640, 480);
dialog.set_modal(true);
let grid = gtk::Grid::new();
grid.set_column_spacing(4);
grid.set_row_spacing(4);
grid.set_margin_bottom(12);
let label = gtk::Label::builder()
.label("Use gtk4paintablesink element for video rendering:")
.hexpand(true)
.halign(gtk::Align::Start)
.margin_start(4)
.build();
let widget = gtk::CheckButton::new();
let settings = settings::Settings::load_settings();
widget.set_active(
settings
.preferences
.get("use_gtk4_sink")
.unwrap_or(&"true".to_string())
.parse::<bool>()
.expect("Should a boolean value"),
);
widget.connect_toggled(glib::clone!(@weak widget => move |c| {
let mut settings = settings::Settings::load_settings();
settings.preferences.insert("use_gtk4_sink".to_string(), c.is_active().to_string());
settings::Settings::save_settings(&settings);
}));
grid.attach(&label, 0, 0, 1, 1);
grid.attach(&widget, 1, 0, 1, 1);
let scrolledwindow = gtk::ScrolledWindow::builder()
.hexpand(true)
.vexpand(true)
.build();
scrolledwindow.set_child(Some(&grid));
let content_area = dialog.content_area();
content_area.append(&scrolledwindow);
content_area.set_vexpand(true);
content_area.set_margin_start(10);
content_area.set_margin_end(10);
content_area.set_margin_top(10);
content_area.set_margin_bottom(10);
dialog.connect_response(move |dialog, _| {
dialog.destroy();
});
dialog.show();
}