Skip to content

Commit

Permalink
Indicate filtering in trust file count (#839)
Browse files Browse the repository at this point in the history
Trust file list count indicator will now display `X / total` when `0 > X < total`.

Closes #803
  • Loading branch information
egbicker authored Apr 1, 2023
1 parent e5ca9eb commit a09fe41
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
49 changes: 49 additions & 0 deletions fapolicy_analyzer/tests/test_trust_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,52 @@ def test_epoch_to_string():

# Verify a NULL string input outputs "Missing"
assert epoch_to_string(None) == "Missing"


def test_tree_count_full(widget, mocker):
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.ThreadPoolExecutor",
return_value=MagicMock(submit=lambda x: x()),
)
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(2)
widget.append_trust(_trust)
refresh_gui(delay=0.5)
assert widget.treeCount.get_text() == "2 files"


def test_tree_count_empty(widget, mocker):
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.ThreadPoolExecutor",
return_value=MagicMock(submit=lambda x: x()),
)
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(0)
widget.append_trust([])
refresh_gui(delay=0.5)
assert widget.treeCount.get_text() == "0 files"


def test_tree_count_partial(widget, mocker):
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.ThreadPoolExecutor",
return_value=MagicMock(submit=lambda x: x()),
)
mocker.patch(
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(2)
widget.append_trust(_trust)
refresh_gui(delay=0.5)
viewFilter = widget.get_object("search")
viewFilter.set_text("foo")
widget.on_search_activate()
refresh_gui(delay=0.3)
assert widget.treeCount.get_text() == "1 / 2 files"
7 changes: 5 additions & 2 deletions fapolicy_analyzer/ui/trust_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, trust_func, markup_func=None, *args):
self.refresh()
self.selection_changed += self.__handle_selection_changed
self.get_ref().connect("destroy", self.on_destroy)
self.total = 0

def __handle_selection_changed(self, data):
trust = [datum[3] for datum in data] if data else None
Expand Down Expand Up @@ -117,8 +118,9 @@ def txt_color_func(col, renderer, model, iter, *args):
return [trustColumn, mtimeColumn, fileColumn]

def _update_list_status(self, count):
label = FILE_LABEL if count == 1 else FILES_LABEL
super()._update_list_status(" ".join([str(count), label]))
label = FILE_LABEL if self.total == 1 else FILES_LABEL
denom_str = "" if count == 0 or count == self.total else " ".join(["/", str(self.total)])
super()._update_list_status(" ".join([str(count), denom_str, label]))

def _update_loading_status(self, status):
super()._update_list_status(status)
Expand Down Expand Up @@ -178,6 +180,7 @@ def process_rows(queue, total):
self.search.set_sensitive(False)
self.search.set_tooltip_text(FILTERING_DISABLED_DURING_LOADING_MESSAGE)
self.__queue = Queue()
self.total = count_of_trust_entries
GLib.timeout_add(200, process_rows, self.__queue, count_of_trust_entries)

def append_trust(self, trust):
Expand Down

0 comments on commit a09fe41

Please sign in to comment.