Back to index

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

#include <LauncherEntryRemoteModel.h>

Inheritance diagram for unity::LauncherEntryRemoteModel:
Inheritance graph
[legend]
Collaboration diagram for unity::LauncherEntryRemoteModel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LauncherEntryRemoteModel ()
 Helper class implementing the remote API to control the icons in the launcher.
 ~LauncherEntryRemoteModel ()
unsigned int Size () const
 Return the number of unique LauncherEntryRemote objects managed by the model.
LauncherEntryRemote::Ptr LookupByUri (std::string const &app_uri)
 Return a smart pointer to a LauncherEntryRemote if there is one for app_uri, otherwise nullptr.
LauncherEntryRemote::Ptr LookupByDesktopId (std::string const &desktop_id)
 Return a smart pointer to a LauncherEntryRemote if there is one for desktop_id, otherwise nullptr.
LauncherEntryRemote::Ptr LookupByDesktopFile (std::string const &desktop_file_path)
 Return a smart pointer to a LauncherEntryRemote if there is one for desktop_file_path, otherwise nullptr.
std::list< std::string > GetUris () const
 Get a list of all application URIs which have registered with the launcher API.

Public Attributes

sigc::signal< void,
LauncherEntryRemote::Ptr const & > 
entry_added
sigc::signal< void,
LauncherEntryRemote::Ptr const & > 
entry_removed

Private Member Functions

void AddEntry (LauncherEntryRemote::Ptr const &entry)
 Add or update a remote launcher entry.
void RemoveEntry (LauncherEntryRemote::Ptr const &entry)
 Add or update a remote launcher entry.
void HandleUpdateRequest (std::string const &sender_name, GVariant *paramaters)
 Handle an incoming Update() signal from DBus.

Static Private Member Functions

static void OnEntrySignalReceived (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
static void OnDBusNameOwnerChanged (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)

Private Attributes

glib::Object< GDBusConnection > _conn
unsigned int _launcher_entry_dbus_signal_id
unsigned int _dbus_name_owner_changed_signal_id
std::map< std::string,
LauncherEntryRemote::Ptr
_entries_by_uri

Detailed Description

Definition at line 32 of file LauncherEntryRemoteModel.h.


Constructor & Destructor Documentation

Helper class implementing the remote API to control the icons in the launcher.

Also known as the com.canonical.Unity.LauncherEntry DBus API. It enables clients to dynamically control their launcher icons by adding a counter, progress indicator, or emblem to it. It also supports adding a quicklist menu by means of the dbusmenu library.

We take care to print out any client side errors or oddities in detail, in order to help third party developers as much as possible when integrating with Unity.

Definition at line 45 of file LauncherEntryRemoteModel.cpp.

  : _launcher_entry_dbus_signal_id(0)
  , _dbus_name_owner_changed_signal_id(0)
{
  glib::Error error;

  _conn = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error);
  if (error)
  {
    LOG_ERROR(logger) << "Unable to connect to session bus: " << error.Message();
    return;
  }

  /* Listen for *all* signals on the "com.canonical.Unity.LauncherEntry"
   * interface, no matter who the sender is */
  _launcher_entry_dbus_signal_id =
    g_dbus_connection_signal_subscribe(_conn,
                                       nullptr,                  // sender
                                       "com.canonical.Unity.LauncherEntry", // iface
                                       nullptr,                  // member
                                       nullptr,                  // path
                                       nullptr,                  // arg0
                                       G_DBUS_SIGNAL_FLAGS_NONE,
                                       &OnEntrySignalReceived,
                                       this,
                                       nullptr);

  _dbus_name_owner_changed_signal_id =
    g_dbus_connection_signal_subscribe(_conn,
                                       "org.freedesktop.DBus",   // sender
                                       "org.freedesktop.DBus",   // interface
                                       "NameOwnerChanged",       // member
                                       "/org/freedesktop/DBus",  // path
                                       nullptr,                  // arg0
                                       G_DBUS_SIGNAL_FLAGS_NONE,
                                       &OnDBusNameOwnerChanged,
                                       this,
                                       nullptr);
}

Here is the call graph for this function:

Definition at line 85 of file LauncherEntryRemoteModel.cpp.

{
  if (_conn)
  {
    if (_launcher_entry_dbus_signal_id)
    {
      g_dbus_connection_signal_unsubscribe(_conn,
                                           _launcher_entry_dbus_signal_id);
    }

    if (_dbus_name_owner_changed_signal_id)
    {
      g_dbus_connection_signal_unsubscribe(_conn,
                                           _dbus_name_owner_changed_signal_id);
    }
  }
}

Member Function Documentation

Add or update a remote launcher entry.

Definition at line 171 of file LauncherEntryRemoteModel.cpp.

