add more apt properties to struct

This commit is contained in:
Ward from fusion-voyager-3 2024-06-29 04:19:36 +03:00
parent 241b2100e9
commit fa0e0359cd
4 changed files with 170 additions and 30 deletions

View File

@ -10,6 +10,8 @@
<list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment=""> <list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.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/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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -100,7 +102,7 @@
<updated>1719504951223</updated> <updated>1719504951223</updated>
<workItem from="1719504952240" duration="1363000" /> <workItem from="1719504952240" duration="1363000" />
<workItem from="1719510804090" duration="7000" /> <workItem from="1719510804090" duration="7000" />
<workItem from="1719609702948" duration="3379000" /> <workItem from="1719609702948" duration="9756000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -20,7 +20,17 @@ pub struct AptPackageRow {
#[property(get, set)] #[property(get, set)]
package_installed_version: RefCell<String>, package_installed_version: RefCell<String>,
#[property(get, set)] #[property(get, set)]
package_candidate_version: RefCell<String> package_candidate_version: RefCell<String>,
#[property(get, set)]
package_description: RefCell<String>,
#[property(get, set)]
package_source_uri: RefCell<String>,
#[property(get, set)]
package_maintainer: RefCell<String>,
#[property(get, set)]
package_size: RefCell<u64>,
#[property(get, set)]
package_installed_size: RefCell<u64>,
} }
// ANCHOR_END: custom_button // ANCHOR_END: custom_button
@ -58,7 +68,6 @@ impl ObjectImpl for AptPackageRow {
let prefix_box = gtk::Box::new(Orientation::Vertical, 0); let prefix_box = gtk::Box::new(Orientation::Vertical, 0);
let expandable_box = gtk::Box::new(Orientation::Vertical, 0); let expandable_box = gtk::Box::new(Orientation::Vertical, 0);
expandable_box.add_css_class("linked");
obj.connect_package_name_notify(clone!(@weak prefix_box, @weak expandable_box, @strong obj => move |obj| { obj.connect_package_name_notify(clone!(@weak prefix_box, @weak expandable_box, @strong obj => move |obj| {
remove_all_children_from_box(&prefix_box); remove_all_children_from_box(&prefix_box);
@ -68,28 +77,15 @@ impl ObjectImpl for AptPackageRow {
let package_arch = obj.package_arch(); let package_arch = obj.package_arch();
let package_installed_version= obj.package_installed_version(); let package_installed_version= obj.package_installed_version();
let package_candidate_version= obj.package_candidate_version(); let package_candidate_version= obj.package_candidate_version();
let package_description = obj.package_description();
let package_source_uri = obj.package_source_uri();
let package_maintainer = obj.package_maintainer();
let package_size = obj.package_size();
let package_installed_size= obj.package_installed_size();
// //
create_prefix_content(&prefix_box, &package_arch, &package_installed_version, &package_candidate_version); create_prefix_content(&prefix_box, &package_name, &package_arch, &package_installed_version, &package_candidate_version);
// //
let expandable_page_selection_box = gtk::Box::builder() create_expandable_content(&expandable_box);
.orientation(Orientation::Horizontal)
.hexpand(false)
.vexpand(false)
.halign(Align::Start)
.valign(Align::Start)
.build();
expandable_page_selection_box.add_css_class("linked");
let description_page_button = gtk::ToggleButton::builder()
.label("Description")
.active(true)
.build();
let changelog_page_button = gtk::ToggleButton::builder()
.label("Changelog")
.group(&description_page_button)
.build();
expandable_page_selection_box.append(&description_page_button);
expandable_page_selection_box.append(&changelog_page_button);
expandable_box.append(&expandable_page_selection_box);
})); }));
obj.add_prefix(&prefix_box); obj.add_prefix(&prefix_box);
@ -112,7 +108,7 @@ impl ListBoxRowImpl for AptPackageRow {}
impl PreferencesRowImpl for AptPackageRow {} impl PreferencesRowImpl for AptPackageRow {}
impl ExpanderRowImpl for AptPackageRow {} impl ExpanderRowImpl for AptPackageRow {}
fn create_version_badge(installed_version: String, candidate_version: String) -> gtk::ListBox { 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() let badge_box = gtk::Box::builder()
@ -202,7 +198,7 @@ fn create_version_badge(installed_version: String, candidate_version: String) ->
boxedlist boxedlist
} }
fn create_arch_badge(arch: String) -> gtk::ListBox { fn create_arch_badge(arch: &str) -> gtk::ListBox {
let arch_label = gtk::Label::builder() let arch_label = gtk::Label::builder()
.halign(Align::Start) .halign(Align::Start)
.hexpand(false) .hexpand(false)
@ -250,7 +246,116 @@ fn create_prefix_content(prefix_box: &gtk::Box, package_name: &str ,package_arch
prefix_box.append(&version_box); prefix_box.append(&version_box);
} }
pub fn get_diff_by_prefix(xs: String, ys: String) -> (String, String, String) { fn create_expandable_content(expandable_box: &gtk::Box) {
let expandable_page_selection_box = gtk::Box::builder()
.orientation(Orientation::Horizontal)
.hexpand(false)
.vexpand(false)
.halign(Align::Start)
.valign(Align::Start)
.margin_bottom(10)
.margin_top(10)
.margin_start(10)
.margin_end(10)
.build();
expandable_page_selection_box.add_css_class("linked");
//
let description_page_button = gtk::ToggleButton::builder()
.label(t!("changelog_page_button_label"))
.active(true)
.build();
let extra_info_page_button = gtk::ToggleButton::builder()
.label(t!("extra_info_page_button_label"))
.group(&description_page_button)
.build();
let changelog_page_button = gtk::ToggleButton::builder()
.label(t!("changelog_page_button_label"))
// till we find a way to implement
.sensitive(false)
.group(&description_page_button)
.build();
expandable_page_selection_box.append(&description_page_button);
expandable_page_selection_box.append(&extra_info_page_button);
expandable_page_selection_box.append(&changelog_page_button);
//
expandable_box.append(&expandable_page_selection_box);
//
let expandable_stack = gtk::Stack::builder()
.hexpand(true)
.vexpand(true)
.vhomogeneous(true)
.hhomogeneous(true)
.transition_type(StackTransitionType::SlideLeftRight)
.build();
//
expandable_box.append(&expandable_stack)
}
fn extra_info_stack_page() {
//create_color_badge(t!(""))
//background-accent-bg
}
fn create_color_badge(
label0_text: &str,
label1_text: &str,
css_style: &str,
group_size: &gtk::SizeGroup,
group_size0: &gtk::SizeGroup,
group_size1: &gtk::SizeGroup,
) -> gtk::ListBox {
let badge_box = gtk::Box::builder().build();
let label0 = gtk::Label::builder()
.label(label0_text)
.margin_start(5)
.margin_end(5)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center)
.halign(Align::Center)
.hexpand(true)
.vexpand(true)
.build();
group_size0.add_widget(&label0);
let label_seprator = gtk::Separator::builder().build();
let label1 = gtk::Label::builder()
.label(label1_text)
.margin_start(3)
.margin_end(0)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center)
.halign(Align::Center)
.hexpand(true)
.vexpand(true)
.build();
group_size1.add_widget(&label1);
label1.add_css_class(css_style);
badge_box.append(&label0);
badge_box.append(&label_seprator);
badge_box.append(&label1);
let boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None)
.halign(Align::Center)
.valign(Align::End)
.margin_start(10)
.margin_end(10)
.margin_bottom(10)
.margin_top(10)
.build();
boxedlist.add_css_class("boxed-list");
boxedlist.append(&badge_box);
group_size.add_widget(&boxedlist);
boxedlist
}
pub fn get_diff_by_prefix(xs: &str, ys: &str) -> (String, String, String) {
let mut count = String::new(); 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 { if x == y {

View File

@ -17,6 +17,11 @@ impl AptPackageRow {
.property("package-arch", package.arch) .property("package-arch", package.arch)
.property("package-installed-version", package.installed_version) .property("package-installed-version", package.installed_version)
.property("package-candidate-version", package.candidate_version) .property("package-candidate-version", package.candidate_version)
.property("package-description", package.description)
.property("package-source-uri", package.source_uri)
.property("package-maintainer", package.maintainer)
.property("package-size", package.size)
.property("package-installed-size", package.installed_size)
.build() .build()
} }
} }
@ -28,7 +33,12 @@ impl Default for AptPackageRow {
name: "name".to_string(), name: "name".to_string(),
arch: "arch".to_string(), arch: "arch".to_string(),
installed_version: "0.0".to_string(), installed_version: "0.0".to_string(),
candidate_version: "0.0".to_string() candidate_version: "0.0".to_string(),
description: "??".to_string(),
source_uri: "??".to_string(),
maintainer: "??".to_string(),
size: 0,
installed_size: 0
}) })
} }
} }

