mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-19 11:08:32 +02:00
Merge remote-tracking branch 'origin/ina' into ina
This commit is contained in:
commit
9507b8a23a
15
src/main.rs
15
src/main.rs
|
@ -1,10 +1,10 @@
|
||||||
mod window;
|
|
||||||
mod audio;
|
mod audio;
|
||||||
mod wifi;
|
|
||||||
mod bluetooth;
|
mod bluetooth;
|
||||||
|
mod wifi;
|
||||||
|
mod window;
|
||||||
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Application, gio};
|
use gtk::{gio, Application};
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
const APP_ID: &str = "org.Xetibo.ReSet";
|
const APP_ID: &str = "org.Xetibo.ReSet";
|
||||||
|
@ -13,9 +13,11 @@ fn main() {
|
||||||
gio::resources_register_include!("src.templates.gresource")
|
gio::resources_register_include!("src.templates.gresource")
|
||||||
.expect("Failed to register resources.");
|
.expect("Failed to register resources.");
|
||||||
|
|
||||||
let app = Application::builder()
|
let app = Application::builder().application_id(APP_ID).build();
|
||||||
.application_id(APP_ID)
|
|
||||||
.build();
|
app.connect_startup(move |_| {
|
||||||
|
adw::init().unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
app.connect_activate(buildUI);
|
app.connect_activate(buildUI);
|
||||||
app.run();
|
app.run();
|
||||||
|
@ -26,3 +28,4 @@ fn buildUI(app: &Application) {
|
||||||
let window = Window::new(app);
|
let window = Window::new(app);
|
||||||
window.present();
|
window.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use adw::BreakpointCondition;
|
|
||||||
use adw::glib::clone;
|
use adw::glib::clone;
|
||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||||
|
use adw::BreakpointCondition;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{Application, FlowBox, gio, glib};
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
use gtk::{gio, glib, Application, FlowBox};
|
||||||
|
|
||||||
use crate::window::handleSidebarClick::{HANDLE_AUDIO_CLICK, HANDLE_BLUETOOTH_CLICK, HANDLE_CONNECTIVITY_CLICK, HANDLE_MICROPHONE_CLICK, HANDLE_VOLUME_CLICK, HANDLE_VPN_CLICK, HANDLE_WIFI_CLICK};
|
use crate::window::handleSidebarClick::{
|
||||||
|
HANDLE_AUDIO_CLICK, HANDLE_BLUETOOTH_CLICK, HANDLE_CONNECTIVITY_CLICK, HANDLE_MICROPHONE_CLICK,
|
||||||
|
HANDLE_VOLUME_CLICK, HANDLE_VPN_CLICK, HANDLE_WIFI_CLICK,
|
||||||
|
};
|
||||||
use crate::window::sidebarEntry::{Categories, SidebarAction};
|
use crate::window::sidebarEntry::{Categories, SidebarAction};
|
||||||
|
|
||||||
mod window;
|
|
||||||
mod sidebarEntry;
|
|
||||||
mod handleSidebarClick;
|
mod handleSidebarClick;
|
||||||
|
mod sidebarEntry;
|
||||||
|
mod window;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct Window(ObjectSubclass<window::Window>)
|
pub struct Window(ObjectSubclass<window::Window>)
|
||||||
|
@ -36,30 +39,48 @@ impl Window {
|
||||||
fn setupCallback(&self) {
|
fn setupCallback(&self) {
|
||||||
let selfImp = self.imp();
|
let selfImp = self.imp();
|
||||||
|
|
||||||
selfImp.resetSearchEntry.connect_search_changed(clone!(@ weak self as window => move |_| {
|
selfImp
|
||||||
|
.resetSearchEntry
|
||||||
|
.connect_search_changed(clone!(@ weak self as window => move |_| {
|
||||||
window.filterList();
|
window.filterList();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
selfImp.resetSideBarToggle.connect_clicked(clone!(@ weak self as window => move |_| {
|
selfImp
|
||||||
|
.resetSideBarToggle
|
||||||
|
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||||
window.toggleSidebar();
|
window.toggleSidebar();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
selfImp.resetSidebarList.connect_row_activated(clone!(@ weak selfImp as flowbox => move |x, y| {
|
selfImp.resetSidebarList.connect_row_activated(
|
||||||
|
clone!(@ weak selfImp as flowbox => move |_, y| {
|
||||||
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
||||||
let clickEvent = result.imp().onClickEvent.borrow().onClickEvent;
|
let clickEvent = result.imp().onClickEvent.borrow().onClickEvent;
|
||||||
(clickEvent)(flowbox.resetMain.get());
|
(clickEvent)(flowbox.resetMain.get());
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
selfImp
|
||||||
|
.resetClose
|
||||||
|
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||||
|
window.close();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleDynamicSidebar(&self) {
|
fn handleDynamicSidebar(&self) {
|
||||||
let selfImp = self.imp();
|
let selfImp = self.imp();
|
||||||
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 500sp").as_ref().ok());
|
selfImp
|
||||||
selfImp.resetSidebarBreakpoint.add_setter(&Object::from(selfImp.resetOverlaySplitView.get()),
|
.resetSidebarBreakpoint
|
||||||
|
.set_condition(BreakpointCondition::parse("max-width: 500sp").as_ref().ok());
|
||||||
|
selfImp.resetSidebarBreakpoint.add_setter(
|
||||||
|
&Object::from(selfImp.resetOverlaySplitView.get()),
|
||||||
"collapsed",
|
"collapsed",
|
||||||
&true.to_value());
|
&true.to_value(),
|
||||||
selfImp.resetSidebarBreakpoint.add_setter(&Object::from(selfImp.resetSideBarToggle.get()),
|
);
|
||||||
|
selfImp.resetSidebarBreakpoint.add_setter(
|
||||||
|
&Object::from(selfImp.resetSideBarToggle.get()),
|
||||||
"visible",
|
"visible",
|
||||||
&true.to_value());
|
&true.to_value(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filterList(&self) {
|
fn filterList(&self) {
|
||||||
|
@ -72,13 +93,25 @@ impl Window {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if mainEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
if mainEntry
|
||||||
|
.imp()
|
||||||
|
.name
|
||||||
|
.borrow()
|
||||||
|
.to_lowercase()
|
||||||
|
.contains(&text.to_lowercase())
|
||||||
|
{
|
||||||
mainEntry.set_visible(true);
|
mainEntry.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
mainEntry.set_visible(false);
|
mainEntry.set_visible(false);
|
||||||
}
|
}
|
||||||
for subEntry in subEntries {
|
for subEntry in subEntries {
|
||||||
if subEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
if subEntry
|
||||||
|
.imp()
|
||||||
|
.name
|
||||||
|
.borrow()
|
||||||
|
.to_lowercase()
|
||||||
|
.contains(&text.to_lowercase())
|
||||||
|
{
|
||||||
subEntry.set_visible(true);
|
subEntry.set_visible(true);
|
||||||
mainEntry.set_visible(true);
|
mainEntry.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,45 +133,68 @@ impl Window {
|
||||||
let selfImp = self.imp();
|
let selfImp = self.imp();
|
||||||
let mut sidebarEntries = selfImp.sidebarEntries.borrow_mut();
|
let mut sidebarEntries = selfImp.sidebarEntries.borrow_mut();
|
||||||
|
|
||||||
let connectivityList = vec![SidebarEntry::new("WiFi",
|
let connectivityList = vec![
|
||||||
|
SidebarEntry::new(
|
||||||
|
"WiFi",
|
||||||
"network-wireless-symbolic",
|
"network-wireless-symbolic",
|
||||||
Categories::Connectivity,
|
Categories::Connectivity,
|
||||||
true,
|
true,
|
||||||
HANDLE_WIFI_CLICK),
|
HANDLE_WIFI_CLICK,
|
||||||
SidebarEntry::new("Bluetooth",
|
),
|
||||||
|
SidebarEntry::new(
|
||||||
|
"Bluetooth",
|
||||||
"bluetooth-symbolic",
|
"bluetooth-symbolic",
|
||||||
Categories::Connectivity,
|
Categories::Connectivity,
|
||||||
true,
|
true,
|
||||||
HANDLE_BLUETOOTH_CLICK),
|
HANDLE_BLUETOOTH_CLICK,
|
||||||
SidebarEntry::new("VPN",
|
),
|
||||||
|
SidebarEntry::new(
|
||||||
|
"VPN",
|
||||||
"network-vpn-symbolic",
|
"network-vpn-symbolic",
|
||||||
Categories::Connectivity,
|
Categories::Connectivity,
|
||||||
true,
|
true,
|
||||||
HANDLE_VPN_CLICK)];
|
HANDLE_VPN_CLICK,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
sidebarEntries.push((SidebarEntry::new("Connectivity",
|
sidebarEntries.push((
|
||||||
|
SidebarEntry::new(
|
||||||
|
"Connectivity",
|
||||||
"network-wired-symbolic",
|
"network-wired-symbolic",
|
||||||
Categories::Connectivity,
|
Categories::Connectivity,
|
||||||
false,
|
false,
|
||||||
HANDLE_CONNECTIVITY_CLICK), connectivityList));
|
HANDLE_CONNECTIVITY_CLICK,
|
||||||
|
),
|
||||||
|
connectivityList,
|
||||||
|
));
|
||||||
|
|
||||||
let audioList = vec![SidebarEntry::new("Volume",
|
let audioList = vec![
|
||||||
|
SidebarEntry::new(
|
||||||
|
"Volume",
|
||||||
"audio-volume-high-symbolic",
|
"audio-volume-high-symbolic",
|
||||||
Categories::Audio,
|
Categories::Audio,
|
||||||
true,
|
true,
|
||||||
HANDLE_VOLUME_CLICK),
|
HANDLE_VOLUME_CLICK,
|
||||||
SidebarEntry::new("Microphone",
|
),
|
||||||
|
SidebarEntry::new(
|
||||||
|
"Microphone",
|
||||||
"audio-input-microphone-symbolic",
|
"audio-input-microphone-symbolic",
|
||||||
Categories::Audio,
|
Categories::Audio,
|
||||||
true,
|
true,
|
||||||
HANDLE_MICROPHONE_CLICK)];
|
HANDLE_MICROPHONE_CLICK,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
sidebarEntries.push((SidebarEntry::new("Audio",
|
sidebarEntries.push((
|
||||||
|
SidebarEntry::new(
|
||||||
|
"Audio",
|
||||||
"audio-headset-symbolic",
|
"audio-headset-symbolic",
|
||||||
Categories::Audio,
|
Categories::Audio,
|
||||||
false,
|
false,
|
||||||
HANDLE_AUDIO_CLICK), audioList));
|
HANDLE_AUDIO_CLICK,
|
||||||
|
),
|
||||||
|
audioList,
|
||||||
|
));
|
||||||
|
|
||||||
for (mainEntry, subEntries) in sidebarEntries.iter() {
|
for (mainEntry, subEntries) in sidebarEntries.iter() {
|
||||||
selfImp.resetSidebarList.append(mainEntry);
|
selfImp.resetSidebarList.append(mainEntry);
|
||||||
|
@ -150,18 +206,28 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SidebarEntry {
|
impl SidebarEntry {
|
||||||
pub fn new(entryName: &str, iconName: &str, category: Categories, isSubcategory: bool, clickEvent: fn(FlowBox)) -> Self {
|
pub fn new(
|
||||||
|
entryName: &str,
|
||||||
|
iconName: &str,
|
||||||
|
category: Categories,
|
||||||
|
isSubcategory: bool,
|
||||||
|
clickEvent: fn(FlowBox),
|
||||||
|
) -> Self {
|
||||||
let entry: SidebarEntry = Object::builder().build();
|
let entry: SidebarEntry = Object::builder().build();
|
||||||
let entryImp = entry.imp();
|
let entryImp = entry.imp();
|
||||||
entryImp.resetSidebarLabel.get().set_text(entryName);
|
entryImp.resetSidebarLabel.get().set_text(entryName);
|
||||||
entryImp.resetSidebarImage.set_from_icon_name(Some(iconName));
|
entryImp
|
||||||
|
.resetSidebarImage
|
||||||
|
.set_from_icon_name(Some(iconName));
|
||||||
entryImp.category.set(category);
|
entryImp.category.set(category);
|
||||||
entryImp.isSubcategory.set(isSubcategory);
|
entryImp.isSubcategory.set(isSubcategory);
|
||||||
{
|
{
|
||||||
let mut name = entryImp.name.borrow_mut();
|
let mut name = entryImp.name.borrow_mut();
|
||||||
*name = String::from(entryName);
|
*name = String::from(entryName);
|
||||||
let mut action = entryImp.onClickEvent.borrow_mut();
|
let mut action = entryImp.onClickEvent.borrow_mut();
|
||||||
*action = SidebarAction { onClickEvent: clickEvent };
|
*action = SidebarAction {
|
||||||
|
onClickEvent: clickEvent,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Self::setMargin(&entry);
|
Self::setMargin(&entry);
|
||||||
entry
|
entry
|
||||||
|
@ -174,3 +240,4 @@ impl SidebarEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use adw::{Breakpoint, OverlaySplitView};
|
|
||||||
use adw::glib::StaticTypeExt;
|
use adw::glib::StaticTypeExt;
|
||||||
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
||||||
|
use adw::{Breakpoint, OverlaySplitView};
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
use gtk::{Button, CompositeTemplate, FlowBox, glib, ListBox, SearchEntry, Box};
|
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
|
use gtk::{glib, Box, Button, CompositeTemplate, FlowBox, ListBox, SearchEntry};
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use crate::wifi::WifiBox;
|
use crate::wifi::WifiBox;
|
||||||
use crate::window::SidebarEntry;
|
use crate::window::SidebarEntry;
|
||||||
|
@ -27,6 +27,8 @@ pub struct Window {
|
||||||
pub resetSideBarToggle: TemplateChild<Button>,
|
pub resetSideBarToggle: TemplateChild<Button>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub resetPath: TemplateChild<Box>,
|
pub resetPath: TemplateChild<Box>,
|
||||||
|
#[template_child]
|
||||||
|
pub resetClose: TemplateChild<Button>,
|
||||||
pub sidebarEntries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
pub sidebarEntries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,5 +66,3 @@ impl WindowImpl for Window {}
|
||||||
impl ApplicationWindowImpl for Window {}
|
impl ApplicationWindowImpl for Window {}
|
||||||
|
|
||||||
impl AdwApplicationWindowImpl for Window {}
|
impl AdwApplicationWindowImpl for Window {}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue