/** * grl_related_keys_set: * @relkeys: set of related keys to modify * @key: (type GrlKeyID): key to change or add * @value: the new value * * Sets the value associated with @key into @relkeys. Old value is freed and * the new one is set. * * Also, checks that @value is compliant with @key specification, modifying it * accordingly. For instance, if @key requires a number between 0 and 10, but * value is outside this range, it will be adapted accordingly. * * Since: 0.1.10 **/ void grl_related_keys_set (GrlRelatedKeys *relkeys, GrlKeyID key, const GValue *value) { GValue *copy = NULL; GrlRegistry *registry; g_return_if_fail (GRL_IS_RELATED_KEYS (relkeys)); g_return_if_fail (key); if (!value) { return; } /* Dup value */ if (G_VALUE_TYPE (value) != GRL_METADATA_KEY_GET_TYPE (key)) { GRL_WARNING ("value has type %s, but expected %s", g_type_name (G_VALUE_TYPE (value)), g_type_name (GRL_METADATA_KEY_GET_TYPE (key))); return; } copy = g_new0 (GValue, 1); g_value_init (copy, G_VALUE_TYPE (value)); g_value_copy (value, copy); registry = grl_registry_get_default (); if (!grl_registry_metadata_key_validate (registry, key, copy)) { GRL_WARNING ("'%s' value invalid, adjusting", GRL_METADATA_KEY_GET_NAME (key)); } g_hash_table_insert (relkeys->priv->data, GRLKEYID_TO_POINTER (key), copy); }
static void grl_metadata_store_source_init (GrlMetadataStoreSource *source) { gint r; gchar *path; gchar *db_path; gchar *sql_error = NULL; source->priv = GRL_METADATA_STORE_GET_PRIVATE (source); path = g_strconcat (g_get_user_data_dir (), G_DIR_SEPARATOR_S, "grilo-plugins", NULL); if (!g_file_test (path, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents (path, 0775); } GRL_DEBUG ("Opening database connection..."); db_path = g_strconcat (path, G_DIR_SEPARATOR_S, GRL_SQL_DB, NULL); r = sqlite3_open (db_path, &source->priv->db); g_free (path); if (r) { g_critical ("Failed to open database '%s': %s", db_path, sqlite3_errmsg (source->priv->db)); sqlite3_close (source->priv->db); g_free (db_path); return; } g_free (db_path); GRL_DEBUG (" OK"); GRL_DEBUG ("Checking database tables..."); r = sqlite3_exec (source->priv->db, GRL_SQL_CREATE_TABLE_STORE, NULL, NULL, &sql_error); if (r) { if (sql_error) { GRL_WARNING ("Failed to create database tables: %s", sql_error); g_clear_pointer (&sql_error, sqlite3_free); } else { GRL_WARNING ("Failed to create database tables."); } sqlite3_close (source->priv->db); return; } // For backwards compatibility, add newer columns if they don't exist // in the old database. sqlite3_exec (source->priv->db, GRL_SQL_ALTER_TABLE_ADD_FAVOURITE, NULL, NULL, &sql_error); sqlite3_exec (source->priv->db, GRL_SQL_ALTER_TABLE_ADD_TYPE_ID, NULL, NULL, &sql_error); GRL_DEBUG (" OK"); }
static void grl_raitv_source_cancel (GrlSource *source, guint operation_id) { RaitvOperation *op = grl_operation_get_data (operation_id); GRL_WARNING ("Cancelling id=%u", operation_id); if (!op) { GRL_WARNING ("\tNo such operation id=%u", operation_id); } if (op->cancellable) { g_cancellable_cancel (op->cancellable); } }
gboolean grl_gravatar_source_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { GRL_LOG_DOMAIN_INIT (gravatar_log_domain, "gravatar"); GRL_DEBUG ("grl_gravatar_source_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!GRL_METADATA_KEY_ARTIST_AVATAR && !GRL_METADATA_KEY_AUTHOR_AVATAR) { GRL_WARNING ("Unable to register \"author-avatar\" nor \"artist-avatar\""); return FALSE; } GrlGravatarSource *source = grl_gravatar_source_new (); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); return TRUE; }
static void server_lost_cb (GrlDleynaServersManager *serversmgr, GrlDleynaServer *server, gpointer *user_data) { GrlDleynaMediaDevice *device; GrlSource *source; GrlRegistry *registry; const gchar* udn; gchar *source_id; GRL_DEBUG (G_STRFUNC); device = grl_dleyna_server_get_media_device (server); udn = grl_dleyna_media_device_get_udn (device); GRL_DEBUG ("%s udn: %s ", G_STRFUNC, udn); registry = grl_registry_get_default (); source_id = grl_dleyna_source_build_id (udn); GRL_DEBUG ("%s id: %s ", G_STRFUNC, source_id); source = grl_registry_lookup_source (registry, source_id); if (source != NULL) { GError *error = NULL; GRL_DEBUG ("%s unregistered %s", G_STRFUNC, source_id); grl_registry_unregister_source (registry, source, &error); if (error != NULL) { GRL_WARNING ("Failed to unregister source %s: %s", udn, error->message); g_error_free (error); } } g_free (source_id); }
static void server_found_cb (GrlDleynaServersManager *serversmgr, GrlDleynaServer *server, gpointer *user_data) { GrlPlugin *plugin = GRL_PLUGIN (user_data); GrlDleynaMediaDevice *device; GrlSource *source; GrlRegistry *registry; GError *error = NULL; GRL_DEBUG (G_STRFUNC); device = grl_dleyna_server_get_media_device (server); GRL_DEBUG ("%s udn: %s ", G_STRFUNC, grl_dleyna_media_device_get_udn (device)); registry = grl_registry_get_default (); source = GRL_SOURCE (grl_dleyna_source_new (server)); GRL_DEBUG ("%s id: %s ", G_STRFUNC, grl_source_get_id (source)); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), &error); if (error != NULL) { GRL_WARNING ("Failed to register source for DLNA device %s: %s", grl_dleyna_media_device_get_udn (device), error->message); g_error_free (error); } }
static void grl_bookmarks_source_query (GrlSource *source, GrlSourceQuerySpec *qs) { GRL_DEBUG ("grl_bookmarks_source_query"); GrlBookmarksSource *bookmarks_source; OperationSpec *os; GError *error = NULL; bookmarks_source = GRL_BOOKMARKS_SOURCE (source); if (!bookmarks_source->priv->adapter) { GRL_WARNING ("Can't execute operation: no database connection."); error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_QUERY_FAILED, _("No database connection")); qs->callback (qs->source, qs->operation_id, NULL, 0, qs->user_data, error); g_error_free (error); } os = g_slice_new0 (OperationSpec); os->source = qs->source; os->operation_id = qs->operation_id; os->count = grl_operation_options_get_count (qs->options); os->skip = grl_operation_options_get_skip (qs->options); os->type_filter = grl_operation_options_get_type_filter (qs->options); os->callback = qs->callback; os->user_data = qs->user_data; os->error_code = GRL_CORE_ERROR_SEARCH_FAILED; produce_bookmarks_from_query (os, qs->query); }
static void tracker_evt_preupdate_sources_cb (GObject *object, GAsyncResult *result, tracker_evt_update_t *evt) { GError *error = NULL; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); evt->cursor = tracker_sparql_connection_query_finish (grl_tracker_connection, result, &error); if (error != NULL) { GRL_WARNING ("\tCannot handle datasource request : %s", error->message); g_error_free (error); tracker_evt_update_items (evt); tracker_evt_update_orphans (evt); return; } tracker_sparql_cursor_next_async (evt->cursor, NULL, (GAsyncReadyCallback) tracker_evt_preupdate_sources_item_cb, (gpointer) evt); }
static void grl_bookmarks_source_init (GrlBookmarksSource *source) { GError *error = NULL; gchar *path; gchar *db_path; GList *object_types; source->priv = GRL_BOOKMARKS_GET_PRIVATE (source); path = g_build_filename (g_get_user_data_dir (), "grilo-plugins", NULL); if (!g_file_test (path, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents (path, 0775); } GRL_DEBUG ("Opening database connection..."); db_path = g_build_filename (path, GRL_SQL_DB, NULL); g_free (path); source->priv->adapter = gom_adapter_new (); if (!gom_adapter_open_sync (source->priv->adapter, db_path, &error)) { GRL_WARNING ("Could not open database '%s': %s", db_path, error->message); g_error_free (error); g_free (db_path); return; } g_free (db_path); source->priv->repository = gom_repository_new (source->priv->adapter); object_types = g_list_prepend(NULL, GINT_TO_POINTER(BOOKMARKS_TYPE_RESOURCE)); gom_repository_automatic_migrate_async (source->priv->repository, 2, object_types, migrate_cb, source); }
static void parsed_finished (TotemPlParser *pl, GAsyncResult *result, BrowseData *data) { TotemPlParserResult retval; GError *error = NULL; retval = totem_pl_parser_parse_finish (TOTEM_PL_PARSER (pl), result, &error); /* Do the fallback ourselves */ if (retval == TOTEM_PL_PARSER_RESULT_IGNORED) { grl_media_set_url (data->media, grl_media_get_id (data->media)); retval = TOTEM_PL_PARSER_RESULT_SUCCESS; } if (retval == TOTEM_PL_PARSER_RESULT_SUCCESS && grl_media_get_url (data->media) != NULL) { data->bs->callback (data->bs->source, data->bs->operation_id, data->media, -1, data->bs->user_data, NULL); } else { if (retval == TOTEM_PL_PARSER_RESULT_ERROR) { GRL_WARNING ("Failed to parse '%s': %s", grl_media_get_id (data->media), error->message); g_error_free (error); } g_object_unref (data->media); } data->media = NULL; resolve_disc_urls (data); }
static void grl_bookmarks_source_browse (GrlSource *source, GrlSourceBrowseSpec *bs) { GRL_DEBUG ("grl_bookmarks_source_browse"); OperationSpec *os; GrlBookmarksSource *bookmarks_source; GError *error = NULL; bookmarks_source = GRL_BOOKMARKS_SOURCE (source); if (!bookmarks_source->priv->adapter) { GRL_WARNING ("Can't execute operation: no database connection."); error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_BROWSE_FAILED, _("No database connection")); bs->callback (bs->source, bs->operation_id, NULL, 0, bs->user_data, error); g_error_free (error); } /* Configure browse operation */ os = g_slice_new0 (OperationSpec); os->source = bs->source; os->operation_id = bs->operation_id; os->media_id = grl_media_get_id (bs->container); os->count = grl_operation_options_get_count (bs->options); os->skip = grl_operation_options_get_skip (bs->options); os->type_filter = grl_operation_options_get_type_filter (bs->options); os->callback = bs->callback; os->user_data = bs->user_data; os->error_code = GRL_CORE_ERROR_BROWSE_FAILED; produce_bookmarks_from_category (os, os->media_id ? os->media_id : "0"); }
static void init_dump_directory (void) { capture_dir = g_getenv (GRL_NET_CAPTURE_DIR_VAR); if (capture_dir && is_mocked ()) { GRL_WARNING ("Cannot capture while mocking is enabled."); capture_dir = NULL; return; } if (capture_dir && g_mkdir_with_parents (capture_dir, 0700) != 0) { GRL_WARNING ("Could not create capture directory \"%s\": %s", capture_dir, g_strerror (errno)); capture_dir = NULL; return; } }
static void dump_data (SoupURI *uri, const char *buffer, const gsize length) { if (!capture_dir) return; char *uri_string = soup_uri_to_string (uri, FALSE); /* Write request content to file in capture directory. */ char *request_filename = build_request_filename (uri_string); char *path = g_build_filename (capture_dir, request_filename, NULL); GError *error = NULL; if (!g_file_set_contents (path, buffer, length, &error)) { GRL_WARNING ("Could not write contents to disk: %s", error->message); g_error_free (error); } g_free (path); /* Append record about the just written file to "grl-net-mock-data-%PID.ini" * in the capture directory. */ char *filename = g_strdup_printf ("grl-net-mock-data-%u.ini", getpid()); path = g_build_filename (capture_dir, filename, NULL); g_free (filename); FILE *stream = g_fopen (path, "at"); g_free (path); if (!stream) { GRL_WARNING ("Could not write contents to disk: %s", g_strerror (errno)); } else { if (ftell (stream) == 0) fprintf (stream, "[default]\nversion=%d\n\n", GRL_NET_MOCK_VERSION); fprintf (stream, "[%s]\ndata=%s\n\n", uri_string, request_filename); fclose (stream); } g_free (request_filename); g_free (uri_string); }
static void grl_metadata_store_source_resolve (GrlSource *source, GrlSourceResolveSpec *rs) { const gchar *source_id, *media_id; sqlite3_stmt *stmt; GError *error = NULL; GRL_DEBUG (__FUNCTION__); source_id = grl_media_get_source (rs->media); media_id = grl_media_get_id (rs->media); /* We need the source id */ if (!source_id) { GRL_WARNING ("Failed to resolve metadata: source-id not available"); error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Failed to resolve: %s"), _("\"source-id\" not available")); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, error); g_error_free (error); return; } /* Special case for root categories */ if (!media_id) { media_id = ""; } stmt = query_metadata_store (GRL_METADATA_STORE_SOURCE (source)->priv->db, source_id, media_id); if (stmt) { fill_metadata (rs->media, rs->keys, stmt); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); } else { GRL_WARNING ("Failed to resolve metadata"); error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Failed to resolve")); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, error); g_error_free (error); } }
static void grl_magnatune_source_init(GrlMagnatuneSource *source) { gint ret; gchar *path; gchar *db_path; gchar *crc_path; gchar *new_db_path; gchar *new_crc_path; GRL_DEBUG("magnatune_source_init"); source->priv = GRL_MAGNATUNE_GET_PRIVATE(source); source->priv->db = NULL; path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", NULL); db_path = g_build_filename(path, GRL_SQL_DB, NULL); crc_path = g_build_filename(path, GRL_SQL_CRC, NULL); new_db_path = g_build_filename(path, GRL_SQL_NEW_DB, NULL); new_crc_path = g_build_filename(path, GRL_SQL_NEW_CRC, NULL); if(!g_file_test(path, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents(path, 0775); } if (g_file_test(db_path, G_FILE_TEST_EXISTS) == TRUE) { if (g_file_test(new_db_path, G_FILE_TEST_EXISTS) == TRUE && g_rename(new_db_path, db_path) == 0) { GRL_DEBUG("New database in use."); } if (g_file_test(new_crc_path, G_FILE_TEST_EXISTS) == TRUE && g_rename(new_crc_path, crc_path) == 0) { GRL_DEBUG("New crc file in use."); } GRL_DEBUG("Opening database connection."); ret = sqlite3_open(db_path, &source->priv->db); if (ret != SQLITE_OK) { GRL_WARNING("Failed to open database '%s': %s", db_path, sqlite3_errmsg(source->priv->db)); sqlite3_close(source->priv->db); source->priv->db = NULL; } } else { GRL_DEBUG("No database was found. Download when user interact."); } g_free(new_crc_path); g_free(new_db_path); g_free(crc_path); g_free(db_path); g_free(path); }
/** * grl_operation_set_data: * @operation_id: the identifier of a running operation * @user_data: the data to attach * * Attach a pointer to the specific operation. */ void grl_operation_set_data (guint operation_id, gpointer user_data) { OperationData *data = g_hash_table_lookup (operations, GUINT_TO_POINTER (operation_id)); if (!data) { GRL_WARNING ("Invalid operation %u", operation_id); } else { data->user_data = user_data; } }
/** * grl_operation_get_data: * @operation_id: the identifier of a running operation * * Obtains the previously attached data * * Returns: (transfer none): The previously attached data. */ gpointer grl_operation_get_data (guint operation_id) { OperationData *data = g_hash_table_lookup (operations, GUINT_TO_POINTER (operation_id)); if (!data) { GRL_WARNING ("Invalid operation %u", operation_id); return NULL; } return data->user_data; }
static void magnatune_get_crc_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { gchar *new_crc_path = NULL; gchar *content = NULL; gsize length = 0; gboolean ret = FALSE; GError *err = NULL; GRL_DEBUG("magnatune_get_crc_done"); ret = grl_net_wc_request_finish(GRL_NET_WC(source_object), res, &content, &length, &err); g_object_unref(source_object); if (ret == TRUE) { new_crc_path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", GRL_SQL_NEW_CRC, NULL); ret = g_file_set_contents(new_crc_path, content, length, &err); if (ret == FALSE) { GRL_WARNING("Failed to save crc-file from magnatune to: '%s' - '%s'", new_crc_path, err->message); } g_free(new_crc_path); } else { GRL_WARNING("Failed to get crc-file from magnatune: %s", err->message); } }
static void migrate_cb (GObject *object, GAsyncResult *result, gpointer user_data) { gboolean ret; GError *error = NULL; ret = gom_repository_migrate_finish (GOM_REPOSITORY (object), result, &error); if (!ret) { GRL_WARNING ("Failed to migrate database: %s", error->message); g_error_free (error); } }
static void bookmark_resolve (GrlSourceResolveSpec *rs) { GomRepository *repository; GValue value = { 0, }; GomFilter *filter; GomResource *resource; GError *error = NULL; gint64 id; GrlTypeFilter type_filter; GRL_DEBUG (__FUNCTION__); repository = GRL_BOOKMARKS_SOURCE (rs->source)->priv->repository; id = g_ascii_strtoll (grl_media_get_id (rs->media), NULL, 0); if (!id) { /* Root category: special case */ grl_media_set_title (rs->media, GRL_ROOT_TITLE); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); return; } g_value_init (&value, G_TYPE_INT64); g_value_set_int64 (&value, id); filter = gom_filter_new_eq (BOOKMARKS_TYPE_RESOURCE, "id", &value); g_value_unset (&value); resource = gom_repository_find_one_sync (repository, BOOKMARKS_TYPE_RESOURCE, filter, &error); g_object_unref (filter); if (!resource) { GRL_WARNING ("Failed to get bookmark: %s", error->message); g_error_free (error); error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Failed to get bookmark metadata")); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, error); g_error_free (error); return; } type_filter = grl_operation_options_get_type_filter (rs->options); build_media_from_resource (rs->media, resource, type_filter); g_object_unref (resource); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); }
/** * grl_operation_cancel: * @operation_id: the identifier of a running operation * * Cancel an operation. */ void grl_operation_cancel (guint operation_id) { OperationData *data = g_hash_table_lookup (operations, GUINT_TO_POINTER (operation_id)); if (!data) { GRL_WARNING ("Invalid operation %u", operation_id); return; } g_return_if_fail (data != NULL); if (data->cancel_cb) { data->cancel_cb (data->private_data); } }
static void entry_parsed_cb (TotemPlParser *parser, const char *uri, GHashTable *metadata, BrowseData *data) { g_return_if_fail (data->media != NULL); if (grl_media_get_url (data->media) != NULL) { GRL_WARNING ("Was going to set media '%s' to URL '%s' but already has URL '%s'", grl_media_get_id (data->media), uri, grl_media_get_url (data->media)); return; } grl_media_set_url (data->media, uri); }
static void parsed_finished (TotemPlParser *pl, GAsyncResult *result, BrowseData *data) { TotemPlParserResult retval; GError *error = NULL; retval = totem_pl_parser_parse_finish (TOTEM_PL_PARSER (pl), result, &error); /* Do the fallback ourselves */ if (retval == TOTEM_PL_PARSER_RESULT_IGNORED) { GRL_DEBUG ("%s: Falling back for %s as has it's been ignored", __FUNCTION__, grl_media_get_id (data->media)); grl_media_set_url (data->media, grl_media_get_id (data->media)); retval = TOTEM_PL_PARSER_RESULT_SUCCESS; } if (retval == TOTEM_PL_PARSER_RESULT_SUCCESS && grl_media_get_url (data->media) != NULL) { GrlOpticalMediaSource *source; source = GRL_OPTICAL_MEDIA_SOURCE (data->bs->source); GRL_DEBUG ("%s: Adding %s which resolved to %s", __FUNCTION__, grl_media_get_id (data->media), grl_media_get_url (data->media)); data->bs->callback (GRL_SOURCE (source), data->bs->operation_id, data->media, -1, data->bs->user_data, NULL); source->priv->list = g_list_append (source->priv->list, g_object_ref (data->media)); } else { if (retval == TOTEM_PL_PARSER_RESULT_ERROR || retval == TOTEM_PL_PARSER_RESULT_CANCELLED) { GRL_WARNING ("Failed to parse '%s': %s", grl_media_get_id (data->media), error ? error->message : "No reason"); g_error_free (error); } g_object_unref (data->media); } data->media = NULL; resolve_disc_urls (data); }
static void grl_bookmarks_source_resolve (GrlSource *source, GrlSourceResolveSpec *rs) { GRL_DEBUG (__FUNCTION__); GrlBookmarksSource *bookmarks_source; GError *error = NULL; bookmarks_source = GRL_BOOKMARKS_SOURCE (source); if (!bookmarks_source->priv->repository) { GRL_WARNING ("Can't execute operation: no database connection."); error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("No database connection")); rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, error); g_error_free (error); } bookmark_resolve (rs); }
static void entry_parsed_cb (TotemPlParser *parser, const char *uri, GHashTable *metadata, GrlMedia **media) { char *scheme; g_return_if_fail (*media != NULL); if (grl_media_get_url (*media) != NULL) { GRL_WARNING ("Was going to set media '%s' to URL '%s' but already has URL '%s'", grl_media_get_id (*media), uri, grl_media_get_url (*media)); return; } scheme = g_uri_parse_scheme (uri); if (scheme != NULL && !g_str_equal (scheme, "file")) grl_media_set_url (*media, uri); g_free (scheme); }
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); } }
static sqlite3_stmt * query_metadata_store (sqlite3 *db, const gchar *source_id, const gchar *media_id) { gint r, idx; sqlite3_stmt *sql_stmt = NULL; GRL_DEBUG ("get_metadata"); r = sqlite3_prepare_v2 (db, GRL_SQL_GET_METADATA, -1, &sql_stmt, NULL); if (r != SQLITE_OK) { GRL_WARNING ("Failed to get metadata: %s", sqlite3_errmsg (db)); return NULL; } idx = 0; sqlite3_bind_text(sql_stmt, ++idx, source_id, -1, SQLITE_STATIC); sqlite3_bind_text(sql_stmt, ++idx, media_id, -1, SQLITE_STATIC); return sql_stmt; }
GFlickr * g_flickr_new (const gchar *consumer_key, const gchar *consumer_secret, const gchar *oauth_token, const gchar *oauth_token_secret) { g_return_val_if_fail (consumer_key && consumer_secret, NULL); GFlickr *f = g_object_new (G_FLICKR_TYPE, NULL); f->priv->consumer_key = g_strdup (consumer_key); f->priv->consumer_secret = g_strdup (consumer_secret); if (oauth_token != NULL) { if (oauth_token_secret == NULL) GRL_WARNING ("No token secret given."); f->priv->oauth_token = g_strdup (oauth_token); f->priv->oauth_token_secret = g_strdup (oauth_token_secret); } return f; }
static void remove_bookmark (GrlBookmarksSource *bookmarks_source, const gchar *bookmark_id, GrlMedia *media, GError **error) { GomResource *resource; gint64 id; GError *local_error = NULL; GRL_DEBUG ("remove_bookmark"); id = g_ascii_strtoll (bookmark_id, NULL, 0); resource = g_object_new (BOOKMARKS_TYPE_RESOURCE, "id", id, "repository", bookmarks_source->priv->repository, NULL); if (!gom_resource_delete_sync (resource, &local_error)) { GRL_WARNING ("Failed to remove bookmark '%s': %s", bookmark_id, local_error->message); *error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_REMOVE_FAILED, _("Failed to remove: %s"), local_error->message); g_error_free (local_error); } g_object_unref (resource); if (bookmarks_source->priv->notify_changes) { /* We can improve accuracy computing the parent container of removed element */ grl_source_notify_change (GRL_SOURCE (bookmarks_source), media, GRL_CONTENT_REMOVED, TRUE); } }
static void grl_metadata_store_source_store_metadata (GrlSource *source, GrlSourceStoreMetadataSpec *sms) { GRL_DEBUG ("grl_metadata_store_source_set_metadata"); const gchar *media_id, *source_id; GError *error = NULL; GList *failed_keys = NULL; source_id = grl_media_get_source (sms->media); media_id = grl_media_get_id (sms->media); /* We need the source id */ if (!source_id) { GRL_WARNING ("Failed to update metadata: source-id not available"); error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_STORE_METADATA_FAILED, _("Failed to update metadata: %s"), _("\"source-id\" not available")); failed_keys = g_list_copy (sms->keys); } else { /* Special case for root categories */ if (!media_id) { media_id = ""; } failed_keys = write_keys (GRL_METADATA_STORE_SOURCE (source)->priv->db, source_id, media_id, sms, &error); } sms->callback (sms->source, sms->media, failed_keys, sms->user_data, error); g_clear_error (&error); g_list_free (failed_keys); }