Skip to content

Commit

Permalink
ProcessInfoView ported
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Nov 24, 2023
1 parent 3961863 commit 3783fd3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
24 changes: 11 additions & 13 deletions src/Services/Appearance.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@ public class Monitor.Appearance : Object {
bool is_dark = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
gtk_settings.gtk_application_prefer_dark_theme = is_dark;


var provider = new Gtk.CssProvider ();

if (is_dark) {
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-dark.css");
} else {
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-light.css");
}

// @TODO: Fix styles
// Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
load_style (is_dark);

// We listen to changes in Granite.Settings and update our app if the user changes their preference
granite_settings.notify["prefers-color-scheme"].connect (() => {
is_dark = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
gtk_settings.gtk_application_prefer_dark_theme = is_dark;
load_style (is_dark);
});
}

private static void load_style (bool is_dark) {
var provider = new Gtk.CssProvider ();

if (is_dark) {
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-dark.css");
} else {
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-light.css");
}
});
// @TODO: Fix styles
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

}

public static void retrofit () {
Expand All @@ -39,7 +37,7 @@ public class Monitor.Appearance : Object {
var provider = new Gtk.CssProvider ();
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-retrofit.css");
// @TODO: Fix retrofitting styles
// Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
}
19 changes: 10 additions & 9 deletions src/Views/ProcessView/ProcessInfoView/Preventor.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Monitor.Preventor : Gtk.Stack {
public class Monitor.Preventor : Gtk.Box {
private Gtk.Box preventive_action_bar;
private Gtk.Label confirmation_label;
private Gtk.Button confirm_button;
Expand Down Expand Up @@ -33,26 +33,27 @@ public class Monitor.Preventor : Gtk.Stack {

public Preventor (Gtk.Widget _child, string name) {
child_widget = _child;
add_named (child_widget, name);
add_named (preventive_action_bar, "preventive_action_bar");
append (child_widget);
append (preventive_action_bar);

deny_button.clicked.connect (() => {
set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
set_visible_child (child_widget);
// set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
// set_visible_child (child_widget);
confirmed (false);
});

confirm_button.clicked.connect (() => {
set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
set_visible_child (child_widget);
// set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
// set_visible_child (child_widget);
confirmed (true);
});
}

public void set_prevention (string confirmation_text) {
set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN);
// set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN);
confirmation_label.set_text (_(confirmation_text));
set_visible_child (preventive_action_bar);
// set_visible_child (preventive_action_bar);
preventive_action_bar.visible = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Monitor.ProcessInfoHeader : Gtk.Grid {

construct {
column_spacing = 12;
width_request = 270;

/* *INDENT-OFF* */
regex = /(?i:^.*\.(xpm|png)$)/; // vala-lint=space-before-paren,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid {
row_spacing = 6;
column_homogeneous = true;
row_homogeneous = false;
width_request = 270;
vexpand = true;

var opened_files_label = create_label (_("Opened files"));
opened_files_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);
Expand Down Expand Up @@ -52,7 +54,7 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid {
var open_files_tree_view_scrolled = new Gtk.ScrolledWindow ();
open_files_tree_view = new OpenFilesTreeView (model);
open_files_tree_view_scrolled.set_child (open_files_tree_view);
attach (open_files_tree_view_scrolled, 0, 4, 3, 1);
// attach (open_files_tree_view_scrolled, 0, 4, 3, 1);
}

public void update (Process process) {
Expand Down
49 changes: 23 additions & 26 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
public class Monitor.ProcessInfoView : Gtk.Box {
// private Preventor preventor;
private ProcessInfoIOStats process_info_io_stats = new ProcessInfoIOStats ();

private Process _process;
Expand All @@ -20,7 +19,8 @@ public class Monitor.ProcessInfoView : Gtk.Box {
if (_process.uid != Posix.getuid ()) {
process_info_cpu_ram.hide ();
process_info_io_stats.hide ();
// preventor.hide ();
end_process_button.hide ();
kill_process_button.hide ();
} else {
_process.fd_permission_error.connect (show_permission_error_infobar);

Expand All @@ -32,7 +32,11 @@ public class Monitor.ProcessInfoView : Gtk.Box {
permission_error_infobar.revealed = false;

process_info_io_stats.open_files_tree_view.model.process = _process;
// process_info_io_stats.open_files_tree_view.show_all ();
process_info_io_stats.open_files_tree_view.set_visible (true);
process_info_cpu_ram.set_visible (true);
process_info_io_stats.set_visible (true);
end_process_button.show ();
kill_process_button.show ();
}
}
}
Expand All @@ -56,7 +60,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
permission_error_infobar.revealed = false;
permission_error_label = new Gtk.Label (Utils.NO_DATA);
permission_error_infobar.add_child (permission_error_label);
append (permission_error_infobar);
// append (permission_error_infobar);

var grid = new Gtk.Grid () {
margin_start = 12,
Expand All @@ -82,52 +86,45 @@ public class Monitor.ProcessInfoView : Gtk.Box {
grid.attach (separator, 0, 1, 1, 1);

process_info_cpu_ram = new ProcessInfoCPURAM ();
process_info_cpu_ram.hide ();
grid.attach (process_info_cpu_ram, 0, 2, 1, 1);

grid.attach (process_info_io_stats, 0, 4, 1, 1);


var process_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
process_action_bar.margin_top = 12;
process_action_bar.valign = Gtk.Align.END;
process_action_bar.halign = Gtk.Align.END;
var process_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
margin_top = 12,
margin_bottom = 12,
margin_end = 12,
valign = Gtk.Align.END,
halign = Gtk.Align.END
};

end_process_button = new Gtk.Button.with_label (_("End Process"));
end_process_button.margin_end = 10;
end_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>E" }, _("End selected process"));
var end_process_button_context = end_process_button.get_style_context ();
// end_process_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
end_process_button_context.add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

kill_process_button = new Gtk.Button.with_label (_("Kill Process"));
kill_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>K" }, _("Kill selected process"));
var kill_process_button_context = kill_process_button.get_style_context ();
// kill_process_button_context.add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
kill_process_button_context.add_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);

process_action_bar.append (end_process_button);
process_action_bar.append (kill_process_button);

// preventor = new Preventor (process_action_bar, "process_action_bar");
append (grid);
append (process_action_bar);


kill_process_button.clicked.connect (() => {
// preventor.set_prevention (_("Confirm kill of the process?"));
// preventor.confirmed.connect ((is_confirmed) => {
// if (is_confirmed) process.kill (); // maybe add a toast that process killed
// });
process.kill (); // maybe add a toast that process killed
});

end_process_button.clicked.connect (() => {
// preventor.set_prevention (_("Confirm end of the process?"));
// preventor.confirmed.connect ((is_confirmed) => {
// if (is_confirmed) process.end (); // maybe add a toast that process ended
// });
process.end (); // maybe add a toast that process ended
});

// grid.attach (preventor, 0, 5, 1, 1);

process_info_cpu_ram.hide ();
process_info_io_stats.hide ();
// preventor.hide ();
}

private void show_permission_error_infobar (string error) {
Expand All @@ -144,7 +141,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
process_info_io_stats.update (process);

process_info_io_stats.open_files_tree_view.model.process = _process;
// process_info_io_stats.open_files_tree_view.show_all ();
process_info_io_stats.open_files_tree_view.set_visible (true);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Views/ProcessView/ProcessView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Monitor.ProcessView : Gtk.Box {

// hide on startup
// process_info_view.no_show_all = true;
treeview_model = TreeViewModel.get_default ();
treeview_model = TreeViewModel.get_default ();

process_tree_view = new CPUProcessTreeView (treeview_model);
process_tree_view.process_selected.connect ((process) => on_process_selected (process));
Expand All @@ -22,7 +22,8 @@ public class Monitor.ProcessView : Gtk.Box {
paned.set_start_child (process_tree_view_scrolled);
paned.set_end_child (process_info_view);
paned.set_shrink_end_child (false);
paned.set_position (paned.max_position);
paned.set_resize_end_child (false);
paned.set_position (paned.max_position - 200);
paned.set_hexpand (true);

append (paned);
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/Headerbar/Search.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Monitor.Search : Gtk.Box {
// process_tree_view.set_model (filter_model);

var sort_model = new Gtk.TreeModelSort.with_model (filter_model);
process_tree_view.set_model (sort_model);
// process_tree_view.set_model (sort_model);
append (search_entry);
}

Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ source_app_files = [
'Views/ContainerView/ContainerInfoView/ContainerInfoCharts.vala',

# Widgets related only to ProcessInfoView
# 'Views/ProcessView/ProcessInfoView/Preventor.vala',
'Views/ProcessView/ProcessInfoView/Preventor.vala',
'Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala',
'Views/ProcessView/ProcessInfoView/ProcessInfoCPURAM.vala',
'Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala',
Expand Down

0 comments on commit 3783fd3

Please sign in to comment.