Exemplo n.º 1
0
static void
photos_base_model_refresh (PhotosBaseModel *self)
{
  PhotosBaseModelPrivate *priv = self->priv;
  GHashTable *objects;
  GHashTableIter hash_iter;
  GMenu *section;
  GObject *object;
  const gchar *action_id;
  const gchar *id;
  const gchar *title;

  g_menu_remove_all (priv->model);

  title = photos_base_manager_get_title (priv->mngr);
  action_id = photos_base_manager_get_action_id (priv->mngr);

  section = g_menu_new ();
  g_menu_append_section (priv->model, title, G_MENU_MODEL (section));

  objects = photos_base_manager_get_objects (priv->mngr);

  g_hash_table_iter_init (&hash_iter, objects);
  while (g_hash_table_iter_next (&hash_iter, (gpointer *) &id, (gpointer *) &object))
    {
      GMenuItem *menu_item;
      GVariant *target_value;
      gchar *name;

      g_object_get (object, "name", &name, NULL);

      menu_item = g_menu_item_new (name, NULL);
      target_value = g_variant_new ("s", id);
      g_menu_item_set_action_and_target_value (menu_item, action_id, target_value);
      g_menu_append_item (section, menu_item);

      g_free (name);
    }

  g_object_unref (section);
}
Exemplo n.º 2
0
static void
photos_base_model_refresh (PhotosBaseModel *self)
{
  g_autoptr (GMenu) section = NULL;
  const gchar *action_id;
  const gchar *title;
  guint i;
  guint n_items;

  g_menu_remove_all (self->model);

  title = photos_base_manager_get_title (self->mngr);
  action_id = photos_base_manager_get_action_id (self->mngr);

  section = g_menu_new ();
  g_menu_append_section (self->model, title, G_MENU_MODEL (section));

  n_items = g_list_model_get_n_items (G_LIST_MODEL (self->mngr));
  for (i = 0; i < n_items; i++)
    {
      g_autoptr (GMenuItem) menu_item = NULL;
      g_autoptr (GObject) object = NULL;
      const gchar *id;
      g_autofree gchar *name = NULL;

      object = g_list_model_get_object (G_LIST_MODEL (self->mngr), i);
      if (!photos_filterable_is_search_criterion (PHOTOS_FILTERABLE (object)))
        continue;

      id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
      g_object_get (object, "name", &name, NULL);

      menu_item = g_menu_item_new (name, NULL);
      g_menu_item_set_action_and_target (menu_item, action_id, "s", id);
      g_menu_append_item (section, menu_item);
    }
}