Пример #1
0
static void
on_find_create_event (GObject *log,
                      GAsyncResult *res,
                      gpointer user_data)
{
  GError             *error;
  ZeitgeistResultSet *events;

  error = NULL;
  events = zeitgeist_log_find_events_finish (ZEITGEIST_LOG (log), res, &error);

  if (error)
  {
    g_warning ("Error reading results: %s", error->message);
    g_error_free (error);
    return;
  }


  if (zeitgeist_result_set_size (events) == 0)
    insert_zeitgeist (BIJI_NOTE_OBJ (user_data), ZEITGEIST_ZG_CREATE_EVENT);

  g_object_unref (events);
}
static void
_zeitgeist_log_find_received (GObject *source_object,
                              GAsyncResult *res,
                              gpointer user_data)
{
  ZeitgeistLog *log = ZEITGEIST_LOG (source_object);
  PengeEverythingPane *pane = user_data;
  PengeEverythingPanePrivate *priv;
  GList *sw_items, *recent_file_items, *l;
  ZeitgeistResultSet *set = NULL;
  GList *old_actors = NULL;
  ClutterActor *actor;
  gboolean show_welcome_tile = TRUE;
  gint recent_files_count, sw_items_count;
  GError *error = NULL;

  g_return_if_fail (PENGE_IS_EVERYTHING_PANE (user_data));

  priv = GET_PRIVATE (pane);

  set = zeitgeist_log_find_events_finish (log, res, &error);
  if (error != NULL)
    {
      g_warning (G_STRLOC ": Error obtaining recent files: %s",
          error->message);
      g_clear_error (&error);
    }

  /* It actually moves the interesting events into a list */
  recent_file_items = _filter_out_unshowable_recent_items (pane, set);
  recent_file_items = g_list_sort (recent_file_items,
                                   (GCompareFunc)_recent_files_sort_func);

  /* Get Sw items */
  sw_items = g_hash_table_get_values (priv->uuid_to_sw_items);
  sw_items = g_list_sort (sw_items,
                          (GCompareFunc)_sw_item_sort_compare_func);

  recent_files_count = priv->block_count * priv->ratio;

  if (recent_files_count > g_list_length (recent_file_items))
    recent_files_count = g_list_length (recent_file_items);

  sw_items_count = priv->block_count - recent_files_count;

  old_actors = g_hash_table_get_values (priv->pointer_to_actor);

  if (sw_items != NULL || recent_file_items != NULL)
  {
    if (priv->welcome_tile)
    {
      clutter_container_remove_actor (CLUTTER_CONTAINER (pane),
                                      priv->welcome_tile);
      priv->welcome_tile = NULL;
    }
  }

  while ((sw_items_count && sw_items) ||
         (recent_files_count && recent_file_items))
  {
    SwItem *sw_item = NULL;
    ZeitgeistEvent *recent_file_event = NULL;

    /* If no sw items -> force compare to favour recent file */
    if (sw_items_count && sw_items)
      sw_item = (SwItem *)sw_items->data;
    else
      sw_item = NULL;

    /* If no recent files -> force compare to favour sw stuff */
    if (recent_files_count && recent_file_items)
      recent_file_event = recent_file_items->data;
    else
      recent_file_event = NULL;

    if (_compare_item_and_event (sw_item, recent_file_event) < 1)
    {
      /* Sw item is newer */

      actor = g_hash_table_lookup (priv->pointer_to_actor,
                                   sw_item);
      if (!actor)
      {
        actor = _add_from_sw_item (pane, sw_item);
        g_hash_table_insert (priv->pointer_to_actor,
                             sw_item,
                             actor);

        /* Needed to remove from hash when we kill the actor */
        g_object_set_data (G_OBJECT (actor), "data-pointer", sw_item);
      }

      sw_items_count -= _sw_item_weight (sw_item);

      clutter_container_child_set (CLUTTER_CONTAINER (pane),
                                   actor,
                                   "col-span", _sw_item_weight (sw_item),
                                   NULL);

      sw_items = g_list_remove (sw_items, sw_item);

      show_welcome_tile = FALSE;
    } else {
      /* Recent file item is newer */

      actor = g_hash_table_lookup (priv->pointer_to_actor,
                                   recent_file_event);

      if (!actor)
      {
        const gchar *uri = NULL;
        gchar *thumbnail_path = NULL;
        ZeitgeistSubject *subj;

        /* FIXME we assume there is only one subject */
        subj = zeitgeist_event_get_subject (recent_file_event, 0);
        uri = zeitgeist_subject_get_uri (subj);

        thumbnail_path = mpl_utils_get_thumbnail_path (uri);

        actor = _add_from_recent_file_event (pane,
                                            recent_file_event,
                                            thumbnail_path);
        g_free (thumbnail_path);
        g_hash_table_insert (priv->pointer_to_actor,
                             recent_file_event,
                             actor);

        /* Needed to remove from hash when we kill the actor */
        g_object_set_data (G_OBJECT (actor), "data-pointer", recent_file_event);

        show_welcome_tile = FALSE;
      }

      recent_files_count--;

      g_object_unref (recent_file_event);
      recent_file_items = g_list_remove (recent_file_items,
                                         recent_file_event);
    }

    clutter_container_lower_child (CLUTTER_CONTAINER (pane),
                                   actor,
                                   NULL);

    old_actors = g_list_remove (old_actors, actor);
  }

  for (l = old_actors; l; l = l->next)
  {
    gpointer p;
    p = g_object_get_data (G_OBJECT (l->data), "data-pointer");

    if (p)
    {
      clutter_container_remove_actor (CLUTTER_CONTAINER (pane),
                                      CLUTTER_ACTOR (l->data));
      g_hash_table_remove (priv->pointer_to_actor, p);
    }
  }

  g_list_free (old_actors);

  if (show_welcome_tile && !priv->welcome_tile)
  {
    priv->welcome_tile = penge_welcome_tile_new ();
    clutter_container_add_actor (CLUTTER_CONTAINER (pane),
                                 priv->welcome_tile);
    clutter_container_child_set (CLUTTER_CONTAINER (pane),
                                 priv->welcome_tile,
                                 "col-span", 3,
                                 NULL);
  }

  g_list_free (sw_items);

  for (l = recent_file_items; l; l = l->next)
  {
    ZeitgeistEvent *recent_file_event = l->data;
    g_object_unref (recent_file_event);
  }
  g_list_free (recent_file_items);

}