Back to index

unity  6.0.0
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
unity::dash::LensView Class Reference

#include <LensView.h>

Inheritance diagram for unity::dash::LensView:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::LensView:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 LensView ()
 LensView (Lens::Ptr lens, nux::Area *show_filters)
CategoryGroupscategories ()
FilterBarfilter_bar () const
Lens::Ptr lens () const
nux::Area * fscroll_view () const
int GetNumRows ()
void JumpToTop ()
virtual void ActivateFirst ()
void PerformSearch (std::string const &search_query)
void CheckNoResults (Lens::Hints const &hints)
void HideResultsMessage ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

nux::ROProperty< std::string > search_string
nux::Property< bool > filters_expanded
nux::Property< ViewTypeview_type
nux::Property< bool > can_refine_search
sigc::signal< void,
std::string const & > 
uri_activated

Protected Member Functions

virtual std::string GetChildsName () const
 Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Private Types

typedef std::vector
< PlacesGroup * > 
CategoryGroups
typedef std::map< PlacesGroup
*, unsigned int > 
ResultCounts

Private Member Functions

 NUX_DECLARE_OBJECT_TYPE (LensView, nux::View)
void SetupViews (nux::Area *show_filters)
void SetupCategories ()
void SetupResults ()
void SetupFilters ()
void OnCategoryAdded (Category const &category)
void OnResultAdded (Result const &result)
void OnResultRemoved (Result const &result)
void UpdateCounts (PlacesGroup *group)
void OnGroupExpanded (PlacesGroup *group)
void OnColumnsChanged ()
void OnFilterAdded (Filter::Ptr filter)
void OnFilterRemoved (Filter::Ptr filter)
void OnViewTypeChanged (ViewType view_type)
void QueueFixRenderering ()
bool FixRenderering ()
virtual void Draw (nux::GraphicsEngine &gfx_context, bool force_draw)
virtual void DrawContent (nux::GraphicsEngine &gfx_context, bool force_draw)
virtual bool AcceptKeyNavFocus ()
virtual std::string GetName () const
virtual void AddProperties (GVariantBuilder *builder)
std::string get_search_string () const

Private Attributes

Lens::Ptr lens_
CategoryGroups categories_
ResultCounts counts_
bool initial_activation_
bool no_results_active_
std::string search_string_
nux::HLayout * layout_
LensScrollViewscroll_view_
nux::VLayout * scroll_layout_
LensScrollViewfscroll_view_
nux::VLayout * fscroll_layout_
FilterBarfilter_bar_
nux::StaticCairoTextno_results_
UBusManager ubus_manager_
glib::Source::UniquePtr fix_rendering_idle_

Detailed Description

Definition at line 46 of file LensView.h.


Member Typedef Documentation

typedef std::vector<PlacesGroup*> unity::dash::LensView::CategoryGroups [private]

Definition at line 49 of file LensView.h.

Definition at line 34 of file Introspectable.h.

typedef std::map<PlacesGroup*, unsigned int> unity::dash::LensView::ResultCounts [private]

Definition at line 50 of file LensView.h.


Constructor & Destructor Documentation

Definition at line 121 of file LensView.cpp.

  : nux::View(NUX_TRACKER_LOCATION)
  , filters_expanded(false)
  , can_refine_search(false)
  , no_results_active_(false)
{}
unity::dash::LensView::LensView ( Lens::Ptr  lens,
nux::Area *  show_filters 
)

Definition at line 128 of file LensView.cpp.

  : nux::View(NUX_TRACKER_LOCATION)
  , filters_expanded(false)
  , can_refine_search(false)
  , lens_(lens)
  , initial_activation_(true)
  , no_results_active_(false)
{
  SetupViews(show_filters);
  SetupCategories();
  SetupResults();
  SetupFilters();

  dash::Style::Instance().columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));

  lens_->connected.changed.connect([&](bool is_connected) { if (is_connected) initial_activation_ = true; });
  search_string.SetGetterFunction(sigc::mem_fun(this, &LensView::get_search_string));
  filters_expanded.changed.connect([&](bool expanded) { fscroll_view_->SetVisible(expanded); QueueRelayout(); OnColumnsChanged(); });
  view_type.changed.connect(sigc::mem_fun(this, &LensView::OnViewTypeChanged));

  ubus_manager_.RegisterInterest(UBUS_RESULT_VIEW_KEYNAV_CHANGED, [&] (GVariant* data) {
    // we get this signal when a result view keynav changes,
    // its a bad way of doing this but nux ABI needs to be broken
    // to do it properly
    nux::Geometry focused_pos;
    g_variant_get (data, "(iiii)", &focused_pos.x, &focused_pos.y, &focused_pos.width, &focused_pos.height);

    for (auto category : categories_)
    {
      if (category->GetLayout() != nullptr)
      {
        auto expand_label = category->GetHeaderFocusableView();
        auto child = category->GetChildView();

        if ((child && child->HasKeyFocus()) ||
            (expand_label && expand_label->HasKeyFocus()))
        {

          focused_pos.x += child->GetGeometry().x;
          focused_pos.y += child->GetGeometry().y - 30;
          focused_pos.height += 30;
          scroll_view_->ScrollToPosition(focused_pos);
          break;
        }
      }
    }
  });

}

