~mhr3/libunity/remote-scope-sources

« back to all changes in this revision

Viewing changes to src/unity-scope-private.vala

  • Committer: Tarmac
  • Author(s): Michal Hruby
  • Date: 2011-11-29 12:37:56 UTC
  • mfrom: (87.2.5 async-friendly-signals)
  • Revision ID: tarmac-20111129123756-r7pii8tkvtfapqqg
This branch provides a new signal "search-changed" which along with the addition of a Cancellable instance tries to make searches more async-friendly.

I made this less complex by cancelling the Cancellable everytime new search is queued, therefore we don't need to check anything. To easily handle the case of doing completely new search when the filters are changed, the scope dev can just connect to filters-changed and call queue_search_changed() himself, but it still also allows you to just filter your results in the filters-changed callback without the need to do new search.

One thing that I'm thinking about is to turn the active-*search properties private and just use this signal - if we want to do this though, the first parameter from queue_search_changed() should be removed.. Fixes: . Reviewed by Mikkel Kamstrup Erlandsen.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
  {
113
113
    _owner.filters_changed ();
114
114
    _filters_changed_id = 0;
 
115
 
115
116
    return false;
116
117
  }
117
118
 
229
230
    return reply;
230
231
  }
231
232
 
 
233
  private Cancellable[] cancellable_arr = new Cancellable[SearchType.N_TYPES];
 
234
 
 
235
  public async void schedule_search_changed (LensSearch search,
 
236
                                             SearchType search_type)
 
237
  {
 
238
    /* Cancel any previous searches */
 
239
    if (cancellable_arr[search_type] != null)
 
240
    {
 
241
      cancellable_arr[search_type].cancel ();
 
242
    }
 
243
 
 
244
    var cancellable = new Cancellable ();
 
245
    cancellable_arr[search_type] = cancellable;
 
246
 
 
247
    /* We'll wait a bit to check if we don't get different search */
 
248
    Idle.add (schedule_search_changed.callback);
 
249
    yield;
 
250
 
 
251
    if (cancellable.is_cancelled ()) return;
 
252
 
 
253
    /* careful with the cancellable, the handler should ref it to use it */
 
254
    _owner.search_changed (search, search_type, cancellable);
 
255
  }
 
256
 
 
257
  private string[] search_keys = new string[SearchType.N_TYPES];
 
258
 
232
259
  public async void search (string search_string,
233
260
                            HashTable<string, Variant> hints) throws IOError
234
261
  {
238
265
      search_finished (lens_search.search_string, lens_search.hints);
239
266
    });
240
267
 
241
 
    if (!s.equals (_owner.active_search))
242
 
      _owner.active_search = s;
 
268
    var search_key = _owner.generate_search_key (s);
 
269
    if (search_key != null && search_key != search_keys[SearchType.DEFAULT])
 
270
    {
 
271
      schedule_search_changed.begin (s, SearchType.DEFAULT);
 
272
      _owner.active_search = s;
 
273
      search_keys[SearchType.DEFAULT] = search_key;
 
274
    }
 
275
    else if (search_key == null && !s.equals (_owner.active_search))
 
276
    {
 
277
      schedule_search_changed.begin (s, SearchType.DEFAULT);
 
278
      _owner.active_search = s;
 
279
    }
 
280
    else
 
281
    {
 
282
      s.finished ();
 
283
    }
243
284
  }
244
285
 
245
286
  public async void global_search (string search_string,
251
292
      global_search_finished (lens_search.search_string, lens_search.hints);
252
293
    });
253
294
 
254
 
    if (!s.equals (_owner.active_global_search))
255
 
      _owner.active_global_search = s;
 
295
    var search_key = _owner.generate_search_key (s);
 
296
    if (search_key != null && search_key != search_keys[SearchType.GLOBAL])
 
297
    {
 
298
      schedule_search_changed.begin (s, SearchType.GLOBAL);
 
299
      _owner.active_global_search = s;
 
300
      search_keys[SearchType.GLOBAL] = search_key;
 
301
    }
 
302
    else if (search_key == null && !s.equals (_owner.active_global_search))
 
303
    {
 
304
      schedule_search_changed.begin (s, SearchType.GLOBAL);
 
305
      _owner.active_global_search = s;
 
306
    }
256
307
  }
257
308
 
258
309
  public async PreviewReplyRaw preview (string uri) throws IOError