コード例 #1
0
static void
_mex_grilo_program_save_metadata (MexContent *content)
{
  MexGriloProgram        *program = MEX_GRILO_PROGRAM (content);
  MexGriloProgramPrivate *priv    = program->priv;
  GrlMediaSource         *source;
  const GList *ckeys;
  GList *keys;

  g_object_get (G_OBJECT (mex_program_get_feed (MEX_PROGRAM (program))),
                "grilo-source", &source,
                NULL);

  if (!(grl_metadata_source_supported_operations (GRL_METADATA_SOURCE (source))
        & GRL_OP_SET_METADATA))
    goto goout;

  ckeys = grl_metadata_source_writable_keys (GRL_METADATA_SOURCE (source));
  keys = g_list_copy ((GList *) ckeys);

  grl_metadata_source_set_metadata (GRL_METADATA_SOURCE (source),
                                    priv->media,
                                    keys,
                                    GRL_WRITE_NORMAL,
                                    NULL, NULL);

  g_list_free (keys);

 goout:
  g_object_unref (source);
}
コード例 #2
0
static void
update_source (MexGriloFeed *feed, GrlMediaSource *new_source)
{
  MexGriloFeedPrivate *priv = feed->priv;
  MexGriloFeedClass *klass = MEX_GRILO_FEED_GET_CLASS (feed);

  if (priv->source != NULL) {
    g_signal_handlers_disconnect_by_func (priv->source,
                                          G_CALLBACK (klass->content_updated),
                                          feed);
    g_object_unref (priv->source);
    priv->source = NULL;
  }

  if (new_source) {
    gchar *lower;
    const gchar *source_name =
      grl_metadata_source_get_name (GRL_METADATA_SOURCE (new_source));

    priv->source = g_object_ref (new_source);
    g_signal_connect (priv->source,
                      "content-changed",
                      G_CALLBACK (klass->content_updated),
                      feed);

    lower = g_ascii_strdown (source_name, -1);
    if (strstr (lower, "removable")) {
      g_object_set (feed, "icon-name", "icon-panelheader-usb", NULL);
    } else {
      g_object_set (feed, "icon-name", "icon-panelheader-computer", NULL);
    }
    g_free (lower);
  }
}
コード例 #3
0
static void
handle_new_source_plugin (MexTrackerPlugin *self, GrlMediaPlugin *plugin)
{
  GrlSupportedOps ops;
  GrlMetadataSource *meta = GRL_METADATA_SOURCE (plugin);
  const char *id;

  id = grl_media_plugin_get_id (plugin);
  if (g_strcmp0 (id,"grl-tracker") != 0)
    {
      MEX_DEBUG ("Attempting to use the media explorer tracker plugin "
                 "but grilo tracker plugin not loaded. "
                 "You may not see any content!");
      return;
    }

  ops = grl_metadata_source_supported_operations (meta);
  if ((ops & GRL_OP_QUERY) == 0)
    return;

  grl_media_source_notify_change_start (GRL_MEDIA_SOURCE (plugin), NULL);

  add_model (self, plugin, MEX_TRACKER_CATEGORY_VIDEO);
  add_model (self, plugin, MEX_TRACKER_CATEGORY_IMAGE);
  add_model (self, plugin, MEX_TRACKER_CATEGORY_MUSIC);
}
コード例 #4
0
static void
mex_grilo_program_complete (MexProgram *program)
{
  GList *keys = NULL;
  GrlMediaSource *source = NULL;

  MexGriloProgram *self = MEX_GRILO_PROGRAM (program);
  MexGriloProgramPrivate *priv = self->priv;

  if (priv->completed)
    return;

  priv->completed = TRUE;

  g_object_get (G_OBJECT (mex_program_get_feed (program)),
                "grilo-source", &source,
                "grilo-metadata-keys", &keys,
                NULL);

  if (!source)
    return;

  if (!GRL_IS_METADATA_SOURCE (source))
    return;

  if (!(grl_metadata_source_supported_operations (GRL_METADATA_SOURCE (source))
        & GRL_OP_METADATA))
    return;

  /* FIXME: Currently just adding a ref, but we should keep the operation ID
   *        and cancel it on dispose instead.
   */
  g_object_ref (self);
  grl_media_source_metadata (source,
                             priv->media,
                             keys,
                             GRL_RESOLVE_IDLE_RELAY | GRL_RESOLVE_FULL,
                             program_complete_cb,
                             self);

  /* We don't unref the source here, it is done in
     mex_grilo_program_complete_cb */
}
コード例 #5
0
static void
mex_grilo_feed_constructed (GObject *object)
{
  const gchar *title;
  MexGriloFeed *self = (MexGriloFeed *) object;
  MexGriloFeedPrivate *priv = self->priv;
  MexGriloFeedClass *klass = MEX_GRILO_FEED_GET_CLASS (object);

  if (G_OBJECT_CLASS (mex_grilo_feed_parent_class)->constructed)
    G_OBJECT_CLASS (mex_grilo_feed_parent_class)->constructed (object);

  if (priv->source == NULL) {
    g_warning ("No source supplied");
    return;
  }

  /* Fill keys in case it's not already done at creation. */
  if (priv->query_keys == NULL) {
    priv->query_keys = mex_grilo_program_get_default_keys ();
  }

  if (priv->metadata_keys == NULL) {
    priv->metadata_keys = g_list_copy (priv->query_keys);
  }

  title = NULL;
  if (priv->root)
    title = grl_media_get_title (priv->root);
  if (!title && GRL_IS_MEDIA_PLUGIN (priv->source))
    title = grl_metadata_source_get_name (GRL_METADATA_SOURCE (priv->source));
  if (title)
    g_object_set (object, "title", title, NULL);

  if (priv->source != NULL) {
    g_signal_handlers_disconnect_by_func (priv->source,
                                          G_CALLBACK (klass->content_updated),
                                          self);
    g_signal_connect (priv->source,
                      "content-changed",
                      G_CALLBACK (klass->content_updated),
                      self);
  }
}
コード例 #6
0
static void
mex_grilo_program_get_stream (MexProgram        *program,
                              MexGetStreamReply  reply,
                              gpointer           userdata)
{
  GList *keys;
  GrlMediaSource *source;
  MexGriloProgramClosure *closure;
  MexGriloProgram *self = MEX_GRILO_PROGRAM (program);
  MexGriloProgramPrivate *priv = self->priv;

  closure = g_slice_new0 (MexGriloProgramClosure);
  closure->self = self;
  closure->reply = reply;
  closure->userdata = userdata;

  /* We have to add a reference around ourselves, as you can't cancel
   * the metadata callback and we need to be around when the reply
   * comes.
   */
  g_object_ref (self);

  g_object_get (G_OBJECT (mex_program_get_feed (program)),
                "grilo-source", &source,
                NULL);
  if (GRL_IS_METADATA_SOURCE (source) &&
      grl_metadata_source_supported_operations (
                                                GRL_METADATA_SOURCE (source)) & GRL_OP_METADATA) {
    keys = grl_metadata_key_list_new (GRL_METADATA_KEY_URL);
    grl_media_source_metadata (source,
                               priv->media,
                               keys,
                               GRL_RESOLVE_IDLE_RELAY | GRL_RESOLVE_FULL,
                               mex_grilo_program_get_stream_cb,
                               closure);
    g_list_free (keys);
  }
  else
    g_idle_add (mex_grilo_program_no_get_stream_cb, closure);
}
コード例 #7
0
static void
browse_cb (GrlMediaSource *source,
           guint           browse_id,
           GrlMedia       *media,
           guint           remaining,
           gpointer        userdata,
           const GError   *error)
{
  MexGriloFeed *feed = (MexGriloFeed *) userdata;
  MexGriloFeedPrivate *priv = feed->priv;
  MexGriloProgram *program;

  if (error) {
    g_warning ("Error browsing: %s", error->message);
    return;
  }

  if (priv->op == NULL) {
    g_warning ("No operation found");
    return;
  }

  if (priv->op->op_id != browse_id)
    return;

  if (media) {
    /*
     * FIXME: talk to thomas/lionel/grilo guys about that crasher. We are
     * being called with what seems to be an invalid media when cancelled.
     * this is obviously temporary to enable people to work in the meantime
     */
    gconstpointer foo = grl_media_get_id (media);
    if (!foo) {
      const gchar *source_name;

      source_name =
        grl_metadata_source_get_name (GRL_METADATA_SOURCE (priv->source));
      g_warning ("FIXME: oh no, a grilo bug! (on the '%s' source)",
                 source_name);
      return;
    }

    program = MEX_GRILO_PROGRAM (mex_feed_lookup (MEX_FEED (feed),
                                                  grl_media_get_id (media)));
    if (program != NULL) {
      mex_grilo_program_set_grilo_media (program, media);
      return;
    } else {
      emit_media_added (feed, media);
      g_object_unref (media);
    }
  }

  priv->op->count++;

  if (remaining == 0) {
    priv->op->op_id = 0;

    /* Emit completed signal */
    priv->completed = TRUE;
    g_object_notify (G_OBJECT (feed), "completed");
  }
}
コード例 #8
0
static void
add_model (MexTrackerPlugin *self,
           GrlMediaPlugin *plugin,
           MexTrackerCategory category)
{
  GList *metadata_keys, *query_keys;
  MexFeed *feed, *dir_feed;
  GrlMedia *box;
  gchar *query, *cat_name;
  GHashTable *models;
  const gchar *source_name = grl_metadata_source_get_name (GRL_METADATA_SOURCE (plugin));
  gint priority;

  switch (category)
    {
    case MEX_TRACKER_CATEGORY_IMAGE:
      cat_name = "pictures";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'image/'))";
      models = self->priv->image_models;
      metadata_keys = self->priv->image_keys;
      query_keys = self->priv->query_image_keys;
      box = grl_media_image_new ();
      break;

    case MEX_TRACKER_CATEGORY_VIDEO:
      cat_name = "videos";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'video/'))";
      models = self->priv->video_models;
      metadata_keys = self->priv->video_keys;
      query_keys = self->priv->query_video_keys;
      box = grl_media_video_new ();
      break;

    case MEX_TRACKER_CATEGORY_MUSIC:
      cat_name = "music";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'audio/'))";
      models = self->priv->music_models;
      metadata_keys = self->priv->music_keys;
      query_keys = self->priv->query_music_keys;
      box = grl_media_audio_new ();
      break;
    }

  grl_media_set_id (GRL_MEDIA (box), NULL);
  feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin),
                                     query_keys,
                                     metadata_keys,
                                     NULL, box);
  mex_model_set_sort_func (MEX_MODEL (feed),
                           mex_model_sort_time_cb,
                           GINT_TO_POINTER (TRUE));
  mex_grilo_feed_query (MEX_GRILO_FEED (feed), query, 0, MAX_TRACKER_RESULTS);

  g_hash_table_insert (models, plugin, feed);

  /* set the local files source to appear first */
  if (!g_strcmp0 (source_name, "Local files"))
    priority = -100;
  else
    priority = 0;

  dir_feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin),
                                         query_keys,
                                         metadata_keys,
                                         query, NULL);
  mex_model_set_sort_func (MEX_MODEL (dir_feed),
                           mex_model_sort_alpha_cb,
                           GINT_TO_POINTER (FALSE));
  mex_grilo_feed_browse (MEX_GRILO_FEED (dir_feed), 0, G_MAXINT);

  g_object_set (G_OBJECT (feed),
                "category", cat_name,
                "priority", priority,
                "alt-model", dir_feed,
                "alt-model-string", _("Show Folders"),
                NULL);

  mex_model_manager_add_model (self->priv->manager, MEX_MODEL (feed));
}