Back to index

unity  6.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
unity::internal::FavoriteStoreGSettings Class Reference

#include <FavoriteStoreGSettings.h>

Inheritance diagram for unity::internal::FavoriteStoreGSettings:
Inheritance graph
[legend]
Collaboration diagram for unity::internal::FavoriteStoreGSettings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FavoriteStoreGSettings ()
 FavoriteStoreGSettings (GSettingsBackend *backend)
virtual FavoriteList const & GetFavorites ()
virtual void AddFavorite (std::string const &desktop_path, int position)
virtual void RemoveFavorite (std::string const &desktop_path)
virtual void MoveFavorite (std::string const &desktop_path, int position)
void SaveFavorites (FavoriteList const &favorites, bool ignore=true)
virtual void SetFavorites (FavoriteList const &desktop_paths)
void Changed (std::string const &key)

Static Public Member Functions

static FavoriteStoreInstance ()

Public Attributes

sigc::signal< void,
std::string const
&, std::string const &, bool > 
favorite_added
sigc::signal< void,
std::string const & > 
favorite_removed
sigc::signal< void > reordered

Private Member Functions

void Init ()
void Refresh ()
void FillList (FavoriteList &list)

Private Attributes

FavoriteList favorites_
glib::Object< GSettings > settings_
bool ignore_signals_

Detailed Description

Definition at line 35 of file FavoriteStoreGSettings.h.


Constructor & Destructor Documentation

Definition at line 54 of file FavoriteStoreGSettings.cpp.

  : settings_(g_settings_new(SETTINGS_NAME))
  , ignore_signals_(false)
{
  Init();
}

Here is the call graph for this function:

Definition at line 61 of file FavoriteStoreGSettings.cpp.

  : settings_(g_settings_new_with_backend(SETTINGS_NAME, backend))
  , ignore_signals_(false)
{
  Init();
}

Here is the call graph for this function:


Member Function Documentation

void unity::internal::FavoriteStoreGSettings::AddFavorite ( std::string const &  desktop_path,
int  position 
) [virtual]

Implements unity::FavoriteStore.

Definition at line 127 of file FavoriteStoreGSettings.cpp.

{
  int size = favorites_.size();
  if (desktop_path.empty() || position > size)
    return;

  if (position < 0)
  {
    // It goes on the end.
    favorites_.push_back(desktop_path);
  }
  else
  {
    FavoriteList::iterator pos = favorites_.begin();
    std::advance(pos, position);
    favorites_.insert(pos, desktop_path);
  }

  SaveFavorites(favorites_);
  Refresh();
}

Here is the call graph for this function:

void unity::internal::FavoriteStoreGSettings::Changed ( std::string const &  key)

Definition at line 232 of file FavoriteStoreGSettings.cpp.

{
  if (ignore_signals_ or key != "favorites")
    return;

  FavoriteList old(favorites_);
  FillList(favorites_);

  auto newbies = impl::GetNewbies(old, favorites_);

  for (auto it : favorites_)
  {
    if (std::find(newbies.begin(), newbies.end(), it) == newbies.end())
      continue;

    std::string pos;
    bool before;

    impl::GetSignalAddedInfo(favorites_, newbies , it, pos, before);
    favorite_added.emit(it, pos, before);
  }

  for (auto it : impl::GetRemoved(old, favorites_))
  {
    favorite_removed.emit(it);
  }

  if (impl::NeedToBeReordered(old, favorites_))
    reordered.emit();

}

Here is the call graph for this function:

Definition at line 80 of file FavoriteStoreGSettings.cpp.

{
  list.clear();

  gchar** favs = g_settings_get_strv(settings_, "favorites");

  for (int i = 0; favs[i] != NULL; ++i)
  {
    // We will be storing either full /path/to/desktop/files or foo.desktop id's
    if (favs[i][0] == '/')
    {
      if (g_file_test(favs[i], G_FILE_TEST_EXISTS))
      {
        list.push_back(favs[i]);
      }
      else
      {
        LOG_WARNING(logger) << "Unable to load desktop file: "
                            << favs[i];
      }
    }
    else
    {
      glib::Object<GDesktopAppInfo> info(g_desktop_app_info_new(favs[i]));
      const char* filename = 0;
      if (info)
        filename = g_desktop_app_info_get_filename(info);

      if (filename)
      {
        list.push_back(filename);
      }
      else
      {
        LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '" << favs[i] << "'";
      }
    }
  }

  g_strfreev(favs);
}

Here is the caller graph for this function:

Implements unity::FavoriteStore.

