static void photos_item_manager_changes_pending_foreach (gpointer key, gpointer value, gpointer user_data) { PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data); PhotosTrackerChangeEvent *change_event = (PhotosTrackerChangeEvent *) value; PhotosTrackerChangeEventType change_type; const gchar *change_urn; change_type = photos_tracker_change_event_get_type (change_event); change_urn = photos_tracker_change_event_get_urn (change_event); if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_CHANGED) { GObject *object; object = photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), change_urn); if (object != NULL) photos_base_item_refresh (PHOTOS_BASE_ITEM (object)); } else if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_CREATED) { photos_item_manager_item_created (self, change_urn); } else if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_DELETED) { GObject *object; object = photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), change_urn); if (object != NULL) { photos_base_item_destroy (PHOTOS_BASE_ITEM (object)); photos_base_manager_remove_object_by_id (PHOTOS_BASE_MANAGER (self), change_urn); } } }
static void photos_search_type_manager_init (PhotosSearchTypeManager *self) { PhotosSearchType *search_type; gchar *item_filter; gchar *all_filter; gchar *col_filter; gchar *gif_filter; gif_filter = g_strdup ("nie:mimeType(?urn) != 'image/gif'"); item_filter = g_strdup_printf ("(fn:contains (?type, 'nmm#Photo') && %s)", gif_filter); col_filter = g_strdup_printf ("(fn:contains (?type, 'nfo#DataContainer')" " && ?count > 0" " && (fn:starts-with (nao:identifier (?urn), '%s')" " || (?urn = nfo:image-category-screenshot)))", PHOTOS_QUERY_COLLECTIONS_IDENTIFIER); all_filter = g_strdup_printf ("(%s || %s)", col_filter, item_filter); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_ALL, _("All"), "?urn a rdfs:Resource. " "OPTIONAL {?item a nmm:Photo; nie:isPartOf ?urn}", all_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_COLLECTIONS, _("Albums"), "?urn a nfo:DataContainer. " "?item a nmm:Photo; nie:isPartOf ?urn.", col_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_FAVORITES, _("Favorites"), "?urn a nmm:Photo; nao:hasTag nao:predefined-tag-favorite. ", gif_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_PHOTOS, _("Photos"), "?urn a nmm:Photo", gif_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SEARCH_TYPE_STOCK_PHOTOS); g_free (item_filter); g_free (all_filter); g_free (col_filter); g_free (gif_filter); }
static gchar * photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags) { PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (mngr); GHashTable *objects; PhotosSearchMatch *search_match; const gchar *blank = "(true)"; gchar *filter = NULL; gchar *ret_val = NULL; gchar **filters = NULL; gchar **terms = NULL; guint i; guint n_terms; if (!(flags & PHOTOS_QUERY_FLAGS_SEARCH)) goto out; terms = photos_search_controller_get_terms (self->priv->srch_cntrlr); n_terms = g_strv_length (terms); if (n_terms == 0) goto out; objects = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self)); filters = (gchar **) g_malloc0_n (n_terms + 1, sizeof (gchar *)); for (i = 0; terms[i] != NULL; i++) { GHashTableIter iter; const gchar *id; g_hash_table_iter_init (&iter, objects); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &search_match)) photos_search_match_set_filter_term (search_match, terms[i]); search_match = PHOTOS_SEARCH_MATCH (photos_base_manager_get_active_object (PHOTOS_BASE_MANAGER (self))); id = photos_filterable_get_id (PHOTOS_FILTERABLE (search_match)); if (g_strcmp0 (id, PHOTOS_SEARCH_MATCH_STOCK_ALL) == 0) filter = photos_base_manager_get_all_filter (PHOTOS_BASE_MANAGER (self)); else filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (search_match)); filters[i] = filter; filter = NULL; } filter = g_strjoinv (" && ", filters); ret_val = g_strconcat ("(", filter, ")", NULL); out: g_free (filter); g_strfreev (filters); g_strfreev (terms); return (ret_val == NULL) ? g_strdup (blank) : ret_val; }
static void photos_base_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { PhotosBaseManager *self = PHOTOS_BASE_MANAGER (object); PhotosBaseManagerPrivate *priv; priv = photos_base_manager_get_instance_private (self); switch (prop_id) { case PROP_ACTION_ID: priv->action_id = g_value_dup_string (value); break; case PROP_SORT_DATA: priv->sort_data = g_value_get_pointer (value); break; case PROP_SORT_FUNC: priv->sort_func = g_value_get_pointer (value); break; case PROP_TITLE: priv->title = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gpointer photos_base_manager_get_item (GListModel *list, guint position) { PhotosBaseManager *self = PHOTOS_BASE_MANAGER (list); PhotosBaseManagerPrivate *priv; GSequenceIter *iter = NULL; gpointer ret_val = NULL; priv = photos_base_manager_get_instance_private (self); if (priv->last_position != G_MAXUINT) { if (priv->last_position == position + 1) iter = g_sequence_iter_prev (priv->last_iter); else if (priv->last_position == position - 1) iter = g_sequence_iter_next (priv->last_iter); else if (priv->last_position == position) iter = priv->last_iter; } if (iter == NULL) iter = g_sequence_get_iter_at_pos (priv->sequence, position); priv->last_iter = iter; priv->last_position = position; if (g_sequence_iter_is_end (iter)) goto out; ret_val = g_object_ref (g_sequence_get (iter)); out: return ret_val; }
static guint photos_base_manager_get_n_items (GListModel *list) { PhotosBaseManager *self = PHOTOS_BASE_MANAGER (list); guint count; count = photos_base_manager_get_objects_count (self); return count; }
static void photos_source_manager_init (PhotosSourceManager *self) { PhotosSourceManagerPrivate *priv; PhotosSource *source; self->priv = photos_source_manager_get_instance_private (self); priv = self->priv; source = photos_source_new (PHOTOS_SOURCE_STOCK_ALL, _("All"), TRUE); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source)); g_object_unref (source); source = photos_source_new (PHOTOS_SOURCE_STOCK_LOCAL, _("Local"), TRUE); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source)); g_object_unref (source); priv->cancellable = g_cancellable_new (); goa_client_new (priv->cancellable, photos_source_manager_goa_client, self); photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SOURCE_STOCK_ALL); }
static void photos_base_manager_finalize (GObject *object) { PhotosBaseManager *self = PHOTOS_BASE_MANAGER (object); PhotosBaseManagerPrivate *priv; priv = photos_base_manager_get_instance_private (self); g_free (priv->action_id); g_free (priv->title); G_OBJECT_CLASS (photos_base_manager_parent_class)->finalize (object); }
static void photos_search_match_manager_init (PhotosSearchMatchManager *self) { PhotosSearchMatch *search_match; const gchar *author_filter; const gchar *title_filter; self->priv = photos_search_match_manager_get_instance_private (self); author_filter = "fn:contains (" " tracker:case-fold (tracker:coalesce (nco:fullname (?creator), nco:fullname(?publisher)))," " \"%s\")"; title_filter = "fn:contains (" " tracker:case-fold (tracker:coalesce (nie:title (?urn), nfo:fileName(?urn)))," " \"%s\")"; search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_ALL, _("All"), "(false)"); /* unused */ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match)); g_object_unref (search_match); search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_TITLE, /* Translators: "Title" refers to "Match Title" when searching. */ C_("Search Filter", "Title"), title_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match)); g_object_unref (search_match); search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_AUTHOR, /* Translators: "Author" refers to "Match Author" when searching. */ C_("Search Filter", "Author"), author_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match)); g_object_unref (search_match); photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SEARCH_MATCH_STOCK_ALL); }
static void photos_base_manager_dispose (GObject *object) { PhotosBaseManager *self = PHOTOS_BASE_MANAGER (object); PhotosBaseManagerPrivate *priv; priv = photos_base_manager_get_instance_private (self); g_clear_object (&priv->active_object); g_clear_pointer (&priv->objects, (GDestroyNotify) g_hash_table_unref); g_clear_pointer (&priv->sequence, (GDestroyNotify) g_sequence_free); G_OBJECT_CLASS (photos_base_manager_parent_class)->dispose (object); }
static void photos_base_model_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { PhotosBaseModel *self = PHOTOS_BASE_MODEL (object); switch (prop_id) { case PROP_MANAGER: self->mngr = PHOTOS_BASE_MANAGER (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void photos_source_manager_refresh_accounts (PhotosSourceManager *self) { PhotosSourceManagerPrivate *priv = self->priv; GHashTable *new_sources; GList *accounts; GList *l; accounts = goa_client_get_accounts (priv->client); new_sources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); for (l = accounts; l != NULL; l = l->next) { GoaAccount *account; GoaObject *object = GOA_OBJECT (l->data); PhotosSource *source; const gchar *id; account = goa_object_peek_account (object); if (account == NULL) continue; if (goa_account_get_photos_disabled (account)) continue; if (goa_object_peek_photos (object) == NULL) continue; source = photos_source_new_from_goa_object (GOA_OBJECT (l->data)); id = photos_filterable_get_id (PHOTOS_FILTERABLE (source)); g_hash_table_insert (new_sources, g_strdup (id), g_object_ref (source)); g_object_unref (source); } photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_sources); g_hash_table_unref (new_sources); g_list_free_full (accounts, g_object_unref); }
static void photos_share_point_manager_refresh_share_points (PhotosSharePointManager *self) { GHashTable *new_share_points; GList *extensions; GList *l; guint i; guint n_items; new_share_points = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); extensions = g_io_extension_point_get_extensions (self->extension_point); for (l = extensions; l != NULL; l = l->next) { GError *error; GIOExtension *extension = (GIOExtension *) l->data; GType type; PhotosSharePoint *share_point; const gchar *id; type = g_io_extension_get_type (extension); if (g_type_is_a (type, G_TYPE_INITABLE)) { error = NULL; share_point = PHOTOS_SHARE_POINT (g_initable_new (type, NULL, &error, NULL)); if (share_point == NULL) { const gchar *name; name = g_io_extension_get_name (extension); g_debug ("Unable to initialize share point %s: %s", name, error->message); g_error_free (error); continue; } } else { share_point = PHOTOS_SHARE_POINT (g_object_new (type, NULL)); } id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point)); g_hash_table_insert (new_share_points, g_strdup (id), g_object_ref (share_point)); g_object_unref (share_point); } n_items = g_list_model_get_n_items (G_LIST_MODEL (self->src_mngr)); for (i = 0; i < n_items; i++) { PhotosSharePoint *share_point = NULL; PhotosSource *source; source = PHOTOS_SOURCE (g_list_model_get_object (G_LIST_MODEL (self->src_mngr), i)); share_point = photos_share_point_manager_create_share_point_online (self, source); if (share_point != NULL) { const gchar *id; id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point)); g_hash_table_insert (new_share_points, g_strdup (id), g_object_ref (share_point)); } g_clear_object (&share_point); g_object_unref (source); } photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_share_points); g_hash_table_unref (new_share_points); }
static void photos_search_type_manager_init (PhotosSearchTypeManager *self) { PhotosSearchType *search_type; gchar *item_filter; gchar *all_filter; gchar *blacklisted_mime_types_filter; gchar *col_filter; gchar **strv; guint i; guint n_elements; n_elements = G_N_ELEMENTS (BLACKLISTED_MIME_TYPES); strv = (gchar **) g_malloc0_n (n_elements + 1, sizeof (gchar *)); for (i = 0; i < n_elements; i++) strv[i] = g_strdup_printf ("nie:mimeType(?urn) != '%s'", BLACKLISTED_MIME_TYPES[i]); blacklisted_mime_types_filter = g_strjoinv (" && ", strv); item_filter = g_strdup_printf ("(fn:contains (?type, 'nmm#Photo') && %s)", blacklisted_mime_types_filter); col_filter = g_strdup_printf ("(fn:contains (?type, 'nfo#DataContainer')" " && ?count > 0" " && (fn:starts-with (nao:identifier (?urn), '%s')" " || (?urn = nfo:image-category-screenshot)))", PHOTOS_QUERY_COLLECTIONS_IDENTIFIER); all_filter = g_strdup_printf ("(%s || %s)", col_filter, item_filter); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_ALL, _("All"), "?urn a rdfs:Resource. " "OPTIONAL {?item a nmm:Photo; nie:isPartOf ?urn}", all_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_COLLECTIONS, _("Albums"), "?urn a nfo:DataContainer. " "?item a nmm:Photo; nie:isPartOf ?urn.", col_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_FAVORITES, _("Favorites"), "?urn a nmm:Photo; nao:hasTag nao:predefined-tag-favorite. ", blacklisted_mime_types_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_PHOTOS, _("Photos"), "?urn a nmm:Photo", blacklisted_mime_types_filter); photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type)); g_object_unref (search_type); photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SEARCH_TYPE_STOCK_ALL); g_free (item_filter); g_free (all_filter); g_free (blacklisted_mime_types_filter); g_free (col_filter); g_strfreev (strv); }