~ps-jenkins/unity-lens-files/latestsnapshot-7.0daily13.05.07ubuntu.unity.experimental.certified-0ubuntu1

« back to all changes in this revision

Viewing changes to src/utils.vala

  • Committer: Michal Hruby
  • Date: 2013-03-12 13:43:11 UTC
  • Revision ID: michal.mhr@gmail.com-20130312134311-e0cdn2bd241gxsm6
Make sure everything works with latest libunity

Show diffs side-by-side

added added

removed removed

Lines of Context:
378
378
      }
379
379
    }
380
380
    
381
 
  /* Run through @filter_set and remove any row from the result set's model
382
 
   * in which URI is not in @valid_uris */
383
 
  public void apply_uri_filter (Set<string> valid_uris,
384
 
                                Dee.ResultSet filter_set)
385
 
  {
386
 
    var model = filter_set.get_model ();
387
 
    uint n_removed = 0;
388
 
    string uri;
389
 
    
390
 
    /* Anything in filter_set that is not in the event_uris set, is removed
391
 
     * from the results_model */
392
 
    foreach (var row in filter_set)
 
381
    /* Extract a hash set of all subject uris in a Zeitgeist.ResultSet */
 
382
    public Set<string> get_uri_set (Zeitgeist.ResultSet results)
393
383
    {
394
 
      uri = model.get_string (row, ResultsColumn.URI);
395
 
      if (!(uri in valid_uris))
 
384
      Set<string> uris = new HashSet<string> ();
 
385
      
 
386
      foreach (var ev in results)
396
387
        {
397
 
          model.remove (row);
398
 
          n_removed++;
399
 
          //debug ("  - %s", uri);
 
388
          for (int i = 0; i  < ev.num_subjects(); i++)
 
389
            uris.add (ev.get_subject (i).get_uri ());
400
390
        }
401
 
    }
402
 
    
403
 
    if (n_removed > 0)
404
 
      debug ("Removed %u rows from result set", n_removed);
405
 
  }
406
 
  
407
 
  /* Returns true iff new_search is a query that simply restricts the
408
 
   * result set of old_query */
409
 
  public bool check_is_filter_search (LensSearch new_search, LensSearch? old_search)
410
 
  {
411
 
    bool is_filter_search = false;      
412
 
    if (old_search != null)
413
 
      {
414
 
        string previous_search_string = old_search.search_string;
415
 
        if (previous_search_string != null && previous_search_string != "")
416
 
          is_filter_search = new_search.search_string.has_prefix (
417
 
                                                      previous_search_string);
418
 
      }
419
 
    
420
 
    return is_filter_search;
421
 
  }
422
 
  
423
 
  /* Extract a hash set of all subject uris in a Zeitgeist.ResultSet */
424
 
  public Set<string> get_uri_set (Zeitgeist.ResultSet results)
425
 
  {
426
 
    Set<string> uris = new HashSet<string> ();
427
 
    
428
 
    foreach (var ev in results)
429
 
      {
430
 
        for (int i = 0; i  < ev.num_subjects(); i++)
431
 
          uris.add (ev.get_subject (i).get_uri ());
432
 
      }
433
 
    
434
 
    return uris;
435
 
  }
436
 
  
437
 
  public string normalize_string (string input)
438
 
  {
439
 
    return input.normalize (-1, NormalizeMode.ALL_COMPOSE).casefold ();
440
 
  }
 
391
      
 
392
      return uris;
 
393
    }
 
394
    
 
395
    public string normalize_string (string input)
 
396
    {
 
397
      return input.normalize (-1, NormalizeMode.ALL_COMPOSE).casefold ();
 
398
    }
441
399
   
442
400
} /* namespace */