Back to index

indicator-appmenu  12.10.0
Classes | Typedefs | Functions | Variables
gactionmuxer.c File Reference
#include "config.h"
#include "gactionmuxer.h"
#include "gactionobservable.h"
#include "gactionobserver.h"
#include <string.h>

Go to the source code of this file.

Classes

struct  _GActionMuxer
struct  Group

Typedefs

typedef GObjectClass GActionMuxerClass

Functions

static void g_action_muxer_group_iface_init (GActionGroupInterface *iface)
static void g_action_muxer_observable_iface_init (GActionObservableInterface *iface)
 G_DEFINE_TYPE_WITH_CODE (GActionMuxer, g_action_muxer, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION_OBSERVABLE, g_action_muxer_observable_iface_init))
static gchar ** g_action_muxer_list_actions (GActionGroup *action_group)
static Groupg_action_muxer_find_group (GActionMuxer *muxer, const gchar **name)
static Actiong_action_muxer_lookup_action (GActionMuxer *muxer, const gchar *prefix, const gchar *action_name, gchar **fullname)
static void g_action_muxer_action_enabled_changed (GActionGroup *action_group, const gchar *action_name, gboolean enabled, gpointer user_data)
static void g_action_muxer_action_state_changed (GActionGroup *action_group, const gchar *action_name, GVariant *state, gpointer user_data)
static void g_action_muxer_action_added (GActionGroup *action_group, const gchar *action_name, gpointer user_data)
static void g_action_muxer_action_removed (GActionGroup *action_group, const gchar *action_name, gpointer user_data)
static gboolean g_action_muxer_query_action (GActionGroup *action_group, const gchar *action_name, gboolean *enabled, const GVariantType **parameter_type, const GVariantType **state_type, GVariant **state_hint, GVariant **state)
static void g_action_muxer_activate_action (GActionGroup *action_group, const gchar *action_name, GVariant *parameter)
static void g_action_muxer_change_action_state (GActionGroup *action_group, const gchar *action_name, GVariant *state)
static void g_action_muxer_unregister_internal (Action *action, gpointer observer)
static void g_action_muxer_weak_notify (gpointer data, GObject *where_the_object_was)
static void g_action_muxer_register_observer (GActionObservable *observable, const gchar *name, GActionObserver *observer)
static void g_action_muxer_unregister_observer (GActionObservable *observable, const gchar *name, GActionObserver *observer)
static void g_action_muxer_free_group (gpointer data)
static void g_action_muxer_finalize (GObject *object)
static void g_action_muxer_init (GActionMuxer *muxer)
static void g_action_muxer_class_init (GObjectClass *class)
void g_action_muxer_insert (GActionMuxer *muxer, const gchar *prefix, GActionGroup *action_group)
void g_action_muxer_remove (GActionMuxer *muxer, const gchar *prefix)
GActionMuxer * g_action_muxer_new (void)

Variables

 Action

Class Documentation

struct _GActionMuxer

Definition at line 62 of file gactionmuxer.c.

Class Members
GHashTable * actions
GHashTable * groups
GObject parent_instance
struct Group

Definition at line 81 of file gactionmuxer.c.

Class Members
GActionGroup * group
gulong handler_ids
GActionMuxer * muxer
gchar * prefix

Typedef Documentation

typedef GObjectClass GActionMuxerClass

Definition at line 60 of file gactionmuxer.c.


Function Documentation

static void g_action_muxer_action_added ( GActionGroup *  action_group,
const gchar *  action_name,
gpointer  user_data 
) [static]

Definition at line 170 of file gactionmuxer.c.