Definition at line 122 of file FavoriteStoreGSettings.cpp.

{
  return favorites_;
}

Definition at line 68 of file FavoriteStoreGSettings.cpp.

{
  g_signal_connect(settings_, "changed", G_CALLBACK(on_settings_updated), this);
  Refresh();
}

Here is the call graph for this function:

Here is the caller graph for this function:

FavoriteStore & unity::FavoriteStore::Instance ( ) [static, inherited]

Definition at line 50 of file FavoriteStore.cpp.

{
  if (! favoritestore_instance)
  {
    LOG_ERROR(logger) << "No FavoriteStore instance created yet!";
  }
  return *favoritestore_instance;
}

Here is the caller graph for this function:

void unity::internal::FavoriteStoreGSettings::MoveFavorite ( std::string const &  desktop_path,
int  position 
) [virtual]

Implements unity::FavoriteStore.

Definition at line 165 of file FavoriteStoreGSettings.cpp.

{
  int size = favorites_.size();
  if (desktop_path.empty() || position > size)
    return;

  FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), desktop_path);
  if (pos == favorites_.end())
  {
    return;
  }

  favorites_.erase(pos);
  if (position < 0)
  {
    // It goes on the end.
    favorites_.push_back(desktop_path);
  }
  else
  {
    FavoriteList::iterator insert_pos = favorites_.begin();
    std::advance(insert_pos, position);
    favorites_.insert(insert_pos, desktop_path);
  }

  SaveFavorites(favorites_);
  Refresh();
}

Here is the call graph for this function:

Definition at line 75 of file FavoriteStoreGSettings.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::internal::FavoriteStoreGSettings::RemoveFavorite ( std::string const &  desktop_path) [virtual]

Implements unity::FavoriteStore.

Definition at line 149 of file FavoriteStoreGSettings.cpp.

{
  if (desktop_path.empty() || desktop_path[0] != '/')
    return;

  FavoriteList::iterator pos = std::find(favorites_.begin(), favorites_.end(), desktop_path);
  if (pos == favorites_.end())
  {
    return;
  }

  favorites_.erase(pos);
  SaveFavorites(favorites_);
  Refresh();
}

Here is the call graph for this function:

void unity::internal::FavoriteStoreGSettings::SaveFavorites ( FavoriteList const &  favorites,
bool  ignore = true 
)

Definition at line 200 of file FavoriteStoreGSettings.cpp.

{
  const int size = favorites.size();
  const char* favs[size + 1];
  favs[size] = NULL;

  int index = 0;
  // Since we don't always save the full path, we store the values we are
  // actually going to save in a different list.
  auto system_dirs = DesktopUtilities::GetDataDirectories();
  FavoriteList values;
  for (FavoriteList::const_iterator i = favorites.begin(), end = favorites.end();
       i != end; ++i, ++index)
  {
    // By using insert we get the iterator to the newly inserted string value.
    // That way we can use the c_str() method to access the const char* for
    // the string that we are going to save.  This way we know that the pointer
    // is valid for the lifetime of the favs array usage in the method call to
    // set the settings, and that we aren't referencing a temporary.
    std::string const& desktop_id = DesktopUtilities::GetDesktopID(system_dirs, *i);
    FavoriteList::iterator iter = values.insert(values.end(), desktop_id);
    favs[index] = iter->c_str();
  }

  ignore_signals_ = ignore;
  if (!g_settings_set_strv(settings_, "favorites", favs))
  {
    LOG_WARNING(logger) << "Saving favorites failed.";
  }
  ignore_signals_ = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::internal::FavoriteStoreGSettings::SetFavorites ( FavoriteList const &  desktop_paths) [virtual]

Implements unity::FavoriteStore.

Definition at line 194 of file FavoriteStoreGSettings.cpp.

{
  SaveFavorites(favorites);
  Refresh();
}

Here is the call graph for this function:


Member Data Documentation

sigc::signal<void, std::string const&, std::string const&, bool> unity::FavoriteStore::favorite_added [inherited]

Definition at line 61 of file FavoriteStore.h.

sigc::signal<void, std::string const&> unity::FavoriteStore::favorite_removed [inherited]

Definition at line 63 of file FavoriteStore.h.

Definition at line 56 of file FavoriteStoreGSettings.h.

Definition at line 58 of file FavoriteStoreGSettings.h.

sigc::signal<void> unity::FavoriteStore::reordered [inherited]

Definition at line 64 of file FavoriteStore.h.

Definition at line 57 of file FavoriteStoreGSettings.h.


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