From 7f4a4b438d380e6d552bef47d363a29197775b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 19 Jan 2022 16:03:19 +0100 Subject: [PATCH] app: add an element notebook for all and favorites Can now see all elements and favorites from the main window --- src/app.rs | 65 ++++++++++++++++++++++++++++++++++++++------ src/gps.ui | 40 ++++++++++++++++++++++++--- src/gps/element.rs | 20 ++++---------- src/plugindialogs.rs | 5 +--- 4 files changed, 99 insertions(+), 31 deletions(-) diff --git a/src/app.rs b/src/app.rs index 90e367a..f111833 100644 --- a/src/app.rs +++ b/src/app.rs @@ -22,9 +22,9 @@ use glib::Value; use gtk::gdk::Rectangle; use gtk::prelude::*; use gtk::{ - gdk::BUTTON_SECONDARY, Application, ApplicationWindow, Builder, Button, CellRendererText, + gdk::BUTTON_SECONDARY, Application, ApplicationWindow, Box, Builder, Button, CellRendererText, FileChooserAction, FileChooserDialog, ListStore, Paned, PopoverMenu, ResponseType, Statusbar, - TreeView, TreeViewColumn, Viewport, Widget, + TextView, TreeView, TreeViewColumn, Viewport, Widget, }; use gtk::{gio, gio::SimpleAction, glib, graphene}; use log::error; @@ -415,19 +415,19 @@ impl GPSApp { } } - fn setup_favorite_list(&self, application: &Application) { + fn setup_favorite_list(&self) { let favorite_list: TreeView = self .builder .object("treeview-favorites") .expect("Couldn't get treeview-favorites"); - self.add_column_to_treeview("treeview-favorites", "Element", 0); + self.add_column_to_treeview("treeview-favorites", "Name", 0); self.reset_favorite_list(&favorite_list); let app_weak = self.downgrade(); favorite_list.connect_row_activated(move |tree_view, _tree_path, _tree_column| { let app = upgrade_weak!(app_weak); let selection = tree_view.selection(); if let Some((model, iter)) = selection.selected() { - let element_name = model.get::(&iter, 1); + let element_name = model.get::(&iter, 0); GPS_DEBUG!("{} selected", element_name); app.add_new_element(&element_name); } @@ -436,13 +436,13 @@ impl GPSApp { gesture.set_button(0); let app_weak = self.downgrade(); gesture.connect_pressed( - glib::clone!(@weak favorite_list, @weak application => move |gesture, _n_press, x, y| { + glib::clone!(@weak favorite_list => move |gesture, _n_press, x, y| { let app = upgrade_weak!(app_weak); if gesture.current_button() == BUTTON_SECONDARY { let selection = favorite_list.selection(); if let Some((model, iter)) = selection.selected() { let element_name = model - .get::(&iter, 1); + .get::(&iter, 0); GPS_DEBUG!("Element {} selected", element_name); let pop_menu = app.app_pop_menu_at_position(&favorite_list, x, y); @@ -487,6 +487,53 @@ impl GPSApp { } } + fn reset_elements_list(&self, elements_list: &TreeView) { + let model = ListStore::new(&[String::static_type()]); + elements_list.set_model(Some(&model)); + let elements = ElementInfo::elements_list().expect("Unable to obtain element's list"); + for element in elements { + model.insert_with_values(None, &[(0, &element.name)]); + } + } + + fn setup_elements_list(&self) { + let tree: TreeView = self + .builder + .object("treeview-elements") + .expect("Couldn't get treeview-elements"); + self.add_column_to_treeview("treeview-elements", "Name", 0); + self.reset_elements_list(&tree); + let app_weak = self.downgrade(); + tree.connect_row_activated(move |tree_view, _tree_path, _tree_column| { + let app = upgrade_weak!(app_weak); + let selection = tree_view.selection(); + if let Some((model, iter)) = selection.selected() { + let element_name = model.get::(&iter, 0); + GPS_DEBUG!("{} selected", element_name); + app.add_new_element(&element_name); + } + }); + let app_weak = self.downgrade(); + tree.connect_cursor_changed(move |tree_view| { + let selection = tree_view.selection(); + if let Some((model, iter)) = selection.selected() { + let element_name = model.get::(&iter, 0); + let description = ElementInfo::element_description(&element_name) + .expect("Unable to get element description from GStreamer"); + let app = upgrade_weak!(app_weak); + let box_property: Box = app + .builder + .object("box-property") + .expect("Couldn't get treeview-elements"); + let text_view = TextView::new(); + let text_buffer = text_view.buffer(); + text_buffer.set_text(""); + text_buffer.insert_markup(&mut text_buffer.end_iter(), &description); + box_property.append(&text_view); + } + }); + } + pub fn display_plugin_list(app: &GPSApp) { let elements = ElementInfo::elements_list().expect("Unable to obtain element's list"); plugindialogs::display_plugin_list(app, &elements); @@ -791,7 +838,9 @@ impl GPSApp { ); // Setup the favorite list - self.setup_favorite_list(application); + self.setup_favorite_list(); + // Setup the favorite list + self.setup_elements_list(); let _ = self .load_graph( diff --git a/src/gps.ui b/src/gps.ui index 8f82885..c2e8fb3 100644 --- a/src/gps.ui +++ b/src/gps.ui @@ -271,13 +271,45 @@ vertical 400 - - True - True + + + - + + True + True + + + + + + + Elements + + + + + + + + + True + True + + + + + + + + + Favorites + + + + diff --git a/src/gps/element.rs b/src/gps/element.rs index ff1abc5..9c6857b 100644 --- a/src/gps/element.rs +++ b/src/gps/element.rs @@ -27,22 +27,13 @@ use gst::prelude::*; use gstreamer as gst; use std::collections::HashMap; -#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] +#[derive(Debug, Default, Eq, Ord, PartialEq, PartialOrd)] pub struct ElementInfo { - pub name: Option, - plugin_name: Option, + pub name: String, + plugin_name: String, rank: i32, } -impl Default for ElementInfo { - fn default() -> ElementInfo { - ElementInfo { - name: None, - plugin_name: None, - rank: -1, - } - } -} impl ElementInfo { pub fn elements_list() -> anyhow::Result> { let registry = gst::Registry::get(); @@ -56,9 +47,8 @@ impl ElementInfo { if let Ok(factory) = feature.downcast::() { let feature = factory.upcast::(); - element.name = Some(gst::PluginFeature::name(&feature).as_str().to_owned()); - element.plugin_name = - Some(gst::Plugin::plugin_name(&plugin).as_str().to_owned()); + element.name = gst::PluginFeature::name(&feature).as_str().to_owned(); + element.plugin_name = gst::Plugin::plugin_name(&plugin).as_str().to_owned(); elements.push(element); } } diff --git a/src/plugindialogs.rs b/src/plugindialogs.rs index 2f33150..074df4d 100644 --- a/src/plugindialogs.rs +++ b/src/plugindialogs.rs @@ -37,10 +37,7 @@ fn create_and_fill_model(elements: &[ElementInfo]) -> ListStore { // Filling up the tree view. for (i, entry) in elements.iter().enumerate() { - model.insert_with_values( - None, - &[(0, &(i as u32 + 1)), (1, &entry.name.as_ref().unwrap())], - ); + model.insert_with_values(None, &[(0, &(i as u32 + 1)), (1, &entry.name)]); } model