Here is the call graph for this function:


Member Function Documentation

bool unity::dash::LensView::AcceptKeyNavFocus ( ) [private, virtual]

Definition at line 568 of file LensView.cpp.

{
  return false;
}

Definition at line 539 of file LensView.cpp.

{
  Results::Ptr results = lens_->results;
  if (results->count())
  {
    for (unsigned int c = 0; c < scroll_layout_->GetChildren().size(); ++c)
    {
      for (unsigned int i = 0; i < results->count(); ++i)
      {
        Result result = results->RowAtIndex(i);
        if (result.category_index == c && result.uri != "")
        {
          uri_activated(result.uri);
          lens_->Activate(result.uri);
          return;
        }
      }
    }
    // Fallback
    Result result = results->RowAtIndex(0);
    if (result.uri != "")
    {
      uri_activated(result.uri);
      lens_->Activate(result.uri);
    }
  }
}

Here is the caller graph for this function:

Definition at line 78 of file Introspectable.cpp.

{
  _children.push_back(child);
  child->_parents.push_back(this);
}

Here is the caller graph for this function:

void unity::dash::LensView::AddProperties ( GVariantBuilder *  builder) [private, virtual]

Implements unity::debug::Introspectable.

Definition at line 579 of file LensView.cpp.

{
  unity::variant::BuilderWrapper(builder)
    .add("name", lens_->id)
    .add("lens-name", lens_->name)
    .add("no-results-active", no_results_active_);
}

Here is the call graph for this function:

Definition at line 56 of file LensView.h.

{ return categories_; }

Here is the caller graph for this function:

Definition at line 383 of file LensView.cpp.

