static GSList *
add_new_days_to_cache (LogviewLog *log, const char **new_lines, guint lines_offset)
{
  GSList *new_days, *l, *last_cached;
  int res;
  Day *day, *last;

  new_days = log_read_dates (new_lines, log->priv->file_time);

  /* the days are stored in chronological order, so we compare the last cached
   * one with the new we got.
   */
  last_cached = g_slist_last (log->priv->days);

  if (!last_cached) {
    /* this means the day list is empty (i.e. we're on the first read */
    log->priv->days = logview_utils_day_list_copy (new_days);
    return new_days;
  }

  for (l = new_days; l; l = l->next) {
    res = days_compare (l->data, last_cached->data);
    day = l->data;

    if (res > 0) {
      /* this day in the list is newer than the last one, append to
       * the cache.
       */
      day->first_line += lines_offset;
      day->last_line += lines_offset;
      log->priv->days = g_slist_append (log->priv->days, logview_utils_day_copy (day));
    } else if (res == 0) {
      last = last_cached->data;
 
      /* update the lines number */
      last->last_line += day->last_line;
    }
  }

  return new_days;
}
Beispiel #2
0
static int
loglist_sort_func (GtkTreeModel *model,
                   GtkTreeIter *a,
                   GtkTreeIter *b,
                   gpointer user_data)
{
  char *name_a, *name_b;
  Day *day_a, *day_b;
  int retval = 0;

  switch (gtk_tree_store_iter_depth (GTK_TREE_STORE (model), a)) {
    case 0:
      gtk_tree_model_get (model, a, LOG_NAME, &name_a, -1);
      gtk_tree_model_get (model, b, LOG_NAME, &name_b, -1);
      retval = g_utf8_collate (name_a, name_b);
      g_free (name_a);
      g_free (name_b);

      break;
    case 1:
      gtk_tree_model_get (model, a, LOG_DAY, &day_a, -1);
      gtk_tree_model_get (model, b, LOG_DAY, &day_b, -1);
      if (day_a && day_b) {
        retval = days_compare (day_a, day_b);
      } else {
        retval = 0;
      }

      break;
    default:
      g_assert_not_reached ();

      break;
  }

  return retval;
}