static void produce_from_recent_theme (RaitvOperation *op) { guint category_index; gchar *start = NULL; gchar *url = NULL; GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); category_index = get_theme_index_from_id (op->container_id); GRL_DEBUG ("produce_from_recent_theme (container_id=%s, category_index=%d",op->container_id,category_index); start = g_strdup_printf ("%u", op->offset+op->length); op->category_info = &themes_dir[category_index]; url = g_strdup_printf (RAITV_VIDEO_RECENT, start, op->category_info->tags, op->category_info->excludeTags); GRL_DEBUG ("Starting browse request for recent theme (%s)", url); grl_net_wc_request_async (source->priv->wc, url, op->cancellable, proxy_call_browse_grlnet_async_cb, op); g_free (url); }
static GrlMedia * create_media_from_mount (GMount *mount) { char *id; GrlMedia *media; /* Is it an audio CD or a blank media */ if (ignore_mount (mount)) { GRL_DEBUG ("%s: Ignoring mount %s", __FUNCTION__, g_mount_get_name (mount)); g_object_unref (mount); return NULL; } id = create_mount_id (mount); if (id == NULL) { GRL_DEBUG ("%s: Not adding mount %s as has no device path", __FUNCTION__, g_mount_get_name (mount)); return NULL; } media = grl_media_video_new (); grl_media_set_id (media, id); g_free (id); media_set_metadata (mount, media); grl_media_set_mime (media, "x-special/device-block"); GRL_DEBUG ("%s: Adding mount %s (id: %s)", __FUNCTION__, g_mount_get_name (mount), grl_media_get_id (media)); return media; }
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 tracker_evt_update_items_cb (gpointer key, gpointer value, tracker_evt_update_t *evt) { guint id = GPOINTER_TO_INT (key); gchar *str_id; GrlTrackerSource *source = (GrlTrackerSource *) value; GrlMedia *media; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); if (!source) { g_assert ("\tnot in cache ???"); return; } if (!grl_tracker_source_can_notify (source)) { GRL_DEBUG ("\tno notification for source %s...", grl_source_get_name (GRL_SOURCE (source))); return; } media = grl_media_new (); str_id = g_strdup_printf ("%i", id); grl_media_set_id (media, str_id); g_free (str_id); GRL_DEBUG ("\tNotify id=%u source=%s", id, grl_source_get_name (GRL_SOURCE (source))); grl_source_notify_change (GRL_SOURCE (source), media, evt->change_type, FALSE); g_object_unref (media); }
static gboolean ignore_drive (GDrive *drive) { GIcon *icon; if (g_drive_can_eject (drive) == FALSE || g_drive_has_media (drive) == FALSE) { GRL_DEBUG ("%s: Not adding %s as cannot eject or has no media", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } /* Hack to avoid USB devices showing up * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */ icon = g_drive_get_icon (drive); if (icon && G_IS_THEMED_ICON (icon)) { const gchar * const * names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) { g_object_unref (icon); GRL_DEBUG ("%s: Not adding drive %s as is not optical drive", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } } g_clear_object (&icon); return FALSE; }
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_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); }
static void on_configuration_ready (GObject *source, GAsyncResult *result, gpointer user_data) { ResolveClosure *closure = (ResolveClosure *) user_data; GrlTmdbRequest *request = GRL_TMDB_REQUEST (source); GrlTmdbSource *self = closure->self; GError *error = NULL; GValue *value; GRL_DEBUG ("Configuration request ready..."); if (!grl_tmdb_request_run_finish (GRL_TMDB_REQUEST (source), result, &error)) { resolve_closure_callback (closure, error); resolve_closure_free (closure); /* Notify pending requests about failure */ while (!g_queue_is_empty (self->priv->pending_resolves)) { ResolveClosure *pending_closure; pending_closure = g_queue_pop_head (self->priv->pending_resolves); resolve_closure_callback (pending_closure, error); resolve_closure_free (pending_closure); } g_error_free (error); return; } self->priv->configuration = g_object_ref (request); remove_request (closure, request); value = grl_tmdb_request_get (request, "$.images.base_url"); if (value != NULL) { GRL_DEBUG ("Got TMDb configuration."); self->priv->image_base_uri = soup_uri_new (g_value_get_string (value)); g_value_unset (value); g_free (value); } g_queue_push_head (self->priv->pending_resolves, closure); /* Flush queue. GrlNetWc will take care of throttling */ while (!g_queue_is_empty (self->priv->pending_resolves)) { ResolveClosure *pending_closure; pending_closure = g_queue_pop_head (self->priv->pending_resolves); run_pending_requests (pending_closure, G_MAXINT); } }
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 gboolean ignore_mount (GMount *mount) { GFile *root; GVolume *volume; gboolean ret = TRUE; root = g_mount_get_root (mount); if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE) { /* We don't add Audio CDs, or blank media */ g_object_unref (root); GRL_DEBUG ("%s: Not adding mount %s as is burn or cdda", __FUNCTION__, g_mount_get_name (mount)); return TRUE; } g_object_unref (root); volume = g_mount_get_volume (mount); if (volume == NULL) return ret; ret = ignore_volume (volume); g_object_unref (volume); return ret; }
static void produce_bookmarks_from_text (OperationSpec *os, const gchar *text) { GomFilter *like1, *like2, *likes, *type1, *filter; GValue value = { 0, }; GRL_DEBUG ("produce_bookmarks_from_text"); /* WHERE (title LIKE '%text%' OR desc LIKE '%text%') AND type == BOOKMARKS_TYPE_STREAM */ like1 = substr_filter ("title", text); like2 = substr_filter ("desc", text); likes = gom_filter_new_or (like1, like2); g_object_unref (like1); g_object_unref (like2); g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, BOOKMARKS_TYPE_STREAM); type1 = gom_filter_new_eq (BOOKMARKS_TYPE_RESOURCE, "type", &value); g_value_unset (&value); filter = gom_filter_new_and (likes, type1); g_object_unref (likes); g_object_unref (type1); produce_bookmarks_from_filter (os, filter); g_object_unref (filter); }
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 grl_dleyna_plugin_deinit (GrlPlugin *plugin) { GRL_DEBUG (G_STRFUNC); g_clear_object (&servers); }
static GrlDpapSource * grl_dpap_source_new (DMAPMdnsBrowserService *service) { gchar *source_desc; gchar *source_id; GrlDpapSource *source; GRL_DEBUG ("grl_dpap_source_new"); source_desc = g_strdup_printf (SOURCE_DESC_TEMPLATE, service->name); source_id = g_strdup_printf (SOURCE_ID_TEMPLATE, service->name); source = g_object_new (GRL_DPAP_SOURCE_TYPE, "source-id", source_id, "source-name", service->name, "source-desc", source_desc, "supported-media", GRL_SUPPORTED_MEDIA_IMAGE, NULL); source->priv->service = service; g_free (source_desc); g_free (source_id); return source; }
static void resolve_album_art (ResolveData *resolve_data, resolution_flags_t flags) { const gchar *artist, *album; GCancellable *cancellable = NULL; GFile *cache_file = NULL; resolve_data_start_operation (resolve_data, "album-art"); artist = grl_media_audio_get_artist (GRL_MEDIA_AUDIO (resolve_data->rs->media)); album = grl_media_audio_get_album (GRL_MEDIA_AUDIO (resolve_data->rs->media)); if (!artist || !album) goto done; cancellable = resolve_data_ensure_cancellable (resolve_data); media_art_get_file (artist, album, "album", &cache_file); if (cache_file) { /* Check whether the cache file exists. */ resolve_data_start_operation (resolve_data, "album-art"); g_file_query_info_async (cache_file, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, cancellable, resolve_album_art_cb, resolve_data); } else { GRL_DEBUG ("Found no thumbnail for artist %s and album %s", artist, album); } done: resolve_data_finish_operation (resolve_data, "album-art", NULL); g_clear_object (&cache_file); }
gboolean grl_tmdb_source_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { GrlConfig *config; char *api_key; GRL_LOG_DOMAIN_INIT (tmdb_log_domain, "tmdb"); GRL_DEBUG ("grl_tmdb_source_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!configs) { GRL_INFO ("No configuration provided. Will not load plugin"); return FALSE; } config = GRL_CONFIG (configs->data); api_key = grl_config_get_api_key (config); if (!api_key) { GRL_INFO ("Missing API Key, cannot load plugin"); return FALSE; } GRL_TMDB_METADATA_KEY_BACKDROP = register_metadata_key (registry, "tmdb-backdrop", "tmdb-backdrop", "A list of URLs for movie backdrops"); GRL_TMDB_METADATA_KEY_POSTER = register_metadata_key (registry, "tmdb-poster", "tmdb-poster", "A list of URLs for movie posters"); GRL_TMDB_METADATA_KEY_IMDB_ID = register_metadata_key (registry, "tmdb-imdb-id", "tmdb-imdb-id", "ID of this movie at imdb.org"); GRL_TMDB_METADATA_KEY_TMDB_ID = register_metadata_key (registry, "tmdb-id", "tmdb-id", "ID of this movie at tmdb.org"); GrlTmdbSource *source = grl_tmdb_source_new (api_key); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); g_free (api_key); return TRUE; }
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); }
/* The caller is responsible for freeing @error. */ static void resolve_data_finish_operation (ResolveData *data, const gchar *op_name, const GError *error) { g_assert (data->n_pending_operations >= 1); data->n_pending_operations--; GRL_DEBUG ("Finishing operation %s; %u operations still pending.", op_name, data->n_pending_operations); if (!data->has_invoked_callback && (data->n_pending_operations == 0 || error != NULL)) { GrlSourceResolveSpec *rs = data->rs; /* All sub-operations have finished (or one has errored), so the callback * can be invoked. */ data->has_invoked_callback = TRUE; rs->callback (data->source, rs->operation_id, rs->media, rs->user_data, error); } /* All sub-operations have finished, so we can free the closure. */ if (data->n_pending_operations == 0) { g_assert (data->has_invoked_callback); g_object_unref (data->source); g_slice_free (ResolveData, data); } }
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 gboolean ignore_volume (GVolume *volume) { gboolean ret = TRUE; char *path; GDrive *drive; /* Ignore drive? */ drive = g_volume_get_drive (volume); if (drive != NULL && ignore_drive (drive)) { g_object_unref (drive); return TRUE; } g_clear_object (&drive); path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); if (path != NULL) { ret = FALSE; g_free (path); } else { GRL_DEBUG ("%s: Not adding volume %s as it has no identifier", __FUNCTION__, g_volume_get_name (volume)); } return ret; }
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 resolve_image (ResolveData *resolve_data, resolution_flags_t flags) { GFile *file; GCancellable *cancellable; GRL_DEBUG ("resolve_image"); resolve_data_start_operation (resolve_data, "image"); if (flags & FLAG_THUMBNAIL) { const gchar *attributes; file = g_file_new_for_uri (grl_media_get_url (resolve_data->rs->media)); cancellable = resolve_data_ensure_cancellable (resolve_data); #if GLIB_CHECK_VERSION (2, 39, 0) attributes = G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," \ G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID; #else attributes = G_FILE_ATTRIBUTE_THUMBNAIL_PATH; #endif g_file_query_info_async (file, attributes, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback)got_file_info, resolve_data); g_object_unref (file); } else { resolve_data_finish_operation (resolve_data, "image", NULL); } }
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 GrlVimeoSource * grl_vimeo_source_new (void) { GIcon *icon; GFile *file; GrlVimeoSource *source; const char *tags[] = { "net:internet", NULL }; GRL_DEBUG ("grl_vimeo_source_new"); file = g_file_new_for_uri ("resource:///org/gnome/grilo/plugins/vimeo/channel-vimeo.svg"); icon = g_file_icon_new (file); g_object_unref (file); source = g_object_new (GRL_VIMEO_SOURCE_TYPE, "source-id", SOURCE_ID, "source-name", SOURCE_NAME, "source-desc", SOURCE_DESC, "supported-media", GRL_SUPPORTED_MEDIA_VIDEO, "source-icon", icon, "source-tags", tags, NULL); g_object_unref (icon); return source; }
static void tracker_evt_update_source_add (tracker_evt_update_t *evt, const gchar *id, const gchar *source_name) { GrlTrackerSource *source; GrlTrackerSourcePriv *priv; source = g_hash_table_lookup (grl_tracker_source_sources_modified, id); if (!source) { source = g_object_new (GRL_TRACKER_SOURCE_TYPE, "source-id", id, "source-name", source_name, "source-desc", GRL_TRACKER_SOURCE_DESC, "tracker-connection", grl_tracker_connection, "tracker-datasource", id, NULL); g_hash_table_insert (grl_tracker_source_sources_modified, (gpointer) grl_tracker_source_get_tracker_source (source), source); } priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source); priv->state = GRL_TRACKER_SOURCE_STATE_INSERTING; priv->notification_ref++; evt->new_sources = g_list_append (evt->new_sources, source); GRL_DEBUG ("Preadd source p=%p name=%s id=%s count=%u", source, source_name, id, priv->notification_ref); }
/* grl.lua.json.string_to_table * * @json_str: (string) A Json object as a string. * * @return: All json content as a table. */ static gint grl_json_parse_string (lua_State *L) { JsonParser *parser = NULL; JsonReader *reader = NULL; const gchar *json_str = NULL; GError *err = NULL; luaL_argcheck (L, lua_isstring (L, 1), 1, "json string expected"); json_str = lua_tostring (L, 1); parser = json_parser_new (); if (!json_parser_load_from_data (parser, json_str, -1, &err)) { GRL_DEBUG ("Can't parse json string: '%s'", err->message); g_error_free (err); g_object_unref (parser); return 0; } reader = json_reader_new (json_parser_get_root (parser)); /* The return of recursive function will be a table with all * json content in it */ lua_pushnil (L); build_table_from_json_reader (L, reader); g_object_unref (reader); g_object_unref (parser); return 1; }
static void cache_down (GrlNetWc *self) { GFile *cache_dir_file; GrlNetWcPrivate *priv = self->priv; SoupSessionFeature *cache = soup_session_get_feature (priv->session, SOUP_TYPE_CACHE); gchar *cache_dir; GRL_DEBUG ("cache down"); if (!cache) { return; } soup_cache_clear (SOUP_CACHE (cache)); g_object_get (cache, "cache-dir", &cache_dir, NULL); cache_dir_file = g_file_new_for_path (cache_dir); g_free (cache_dir); g_file_delete (cache_dir_file, NULL, NULL); g_object_unref (G_OBJECT (cache_dir_file)); soup_session_remove_feature (priv->session, cache); }
static void cache_up (GrlNetWc *self) { SoupCache *cache; GrlNetWcPrivate *priv = self->priv; gchar *dir; GRL_DEBUG ("cache up"); dir = g_dir_make_tmp ("grilo-plugin-cache-XXXXXX", NULL); if (!dir) return; cache = soup_cache_new (dir, SOUP_CACHE_SINGLE_USER); g_free (dir); soup_session_add_feature (priv->session, SOUP_SESSION_FEATURE (cache)); if (priv->cache_size) { soup_cache_set_max_size (cache, priv->cache_size * 1024 * 1024); } g_object_unref (cache); }
static void extract_gibest_hash (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { GFile *file = source_object; guint64 buffer[2][CHUNK_N_BYTES/8]; GInputStream *stream = NULL; gssize n_bytes, file_size; GError *error = NULL; guint64 hash = 0; gint i; char *str; ResolveData *resolve_data = task_data; GrlLocalMetadataSourcePriv *priv; priv = GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (resolve_data->source); stream = G_INPUT_STREAM (g_file_read (file, cancellable, &error)); if (stream == NULL) goto fail; /* Extract start/end chunks of the file */ n_bytes = g_input_stream_read (stream, buffer[0], CHUNK_N_BYTES, cancellable, &error); if (n_bytes == -1) goto fail; if (!g_seekable_seek (G_SEEKABLE (stream), -CHUNK_N_BYTES, G_SEEK_END, cancellable, &error)) goto fail; n_bytes = g_input_stream_read (stream, buffer[1], CHUNK_N_BYTES, cancellable, &error); if (n_bytes == -1) goto fail; for (i = 0; i < G_N_ELEMENTS (buffer[0]); i++) hash += buffer[0][i] + buffer[1][i]; file_size = g_seekable_tell (G_SEEKABLE (stream)); if (file_size < CHUNK_N_BYTES) goto fail; /* Include file size */ hash += file_size; g_object_unref (stream); str = g_strdup_printf ("%" G_GINT64_FORMAT, hash); grl_data_set_string (GRL_DATA (resolve_data->rs->media), priv->hash_keyid, str); g_free (str); g_task_return_boolean (task, TRUE); return; fail: GRL_DEBUG ("Could not get file hash: %s\n", error ? error->message : "Unknown error"); g_task_return_error (task, error); g_clear_object (&stream); }