{
  gint count = lens_->results()->count();

  if (count == 0 && !no_results_active_ && !search_string_.empty())
  {
    std::stringstream markup;
    Lens::Hints::const_iterator it;

    it = hints.find("no-results-hint");
    markup << "<span size='larger' weight='bold'>";

    if (it != hints.end())
    {
      markup << it->second.GetString();
    }
    else
    {
      markup << _("Sorry, there is nothing that matches your search.");
    }
    markup << "</span>";

    LOG_DEBUG(logger) << "The no-result-hint is: " << markup.str();

    scroll_layout_->SetContentDistribution(nux::MAJOR_POSITION_CENTER);

    no_results_active_ = true;
    no_results_->SetText(markup.str());
    no_results_->SetVisible(true);
  }
  else if (count && no_results_active_)
  {
    scroll_layout_->SetContentDistribution(nux::MAJOR_POSITION_START);

    no_results_active_ = false;
    no_results_->SetText("");
    no_results_->SetVisible(false);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::Draw ( nux::GraphicsEngine &  gfx_context,
bool  force_draw 
) [private, virtual]

Definition at line 486 of file LensView.cpp.

{
  nux::Geometry const& geo = GetGeometry();

  gfx_context.PushClippingRectangle(geo);
  nux::GetPainter().PaintBackground(gfx_context, geo);
  gfx_context.PopClippingRectangle();
}
void unity::dash::LensView::DrawContent ( nux::GraphicsEngine &  gfx_context,
bool  force_draw 
) [private, virtual]

Definition at line 495 of file LensView.cpp.

{
  gfx_context.PushClippingRectangle(GetGeometry());
  layout_->ProcessDraw(gfx_context, force_draw);
  gfx_context.PopClippingRectangle();
}

Definition at line 57 of file LensView.h.

{ return filter_bar_; }

Here is the caller graph for this function:

Definition at line 365 of file LensView.cpp.

{
  std::list<AbstractPlacesGroup*> groups;

  for (auto child : scroll_layout_->GetChildren())
  {
    if (child == no_results_)
      continue;

    groups.push_back(static_cast<AbstractPlacesGroup*>(child));
  }

  dash::impl::UpdateDrawSeparators(groups);

  fix_rendering_idle_.reset();
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nux::Area * unity::dash::LensView::fscroll_view ( ) const

Definition at line 507 of file LensView.cpp.

{
  return fscroll_view_;
}

Here is the caller graph for this function:

std::string unity::dash::LensView::get_search_string ( ) const [private]

Definition at line 440 of file LensView.cpp.

{
  return search_string_;
}

Here is the caller graph for this function:

std::string unity::debug::Introspectable::GetChildsName ( ) const [protected, virtual, inherited]

Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Definition at line 92 of file Introspectable.cpp.

{
  return "Children";
}

Here is the caller graph for this function:

Introspectable::IntrospectableList unity::debug::Introspectable::GetIntrospectableChildren ( ) [virtual, inherited]

Reimplemented in unity::hud::View, unity::launcher::LauncherModel, unity::QuicklistView, and unity::dash::ResultView.

Definition at line 41 of file Introspectable.cpp.

{
  return _children;
}

Here is the caller graph for this function:

guint64 unity::debug::Introspectable::GetIntrospectionId ( ) const [inherited]

Definition at line 97 of file Introspectable.cpp.

{
  return _id;
}

Here is the caller graph for this function:

std::string unity::dash::LensView::GetName ( ) const [private, virtual]

Implements unity::debug::Introspectable.

Definition at line 574 of file LensView.cpp.

{
  return "LensView";
}

Definition at line 512 of file LensView.cpp.

{
  unsigned int columns = dash::Style::Instance().GetDefaultNColumns();
  columns -= filters_expanded ? 2 : 0;

  int num_rows = 0;
  for (auto group: categories_)
  {
    if (group->IsVisible())
    {
      num_rows += 1; // The category header

      if (group->GetExpanded() && columns)
        num_rows += ceil(counts_[group] / static_cast<double>(columns));
      else
        num_rows += 1;
    }
  }

  return num_rows;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 423 of file LensView.cpp.

{
  if (no_results_active_)
  {
    scroll_layout_->SetContentDistribution(nux::MAJOR_POSITION_START);
    no_results_active_ = false;
    no_results_->SetText("");
    no_results_->SetVisible(false);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant * unity::debug::Introspectable::Introspect ( ) [inherited]

Definition at line 47 of file Introspectable.cpp.

{
  GVariantBuilder  builder;
  GVariantBuilder  child_builder;
  gint             n_children = 0;

  g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id));

  AddProperties(&builder);

  g_variant_builder_init(&child_builder, G_VARIANT_TYPE("as"));

  auto children = GetIntrospectableChildren();
  for (auto it = children.begin(); it != children.end(); it++)
  {
    if ((*it)->GetName() != "")
    {
      g_variant_builder_add(&child_builder, "s", (*it)->GetName().c_str());
      n_children++;
    }
  }

  GVariant* child_results = g_variant_builder_end(&child_builder);

  if (n_children > 0)
    g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results);
  return g_variant_builder_end(&builder);
}

Here is the call graph for this function:

Definition at line 534 of file LensView.cpp.

{
  scroll_view_->ScrollToPosition(nux::Geometry(0, 0, 0, 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 502 of file LensView.cpp.

{
  return lens_;
}

Here is the caller graph for this function:

unity::dash::LensView::NUX_DECLARE_OBJECT_TYPE ( LensView  ,
nux::View   
) [private]
void unity::dash::LensView::OnCategoryAdded ( Category const &  category) [private]

Definition at line 254 of file LensView.cpp.

{
  std::string name = category.name;
  std::string icon_hint = category.icon_hint;
  std::string renderer_name = category.renderer_name;
  int index = category.index;

  LOG_DEBUG(logger) << "Category added: " << name
                    << "(" << icon_hint
                    << ", " << renderer_name
                    << ", " << boost::lexical_cast<int>(index) << ")";

  PlacesGroup* group = new PlacesGroup();
  AddChild(group);
  group->SetName(name);
  group->SetIcon(icon_hint);
  group->SetExpanded(false);
  group->SetVisible(false);
  group->expanded.connect(sigc::mem_fun(this, &LensView::OnGroupExpanded));


  /* Add the group at the correct offset into the categories vector */
  categories_.insert(categories_.begin() + index, group);

  /* Reset result count */
  counts_[group] = 0;

  ResultViewGrid* grid = new ResultViewGrid(NUX_TRACKER_LOCATION);
  grid->expanded = false;
  if (renderer_name == "tile-horizontal")
  {
    grid->SetModelRenderer(new ResultRendererHorizontalTile(NUX_TRACKER_LOCATION));
    grid->horizontal_spacing = CARD_VIEW_GAP_HORIZ;
    grid->vertical_spacing = CARD_VIEW_GAP_VERT;
  }    
  else
    grid->SetModelRenderer(new ResultRendererTile(NUX_TRACKER_LOCATION));

  grid->UriActivated.connect([&] (std::string const& uri) { uri_activated.emit(uri); lens_->Activate(uri); });
  group->SetChildView(grid);

  /* We need the full range of method args so we can specify the offset
   * of the group into the layout */
  scroll_layout_->AddView(group, 0, nux::MinorDimensionPosition::eAbove,
                          nux::MinorDimensionSize::eFull, 100.0f,
                          (nux::LayoutPosition)index);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 452 of file LensView.cpp.

{
  unsigned int columns = dash::Style::Instance().GetDefaultNColumns();
  columns -= filters_expanded ? 2 : 0;

  for (auto group: categories_)
  {
    group->SetCounts(columns, counts_[group]);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 463 of file LensView.cpp.

{
  filter_bar_->AddFilter(filter);
  can_refine_search = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 469 of file LensView.cpp.

{
  filter_bar_->RemoveFilter(filter);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 445 of file LensView.cpp.

{
  ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView());
  grid->expanded = group->GetExpanded();
  ubus_manager_.SendMessage(UBUS_PLACE_VIEW_QUEUE_DRAW);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::OnResultAdded ( Result const &  result) [private]

Definition at line 302 of file LensView.cpp.

{
  try {
    PlacesGroup* group = categories_.at(result.category_index);
    ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView());

    std::string uri = result.uri;
    LOG_TRACE(logger) << "Result added: " << uri;

    grid->AddResult(const_cast<Result&>(result));
    counts_[group]++;
    UpdateCounts(group);
    // make sure we don't display the no-results-hint if we do have results
    if (G_UNLIKELY (no_results_active_))
    {
      CheckNoResults(Lens::Hints());
    }
  } catch (std::out_of_range& oor) {
    LOG_WARN(logger) << "Result does not have a valid category index: "
                     << boost::lexical_cast<unsigned int>(result.category_index)
                     << ". Is out of range.";
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::OnResultRemoved ( Result const &  result) [private]

Definition at line 326 of file LensView.cpp.

{
  try {
    PlacesGroup* group = categories_.at(result.category_index);
    ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView());

    std::string uri = result.uri;
    LOG_TRACE(logger) << "Result removed: " << uri;

    grid->RemoveResult(const_cast<Result&>(result));
    counts_[group]--;
    UpdateCounts(group);
  } catch (std::out_of_range& oor) {
    LOG_WARN(logger) << "Result does not have a valid category index: "
                     << boost::lexical_cast<unsigned int>(result.category_index)
                     << ". Is out of range.";
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::OnViewTypeChanged ( ViewType  view_type) [private]

Definition at line 474 of file LensView.cpp.

{
  if (view_type != HIDDEN && initial_activation_)
  {
    /* We reset the lens for ourselves, in case this is a restart or something */
    lens_->Search(search_string_);
    initial_activation_ = false;
  }

  lens_->view_type = view_type;
}

Here is the caller graph for this function:

void unity::dash::LensView::PerformSearch ( std::string const &  search_query)

Definition at line 434 of file LensView.cpp.

{
  search_string_ = search_query;
  lens_->Search(search_query);
}

Here is the caller graph for this function:

Definition at line 356 of file LensView.cpp.

{
  if (fix_rendering_idle_)
    return;

  fix_rendering_idle_.reset(new glib::Idle(sigc::mem_fun(this, &LensView::FixRenderering),
                                           glib::Source::Priority::DEFAULT));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 85 of file Introspectable.cpp.

{
  _children.remove(child);
  child->_parents.remove(this);
}

Here is the caller graph for this function:

Definition at line 225 of file LensView.cpp.

{
  Categories::Ptr categories = lens_->categories;
  categories->category_added.connect(sigc::mem_fun(this, &LensView::OnCategoryAdded));

  for (unsigned int i = 0; i < categories->count(); ++i)
    OnCategoryAdded(categories->RowAtIndex(i));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 244 of file LensView.cpp.

{
  Filters::Ptr filters = lens_->filters;
  filters->filter_added.connect(sigc::mem_fun(this, &LensView::OnFilterAdded));
  filters->filter_removed.connect(sigc::mem_fun(this, &LensView::OnFilterRemoved));

  for (unsigned int i = 0; i < filters->count(); ++i)
    OnFilterAdded(filters->FilterAtIndex(i));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 234 of file LensView.cpp.

{
  Results::Ptr results = lens_->results;
  results->result_added.connect(sigc::mem_fun(this, &LensView::OnResultAdded));
  results->result_removed.connect(sigc::mem_fun(this, &LensView::OnResultRemoved));

  for (unsigned int i = 0; i < results->count(); ++i)
    OnResultAdded(results->RowAtIndex(i));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::SetupViews ( nux::Area *  show_filters) [private]

Definition at line 178 of file LensView.cpp.

{
  dash::Style& style = dash::Style::Instance();

  layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
  layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenLensAndFilters());

  scroll_view_ = new LensScrollView(new PlacesVScrollBar(NUX_TRACKER_LOCATION),
                                    NUX_TRACKER_LOCATION);
  scroll_view_->EnableVerticalScrollBar(true);
  scroll_view_->EnableHorizontalScrollBar(false);
  layout_->AddView(scroll_view_);

  scroll_layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
  scroll_view_->SetLayout(scroll_layout_);
  scroll_view_->SetRightArea(show_filters);

  no_results_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION);
  no_results_->SetTextColor(nux::color::White);
  no_results_->SetVisible(false);
  scroll_layout_->AddView(no_results_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);

  fscroll_view_ = new LensScrollView(new PlacesVScrollBar(NUX_TRACKER_LOCATION), NUX_TRACKER_LOCATION);
  fscroll_view_->EnableVerticalScrollBar(true);
  fscroll_view_->EnableHorizontalScrollBar(false);
  fscroll_view_->SetVisible(false);
  fscroll_view_->SetUpArea(show_filters);
  layout_->AddView(fscroll_view_, 1);

  fscroll_layout_ = new nux::VLayout();
  fscroll_view_->SetLayout(fscroll_layout_);

  filter_bar_ = new FilterBar();
  int width = style.GetFilterBarWidth() +
              style.GetFilterBarLeftPadding() +
              style.GetFilterBarRightPadding();

  fscroll_view_->SetMinimumWidth(width + style.GetFilterViewRightPadding());
  fscroll_view_->SetMaximumWidth(width + style.GetFilterViewRightPadding());
  filter_bar_->SetMinimumWidth(width);
  filter_bar_->SetMaximumWidth(width);
  AddChild(filter_bar_);
  fscroll_layout_->AddView(filter_bar_, 0);

  SetLayout(layout_);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::LensView::UpdateCounts ( PlacesGroup group) [private]

Definition at line 345 of file LensView.cpp.

{
  unsigned int columns = dash::Style::Instance().GetDefaultNColumns();
  columns -= filters_expanded ? 2 : 0;

  group->SetCounts(columns, counts_[group]);
  group->SetVisible(counts_[group]);

  QueueFixRenderering();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 69 of file LensView.h.

Definition at line 106 of file LensView.h.

Definition at line 107 of file LensView.h.

Definition at line 117 of file LensView.h.

Definition at line 67 of file LensView.h.

Definition at line 121 of file LensView.h.

nux::VLayout* unity::dash::LensView::fscroll_layout_ [private]

Definition at line 116 of file LensView.h.

Definition at line 115 of file LensView.h.

Definition at line 108 of file LensView.h.

nux::HLayout* unity::dash::LensView::layout_ [private]

Definition at line 112 of file LensView.h.

Definition at line 105 of file LensView.h.

Definition at line 118 of file LensView.h.

Definition at line 109 of file LensView.h.

nux::VLayout* unity::dash::LensView::scroll_layout_ [private]

Definition at line 114 of file LensView.h.

Definition at line 113 of file LensView.h.

nux::ROProperty<std::string> unity::dash::LensView::search_string

Definition at line 66 of file LensView.h.

Definition at line 110 of file LensView.h.

Definition at line 120 of file LensView.h.

sigc::signal<void, std::string const&> unity::dash::LensView::uri_activated

Definition at line 71 of file LensView.h.

Definition at line 68 of file LensView.h.


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