add sidebarentry

fix github workflows
This commit is contained in:
tranfelix 2023-10-22 16:42:10 +02:00
parent 4c2d5a4105
commit d6daf2ae19
12 changed files with 170 additions and 26 deletions

View file

@ -12,8 +12,6 @@ jobs:
with:
profile: minimal
toolchain: nightly
- name: Install gtk
run: sudo apt install libgtk-4-dev libadwaita-1-dev -y
- name: Build
run: cargo build --release --verbose
- name: Release

View file

@ -20,13 +20,6 @@ jobs:
with:
profile: minimal
toolchain: nightly
- name: Install gtk
run: sudo apt install libgtk-4-dev libadwaita-1-dev -y
- name: Cache
uses: actions/cache@v3
with:
path: target/debug
key: ${{ runner.os }}-cache
- name: run code coverage
uses: actions-rs/tarpaulin@v0.1
with:
@ -37,7 +30,6 @@ jobs:
with:
name: code-coverage-report
path: cobertura.xml
- name: Build
run: cargo build --verbose
- name: Run tests

View file

@ -7,7 +7,7 @@ description = "A wip universal Linux settings application."
[dependencies]
ReSet-Lib = "*"
adw = { version = "*", package = "libadwaita", features = ["v1_4"]}
gtk = { version = "*", package = "gtk4"}
gtk = { version = "*", package = "gtk4", features = ["v4_12"]}
[build-dependencies]
glib-build-tools = "*"

View file

@ -99,6 +99,9 @@
</child>
</object>
</child>
<child>
<object class="GtkGestureClick"/>
</child>
</object>
</child>
<child>

View file

@ -0,0 +1,22 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.17.0 -->
<interface>
<requires lib="gtk" version="4.0"/>
<template class="resetSidebarEntry" parent="GtkListBoxRow">
<child>
<object class="GtkBox">
<property name="margin-bottom">10</property>
<property name="margin-start">10</property>
<property name="margin-top">10</property>
<child>
<object class="GtkImage" id="resetSidebarImage">
<property name="margin-end">10</property>
</object>
</child>
<child>
<object class="GtkLabel" id="resetSidebarLabel"/>
</child>
</object>
</child>
</template>
</interface>

View file

@ -4,7 +4,8 @@
<ui>
(3,1,None,"resetMainWindow",None,None,None,None,None,None,None),
(4,7,None,"resetWiFi",None,None,None,None,None,None,None),
(5,1,None,"resetWifiEntry",None,None,None,None,None,None,None)
(5,1,None,"resetWifiEntry",None,None,None,None,None,None,None),
(6,1,None,"resetSidebarEntry",None,None,None,None,None,None,None)
</ui>
<object>
(3,1,"AdwApplicationWindow","resetUI",None,None,None,None,-1," &lt;child&gt;\n &lt;object id=\"resetSidebarBreakpoint\" class=\"AdwBreakpoint\"&gt;\n &lt;/object&gt;\n &lt;/child&gt;"),
@ -67,7 +68,11 @@
(5,2,"GtkBox",None,1,None,None,None,None,None),
(5,3,"GtkImage","resetWifiStrength",2,None,None,None,None,None),
(5,4,"GtkLabel","resetWifiLabel",2,None,None,None,1,None),
(5,5,"GtkButton","resetWifiButton",2,None,None,None,2,None)
(5,5,"GtkButton","resetWifiButton",2,None,None,None,2,None),
(6,1,"GtkListBoxRow","resetSidebarEntry",None,None,None,None,None,None),
(6,2,"GtkBox",None,1,None,None,None,None,None),
(6,3,"GtkImage","resetSidebarImage",2,None,None,None,None,None),
(6,4,"GtkLabel","resetSidebarLabel",2,None,None,None,1,None)
</object>
<object_property>
(3,2,"AdwOverlaySplitView","content",None,None,None,None,None,3,None,None,None,None),
@ -166,7 +171,11 @@
(5,4,"GtkWidget","width-request","200",None,None,None,None,None,None,None,None,None),
(5,5,"GtkButton","icon-name","emblem-system-symbolic",None,None,None,None,None,None,None,None,None),
(5,5,"GtkWidget","halign","start",None,None,None,None,None,None,None,None,None),
(5,5,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None)
(5,5,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None),
(6,2,"GtkWidget","margin-bottom","10",None,None,None,None,None,None,None,None,None),
(6,2,"GtkWidget","margin-start","10",None,None,None,None,None,None,None,None,None),
(6,2,"GtkWidget","margin-top","10",None,None,None,None,None,None,None,None,None),
(6,3,"GtkWidget","margin-end","10",None,None,None,None,None,None,None,None,None)
</object_property>
<object_data>
(3,15,"GtkWidget",2,2,None,1,None,None,None,None),

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/xetibo/reset/">
<file compressed="true" preprocess="xml-stripblanks">resetSidebarEntry.ui</file>
<file compressed="true" preprocess="xml-stripblanks">resetWifiEntry.ui</file>
<file compressed="true" preprocess="xml-stripblanks">resetWiFi.ui</file>
<file compressed="true" preprocess="xml-stripblanks">resetMainWindow.ui</file>

View file

@ -1,5 +1,4 @@
#![allow(non_snake_case)]
mod wifiBox;
mod wifiEntry;

View file

@ -0,0 +1,12 @@
use gtk::FlowBox;
use crate::wifi::WifiBox;
pub const HANDLE_WIFI_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let wifibox = WifiBox::new();
resetMain.remove_all();
resetMain.insert(&wifibox, -1);
};
pub const HANDLE_HOME: fn(FlowBox) = |resetMain: FlowBox| {
resetMain.remove_all();
};

