Back to index

indicator-appmenu  12.10.0
Classes | Defines | Typedefs | Functions
hudappindicatorsource.c File Reference
#include "hudappindicatorsource.h"
#include <glib/gi18n.h>
#include <gio/gio.h>
#include "hudsettings.h"
#include "huddbusmenucollector.h"
#include "hudsource.h"

Go to the source code of this file.

Classes

struct  _HudAppIndicatorSource

Defines

#define G_LOG_DOMAIN   "hudappindicatorsource"
#define APP_INDICATOR_SERVICE_BUS_NAME   "com.canonical.indicator.application"
 SECTION:hudappindicatorsource : HudAppIndicatorSource : a #HudSource to search through the application indicators.
#define APP_INDICATOR_SERVICE_OBJECT_PATH   "/com/canonical/indicator/application/service"
#define APP_INDICATOR_SERVICE_IFACE   "com.canonical.indicator.application.service"

Typedefs

typedef GObjectClass HudAppIndicatorSourceClass

Functions

static void hud_app_indicator_source_iface_init (HudSourceInterface *iface)
 G_DEFINE_TYPE_WITH_CODE (HudAppIndicatorSource, hud_app_indicator_source, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(HUD_TYPE_SOURCE, hud_app_indicator_source_iface_init))
static void hud_app_indicator_source_add_indicator (HudAppIndicatorSource *source, GVariant *description)
static void hud_app_indicator_source_remove_indicator (HudAppIndicatorSource *source, GVariant *description)
static void hud_app_indicator_source_dbus_signal (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 hud_app_indicator_source_ready (GObject *connection, GAsyncResult *result, gpointer user_data)
static void hud_app_indicator_source_name_appeared (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
static void hud_app_indicator_source_name_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data)
static void hud_app_indicator_source_use (HudSource *hud_source)
static void hud_app_indicator_source_unuse (HudSource *hud_source)
static void hud_app_indicator_source_search (HudSource *hud_source, GPtrArray *results_array, HudTokenList *search_tokens)
static void hud_app_indicator_source_finalize (GObject *object)
static void hud_app_indicator_source_init (HudAppIndicatorSource *source)
static void hud_app_indicator_source_class_init (HudAppIndicatorSourceClass *class)
HudAppIndicatorSource * hud_app_indicator_source_new (void)
 hud_app_indicator_source_new:

Class Documentation

struct _HudAppIndicatorSource

Definition at line 51 of file hudappindicatorsource.c.

Class Members
GCancellable * cancellable
GSequence * indicators
GObject parent_instance
gboolean ready
guint subscription
gint use_count

Define Documentation

#define APP_INDICATOR_SERVICE_BUS_NAME   "com.canonical.indicator.application"

SECTION:hudappindicatorsource : HudAppIndicatorSource : a #HudSource to search through the application indicators.

HudAppIndicatorSource searches through the menus of application

indicators. HudAppIndicatorSource:

This is an opaque structure type.

Definition at line 47 of file hudappindicatorsource.c.

#define APP_INDICATOR_SERVICE_IFACE   "com.canonical.indicator.application.service"

Definition at line 49 of file hudappindicatorsource.c.

#define APP_INDICATOR_SERVICE_OBJECT_PATH   "/com/canonical/indicator/application/service"

Definition at line 48 of file hudappindicatorsource.c.

#define G_LOG_DOMAIN   "hudappindicatorsource"

Definition at line 20 of file hudappindicatorsource.c.


Typedef Documentation

typedef GObjectClass HudAppIndicatorSourceClass

Definition at line 62 of file hudappindicatorsource.c.


Function Documentation

G_DEFINE_TYPE_WITH_CODE ( HudAppIndicatorSource  ,
hud_app_indicator_source  ,
G_TYPE_OBJECT  ,
G_IMPLEMENT_INTERFACE(HUD_TYPE_SOURCE, hud_app_indicator_source_iface_init  
)

Definition at line 65 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = user_data;

  hud_source_changed (HUD_SOURCE (source));
}

Here is the call graph for this function:

static void hud_app_indicator_source_add_indicator ( HudAppIndicatorSource *  source,
GVariant *  description 
) [static]

Definition at line 78 of file hudappindicatorsource.c.

{
  HudDbusmenuCollector *collector;
  const gchar *dbus_name;
  const gchar *dbus_path;
  GSequenceIter *iter;
  const gchar *id;
  const gchar *icon_name;
  gint32 position;
  gchar *title;

  g_variant_get_child (description, 0, "&s", &icon_name);
  g_variant_get_child (description, 1, "i", &position);
  g_variant_get_child (description, 2, "&s", &dbus_name);
  g_variant_get_child (description, 3, "&o", &dbus_path);
  g_variant_get_child (description, 8, "&s", &id);
  g_variant_get_child (description, 9, "s", &title);

  if (title[0] == '\0')
    {
      g_free (title);
      /* TRANSLATORS:  This is used for Application indicators that
         are not providing a title string.  The '%s' represents the
         unique ID that the app indicator provides, but it is usually
         the package name and not generally human readable.  An example
         for Network Manager would be 'nm-applet'. */
      title = g_strdup_printf(_("Untitled Indicator (%s)"), id);
    }
  g_debug ("adding appindicator %s at %d ('%s', %s, %s, %s)", id, position, title, icon_name, dbus_name, dbus_path);

  collector = hud_dbusmenu_collector_new_for_endpoint (id, title, icon_name,
                                                       hud_settings.indicator_penalty,
                                                       dbus_name, dbus_path);
  g_signal_connect (collector, "changed", G_CALLBACK (hud_app_indicator_source_collector_changed), source);

  /* If query is active, mark new app indicator as used. */
  if (source->use_count)
    hud_source_use (HUD_SOURCE (collector));

  iter = g_sequence_get_iter_at_pos (source->indicators, position);
  g_sequence_insert_before (iter, collector);
  g_free (title);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 416 of file hudappindicatorsource.c.

{
  class->finalize = hud_app_indicator_source_finalize;
}

Here is the call graph for this function:

static void hud_app_indicator_source_dbus_signal ( GDBusConnection *  connection,
const gchar *  sender_name,
const gchar *  object_path,
const gchar *  interface_name,
const gchar *  signal_name,
GVariant *  parameters,
gpointer  user_data 
) [static]

Definition at line 149 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = user_data;

  g_debug ("got signal");

  if (!source->ready)
    {
      g_debug ("not ready, so ignoring signal");
      return;
    }

  if (g_str_equal (signal_name, "ApplicationAdded"))
    {
      if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sisossssss)")))
        return;

      hud_app_indicator_source_add_indicator (source, parameters);
      hud_source_changed (HUD_SOURCE (source));
    }

  else if (g_str_equal (signal_name, "ApplicationRemoved"))
    {
      if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(i)")))
        return;

      hud_app_indicator_source_remove_indicator (source, parameters);
      hud_source_changed (HUD_SOURCE (source));
    }

  else if (g_str_equal (signal_name, "ApplicationTitleChanged"))
    {
      GSequenceIter *iter;
      const gchar *title;
      gint32 position;

      if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(is)")))
        return;

      g_variant_get (parameters, "(i&s)", &position, &title);

      g_debug ("changing title of appindicator at %d to '%s'", position, title);

      iter = g_sequence_get_iter_at_pos (source->indicators, position);
      if (!g_sequence_iter_is_end (iter))
        {
          HudDbusmenuCollector *collector;

          collector = g_sequence_get (iter);
          hud_dbusmenu_collector_set_prefix (collector, title);
        }
    }

  else if (g_str_equal (signal_name, "ApplicationIconChanged"))
    {
      GSequenceIter *iter;
      const gchar *icon;
      gint32 position;

      if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(iss)")))
        return;

      g_variant_get (parameters, "(i&ss)", &position, &icon, NULL);

      g_debug ("changing icon of appindicator at %d to '%s'", position, icon);

      iter = g_sequence_get_iter_at_pos (source->indicators, position);
      if (!g_sequence_iter_is_end (iter))
        {
          HudDbusmenuCollector *collector;

          collector = g_sequence_get (iter);
          hud_dbusmenu_collector_set_icon (collector, icon);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_finalize ( GObject *  object) [static]

Definition at line 391 of file hudappindicatorsource.c.

{
  g_assert_not_reached ();
}

Here is the caller graph for this function:

static void hud_app_indicator_source_iface_init ( HudSourceInterface *  iface) [static]

Definition at line 408 of file hudappindicatorsource.c.

Here is the call graph for this function:

static void hud_app_indicator_source_init ( HudAppIndicatorSource *  source) [static]

Definition at line 397 of file hudappindicatorsource.c.

{
  g_debug ("online");

  source->indicators = g_sequence_new (g_object_unref);
  g_bus_watch_name (G_BUS_TYPE_SESSION, APP_INDICATOR_SERVICE_BUS_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE,
                    hud_app_indicator_source_name_appeared, hud_app_indicator_source_name_vanished,
                    g_object_ref (source), g_object_unref);
}

Here is the call graph for this function:

static void hud_app_indicator_source_name_appeared ( GDBusConnection *  connection,
const gchar *  name,
const gchar *  name_owner,
gpointer  user_data 
) [static]

Definition at line 280 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = user_data;

  g_debug ("name appeared (owner is %s)", name_owner);

  g_assert (source->subscription == 0);
  source->subscription = g_dbus_connection_signal_subscribe (connection, name_owner,
                                                             APP_INDICATOR_SERVICE_IFACE, NULL,
                                                             APP_INDICATOR_SERVICE_OBJECT_PATH, NULL,
                                                             G_DBUS_SIGNAL_FLAGS_NONE,
                                                             hud_app_indicator_source_dbus_signal,
                                                             source, NULL);

  g_assert (source->cancellable == NULL);
  source->cancellable = g_cancellable_new ();
  g_dbus_connection_call (connection, name_owner, APP_INDICATOR_SERVICE_OBJECT_PATH, APP_INDICATOR_SERVICE_IFACE,
                          "GetApplications", NULL, G_VARIANT_TYPE ("(a(sisossssss))"),
                          G_DBUS_CALL_FLAGS_NONE, -1, source->cancellable,
                          hud_app_indicator_source_ready, g_object_ref (source));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_name_vanished ( GDBusConnection *  connection,
const gchar *  name,
gpointer  user_data 
) [static]

Definition at line 306 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = user_data;

  g_debug ("name vanished");

  if (source->subscription > 0)
    {
      g_dbus_connection_signal_unsubscribe (connection, source->subscription);
      source->subscription = 0;
    }

  if (source->cancellable)
    {
      g_cancellable_cancel (source->cancellable);
      g_clear_object (&source->cancellable);
    }

  if (source->ready)
    {
      GSequenceIter *iter;

      source->ready = FALSE;

      iter = g_sequence_get_begin_iter (source->indicators);
      while (!g_sequence_iter_is_end (iter))
        {
          HudDbusmenuCollector *collector;
          GSequenceIter *next;

          collector = g_sequence_get (iter);
          g_signal_handlers_disconnect_by_func (collector, hud_app_indicator_source_collector_changed, source);
          next = g_sequence_iter_next (iter);
          g_sequence_remove (iter);
          iter = next;
        }

      hud_source_changed (HUD_SOURCE (source));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

HudAppIndicatorSource* hud_app_indicator_source_new ( void  )

hud_app_indicator_source_new:

Creates a #HudAppIndicatorSource.

Returns: a new #HudAppIndicatorSource

Definition at line 429 of file hudappindicatorsource.c.

{
  return g_object_new (HUD_TYPE_APP_INDICATOR_SOURCE, NULL);
}

Here is the caller graph for this function:

static void hud_app_indicator_source_ready ( GObject *  connection,
GAsyncResult *  result,
gpointer  user_data 
) [static]

Definition at line 233 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = user_data;
  GError *error = NULL;
  GVariant *reply;

  g_debug ("GetApplications returned");

  g_clear_object (&source->cancellable);

  reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (connection), result, &error);

  if (reply)
    {
      GVariant *description;
      GVariantIter *iter;

      g_assert (!source->ready);
      source->ready = TRUE;

      g_debug ("going ready");

      g_variant_get (reply, "(a(sisossssss))", &iter);
      while ((description = g_variant_iter_next_value (iter)))
        {
          hud_app_indicator_source_add_indicator (source, description);
          g_variant_unref (description);
        }
      g_variant_iter_free (iter);
      g_variant_unref (reply);

      hud_source_changed (HUD_SOURCE (source));
    }
  else
    {
      g_warning ("GetApplications returned an error: %s", error->message);
      g_error_free (error);
    }

  g_object_unref (source);

  g_debug ("done handling GetApplications reply");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_remove_indicator ( HudAppIndicatorSource *  source,
GVariant *  description 
) [static]

Definition at line 124 of file hudappindicatorsource.c.

{
  GSequenceIter *iter;
  gint32 position;

  g_variant_get_child (description, 0, "i", &position);

  g_debug ("removing appindicator at %d", position);

  iter = g_sequence_get_iter_at_pos (source->indicators, position);
  if (!g_sequence_iter_is_end (iter))
    {
      HudDbusmenuCollector *collector;

      collector = g_sequence_get (iter);
      g_signal_handlers_disconnect_by_func (collector, hud_app_indicator_source_collector_changed, source);
      /* Drop use count if we added one... */
      if (source->use_count)
        hud_source_unuse (HUD_SOURCE (collector));
      g_sequence_remove (iter);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_search ( HudSource *  hud_source,
GPtrArray *  results_array,
HudTokenList *  search_tokens 
) [static]

Definition at line 374 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = HUD_APP_INDICATOR_SOURCE (hud_source);
  GSequenceIter *iter;

  iter = g_sequence_get_begin_iter (source->indicators);

  while (!g_sequence_iter_is_end (iter))
    {
      hud_source_search (g_sequence_get (iter), results_array, search_tokens);
      iter = g_sequence_iter_next (iter);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_unuse ( HudSource *  hud_source) [static]

Definition at line 361 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = HUD_APP_INDICATOR_SOURCE (hud_source);

  g_return_if_fail (source->use_count > 0);

  source->use_count--;

  if (source->use_count == 0)
    g_sequence_foreach (source->indicators, (GFunc) hud_source_unuse, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_app_indicator_source_use ( HudSource *  hud_source) [static]

Definition at line 350 of file hudappindicatorsource.c.

{
  HudAppIndicatorSource *source = HUD_APP_INDICATOR_SOURCE (hud_source);

  if (source->use_count == 0)
    g_sequence_foreach (source->indicators, (GFunc) hud_source_use, NULL);

  source->use_count++;
}

Here is the call graph for this function:

Here is the caller graph for this function: