Back to index

unity  6.0.0
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
unity::launcher::LauncherModel Class Reference

#include <LauncherModel.h>

Inheritance diagram for unity::launcher::LauncherModel:
Inheritance graph
[legend]
Collaboration diagram for unity::launcher::LauncherModel:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< LauncherModel
Ptr
typedef std::vector
< AbstractLauncherIcon::Ptr
Base
typedef Base::iterator iterator
typedef Base::const_iterator const_iterator
typedef Base::reverse_iterator reverse_iterator
typedef Base::reverse_iterator const_reverse_iterator
typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 LauncherModel ()
void AddIcon (AbstractLauncherIcon::Ptr icon)
void RemoveIcon (AbstractLauncherIcon::Ptr icon)
void Save ()
void Sort ()
int Size () const
void OnIconRemove (AbstractLauncherIcon::Ptr icon)
bool IconHasSister (AbstractLauncherIcon::Ptr icon) const
void ReorderAfter (AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other)
void ReorderBefore (AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save)
void ReorderSmart (AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save)
AbstractLauncherIcon::Ptr Selection () const
int SelectionIndex () const
void SetSelection (int selection)
void SelectNext ()
void SelectPrevious ()
iterator begin ()
iterator end ()
iterator at (int index)
reverse_iterator rbegin ()
reverse_iterator rend ()
iterator main_begin ()
iterator main_end ()
reverse_iterator main_rbegin ()
reverse_iterator main_rend ()
iterator shelf_begin ()
iterator shelf_end ()
reverse_iterator shelf_rbegin ()
reverse_iterator shelf_rend ()
IntrospectableList GetIntrospectableChildren ()
template<class T >
std::list
< AbstractLauncherIcon::Ptr
GetSublist ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
guint64 GetIntrospectionId () const

Public Attributes

sigc::signal< void,
AbstractLauncherIcon::Ptr
icon_added
sigc::signal< void,
AbstractLauncherIcon::Ptr
icon_removed
sigc::signal< void > order_changed
sigc::signal< void > saved
sigc::signal< void,
AbstractLauncherIcon::Ptr
selection_changed

Protected Member Functions

std::string GetName () const
void AddProperties (GVariantBuilder *builder)
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 Member Functions

bool Populate ()
bool IconShouldShelf (AbstractLauncherIcon::Ptr icon) const

Static Private Member Functions

static bool CompareIcons (AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second)

Private Attributes

Base _inner
Base _inner_shelf
Base _inner_main
int selection_
std::list
< unity::debug::Introspectable * > 
introspection_results_
glib::SourceManager timeouts_

Detailed Description

Definition at line 32 of file LauncherModel.h.


Member Typedef Documentation

Definition at line 36 of file LauncherModel.h.

typedef Base::const_iterator unity::launcher::LauncherModel::const_iterator

Definition at line 38 of file LauncherModel.h.

Definition at line 40 of file LauncherModel.h.

Definition at line 34 of file Introspectable.h.

Definition at line 37 of file LauncherModel.h.

Definition at line 35 of file LauncherModel.h.

typedef Base::reverse_iterator unity::launcher::LauncherModel::reverse_iterator

Definition at line 39 of file LauncherModel.h.


Constructor & Destructor Documentation

Definition at line 31 of file LauncherModel.cpp.

  : selection_(0)
{
}

Member Function Documentation

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:

Definition at line 100 of file LauncherModel.cpp.

{
  if (IconShouldShelf(icon))
    _inner_shelf.push_back(icon);
  else
    _inner_main.push_back(icon);

  Sort();

  icon_added.emit(icon);

  if (icon->on_icon_removed_connection.connected())
    icon->on_icon_removed_connection.disconnect();
  icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove));
}

Here is the call graph for this function:

