Ejemplo n.º 1
0
/**
 * grl_related_keys_dup:
 * @relkeys: set of related keys to duplicate
 *
 * Makes a deep copy of @relkeys and its contents.
 *
 * Returns: (transfer full): a new #GrlRelatedKeys.
 * Free it with #g_object_unref.
 *
 * Since: 0.1.10
 **/
GrlRelatedKeys *
grl_related_keys_dup (GrlRelatedKeys *relkeys)
{
  GList *keys, *key;
  const GValue *value;
  GValue *value_copy;
  GrlRelatedKeys *dup_relkeys;

  g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), NULL);

  dup_relkeys = grl_related_keys_new ();

  keys = grl_related_keys_get_keys (relkeys);
  for (key = keys; key; key = g_list_next (key)) {
    value = grl_related_keys_get (relkeys, GRLPOINTER_TO_KEYID (key->data));
    value_copy = g_new0 (GValue, 1);
    g_value_init (value_copy, G_VALUE_TYPE (value));
    g_value_copy (value, value_copy);
    g_hash_table_insert (dup_relkeys->priv->data, key->data, value_copy);
  }

  g_list_free (keys);

  return dup_relkeys;
}
Ejemplo n.º 2
0
static void
grl_gravatar_source_resolve (GrlSource *source,
                             GrlSourceResolveSpec *rs)
{
  gboolean artist_avatar_required = FALSE;
  gboolean author_avatar_required = FALSE;

  GRL_DEBUG (__FUNCTION__);

  GList *iter;

  /* Check that albumart is requested */
  iter = rs->keys;
  while (iter && (!artist_avatar_required || !author_avatar_required)) {
    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
    if (key == GRL_METADATA_KEY_ARTIST_AVATAR) {
      artist_avatar_required = TRUE;
    } else if (key == GRL_METADATA_KEY_AUTHOR_AVATAR) {
      author_avatar_required = TRUE;
    }
    iter = g_list_next (iter);
  }

  if (artist_avatar_required) {
    set_avatar (GRL_DATA (rs->media), GRL_METADATA_KEY_ARTIST);
  }

  if (author_avatar_required) {
    set_avatar (GRL_DATA (rs->media), GRL_METADATA_KEY_AUTHOR);
  }

  rs->callback (source, rs->operation_id, rs->media, rs->user_data, NULL);
}
static resolution_flags_t
get_resolution_flags (GList                      *keys,
                      GrlLocalMetadataSourcePriv *priv)
{
  GList *iter = keys;
  resolution_flags_t flags = 0;

  while (iter != NULL) {
    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
    if (key == GRL_METADATA_KEY_TITLE)
      flags |= FLAG_VIDEO_TITLE;
    else if (key == GRL_METADATA_KEY_SHOW)
      flags |= FLAG_VIDEO_SHOWNAME;
    else if (key == GRL_METADATA_KEY_PUBLICATION_DATE)
      flags |= FLAG_VIDEO_DATE;
    else if (key == GRL_METADATA_KEY_SEASON)
      flags |= FLAG_VIDEO_SEASON;
    else if (key == GRL_METADATA_KEY_EPISODE)
      flags |= FLAG_VIDEO_EPISODE;
    else if (key == GRL_METADATA_KEY_THUMBNAIL)
      flags |= FLAG_THUMBNAIL;
    else if (key == priv->hash_keyid)
      flags |= FLAG_GIBEST_HASH;
    else if (key == GRL_METADATA_KEY_EPISODE_TITLE)
      flags |= FLAG_VIDEO_EPISODE_TITLE;

    iter = iter->next;
  }

  return flags;
}
Ejemplo n.º 4
0
gchar *
grl_tracker_get_delete_string (const GList *keys)
{
  gboolean first = TRUE;
  const GList *key = keys, *assoc_list;
  tracker_grl_sparql_t *assoc;
  GString *gstr = g_string_new ("");
  gchar *ret;
  gint var_n = 0;

  while (key != NULL) {
    assoc_list = get_mapping_from_grl (GRLPOINTER_TO_KEYID (key->data));
    while (assoc_list != NULL) {
      assoc = (tracker_grl_sparql_t *) assoc_list->data;
      if (assoc != NULL) {
        if (first) {
          g_string_append_printf (gstr, "%s ?v%i",
                                  assoc->sparql_key_attr, var_n);
          first = FALSE;
        } else {
          g_string_append_printf (gstr, " ; %s ?v%i",
                                  assoc->sparql_key_attr, var_n);
        }
        var_n++;
      }
      assoc_list = assoc_list->next;
    }
    key = key->next;
  }

  ret = gstr->str;
  g_string_free (gstr, FALSE);

  return ret;
}
Ejemplo n.º 5
0
gchar *
grl_tracker_source_get_select_string (const GList *keys)
{
  const GList *key = keys;
  GString *gstr = g_string_new ("");
  GList *assoc_list;
  tracker_grl_sparql_t *assoc;

  assoc_list = get_mapping_from_grl (grl_metadata_key_tracker_urn);
  assoc = (tracker_grl_sparql_t *) assoc_list->data;
  g_string_append_printf (gstr, "%s AS %s ",
                          assoc->sparql_key_attr_call,
                          assoc->sparql_key_name);

  while (key != NULL) {
    assoc_list = get_mapping_from_grl (GRLPOINTER_TO_KEYID (key->data));
    while (assoc_list != NULL) {
      assoc = (tracker_grl_sparql_t *) assoc_list->data;
      if (assoc != NULL) {
        g_string_append_printf (gstr, "%s AS %s ",
                                assoc->sparql_key_attr_call,
                                assoc->sparql_key_name);
      }
      assoc_list = assoc_list->next;
    }
    key = key->next;
  }

  return g_string_free (gstr, FALSE);
}
Ejemplo n.º 6
0
gchar *
grl_tracker_tracker_get_insert_string (GrlMedia *media, const GList *keys)
{
  gboolean first = TRUE;
  const GList *key;
  GString *gstr = g_string_new ("");

  for (key = keys; key != NULL; key = key->next) {
    const GList *assoc_list;
    GrlKeyID key_id = GRLPOINTER_TO_KEYID (key->data);

    for (assoc_list = get_mapping_from_grl (key_id);
         assoc_list != NULL;
         assoc_list = assoc_list->next) {
      tracker_grl_sparql_t *assoc = assoc_list->data;

      if (assoc == NULL)
        continue;

      /* The favourite key is really setting or deleting a tag
       * in tracker, so in the case of setting it to false skip
       * the insert string creation step for this key completely.
       */
      if (assoc->grl_key == GRL_METADATA_KEY_FAVOURITE &&
          !grl_media_get_favourite (media))
        continue;

      if (!grl_data_has_key (GRL_DATA (media), key_id))
        continue;

      if (!first)
        g_string_append (gstr, " ; ");

      gen_prop_insert_string (gstr, assoc, GRL_DATA (media));
      first = FALSE;
    }
  }

  return g_string_free (gstr, FALSE);
}
Ejemplo n.º 7
0
static void
fill_metadata_from_stmt (GrlMedia *media, GList *keys, sqlite3_stmt *stmt)
{
  GList *iter;
  gint play_count, last_position, favourite;
  gdouble rating;
  gchar *last_played;

  iter = keys;
  while (iter) {
    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
    if (key == GRL_METADATA_KEY_PLAY_COUNT) {
      play_count = sqlite3_column_int (stmt, STORE_PLAY_COUNT);
      grl_media_set_play_count (media, play_count);
    } else if (key == GRL_METADATA_KEY_RATING) {
      rating = sqlite3_column_double (stmt, STORE_RATING);
      grl_media_set_rating (media, rating, 5.00);
    } else if (key == GRL_METADATA_KEY_LAST_PLAYED) {
      GDateTime *date;
      last_played = (gchar *) sqlite3_column_text (stmt, STORE_LAST_PLAYED);
      date = grl_date_time_from_iso8601 (last_played);
      if (date) {
        grl_media_set_last_played (media, date);
        g_date_time_unref (date);
      } else {
        GRL_WARNING ("Unable to set 'last-played', as '%s' date is invalid",
                     last_played);
      }
    } else if (key == GRL_METADATA_KEY_LAST_POSITION) {
      last_position = sqlite3_column_int (stmt, STORE_LAST_POSITION);
      grl_media_set_last_position (media, last_position);
    } else if (key == GRL_METADATA_KEY_FAVOURITE) {
      favourite = sqlite3_column_int (stmt, STORE_FAVOURITE);
      grl_media_set_favourite (media, (gboolean) favourite);
    }
    iter = g_list_next (iter);
  }
}
Ejemplo n.º 8
0
static GList *
write_keys (sqlite3 *db,
            const gchar *source_id,
            const gchar *media_id,
            GrlSourceStoreMetadataSpec *sms,
            GError **error)
{
  GList *col_names = NULL;
  GList *iter;
  GList *failed_keys = NULL;
  guint supported_keys = 0;
  gint r;

  /* Get DB column names for each key to be updated */
  iter = sms->keys;
  while (iter) {
    const gchar *col_name =
        get_column_name_from_key_id (GRLPOINTER_TO_KEYID (iter->data));
    if (!col_name) {
      GRL_WARNING ("Key %" GRL_KEYID_FORMAT " is not supported for "
                       "writing, ignoring...",
                 GRLPOINTER_TO_KEYID (iter->data));
      failed_keys = g_list_prepend (failed_keys, iter->data);
    } else {
      supported_keys++;
    }
    col_names = g_list_prepend (col_names, (gchar *) col_name);
    iter = g_list_next (iter);
  }
  col_names = g_list_reverse (col_names);

  if (supported_keys == 0) {
    GRL_WARNING ("Failed to update metadata, none of the specified "
                     "keys is writable");
    *error = g_error_new (GRL_CORE_ERROR,
                          GRL_CORE_ERROR_STORE_METADATA_FAILED,
                          _("Failed to update metadata: %s"),
                          _("specified keys are not writable"));
    goto done;
  }

  r = prepare_and_exec_update (db,
			       source_id,
			       media_id,
			       col_names,
			       sms->keys,
			       sms->media);

  if (!r) {
    GRL_WARNING ("Failed to update metadata for '%s - %s': %s",
                     source_id, media_id, sqlite3_errmsg (db));
    g_list_free (failed_keys);
    failed_keys = g_list_copy (sms->keys);
    *error = g_error_new (GRL_CORE_ERROR,
                          GRL_CORE_ERROR_STORE_METADATA_FAILED,
                          _("Failed to update metadata: %s"),
                          sqlite3_errmsg (db));
    goto done;
  }

  if (sqlite3_changes (db) == 0) {
    /* We have to create the row */
    r = prepare_and_exec_insert (db,
				 source_id,
				 media_id,
				 col_names,
				 sms->keys,
				 sms->media);
  }

  if (!r) {
    GRL_WARNING ("Failed to update metadata for '%s - %s': %s",
                     source_id, media_id, sqlite3_errmsg (db));
    g_list_free (failed_keys);
    failed_keys = g_list_copy (sms->keys);
    *error = g_error_new_literal (GRL_CORE_ERROR,
                                  GRL_CORE_ERROR_STORE_METADATA_FAILED,
                                  _("Failed to update metadata"));
    goto done;
  }

 done:
  g_list_free (col_names);
  return failed_keys;
}
Ejemplo n.º 9
0
static gboolean
bind_and_exec (sqlite3 *db,
	       const gchar *sql,
	       const gchar *source_id,
	       const gchar *media_id,
	       GList *col_names,
	       GList *keys,
	       GrlMedia *media)
{
  gint r;
  const gchar *char_value;
  gint int_value;
  double double_value;
  GList *iter_names, *iter_keys;
  guint count;
  sqlite3_stmt *stmt;

  /* Create statement from sql */
  GRL_DEBUG ("%s", sql);
  r = sqlite3_prepare_v2 (db, sql, strlen (sql), &stmt, NULL);

  if (r != SQLITE_OK) {
    GRL_WARNING ("Failed to update metadata for '%s - %s': %s",
                     source_id, media_id, sqlite3_errmsg (db));
    sqlite3_finalize (stmt);
    return FALSE;
  }

  /* Bind media type */
  sqlite3_bind_int (stmt, 1, get_media_type (media));

  /* Bind column values */
  count = 2;
  iter_names = col_names;
  iter_keys = keys;
  while (iter_names) {
    if (iter_names->data) {
      GrlKeyID key = GRLPOINTER_TO_KEYID (iter_keys->data);
      if (key == GRL_METADATA_KEY_RATING) {
	double_value = grl_media_get_rating (media);
	sqlite3_bind_double (stmt, count, double_value);
      } else if (key == GRL_METADATA_KEY_PLAY_COUNT) {
	int_value = grl_media_get_play_count (media);
	sqlite3_bind_int (stmt, count, int_value);
      } else if (key == GRL_METADATA_KEY_LAST_POSITION) {
	int_value = grl_media_get_last_position (media);
	sqlite3_bind_int (stmt, count, int_value);
      } else if (key == GRL_METADATA_KEY_LAST_PLAYED) {
	char_value = grl_media_get_last_played (media);
	sqlite3_bind_text (stmt, count, char_value, -1, SQLITE_STATIC);
      } else if (key == GRL_METADATA_KEY_FAVOURITE) {
        int_value = (gint) grl_media_get_favourite (media);
        sqlite3_bind_int (stmt, count, int_value);
      }
      count++;
    }
    iter_keys = g_list_next (iter_keys);
    iter_names = g_list_next (iter_names);
  }

  sqlite3_bind_text (stmt, count++, source_id, -1, SQLITE_STATIC);
  sqlite3_bind_text (stmt, count++, media_id, -1, SQLITE_STATIC);

  /* execute query */
  while ((r = sqlite3_step (stmt)) == SQLITE_BUSY);

  sqlite3_finalize (stmt);

  return (r == SQLITE_DONE);
}
Ejemplo n.º 10
0
static void
fill_properties_table (MS2Server *server,
                       GHashTable *properties_table,
                       GList *keys,
                       GrlMedia *media)
{
  GList *prop;
  GrlKeyID key;
  const gchar *title;
  gchar *id;
  gchar *urls[2] = { 0 };

  for (prop = keys; prop; prop = g_list_next (prop)) {
    key = GRLPOINTER_TO_KEYID (prop->data);
    if (key == GRL_METADATA_KEY_ID ||
        grl_data_has_key (GRL_DATA (media), key)) {
      if (key == GRL_METADATA_KEY_ID) {
        id = serialize_media (media);
        if (id) {
          ms2_server_set_path (server,
                               properties_table,
                               id,
                               grl_media_is_container (media));
          g_free (id);
        }
      } else if (key == GRL_METADATA_KEY_TITLE) {
        /* Ensure we always insert a valid title */
        title = grl_media_get_title (media);
        if (!title) {
          title = "Unknown";
        }
        ms2_server_set_display_name (server,
                                     properties_table,
                                     title);
      } else if (key == GRL_METADATA_KEY_ALBUM) {
        ms2_server_set_album (server,
                              properties_table,
                              grl_data_get_string (GRL_DATA (media),
                                                   GRL_METADATA_KEY_ALBUM));
      } else if (key == GRL_METADATA_KEY_ARTIST) {
        ms2_server_set_artist (server,
                               properties_table,
                               grl_data_get_string (GRL_DATA (media),
                                                    GRL_METADATA_KEY_ARTIST));
      } else if (key == GRL_METADATA_KEY_GENRE) {
        ms2_server_set_genre (server,
                              properties_table,
                              grl_data_get_string (GRL_DATA (media),
                                                   GRL_METADATA_KEY_GENRE));
      } else if (key == GRL_METADATA_KEY_MIME) {
        ms2_server_set_mime_type (server,
                                  properties_table,
                                  grl_media_get_mime (media));
      } else if (key == GRL_METADATA_KEY_URL) {
        urls[0] = (gchar *) grl_media_get_url (media);
        ms2_server_set_urls (server, properties_table, urls);
      } else if (key == GRL_METADATA_KEY_BITRATE) {
        ms2_server_set_bitrate (server,
                                properties_table,
                                grl_data_get_int (GRL_DATA (media),
                                                  GRL_METADATA_KEY_BITRATE));
      } else if (key == GRL_METADATA_KEY_DURATION) {
        ms2_server_set_duration (server,
                                 properties_table,
                                 grl_media_get_duration (media));
      } else if (key == GRL_METADATA_KEY_HEIGHT) {
        ms2_server_set_height (server,
                               properties_table,
                               grl_data_get_int (GRL_DATA (media),
                                                 GRL_METADATA_KEY_HEIGHT));
      } else if (key == GRL_METADATA_KEY_WIDTH) {
        ms2_server_set_width (server,
                              properties_table,
                              grl_data_get_int (GRL_DATA (media),
                                                GRL_METADATA_KEY_WIDTH));
      } else if (key == GRL_METADATA_KEY_GRILO_MS2_PARENT) {
        if (grl_media_get_id (media) == NULL) {
          ms2_server_set_parent (server,
                                 properties_table,
                                 MS2_ROOT);
        } else {
          ms2_server_set_parent (server,
                                 properties_table,
                                 grl_media_get_grilo_ms2_parent (media));
        }
      }
    }
  }
}
Ejemplo n.º 11
0
/**
 * grl_operation_options_obey_caps:
 * @options: a #GrlOperationOptions instance
 * @caps: capabilities against which we want to test @options
 * @supported_options: (out callee-allocates): if not %NULL, will contain a
 * newly-allocated #GrlOperationOptions instance containing all the values of
 * @options that match @caps.
 * @unsupported_options: (out callee-allocates): if not %NULL, will contain a
 * newly-allocated #GrlOperationOptions instance containing all the values of
 * @options that do not match @caps.
 *
 * Check whether @options obey to @caps.
 * Optionally provide the options that match (respectively don't match) @caps
 * in @supported_options (respectively @unsupported_options).
 * This would typically (but not necessarily) be used with a
 * #GrlOperationOptions instance that was created with %NULL caps.
 *
 * Returns: %TRUE if @options obey to @caps, %FALSE otherwise.
 *
 * Since: 0.2.0
 */
