Пример #1
0
/**
 * mex_menu_add_action:
 * @menu: A #MexMenu
 * @action: A #MxAction
 * @type: The menu action type
 *
 * Adds a menu item to @menu at the current depth. @action must be a uniquely
 * named action, if an action with that name already exists in the menu, this
 * function will do nothing.
 */
void
mex_menu_add_action (MexMenu           *menu,
                     MxAction          *action,
                     MexMenuActionType  type)
{
  ClutterActor *item;
  MexMenuPrivate *priv;

  g_return_if_fail (MEX_IS_MENU (menu));
  g_return_if_fail (MX_IS_ACTION (action));

  priv = menu->priv;

  if (mex_menu_find_action (menu, mx_action_get_name (action), NULL))
    {
      g_warning (G_STRLOC ": Action '%s' is already contained in this menu",
                 mx_action_get_name (action));
      return;
    }

  item = mex_menu_item_new (menu, action, type);
  g_hash_table_insert (priv->action_to_item, action, item);

  clutter_container_add_actor (CLUTTER_CONTAINER (priv->action_layout), item);

  if (priv->focus_on_add)
    {
      mex_push_focus (MX_FOCUSABLE (item));
      priv->focus_on_add = FALSE;
    }
}
Пример #2
0
void
mex_action_manager_add_action (MexActionManager *manager,
                               MexActionInfo    *info)
{
  MexActionInfo *info_copy;
  MexActionManagerPrivate *priv;

  g_return_if_fail (MEX_IS_ACTION_MANAGER (manager));

  priv = manager->priv;

  if (g_hash_table_lookup (priv->actions, mx_action_get_name (info->action)))
    {
      g_warning (G_STRLOC ": Action '%s' already exists",
                 mx_action_get_name (info->action));
      return;
    }

  info_copy = g_slice_dup (MexActionInfo, info);
  info_copy->action = g_object_ref_sink (info->action);
  info_copy->mime_types = g_strdupv (info->mime_types);
  info_copy->exclude_mime_types = g_strdupv (info->exclude_mime_types);

  g_hash_table_insert (priv->actions,
                       (gpointer)mx_action_get_name (info->action),
                       info_copy);
  g_signal_emit (manager, signals[ACTION_ADDED], 0, info_copy);
}
Пример #3
0
static MxAction *
mex_menu_find_action (MexMenu       *menu,
                      const gchar   *action_name,
                      ClutterActor **item)
{
  gpointer key, value;
  GHashTableIter iter;

  MexMenuPrivate *priv = menu->priv;

  g_hash_table_iter_init (&iter, priv->action_to_item);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      MxAction *action = key;

      if (g_strcmp0 (mx_action_get_name (action), action_name) == 0)
        {
          if (item)
            *item = value;

          return action;
        }
    }

  if (item)
    *item = NULL;

  return NULL;
}
Пример #4
0
/**
 * mex_menu_remove_action:
 * @menu: A #MexMenu
 * @action: The action name
 *
 * Remove the menu item that represents the given action name.
 */
