From 4b097b45426039a6431e536673fd6f59d33515d9 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Thu, 16 Apr 2020 13:05:07 +1000 Subject: [PATCH] Components.InspectorLogView: Add sidebar listing accounts & log domains Adds a sidebar that displays accounts and logging domains, grouped into accounts, internal domains, and external domains. --- .../components-inspector-log-view.vala | 99 +++++++++++++++++++ ui/components-inspector-log-view.ui | 99 +++++++++++++------ ui/geary.css | 10 ++ 3 files changed, 180 insertions(+), 28 deletions(-) diff --git a/src/client/components/components-inspector-log-view.vala b/src/client/components/components-inspector-log-view.vala index f3c401ad..351d457e 100644 --- a/src/client/components/components-inspector-log-view.vala +++ b/src/client/components/components-inspector-log-view.vala @@ -15,6 +15,37 @@ public class Components.InspectorLogView : Gtk.Grid { private const int COL_MESSAGE = 0; + private class SidebarRow : Gtk.ListBoxRow { + + public enum RowType { ACCOUNT, INTERNAL_DOMAIN, EXTERNAL_DOMAIN } + + + public RowType row_type { get; private set; } + public string id { get; private set; } + + internal Gtk.CheckButton enabled = new Gtk.CheckButton(); + + + public SidebarRow(RowType type, string label, string id) { + this.row_type = type; + this.id = id; + + var label_widget = new Gtk.Label(label); + label_widget.hexpand = true; + label_widget.xalign = 0.0f; + + var grid = new Gtk.Grid(); + grid.orientation = HORIZONTAL; + grid.add(label_widget); + grid.add(this.enabled); + add(grid); + + show_all(); + } + + } + + /** Determines if the log record search user interface is shown. */ public bool search_mode_enabled { get { return this.search_bar.search_mode_enabled; } @@ -27,6 +58,9 @@ public class Components.InspectorLogView : Gtk.Grid { [GtkChild] private Gtk.SearchEntry search_entry { get; private set; } + [GtkChild] + private Gtk.ListBox sidebar; + [GtkChild] private Gtk.ScrolledWindow logs_scroller; @@ -49,6 +83,10 @@ public class Components.InspectorLogView : Gtk.Grid { private bool autoscroll = true; + private Gee.Set seen_accounts = new Gee.HashSet(); + + private Gee.Set seen_domains = new Gee.HashSet(); + private Geary.AccountInformation? account_filter = null; private bool listener_installed = false; @@ -68,6 +106,7 @@ public class Components.InspectorLogView : Gtk.Grid { ); this.search_bar.connect_entry(this.search_entry); + this.sidebar.set_header_func(this.sidebar_header_update); this.account_filter = filter_by; } @@ -210,8 +249,56 @@ public class Components.InspectorLogView : Gtk.Grid { } } + private void add_account(Geary.AccountInformation account) { + if (this.seen_accounts.add(account.id)) { + var row = new SidebarRow(ACCOUNT, account.display_name, account.id); + for (int i = 0;; i++) { + var existing = this.sidebar.get_row_at_index(i) as SidebarRow; + if (existing == null || + existing.row_type != ACCOUNT || + existing.id.collate(row.id) > 0) { + this.sidebar.insert(row, i); + break; + } + } + } + } + + private void add_domain(string? domain) { + var safe_domain = domain ?? "(none)"; + if (this.seen_domains.add(domain)) { + var type = ( + safe_domain.down().has_prefix(Geary.Logging.DOMAIN.down()) + ? SidebarRow.RowType.INTERNAL_DOMAIN + : SidebarRow.RowType.EXTERNAL_DOMAIN + ); + var row = new SidebarRow(type, safe_domain, safe_domain); + int i = 0; + for (;; i++) { + var existing = this.sidebar.get_row_at_index(i) as SidebarRow; + if (existing == null || + existing.row_type == type) { + break; + } + } + for (;; i++) { + var existing = this.sidebar.get_row_at_index(i) as SidebarRow; + if (existing == null || + existing.row_type != type || + existing.id.collate(row.id) > 0) { + this.sidebar.insert(row, i); + break; + } + } + } + } + private inline bool should_append(Geary.Logging.Record record) { record.fill_well_known_sources(); + if (record.account != null) { + add_account(record.account.information); + } + add_domain(record.domain); return ( record.account == null || this.account_filter == null || @@ -239,6 +326,18 @@ public class Components.InspectorLogView : Gtk.Grid { } } + private void sidebar_header_update(Gtk.ListBoxRow current_row, + Gtk.ListBoxRow? previous_row) { + Gtk.Widget? header = null; + var current = current_row as SidebarRow; + var previous = previous_row as SidebarRow; + if (current != null && + (previous == null || current.row_type != previous.row_type)) { + header = new Gtk.Separator(HORIZONTAL); + } + current_row.set_header(header); + } + [GtkCallback] private void on_logs_size_allocate() { if (this.autoscroll) { diff --git a/ui/components-inspector-log-view.ui b/ui/components-inspector-log-view.ui index e72c39b0..d2dd568e 100644 --- a/ui/components-inspector-log-view.ui +++ b/ui/components-inspector-log-view.ui @@ -1,5 +1,5 @@ - + @@ -33,45 +33,85 @@ - - - 0 - 0 - + + + 0 + 0 + - + True - True - True - in + False - + True True - logs_store - False - False - False - - - - multiple - - - + never + in - - column + + True + False - - - 0 - + + True + False + False + none + + + + 0 + 0 + + + + + True + True + True + True + in + + + True + True + logs_store + False + False + False + + + + multiple + + + + + + column + + + + 0 + + + + + + + + + 1 + 0 + @@ -79,5 +119,8 @@ 1 + diff --git a/ui/geary.css b/ui/geary.css index de4a51e6..355882e6 100644 --- a/ui/geary.css +++ b/ui/geary.css @@ -327,3 +327,13 @@ treeview.sidebar:drop(active).into { border-top-style: solid; border-bottom-style: solid; } + +/* Inspector */ + +.geary-inspector-log-viewer .sidebar row > grid { + padding: 0 6px; +} + +.geary-inspector-log-viewer .sidebar row > grid * { + margin: 4px; +}