void unity::launcher::LauncherModel::AddProperties ( GVariantBuilder *  builder) [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 41 of file LauncherModel.cpp.

{
  unity::variant::BuilderWrapper(builder)
  .add("selection", selection_);
}

Here is the call graph for this function:

Definition at line 409 of file LauncherModel.cpp.

{
  LauncherModel::iterator it;
  int i;

  // start currently selected icon
  for (it = _inner.begin(), i = 0; it != _inner.end(); it++, i++)
  {
    if (i == index)
      return it;
  }

  return (LauncherModel::iterator)NULL;
}

Definition at line 397 of file LauncherModel.cpp.

{
  return _inner.begin();
}

Here is the caller graph for this function:

Definition at line 62 of file LauncherModel.cpp.

{
  if (first->GetIconType() < second->GetIconType())
    return true;
  else if (first->GetIconType() > second->GetIconType())
    return false;

  return first->SortPriority() < second->SortPriority();
}

Here is the caller graph for this function:

Definition at line 403 of file LauncherModel.cpp.

{
  return _inner.end();
}

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:

Reimplemented from unity::debug::Introspectable.

Definition at line 47 of file LauncherModel.cpp.

{
  introspection_results_.clear();

  for (auto icon : _inner)
    introspection_results_.push_back(icon.GetPointer());

  return introspection_results_;
}
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::launcher::LauncherModel::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 36 of file LauncherModel.cpp.

{
  return "LauncherModel";
}
template<class T >
std::list<AbstractLauncherIcon::Ptr> unity::launcher::LauncherModel::GetSublist ( ) [inline]

Definition at line 110 of file LauncherModel.h.

  {
    std::list<AbstractLauncherIcon::Ptr> result;

    iterator it;
    for (it = begin(); it != end(); it++)
    {
      T* var = dynamic_cast<T*>((*it).GetPointer());

      if (var)
        result.push_back(*it);
    }

    return result;
  }

Here is the call graph for this function:

Definition at line 162 of file LauncherModel.cpp.

{
  const_iterator it;
  const_iterator end;

  if (icon && icon->GetIconType() == AbstractLauncherIcon::TYPE_DEVICE)
    return true;

  if (IconShouldShelf(icon))
  {
    it = _inner_shelf.begin();
    end = _inner_shelf.end();
  }
  else
  {
    it = _inner_main.begin();
    end = _inner_main.end();
  }

  for (; it != end; ++it)
  {
    AbstractLauncherIcon::Ptr iter_icon = *it;
    if ((iter_icon  != icon)
        && iter_icon->GetIconType() == icon->GetIconType())
      return true;
  }

  return false;
}

Here is the call graph for this function:

Definition at line 57 of file LauncherModel.cpp.

{
  return icon->GetIconType() == AbstractLauncherIcon::TYPE_TRASH;
}

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 437 of file LauncherModel.cpp.

{
  return _inner_main.begin();
}

Here is the caller graph for this function:

Definition at line 443 of file LauncherModel.cpp.

{
  return _inner_main.end();
}

Here is the caller graph for this function:

Definition at line 449 of file LauncherModel.cpp.

{
  return _inner_main.rbegin();
}

Definition at line 455 of file LauncherModel.cpp.

{
  return _inner_main.rend();
}

Definition at line 134 of file LauncherModel.cpp.

{
  auto timeout = std::make_shared<glib::Timeout>(1000);
  timeouts_.Add(timeout);

  timeout->Run([&, icon] {
    RemoveIcon(icon);
    return false;
  });
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 73 of file LauncherModel.cpp.

{
  Base copy = _inner;

  _inner.clear();

  iterator it, it2;

  int i = 0;
  for (it = main_begin(); it != main_end(); it++)
  {
    _inner.push_back(*it);
    (*it)->SetSortPriority(i);
    ++i;
  }

  for (it = shelf_begin(); it != shelf_end(); it++)
  {
    _inner.push_back(*it);
    (*it)->SetSortPriority(i);
    ++i;
  }

  return copy.size() == _inner.size() && !std::equal(begin(), end(), copy.begin());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 425 of file LauncherModel.cpp.

{
  return _inner.rbegin();
}

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 117 of file LauncherModel.cpp.

{
  size_t size;

  _inner_shelf.erase(std::remove(_inner_shelf.begin(), _inner_shelf.end(), icon), _inner_shelf.end());
  _inner_main.erase(std::remove(_inner_main.begin(), _inner_main.end(), icon), _inner_main.end());

  size = _inner.size();
  _inner.erase(std::remove(_inner.begin(), _inner.end(), icon), _inner.end());

  if (size != _inner.size())
  {
    icon_removed.emit(icon);
  }
}

Here is the caller graph for this function:

Definition at line 431 of file LauncherModel.cpp.

{
  return _inner.rend();
}

Definition at line 193 of file LauncherModel.cpp.

{
  if (icon == other || icon.IsNull() || other.IsNull())
    return;

  if (icon->GetIconType() != other->GetIconType())
    return;

  int i = 0;
  for (LauncherModel::iterator it = begin(); it != end(); ++it)
  {
    if ((*it) == icon)
      continue;

    if ((*it) == other)
    {
      (*it)->SetSortPriority(i);
      ++i;

      icon->SetSortPriority(i);
      ++i;
    }
    else
    {
      (*it)->SetSortPriority(i);
      ++i;
    }
  }

  Sort();
}

Here is the call graph for this function:

Definition at line 226 of file LauncherModel.cpp.

{
  if (icon == other || icon.IsNull() || other.IsNull())
    return;

  if (icon->GetIconType() != other->GetIconType())
    return;

  int i = 0;
  int j = 0;
  for (auto icon_it : _inner)
  {
    if (icon_it == icon)
    {
      j++;
      continue;
    }

    if (icon_it == other)
    {
      icon->SetSortPriority(i);
      if (i != j && save)
        icon_it->SaveCenter();
      i++;

      icon_it->SetSortPriority(i);
      if (i != j && save)
        icon_it->SaveCenter();
      i++;
    }
    else
    {
      icon_it->SetSortPriority(i);
      if (i != j && save)
        icon_it->SaveCenter();
      i++;
    }
    j++;
  }

  Sort();
}

Here is the call graph for this function:

Definition at line 270 of file LauncherModel.cpp.

{
  if (icon == other || icon.IsNull() || other.IsNull())
    return;

  if (icon->GetIconType() != other->GetIconType())
    return;

  int i = 0;
  int j = 0;
  bool skipped = false;
  for (auto icon_it : _inner)
  {
    if (icon_it == icon)
    {
      skipped = true;
      j++;
      continue;
    }

    if (icon_it == other)
    {
      if (!skipped)
      {
        icon->SetSortPriority(i);
        if (i != j && save)
          icon_it->SaveCenter();
        i++;
      }

      icon_it->SetSortPriority(i);
      if (i != j && save)
        icon_it->SaveCenter();
      i++;

      if (skipped)
      {
        icon->SetSortPriority(i);
        if (i != j && save)
          icon_it->SaveCenter();
        i++;
      }
    }
    else
    {
      icon_it->SetSortPriority(i);
      if (i != j && save)
        icon_it->SaveCenter();
      i++;
    }
    j++;
  }

  Sort();
}

Here is the call graph for this function:

Definition at line 146 of file LauncherModel.cpp.

{
  saved.emit();
}

Definition at line 332 of file LauncherModel.cpp.

{
  return _inner[selection_];
}

Here is the caller graph for this function:

Definition at line 337 of file LauncherModel.cpp.

{
  return selection_;
}

Definition at line 353 of file LauncherModel.cpp.

{
  int temp = selection_;

  temp++;
  while (temp != selection_)
  {
    if (temp >= Size())
      temp = 0;

    if (_inner[temp]->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE))
    {
      selection_ = temp;
      selection_changed.emit(Selection());
      break;
    }
    temp++;
  }
}

Here is the call graph for this function:

Definition at line 373 of file LauncherModel.cpp.

{
  int temp = selection_;

  temp--;
  while (temp != selection_)
  {
    if (temp < 0)
      temp = Size() - 1;

    if (_inner[temp]->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE))
    {
      selection_ = temp;
      selection_changed.emit(Selection());
      break;
    }
    temp--;
  }
}

Here is the call graph for this function:

Definition at line 342 of file LauncherModel.cpp.

{
  int new_selection = std::min<int>(Size() - 1, std::max<int> (0, selection));

  if (new_selection == selection_)
    return;

  selection_ = new_selection;
  selection_changed.emit(Selection());
}

Here is the call graph for this function:

Definition at line 461 of file LauncherModel.cpp.

{
  return _inner_shelf.begin();
}

Here is the caller graph for this function:

Definition at line 467 of file LauncherModel.cpp.

{
  return _inner_shelf.end();
}

Here is the caller graph for this function:

Definition at line 473 of file LauncherModel.cpp.

{
  return _inner_shelf.rbegin();
}

Definition at line 479 of file LauncherModel.cpp.

{
  return _inner_shelf.rend();
}

Definition at line 327 of file LauncherModel.cpp.

{
  return _inner.size();
}

Here is the caller graph for this function:

Definition at line 152 of file LauncherModel.cpp.

{
  std::stable_sort(_inner_shelf.begin(), _inner_shelf.end(), &LauncherModel::CompareIcons);
  std::stable_sort(_inner_main.begin(), _inner_main.end(), &LauncherModel::CompareIcons);

  if (Populate())
    order_changed.emit();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 94 of file LauncherModel.h.

Definition at line 96 of file LauncherModel.h.

Definition at line 95 of file LauncherModel.h.

Definition at line 81 of file LauncherModel.h.

Definition at line 82 of file LauncherModel.h.

Definition at line 98 of file LauncherModel.h.

Definition at line 83 of file LauncherModel.h.

Definition at line 84 of file LauncherModel.h.

Definition at line 97 of file LauncherModel.h.

Definition at line 85 of file LauncherModel.h.

Definition at line 99 of file LauncherModel.h.


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