Back to index

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

List of all members.

Public Member Functions

 CategoryMerger (glib::Object< DeeModel > target, HomeLens::CategoryRegistry *cat_registry)
void OnSourceRowAdded (DeeModel *model, DeeModelIter *iter)
void OnSourceRowRemoved (DeeModel *model, DeeModelIter *iter)
void AddSource (glib::Object< DeeModel > source)

Protected Member Functions

virtual void OnSourceRowChanged (DeeModel *model, DeeModelIter *iter)
void EnsureRowBuf (DeeModel *source)
DeeModelTag * FindSourceToTargetTag (DeeModel *model)

Protected Attributes

glib::SignalManager sig_manager_
GVariant ** row_buf_
unsigned int n_cols_
glib::Object< DeeModel > target_
std::map< DeeModel
*, DeeModelTag * > 
source_to_target_tags_

Private Attributes

HomeLens::CategoryRegistrycat_registry_
DeeModelTag * priority_tag_

Detailed Description

Definition at line 248 of file HomeLens.cpp.


Constructor & Destructor Documentation

Definition at line 316 of file HomeLens.cpp.

  : HomeLens::ModelMerger::ModelMerger(target)
  , cat_registry_(cat_registry)
  , priority_tag_(dee_model_register_tag(target, NULL))
{}

Member Function Documentation

void unity::dash::HomeLens::ModelMerger::AddSource ( glib::Object< DeeModel >  source) [inherited]

Definition at line 333 of file HomeLens.cpp.

{
  typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType;

  if (!source)
  {
    LOG_ERROR(logger) << "Trying to add NULL source to ModelMerger";
    return;
  }

  DeeModelTag* merger_tag = dee_model_register_tag(source, NULL);
  source_to_target_tags_[source.RawPtr()] = merger_tag;

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                     "row-added",
                                     sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowAdded)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-removed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowRemoved)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-changed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowChanged)));
}

Here is the call graph for this function:

void unity::dash::HomeLens::ModelMerger::EnsureRowBuf ( DeeModel *  source) [protected, inherited]

Definition at line 557 of file HomeLens.cpp.

{
  if (G_UNLIKELY (n_cols_ == 0))
  {
    /* We have two things to accomplish here.
     * 1) Allocate the row_buf_, and
     * 2) Make sure that the target model has the correct schema set.
     *
     * INVARIANT: n_cols_ == 0 iff row_buf_ == NULL.
     */

    n_cols_ = dee_model_get_n_columns(model);

    if (n_cols_ == 0)
    {
      LOG_ERROR(logger) << "Source model has not provided a schema for the model merger!";
      return;
    }

    /* Lazily adopt schema from source if we don't have one.
     * If we do have a schema let's validate that they match the source */
    if (dee_model_get_n_columns(target_) == 0)
    {
      dee_model_set_schema_full(target_,
                                dee_model_get_schema(model, NULL),
                                n_cols_);
    }
    else
    {
      unsigned int n_cols1;
      const gchar* const *schema1 = dee_model_get_schema(target_, &n_cols1);
      const gchar* const *schema2 = dee_model_get_schema(model, NULL);

      /* At the very least we should have an equal number of rows */
      if (n_cols_ != n_cols1)
      {
        LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected "
                          << n_cols1 << " columns, but found "
                          << n_cols_ << ".";
        n_cols_ = 0;
        return;
      }

      /* Compare schemas */
      for (unsigned int i = 0; i < n_cols_; i++)
      {
        if (g_strcmp0(schema1[i], schema2[i]) != 0)
        {
          LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected column "
                            << i << " to be '" << schema1[i] << "', but found '"
                            << schema2[i] << "'.";
          n_cols_ = 0;
          return;
        }
      }
    }

    row_buf_ = g_new0 (GVariant*, n_cols_);
  }
}
DeeModelTag * unity::dash::HomeLens::ModelMerger::FindSourceToTargetTag ( DeeModel *  model) [protected, inherited]

Definition at line 618 of file HomeLens.cpp.

{
  return source_to_target_tags_[model];
}
void unity::dash::HomeLens::CategoryMerger::OnSourceRowAdded ( DeeModel *  model,
DeeModelIter *  iter 
) [virtual]

Reimplemented from unity::dash::HomeLens::ModelMerger.

Definition at line 407 of file HomeLens.cpp.

