mirror of
				https://github.com/Xetibo/ReSet.git
				synced 2025-10-31 08:05:21 +01:00 
			
		
		
		
	Merge pull request #97 from Xetibo/dashie
refactor: SideBar and PluginSideBar
This commit is contained in:
		
						commit
						fd99d902c2
					
				
					 20 changed files with 131 additions and 88 deletions
				
			
		|  | @ -9,9 +9,9 @@ use adw::glib::Object; | |||
| use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt}; | ||||
| use dbus::blocking::Connection; | ||||
| use dbus::Error; | ||||
| use glib::prelude::Cast; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use glib::{clone, Propagation}; | ||||
| use glib::prelude::Cast; | ||||
| use gtk::{gio, StringObject}; | ||||
| use re_set_lib::audio::audio_structures::OutputStream; | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,8 +4,8 @@ use std::{ | |||
| }; | ||||
| 
 | ||||
| use adw::prelude::{ComboRowExt, PreferencesRowExt}; | ||||
| use glib::{subclass::types::ObjectSubclassIsExt, ControlFlow, Propagation}; | ||||
| use glib::prelude::Cast; | ||||
| use glib::{subclass::types::ObjectSubclassIsExt, ControlFlow, Propagation}; | ||||
| use gtk::{ | ||||
|     gio, | ||||
|     prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt}, | ||||
|  |  | |||
|  | @ -9,9 +9,9 @@ use adw::glib::Object; | |||
| use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt}; | ||||
| use dbus::blocking::Connection; | ||||
| use dbus::Error; | ||||
| use glib::prelude::Cast; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use glib::{clone, Propagation}; | ||||
| use glib::prelude::Cast; | ||||
| use gtk::{gio, StringObject}; | ||||
| use re_set_lib::audio::audio_structures::InputStream; | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,8 +7,8 @@ use adw::{ | |||
|     prelude::{ComboRowExt, PreferencesRowExt}, | ||||
|     ComboRow, | ||||
| }; | ||||
| use glib::{subclass::types::ObjectSubclassIsExt, Propagation}; | ||||
| use glib::prelude::Cast; | ||||
| use glib::{subclass::types::ObjectSubclassIsExt, Propagation}; | ||||
| use gtk::{ | ||||
|     gio, | ||||
|     prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt}, | ||||
|  |  | |||
|  | @ -4,9 +4,9 @@ use adw::glib::Object; | |||
| use adw::prelude::{ComboRowExt, PreferencesRowExt}; | ||||
| use dbus::blocking::Connection; | ||||
| use dbus::Error; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use glib::{clone}; | ||||
| use glib::clone; | ||||
| use glib::prelude::Cast; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use gtk::{gio, StringList, StringObject}; | ||||
| 
 | ||||
| use components::utils::create_dropdown_label_factory; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| use crate::components::base::list_entry_impl; | ||||
| use adw::glib::{Object}; | ||||
| use adw::glib::Object; | ||||
| use glib::prelude::IsA; | ||||
| use gtk::prelude::ListBoxRowExt; | ||||
| use gtk::Widget; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| use crate::components::base::setting_box_impl; | ||||
| use adw::glib::{Object}; | ||||
| use adw::glib::Object; | ||||
| use glib::prelude::IsA; | ||||
| use gtk::prelude::BoxExt; | ||||
| use gtk::Widget; | ||||
|  |  | |||
|  | @ -8,9 +8,9 @@ use adw::subclass::prelude::ObjectSubclassIsExt; | |||
| use dbus::blocking::Connection; | ||||
| use dbus::message::SignalArgs; | ||||
| use dbus::{Error, Path}; | ||||
| use glib::{clone, ControlFlow}; | ||||
| use glib::prelude::Cast; | ||||
| use glib::property::PropertySet; | ||||
| use glib::{clone, ControlFlow}; | ||||
| use gtk::glib::Variant; | ||||
| use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt}; | ||||
| use gtk::{gio, StringObject}; | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| pub mod audio; | ||||
| pub mod base; | ||||
| pub mod bluetooth; | ||||
| mod plugin; | ||||
| pub mod utils; | ||||
| pub mod wifi; | ||||
| pub mod window; | ||||
| mod plugin; | ||||
|  |  | |||
|  | @ -3,21 +3,58 @@ use std::rc::Rc; | |||
| use std::sync::Arc; | ||||
| 
 | ||||
| use gtk::FlowBox; | ||||
| use re_set_lib::utils::plugin::SidebarInfo; | ||||
| 
 | ||||
| use crate::components::base::utils::{Listeners, Position}; | ||||
| 
 | ||||
| extern "C" { | ||||
|     pub fn startup() -> SidebarInfo; | ||||
|     pub fn shutdown(); | ||||
|     pub fn run_test(); | ||||
| // extern "C" {
 | ||||
| //     pub fn startup() -> SidebarInfo;
 | ||||
| //     pub fn shutdown();
 | ||||
| //     pub fn run_test();
 | ||||
| // }
 | ||||
| 
 | ||||
| pub type RegularClickEvent = fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>); | ||||
| pub type PluginClickEvent = Rc<dyn Fn(FlowBox, Rc<RefCell<Position>>, Vec<gtk::Box>)>; | ||||
| 
 | ||||
| pub trait TSideBarInfo { | ||||
|     fn name(&self) -> &'static str; | ||||
|     fn icon_name(&self) -> &'static str; | ||||
|     fn parent(&self) -> Option<&'static str>; | ||||
|     fn regular_click_event(&self) -> Option<RegularClickEvent>; | ||||
|     fn plugin_click_event(&self) -> PluginClickEvent; | ||||
|     fn plugin_boxes(&self) -> Option<Vec<gtk::Box>>; | ||||
| } | ||||
| 
 | ||||
| pub struct ReSetSidebarInfo { | ||||
|     pub name: &'static str, | ||||
|     pub icon_name: &'static str, | ||||
|     pub parent: Option<&'static str>, | ||||
|     pub click_event: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>), | ||||
|     pub click_event: RegularClickEvent, | ||||
| } | ||||
| 
 | ||||
| impl TSideBarInfo for ReSetSidebarInfo { | ||||
|     fn name(&self) -> &'static str { | ||||
|         self.name | ||||
|     } | ||||
| 
 | ||||
|     fn icon_name(&self) -> &'static str { | ||||
|         self.icon_name | ||||
|     } | ||||
| 
 | ||||
|     fn parent(&self) -> Option<&'static str> { | ||||
|         self.parent | ||||
|     } | ||||
| 
 | ||||
|     fn regular_click_event(&self) -> Option<RegularClickEvent> { | ||||
|         Some(self.click_event) | ||||
|     } | ||||
| 
 | ||||
|     fn plugin_click_event(&self) -> PluginClickEvent { | ||||
|         Rc::new(|_, _, _| {}) | ||||
|     } | ||||
| 
 | ||||
|     fn plugin_boxes(&self) -> Option<Vec<gtk::Box>> { | ||||
|         None | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[repr(C)] | ||||
|  | @ -25,6 +62,32 @@ pub struct PluginSidebarInfo { | |||
|     pub name: &'static str, | ||||
|     pub icon_name: &'static str, | ||||
|     pub parent: Option<&'static str>, | ||||
|     pub click_event: Rc<dyn Fn(FlowBox, Rc<RefCell<Position>>, Vec<gtk::Box>)>, | ||||
|     pub click_event: PluginClickEvent, | ||||
|     pub plugin_boxes: Vec<gtk::Box>, | ||||
| } | ||||
| 
 | ||||
| impl TSideBarInfo for PluginSidebarInfo { | ||||
|     fn name(&self) -> &'static str { | ||||
|         self.name | ||||
|     } | ||||
| 
 | ||||
|     fn icon_name(&self) -> &'static str { | ||||
|         self.icon_name | ||||
|     } | ||||
| 
 | ||||
|     fn parent(&self) -> Option<&'static str> { | ||||
|         self.parent | ||||
|     } | ||||
| 
 | ||||
|     fn regular_click_event(&self) -> Option<RegularClickEvent> { | ||||
|         None | ||||
|     } | ||||
| 
 | ||||
|     fn plugin_click_event(&self) -> PluginClickEvent { | ||||
|         self.click_event.clone() | ||||
|     } | ||||
| 
 | ||||
