[calls] history-box: Cap size of slice at number of call records



commit b81b216cf08489dd540a778238d6a6a6a18a4184
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Wed Jul 27 16:54:26 2022 +0200

    history-box: Cap size of slice at number of call records
    
    This helps avoiding some log spam when scrolling to the bottom:
    
    16:29:17.1053      CallsHistoryBox[2798409]:   DEBUG: Increasing history slice from 1825 to 1875
    16:29:17.1215      CallsHistoryBox[2798409]:   DEBUG: Increasing history slice from 1875 to 1925
    16:29:20.6739      CallsHistoryBox[2798409]:   DEBUG: Increasing history slice from 1925 to 1975
    16:29:23.1919      CallsHistoryBox[2798409]:   DEBUG: Increasing history slice from 1975 to 2025
    16:29:24.2533      CallsHistoryBox[2798409]:   DEBUG: Increasing history slice from 2025 to 2075
    
    for a history of ~1400 records.

 src/calls-history-box.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/calls-history-box.c b/src/calls-history-box.c
index 6f6139ed..3e81d26e 100644
--- a/src/calls-history-box.c
+++ b/src/calls-history-box.c
@@ -48,6 +48,8 @@ struct _CallsHistoryBox {
   GListModel        *model;
   GtkSliceListModel *slice_model;
 
+  gsize              n_items;
+
   gulong             model_changed_handler_id;
 
 };
@@ -64,12 +66,16 @@ static GParamSpec *props[PROP_LAST_PROP];
 
 
 static void
-update (CallsHistoryBox *self)
+on_model_changed (GListModel      *model,
+                  guint            position,
+                  guint            removed,
+                  guint            added,
+                  CallsHistoryBox *self)
 {
   gchar *child_name;
 
-  if (g_list_model_get_n_items (self->model) == 0) {
- if (g_list_model_get_n_items (self->model) == 0)
+  self->n_items = self->n_items + added - removed;
+  if (self->n_items == 0)
     child_name = "empty";
   else
     child_name = "history";
@@ -153,6 +159,11 @@ on_adjustment_position_changed (GtkAdjustment   *adjustment,
   if (position > upper_limit - CALLS_HISTORY_INCREASE_N_PAGES_THRESHOLD * page_size) {
     guint new_size = old_size + CALLS_HISTORY_SIZE_INCREMENTS;
 
+    new_size = MIN (new_size, self->n_items);
+
+    if (old_size == new_size)
+      return;
+
     g_debug ("Increasing history slice from %u to %u",
              old_size, new_size);
     gtk_slice_list_model_set_size (self->slice_model, new_size);
@@ -195,8 +206,10 @@ constructed (GObject *object)
                                                 CALLS_HISTORY_SIZE_INITIAL);
 
   self->model_changed_handler_id =
-    g_signal_connect_swapped
-      (self->model, "items-changed", G_CALLBACK (update), self);
+    g_signal_connect (self->model,
+                      "items-changed",
+                      G_CALLBACK (on_model_changed),
+                      self);
   g_assert (self->model_changed_handler_id != 0);
 
   gtk_list_box_bind_model (self->history,
@@ -205,7 +218,7 @@ constructed (GObject *object)
                            self,
                            NULL);
 
-  update (self);
+  on_model_changed (self->model, 0, 0, g_list_model_get_n_items (self->model), self);
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]