View File

@ -3,6 +3,7 @@ use std::path::Path;
use rust_apt::*; use rust_apt::*;
use rust_apt::cache::*; use rust_apt::cache::*;
use rust_apt::new_cache; use rust_apt::new_cache;
use rust_apt::records::RecordField;
use std::process::Command; use std::process::Command;
use gtk::glib::*; use gtk::glib::*;
use adw::prelude::*; use adw::prelude::*;
@ -18,7 +19,12 @@ pub struct AptPackageSocket {
pub name: String, pub name: String,
pub arch: String, pub arch: String,
pub installed_version: String, pub installed_version: String,
pub candidate_version: String pub candidate_version: String,
pub description: String,
pub source_uri: String,
pub maintainer: String,
pub size: u64,
pub installed_size: u64
} }
pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box { pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
@ -122,11 +128,23 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
let upgradable_sort = PackageSort::default().upgradable().names(); let upgradable_sort = PackageSort::default().upgradable().names();
for pkg in upgradable_cache.packages(&upgradable_sort) { for pkg in upgradable_cache.packages(&upgradable_sort) {
let candidate_version_pkg = pkg.candidate().unwrap();
let package_struct = AptPackageSocket { let package_struct = AptPackageSocket {
name: pkg.name().to_string(), name: pkg.name().to_string(),
arch: pkg.arch().to_string(), arch: pkg.arch().to_string(),
installed_version: pkg.installed().unwrap().version().to_string(), installed_version: pkg.installed().unwrap().version().to_string(),
candidate_version: pkg.candidate().unwrap().version().to_string() candidate_version: candidate_version_pkg.version().to_string(),
description: match candidate_version_pkg.description() {
Some(s) => s,
_ => t!("apt_pkg_property_unknown").to_string()
},
source_uri: candidate_version_pkg.uris().collect::<Vec<String>>().join("\n"),
maintainer: match candidate_version_pkg.get_record(RecordField::Maintainer) {
Some(s) => s,
_ => t!("apt_pkg_property_unknown").to_string()
},
size: candidate_version_pkg.size(),
installed_size: candidate_version_pkg.installed_size()
}; };
get_upgradable_sender.send_blocking(package_struct).unwrap() get_upgradable_sender.send_blocking(package_struct).unwrap()
} }
@ -163,7 +181,12 @@ pub fn apt_update_page(window: adw::ApplicationWindow) -> gtk::Box {
name: state.name, name: state.name,
arch: state.arch, arch: state.arch,
installed_version: state.installed_version, installed_version: state.installed_version,
candidate_version: state.candidate_version candidate_version: state.candidate_version,
description: state.description,
source_uri: state.source_uri,
maintainer: state.maintainer,
size: state.size,
installed_size: state.installed_size
})); }));
} }
})); }));