add search to kernel download page

This commit is contained in:
Ward from fusion-voyager-3 2024-06-19 03:52:50 +03:00
parent b0fda8a123
commit 7dda928089
6 changed files with 146 additions and 21 deletions

View File

@ -450,7 +450,6 @@ fn create_kernel_badges(
let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both); let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both); let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
dbg!(&selected_kernel_branch_clone.db);
let json: serde_json::Value = let json: serde_json::Value =
serde_json::from_str(&selected_kernel_branch_clone.db).expect("Unable to parse"); serde_json::from_str(&selected_kernel_branch_clone.db).expect("Unable to parse");

View File

@ -0,0 +1,65 @@
use std::{cell::RefCell, env, rc::Rc, sync::OnceLock};
use adw::{prelude::*, subclass::prelude::*, *};
use glib::{clone, subclass::Signal, Properties};
use gtk::{glib, Orientation::Horizontal};
use adw::*;
// ANCHOR: custom_button
// Object holding the state
#[derive(Properties, Default)]
#[properties(wrapper_type = super::KernelPackageRow)]
pub struct KernelPackageRow {
#[property(get, set)]
package: RefCell<String>,
}
// ANCHOR_END: custom_button
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for KernelPackageRow {
const NAME: &'static str = "KernelPackageRow";
type Type = super::KernelPackageRow;
type ParentType = adw::ExpanderRow;
}
// ANCHOR: object_impl
// Trait shared by all GObjects
#[glib::derived_properties]
impl ObjectImpl for KernelPackageRow {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| vec![Signal::builder("row-deleted").build()])
}
fn constructed(&self) {
self.parent_constructed();
// Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set
let obj = self.obj();
let basic_expander_row_package_label = gtk::Label::builder()
.build();
obj.add_suffix(&basic_expander_row_package_label);
// Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set
let obj = self.obj();
obj.bind_property("package", &basic_expander_row_package_label, "label")
.sync_create()
.bidirectional()
.build();
}
}
// Trait shared by all widgets
impl WidgetImpl for KernelPackageRow {}
// Trait shared by all buttons
// Trait shared by all buttons
impl ListBoxRowImpl for KernelPackageRow {}
impl PreferencesRowImpl for KernelPackageRow {}
impl ExpanderRowImpl for KernelPackageRow {}

View File

@ -0,0 +1,23 @@
mod imp;
use glib::Object;
use gtk::glib;
glib::wrapper! {
pub struct KernelPackageRow(ObjectSubclass<imp::KernelPackageRow>)
@extends adw::ExpanderRow, gtk::Widget, gtk::ListBoxRow, adw::PreferencesRow,
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
}
impl KernelPackageRow {
pub fn new() -> Self {
Object::builder().build()
}
}
// ANCHOR_END: mod
impl Default for KernelPackageRow {
fn default() -> Self {
Self::new()
}
}

View File