|     fn plugin_boxes(&self) -> Option<Vec<gtk::Box>> { | ||||
|         Some(self.plugin_boxes.clone()) | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| use adw::gdk::pango::EllipsizeMode; | ||||
| use adw::prelude::ListModelExtManual; | ||||
| use adw::{ActionRow, ComboRow}; | ||||
| use glib::{Object}; | ||||
| use glib::prelude::Cast; | ||||
| use glib::Object; | ||||
| use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt}; | ||||
| use gtk::{Align, SignalListItemFactory, StringObject}; | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,9 +10,9 @@ use adw::glib::Object; | |||
| use adw::prelude::{ActionRowExt, ButtonExt, PreferencesGroupExt, PreferencesRowExt}; | ||||
| use dbus::blocking::Connection; | ||||
| use dbus::{Error, Path}; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use glib::{clone}; | ||||
| use glib::clone; | ||||
| use glib::property::PropertySet; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use gtk::prelude::{BoxExt, ListBoxRowExt}; | ||||
| use gtk::{gio, Align, Button, Orientation}; | ||||
| 
 | ||||
|  |  | |||
|  | @ -14,9 +14,9 @@ use dbus::blocking::Connection; | |||
| use dbus::message::SignalArgs; | ||||
| use dbus::Error; | ||||
| use dbus::Path; | ||||
| use glib::{clone, ControlFlow}; | ||||
| use glib::prelude::Cast; | ||||
| use glib::property::PropertySet; | ||||
| use glib::{clone, ControlFlow}; | ||||
| use gtk::glib::Variant; | ||||
| use gtk::prelude::ActionableExt; | ||||
| use gtk::{gio, StringList, StringObject}; | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ use std::time::Duration; | |||
| 
 | ||||
| use crate::components::utils::{BASE, DBUS_PATH, WIRELESS}; | ||||
| use crate::components::wifi::utils::get_connection_settings; | ||||
| use adw::glib::{Object}; | ||||
| use adw::glib::Object; | ||||
| use adw::prelude::{ActionRowExt, ButtonExt, EditableExt, PopoverExt, PreferencesRowExt}; | ||||
| use adw::subclass::prelude::ObjectSubclassIsExt; | ||||
| use dbus::blocking::Connection; | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| use std::sync::Arc; | ||||
| 
 | ||||
