static void photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object) { PhotosBaseManagerPrivate *priv; GObject *old_object; GSequenceIter *iter; PhotosBaseManagerObjectData *object_data; const gchar *id; guint position; priv = photos_base_manager_get_instance_private (self); id = photos_filterable_get_id (PHOTOS_FILTERABLE (object)); old_object = photos_base_manager_get_object_by_id (self, id); if (old_object != NULL) return; if (priv->sort_func == NULL) { position = photos_base_manager_get_objects_count (self); iter = g_sequence_append (priv->sequence, g_object_ref (object)); } else { iter = g_sequence_insert_sorted (priv->sequence, g_object_ref (object), priv->sort_func, priv->sort_data); position = g_sequence_iter_get_position (iter); } object_data = photos_base_manager_object_data_new (object, iter); g_hash_table_insert (priv->objects, g_strdup (id), object_data); photos_base_manager_objects_changed (self, position, 0, 1); g_signal_emit (self, signals[OBJECT_ADDED], 0, object); }
static void photos_item_manager_add_object (PhotosBaseManager *mngr, GObject *object) { PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr); PhotosBaseItem *item; const gchar *id; gpointer *old_collection; g_return_if_fail (PHOTOS_IS_BASE_ITEM (object)); item = PHOTOS_BASE_ITEM (object); if (!photos_base_item_is_collection (item)) goto end; id = photos_filterable_get_id (PHOTOS_FILTERABLE (item)); if (id == NULL) goto end; old_collection = g_hash_table_lookup (self->collections, id); if (old_collection != NULL) goto end; g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item)); end: PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->add_object (mngr, object); }
static void photos_import_dialog_fetch_collections_local_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosImportDialog *self; g_autoptr (PhotosBaseItem) collection = NULL; TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object); gboolean success; const gchar *identifier; g_autofree gchar *identifier_time = NULL; { g_autoptr (GError) error = NULL; /* Note that tracker_sparql_cursor_next_finish can return FALSE even * without an error. */ success = tracker_sparql_cursor_next_finish (cursor, res, &error); if (error != NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Unable to fetch local collections: %s", error->message); goto out; } } self = PHOTOS_IMPORT_DIALOG (user_data); if (!success) { photos_import_dialog_initialize_index_and_popover (self); goto out; } collection = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), G_TYPE_NONE, cursor, FALSE); photos_import_dialog_add_collection (self, collection); identifier = photos_base_item_get_identifier (collection); identifier_time = g_strdup_printf ("%s%" G_GINT64_FORMAT, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER, self->time); if (g_strcmp0 (identifier, identifier_time) == 0) { const gchar *id; id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); photos_debug (PHOTOS_DEBUG_IMPORT, "Default collection already exists: %s", id); g_set_object (&self->default_collection, collection); } tracker_sparql_cursor_next_async (cursor, self->cancellable, photos_import_dialog_fetch_collections_local_cursor_next, self); out: return; }
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_model_active_changed (PhotosBaseModel *self, GObject *active_object) { GApplication *app; GVariant *state; const gchar *action_id; const gchar *id; app = g_application_get_default (); action_id = photos_base_manager_get_action_id (self->mngr); id = photos_filterable_get_id (PHOTOS_FILTERABLE (active_object)); state = g_variant_new ("s", id); g_action_group_change_action_state (G_ACTION_GROUP (app), action_id, state); }
static void photos_tracker_controller_refresh_for_source (PhotosTrackerController *self) { PhotosTrackerControllerPrivate *priv = self->priv; if (priv->current_query->source != NULL) { const gchar *id; id = photos_filterable_get_id (PHOTOS_FILTERABLE (priv->current_query->source)); if (g_strcmp0 (id, PHOTOS_SOURCE_STOCK_ALL) == 0) photos_tracker_controller_refresh_internal (self, PHOTOS_TRACKER_REFRESH_FLAGS_NONE); } priv->refresh_pending = FALSE; }
static void photos_import_dialog_add_collection (PhotosImportDialog *self, PhotosBaseItem *collection) { const gchar *id; const gchar *identifier; g_return_if_fail (photos_base_item_is_collection (collection)); id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); identifier = photos_base_item_get_identifier (collection); g_return_if_fail (g_strcmp0 (id, PHOTOS_COLLECTION_SCREENSHOT) == 0 || (identifier != NULL && g_str_has_prefix (identifier, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER))); g_hash_table_insert (self->collections, (gpointer) id, g_object_ref (collection)); }
static void photos_application_remote_display_current (PhotosApplication *self) { PhotosApplicationPrivate *priv = self->priv; GObject *item; GtkWidget *dialog; const gchar *urn; item = photos_base_manager_get_active_object (priv->item_mngr); if (item == NULL) return; urn = photos_filterable_get_id (PHOTOS_FILTERABLE (item)); dialog = photos_dlna_renderers_dialog_new (GTK_WINDOW (priv->main_window), urn); gtk_widget_show_all (dialog); }
static void photos_application_properties (PhotosApplication *self) { PhotosApplicationPrivate *priv = self->priv; GObject *item; GtkWidget *dialog; const gchar *id; item = photos_base_manager_get_active_object (priv->item_mngr); if (item == NULL) return; id = photos_filterable_get_id (PHOTOS_FILTERABLE (item)); dialog = photos_properties_dialog_new (GTK_WINDOW (priv->main_window), id); gtk_widget_show_all (dialog); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); }
static gchar * photos_source_manager_get_filter (PhotosBaseManager *mngr, gint flags) { GObject *source; const gchar *id; gchar *filter; if (flags & PHOTOS_QUERY_FLAGS_SEARCH) source = photos_base_manager_get_active_object (mngr); else source = photos_base_manager_get_object_by_id (mngr, PHOTOS_SOURCE_STOCK_ALL); id = photos_filterable_get_id (PHOTOS_FILTERABLE (source)); if (g_strcmp0 (id, PHOTOS_SOURCE_STOCK_ALL) == 0) filter = photos_base_manager_get_all_filter (mngr); else filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (source)); return filter; }
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_selection_controller_object_removed (PhotosBaseManager *manager, GObject *object, gpointer user_data) { PhotosSelectionController *self = PHOTOS_SELECTION_CONTROLLER (user_data); PhotosSelectionControllerPrivate *priv = self->priv; GList *l; gboolean changed = FALSE; const gchar *id; id = photos_filterable_get_id (PHOTOS_FILTERABLE (object)); l = g_list_find_custom (priv->selection, (gconstpointer) id, (GCompareFunc) g_strcmp0); while (l != NULL) { changed = TRUE; g_free (l->data); priv->selection = g_list_delete_link (priv->selection, l); l = g_list_find_custom (priv->selection, (gconstpointer) id, (GCompareFunc) g_strcmp0); } if (changed) g_signal_emit (self, signals[SELECTION_CHANGED], 0); }
static GtkWidget * photos_import_dialog_create_collection_button (PhotosBaseItem *collection) { GtkWidget *collection_button; GtkWidget *collection_label; const gchar *id; const gchar *name; id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); name = photos_base_item_get_name (collection); collection_button = photos_model_button_new (); gtk_actionable_set_action_name (GTK_ACTIONABLE (collection_button), "dialog.add-existing"); gtk_actionable_set_action_target (GTK_ACTIONABLE (collection_button), "s", id); collection_label = gtk_label_new (name); gtk_widget_set_halign (collection_label, GTK_ALIGN_START); gtk_widget_set_hexpand (collection_label, TRUE); gtk_container_add (GTK_CONTAINER (collection_button), collection_label); return collection_button; }
static gboolean photos_organize_collection_model_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) { PhotosOrganizeCollectionModel *self = PHOTOS_ORGANIZE_COLLECTION_MODEL (model); PhotosBaseItem *collection = PHOTOS_BASE_ITEM (user_data); gboolean ret_val = FALSE; gchar *id; gtk_tree_model_get (GTK_TREE_MODEL (self), iter, PHOTOS_ORGANIZE_MODEL_ID, &id, -1); if (g_strcmp0 (photos_filterable_get_id (PHOTOS_FILTERABLE (collection)), id) == 0) { self->priv->coll_path = gtk_tree_path_copy (path); ret_val = TRUE; goto out; } out: g_free (id); return ret_val; }
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); } }
static GObject * photos_base_manager_default_get_previous_object (PhotosBaseManager *self, GObject *object) { PhotosBaseManagerPrivate *priv; GObject *ret_val = NULL; GSequenceIter *iter; PhotosBaseManagerObjectData *object_data; const gchar *id; priv = photos_base_manager_get_instance_private (self); id = photos_filterable_get_id (PHOTOS_FILTERABLE (object)); object_data = g_hash_table_lookup (priv->objects, id); g_return_val_if_fail (object_data != NULL, NULL); iter = g_sequence_iter_prev (object_data->iter); if (g_sequence_iter_compare (iter, object_data->iter) == 0) goto out; ret_val = G_OBJECT (g_sequence_get (iter)); out: return ret_val; }
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_fetch_collection_state_job_emit_callback (PhotosFetchCollectionStateJob *self) { GHashTable *collection_state; GHashTable *collections; GHashTableIter iter1; PhotosBaseItem *collection; const gchar *coll_idx; collection_state = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); collections = photos_item_manager_get_collections (PHOTOS_ITEM_MANAGER (self->item_mngr)); /* For all the registered collections… */ g_hash_table_iter_init (&iter1, collections); while (g_hash_table_iter_next (&iter1, (gpointer *) &coll_idx, (gpointer *) &collection)) { GHashTableIter iter2; GList *collections_for_item; GList *keys; PhotosBaseItem *item; gboolean found = FALSE; gboolean hidden = FALSE; gboolean not_found = FALSE; const gchar *item_idx; gint state = PHOTOS_COLLECTION_STATE_NORMAL; /* If the only object we are fetching collection state for is a * collection itself, hide this if it is the same collection. */ keys = g_hash_table_get_keys (self->collections_for_items); if (g_list_length (keys) == 1) { item_idx = (gchar *) keys->data; item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr, item_idx)); if (g_strcmp0 (photos_filterable_get_id (PHOTOS_FILTERABLE (item)), photos_filterable_get_id (PHOTOS_FILTERABLE (collection))) == 0) hidden = TRUE; } g_list_free (keys); g_hash_table_iter_init (&iter2, self->collections_for_items); while (g_hash_table_iter_next (&iter2, (gpointer *) &item_idx, (gpointer *) &collections_for_item)) { const gchar *identifier; item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr, item_idx)); /* If one of the selected items is part of this collection… */ if (g_list_find_custom (collections_for_item, coll_idx, (GCompareFunc) g_strcmp0) != NULL) found = TRUE; else not_found = TRUE; identifier = photos_base_item_get_identifier (collection); if (g_strcmp0 (photos_base_item_get_resource_urn (item), photos_base_item_get_resource_urn (collection)) != 0 && identifier != NULL && !g_str_has_prefix (identifier, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER)) hidden = TRUE; } if (found && not_found) state |= PHOTOS_COLLECTION_STATE_INCONSISTENT; else if (found) state |= PHOTOS_COLLECTION_STATE_ACTIVE; if (hidden) state |= PHOTOS_COLLECTION_STATE_HIDDEN; g_hash_table_insert (collection_state, g_strdup (coll_idx), GINT_TO_POINTER (state)); } if (self->callback != NULL) (*self->callback) (collection_state, self->user_data); g_hash_table_unref (collection_state); }
static void photos_import_dialog_initialize_index_and_popover (PhotosImportDialog *self) { GHashTableIter iter; GList *extra_collections = NULL; GList *l; PhotosBaseItem *collection; guint n_buttons = 0; g_clear_pointer (&self->index, (GDestroyNotify) dzl_fuzzy_mutable_index_unref); g_clear_pointer (&self->recent_collections, (GDestroyNotify) photos_utils_object_list_free_full); gtk_container_foreach (GTK_CONTAINER (self->collections_popover_grid), (GtkCallback) gtk_widget_destroy, NULL); gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE); photos_import_dialog_enable_create_new (self, FALSE); photos_import_dialog_show_add_existing (self, FALSE); self->index = dzl_fuzzy_mutable_index_new_with_free_func (FALSE, g_object_unref); dzl_fuzzy_mutable_index_begin_bulk_insert (self->index); g_hash_table_iter_init (&iter, self->collections); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &collection)) { const gchar *name; name = photos_base_item_get_name (collection); dzl_fuzzy_mutable_index_insert (self->index, name, g_object_ref (collection)); self->recent_collections = g_list_prepend (self->recent_collections, g_object_ref (collection)); } dzl_fuzzy_mutable_index_end_bulk_insert (self->index); self->recent_collections = g_list_sort_with_data (self->recent_collections, photos_import_dialog_sort_func, self); for (l = self->recent_collections; l != NULL && n_buttons < MAX_MATCHES; l = l->next) { GtkWidget *collection_button; collection = PHOTOS_BASE_ITEM (l->data); collection_button = photos_import_dialog_create_collection_button (collection); gtk_container_add (GTK_CONTAINER (self->collections_popover_grid), collection_button); gtk_widget_show_all (collection_button); n_buttons++; } if (self->recent_collections != NULL) { GVariant *state; const gchar *id; if (l != NULL) { l->prev->next = NULL; l->prev = NULL; extra_collections = g_steal_pointer (&l); } collection = PHOTOS_BASE_ITEM (self->recent_collections->data); id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); state = g_variant_new_string (id); g_action_change_state (G_ACTION (self->add_existing_action), state); photos_import_dialog_show_add_existing (self, TRUE); } photos_import_dialog_enable_create_new (self, TRUE); photos_import_dialog_update_response_sensitivity (self); g_list_free_full (extra_collections, g_object_unref); g_return_if_fail (g_list_length (self->recent_collections) <= MAX_MATCHES); }