@ -1,5 +1,5 @@
use crate::content::get_running_kernel_info; use crate::content::get_running_kernel_info;
use crate::{KernelBranch, RunningKernelInfo}; use crate::{kernel_package_row, KernelBranch, RunningKernelInfo};
use adw::prelude::*; use adw::prelude::*;
use duct::cmd; use duct::cmd;
use glib::*; use glib::*;
@ -53,6 +53,10 @@ pub fn kernel_pkg_page(
let packages_boxedlist = gtk::ListBox::builder() let packages_boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None) .selection_mode(SelectionMode::None)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.margin_start(15)
.build(); .build();
packages_boxedlist.add_css_class("boxed-list"); packages_boxedlist.add_css_class("boxed-list");
let rows_size_group = gtk::SizeGroup::new(SizeGroupMode::Both); let rows_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
@ -61,6 +65,7 @@ pub fn kernel_pkg_page(
&selected_kernel_branch_clone0.db, &selected_kernel_branch_clone0.db,
&window, &window,
&rows_size_group, &rows_size_group,
&searchbar
); );
let packages_viewport = gtk::ScrolledWindow::builder() let packages_viewport = gtk::ScrolledWindow::builder()
@ -113,6 +118,7 @@ fn add_package_rows(
data: &str, data: &str,
window: &adw::ApplicationWindow, window: &adw::ApplicationWindow,
rows_size_group: &gtk::SizeGroup, rows_size_group: &gtk::SizeGroup,
searchbar: &gtk::SearchEntry
) { ) {
let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse"); let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
if let serde_json::Value::Array(kernels) = &res["kernels"] { if let serde_json::Value::Array(kernels) = &res["kernels"] {
@ -137,24 +143,25 @@ fn add_package_rows(
let kernel_status_loop_sender: async_channel::Sender<bool> = let kernel_status_loop_sender: async_channel::Sender<bool> =
kernel_status_loop_sender.clone(); kernel_status_loop_sender.clone();
let kernel_package_clone0 = kernel_package.clone();
std::thread::spawn(move || loop { std::thread::spawn(move || loop {
// let command_installed_status = std::Command::new("dpkg") let command_installed_status = Command::new("rpm")
// .args(["-s", &kernel_package_ind2]) .args(["-q", &kernel_package_clone0])
// .output() .output()
// .unwrap(); .unwrap();
//if command_installed_status.status.success() { if command_installed_status.status.success() {
// kernel_status_loop_sender.send_blocking(true).expect("channel needs to be open") kernel_status_loop_sender.send_blocking(true).expect("channel needs to be open")
//} else { } else {
// kernel_status_loop_sender.send_blocking(false).expect("channel needs to be open") kernel_status_loop_sender.send_blocking(false).expect("channel needs to be open")
//} }
std::thread::sleep(Duration::from_secs(6)); std::thread::sleep(Duration::from_secs(6));
kernel_status_loop_sender
.send_blocking(true)
.expect("channel needs to be open")
}); });
let kernel_expander_row = adw::ExpanderRow::new(); let kernel_package_clone0 = kernel_package.clone();
let kernel_package_label = gtk::Label::builder().label(&kernel_package).build();
let kernel_expander_row = kernel_package_row::KernelPackageRow::new();
kernel_expander_row.set_package(kernel_package_clone0);
let kernel_status_icon = gtk::Image::builder() let kernel_status_icon = gtk::Image::builder()
.icon_name("emblem-default") .icon_name("emblem-default")
.pixel_size(24) .pixel_size(24)
@ -185,7 +192,6 @@ fn add_package_rows(
let kernel_action_box = gtk::Box::builder().homogeneous(true).build(); let kernel_action_box = gtk::Box::builder().homogeneous(true).build();
kernel_remove_button.add_css_class("destructive-action"); kernel_remove_button.add_css_class("destructive-action");
kernel_expander_row.add_suffix(&kernel_status_icon); kernel_expander_row.add_suffix(&kernel_status_icon);
kernel_expander_row.add_suffix(&kernel_package_label);
kernel_expander_row.set_title(&kernel_name); kernel_expander_row.set_title(&kernel_name);
//kernel_expander_row.set_subtitle(&kernel_package_version); //kernel_expander_row.set_subtitle(&kernel_package_version);
// //
@ -346,19 +352,51 @@ fn add_package_rows(
boxedlist.append(&kernel_expander_row); boxedlist.append(&kernel_expander_row);
} }
}; };
searchbar.connect_search_changed(clone!(@weak searchbar, @weak boxedlist => move |_| {
let mut counter = boxedlist.first_child();
while let Some(row) = counter {
if row.widget_name() == "KernelPackageRow" {
if !searchbar.text().is_empty() {
if row.property::<String>("title").to_lowercase().contains(&searchbar.text().to_string().to_lowercase()) || row.property::<String>("package").to_lowercase().contains(&searchbar.text().to_string().to_lowercase()) {
//row.grab_focus();
//row.add_css_class("highlight-widget");
row.set_property("visible", true);
searchbar.grab_focus();
} else {
row.set_property("visible", false);
}
} else {
row.set_property("visible", true);
}
}
counter = row.next_sibling();
}
}));
} }
const KERNEL_MODIFY_PROG: &str = r###" const KERNEL_MODIFY_PROG: &str = r###"
#! /bin/bash #! /bin/bash
DRIVER="$0"
/usr/lib/pika/drivers/modify-driver.sh "${DRIVER}" set -e
PACKAGE="$0"
if rpm -q "${PACKAGE}"
then
dnf remove -y "${PACKAGE}"
else
dnf install -y "${PACKAGE}"
fi
exit 0
"###; "###;
fn kernel_modify( fn kernel_modify(
log_loop_sender: async_channel::Sender<String>, log_loop_sender: async_channel::Sender<String>,
kernel_pkg: &str, kernel_pkg: &str,
) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> { ) -> Result<(), std::boxed::Box<dyn Error + Send + Sync>> {
let (pipe_reader, pipe_writer) = os_pipe::pipe()?; let (pipe_reader, pipe_writer) = os_pipe::pipe()?;
let child = cmd!("bash", "-c", KERNEL_MODIFY_PROG, kernel_pkg) let child = cmd!("pkexec", "bash", "-c", KERNEL_MODIFY_PROG, kernel_pkg)
.stderr_to_stdout() .stderr_to_stdout()
.stdout_file(pipe_writer) .stdout_file(pipe_writer)
.start()?; .start()?;

View File

@ -2,6 +2,7 @@ mod build_ui;
mod content; mod content;
mod kernel_pkg; mod kernel_pkg;
mod sched_ext; mod sched_ext;
mod kernel_package_row;
use adw::prelude::*; use adw::prelude::*;
use gtk::*; use gtk::*;

View File

@ -166,7 +166,6 @@ fn scx_sched_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
.label("No branch selected") .label("No branch selected")
.build(); .build();
let mut scx_sched_array: Vec<String> = Vec::new();
let data = fs::read_to_string( let data = fs::read_to_string(
"/home/ward/RustroverProjects/fedora-kernel-manager/data/scx_scheds.json", "/home/ward/RustroverProjects/fedora-kernel-manager/data/scx_scheds.json",
) )