{
  auto existing_entry = LookupByUri(entry->AppUri());

  if (existing_entry)
  {
    existing_entry->Update(entry);
  }
  else
  {
    _entries_by_uri[entry->AppUri()] = entry;
    entry_added.emit(entry);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::list< std::string > unity::LauncherEntryRemoteModel::GetUris ( ) const

Get a list of all application URIs which have registered with the launcher API.

Definition at line 158 of file LauncherEntryRemoteModel.cpp.

{
  std::list<std::string> uris;

  for (auto entry : _entries_by_uri)
    uris.push_back(entry.first);

  return uris;
}
void unity::LauncherEntryRemoteModel::HandleUpdateRequest ( std::string const &  sender_name,
GVariant *  paramaters 
) [private]

Handle an incoming Update() signal from DBus.

Definition at line 198 of file LauncherEntryRemoteModel.cpp.

{
  if (!parameters)
    return;

  if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sa{sv})")))
  {
    LOG_ERROR(logger) << "Received 'com.canonical.Unity.LauncherEntry.Update' with"
                         " illegal payload signature '"
                      << g_variant_get_type_string(parameters)
                      << "'. Expected '(sa{sv})'.";
    return;
  }

  glib::String app_uri;
  GVariantIter* prop_iter;
  g_variant_get(parameters, "(sa{sv})", &app_uri, &prop_iter);

  auto entry = LookupByUri(app_uri.Str());

  if (entry)
  {
    /* It's important that we update the DBus name first since it might
     * unset the quicklist if it changes */
    entry->SetDBusName(sender_name);
    entry->Update(prop_iter);
  }
  else
  {
    LauncherEntryRemote::Ptr entry_ptr(new LauncherEntryRemote(sender_name, parameters));
    AddEntry(entry_ptr);
  }

  g_variant_iter_free(prop_iter);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Return a smart pointer to a LauncherEntryRemote if there is one for desktop_file_path, otherwise nullptr.

Definition at line 144 of file LauncherEntryRemoteModel.cpp.

{
  std::string const& desktop_id = DesktopUtilities::GetDesktopID(desktop_file_path);

  if (desktop_id.empty())
    return nullptr;

  return LookupByDesktopId(desktop_id);
}

Here is the call graph for this function:

Return a smart pointer to a LauncherEntryRemote if there is one for desktop_id, otherwise nullptr.

The desktop id is the base name of the .desktop file for the application including the .desktop extension. Eg. firefox.desktop.

Definition at line 134 of file LauncherEntryRemoteModel.cpp.

{
  std::string prefix = "application://";
  return LookupByUri(prefix + desktop_id);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Return a smart pointer to a LauncherEntryRemote if there is one for app_uri, otherwise nullptr.

App Uris look like application://$desktop_file_id, where desktop_file_id is the base name of the .desktop file for the application including the .desktop extension. Eg. application://firefox.desktop.

Definition at line 120 of file LauncherEntryRemoteModel.cpp.

{
  auto target_en = _entries_by_uri.find(app_uri);

  return (target_en != _entries_by_uri.end()) ? target_en->second : nullptr;
}

Here is the caller graph for this function:

void unity::LauncherEntryRemoteModel::OnDBusNameOwnerChanged ( GDBusConnection *  connection,
const gchar *  sender_name,
const gchar *  object_path,
const gchar *  interface_name,
const gchar *  signal_name,
GVariant *  parameters,
gpointer  user_data 
) [static, private]

Definition at line 272 of file LauncherEntryRemoteModel.cpp.

{
  auto self = static_cast<LauncherEntryRemoteModel*>(user_data);

  if (!parameters || self->_entries_by_uri.empty())
    return;

  glib::String name, before, after;
  g_variant_get(parameters, "(sss)", &name, &before, &after);

  if (!after || after.Str().empty())
  {
    // Name gone, find and destroy LauncherEntryRemote
    std::vector<LauncherEntryRemote::Ptr> to_rm;

    for (auto it = self->_entries_by_uri.begin(); it != self->_entries_by_uri.end(); ++it)
    {
      auto entry = it->second;

      if (entry->DBusName() == name.Str())
      {
        to_rm.push_back(entry);
      }
    }

    for (auto entry : to_rm)
    {
      self->RemoveEntry(entry);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::LauncherEntryRemoteModel::OnEntrySignalReceived ( GDBusConnection *  connection,
const gchar *  sender_name,
const gchar *  object_path,
const gchar *  interface_name,
const gchar *  signal_name,
GVariant *  parameters,
gpointer  user_data 
) [static, private]

Definition at line 235 of file LauncherEntryRemoteModel.cpp.

{
  auto self = static_cast<LauncherEntryRemoteModel*>(user_data);

  if (!parameters || !signal_name)
  {
    LOG_ERROR(logger) << "Received DBus signal '" << interface_name << "."
                      << signal_name << "' with empty payload from " << sender_name;
    return;
  }

  if (std::string(signal_name) == "Update")
  {
    if (!sender_name)
    {
      LOG_ERROR(logger) << "Received 'com.canonical.Unity.LauncherEntry.Update' from"
                           " an undefined sender. This may happen if you are trying "
                           "to run Unity on a p2p DBus connection.";
      return;
    }

    self->HandleUpdateRequest(sender_name, parameters);
  }
  else
  {
    LOG_ERROR(logger) << "Unknown signal '" << interface_name << "."
                      << signal_name << "' from " << sender_name;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Add or update a remote launcher entry.

Definition at line 189 of file LauncherEntryRemoteModel.cpp.

{
  _entries_by_uri.erase(entry->AppUri());
  entry_removed.emit(entry);
}
unsigned int unity::LauncherEntryRemoteModel::Size ( ) const

Return the number of unique LauncherEntryRemote objects managed by the model.

The entries are identified by their LauncherEntryRemote::AppUri property.

Definition at line 107 of file LauncherEntryRemoteModel.cpp.

{
  return _entries_by_uri.size();
}

Member Data Documentation

Definition at line 68 of file LauncherEntryRemoteModel.h.

Definition at line 70 of file LauncherEntryRemoteModel.h.

Definition at line 71 of file LauncherEntryRemoteModel.h.

Definition at line 69 of file LauncherEntryRemoteModel.h.

Definition at line 44 of file LauncherEntryRemoteModel.h.

Definition at line 45 of file LauncherEntryRemoteModel.h.


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