gboolean
grl_operation_options_obey_caps (GrlOperationOptions *options,
                                 GrlCaps *caps,
                                 GrlOperationOptions **supported_options,
                                 GrlOperationOptions **unsupported_options)
{
  gboolean ret = TRUE;
  GHashTableIter table_iter;
  gpointer key_ptr;
  GValue *value;
  GrlRangeValue *range_value;

  if (supported_options) {
    *supported_options = grl_operation_options_new (caps);

    /* these options are always supported */
    copy_option (options, *supported_options, GRL_OPERATION_OPTION_SKIP);
    copy_option (options, *supported_options, GRL_OPERATION_OPTION_COUNT);
    copy_option (options, *supported_options, GRL_OPERATION_OPTION_RESOLUTION_FLAGS);
  }

  if (unsupported_options)
    *unsupported_options = grl_operation_options_new (NULL);

  ret &= check_and_copy_option (options,
                                caps,
                                GRL_OPERATION_OPTION_TYPE_FILTER,
                                supported_options,
                                unsupported_options);

  /* Check filter-by-equal-key */
  g_hash_table_iter_init (&table_iter, options->priv->key_filter);
  while (g_hash_table_iter_next (&table_iter, &key_ptr, (gpointer *)&value)) {
    GrlKeyID key_id = GRLPOINTER_TO_KEYID (key_ptr);
    if (grl_caps_is_key_filter (caps, key_id)) {
      if (supported_options) {
        g_hash_table_insert ((*supported_options)->priv->key_filter,
                             key_ptr,
                             grl_g_value_dup (value));
      }
    } else {
      ret = FALSE;
      if (unsupported_options) {
        g_hash_table_insert ((*unsupported_options)->priv->key_filter,
                             key_ptr,
                             grl_g_value_dup (value));
      }
    }
  }

  /* Check filter-by-range-key */
  g_hash_table_iter_init (&table_iter, options->priv->key_range_filter);
  while (g_hash_table_iter_next (&table_iter, &key_ptr, (gpointer *)&range_value)) {
    GrlKeyID key_id = GRLPOINTER_TO_KEYID (key_ptr);
    if (grl_caps_is_key_range_filter (caps, key_id)) {
      if (supported_options) {
        g_hash_table_insert ((*supported_options)->priv->key_range_filter,
                             key_ptr,
                             grl_range_value_dup (range_value));
      }
    } else {
      ret = FALSE;
      if (unsupported_options) {
        g_hash_table_insert ((*unsupported_options)->priv->key_range_filter,
                             key_ptr,
                             grl_range_value_dup (range_value));
      }
    }
  }

  return ret;
}
Ejemplo n.º 12
0
static void fill_key_id(gpointer data, gpointer user_data) {
  QVariantList *varList = static_cast<QVariantList *>(user_data);
  varList->append(GriloDataSource::MetadataKeys(GRLPOINTER_TO_KEYID(data)));
}