| use adw::prelude::{ComboRowExt, PreferencesGroupExt, PreferencesRowExt}; | ||||
| use glib::{subclass::types::ObjectSubclassIsExt}; | ||||
| use glib::property::PropertySet; | ||||
| use glib::subclass::types::ObjectSubclassIsExt; | ||||
| use gtk::prelude::WidgetExt; | ||||
| use re_set_lib::{ | ||||
|     network::network_structures::WifiStrength, | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt}; | |||
| use adw::subclass::prelude::ObjectSubclassIsExt; | ||||
| use dbus::arg::PropMap; | ||||
| use dbus::{Error, Path}; | ||||
| use glib::{clone}; | ||||
| use glib::clone; | ||||
| use glib::property::PropertySet; | ||||
| use gtk::prelude::{ActionableExt, ButtonExt, EditableExt, ListBoxRowExt, WidgetExt}; | ||||
| use re_set_lib::network::connection::{ | ||||
|  |  | |||
|  | @ -2,13 +2,16 @@ use std::cell::RefCell; | |||
| use std::rc::Rc; | ||||
| use std::sync::Arc; | ||||
| 
 | ||||
| use adw::BreakpointCondition; | ||||
| use adw::glib::clone; | ||||
| use adw::subclass::prelude::ObjectSubclassIsExt; | ||||
| use adw::BreakpointCondition; | ||||
| use glib::Object; | ||||
| use gtk::{AccessibleRole, Align, Application, FlowBox, FlowBoxChild, Frame, gio, ListBoxRow, Orientation, StateFlags}; | ||||
| use gtk::{DirectionType, prelude::*}; | ||||
| use gtk::gio::ActionEntry; | ||||
| use gtk::{ | ||||
|     gio, AccessibleRole, Align, Application, FlowBox, FlowBoxChild, Frame, ListBoxRow, Orientation, | ||||
|     StateFlags, | ||||
| }; | ||||
| use gtk::{prelude::*, DirectionType}; | ||||
| use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS; | ||||
| 
 | ||||
| use crate::components::base::setting_box::SettingBox; | ||||
|  | @ -157,17 +160,24 @@ impl ReSetWindow { | |||
|                 (plugin.frontend_startup)(); | ||||
| 
 | ||||
|                 let event = Rc::new( | ||||
|                     move |reset_main: FlowBox, position: Rc<RefCell<Position>>, boxes: Vec<gtk::Box>| { | ||||
|                         if handle_init(listeners.clone(), position, Position::Custom(String::from(sidebar_info.name))) { | ||||
|                     move |reset_main: FlowBox, | ||||
|                           position: Rc<RefCell<Position>>, | ||||
|                           boxes: Vec<gtk::Box>| { | ||||
|                         if handle_init( | ||||
|                             listeners.clone(), | ||||
|                             position, | ||||
|                             Position::Custom(String::from(sidebar_info.name)), | ||||
|                         ) { | ||||
|                             return; | ||||
|                         } | ||||
|                         reset_main.remove_all(); | ||||
|                         for plugin_box in &boxes { | ||||
|                             let frame = wrap_in_flow_box_child(SettingBox::new(&plugin_box.clone())); | ||||
|                             let frame = | ||||
|                                 wrap_in_flow_box_child(SettingBox::new(&plugin_box.clone())); | ||||
|                             reset_main.insert(&frame, -1); | ||||
|                         } | ||||
|                         reset_main.set_max_children_per_line(boxes.len() as u32); | ||||
|                     } | ||||
|                     }, | ||||
|                 ); | ||||
| 
 | ||||
|                 plugin_sidebar_list.push(PluginSidebarInfo { | ||||
|  | @ -208,7 +218,7 @@ impl ReSetWindow { | |||
|                 self_imp.reset_sidebar_list.insert(&create_separator(), i); | ||||
|                 i += 1; | ||||
|             } | ||||
|             let entry = SidebarEntry::new_plugin(&info); | ||||
|             let entry = SidebarEntry::new(&info); | ||||
|             self_imp.reset_sidebar_list.insert(&entry, i); | ||||
|             i += 1; | ||||
|         } | ||||
|  |  | |||
|  | @ -1,13 +1,11 @@ | |||
| use std::rc::Rc; | ||||
| 
 | ||||
| use crate::components::plugin::function::{TSideBarInfo}; | ||||
| use crate::components::window::sidebar_entry_impl; | ||||
| use crate::components::window::sidebar_entry_impl::{SidebarAction}; | ||||
| use crate::components::window::sidebar_entry_impl::SidebarAction; | ||||
| use adw::subclass::prelude::ObjectSubclassIsExt; | ||||
| use glib::Object; | ||||
| use gtk::prelude::*; | ||||
| use crate::components::plugin::function::{PluginSidebarInfo, ReSetSidebarInfo}; | ||||
| 
 | ||||
| use super::handle_sidebar_click::HANDLE_HOME; | ||||
| 
 | ||||
| glib::wrapper! { | ||||
|     pub struct SidebarEntry(ObjectSubclass<sidebar_entry_impl::SidebarEntry>) | ||||
|  | @ -16,16 +14,18 @@ glib::wrapper! { | |||
| } | ||||
| 
 | ||||
| impl SidebarEntry { | ||||
|     // TODO: refactor new and new_plugin
 | ||||
|     pub fn new(info: &ReSetSidebarInfo) -> Self { | ||||
|     pub fn new<T: TSideBarInfo>(info: &T) -> Self { | ||||
|         let entry: SidebarEntry = Object::builder().build(); | ||||
|         let entry_imp = entry.imp(); | ||||
|         entry_imp.reset_sidebar_label.get().set_text(info.name); | ||||
|         entry_imp.reset_sidebar_label.get().set_text(info.name()); | ||||
|         entry_imp | ||||
|             .reset_sidebar_image | ||||
|             .set_from_icon_name(Some(info.icon_name)); | ||||
|             .set_from_icon_name(Some(info.icon_name())); | ||||
|         if let Some(boxes) = info.plugin_boxes() { | ||||
|             entry_imp.plugin_boxes.borrow_mut().extend(boxes); | ||||
|         } | ||||
| 
 | ||||
|         match &info.parent { | ||||
|         match &info.parent() { | ||||
|             None => {} | ||||
|             Some(parent) => { | ||||
|                 let mut name = entry_imp.parent.borrow_mut(); | ||||
|  | @ -36,41 +36,11 @@ impl SidebarEntry { | |||
| 
 | ||||
|         { | ||||
|             let mut name = entry_imp.name.borrow_mut(); | ||||
|             *name = info.name.to_string(); | ||||
|             *name = info.name().to_string(); | ||||
|             let mut action = entry_imp.on_click_event.borrow_mut(); | ||||
|             *action = SidebarAction { | ||||
|                 on_click_event: Some(info.click_event), | ||||
|                 on_plugin_click_event: Rc::new(|_,_,_|{}), | ||||
|             }; | ||||
|         } | ||||
|         entry | ||||
|     } | ||||
|     
 | ||||
|     pub fn new_plugin(info: &PluginSidebarInfo) -> Self { | ||||
|         let entry: SidebarEntry = Object::builder().build(); | ||||
|         let entry_imp = entry.imp(); | ||||
|         entry_imp.reset_sidebar_label.get().set_text(info.name); | ||||
|         entry_imp | ||||
|             .reset_sidebar_image | ||||
|             .set_from_icon_name(Some(info.icon_name)); | ||||
|         entry_imp.plugin_boxes.borrow_mut().extend(info.plugin_boxes.clone()); | ||||
|         
 | ||||
|         match &info.parent { | ||||
|             None => {} | ||||
|             Some(parent) => { | ||||
|                 let mut name = entry_imp.parent.borrow_mut(); | ||||
|                 *name = parent.to_string(); | ||||
|                 entry.child().unwrap().set_margin_start(30); | ||||
|             } | ||||
|         } | ||||
|         
 | ||||
|         { | ||||
|             let mut name = entry_imp.name.borrow_mut(); | ||||
|             *name = info.name.to_string(); | ||||
|             let mut action = entry_imp.on_click_event.borrow_mut(); | ||||
|             *action = SidebarAction { | ||||
|                 on_click_event: None, | ||||
|                 on_plugin_click_event: info.click_event.clone(), | ||||
|                 on_click_event: info.regular_click_event(), | ||||
|                 on_plugin_click_event: info.plugin_click_event(), | ||||
|             }; | ||||
|         } | ||||
|         entry | ||||
|  |  | |||
|  | @ -1,20 +1,20 @@ | |||
| use std::cell::{Cell, RefCell}; | ||||
| use std::cell::RefCell; | ||||
| use std::rc::Rc; | ||||
| use std::sync::Arc; | ||||
| 
 | ||||
| use glib::subclass::InitializingObject; | ||||
| use gtk::{CompositeTemplate, FlowBox, Image, Label, ListBoxRow}; | ||||
| use gtk::subclass::prelude::*; | ||||
| use gtk::{CompositeTemplate, Image, Label, ListBoxRow}; | ||||
| 
 | ||||
| use crate::components::base::utils::{Listeners, Position}; | ||||
| use crate::components::plugin::function::{PluginClickEvent, RegularClickEvent}; | ||||
| use crate::components::window::handle_sidebar_click::HANDLE_HOME; | ||||
| use crate::components::window::sidebar_entry; | ||||
| 
 | ||||
| #[derive(Default)] | ||||
| pub enum Categories { | ||||
|     Connectivity, | ||||
|     Audio, | ||||
|     Peripherals, | ||||
|     // TODO: are these ever used ?
 | ||||
|     // Connectivity,
 | ||||
|     // Audio,
 | ||||
|     // Peripherals,
 | ||||
|     #[default] | ||||
|     Misc, | ||||
| } | ||||
|  | @ -33,15 +33,15 @@ pub struct SidebarEntry { | |||
| } | ||||
| 
 | ||||
| pub struct SidebarAction { | ||||
|     pub on_click_event: Option<fn(Arc<Listeners>, FlowBox, Rc<RefCell<Position>>)>, | ||||
|     pub on_plugin_click_event: Rc<dyn Fn(FlowBox, Rc<RefCell<Position>>, Vec<gtk::Box>)>, | ||||
|     pub on_click_event: Option<RegularClickEvent>, | ||||
|     pub on_plugin_click_event: PluginClickEvent, | ||||
| } | ||||
| 
 | ||||
| impl Default for SidebarAction { | ||||
|     fn default() -> Self { | ||||
|         Self { | ||||
|             on_click_event: Some(HANDLE_HOME), | ||||
|             on_plugin_click_event: Rc::new(|_,_,_|{}), | ||||
|             on_plugin_click_event: Rc::new(|_, _, _| {}), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 takotori
						takotori