{
  DeeModel* results_model;
  DeeModelIter* target_iter;
  DeeModelIter* target_end;
  DeeModelTag*  target_tag;
  int target_cat_offset, source_cat_offset;
  const gchar* display_name;
  const unsigned int DISPLAY_NAME_COLUMN = 0;
  gsize lens_priority, prio;

  EnsureRowBuf(model);

  results_model = static_cast<DeeModel*>(g_object_get_data(
                              G_OBJECT(model), "unity-homelens-results-model"));
  if (results_model == NULL)
  {
    LOG_DEBUG(logger) << "Category model " << model
                      << " does not have a results model yet";
    return;
  }

  dee_model_get_row (model, iter, row_buf_);
  target_tag = FindSourceToTargetTag(model);
  source_cat_offset = dee_model_get_position(model, iter);

  /* If we already have a category registered with the same display name
   * then we just use that. Otherwise register a new category for it */
  display_name = dee_model_get_string(model, iter, DISPLAY_NAME_COLUMN);
  target_cat_offset = cat_registry_->FindCategoryOffset(display_name);
  if (target_cat_offset >= 0)
  {
    cat_registry_->AssociateCategoryOffset(results_model, source_cat_offset,
                                           target_cat_offset);
    goto cleanup;
  }

  /*
   * Below we can assume that we have a genuinely new category.
   *
   * Our goal is to insert the category at a position suitable for its
   * priority. We insert it as the last item in the set of items which
   * have equal priority.
   *
   * We allow our selves to do linear inserts as we wont expect a lot
   * of categories.
   */

  lens_priority = GPOINTER_TO_SIZE(g_object_get_data(
                              G_OBJECT(model), "unity-homelens-priority"));

  /* Seek correct position in the merged category model */
  target_iter = dee_model_get_first_iter(target_);
  target_end = dee_model_get_last_iter(target_);
  while (target_iter != target_end)
  {
    prio = GPOINTER_TO_SIZE(dee_model_get_tag(target_, target_iter, priority_tag_));
    if (lens_priority > prio)
      break;
    target_iter = dee_model_next(target_, target_iter);
  }

  /* Add the row to the merged categories model and store required metadata */
  target_iter = dee_model_insert_row_before(target_, target_iter, row_buf_);
  dee_model_set_tag(model, iter, target_tag, target_iter);
  dee_model_set_tag(target_, target_iter, priority_tag_, GSIZE_TO_POINTER(lens_priority));
  target_cat_offset = dee_model_get_position(target_, target_iter);
  cat_registry_->RegisterCategoryOffset(results_model, source_cat_offset,
                                        display_name, target_cat_offset);

  cleanup:
    for (unsigned int i = 0; i < n_cols_; i++) g_variant_unref(row_buf_[i]);
}
void unity::dash::HomeLens::ModelMerger::OnSourceRowChanged ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual, inherited]

Reimplemented in unity::dash::HomeLens::FiltersMerger, and unity::dash::HomeLens::ResultsMerger.

Definition at line 528 of file HomeLens.cpp.

{
  DeeModelIter* target_iter;
  DeeModelTag*  target_tag;

  EnsureRowBuf(model);

  dee_model_get_row (model, iter, row_buf_);
  target_tag = FindSourceToTargetTag(model);
  target_iter = static_cast<DeeModelIter*>(dee_model_get_tag(model,
                                                                 iter,
                                                                 target_tag));

  dee_model_set_row (target_, target_iter, row_buf_);

  for (unsigned int i = 0; i < n_cols_; i++) g_variant_unref(row_buf_[i]);
}

Here is the caller graph for this function:

void unity::dash::HomeLens::CategoryMerger::OnSourceRowRemoved ( DeeModel *  model,
DeeModelIter *  iter 
) [virtual]

Reimplemented from unity::dash::HomeLens::ModelMerger.

Definition at line 488 of file HomeLens.cpp.

{
  /* We don't support removals of categories.
   * You can check out any time you like, but you can never leave
   *
   * The category registry code is spaghettified enough already.
   * No more please.
   */
  LOG_DEBUG(logger) << "Removal of categories not supported.";
}

Member Data Documentation

Definition at line 258 of file HomeLens.cpp.

unsigned int unity::dash::HomeLens::ModelMerger::n_cols_ [protected, inherited]

Definition at line 206 of file HomeLens.cpp.

Definition at line 259 of file HomeLens.cpp.

GVariant** unity::dash::HomeLens::ModelMerger::row_buf_ [protected, inherited]

Definition at line 205 of file HomeLens.cpp.

Definition at line 204 of file HomeLens.cpp.

std::map<DeeModel*,DeeModelTag*> unity::dash::HomeLens::ModelMerger::source_to_target_tags_ [protected, inherited]

Definition at line 208 of file HomeLens.cpp.

Definition at line 207 of file HomeLens.cpp.


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