View file

@ -1,19 +1,31 @@
mod imp;
#![allow(non_snake_case)]
use adw::BreakpointCondition;
use adw::glib::clone;
use adw::subclass::prelude::ObjectSubclassIsExt;
use glib::Object;
use gtk::{gio, glib, Application};
use gtk::{Application, FlowBox, gio, glib};
use gtk::prelude::*;
use crate::window::sidebarEntry::{Categories, SidebarAction};
mod window;
mod sidebarEntry;
mod handleSidebarClick;
glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
pub struct Window(ObjectSubclass<window::Window>)
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
}
glib::wrapper! {
pub struct SidebarEntry(ObjectSubclass<sidebarEntry::SidebarEntry>)
@extends gtk::ListBoxRow, gtk::Widget,
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
}
#[allow(non_snake_case)]
impl Window {
pub fn new(app: &Application) -> Self {
@ -21,15 +33,23 @@ impl Window {
}
fn setupCallback(&self) {
self.imp().resetSearchEntry
let selfImp = self.imp();
selfImp.resetSearchEntry
.connect_search_changed(clone!(@ weak self as window => move |_| {
window.filterList();
}));
self.imp().resetSideBarToggle
selfImp.resetSideBarToggle
.connect_clicked(clone!(@ weak self as window => move |_| {
window.toggleSidebar();
}));
selfImp.resetSidebarList.connect_row_activated(clone!(@ weak selfImp as flowbox => move |x, y| {
let mut result = y.downcast_ref::<SidebarEntry>().unwrap();
let x1 = result.imp().onClickEvent.borrow().onClickEvent;
(x1)(flowbox.resetMain.get());
}));
}
fn handleDynamicSidebar(&self) {
@ -46,9 +66,7 @@ impl Window {
}
fn filterList(&self) {
let text = self.imp().resetSearchEntry
.text()
.to_string();
let text = self.imp().resetSearchEntry.text().to_string();
self.imp().resetSidebarList.set_filter_func(move |x| {
if text == "" {
return true;
@ -73,4 +91,20 @@ impl Window {
.set_show_sidebar(true);
}
}
}
impl SidebarEntry {
pub fn new(entryName: &str, iconName: &str, category: Categories, isSubcategory: bool, clickEvent: fn(FlowBox)) -> Self {
let entry: SidebarEntry = Object::builder().build();
let entryImp = entry.imp();
entryImp.resetSidebarLabel.get().set_text(entryName);
entryImp.resetSidebarImage.set_from_icon_name(Some(iconName));
entryImp.category.set(category);
entryImp.isSubcategory.set(isSubcategory);
{
let mut ref_mut = entryImp.onClickEvent.borrow_mut();
*ref_mut = SidebarAction { onClickEvent: clickEvent };
}
entry
}
}

View file

@ -0,0 +1,62 @@
use std::cell::{Cell, RefCell};
use glib::subclass::InitializingObject;
use gtk::{CompositeTemplate, FlowBox, glib, Image, Label, ListBoxRow};
use gtk::subclass::prelude::*;
use crate::window::handleSidebarClick::HANDLE_HOME;
#[derive(Default)]
pub enum Categories {
Connectivity,
Sound,
#[default]
Misc,
}
#[allow(non_snake_case)]
#[derive(CompositeTemplate, Default)]
#[template(resource = "/org/xetibo/reset/resetSidebarEntry.ui")]
pub struct SidebarEntry {
#[template_child]
pub resetSidebarLabel: TemplateChild<Label>,
#[template_child]
pub resetSidebarImage: TemplateChild<Image>,
pub category: Cell<Categories>,
pub isSubcategory: Cell<bool>,
pub onClickEvent: RefCell<SidebarAction>,
}
#[allow(non_snake_case)]
pub struct SidebarAction {
pub onClickEvent: fn(FlowBox),
}
impl Default for SidebarAction {
fn default() -> Self {
Self {
onClickEvent: HANDLE_HOME
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for SidebarEntry {
const NAME: &'static str = "resetSidebarEntry";
type Type = super::SidebarEntry;
type ParentType = ListBoxRow;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}
impl ListBoxRowImpl for SidebarEntry {}
impl ObjectImpl for SidebarEntry {}
impl WidgetImpl for SidebarEntry {}

View file

@ -1,10 +1,14 @@
use adw::glib::{StaticTypeExt};
use adw::{Breakpoint, OverlaySplitView};
use adw::subclass::prelude::{AdwApplicationWindowImpl};
use adw::glib::StaticTypeExt;
use adw::subclass::prelude::AdwApplicationWindowImpl;
use glib::subclass::InitializingObject;
use gtk::{Button, CompositeTemplate, FlowBox, glib, ListBox, SearchEntry};
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, SearchEntry, ListBox, FlowBox, Button};
use crate::wifi::WifiBox;
use crate::window::handleSidebarClick::HANDLE_WIFI_CLICK;
use crate::window::SidebarEntry;
use crate::window::sidebarEntry::Categories;
#[allow(non_snake_case)]
#[derive(CompositeTemplate, Default)]
@ -48,6 +52,14 @@ impl ObjectImpl for Window {
object.setupCallback();
object.handleDynamicSidebar();
let WiFiEntry = SidebarEntry::new("WiFi",
"network-wireless-symbolic",
Categories::Connectivity,
false,
HANDLE_WIFI_CLICK);
self.resetSidebarList.append(&WiFiEntry);
let wifibox = WifiBox::new();
let wifibox2 = WifiBox::new();
let wifibox3 = WifiBox::new();