add suffixes

This commit is contained in:
Ward from fusion-voyager-3 2024-07-06 22:34:23 +03:00
parent 346411c02f
commit 9a7e998f31
4 changed files with 118 additions and 52 deletions

View File

@ -8,9 +8,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/apt_package_row/imp.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/apt_package_row/imp.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/apt_package_row/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/apt_package_row/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/apt_update_page/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/apt_update_page/mod.rs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -107,7 +107,8 @@
<workItem from="1719797522707" duration="698000" />
<workItem from="1719847278228" duration="8841000" />
<workItem from="1719872581190" duration="4000" />
<workItem from="1720090281244" duration="2690000" />
<workItem from="1720090281244" duration="5582000" />
<workItem from="1720289925469" duration="4403000" />
</task>
<servers />
</component>

View File

@ -1,11 +1,11 @@
use std::{cell::RefCell, default, sync::OnceLock};
use crate::apt_update_page::AptPackageSocket;
use adw::*;
use adw::{prelude::*, subclass::prelude::*};
use glib::{subclass::Signal, Properties, clone};
use gtk::{*};
use glib::{clone, subclass::Signal, Properties};
use gtk::Orientation::Horizontal;
use crate::apt_update_page::AptPackageSocket;
use gtk::*;
use pretty_bytes::converter::convert;
use std::env;
use std::os::unix::raw::nlink_t;
@ -54,7 +54,10 @@ impl ObjectImpl for AptPackageRow {
}
fn constructed(&self) {
let current_locale = match env::var_os("LANG") {
Some(v) => v.into_string().unwrap().chars()
Some(v) => v
.into_string()
.unwrap()
.chars()
.take_while(|&ch| ch != '.')
.collect::<String>(),
None => panic!("$LANG is not set"),
@ -111,7 +114,8 @@ impl PreferencesRowImpl for AptPackageRow {}
impl ExpanderRowImpl for AptPackageRow {}
fn create_version_badge(installed_version: &str, candidate_version: &str) -> gtk::ListBox {
let (base_version, installed_diff, candidate_diff) = get_diff_by_prefix(installed_version, candidate_version);
let (base_version, installed_diff, candidate_diff) =
get_diff_by_prefix(installed_version, candidate_version);
let badge_box = gtk::Box::builder()
.halign(Align::Start)
@ -131,7 +135,11 @@ fn create_version_badge(installed_version: &str, candidate_version: &str) -> gtk
.build();
let installed_version_base_version_label = gtk::Label::builder()
.label(format!("{}: {}", t!("installed_version_badge_text"), &base_version))
.label(format!(
"{}: {}",
t!("installed_version_badge_text"),
&base_version
))
.valign(Align::Center)
.halign(Align::Start)
.hexpand(false)
@ -163,7 +171,11 @@ fn create_version_badge(installed_version: &str, candidate_version: &str) -> gtk
.build();
let candidate_version_base_version_label = gtk::Label::builder()
.label(format!("{}: {}", t!("candidate_version_badge_text"), &base_version))
.label(format!(
"{}: {}",
t!("candidate_version_badge_text"),
&base_version
))
.valign(Align::Center)
.halign(Align::Start)
.hexpand(false)
@ -231,7 +243,13 @@ fn remove_all_children_from_box(parent: &gtk::Box) {
}
}
fn create_prefix_content(prefix_box: &gtk::Box, package_name: &str ,package_arch: &str, package_installed_version: &str, package_candidate_version: &str) {
fn create_prefix_content(
prefix_box: &gtk::Box,
package_name: &str,
package_arch: &str,
package_installed_version: &str,
package_candidate_version: &str,
) {
let package_label = gtk::Label::builder()
.halign(Align::Start)
.margin_start(5)
@ -242,13 +260,24 @@ fn create_prefix_content(prefix_box: &gtk::Box, package_name: &str ,package_arch
.build();
package_label.add_css_class("size-20-bold-text");
let version_box = gtk::Box::new(Orientation::Horizontal, 0);
version_box.append(&create_version_badge(package_installed_version, package_candidate_version));
version_box.append(&create_version_badge(
package_installed_version,
package_candidate_version,
));
version_box.append(&create_arch_badge(package_arch));
prefix_box.append(&package_label);
prefix_box.append(&version_box);
}
fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable_box: &gtk::Box, package_description: String, package_source_uri: String, package_maintainer: String, package_size: u64, package_installed_size: u64) {
fn create_expandable_content(
apt_package_row: &impl IsA<ExpanderRow>,
expandable_box: &gtk::Box,
package_description: String,
package_source_uri: String,
package_maintainer: String,
package_size: u64,
package_installed_size: u64,
) {
let expandable_page_selection_box = gtk::Box::builder()
.orientation(Orientation::Horizontal)
.hexpand(false)
@ -287,16 +316,15 @@ fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable
//
expandable_box.append(&expandable_page_selection_box);
//
let expandable_bin = adw::Bin::builder()
.hexpand(true)
.vexpand(true)
.build();
let expandable_bin = adw::Bin::builder().hexpand(true).vexpand(true).build();
//
description_page_button.connect_clicked(clone!(@strong expandable_bin, @strong description_page_button => move |_|{
description_page_button.connect_clicked(
clone!(@strong expandable_bin, @strong description_page_button => move |_|{
if description_page_button.is_active() {
expandable_bin.set_child(Some(&description_stack_page(&package_description)));
}
}));
}),
);
extra_info_page_button.connect_clicked(clone!(@strong expandable_bin, @strong extra_info_page_button => move |_|{
if extra_info_page_button.is_active() {
@ -304,11 +332,13 @@ fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable
}
}));
uris_page_button.connect_clicked(clone!(@strong expandable_bin, @strong uris_page_button => move |_|{
uris_page_button.connect_clicked(
clone!(@strong expandable_bin, @strong uris_page_button => move |_|{
if uris_page_button.is_active() {
expandable_bin.set_child(Some(&uris_stack_page(&package_source_uri)));
}
}));
}),
);
apt_package_row.connect_expanded_notify(clone!(@strong expandable_bin, @strong expandable_box, @strong apt_package_row, @strong description_page_button => move |apt_package_row| {
if apt_package_row.property("expanded") {
@ -330,7 +360,7 @@ fn uris_stack_page(package_source_uri: &str) -> gtk::Box {
.orientation(Orientation::Vertical)
.build();
let uris_text_buffer = gtk::TextBuffer::builder()
.text(package_source_uri.to_owned()+"\n")
.text(package_source_uri.to_owned() + "\n")
.build();
let uris_text_view = gtk::TextView::builder()
.buffer(&uris_text_buffer)
@ -354,7 +384,7 @@ fn description_stack_page(package_description: &str) -> gtk::Box {
.orientation(Orientation::Vertical)
.build();
let description_text_buffer = gtk::TextBuffer::builder()
.text(package_description.to_owned()+"\n")
.text(package_description.to_owned() + "\n")
.build();
let description_text_view = gtk::TextView::builder()
.buffer(&description_text_buffer)
@ -371,7 +401,11 @@ fn description_stack_page(package_description: &str) -> gtk::Box {
description_content_box
}
fn extra_info_stack_page(package_maintainer: &str, package_size: u64, package_installed_size: u64) -> gtk::Box {
fn extra_info_stack_page(
package_maintainer: &str,
package_size: u64,
package_installed_size: u64,
) -> gtk::Box {
let extra_info_badges_content_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
@ -382,9 +416,30 @@ fn extra_info_stack_page(package_maintainer: &str, package_size: u64, package_in
let extra_info_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
let package_size = package_size as f64;
let package_installed_size = package_installed_size as f64;
extra_info_badges_content_box.append(&create_color_badge(&t!("extra_info_maintainer").to_string(), package_maintainer, "background-accent-bg", &extra_info_badges_size_group, &extra_info_badges_size_group0, &extra_info_badges_size_group1));
extra_info_badges_content_box.append(&create_color_badge(&t!("extra_info_download_size").to_string(), &convert(package_size), "background-accent-bg", &extra_info_badges_size_group, &extra_info_badges_size_group0, &extra_info_badges_size_group1));
extra_info_badges_content_box.append(&create_color_badge(&t!("extra_info_installed_size").to_string(), &convert(package_installed_size), "background-accent-bg", &extra_info_badges_size_group, &extra_info_badges_size_group0, &extra_info_badges_size_group1));
extra_info_badges_content_box.append(&create_color_badge(
&t!("extra_info_maintainer").to_string(),
package_maintainer,
"background-accent-bg",
&extra_info_badges_size_group,
&extra_info_badges_size_group0,
&extra_info_badges_size_group1,
));
extra_info_badges_content_box.append(&create_color_badge(
&t!("extra_info_download_size").to_string(),
&convert(package_size),
"background-accent-bg",
&extra_info_badges_size_group,
&extra_info_badges_size_group0,
&extra_info_badges_size_group1,
));
extra_info_badges_content_box.append(&create_color_badge(
&t!("extra_info_installed_size").to_string(),
&convert(package_installed_size),
"background-accent-bg",
&extra_info_badges_size_group,
&extra_info_badges_size_group0,
&extra_info_badges_size_group1,
));
extra_info_badges_content_box
}
fn create_color_badge(
@ -449,13 +504,17 @@ fn create_color_badge(
pub fn get_diff_by_prefix(xs: &str, ys: &str) -> (String, String, String) {
let mut count = String::new();
for (x,y) in xs.chars().zip(ys.chars()) {
for (x, y) in xs.chars().zip(ys.chars()) {
if x == y {
count.push(x)
} else {
break
break;
}
}
let count_clone0 = count.clone();
return(count_clone0, xs.trim_start_matches(&count.as_str()).to_string(), ys.trim_start_matches(&count.as_str()).to_string())
return (
count_clone0,
xs.trim_start_matches(&count.as_str()).to_string(),
ys.trim_start_matches(&count.as_str()).to_string(),
);
}

View File

@ -39,6 +39,7 @@ impl Default for AptPackageRow {
maintainer: "??".to_string(),
size: 0,
installed_size: 0,
is_last: false,
})
}
}

View File

@ -1,5 +1,7 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::Action;
use adw::prelude::*;
use adw::ActionRow;
use gtk::glib::*;
use gtk::*;
use pika_unixsocket_tools::*;
@ -28,6 +30,7 @@ pub struct AptPackageSocket {
pub maintainer: String,
pub size: u64,
pub installed_size: u64,
pub is_last: bool,
}
pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
@ -121,25 +124,21 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
.width_request(500)
.build();
let mut updates_parsed = Arc::new(AtomicBool::new(false));
let update_parsed_clone0 = Arc::clone(&updates_parsed);
let update_percent_server_context = MainContext::default();
// The main loop executes the asynchronous block
update_percent_server_context.spawn_local(clone!(@weak apt_update_dialog_progress_bar, @weak apt_update_dialog, @strong get_upgradable_sender, @strong update_parsed_clone0 => async move {
update_percent_server_context.spawn_local(clone!(@weak apt_update_dialog_progress_bar, @weak apt_update_dialog, @strong get_upgradable_sender => async move {
while let Ok(state) = update_percent_receiver.recv().await {
match state.as_ref() {
"FN_OVERRIDE_SUCCESSFUL" => {
let get_upgradable_sender = get_upgradable_sender.clone();
let update_parsed_clone = Arc::clone(&update_parsed_clone0);
thread::spawn(move || {
// Create upgradable list cache
let upgradable_cache = new_cache!().unwrap();
// Create pack sort from upgradable_cache
let upgradable_sort = PackageSort::default().upgradable().names();
for pkg in upgradable_cache.packages(&upgradable_sort) {
let mut upgradeable_iter = upgradable_cache.packages(&upgradable_sort).peekable();
while let Some(pkg) = upgradeable_iter.next() {
let candidate_version_pkg = pkg.candidate().unwrap();
let package_struct = AptPackageSocket {
name: pkg.name().to_string(),
@ -156,11 +155,11 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
_ => t!("apt_pkg_property_unknown").to_string()
},
size: candidate_version_pkg.size(),
installed_size: candidate_version_pkg.installed_size()
installed_size: candidate_version_pkg.installed_size(),
is_last: upgradeable_iter.peek().is_none()
};
get_upgradable_sender.send_blocking(package_struct).unwrap()
}
update_parsed_clone.store(true, std::sync::atomic::Ordering::Relaxed)
});
apt_update_dialog.close();
}
@ -188,11 +187,10 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
}),
);
let update_parsed_clone1 = Arc::clone(&updates_parsed);
let get_upgradable_server_context = MainContext::default();
// The main loop executes the asynchronous block
get_upgradable_server_context.spawn_local(
clone!(@weak packages_boxedlist, @strong update_parsed_clone1 => async move {
clone!(@weak packages_boxedlist => async move {
while let Ok(state) = get_upgradable_receiver.recv().await {
packages_boxedlist.append(&AptPackageRow::new(AptPackageSocket {
name: state.name,
@ -203,10 +201,17 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
source_uri: state.source_uri,
maintainer: state.maintainer,
size: state.size,
installed_size: state.installed_size
installed_size: state.installed_size,
is_last: state.is_last
}));
if update_parsed_clone1.load(std::sync::atomic::Ordering::Relaxed) {
packages_boxedlist.set_sensitive(true)
if state.is_last {
packages_boxedlist.set_sensitive(true);
let mut counter = packages_boxedlist.first_child();
while let Some(row) = counter {
let row_next_sibling = row.next_sibling();
row.downcast::<AptPackageRow>().unwrap().add_suffix(&gtk::Button::builder().label("gg").build());
counter = row_next_sibling;
}
}
}
}),