Back to index

unity  6.0.0
Public Member Functions | Public Attributes
unity::dash::HomeLens::Impl Class Reference
Inheritance diagram for unity::dash::HomeLens::Impl:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::HomeLens::Impl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Impl (HomeLens *owner)
 ~Impl ()
void OnLensAdded (Lens::Ptr &lens)
gsize FindLensPriority (Lens::Ptr &lens)
void EnsureCategoryAnnotation (Lens::Ptr &lens, DeeModel *results, DeeModel *categories)
Lens::Ptr FindLensForUri (std::string const &uri)

Public Attributes

HomeLensowner_
Lenses::LensList lenses_
HomeLens::CategoryRegistry cat_registry_
HomeLens::ResultsMerger results_merger_
HomeLens::CategoryMerger categories_merger_
HomeLens::FiltersMerger filters_merger_
int running_searches_
glib::Object< GSettings > settings_

Detailed Description

Definition at line 279 of file HomeLens.cpp.


Constructor & Destructor Documentation

Definition at line 677 of file HomeLens.cpp.

  : owner_(owner)
  , cat_registry_(owner)
  , results_merger_(owner->results()->model(), &cat_registry_)
  , categories_merger_(owner->categories()->model(), &cat_registry_)
  , filters_merger_(owner->filters()->model())
  , running_searches_(0)
  , settings_(g_settings_new("com.canonical.Unity.Dash"))
{
  DeeModel* results = owner->results()->model();
  if (dee_model_get_n_columns(results) == 0)
  {
    dee_model_set_schema(results, "s", "s", "u", "s", "s", "s", "s", NULL);
  }

  DeeModel* categories = owner->categories()->model();
  if (dee_model_get_n_columns(categories) == 0)
  {
    dee_model_set_schema(categories, "s", "s", "s", "a{sv}", NULL);
  }

  DeeModel* filters = owner->filters()->model();
  if (dee_model_get_n_columns(filters) == 0)
  {
    dee_model_set_schema(filters, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);
  }
}

Definition at line 705 of file HomeLens.cpp.

{

}

Member Function Documentation

void unity::dash::HomeLens::Impl::EnsureCategoryAnnotation ( Lens::Ptr lens,
DeeModel *  results,
DeeModel *  categories 
)

Definition at line 731 of file HomeLens.cpp.

{
  if (categories && results)
  {
    if (!(DEE_IS_MODEL(results) && DEE_IS_MODEL(categories)))
    {
      LOG_ERROR(logger) << "The "
                        << std::string(DEE_IS_MODEL(results) ? "categories" : "results")
                        << " model is not a valid DeeModel. ("
                        << lens->id() << ")";
      return;
    }

    g_object_set_data(G_OBJECT(categories),
                      "unity-homelens-results-model",
                      results);

    gsize lens_priority = FindLensPriority(lens);
    g_object_set_data(G_OBJECT(categories),
                      "unity-homelens-priority",
                      GSIZE_TO_POINTER(lens_priority));

    LOG_DEBUG(logger) << "Registering results model "  << results
                      << " and lens priority " << lens_priority
                      << " on category model " << categories << ". ("
                      << lens->id() << ")";
  }
}

Definition at line 762 of file HomeLens.cpp.

{
  /* We iterate over all lenses looking for the given uri in their
   * global results. This might seem like a sucky approach, but it
   * saves us from a ship load of book keeping */

  for (auto lens : lenses_)
  {
    DeeModel* results = lens->global_results()->model();
    DeeModelIter* iter = dee_model_get_first_iter(results);
    DeeModelIter* end = dee_model_get_last_iter(results);
    const int URI_COLUMN = 0;

    while (iter != end)
      {
        if (g_strcmp0(uri.c_str(), dee_model_get_string(results, iter, URI_COLUMN)) == 0)
        {
          return lens;
        }
        iter = dee_model_next(results, iter);
      }
  }

  return Lens::Ptr();
}

Here is the caller graph for this function:

Definition at line 715 of file HomeLens.cpp.

{
  gchar** lenses = g_settings_get_strv(settings_, "home-lens-ordering");
  gsize pos = 0, len = g_strv_length(lenses);

  for (pos = 0; pos < len; pos++)
  {
    if (g_strcmp0(lenses[pos], lens->id().c_str()) == 0)
      break;
  }

  g_strfreev(lenses);

  return len - pos;
}

Definition at line 791 of file HomeLens.cpp.

{
  lenses_.push_back (lens);
  owner_->lens_added.emit(lens);

  /* When we dispatch a search we inc the search count and when we finish
   * one we decrease it. When we reach 0 we'll emit search_finished. */
  lens->global_search_finished.connect([&] (Hints const& hints) {
      running_searches_--;

      if (running_searches_ <= 0)
      {
        owner_->search_finished.emit(Hints());
        LOG_INFO(logger) << "Search finished";
      }
  });

  nux::ROProperty<glib::Object<DeeModel>>& results_prop = lens->global_results()->model;
  nux::ROProperty<glib::Object<DeeModel>>& categories_prop = lens->categories()->model;
  nux::ROProperty<glib::Object<DeeModel>>& filters_prop = lens->filters()->model;

  /*
   * Important: We must ensure that the categories model is annotated
   *            with the results model in the "unity-homelens-results-model"
   *            data slot. We need it later to compute the transfermed offsets
   *            of the categories in the merged category model.
   */

  /* Most lenses add models lazily, but we can't know that;
   * so try to see if we can add them up front */
  if (results_prop().RawPtr())
  {
    EnsureCategoryAnnotation(lens, categories_prop(), results_prop());
    results_merger_.AddSource(results_prop());
  }

  if (categories_prop().RawPtr())
  {
    EnsureCategoryAnnotation(lens, categories_prop(), results_prop());
    categories_merger_.AddSource(categories_prop());
  }

  if (filters_prop().RawPtr())
    filters_merger_.AddSource(filters_prop());

  /*
   * Pick it up when the lens set models lazily.
   */
  results_prop.changed.connect([&] (glib::Object<DeeModel> model)
  {
    EnsureCategoryAnnotation(lens, lens->categories()->model(), model);
    results_merger_.AddSource(model);
  });

  categories_prop.changed.connect([&] (glib::Object<DeeModel> model)
  {
    EnsureCategoryAnnotation(lens, model, lens->global_results()->model());
    categories_merger_.AddSource(model);
  });

  filters_prop.changed.connect([&] (glib::Object<DeeModel> model)
  {
    filters_merger_.AddSource(model);
  });

  /*
   * Register pre-existing categories up front
   * FIXME: Do the same for results?
   */
  DeeModel* cats = categories_prop();
  if (cats)
  {
    DeeModelIter* cats_iter;
    DeeModelIter* cats_end;
    for (cats_iter = dee_model_get_first_iter(cats), cats_end = dee_model_get_last_iter(cats);
        cats_iter != cats_end;
        cats_iter = dee_model_next(cats, cats_iter))
    {
      categories_merger_.OnSourceRowAdded(cats, cats_iter);
    }
  }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 292 of file HomeLens.cpp.

Definition at line 294 of file HomeLens.cpp.

Definition at line 295 of file HomeLens.cpp.

Definition at line 291 of file HomeLens.cpp.

Definition at line 290 of file HomeLens.cpp.

Definition at line 293 of file HomeLens.cpp.

Definition at line 296 of file HomeLens.cpp.

Definition at line 297 of file HomeLens.cpp.


The documentation for this class was generated from the following file: