~desrt/indicator-appmenu/hud-rewrite-wip

« back to all changes in this revision

Viewing changes to src/hudappindicatorsource.c

  • Committer: Ryan Lortie
  • Date: 2012-03-15 18:25:50 UTC
  • Revision ID: desrt@desrt.ca-20120315182550-vafhb1snbn5hxigs
hud-service: hudsource: add a concept of "use count"

Add hud_source_use() and hud_source_unuse() to indicate to a HudSource
that an active query is being performed against it.

This is wired up all the way through to the level of the collectors but
it does not yet do anything there.  Stay tuned.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
  GSequence    *indicators;
56
56
  guint         subscription;
57
57
  GCancellable *cancellable;
 
58
  gint          use_count;
58
59
  gboolean      ready;
59
60
};
60
61
 
107
108
                                                       dbus_name, dbus_path);
108
109
  g_signal_connect (collector, "changed", G_CALLBACK (hud_app_indicator_source_collector_changed), source);
109
110
 
 
111
  /* If query is active, mark new app indicator as used. */
 
112
  if (source->use_count)
 
113
    hud_source_use (HUD_SOURCE (collector));
 
114
 
110
115
  iter = g_sequence_get_iter_at_pos (source->indicators, position);
111
116
  g_sequence_insert_before (iter, collector);
112
117
  g_free (title);
130
135
 
131
136
      collector = g_sequence_get (iter);
132
137
      g_signal_handlers_disconnect_by_func (collector, hud_app_indicator_source_collector_changed, source);
 
138
      /* Drop use count if we added one... */
 
139
      if (source->use_count)
 
140
        hud_source_unuse (HUD_SOURCE (collector));
133
141
      g_sequence_remove (iter);
134
142
    }
135
143
}
313
321
}
314
322
 
315
323
static void
 
324
hud_app_indicator_source_use (HudSource *hud_source)
 
325
{
 
326
  HudAppIndicatorSource *source = HUD_APP_INDICATOR_SOURCE (hud_source);
 
327
 
 
328
  if (source->use_count == 0)
 
329
    g_sequence_foreach (source->indicators, (GFunc) hud_source_use, NULL);
 
330
 
 
331
  source->use_count++;
 
332
}
 
333
 
 
334
static void
 
335
hud_app_indicator_source_unuse (HudSource *hud_source)
 
336
{
 
337
  HudAppIndicatorSource *source = HUD_APP_INDICATOR_SOURCE (hud_source);
 
338
 
 
339
  g_return_if_fail (source->use_count > 0);
 
340
 
 
341
  source->use_count--;
 
342
 
 
343
  if (source->use_count == 0)
 
344
    g_sequence_foreach (source->indicators, (GFunc) hud_source_unuse, NULL);
 
345
}
 
346
 
 
347
static void
316
348
hud_app_indicator_source_search (HudSource   *hud_source,
317
349
                                 GPtrArray   *results_array,
318
350
                                 const gchar *search_string)
351
383
static void
352
384
hud_app_indicator_source_iface_init (HudSourceInterface *iface)
353
385
{
 
386
  iface->use = hud_app_indicator_source_use;
 
387
  iface->unuse = hud_app_indicator_source_unuse;
354
388
  iface->search = hud_app_indicator_source_search;
355
389
}
356
390