static gboolean
account_miner_job_process_entry (GomAccountMinerJob *job,
                                 OpType op_type,
                                 FlickrEntry *entry,
                                 GError **error)
{
  GDateTime *created_time, *modification_date;
  gchar *contact_resource;
  gchar *mime;
  gchar *resource = NULL;
  gchar *date, *identifier;
  const gchar *class = NULL, *id;
  const gchar *url;
  gboolean resource_exists, mtime_changed;
  gint64 new_mtime;

  if (op_type == OP_CREATE_HIEARCHY && entry->parent == NULL && !GRL_IS_MEDIA_BOX (entry->media))
    return TRUE;

  id = grl_media_get_id (entry->media);
  identifier = g_strdup_printf ("%sflickr:%s",
                                GRL_IS_MEDIA_BOX (entry->media) ?
                                "photos:collection:" : "",
                                id);

  /* remove from the list of the previous resources */
  g_hash_table_remove (job->previous_resources, identifier);

  if (GRL_IS_MEDIA_BOX (entry->media))
    class = "nfo:DataContainer";
  else
示例#2
0
/*
 * If we need to, generate a thumbnail.
 *
 * If the URL is not file:/// then we assume it's okay to use.
 *
 */
static void
mex_grilo_program_thumbnail (MexContent *content, GrlMedia *media)
{
  const char *url;
  char *thumb_path;

  /* If the media isn't local, then we'll ignore it for now */
  url = grl_media_get_url (media);
  if (url == NULL || !g_str_has_prefix (url, "file:///"))
    return;

  if (GRL_IS_MEDIA_BOX (media))
    {
      gchar *tmp;

      tmp = g_build_filename (mex_get_data_dir (), "common", "folder-tile.png",
                              NULL);
      mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL, tmp);
      g_free (tmp);
      return;
    }

  /*
   * If we're already got a thumbnail, see if we're happy with it or want to
   * ignore it.
   */
  thumb_path = (char*)mex_content_get_metadata (content,
                                                MEX_CONTENT_METADATA_STILL);
  if (thumb_path) {
    /* If the thumbnail is already a good one, we're done */
    if (thumb_path && strstr (thumb_path, "/.thumbnails/x-huge/"))
      return;

    /*
     * If the thumbnail currently set is a "normal" thumbnail we ignore it on the
     * basis that it's likely to have been generated by Totem, and thus is bad.
     * If your platform doesn't have Totem then this can be removed!
     */
    if (thumb_path && strstr (thumb_path, "/.thumbnails/normal/"))
      mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL, NULL);
  }

  /*
   * Now see if we've a thumbnail generated already.  TODO: use the Tumbler API
   * to do this.
   */
  thumb_path = get_thumbnail_path_for_uri (url);
  if (g_file_test (thumb_path, G_FILE_TEST_EXISTS)) {
    gchar *thumb_uri = g_filename_to_uri (thumb_path, NULL, NULL);
    mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL,
                                    thumb_uri);
    g_free (thumb_uri);
  } else {
    mex_thumbnailer_generate (url, grl_media_get_mime (media),
                              thumbnail_cb, content);
  }
  g_free (thumb_path);
}
示例#3
0
static int
get_media_type (GrlMedia *media)
{
  if (GRL_IS_MEDIA_AUDIO (media)) {
    return MEDIA_AUDIO;
  }
  if (GRL_IS_MEDIA_VIDEO (media)) {
    return MEDIA_VIDEO;
  }
  if (GRL_IS_MEDIA_IMAGE (media)) {
    return MEDIA_IMAGE;
  }
  if (GRL_IS_MEDIA_BOX (media)) {
    return MEDIA_BOX;
  }

  return MEDIA;
}
static void
grl_raitv_source_resolve (GrlSource *source,
                          GrlSourceResolveSpec *rs)
{
  gchar *urltarget;
  GrlRaitvSource *self = GRL_RAITV_SOURCE (source);
  RaitvOperation *op;
  RaitvMediaType mediatype;

  GRL_DEBUG ("Starting resolve source: url=%s",grl_media_get_url (rs->media));

  if (!GRL_IS_MEDIA_VIDEO (rs->media) && !GRL_IS_MEDIA_BOX (rs->media)) {
    rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
    return;
  }

  mediatype = classify_media_id (grl_media_get_id (rs->media));
  switch (mediatype) {
  case RAITV_MEDIA_TYPE_ROOT:
    rs->media = produce_container_from_directory (rs->media, NULL, 0, mediatype);
    break;
  case RAITV_MEDIA_TYPE_POPULARS:
    rs->media = produce_container_from_directory (rs->media, root_dir, ROOT_DIR_POPULARS_INDEX, mediatype);
    break;
  case RAITV_MEDIA_TYPE_RECENTS:
    rs->media = produce_container_from_directory (rs->media, root_dir, ROOT_DIR_RECENTS_INDEX, mediatype);
    break;
  case RAITV_MEDIA_TYPE_POPULAR_THEME:
  case RAITV_MEDIA_TYPE_RECENT_THEME:
    rs->media = produce_container_from_directory (rs->media,
                                                  themes_dir,
                                                  get_theme_index_from_id (grl_media_get_id (rs->media)),
                                                  mediatype);
    break;
  case RAITV_MEDIA_TYPE_VIDEO:
    op = g_slice_new0 (RaitvOperation);
    op->source       = g_object_ref (source);
    op->cancellable  = g_cancellable_new ();
    op->operation_id = rs->operation_id;
    op->resolveCb    = rs->callback;
    op->user_data    = rs->user_data;
    op->media	      = rs->media;

    grl_operation_set_data_full (rs->operation_id, op, (GDestroyNotify) raitv_operation_free);

    urltarget = g_strdup_printf ("http://www.rai.tv/dl/RaiTV/programmi/media/%s.html",
                                 grl_media_get_id(rs->media));

    GRL_DEBUG ("Opening '%s'", urltarget);

    grl_net_wc_request_async (self->priv->wc,
                              urltarget,
                              op->cancellable,
                              proxy_call_resolve_grlnet_async_cb,
                              op);

    g_free(urltarget);
    return;
  }
  rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
  return;

  if ( grl_media_get_url (rs->media) != NULL) {
    rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
    return;
  }

  op = g_slice_new0 (RaitvOperation);
  op->source       = g_object_ref (source);
  op->cancellable  = g_cancellable_new ();
  op->operation_id = rs->operation_id;
  op->resolveCb     = rs->callback;
  op->user_data    = rs->user_data;
  op->media	   = rs->media;

  grl_operation_set_data_full (rs->operation_id, op, (GDestroyNotify) raitv_operation_free);

  urltarget = g_strdup_printf("%s/%s.html","http://www.rai.tv/dl/RaiTV/programmi/media",grl_media_get_id(rs->media));

  GRL_DEBUG ("Opening '%s'", urltarget);

  grl_net_wc_request_async (self->priv->wc,
                            urltarget,
                            op->cancellable,
                            proxy_call_resolve_grlnet_async_cb,
                            op);

  g_free(urltarget);
}
static void
grilo_media_browse_cb (GrlSource *grilo_source, guint operation_id, GrlMedia *media, guint remaining, RBGriloSource *source, const GError *error)
{
	if (operation_id != source->priv->media_browse_op) {
		return;
	}

	if (error != NULL) {
		/* do something? */
		rb_debug ("got error for %s: %s",
			  grl_source_get_name (grilo_source),
			  error->message);
		return;
	}

	GDK_THREADS_ENTER ();
	if (media != NULL) {
		source->priv->media_browse_got_results = TRUE;
		source->priv->media_browse_position++;

		if (GRL_IS_MEDIA_AUDIO (media)) {
			RhythmDBEntry *entry;
			entry = create_entry_for_media (source->priv->db,
							source->priv->entry_type,
							GRL_DATA (media),
							GRL_DATA (source->priv->browse_container));
			if (entry != NULL) {
				rhythmdb_query_model_add_entry (source->priv->query_model, entry, -1);
			}
		} else if (GRL_IS_MEDIA_BOX (media)) {
			source->priv->media_browse_got_containers = TRUE;
		}
	}

	if (remaining == 0) {
		source->priv->media_browse_op = 0;

		if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (source->priv->query_model), NULL) == 0 &&
		    source->priv->media_browse_position >= CONTAINER_GIVE_UP_POINT) {
			/* if we don't find any media within the first 100 or so results,
			 * assume this container doesn't have any.  otherwise we'd load
			 * the entire thing when it got selected, which would suck.
			 */
			rb_debug ("didn't find any media in %s, giving up", grl_media_get_title (source->priv->media_browse_container));
			gtk_tree_store_set (source->priv->browser_model,
					    &source->priv->media_browse_container_iter,
					    2, CONTAINER_NO_MEDIA,
					    -1);
		} else if (source->priv->media_browse_got_results) {
			if (source->priv->media_browse_position < source->priv->media_browse_limit) {
				media_browse_next (source);
			} else {
				char *text;

				text = g_strdup_printf (ngettext ("Only showing %d result",
								  "Only showing %d results",
								  source->priv->media_browse_position),
							source->priv->media_browse_position);
				gtk_label_set_text (GTK_LABEL (source->priv->info_bar_label), text);
				g_free (text);

				gtk_widget_show (source->priv->info_bar);
			}
		} else if (source->priv->media_browse_got_containers == FALSE &&
			   source->priv->media_browse_container != NULL) {
			/* make sure there's no marker row for this container */
			delete_marker_row (source, &source->priv->media_browse_container_iter);
		}
	}
	GDK_THREADS_LEAVE ();
}
static void
grilo_browse_cb (GrlSource *grilo_source, guint operation_id, GrlMedia *media, guint remaining, RBGriloSource *source, const GError *error)
{
	if (operation_id != source->priv->browse_op) {
		return;
	}

	if (error != NULL) {
		/* do something? */
		rb_debug ("got error for %s: %s", grl_source_get_name (grilo_source), error->message);
		source->priv->browse_op = 0;
		return;
	}

	if (media != NULL) {
		source->priv->browse_got_results = TRUE;
		source->priv->browse_position++;
	}

	if (media && GRL_IS_MEDIA_BOX (media)) {

		GtkTreeIter new_row;
		if (source->priv->browse_container == NULL) {
			/* insert at the end */
			gtk_tree_store_insert_with_values (source->priv->browser_model,
							   &new_row,
							   NULL,
							   -1,
							   0, g_object_ref (media),
							   1, grl_media_get_title (media),
							   2, CONTAINER_UNKNOWN_MEDIA,
							   3, 0,
							   -1);
		} else {
			int n;
			/* insert before the expand marker row */
			n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (source->priv->browser_model),
							    &source->priv->browse_container_iter);
			gtk_tree_store_insert_with_values (source->priv->browser_model,
							   &new_row,
							   &source->priv->browse_container_iter,
							   n - 1,
							   0, g_object_ref (media),
							   1, grl_media_get_title (media),
							   2, CONTAINER_UNKNOWN_MEDIA,
							   3, 0,
							   -1);
		}

		/* and insert an expand marker below it too */
		gtk_tree_store_insert_with_values (source->priv->browser_model,
						   NULL,
						   &new_row,
						   -1,
						   0, NULL,
						   1, "...",	/* needs to be translatable? */
						   2, CONTAINER_NO_MEDIA,
						   3, 0,
						   -1);
	} else if (media && GRL_IS_MEDIA_AUDIO (media)) {
		source->priv->browse_got_media = TRUE;
	}

	if (remaining == 0) {
		source->priv->browse_op = 0;
		if (source->priv->browse_got_results == FALSE &&
		    source->priv->browse_container != NULL) {
			/* no more results for this container, so delete the marker row */
			delete_marker_row (source, &source->priv->browse_container_iter);

			set_container_type (source, &source->priv->browse_container_iter, source->priv->browse_got_media);
			gtk_tree_store_set (source->priv->browser_model,
					    &source->priv->browse_container_iter,
					    3, -1,
					    -1);
		} else if (source->priv->browse_container != NULL) {
			if (source->priv->browse_position >= CONTAINER_GIVE_UP_POINT &&
			    gtk_tree_model_iter_n_children (GTK_TREE_MODEL (source->priv->browser_model),
							    &source->priv->browse_container_iter) == 1) {
				/* no containers yet, so remove the marker row */
				delete_marker_row (source, &source->priv->browse_container_iter);
			} else {
				/* store browse position for next time we want more */
				gtk_tree_store_set (source->priv->browser_model,
						    &source->priv->browse_container_iter,
						    3, source->priv->browse_position,
						    -1);
				maybe_expand_container (source);
			}

		} else if (source->priv->browse_got_results && source->priv->browse_container == NULL) {
			/* get all top-level containers */
			browse_next (source);
		}
	}
}
示例#7
0
static void
store_bookmark (GrlBookmarksSource *bookmarks_source,
                GList **keylist,
                GrlMediaBox *parent,
                GrlMedia *bookmark,
                GError **error)
{
  GomResource *resource;
  const gchar *title;
  const gchar *url;
  const gchar *desc;
  const gchar *thumb;
  GTimeVal now;
  gint64 parent_id;
  const gchar *mime;
  gchar *date;
  guint type;
  gint64 id;
  gchar *str_id;
  GError *local_error = NULL;
  gboolean ret;

  GRL_DEBUG ("store_bookmark");

  title = grl_media_get_title (bookmark);
  url = grl_media_get_url (bookmark);
  thumb = grl_media_get_thumbnail (bookmark);
  desc = grl_media_get_description (bookmark);
  mime = grl_media_get_mime (bookmark);
  g_get_current_time (&now);
  date = g_time_val_to_iso8601 (&now);

  if (!parent) {
    parent_id = 0;
  } else {
    parent_id = g_ascii_strtoll (grl_media_get_id (GRL_MEDIA (parent)), NULL, 0);
  }
  if (parent_id < 0) {
    parent_id = 0;
  }

  GRL_DEBUG ("URL: '%s'", url);

  if (GRL_IS_MEDIA_BOX (bookmark)) {
    type = BOOKMARK_TYPE_CATEGORY;
  } else {
    type = BOOKMARK_TYPE_STREAM;
  }

  resource = g_object_new (BOOKMARKS_TYPE_RESOURCE,
                           "repository", bookmarks_source->priv->repository,
                           "parent", parent_id,
                           "type", type,
                           NULL);

  if (type == BOOKMARK_TYPE_STREAM) {
    g_object_set (G_OBJECT (resource), "url", url, NULL);
    *keylist = g_list_remove (*keylist,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_URL));
  }
  if (title) {
    g_object_set (G_OBJECT (resource), "title", title, NULL);
    *keylist = g_list_remove (*keylist,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_TITLE));
  } else if (url) {
    g_object_set (G_OBJECT (resource), "title", url, NULL);
  } else {
    g_object_set (G_OBJECT (resource), "title", "(unknown)", NULL);
  }
  if (date) {
    g_object_set (G_OBJECT (resource), "date", date, NULL);
  }
  if (mime) {
    g_object_set (G_OBJECT (resource), "mime", mime, NULL);
    *keylist = g_list_remove (*keylist,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_MIME));
  }
  if (desc) {
    g_object_set (G_OBJECT (resource), "desc", desc, NULL);
    *keylist = g_list_remove (*keylist,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_DESCRIPTION));
  }
  if (thumb) {
    g_object_set (G_OBJECT (resource), "thumbnail-url", desc, NULL);
    *keylist = g_list_remove (*keylist,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_THUMBNAIL));
  }

  ret = gom_resource_save_sync (resource, &local_error);
  if (!ret) {
    GRL_WARNING ("Failed to store bookmark '%s': %s", title,
                 local_error->message);
    *error = g_error_new (GRL_CORE_ERROR,
                          GRL_CORE_ERROR_STORE_FAILED,
                          _("Failed to store: %s"),
                          local_error->message);
    g_error_free (local_error);
    g_object_unref (resource);
    return;
  }

  g_object_get (resource, "id", &id, NULL);
  str_id = g_strdup_printf ("%" G_GINT64_FORMAT, id);
  grl_media_set_id (bookmark, str_id);
  g_free (str_id);

  g_object_unref (resource);

  if (bookmarks_source->priv->notify_changes) {
    grl_source_notify_change (GRL_SOURCE (bookmarks_source),
                              bookmark,
                              GRL_CONTENT_ADDED,
                              FALSE);
  }
}