Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gtk4, toml and sysinfo dependencies version #207

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
581 changes: 345 additions & 236 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ readme = "README.md"
keywords = ["GUI", "process", "viewer", "gtk"]

[dependencies]
gtk = { version = "0.7", package = "gtk4" }
sysinfo = "0.28.2"
gtk = { version = "0.8", package = "gtk4" }
sysinfo = "0.30"
libc = "0.2"
serde = "1.0"
serde_derive = "1.0"
toml = "0.5"
toml = "0.8"
async-channel = "2.2.1"
26 changes: 9 additions & 17 deletions src/display_disk.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::{Arc, Mutex};

use crate::utils::format_number;

use gtk::glib;
use gtk::prelude::*;

use sysinfo::{DiskExt, SystemExt};

struct DiskInfo {
label: gtk::Label,
progress: gtk::ProgressBar,
Expand Down Expand Up @@ -76,7 +73,7 @@ fn refresh_disks(container: &gtk::Box, disks: &[sysinfo::Disk], elems: &mut Vec<
}
}

pub fn create_disk_info(sys: &Arc<Mutex<sysinfo::System>>, stack: &gtk::Stack) {
pub fn create_disk_info(stack: &gtk::Stack) {
let elems: Rc<RefCell<Vec<DiskInfo>>> = Rc::new(RefCell::new(Vec::new()));
let vertical_layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
let container = gtk::Box::new(gtk::Orientation::Vertical, 0);
Expand All @@ -86,24 +83,19 @@ pub fn create_disk_info(sys: &Arc<Mutex<sysinfo::System>>, stack: &gtk::Stack) {
.child(&container)
.build();

let disks = RefCell::new(sysinfo::Disks::new_with_refreshed_list());

refresh_disks(&container, &disks.borrow(), &mut elems.borrow_mut());

let refresh_but = gtk::Button::with_label("Refresh disks");

refresh_but.connect_clicked(
glib::clone!(@weak sys, @weak container, @strong elems => move |_| {
let mut sys = sys.lock().expect("failed to lock to refresh disks");
sys.refresh_disks();
refresh_disks(&container, sys.disks(), &mut elems.borrow_mut());
}),
);
refresh_but.connect_clicked(glib::clone!(@weak container, @strong elems => move |_| {
disks.borrow_mut().refresh_list();
refresh_disks(&container, &disks.borrow(), &mut elems.borrow_mut());
}));

vertical_layout.append(&scroll);
vertical_layout.append(&refresh_but);

stack.add_titled(&vertical_layout, Some("Disks"), "Disks");

refresh_disks(
&container,
sys.lock().expect("failed to lock to get disks").disks(),
&mut elems.borrow_mut(),
);
}
28 changes: 14 additions & 14 deletions src/display_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::network_dialog::{self, NetworkDialog};
use crate::utils::{format_number, format_number_full};
use gtk::glib;
use gtk::prelude::*;
use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
use sysinfo::Networks;

use std::cell::RefCell;
use std::collections::HashSet;
Expand Down Expand Up @@ -41,13 +41,12 @@ fn append_column(

pub struct Network {
list_store: gtk::ListStore,
pub filter_entry: gtk::SearchEntry,
pub search_bar: gtk::SearchBar,
dialogs: Rc<RefCell<Vec<NetworkDialog>>>,
}

impl Network {
pub fn new(stack: &gtk::Stack, sys: &Arc<Mutex<System>>) -> Network {
pub fn new(stack: &gtk::Stack, networks: &Arc<Mutex<Networks>>) -> Self {
let tree = gtk::TreeView::builder().headers_visible(true).build();
let scroll = gtk::ScrolledWindow::builder().child(&tree).build();
let info_button = gtk::Button::builder()
Expand Down Expand Up @@ -99,7 +98,7 @@ impl Network {
// The filter model
let filter_model = gtk::TreeModelFilter::new(&list_store, None);
filter_model.set_visible_func(
glib::clone!(@weak filter_entry => @default-return false, move |model, iter| {
glib::clone!(@strong filter_entry => @default-return false, move |model, iter| {
if !WidgetExt::is_visible(&filter_entry) {
return true;
}
Expand Down Expand Up @@ -173,19 +172,19 @@ impl Network {

let dialogs = Rc::new(RefCell::new(Vec::new()));

info_button.connect_clicked(glib::clone!(@weak dialogs, @weak sys => move |_| {
info_button.connect_clicked(glib::clone!(@weak dialogs, @weak networks => move |_| {
let current_network = current_network.borrow();
if let Some(ref interface_name) = *current_network {
create_network_dialog(
&mut dialogs.borrow_mut(),
interface_name,
&sys.lock().expect("failed to lock for new network dialog"),
&networks.lock().expect("failed to lock for new network dialog"),
);
}
}));

tree.connect_row_activated(
glib::clone!(@weak sys, @weak dialogs => move |tree_view, path, _| {
glib::clone!(@weak networks, @weak dialogs => move |tree_view, path, _| {
let model = tree_view.model().expect("couldn't get model");
let iter = model.iter(path).expect("couldn't get iter");
let interface_name = model.get_value(&iter, 0)
Expand All @@ -194,26 +193,24 @@ impl Network {
create_network_dialog(
&mut dialogs.borrow_mut(),
&interface_name,
&sys.lock().expect("failed to lock for new network dialog (from tree)"),
&networks.lock().expect("failed to lock for new network dialog (from tree)"),
);
}),
);

Network {
list_store,
filter_entry,
search_bar,
dialogs,
}
}

pub fn update_networks(&mut self, sys: &System) {
pub fn update_networks(&mut self, networks: &Networks) {
// first part, deactivate sorting
let sorted = TreeSortableExtManual::sort_column_id(&self.list_store);
self.list_store.set_unsorted();

let mut seen: HashSet<String> = HashSet::new();
let networks = sys.networks();

if let Some(iter) = self.list_store.iter_first() {
let mut valid = true;
Expand Down Expand Up @@ -319,15 +316,18 @@ fn create_and_fill_model(
);
}

fn create_network_dialog(dialogs: &mut Vec<NetworkDialog>, interface_name: &str, sys: &System) {
fn create_network_dialog(
dialogs: &mut Vec<NetworkDialog>,
interface_name: &str,
networks: &Networks,
) {
for dialog in dialogs.iter() {
if dialog.name == interface_name {
dialog.show();
return;
}
}
if let Some((_, data)) = sys
.networks()
if let Some((_, data)) = networks
.iter()
.find(|(name, _)| name.as_str() == interface_name)
{
Expand Down
6 changes: 3 additions & 3 deletions src/display_procs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gtk::glib;
use gtk::prelude::*;

use sysinfo::{Pid, PidExt, Process, ProcessExt};
use sysinfo::{Pid, Process};

use crate::utils::format_number;

Expand Down Expand Up @@ -42,6 +42,7 @@ impl Procs {
.margin_top(6)
.margin_bottom(6)
.margin_end(6)
.margin_start(6)
.sensitive(false)
.build();

Expand Down Expand Up @@ -80,8 +81,7 @@ impl Procs {
for pro in proc_list.values() {
if let Some(exe) = pro
.exe()
.file_name()
.and_then(|f| f.to_str())
.and_then(|exe| exe.file_name().and_then(|f| f.to_str()))
.or_else(|| Some(pro.name()))
{
create_and_fill_model(
Expand Down
20 changes: 12 additions & 8 deletions src/display_sysinfo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use gtk::glib;
use gtk::prelude::*;
use sysinfo::{ComponentExt, CpuExt, SystemExt};

use std::cell::RefCell;
use std::iter;
Expand Down Expand Up @@ -71,6 +70,7 @@ pub struct DisplaySysInfo {
impl DisplaySysInfo {
pub fn new(
sys: &Arc<Mutex<sysinfo::System>>,
sys_components: &sysinfo::Components,
stack: &gtk::Stack,
settings: &Settings,
) -> DisplaySysInfo {
Expand Down Expand Up @@ -192,13 +192,13 @@ impl DisplaySysInfo {
//
// TEMPERATURES PART
//
if !sys.components().is_empty() {
if !sys_components.is_empty() {
check_box3 = Some(create_header(
"Components' temperature",
&vertical_layout,
settings.display_graph,
));
for component in sys.components() {
for component in sys_components {
let horizontal_layout = gtk::Box::new(gtk::Orientation::Horizontal, 10);
// TODO: add max and critical temperatures as well
let temp = gtk::Label::new(Some(&format!("{:.1} °C", component.temperature())));
Expand Down Expand Up @@ -273,7 +273,7 @@ impl DisplaySysInfo {
temperature_usage_history,
temperature_check_box: check_box3,
};
tmp.update_system_info(&sys, settings.display_fahrenheit);
tmp.update_system_info(&sys, sys_components, settings.display_fahrenheit);
tmp
}

Expand All @@ -285,7 +285,12 @@ impl DisplaySysInfo {
}
}

pub fn update_system_info(&mut self, sys: &sysinfo::System, display_fahrenheit: bool) {
pub fn update_system_info(
&mut self,
sys: &sysinfo::System,
sys_components: &sysinfo::Components,
display_fahrenheit: bool,
) {
let disp = |total, used| {
format!(
"{} / {}",
Expand Down Expand Up @@ -337,8 +342,7 @@ impl DisplaySysInfo {

// temperature part
let t = self.temperature_usage_history.borrow_mut();
for (pos, (component, label)) in sys
.components()
for (pos, (component, label)) in sys_components
.iter()
.zip(self.components.iter())
.enumerate()
Expand Down Expand Up @@ -385,7 +389,7 @@ impl DisplaySysInfo {
}
}

pub fn show_if_necessary<U: gtk::glib::IsA<gtk::CheckButton>, T: WidgetExt>(
pub fn show_if_necessary<U: gtk::glib::object::IsA<gtk::CheckButton>, T: WidgetExt>(
check_box: &U,
proc_horizontal_layout: &GraphWidget,
non_graph_layout: &T,
Expand Down
Loading
Loading