GList * _filter_out_unshowable_recent_items (PengeEverythingPane *pane, ZeitgeistResultSet *set) { PengeEverythingPanePrivate *priv = GET_PRIVATE (pane); GList *ret = NULL; guint i; /* loop index */ /* probably an error (or an actual empty set, obv), we need to return empty * list anyway */ if (set == NULL) return NULL; while (zeitgeist_result_set_has_next (set)) { ZeitgeistEvent *event = NULL; gchar *thumbnail_path = NULL; /* We have to do this because we edit the list */ event = zeitgeist_result_set_next (set); /* FIXME, so far this is the assumption, then we can use a better data * structure for managing events with multiple subjects */ g_assert (zeitgeist_event_num_subjects (event) == 1); for (i = 0; i < zeitgeist_event_num_subjects (event); ++i) { ZeitgeistSubject *s; GFile *file; const gchar *uri = NULL; s = zeitgeist_event_get_subject (event, i); g_assert (s != NULL); uri = zeitgeist_subject_get_uri (s); g_assert (uri != NULL); /* Just a small debug help :) g_warning ("%s: subj(%d): i=%s m=%s", zeitgeist_subject_get_uri (s), i, zeitgeist_subject_get_interpretation (s), zeitgeist_subject_get_manifestation (s)); */ /* Current detault template look for local files only, if it's not local, * it's probably a template error, log it and move on */ if (!g_str_has_prefix (uri, "file:")) { g_warning ("uri %s for recent event is not local", uri); continue; } file = g_file_new_for_uri (uri); /* if the file does not exist anymore we ignore it and move on */ if (!g_file_query_exists (file, NULL)) break; /* consider the next event */ thumbnail_path = mpl_utils_get_thumbnail_path (uri); /* add to the return list only if it has a valid thumbnail */ if (thumbnail_path && g_file_test (thumbnail_path, G_FILE_TEST_EXISTS)) ret = g_list_prepend (ret, g_object_ref (event)); g_free (thumbnail_path); g_object_unref (file); } } return ret; }
static void _on_got_events (ZeitgeistResultSet *pEvents, GtkListStore *pModel) { int i, n; ZeitgeistEvent *event; ZeitgeistSubject *subject; gint64 iTimeStamp; const gchar *cEventURI; guint id; gchar *cName = NULL, *cURI = NULL, *cIconName = NULL, *cIconPath, *cPath = NULL; double fOrder; int iVolumeID; gboolean bIsDirectory; GdkPixbuf *pixbuf; GtkTreeIter iter; GHashTable *pHashTable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); // used to prevent doubles //\_____________ parse all the events. while (zeitgeist_result_set_has_next (pEvents)) { #ifdef ZEITGEIST_1_0 event = zeitgeist_result_set_next (pEvents); #else event = zeitgeist_result_set_next_value (pEvents); #endif iTimeStamp = zeitgeist_event_get_timestamp (event) / 1e3; id = zeitgeist_event_get_id (event); n = zeitgeist_event_num_subjects (event); if (n > 1) cd_debug (" +++ %s, %s, %d", zeitgeist_event_get_interpretation (event), zeitgeist_event_get_manifestation (event), n); for (i = 0; i < n; i++) { subject = zeitgeist_event_get_subject (event, i); //\_____________ prevent doubles. cEventURI = zeitgeist_subject_get_uri (subject); if (g_hash_table_lookup_extended (pHashTable, cEventURI, NULL, NULL)) continue; //g_print (" %s:\n %s, %s\n", cEventURI, zeitgeist_subject_get_interpretation (subject), zeitgeist_subject_get_manifestation (subject)); //\_____________ ignore files that have been deleted cPath = g_filename_from_uri (cEventURI, NULL, NULL); // NULL for anything else than file://* if (strncmp (cEventURI, "file://", 7) == 0 && ! g_file_test (cPath, G_FILE_TEST_EXISTS)) { g_hash_table_insert (pHashTable, (gchar*)cEventURI, NULL); // since we've checked it, insert it, even if we don't display it. g_free (cPath); continue; } //\_____________ get the text to display. const gchar *cText = zeitgeist_subject_get_text (subject); if (cText == NULL) // skip empty texts (they are most of the times web page that redirect to another page, which is probably in the next event anyway). continue; //\_____________ find the icon. if (strncmp (cEventURI, "http", 4) == 0) // gvfs is deadly slow to get info on distant URI... { cIconName = cairo_dock_search_icon_s_path ("text-html", myData.iDesiredIconSize); } else if (strncmp (cEventURI, "application://", 14) == 0) // application URL { gchar *cClass = cairo_dock_register_class (cEventURI+14); cIconName = g_strdup (cairo_dock_get_class_icon (cClass)); cText = cairo_dock_get_class_name (cClass); // use the translated name g_free (cClass); } else { cairo_dock_fm_get_file_info (cEventURI, &cName, &cURI, &cIconName, &bIsDirectory, &iVolumeID, &fOrder, CAIRO_DOCK_FM_SORT_BY_DATE); } if (cIconName != NULL) { cIconPath = cairo_dock_search_icon_s_path (cIconName, myData.iDesiredIconSize); pixbuf = gdk_pixbuf_new_from_file_at_size (cIconPath, myData.iDesiredIconSize, myData.iDesiredIconSize, NULL); g_free (cIconPath); } else pixbuf = NULL; //\_____________ build the path to display. const gchar *cDisplayedPath = (cPath ? cPath : cEventURI); // need to escape the '&' (and ', etc.) because gtk-tooltips use markups by default. gchar *cEscapedPath = g_markup_escape_text (cDisplayedPath, -1); //\_____________ store in the model. memset (&iter, 0, sizeof (GtkTreeIter)); gtk_list_store_append (GTK_LIST_STORE (pModel), &iter); gtk_list_store_set (GTK_LIST_STORE (pModel), &iter, CD_MODEL_NAME, cText, CD_MODEL_URI, cEventURI, CD_MODEL_PATH, cEscapedPath, CD_MODEL_ICON, pixbuf, CD_MODEL_DATE, iTimeStamp, CD_MODEL_ID, id, -1); g_free (cIconName); cIconName = NULL; g_free (cName); cName = NULL; g_free (cURI); cURI = NULL; if (pixbuf) g_object_unref (pixbuf); g_free (cPath); g_free (cEscapedPath); g_hash_table_insert (pHashTable, (gchar*)cEventURI, NULL); // cEventURI stays valid in this function. } } g_hash_table_destroy (pHashTable); }