void
mex_menu_remove_action (MexMenu     *menu,
                        const gchar *action_name)
{
  gpointer key, value;
  GHashTableIter iter;
  MexMenuPrivate *priv;

  g_return_if_fail (MEX_IS_MENU (menu));
  g_return_if_fail (action_name);

  priv = menu->priv;

  g_hash_table_iter_init (&iter, priv->action_to_item);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      gint n_children;
      ClutterActor *parent;

      MxAction *action = key;
      ClutterActor *item = value;

      if (g_strcmp0 (action_name, mx_action_get_name (action)) != 0)
        continue;

      g_hash_table_iter_remove (&iter);

      parent = clutter_actor_get_parent (item);
      clutter_actor_destroy (item);

      n_children = 0;
      clutter_container_foreach (CLUTTER_CONTAINER (parent),
                                 mex_menu_count_children_cb,
                                 &n_children);

      if (!n_children)
        {
          if (priv->depth > 0)
            mex_menu_pop (menu);
          else if (priv->depth < 0)
            mex_menu_push (menu);
        }

      return;
    }

  g_warning (G_STRLOC ": Action '%s' not found", action_name);
}
Пример #5
0
static void
mex_grid_view_timeline_complete_cb (ClutterTimeline *timeline,
                                    MexGridView     *view)
{
  MexGridViewPrivate *priv = MEX_GRID_VIEW (view)->priv;

  if (priv->state == STATE_CLOSING_STAGE1)
    {
      GList *l, *actions;

      /* move to stage 2 of the close animation */
      clutter_timeline_rewind (timeline);
      clutter_timeline_start (timeline);
      priv->state = STATE_CLOSING_STAGE2;

      /* remove the actions from the menu */
      actions = mex_menu_get_actions (MEX_MENU (priv->menu_layout), 0);
      for (l = actions; l; l = g_list_next (l))
        mex_menu_remove_action (MEX_MENU (priv->menu_layout), mx_action_get_name (l->data));
      g_list_free (actions);

      return;
    }
  else if (priv->state == STATE_CLOSING_STAGE2)
    {
      priv->state = STATE_CLOSED;
      CLUTTER_ACTOR_CLASS (mex_grid_view_parent_class)->hide (CLUTTER_ACTOR (view));
    }
  else if (priv->state == STATE_OPENING)
    {
      priv->state = STATE_OPEN;
      clutter_actor_show (priv->grid);
      clutter_actor_animate (priv->grid, CLUTTER_LINEAR, 250,
                             "opacity", 255,
                             NULL);
    }

  if (priv->callback)
    {
      g_object_ref (G_OBJECT (view));

      priv->callback (CLUTTER_ACTOR (view), priv->userdata);
      priv->callback = NULL;
      priv->userdata = NULL;

      g_object_unref (G_OBJECT (view));
    }
}
Пример #6
0
static void
_back_button_cb (ClutterActor *actor,
                 MexInfoBar   *bar)
{
  GList *actions, *l;

  actions = mex_action_manager_get_actions (mex_action_manager_get_default ());

  /* find the back action */
  for (l = actions; l; l = g_list_next (l))
    {
      MxAction *action = l->data;

      if (!g_strcmp0 (mx_action_get_name (action), "go-back"))
        g_action_activate (G_ACTION (action), NULL);
    }

  g_list_free (actions);
}
Пример #7
0
GList *
mex_action_manager_get_actions_for_content (MexActionManager *manager,
                                            MexContent      *content)
{
  GList *a, *actions;
  gpointer key, value;
  GHashTableIter iter;
  MexActionManagerPrivate *priv;
  const gchar *last_position, *mime;

  g_return_val_if_fail (MEX_IS_ACTION_MANAGER (manager), NULL);

  mime = mex_content_get_metadata (content, MEX_CONTENT_METADATA_MIMETYPE);

  last_position = mex_content_get_metadata (content,
                                            MEX_CONTENT_METADATA_LAST_POSITION);

  actions = NULL;
  priv = manager->priv;

  g_hash_table_iter_init (&iter, priv->actions);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      gint i;
      MexActionInfo *info = value;
      const gchar *action_name;
      action_name = mx_action_get_name (info->action);

      /* If there isn't a last position skip: */
      if (!last_position)
        {
          if (g_str_equal (action_name, "play-from-last") ||
              g_str_equal (action_name, "play-from-begin") ||
              g_str_equal (action_name, "listen-from-begin"))
            continue;
        }
      else
        {
          /* We don't want resume and listen or play because
           * this action is provided by the start
           */
          if (g_str_equal (action_name, "play") ||
              g_str_equal (action_name, "listen"))
            continue;
        }

      /* If we've been asked for actions that apply to a
       * blank mime-type, only return actions that were
       * registered for a blank mime-type.
       */
      if (!mime || !*mime)
        {
          if (!info->mime_types ||
              !info->mime_types[0] ||
              !(*info->mime_types[0]))
            actions = g_list_prepend (actions, info);

          continue;
        }

      /* Add actions that match a mime prefix */
      for (i = 0; info->mime_types[i]; i++)
        {
          if (g_str_has_prefix (mime, info->mime_types[i]))
            {
              actions = g_list_prepend (actions, info);
              break;
            }
        }

      /* Now check that this action isn't for an excluded mimetype */
      if (!info->exclude_mime_types)
        continue;

      for (i = 0; info->exclude_mime_types[i]; i++)
        {
          if (g_str_has_prefix (mime, info->exclude_mime_types[i]))
            {
              actions = g_list_remove (actions, info);
              break;
            }
        }
    }

  actions = g_list_sort (actions, mex_action_manager_sort_cb);
  for (a = actions; a; a = a->next)
    a->data = ((MexActionInfo *)a->data)->action;

  return actions;
}