Add packages support (mostly)

This commit is contained in:
Hellx2 2024-08-11 18:02:00 +10:00
parent d4f24c97eb
commit 55d9f15afd
7 changed files with 463 additions and 193 deletions

163
Cargo.lock generated
View file

@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.2.0" version = "1.2.0"
@ -16,15 +10,15 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.5.0" version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]] [[package]]
name = "cairo-rs" name = "cairo-rs"
version = "0.19.2" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2650f66005301bd33cc486dec076e1293c4cecf768bc7ba9bf5d2b1be339b99c" checksum = "797fd5a634dcb0ad0d7d583df794deb0a236d88e759cd34b7da20198c6c9d145"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cairo-sys-rs", "cairo-sys-rs",
@ -35,9 +29,9 @@ dependencies = [
[[package]] [[package]]
name = "cairo-sys-rs" name = "cairo-sys-rs"
version = "0.19.2" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3bb3119664efbd78b5e6c93957447944f16bdbced84c17a9f41c7829b81e64" checksum = "428290f914b9b86089f60f5d8a9f6e440508e1bcff23b25afd51502b0a2da88f"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -110,7 +104,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.58", "syn",
] ]
[[package]] [[package]]
@ -135,9 +129,9 @@ dependencies = [
[[package]] [[package]]
name = "gdk-pixbuf" name = "gdk-pixbuf"
version = "0.19.2" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6a23f8a0b5090494fd04924662d463f8386cc678dd3915015a838c1a3679b92" checksum = "28bb53ecb56857c683c9ec859908e076dd3969c7d67598bd8b1ce095d211304a"
dependencies = [ dependencies = [
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
"gio", "gio",
@ -147,9 +141,9 @@ dependencies = [
[[package]] [[package]]
name = "gdk-pixbuf-sys" name = "gdk-pixbuf-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcbd04c1b2c4834cc008b4828bc917d062483b88d26effde6342e5622028f96" checksum = "9f6681a0c1330d1d3968bec1529f7172d62819ef0bdbb0d18022320654158b03"
dependencies = [ dependencies = [
"gio-sys", "gio-sys",
"glib-sys", "glib-sys",
@ -160,9 +154,9 @@ dependencies = [
[[package]] [[package]]
name = "gdk4" name = "gdk4"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9100b25604183f2fd97f55ef087fae96ab4934d7215118a35303e422688e6e4b" checksum = "4b7d7237c1487ed4b300aac7744efcbf1319e12d60d7afcd6f505414bd5b5dea"
dependencies = [ dependencies = [
"cairo-rs", "cairo-rs",
"gdk-pixbuf", "gdk-pixbuf",
@ -175,9 +169,9 @@ dependencies = [
[[package]] [[package]]
name = "gdk4-sys" name = "gdk4-sys"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0b76874c40bb8d1c7d03a7231e23ac75fa577a456cd53af32ec17ec8f121626" checksum = "a67576c8ec012156d7f680e201a807b4432a77babb3157e0555e990ab6bcd878"
dependencies = [ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
@ -192,9 +186,9 @@ dependencies = [
[[package]] [[package]]
name = "gio" name = "gio"
version = "0.19.3" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64947d08d7fbb03bf8ad1f25a8ac6cf4329bc772c9b7e5abe7bf9493c81194f" checksum = "398e3da68749fdc32783cbf7521ec3f65c9cf946db8c7774f8460af49e52c6e2"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -210,9 +204,9 @@ dependencies = [
[[package]] [[package]]
name = "gio-sys" name = "gio-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf8e1d9219bb294636753d307b030c1e8a032062cba74f493c431a5c8b81ce4" checksum = "e4feb96b31c32730ea3e1e89aecd2e4e37ecb1c473ad8f685e3430a159419f63"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -223,9 +217,9 @@ dependencies = [
[[package]] [[package]]
name = "glib" name = "glib"
version = "0.19.3" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e191cc1af1f35b9699213107068cd3fe05d9816275ac118dc785a0dd8faebf" checksum = "fee90a615ce05be7a32932cfb8adf2c4bbb4700e80d37713c981fb24c0c56238"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"futures-channel", "futures-channel",
@ -245,22 +239,22 @@ dependencies = [
[[package]] [[package]]
name = "glib-macros" name = "glib-macros"
version = "0.19.3" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9972bb91643d589c889654693a4f1d07697fdcb5d104b5c44fb68649ba1bf68d" checksum = "4da558d8177c0c8c54368818b508a4244e1286fce2858cef4e547023f0cfa5ef"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.58", "syn",
] ]
[[package]] [[package]]
name = "glib-sys" name = "glib-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630f097773d7c7a0bb3258df4e8157b47dc98bbfa0e60ad9ab56174813feced4" checksum = "4958c26e5a01c9af00dea669a97369eccbec29a8e6d125c24ea2d85ee7467b60"
dependencies = [ dependencies = [
"libc", "libc",
"system-deps", "system-deps",
@ -268,9 +262,9 @@ dependencies = [
[[package]] [[package]]
name = "gobject-sys" name = "gobject-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c85e2b1080b9418dd0c58b498da3a5c826030343e0ef07bde6a955d28de54979" checksum = "c6908864f5ffff15b56df7e90346863904f49b949337ed0456b9287af61903b8"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -279,9 +273,9 @@ dependencies = [
[[package]] [[package]]
name = "graphene-rs" name = "graphene-rs"
version = "0.19.2" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e4d388e96c5f29e2b2f67045d229ddf826d0a8d6d282f94ed3b34452222c91" checksum = "630e940ad5824f90221d6579043a9cd1f8bec86b4a17faaf7827d58eb16e8c1f"
dependencies = [ dependencies = [
"glib", "glib",
"graphene-sys", "graphene-sys",
@ -290,9 +284,9 @@ dependencies = [
[[package]] [[package]]
name = "graphene-sys" name = "graphene-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "236ed66cc9b18d8adf233716f75de803d0bf6fc806f60d14d948974a12e240d0" checksum = "6fb8fade7b754982f47ebbed241fd2680816fdd4598321784da10b9e1168836a"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -302,9 +296,9 @@ dependencies = [
[[package]] [[package]]
name = "gsk4" name = "gsk4"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c65036fc8f99579e8cb37b12487969b707ab23ec8ab953682ff347cbd15d396e" checksum = "1f3cf2091e1af185b347b3450817d93dea6fe435df7abd4c2cd7fb5bcb4cfda8"
dependencies = [ dependencies = [
"cairo-rs", "cairo-rs",
"gdk4", "gdk4",
@ -317,9 +311,9 @@ dependencies = [
[[package]] [[package]]
name = "gsk4-sys" name = "gsk4-sys"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd24c814379f9c3199dc53e52253ee8d0f657eae389ab282c330505289d24738" checksum = "6aa69614a26d8760c186c3690f1b0fbb917572ca23ef83137445770ceddf8cde"
dependencies = [ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"gdk4-sys", "gdk4-sys",
@ -333,9 +327,9 @@ dependencies = [
[[package]] [[package]]
name = "gtk4" name = "gtk4"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa82753b8c26277e4af1446c70e35b19aad4fb794a7b143859e7eeb9a4025d83" checksum = "eaffc6c743c9160514cc9b67eace364e5dc5798369fa809cdb04e035c21c5c5d"
dependencies = [ dependencies = [
"cairo-rs", "cairo-rs",
"field-offset", "field-offset",
@ -354,23 +348,21 @@ dependencies = [
[[package]] [[package]]
name = "gtk4-macros" name = "gtk4-macros"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40300bf071d2fcd4c94eacc09e84ec6fe73129d2ceb635cf7e55b026b5443567" checksum = "188211f546ce5801f6d0245c37b6249143a2cb4fa040e54829ca1e76796e9f09"
dependencies = [ dependencies = [
"anyhow",
"proc-macro-crate", "proc-macro-crate",
"proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn",
] ]
[[package]] [[package]]
name = "gtk4-sys" name = "gtk4-sys"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0db1b104138f087ccdc81d2c332de5dd049b89de3d384437cc1093b17cd2da18" checksum = "1114a207af8ada02cf4658a76692f4190f06f093380d5be07e3ca8b43aa7c666"
dependencies = [ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"gdk-pixbuf-sys", "gdk-pixbuf-sys",
@ -415,9 +407,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.2" version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]] [[package]]
name = "memoffset" name = "memoffset"
@ -437,9 +429,9 @@ dependencies = [
[[package]] [[package]]
name = "pango" name = "pango"
version = "0.19.3" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1264d13deb823cc652f26cfe59afb1ec4b9db2a5bd27c41b738c879cc1bfaa1" checksum = "54768854025df6903061d0084fd9702a253ddfd60db7d9b751d43b76689a7f0a"
dependencies = [ dependencies = [
"gio", "gio",
"glib", "glib",
@ -449,9 +441,9 @@ dependencies = [
[[package]] [[package]]
name = "pango-sys" name = "pango-sys"
version = "0.19.0" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52ef6a881c19fbfe3b1484df5cad411acaaba29dbec843941c3110d19f340ea" checksum = "b07cc57d10cee4ec661f718a6902cee18c2f4cfae08e87e5a390525946913390"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -486,35 +478,11 @@ dependencies = [
"toml_edit 0.21.1", "toml_edit 0.21.1",
] ]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.79" version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -560,7 +528,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.58", "syn",
] ]
[[package]] [[package]]
@ -589,20 +557,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -611,9 +568,9 @@ dependencies = [
[[package]] [[package]]
name = "system-deps" name = "system-deps"
version = "6.2.2" version = "7.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" checksum = "6c81f13d9a334a6c242465140bd262fae382b752ff2011c4f7419919a9c97922"
dependencies = [ dependencies = [
"cfg-expr", "cfg-expr",
"heck", "heck",
@ -645,7 +602,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.58", "syn",
] ]
[[package]] [[package]]
@ -705,12 +662,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" version = "0.52.0"

View file

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_4"] } gtk = { version = "0.9.0", package = "gtk4" }

View file

@ -1,8 +1,121 @@
use gtk::{glib, prelude::ApplicationExtManual, Application}; use gtk::{
gdk, glib,
prelude::{ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt},
style_context_add_provider_for_display, Align, Application, ApplicationWindow,
Orientation::{Horizontal, Vertical},
SearchBar, SearchEntry, Stack, StackSwitcher,
};
pub mod packages;
const APP_ID: &str = "org.oreonproject.SystemManager"; const APP_ID: &str = "org.oreonproject.SystemManager";
fn main() -> glib::ExitCode { fn main() -> glib::ExitCode {
let app = Application::builder().application_id(APP_ID).build(); let app = Application::builder().application_id(APP_ID).build();
app.connect_startup(on_startup);
app.connect_activate(on_activate);
app.connect_shutdown(on_shutdown);
app.run() app.run()
} }
fn on_activate(app: &Application) {
let main_window = ApplicationWindow::new(app);
main_window.set_title(Some("System Manager"));
main_window.set_default_size(800, 600);
let main_stack = Stack::builder().css_classes(["main-stack"]).build();
let switcher = StackSwitcher::builder()
.orientation(Horizontal)
.stack(&main_stack)
.build();
let main_box = gtk::Box::builder()
.orientation(Vertical)
.css_classes(["main-box"])
.build();
main_stack.add_titled(&packages::packages(), Some("packages"), "Packages");
main_stack.add_titled(&drivers(), Some("drivers"), "Drivers");
main_stack.add_titled(&containers(), Some("containers"), "Containers");
main_stack.add_titled(&virtualization(), Some("virtualization"), "Virtualization");
main_box.append(&switcher);
main_box.append(&main_stack);
main_window.set_child(Some(&main_box));
main_window.present();
}
fn drivers() -> gtk::Box {
let drivers_box = gtk::Box::builder()
.orientation(Vertical)
.css_classes(["packages-box"])
.valign(Align::Center)
.halign(Align::Fill)
.hexpand(true)
.build();
let drivers_search = SearchBar::builder()
.halign(Align::Fill)
.valign(Align::Start)
.css_classes(["search-bar"])
.build();
let drivers_entry = SearchEntry::builder()
.css_classes(["entries"])
.halign(Align::Center)
.valign(Align::Start)
.width_request(600)
.placeholder_text("Search for a driver...")
.sensitive(true)
.hexpand(true)
.build();
drivers_search.connect_entry(&drivers_entry);
drivers_box.append(&drivers_search);
drivers_box.append(&drivers_entry);
drivers_box
}
fn containers() -> gtk::Box {
let containers_box = gtk::Box::builder()
.orientation(Horizontal)
.css_classes(["containers-box"])
.build();
containers_box.append(&gtk::Label::new(Some("Containers")));
containers_box
}
fn virtualization() -> gtk::Box {
let virtualization_box = gtk::Box::builder()
.orientation(Horizontal)
.css_classes(["virtualization-box"])
.build();
virtualization_box.append(&gtk::Label::new(Some("Virtualization")));
virtualization_box
}
fn on_startup(_: &Application) {
let css_provider = gtk::CssProvider::new();
css_provider.load_from_data(include_str!("style.css"));
style_context_add_provider_for_display(
gdk::Display::default().as_ref().unwrap(),
&css_provider,
gtk::STYLE_PROVIDER_PRIORITY_USER,
);
}
fn on_shutdown(_: &Application) {
unsafe {
std::mem::drop(packages::browse::PACKAGES_LIST.take());
std::mem::drop(packages::installed::PACKAGES_LIST.take());
}
}

128
src/packages/browse.rs Normal file
View file

@ -0,0 +1,128 @@
use gtk::{
prelude::{BoxExt, ButtonExt, Cast, EditableExt, ListBoxRowExt},
Button, Window,
};
use std::process::Command;
use gtk::{Align, ListBox, ScrolledWindow, SearchBar, SearchEntry};
pub static mut PACKAGES_LIST: Option<ListBox> = None;
pub fn browse() -> gtk::Box {
let packages_box = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.css_classes(["packages-box"])
.valign(Align::Center)
.halign(Align::Fill)
.hexpand(true)
.build();
let pkgs_search = SearchBar::builder()
.halign(Align::Fill)
.valign(Align::Start)
.css_classes(["search-bar"])
.build();
let pkgs_entry = SearchEntry::builder()
.css_classes(["entries"])
.halign(Align::Center)
.valign(Align::Start)
.width_request(600)
.placeholder_text("Search for a package...")
.sensitive(true)
.hexpand(true)
.build();
unsafe {
PACKAGES_LIST = Some(
ListBox::builder()
.css_classes(["packages-list"])
.valign(Align::Center)
.halign(Align::Fill)
.hexpand(true)
.build(),
)
};
// TODO: Make this part asynchronous so that the app opens faster
let pkg_list = String::from_utf8(
Command::new("dnf")
.args(["list", "--available"])
.output()
.unwrap()
.stdout,
)
.unwrap();
let pkg_list = pkg_list
.lines()
.skip(1)
.map(|x| {
x.split_whitespace()
.next()
.unwrap_or("")
.split(".")
.next()
.unwrap()
})
.filter(|x| !x.trim().is_empty());
for pkg in pkg_list {
let pkg_btn = Button::builder()
.label(pkg)
.css_classes(["package-name"])
.build();
pkg_btn.connect_clicked(|x| {
show_installed_package(x.label().map(|x| x.to_string()).unwrap_or("".to_owned()));
});
unsafe { PACKAGES_LIST.as_ref().unwrap().append(&pkg_btn) };
}
pkgs_entry.connect_search_changed(move |x| {
let x = x.clone();
// TODO: Possibly refactor to use `dnf search` instead of a filter function.
unsafe {
PACKAGES_LIST.as_ref().unwrap().set_filter_func(move |y| {
y.child()
.unwrap()
.downcast::<Button>()
.unwrap()
.label()
.map(|x| x.to_string())
.unwrap_or("".to_string())
.contains(x.text().to_string().as_str())
})
};
});
let pkg_listbox = ScrolledWindow::builder()
.css_classes(["package-list-scrollable"])
.valign(Align::Center)
.halign(Align::Center)
.width_request(800)
.height_request(600)
.build();
pkgs_search.connect_entry(&pkgs_entry);
packages_box.append(&pkgs_search);
packages_box.append(&pkgs_entry);
packages_box.append(&pkg_listbox);
pkg_listbox.set_child(Some(unsafe { PACKAGES_LIST.as_ref().unwrap() }));
dbg!(&pkg_listbox);
packages_box
}
fn show_installed_package(pkg: String) {
if pkg.is_empty() {
return;
}
let pkg_window = Window::builder().build();
}

126
src/packages/installed.rs Normal file
View file

@ -0,0 +1,126 @@
use gtk::{
prelude::{BoxExt, ButtonExt, Cast, EditableExt, ListBoxRowExt},
Button, Window,
};
use std::process::Command;
use gtk::{Align, ListBox, ScrolledWindow, SearchBar, SearchEntry};
pub static mut PACKAGES_LIST: Option<ListBox> = None;
pub fn installed() -> gtk::Box {
let packages_box = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.css_classes(["packages-box"])
.valign(Align::Center)
.halign(Align::Fill)
.hexpand(true)
.build();
let pkgs_search = SearchBar::builder()
.halign(Align::Fill)
.valign(Align::Start)
.css_classes(["search-bar"])
.build();
let pkgs_entry = SearchEntry::builder()
.css_classes(["entries"])
.halign(Align::Center)
.valign(Align::Start)
.width_request(600)
.placeholder_text("Search for a package...")
.sensitive(true)
.hexpand(true)
.build();
unsafe {
PACKAGES_LIST = Some(
ListBox::builder()
.css_classes(["packages-list"])
.valign(Align::Center)
.halign(Align::Fill)
.hexpand(true)
.build(),
)
};
// TODO: Make this part asynchronous so that the app opens faster
let pkg_list = String::from_utf8(
Command::new("dnf")
.args(["list", "--installed"])
.output()
.unwrap()
.stdout,
)
.unwrap();
let pkg_list = pkg_list
.lines()
.skip(1)
.map(|x| {
x.split_whitespace()
.next()
.unwrap_or("")
.split(".")
.next()
.unwrap()
})
.filter(|x| !x.trim().is_empty());
for pkg in pkg_list {
let pkg_btn = Button::builder()
.label(pkg)
.css_classes(["package-name"])
.build();
pkg_btn.connect_clicked(|x| {
show_installed_package(x.label().map(|x| x.to_string()).unwrap_or("".to_owned()));
});
unsafe { PACKAGES_LIST.as_ref().unwrap().append(&pkg_btn) };
}
pkgs_entry.connect_search_changed(move |x| {
let x = x.clone();
unsafe {
PACKAGES_LIST.as_ref().unwrap().set_filter_func(move |y| {
y.child()
.unwrap()
.downcast::<Button>()
.unwrap()
.label()
.map(|x| x.to_string())
.unwrap_or("".to_string())
.contains(x.text().to_string().as_str())
})
};
});
let pkg_listbox = ScrolledWindow::builder()
.css_classes(["package-list-scrollable"])
.valign(Align::Center)
.halign(Align::Center)
.width_request(800)
.height_request(600)
.build();
pkgs_search.connect_entry(&pkgs_entry);
packages_box.append(&pkgs_search);
packages_box.append(&pkgs_entry);
packages_box.append(&pkg_listbox);
pkg_listbox.set_child(Some(unsafe { PACKAGES_LIST.as_ref().unwrap() }));
dbg!(&pkg_listbox);
packages_box
}
fn show_installed_package(pkg: String) {
if pkg.is_empty() {
return;
}
let pkg_window = Window::builder().build();
}

30
src/packages/mod.rs Normal file
View file

@ -0,0 +1,30 @@
use gtk::{prelude::BoxExt, Align, Stack, StackSidebar};
pub mod browse;
pub mod installed;
pub fn packages() -> gtk::Box {
let packages_stack = Stack::builder()
.css_classes(["packages-stack"])
.valign(Align::Fill)
.halign(Align::Fill)
.hexpand(true)
.vexpand(true)
.build();
let packages_stack_sidebar = StackSidebar::builder()
.stack(&packages_stack)
.css_classes(["packages-stack-switcher"])
.build();
packages_stack.add_titled(&browse::browse(), Some("browse"), "Browse");
packages_stack.add_titled(&installed::installed(), Some("installed"), "Installed");
let packages_box = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
packages_box.append(&packages_stack_sidebar);
packages_box.append(&packages_stack);
packages_box
}

View file

@ -1,91 +1,13 @@
.sidebar {
margin: 10px;
background: none;
box-shadow: none;
border: none;
}
.sidebar button {
color: #ffffff;
background: #5c5c5c;
padding: 10px;
font-weight: bold;
margin: 10px;
font-size: 20px;
border-radius: 10px;
border: none;
}
.sidebar button:hover {
background: #2f5faa;
}
.sidebar button:checked {
background: #1f4e99;
}
.search-bar { .search-bar {
background: #ff0000; display: flex;
color: #ffffff; align-items: center;
justify-content: center;
margin-top: 10px;
margin-bottom: 10px;
} }
.entries { .package-list-scrollable {
color: black; padding: 10px;
border-radius: 10px;
background: #ffffff;
border: none;
font-size: 20px;
}
.label {
font-size: 14px;
}
.pkg-ls-btn, .pkg-ls-btn *, .pkgs-list, .pkgs-list *, .pkgs-categories, .pkgs-categories *, .bbox, .bbox * .pkg-ls-win {
font-size: 20px;
border-radius: 10px;
background: #2c2c2c;
}
.pkg-ls-btn:hover {
background: #3a3a3a;
}
.bbox *:hover, .bbox *:hover * {
background: #5c5c5c;
}
.pkg-ls-win {
background: #3c3c3c;
border-radius: 10px;
}
.opt {
margin: 10px;
}
.opt-box {
font-size: 20px;
}
.container-button {
font-size: 20px;
padding: 20px;
margin: 20px; margin: 20px;
border-radius: 10px; border-radius: 10px;
border: none;
background: #4c4c4c;
color: #ffffff;
}
.main {
background-color: #2f2f2f;
}
* {
color: #ffffff;
}
.bbox, .bbox:hover {
background: #2c2c2c;
} }