Back to index

unity  6.0.0
Static Public Member Functions
unity::DesktopUtilities Class Reference

#include <DesktopUtilities.h>

List of all members.

Static Public Member Functions

static std::string GetUserDataDirectory ()
static std::vector< std::string > GetSystemDataDirectories ()
static std::vector< std::string > GetDataDirectories ()
static std::string GetDesktopID (std::string const &desktop_path)
static std::string GetDesktopID (std::vector< std::string > const &default_paths, std::string const &desktop_path)
static std::string GetBackgroundColor (std::string const &desktop_path)

Detailed Description

Definition at line 29 of file DesktopUtilities.h.


Member Function Documentation

std::string unity::DesktopUtilities::GetBackgroundColor ( std::string const &  desktop_path) [static]

Definition at line 123 of file DesktopUtilities.cpp.

{
  GKeyFile* key_file = g_key_file_new();

  glib::Error error;
  g_key_file_load_from_file(key_file, desktop_path.c_str(), static_cast<GKeyFileFlags>(0), &error);

  if (error)
  {
    g_key_file_free(key_file);
    return "";
  }

  glib::String value(g_key_file_get_string(key_file, "Desktop Entry", "X-Unity-IconBackgroundColor", &error));

  g_key_file_free(key_file);
  return value.Str();
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::string > unity::DesktopUtilities::GetDataDirectories ( ) [static]

Definition at line 67 of file DesktopUtilities.cpp.

{
  std::vector<std::string> dirs = GetSystemDataDirectories();
  std::string const& user_directory = GetUserDataDirectory();

  dirs.push_back(user_directory);

  return dirs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string unity::DesktopUtilities::GetDesktopID ( std::string const &  desktop_path) [static]

Definition at line 116 of file DesktopUtilities.cpp.

{
  std::vector<std::string> const& data_dirs = GetDataDirectories();
  return GetDesktopID(data_dirs, desktop_path);
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string unity::DesktopUtilities::GetDesktopID ( std::vector< std::string > const &  default_paths,
std::string const &  desktop_path 
) [static]

Definition at line 77 of file DesktopUtilities.cpp.

{
  /* We check to see if the desktop file belongs to one of the system data
   * directories. If so, then we store it's desktop id, otherwise we store
   * it's full path. We're clever like that.
   */

  if (desktop_path.empty())
    return "";

  for (auto dir : default_paths)
  {
    if (!dir.empty())
    {
      if (dir.at(dir.length()-1) == G_DIR_SEPARATOR)
      {
        dir.append("applications" G_DIR_SEPARATOR_S);
      }
      else
      {
        dir.append(G_DIR_SEPARATOR_S "applications" G_DIR_SEPARATOR_S);
      }

      if (desktop_path.find(dir) == 0)
      {
        // if we are in a subdirectory of system path, the store name should
        // be subdir-filename.desktop
        std::string desktop_suffix = desktop_path.substr(dir.size());
        std::replace(desktop_suffix.begin(), desktop_suffix.end(), G_DIR_SEPARATOR, '-');

        return desktop_suffix;
      }
    }
  }

  return desktop_path;
}
std::vector< std::string > unity::DesktopUtilities::GetSystemDataDirectories ( ) [static]

Definition at line 50 of file DesktopUtilities.cpp.

{
  const char* const* system_dirs = g_get_system_data_dirs();
  std::vector<std::string> directories;

  for (unsigned int i = 0; system_dirs && system_dirs[i]; ++i)
  {
    if (system_dirs[i][0] != '\0')
    {
      std::string dir(system_dirs[i]);
      directories.push_back(dir);
    }
  }

  return directories;
}

Here is the caller graph for this function:

Definition at line 31 of file DesktopUtilities.cpp.

{
  const char* user_dir = g_get_user_data_dir();

  if (user_dir)
    return user_dir;

  // This shouldn't ever happen, but let's manually fallback to the default
  const char* home = g_get_home_dir();

  if (home)
  {
    const char* subdir = G_DIR_SEPARATOR_S ".local" G_DIR_SEPARATOR_S "share";
    return std::string(home).append(subdir);
  }

  return "";
}

Here is the caller graph for this function:


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