port to libadwaita

This commit is contained in:
Ward Nakchbandi (Cosmic Fusion) 2023-07-02 14:59:49 +03:00
parent 5434b0b8c6
commit 96509df38e
3 changed files with 29 additions and 18 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "pika-drivers" name = "pika-drivers"
version = "0.3.2" version = "0.4.0"
edition = "2021" 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

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
pika-drivers (0.3.2-99pika1.lunar) lunar; urgency=medium pika-drivers (0.4.0-99pika1.lunar) lunar; urgency=medium
* initial release * initial release

View File

@ -2,14 +2,17 @@ use std::process::Command;
use std::thread; use std::thread;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::*; use gtk::*;
use gtk::prelude::*;
use glib::*; use glib::*;
use adw::*;
use gdk::Display; use gdk::Display;
use adw::prelude::*;
const PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION"); const PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() { fn main() {
let application = gtk::Application::new(Some("com.pika.drivers"), Default::default()); let application = adw::Application::new(Some("com.pika.drivers"), Default::default());
application.connect_startup(|app| { application.connect_startup(|app| {
// The CSS "magic" happens here. // The CSS "magic" happens here.
let provider = CssProvider::new(); let provider = CssProvider::new();
@ -29,13 +32,19 @@ fn main() {
} }
fn build_ui(app: &gtk::Application) { fn build_ui(app: &adw::Application) {
gtk::glib::set_prgname(Some("Pika Drivers")); gtk::glib::set_prgname(Some("Pika Drivers"));
glib::set_application_name("Pika Drivers"); glib::set_application_name("Pika Drivers");
let glib_settings = gio::Settings::new("com.pika.drivers"); let glib_settings = gio::Settings::new("com.pika.drivers");
let content_box = gtk::Box::builder()
.orientation(Orientation::Vertical)
.vexpand(true)
.hexpand(true)
.build();
let loading_box = gtk::Box::builder() let loading_box = gtk::Box::builder()
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.margin_top(20) .margin_top(20)
@ -46,7 +55,6 @@ fn build_ui(app: &gtk::Application) {
.hexpand(true) .hexpand(true)
.build(); .build();
let loading_icon = gtk::Image::builder() let loading_icon = gtk::Image::builder()
.icon_name("pika-drivers") .icon_name("pika-drivers")
.margin_top(20) .margin_top(20)
@ -83,10 +91,10 @@ fn build_ui(app: &gtk::Application) {
loading_box.append(&loading_spinner); loading_box.append(&loading_spinner);
loading_box.append(&loading_label); loading_box.append(&loading_label);
let window = gtk::ApplicationWindow::builder() let window = adw::ApplicationWindow::builder()
.title("PikaOS Driver Manager") .title("PikaOS Driver Manager")
.application(app) .application(app)
.child(&loading_box) .content(&content_box)
.icon_name("pika-drivers") .icon_name("pika-drivers")
.default_width(glib_settings.int("window-width")) .default_width(glib_settings.int("window-width"))
.default_height(glib_settings.int("window-height")) .default_height(glib_settings.int("window-height"))
@ -142,8 +150,8 @@ fn build_ui(app: &gtk::Application) {
credits_frame.set_label(Some(PROJECT_VERSION)); credits_frame.set_label(Some(PROJECT_VERSION));
let credits_window = gtk::Window::builder() let credits_window = adw::Window::builder()
.child(&credits_window_box) .content(&credits_window_box)
.transient_for(&window) .transient_for(&window)
.resizable(false) .resizable(false)
.hide_on_close(true) .hide_on_close(true)
@ -151,11 +159,13 @@ fn build_ui(app: &gtk::Application) {
.startup_id("pika-drivers") .startup_id("pika-drivers")
.build(); .build();
credits_window_box.append(&gtk::HeaderBar::builder().show_title_buttons(true).build());
credits_window_box.append(&credits_icon); credits_window_box.append(&credits_icon);
credits_window_box.append(&credits_label); credits_window_box.append(&credits_label);
credits_window_box.append(&credits_frame); credits_window_box.append(&credits_frame);
window.set_titlebar(Some(&window_title_bar)); content_box.append(&window_title_bar);
content_box.append(&loading_box);
window_title_bar.pack_end(&credits_button.clone()); window_title_bar.pack_end(&credits_button.clone());
@ -185,9 +195,9 @@ fn build_ui(app: &gtk::Application) {
receiver.attach( receiver.attach(
None, None,
clone!(@weak window => @default-return Continue(false), clone!(@weak content_box => @default-return Continue(false),
move |sent_output| { move |sent_output| {
get_drivers(&window, sent_output); get_drivers(&content_box, &loading_box, sent_output);
Continue(true) Continue(true)
} }
), ),
@ -197,7 +207,7 @@ fn build_ui(app: &gtk::Application) {
} }
fn modify_package(package: &str, driver_button: &Image) { fn modify_package(package: &str, driver_button: &gtk::Image) {
let str_pkg = package.to_string(); let str_pkg = package.to_string();
println!("Start installing driver {}: ", package); println!("Start installing driver {}: ", package);
let wrapper_command = Command::new("x-terminal-emulator") let wrapper_command = Command::new("x-terminal-emulator")
@ -237,7 +247,7 @@ fn modify_package(package: &str, driver_button: &Image) {
} }
} }
fn driver_button_refresh(driver: &str, driver_button: &Image) { fn driver_button_refresh(driver: &str, driver_button: &gtk::Image) {
let driver_command = Command::new("dpkg") let driver_command = Command::new("dpkg")
.args(["-s", driver]) .args(["-s", driver])
.output() .output()
@ -261,7 +271,7 @@ fn driver_button_refresh(driver: &str, driver_button: &Image) {
} }
} }
fn get_drivers(main_window: &ApplicationWindow, ubuntu_drivers_list_utf8: String) { fn get_drivers(main_window: &gtk::Box, loading_box: &gtk::Box, ubuntu_drivers_list_utf8: String) {
let main_box = gtk::Box::builder() let main_box = gtk::Box::builder()
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.build(); .build();
@ -447,12 +457,13 @@ fn get_drivers(main_window: &ApplicationWindow, ubuntu_drivers_list_utf8: String
driver_button.connect_clicked(clone!(@weak driver_button => move |_| modify_package(&driver_string, &driver_button_icon))); driver_button.connect_clicked(clone!(@weak driver_button => move |_| modify_package(&driver_string, &driver_button_icon)));
main_window.set_child(Some(&window_box)); main_window.remove(loading_box);
main_window.append(&window_box);
} }
} }
fn save_window_size(window: &ApplicationWindow, glib_settings: &gio::Settings) { fn save_window_size(window: &adw::ApplicationWindow, glib_settings: &gio::Settings) {
let size = window.default_size(); let size = window.default_size();