{
  const GVariantType *parameter_type;
  Group *group = user_data;
  gboolean enabled;
  GVariant *state;

  if (g_action_group_query_action (group->group, action_name, &enabled, &parameter_type, NULL, NULL, &state))
    {
      gchar *fullname;
      Action *action;
      GSList *node;

      action = g_action_muxer_lookup_action (group->muxer, group->prefix, action_name, &fullname);

      for (node = action ? action->watchers : NULL; node; node = node->next)
        g_action_observer_action_added (node->data,
                                        G_ACTION_OBSERVABLE (group->muxer),
                                        fullname, parameter_type, enabled, state);

      g_action_group_action_added (G_ACTION_GROUP (group->muxer), fullname);

      if (state)
        g_variant_unref (state);

      g_free (fullname);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_action_enabled_changed ( GActionGroup *  action_group,
const gchar *  action_name,
gboolean  enabled,
gpointer  user_data 
) [static]

Definition at line 134 of file gactionmuxer.c.

{
  Group *group = user_data;
  gchar *fullname;
  Action *action;
  GSList *node;

  action = g_action_muxer_lookup_action (group->muxer, group->prefix, action_name, &fullname);
  for (node = action ? action->watchers : NULL; node; node = node->next)
    g_action_observer_action_enabled_changed (node->data, G_ACTION_OBSERVABLE (group->muxer), fullname, enabled);
  g_action_group_action_enabled_changed (G_ACTION_GROUP (group->muxer), fullname, enabled);
  g_free (fullname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_action_removed ( GActionGroup *  action_group,
const gchar *  action_name,
gpointer  user_data 
) [static]

Definition at line 202 of file gactionmuxer.c.

{
  Group *group = user_data;
  gchar *fullname;
  Action *action;
  GSList *node;

  action = g_action_muxer_lookup_action (group->muxer, group->prefix, action_name, &fullname);
  for (node = action ? action->watchers : NULL; node; node = node->next)
    g_action_observer_action_removed (node->data, G_ACTION_OBSERVABLE (group->muxer), fullname);
  g_action_group_action_removed (G_ACTION_GROUP (group->muxer), fullname);
  g_free (fullname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_action_state_changed ( GActionGroup *  action_group,
const gchar *  action_name,
GVariant *  state,
gpointer  user_data 
) [static]

Definition at line 152 of file gactionmuxer.c.

{
  Group *group = user_data;
  gchar *fullname;
  Action *action;
  GSList *node;

  action = g_action_muxer_lookup_action (group->muxer, group->prefix, action_name, &fullname);
  for (node = action ? action->watchers : NULL; node; node = node->next)
    g_action_observer_action_state_changed (node->data, G_ACTION_OBSERVABLE (group->muxer), fullname, state);
  g_action_group_action_state_changed (G_ACTION_GROUP (group->muxer), fullname, state);
  g_free (fullname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_activate_action ( GActionGroup *  action_group,
const gchar *  action_name,
GVariant *  parameter 
) [static]

Definition at line 240 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (action_group);
  Group *group;

  group = g_action_muxer_find_group (muxer, &action_name);

  if (group)
    g_action_group_activate_action (group->group, action_name, parameter);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_change_action_state ( GActionGroup *  action_group,
const gchar *  action_name,
GVariant *  state 
) [static]

Definition at line 254 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (action_group);
  Group *group;

  group = g_action_muxer_find_group (muxer, &action_name);

  if (group)
    g_action_group_change_action_state (group->group, action_name, state);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_class_init ( GObjectClass *  class) [static]

Definition at line 387 of file gactionmuxer.c.

{
  class->finalize = g_action_muxer_finalize;
}

Here is the call graph for this function:

static void g_action_muxer_finalize ( GObject *  object) [static]

Definition at line 351 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (object);

  g_assert_cmpint (g_hash_table_size (muxer->actions), ==, 0);
  g_hash_table_unref (muxer->actions);
  g_hash_table_unref (muxer->groups);

  G_OBJECT_CLASS (g_action_muxer_parent_class)
    ->finalize (object);
}

Here is the caller graph for this function:

static Group* g_action_muxer_find_group ( GActionMuxer *  muxer,
const gchar **  name 
) [static]

Definition at line 98 of file gactionmuxer.c.

{
  const gchar *dot;
  gchar *prefix;
  Group *group;

  dot = strchr (*name, '.');

  if (!dot)
    return NULL;

  prefix = g_strndup (*name, dot - *name);
  group = g_hash_table_lookup (muxer->groups, prefix);
  g_free (prefix);

  *name = dot + 1;

  return group;
}

Here is the caller graph for this function:

static void g_action_muxer_free_group ( gpointer  data) [static]

Definition at line 340 of file gactionmuxer.c.

{
  Group *group = data;

  g_object_unref (group->group);
  g_free (group->prefix);

  g_slice_free (Group, group);
}

Here is the caller graph for this function:

static void g_action_muxer_group_iface_init ( GActionGroupInterface *  iface) [static]

Definition at line 378 of file gactionmuxer.c.

{
  iface->list_actions = g_action_muxer_list_actions;
  iface->query_action = g_action_muxer_query_action;
  iface->activate_action = g_action_muxer_activate_action;
  iface->change_action_state = g_action_muxer_change_action_state;
}

Here is the call graph for this function:

static void g_action_muxer_init ( GActionMuxer *  muxer) [static]

Definition at line 364 of file gactionmuxer.c.

{
  muxer->actions = g_hash_table_new (g_str_hash, g_str_equal);
  muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_action_muxer_free_group);
}

Here is the call graph for this function:

void g_action_muxer_insert ( GActionMuxer *  muxer,
const gchar *  prefix,
GActionGroup *  action_group 
)

Definition at line 413 of file gactionmuxer.c.

{
  gchar **actions;
  Group *group;
  gint i;

  /* TODO: diff instead of ripout and replace */
  g_action_muxer_remove (muxer, prefix);

  group = g_slice_new (Group);
  group->muxer = muxer;
  group->group = g_object_ref (action_group);
  group->prefix = g_strdup (prefix);

  g_hash_table_insert (muxer->groups, group->prefix, group);

  actions = g_action_group_list_actions (group->group);
  for (i = 0; actions[i]; i++)
    g_action_muxer_action_added (group->group, actions[i], group);
  g_strfreev (actions);

  group->handler_ids[0] = g_signal_connect (group->group, "action-added",
                                            G_CALLBACK (g_action_muxer_action_added), group);
  group->handler_ids[1] = g_signal_connect (group->group, "action-removed",
                                            G_CALLBACK (g_action_muxer_action_removed), group);
  group->handler_ids[2] = g_signal_connect (group->group, "action-enabled-changed",
                                            G_CALLBACK (g_action_muxer_action_enabled_changed), group);
  group->handler_ids[3] = g_signal_connect (group->group, "action-state-changed",
                                            G_CALLBACK (g_action_muxer_action_state_changed), group);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gchar** g_action_muxer_list_actions ( GActionGroup *  action_group) [static]

Definition at line 90 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (action_group);

  return (gchar **) muxer->groups;
}

Here is the caller graph for this function:

static Action* g_action_muxer_lookup_action ( GActionMuxer *  muxer,
const gchar *  prefix,
const gchar *  action_name,
gchar **  fullname 
) [static]

Definition at line 120 of file gactionmuxer.c.

{
  Action *action;

  *fullname = g_strconcat (prefix, ".", action_name, NULL);
  action = g_hash_table_lookup (muxer->actions, *fullname);

  return action;
}

Here is the caller graph for this function:

GActionMuxer* g_action_muxer_new ( void  )

Definition at line 490 of file gactionmuxer.c.

{
  return g_object_new (G_TYPE_ACTION_MUXER, NULL);
}

Here is the caller graph for this function:

static void g_action_muxer_observable_iface_init ( GActionObservableInterface *  iface) [static]

Definition at line 371 of file gactionmuxer.c.

{
  iface->register_observer = g_action_muxer_register_observer;
  iface->unregister_observer = g_action_muxer_unregister_observer;
}

Here is the call graph for this function:

static gboolean g_action_muxer_query_action ( GActionGroup *  action_group,
const gchar *  action_name,
gboolean *  enabled,
const GVariantType **  parameter_type,
const GVariantType **  state_type,
GVariant **  state_hint,
GVariant **  state 
) [static]

Definition at line 219 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (action_group);
  Group *group;

  group = g_action_muxer_find_group (muxer, &action_name);

  if (!group)
    return FALSE;

  return g_action_group_query_action (group->group, action_name, enabled,
                                      parameter_type, state_type, state_hint, state);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_register_observer ( GActionObservable *  observable,
const gchar *  name,
GActionObserver *  observer 
) [static]

Definition at line 303 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (observable);
  Action *action;

  action = g_hash_table_lookup (muxer->actions, name);

  if (action == NULL)
    {
      action = g_slice_new (Action);
      action->muxer = g_object_ref (muxer);
      action->fullname = g_strdup (name);
      action->watchers = NULL;

      g_hash_table_insert (muxer->actions, action->fullname, action);
    }

  action->watchers = g_slist_prepend (action->watchers, observer);
  g_object_weak_ref (G_OBJECT (observer), g_action_muxer_weak_notify, action);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void g_action_muxer_remove ( GActionMuxer *  muxer,
const gchar *  prefix 
)

Definition at line 457 of file gactionmuxer.c.

{
  Group *group;

  group = g_hash_table_lookup (muxer->groups, prefix);

  if (group != NULL)
    {
      gchar **actions;
      gint i;

      g_hash_table_steal (muxer->groups, prefix);

      actions = g_action_group_list_actions (group->group);
      for (i = 0; actions[i]; i++)
        g_action_muxer_action_removed (group->group, actions[i], group);
      g_strfreev (actions);

      /* 'for loop' or 'four loop'? */
      for (i = 0; i < 4; i++)
        g_signal_handler_disconnect (group->group, group->handler_ids[i]);

      g_action_muxer_free_group (group);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_unregister_internal ( Action action,
gpointer  observer 
) [static]

Definition at line 268 of file gactionmuxer.c.

{
  GActionMuxer *muxer = action->muxer;
  GSList **ptr;

  for (ptr = &action->watchers; *ptr; ptr = &(*ptr)->next)
    if ((*ptr)->data == observer)
      {
        *ptr = g_slist_remove (*ptr, observer);

        if (action->watchers == NULL)
          {
            g_hash_table_remove (muxer->actions, action->fullname);
            g_free (action->fullname);

            g_slice_free (Action, action);

            g_object_unref (muxer);
          }

        break;
      }
}

Here is the caller graph for this function:

static void g_action_muxer_unregister_observer ( GActionObservable *  observable,
const gchar *  name,
GActionObserver *  observer 
) [static]

Definition at line 327 of file gactionmuxer.c.

{
  GActionMuxer *muxer = G_ACTION_MUXER (observable);
  Action *action;

  action = g_hash_table_lookup (muxer->actions, name);
  g_object_weak_unref (G_OBJECT (observer), g_action_muxer_weak_notify, action);
  g_action_muxer_unregister_internal (action, observer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void g_action_muxer_weak_notify ( gpointer  data,
GObject *  where_the_object_was 
) [static]

Definition at line 294 of file gactionmuxer.c.

{
  Action *action = data;

  g_action_muxer_unregister_internal (action, where_the_object_was);
}

Here is the call graph for this function:

Here is the caller graph for this function:

G_DEFINE_TYPE_WITH_CODE ( GActionMuxer  ,
g_action_muxer  ,
G_TYPE_OBJECT  ,
G_IMPLEMENT_INTERFACE(G_TYPE_ACTION_OBSERVABLE, g_action_muxer_observable_iface_init  
)

Definition at line 70 of file gactionmuxer.c.

{
  GActionMuxer *muxer;
  GSList       *watchers;
  gchar        *fullname;
} Action;

Variable Documentation

Definition at line 79 of file gactionmuxer.c.