app: add an element notebook for all and favorites

Can now see all elements and favorites from the main window
This commit is contained in:
Stéphane Cerveau 2022-01-19 16:03:19 +01:00
parent 8f83721047
commit 7f4a4b438d
4 changed files with 99 additions and 31 deletions

View file

@ -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::<String>(&iter, 1);
let element_name = model.get::<String>(&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::<String>(&iter, 1);
.get::<String>(&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::<String>(&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::<String>(&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(

View file

@ -271,13 +271,45 @@
<property name="orientation">vertical</property>
<property name="position">400</property>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<object class="GtkNotebook" id="notebook-elements">
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkTreeView" id="treeview-favorites">
<object class="GtkScrolledWindow">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="child">
<object class="GtkTreeView" id="treeview-elements">
</object>
</property>
</object>
</property>
<property name="tab">
<object class="GtkLabel" id="label-page-elements">
<property name="label" translatable="1">Elements</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkScrolledWindow">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="child">
<object class="GtkTreeView" id="treeview-favorites">
</object>
</property>
</object>
</property>
<property name="tab">
<object class="GtkLabel" id="label-page-favorites">
<property name="label" translatable="1">Favorites</property>
</object>
</property>
</object>
</child>
</object>
</child>
<child>

View file

@ -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<String>,
plugin_name: Option<String>,
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<Vec<ElementInfo>> {
let registry = gst::Registry::get();
@ -56,9 +47,8 @@ impl ElementInfo {
if let Ok(factory) = feature.downcast::<gst::ElementFactory>() {
let feature = factory.upcast::<gst::PluginFeature>();
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);
}
}

View file

@ -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