Changeset 13938


Ignore:
Timestamp:
Feb 2, 2013, 11:01:33 PM (8 years ago)
Author:
jordan
Message:

(gtk) #4076 'free space indicator': tweak the GTK+ client's visible count label's behavior as the previous commit did for the Qt client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/filter.c

    r13927 r13938  
    113113
    114114static gboolean
    115 tracker_filter_model_update (GtkTreeStore * store)
     115tracker_filter_model_update (gpointer gstore)
    116116{
    117117  int i, n;
     
    119119  int store_pos;
    120120  GtkTreeIter iter;
    121   GtkTreeModel * model = GTK_TREE_MODEL (store);
     121  GObject * o = G_OBJECT (gstore);
     122  GtkTreeStore * store = GTK_TREE_STORE (gstore);
     123  GtkTreeModel * model = GTK_TREE_MODEL (gstore);
    122124  GPtrArray * hosts = g_ptr_array_new ();
    123125  GStringChunk * strings = g_string_chunk_new (4096);
    124126  GHashTable * hosts_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
    125   GObject * o = G_OBJECT (store);
    126127  GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY));
    127128  const int first_tracker_pos = 2; /* offset past the "All" and the separator */
     
    267268  g_hash_table_unref (hosts_hash);
    268269  g_string_chunk_free (strings);
    269   return FALSE;
     270  return G_SOURCE_REMOVE;
    270271}
    271272
     
    308309  if (!pending)
    309310    {
    310       GSourceFunc func = (GSourceFunc) tracker_filter_model_update;
     311      GSourceFunc func = tracker_filter_model_update;
    311312      g_object_set_qdata (o, DIRTY_KEY, GINT_TO_POINTER (1));
    312313      gdk_threads_add_idle (func, tracker_model);
     
    543544}
    544545
    545 static void
    546 activity_filter_model_update (GtkListStore * store)
     546static gboolean
     547activity_filter_model_update (gpointer gstore)
    547548{
    548549  GtkTreeIter iter;
     550  GObject * o = G_OBJECT (gstore);
     551  GtkListStore * store = GTK_LIST_STORE (gstore);
    549552  GtkTreeModel * model = GTK_TREE_MODEL (store);
    550   GObject * o = G_OBJECT (store);
    551553  GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY));
    552554
     
    572574
    573575      status_model_update_count (store, &iter, hits);
    574 
    575576    }
    576577  while (gtk_tree_model_iter_next (model, &iter));
     578
     579  return G_SOURCE_REMOVE;
    577580}
    578581
     
    646649  if (!pending)
    647650    {
    648       GSourceFunc func = (GSourceFunc) activity_filter_model_update;
     651      GSourceFunc func = activity_filter_model_update;
    649652      g_object_set_qdata (o, DIRTY_KEY, GINT_TO_POINTER (1));
    650653      gdk_threads_add_idle (func, activity_model);
     
    860863***/
    861864
    862 static void
    863 update_count_label (struct filter_data * data)
     865static gboolean
     866update_count_label (gpointer gdata)
    864867{
    865868  char buf[512];
    866   GtkTreeModel * tmodel = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (data->filter_model));
    867   const int torrentCount = gtk_tree_model_iter_n_children (tmodel, NULL);
    868   const int visibleCount = gtk_tree_model_iter_n_children (data->filter_model, NULL);
     869  int visibleCount;
     870  int trackerCount;
     871  int activityCount;
     872  GtkTreeModel * model;
     873  GtkComboBox * combo;
     874  GtkTreeIter iter;
     875  struct filter_data * data = gdata;
     876
     877  /* get the visible count */
     878  visibleCount = gtk_tree_model_iter_n_children (data->filter_model, NULL);
     879
     880  /* get the tracker count */
     881  combo = GTK_COMBO_BOX (data->tracker);
     882  model = gtk_combo_box_get_model (combo);
     883  if (gtk_combo_box_get_active_iter (combo, &iter))
     884    gtk_tree_model_get (model, &iter, TRACKER_FILTER_COL_COUNT, &trackerCount, -1);
     885  else
     886    trackerCount = 0;
     887
     888  /* get the activity count */
     889  combo = GTK_COMBO_BOX (data->activity);
     890  model = gtk_combo_box_get_model (combo);
     891  if (gtk_combo_box_get_active_iter (combo, &iter))
     892    gtk_tree_model_get (model, &iter, ACTIVITY_FILTER_COL_COUNT, &activityCount, -1);
     893  else
     894    activityCount = 0;
    869895
    870896  /* set the text */
    871   if (visibleCount == torrentCount)
     897  if (visibleCount == MIN (activityCount, trackerCount))
    872898    g_snprintf (buf, sizeof(buf), _("_Show:"));
    873899  else
    874     g_snprintf (buf, sizeof(buf), _("_Show %'d:"), visibleCount);
     900    g_snprintf (buf, sizeof(buf), _("_Show %'d of:"), visibleCount);
    875901  gtk_label_set_markup_with_mnemonic (GTK_LABEL (data->show_lb), buf);
     902
     903  g_object_steal_qdata (G_OBJECT(data->show_lb), DIRTY_KEY);
     904  return G_SOURCE_REMOVE;
     905}
     906
     907static void
     908update_count_label_idle (struct filter_data * data)
     909{
     910  GObject * o = G_OBJECT (data->show_lb);
     911  const gboolean pending = g_object_get_qdata (o, DIRTY_KEY) != NULL;
     912  if (!pending)
     913    {
     914      g_object_set_qdata (o, DIRTY_KEY, GINT_TO_POINTER (1));
     915      gdk_threads_add_idle (update_count_label, data);
     916    }
    876917}
    877918
     
    882923                              gpointer       data)
    883924{
    884   update_count_label (data);
     925  update_count_label_idle (data);
    885926}
    886927
     
    890931                             gpointer       data       UNUSED)
    891932{
    892   update_count_label (data);
     933  update_count_label_idle (data);
    893934}
    894935
Note: See TracChangeset for help on using the changeset viewer.