Esempio n. 1
0
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;
}
Esempio n. 2
0
static gchar *
photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
  GFBGraphPhoto *photo;
  const GFBGraphPhotoImage *higher_image;
  const gchar *identifier;
  gchar *local_dir, *filename, *local_filename;
  GFile *local_file, *remote_file;

  photo = photos_facebook_get_gfbgraph_photo (item, cancellable, error);
  if (photo == NULL)
    {
      g_error ("Can't get the photo from the Facebook Graph\n");
    }
  else
    {
      higher_image = gfbgraph_photo_get_image_hires (photo);
      if (higher_image == NULL)
        {
          g_error ("Cant' get the higher photo size from Facebook.\n");
        }
      else
        {
          remote_file = g_file_new_for_uri (higher_image->source);

          /* Local path */
          local_dir = g_build_filename (g_get_user_cache_dir (), PACKAGE_TARNAME, "facebook", NULL);
          g_mkdir_with_parents (local_dir, 0700);

          /* Local filename */
          identifier = photos_base_item_get_identifier (item) + strlen("facebook:photos:");
          filename = g_strdup_printf ("%s.jpeg", identifier);
          local_filename = g_build_filename (local_dir, filename, NULL);

          local_file = g_file_new_for_path (local_filename);

          g_debug ("Downloading %s from Facebook to %s", higher_image->source, local_filename);
          if (!g_file_copy (remote_file,
                            local_file,
                            G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
                            cancellable,
                            NULL,
                            NULL,
                            error))
            g_warning ("Failed downloading %s from Facebook to %s\n", higher_image->source, local_filename);

          g_free (filename);
          g_free (local_dir);
          g_clear_object (&local_file);
          g_clear_object (&remote_file);
        }

      g_clear_object (&photo);
    }

  return local_filename;
}
Esempio n. 3
0
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));
}
Esempio n. 4
0
GIcon *
photos_utils_get_icon_from_item (PhotosBaseItem *item)
{
  GIcon *icon = NULL;
  gboolean is_remote = FALSE;
  const gchar *identifier;
  const gchar *mime_type;

  identifier = photos_base_item_get_identifier (item);
  if (identifier != NULL)
    {
      if (g_str_has_prefix (identifier, "facebook:") ||
          g_str_has_prefix (identifier, "flickr:") ||
          g_str_has_prefix (identifier, "google:"))
        is_remote = TRUE;
    }

  if (!is_remote)
    icon = photos_utils_get_thumbnail_icon (item);

  if (icon != NULL)
    goto out;

  mime_type = photos_base_item_get_mime_type (item);
  if (mime_type != NULL)
    icon = g_content_type_get_icon (mime_type);

  if (icon != NULL)
    goto out;

  if (photos_base_item_is_collection (item))
    {
      gint size;

      size = photos_utils_get_icon_size ();
      icon = photos_utils_create_collection_icon (size, NULL);
    }

  if (icon != NULL)
    goto out;

  icon = g_themed_icon_new ("image-x-generic");

 out:
  return icon;
}
Esempio n. 5
0
static GFBGraphPhoto *
photos_facebook_get_gfbgraph_photo (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
  PhotosFacebookItemPrivate *priv = PHOTOS_FACEBOOK_ITEM (item)->priv;
  PhotosSource *source;
  const gchar *identifier, *resource_urn;
  GFBGraphGoaAuthorizer *authorizer;
  GFBGraphPhoto *photo;

  resource_urn = photos_base_item_get_resource_urn (item);
  source = PHOTOS_SOURCE (photos_base_manager_get_object_by_id (priv->src_mngr, resource_urn));
  authorizer = gfbgraph_goa_authorizer_new (photos_source_get_goa_object (source));
  identifier = photos_base_item_get_identifier (item) + strlen("facebook:");

  gfbgraph_authorizer_refresh_authorization (GFBGRAPH_AUTHORIZER (authorizer), cancellable, error);

  photo = gfbgraph_photo_new_from_id (GFBGRAPH_AUTHORIZER (authorizer), identifier, error);

  return photo;
}
static void
photos_organize_collection_view_detail_cell (GtkTreeViewColumn *tree_column,
                                             GtkCellRenderer *cell_renderer,
                                             GtkTreeModel *tree_model,
                                             GtkTreeIter *iter,
                                             gpointer user_data)
{
  PhotosOrganizeCollectionView *self = PHOTOS_ORGANIZE_COLLECTION_VIEW (user_data);
  GObject *object;
  const gchar *identifier = NULL;
  gchar *id;

  gtk_tree_model_get (GTK_TREE_MODEL (self->model), iter, PHOTOS_ORGANIZE_MODEL_ID, &id, -1);
  object = photos_base_manager_get_object_by_id (self->item_mngr, id);

  if (object != NULL)
    identifier = photos_base_item_get_identifier (PHOTOS_BASE_ITEM (object));

  if (identifier != NULL && !g_str_has_prefix (identifier, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER))
    {
      PhotosSource *source;
      const gchar *name;
      const gchar *resource_urn;

      resource_urn = photos_base_item_get_resource_urn (PHOTOS_BASE_ITEM (object));
      source = PHOTOS_SOURCE (photos_base_manager_get_object_by_id (self->src_mngr, resource_urn));
      name = photos_source_get_name (source);
      g_object_set (cell_renderer, "text", name, NULL);
      gtk_cell_renderer_set_visible (cell_renderer, TRUE);
    }
  else
    {
      g_object_set (cell_renderer, "text", "", NULL);
      gtk_cell_renderer_set_visible (cell_renderer, FALSE);
    }

  g_free (id);
}
static gboolean
photos_preview_model_visible (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
{
  PhotosPreviewModel *self = PHOTOS_PREVIEW_MODEL (user_data);
  PhotosBaseItem *item;
  gboolean ret_val = FALSE;
  const gchar *identifier;
  gchar *id;

  gtk_tree_model_get (model, iter, PHOTOS_VIEW_MODEL_URN, &id, -1);
  if (id == NULL)
    goto out;

  item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->priv->item_mngr, id));
  identifier = photos_base_item_get_identifier (item);
  if (identifier != NULL && g_str_has_prefix (identifier, PHOTOS_QUERY_COLLECTIONS_IDENTIFIER))
    goto out;

  ret_val = TRUE;

 out:
  g_free (id);
  return ret_val;
}
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);
}