Ejemplo n.º 1
0
/**
 * 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);
}
Ejemplo n.º 2
0
/**
 * grl_operation_options_set_key_filter_value:
 * @options: a #GrlOperationOptions instance
 * @key: a #GrlKeyID
 * @value: a #GValue
 *
 * Set filter as "@key == @value".
 *
 * Returns: %TRUE on success
 *
 * Since: 0.2.0
 **/
gboolean
grl_operation_options_set_key_filter_value (GrlOperationOptions *options,
                                            GrlKeyID key,
                                            GValue *value)
{
  gboolean ret;
  GrlRegistry *registry;
  GType key_type;

  registry = grl_registry_get_default ();
  key_type = grl_registry_lookup_metadata_key_type (registry, key);

  if (G_VALUE_TYPE (value) != key_type)
    return FALSE;

  ret = (options->priv->caps == NULL) ||
    grl_caps_is_key_filter (options->priv->caps, key);

  if (ret) {
    if (value) {
      g_hash_table_insert (options->priv->key_filter,
                           GRLKEYID_TO_POINTER (key),
                           grl_g_value_dup (value));
    } else {
      g_hash_table_remove (options->priv->key_filter,
                           GRLKEYID_TO_POINTER (key));
    }
  }

  return ret;
}
Ejemplo n.º 3
0
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);
  }
}
void
test_setup_thetvdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  if (tmp_dir == NULL) {
    /* Only create tmp dir and set the XDG_DATA_HOME once */
    tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
    tmp_dir = g_mkdtemp (tmp_dir);
    g_assert_nonnull (tmp_dir);

    g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
  }

  config = grl_config_new (THETVDB_ID, NULL);
  grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, THETVDB_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, THETVDB_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Ejemplo n.º 5
0
static void
impl_activate (PeasActivatable *plugin)
{
	RBGriloPlugin *pi = RB_GRILO_PLUGIN (plugin);
	GError *error = NULL;
	RBShell *shell;

	pi->sources = g_hash_table_new_full (g_direct_hash,
					     g_direct_equal,
					     g_object_unref,
					     g_object_unref);

	grl_init (0, NULL);
	pi->registry = grl_registry_get_default ();
	g_signal_connect (pi->registry, "source-added", G_CALLBACK (grilo_source_added_cb), pi);
	if (grl_registry_load_all_plugins (pi->registry, &error) == FALSE) {
		g_warning ("Failed to load Grilo plugins: %s", error->message);
		g_clear_error (&error);
	}

	g_object_get (plugin, "object", &shell, NULL);
	g_object_get (shell, "shell-player", &pi->shell_player, NULL);
	g_object_unref (shell);

	g_signal_connect (pi->shell_player, "playing-song-changed", G_CALLBACK (playing_song_changed_cb), pi);

	pi->art_store = rb_ext_db_new ("album-art");
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
/**
 * grl_plugin_get_sources:
 * @plugin: a plugin
 *
 * Gets the sources belonging to @plugin.
 *
 * Returns: (transfer container) (element-type GrlSource): a #GList of
 * #GrlSource<!-- -->s. The content of the list should not be modified or
 * freed. Use g_list_free() when done using the list.
 *
 * Since: 0.2.0
 **/
GList *
grl_plugin_get_sources (GrlPlugin *plugin)
{
    GrlRegistry *registry;
    GList *all_sources;
    GList *plugin_sources = NULL;
    GList *sources_iter;

    g_return_val_if_fail (GRL_IS_PLUGIN (plugin), NULL);

    registry = grl_registry_get_default ();
    all_sources = grl_registry_get_sources (registry, FALSE);

    for (sources_iter = all_sources;
            sources_iter;
            sources_iter = g_list_next (sources_iter)) {
        if (grl_source_get_plugin (GRL_SOURCE (sources_iter->data)) == plugin) {
            plugin_sources = g_list_prepend (plugin_sources, sources_iter->data);
        }
    }

    g_list_free (all_sources);

    return plugin_sources;
}
Ejemplo n.º 8
0
static void
load_plugins (gchar* playlist)
{
  GrlRegistry *registry;
  GrlSource *source;
  GError *error = NULL;
  GList *keys;
  GrlOperationOptions *options;
  GrlCaps *caps;
  GrlMedia* media;
  gboolean pls_media;
  const gchar *mime;

  registry = grl_registry_get_default ();
  grl_registry_load_all_plugins (registry, FALSE, NULL);

  /* Activate plugin */
  if (!grl_registry_activate_plugin_by_id (registry, "grl-filesystem", &error))
    g_error ("Failed to load plugin: %s", error->message);

  source = grl_registry_lookup_source (registry, "grl-filesystem");
  if (!source)
    g_error ("Unable to load grl-filesystem plugin");

  if (!(grl_source_supported_operations (source) & GRL_OP_MEDIA_FROM_URI))
    g_error ("Unable to get media from URI");

  keys = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE, GRL_METADATA_KEY_URL, GRL_METADATA_KEY_MIME, NULL);
  if (!keys)
    g_error ("Unable to create key list");

  caps = grl_source_get_caps (source, GRL_OP_MEDIA_FROM_URI);
  if (!caps)
    g_error ("Unable to get source caps");

  options = grl_operation_options_new (caps);
  if (!options)
    g_error ("Unable to create operation options");

  media = grl_source_get_media_from_uri_sync (source, playlist, keys, options, &error);
  if (!media)
    g_error ("Unable to get GrlMedia for playlist %s", playlist);

  g_object_unref (options);

  mime = grl_media_get_mime (media);

  pls_media = grl_pls_media_is_playlist (media);

  g_printf("Got Media for %s - mime=%s\n", playlist, mime);
  g_printf("\tgrl_pls_media_is_playlist = %d\n", pls_media);

  if (pls_media) {
    source_browser (source, media);
  }

  g_object_unref (media);
  g_object_unref (source);
}
Ejemplo n.º 9
0
void GriloRegistry::componentComplete() {
  m_registry = grl_registry_get_default();

  g_signal_connect(m_registry, "source-added", G_CALLBACK(grilo_source_added), this);
  g_signal_connect(m_registry, "source-removed", G_CALLBACK(grilo_source_removed), this);

  loadConfigurationFile();
}
static void
ensure_hash_keyid (GrlLocalMetadataSourcePriv *priv)
{
  if (priv->hash_keyid == GRL_METADATA_KEY_INVALID) {
    GrlRegistry *registry = grl_registry_get_default ();
    priv->hash_keyid = grl_registry_lookup_metadata_key (registry, "gibest-hash");
  }
}
static void
test_lua_factory_shutdown (void)
{
  GrlRegistry *registry;
  GError *error = NULL;

  registry = grl_registry_get_default ();
  grl_registry_unload_plugin (registry, LUA_FACTORY_ID, &error);
  g_assert_no_error (error);
}
static GrlSource*
test_lua_factory_get_source (gchar *source_id,
                             GrlSupportedOps source_ops)
{
  GrlRegistry *registry = grl_registry_get_default ();
  GrlSource *source = grl_registry_lookup_source (registry, source_id);
  g_assert_nonnull (source);
  g_assert (grl_source_supported_operations (source) & source_ops);
  return source;
}
void
test_shutdown_tmdb (void)
{
  GrlRegistry *registry;
  GError *error = NULL;

  registry = grl_registry_get_default ();
  grl_registry_unload_plugin (registry, TMDB_PLUGIN_ID, &error);
  g_assert_no_error (error);
}
Ejemplo n.º 14
0
/**
 * grl_metadata_key_get_type:
 * @key: key to look up
 *
 * Retrieves the expected type for values associated with this key
 *
 * Returns: the expected value type
 *
 * Since: 0.2.0
 **/
GType grl_metadata_key_get_type (GrlKeyID key)
{
  GrlRegistry *registry = grl_registry_get_default ();

  if (registry) {
    return grl_registry_lookup_metadata_key_type (registry, key);
  } else {
    return G_TYPE_INVALID;
  }
}
Ejemplo n.º 15
0
/**
 * grl_metadata_key_get_desc:
 * @key: key to look up
 *
 * Retrieves the description associated with the key
 *
 * Returns: the description of the key
 *
 * Since: 0.1.6
 */
const gchar *
grl_metadata_key_get_desc (GrlKeyID key)
{
  GrlRegistry *registry = grl_registry_get_default ();

  if (registry) {
    return grl_registry_lookup_metadata_key_desc (registry, key);
  } else {
    return NULL;
  }
}
Ejemplo n.º 16
0
/**
 * grl_plugin_register_keys: (skip)
 * @plugin: a plugin
 *
 * Register custom metadata keys for the plugin
 */
void
grl_plugin_register_keys (GrlPlugin *plugin)
{
    GrlRegistry *registry;

    g_return_if_fail (GRL_IS_PLUGIN (plugin));

    registry = grl_registry_get_default ();

    if (plugin->priv->desc.register_keys) {
        plugin->priv->desc.register_keys (registry, plugin);
    }
}
Ejemplo n.º 17
0
GriloRegistry::GriloRegistry(QObject *parent) :
  QObject(parent) {

  grl_init(0, 0);

  m_registry = grl_registry_get_default();

  g_signal_connect(m_registry, "source-added", G_CALLBACK(grilo_source_added), this);
  g_signal_connect(m_registry, "source-removed", G_CALLBACK(grilo_source_removed), this);

  GList *sources = grl_registry_get_sources(m_registry, FALSE);
  g_list_foreach(sources, connect_source, this);
  g_list_free(sources);
}
Ejemplo n.º 18
0
static void
config_plugins (gchar* chosen_test_path)
{
  GrlRegistry *registry;
  GrlConfig *config;

  registry = grl_registry_get_default ();

  /* Configure plugin */
  config = grl_config_new ("grl-filesystem", "Filesystem");
  grl_config_set_string (config, "base-path", chosen_test_path);
  grl_registry_add_config (registry, config, NULL);

  g_printf ("config_plugin with %s\n", chosen_test_path);
}
Ejemplo n.º 19
0
static void
grl_dpap_service_removed_cb (DMAPMdnsBrowser *browser,
                             const gchar *service_name,
                             GrlPlugin *plugin)
{
  GrlRegistry   *registry = grl_registry_get_default ();
  GrlDpapSource *source   = g_hash_table_lookup (sources, service_name);

  GRL_DEBUG (__FUNCTION__);

  if (source) {
    grl_registry_unregister_source (registry, GRL_SOURCE (source), NULL);
    g_hash_table_remove (sources, service_name);
  }
}
void
test_lua_factory_setup (GrlConfig *config)
{
  GrlRegistry *registry;
  GError *error = NULL;

  registry = grl_registry_get_default ();

  if (config != NULL) {
    grl_registry_add_config (registry, config, &error);
    g_assert_no_error (error);
  }

  grl_registry_load_plugin_by_id (registry, LUA_FACTORY_ID, &error);
  g_assert_no_error (error);
}
static void
test_unload (void)
{
  GrlRegistry *registry;
  GError *error = NULL;
  gchar *db_path;

  registry = grl_registry_get_default ();
  grl_registry_unload_plugin (registry, THETVDB_ID, &error);
  g_assert_no_error (error);

  /* Remove grl-thetvdb database to avoid unecessary grow of tmpdir */
  db_path = g_build_filename (tmp_dir, "grilo-plugins", "grl-thetvdb.db", NULL);
  g_remove (db_path);
  g_free (db_path);
}
Ejemplo n.º 22
0
static void
grl_dpap_service_added_cb (DMAPMdnsBrowser *browser,
                           DMAPMdnsBrowserService *service,
                           GrlPlugin *plugin)
{
  GrlRegistry   *registry = grl_registry_get_default ();
  GrlDpapSource *source   = grl_dpap_source_new (service);

  GRL_DEBUG (__FUNCTION__);

  g_object_add_weak_pointer (G_OBJECT (source), (gpointer *) &source);
  grl_registry_register_source (registry,
                                plugin,
                                GRL_SOURCE (source),
                                NULL);
  if (source != NULL) {
    g_hash_table_insert (sources, g_strdup (service->name), g_object_ref (source));
    g_object_remove_weak_pointer (G_OBJECT (source), (gpointer *) &source);
  }
}
Ejemplo n.º 23
0
static void
mex_bliptv_plugin_init (MexBliptvPlugin  *self)
{
  MexBliptvPluginPrivate *priv;
  GrlRegistry *registry;
  GList *sources, *iter;

  priv = self->priv = GET_PRIVATE (self);

  priv->video_models = g_hash_table_new_full (g_direct_hash, g_direct_equal,
                                                   NULL, NULL);

  priv->query_keys = grl_metadata_key_list_new (GRL_METADATA_KEY_ID,
                                                GRL_METADATA_KEY_TITLE,
                                                GRL_METADATA_KEY_MIME,
                                                GRL_METADATA_KEY_URL,
                                                GRL_METADATA_KEY_PUBLICATION_DATE,
                                                NULL);

  priv->video_keys = grl_metadata_key_list_new (GRL_METADATA_KEY_ID,
                                                GRL_METADATA_KEY_DESCRIPTION,
                                                GRL_METADATA_KEY_DURATION,
                                                GRL_METADATA_KEY_THUMBNAIL,
                                                GRL_METADATA_KEY_WIDTH,
                                                GRL_METADATA_KEY_HEIGHT,
                                                NULL);

  priv->manager = mex_model_manager_get_default ();

  registry = grl_registry_get_default ();
  sources = grl_registry_get_sources (registry, FALSE);
  for (iter = sources; iter != NULL; iter = iter->next)
    handle_new_source (self, GRL_SOURCE (iter->data));
  g_list_free (sources);

  g_signal_connect (registry, "source-added",
                    G_CALLBACK (registry_source_added_cb), self);
  g_signal_connect (registry, "source-removed",
                    G_CALLBACK (registry_source_removed_cb), self);
}
Ejemplo n.º 24
0
static void
load_plugins (void)
{
  GrlRegistry *registry;
  GError *error = NULL;

  registry = grl_registry_get_default ();

  /* These callback will be invoked when media providers
     are loaded/unloaded */
  g_signal_connect (registry, "source-added",
                    G_CALLBACK (source_added_cb), NULL);
  g_signal_connect (registry, "source-removed",
                    G_CALLBACK (source_removed_cb), NULL);

  /* Command the registry to load all available plugins.
     The registry will look for plugins in the default
     plugin path and directories specified using the
     GRL_PLUGIN_PATH environment variable */
  if (!grl_registry_load_all_plugins (registry, TRUE, &error)) {
    g_error ("Failed to load plugins: %s", error->message);
  }
}
Ejemplo n.º 25
0
/**
 * grl_plugin_load: (skip)
 * @plugin: a plugin
 * @configurations: (element-type GrlConfig): a list of configurations
 *
 * Load the plugin
 *
 * Returns: @TRUE if loaded was successful
 */
gboolean
grl_plugin_load (GrlPlugin *plugin,
                 GList *configurations)
{
    GrlRegistry *registry;

    g_return_val_if_fail (GRL_IS_PLUGIN (plugin), FALSE);

    if (!plugin->priv->desc.init) {
        return FALSE;
    }

    registry = grl_registry_get_default ();

    if (!plugin->priv->desc.init (registry, plugin, configurations)) {
        return FALSE;
    }

    plugin->priv->loaded = TRUE;
    g_object_notify_by_pspec (G_OBJECT (plugin), properties[PROP_LOADED]);

    return TRUE;
}
void
test_setup_tmdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  config = grl_config_new (TMDB_PLUGIN_ID, NULL);
  /* It does not matter what we set this to. It just needs to be non-empty because we're
   * going to fake the network responses. */
  grl_config_set_api_key (config, "TMDB_TEST_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, TMDB_PLUGIN_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, TMDB_PLUGIN_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Ejemplo n.º 27
0
void
grl_tracker_setup_key_mappings (void)
{
  GrlRegistry *registry = grl_registry_get_default ();

  /* Check if "tracker-urn" is registered; if not, then register it */
  grl_metadata_key_tracker_urn =
    grl_registry_lookup_metadata_key (registry, "tracker-urn");

  if (grl_metadata_key_tracker_urn == GRL_METADATA_KEY_INVALID) {
    grl_metadata_key_tracker_urn =
      grl_registry_register_metadata_key (grl_registry_get_default (),
                                          g_param_spec_string ("tracker-urn",
                                                               "Tracker URN",
                                                               "Universal resource number in Tracker's store",
                                                               NULL,
                                                               G_PARAM_STATIC_STRINGS |
                                                               G_PARAM_READWRITE),
                                          NULL);
  }

  /* Check if "gibest-hash" is registered; if not, then register it */
  grl_metadata_key_gibest_hash =
    grl_registry_lookup_metadata_key (registry, "gibest-hash");

  if (grl_metadata_key_gibest_hash == GRL_METADATA_KEY_INVALID) {
    grl_metadata_key_gibest_hash =
      grl_registry_register_metadata_key (grl_registry_get_default (),
                                          g_param_spec_string ("gibest-hash",
                                                               "Gibest hash",
                                                               "Gibest hash of the video file",
                                                               NULL,
                                                               G_PARAM_STATIC_STRINGS |
                                                               G_PARAM_READWRITE),
                                          NULL);
  }

  grl_to_sparql_mapping = g_hash_table_new (g_direct_hash, g_direct_equal);
  sparql_to_grl_mapping = g_hash_table_new (g_str_hash, g_str_equal);

  insert_key_mapping (grl_metadata_key_tracker_urn,
                      NULL,
                      "?urn",
                      "file");

  insert_key_mapping (GRL_METADATA_KEY_ALBUM,
                      NULL,
                      "nmm:albumTitle(nmm:musicAlbum(?urn))",
                      "audio");

  insert_key_mapping (GRL_METADATA_KEY_ARTIST,
                      NULL,
                      "nmm:artistName(nmm:performer(?urn))",
                      "audio");

  insert_key_mapping (GRL_METADATA_KEY_AUTHOR,
                      NULL,
                      "nmm:artistName(nmm:performer(?urn))",
                      "audio");

  insert_key_mapping (GRL_METADATA_KEY_BITRATE,
                      "nfo:averageBitrate",
                      "nfo:averageBitrate(?urn)",
                      "audio");

  insert_key_mapping (GRL_METADATA_KEY_CHILDCOUNT,
                      "nfo:entryCounter",
                      "nfo:entryCounter(?urn)",
                      "directory");

  insert_key_mapping (GRL_METADATA_KEY_SIZE,
                      NULL,
                      "nfo:fileSize(?urn)",
                      "file");

  insert_key_mapping (grl_metadata_key_gibest_hash,
                      NULL,
                      "(select nfo:hashValue(?h) { ?urn nfo:hasHash ?h . ?h nfo:hashAlgorithm \"gibest\" })",
                      "video");

  insert_key_mapping_with_setter (GRL_METADATA_KEY_MODIFICATION_DATE,
                                  "nfo:fileLastModified",
                                  "nfo:fileLastModified(?urn)",
                                  "file",
                                  set_date);

  insert_key_mapping (GRL_METADATA_KEY_DURATION,
                      "nfo:duration",
                      "nfo:duration(?urn)",
                      "audio");

  insert_key_mapping (GRL_METADATA_KEY_FRAMERATE,
                      "nfo:frameRate",
                      "nfo:frameRate(?urn)",
                      "video");

  insert_key_mapping (GRL_METADATA_KEY_HEIGHT,
                      "nfo:height",
                      "nfo:height(?urn)",
                      "video");

  insert_key_mapping (GRL_METADATA_KEY_ID,
                      "tracker:id",
                      "tracker:id(?urn)",
                      "file");

  /* insert_key_mapping (GRL_METADATA_KEY_LAST_PLAYED, */
  /*                     "nfo:fileLastAccessed(?urn)", */
  /*                     "file"); */

  insert_key_mapping (GRL_METADATA_KEY_MIME,
                      "nie:mimeType",
                      "nie:mimeType(?urn)",
                      "file");

  insert_key_mapping (GRL_METADATA_KEY_SITE,
                      "nie:url",
                      "nie:url(?urn)",
                      "file");

  insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
                                  "nie:title",
                                  "nie:title(?urn)",
                                  "audio",
                                  set_title);

  insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
                                  "nfo:fileName",
                                  "nfo:fileName(?urn)",
                                  "file",
                                  set_title_from_filename);

  insert_key_mapping (GRL_METADATA_KEY_URL,
                      "nie:url",
                      "nie:url(?urn)",
                      "file");

  insert_key_mapping (GRL_METADATA_KEY_WIDTH,
                      "nfo:width",
                      "nfo:width(?urn)",
                      "video");

  insert_key_mapping (GRL_METADATA_KEY_SEASON,
                      "nmm:season",
                      "nmm:season(?urn)",
                      "video");

  insert_key_mapping (GRL_METADATA_KEY_EPISODE,
                      "nmm:episodeNumber",
                      "nmm:episodeNumber(?urn)",
                      "video");

  insert_key_mapping_with_setter (GRL_METADATA_KEY_CREATION_DATE,
                                  "nie:contentCreated",
                                  "nie:contentCreated(?urn)",
                                  "image",
                                  set_date);

  insert_key_mapping (GRL_METADATA_KEY_CAMERA_MODEL,
                      NULL,
                      "nfo:model(nfo:equipment(?urn))",
                      "image");

  insert_key_mapping (GRL_METADATA_KEY_FLASH_USED,
                      "nmm:flash",
                      "nmm:flash(?urn)",
                      "image");

  insert_key_mapping (GRL_METADATA_KEY_EXPOSURE_TIME,
                      "nmm:exposureTime",
                      "nmm:exposureTime(?urn)",
                      "image");

  insert_key_mapping (GRL_METADATA_KEY_ISO_SPEED,
                      "nmm:isoSpeed",
                      "nmm:isoSpeed(?urn)",
                      "image");

  insert_key_mapping_with_setter (GRL_METADATA_KEY_ORIENTATION,
                                  "nfo:orientation",
                                  "nfo:orientation(?urn)",
                                  "image",
                                  set_orientation);

  insert_key_mapping (GRL_METADATA_KEY_PLAY_COUNT,
                      "nie:usageCounter",
                      "nie:usageCounter(?urn)",
                      "media");

  insert_key_mapping (GRL_METADATA_KEY_LAST_PLAYED,
                      "nie:contentAccessed",
                      "nie:contentAccessed(?urn)",
                      "media");

  insert_key_mapping (GRL_METADATA_KEY_LAST_POSITION,
                      "nfo:lastPlayedPosition",
                      "nfo:lastPlayedPosition(?urn)",
                      "media");

  insert_key_mapping (GRL_METADATA_KEY_START_TIME,
                      "nfo:audioOffset",
                      "nfo:audioOffset(?urn)",
                      "media");

  if (grl_tracker_upnp_present) {
    insert_key_mapping (GRL_METADATA_KEY_THUMBNAIL,
                        "upnp:thumbnail",
                        "upnp:thumbnail(?urn)",
                        "media");
  }
}
Ejemplo n.º 28
0
/* Main program */
gint
main (gint argc, gchar **argv)
{
  GError *error = NULL;
  GOptionContext *context = NULL;
  gint i;

  context = g_option_context_new ("- run Grilo plugin as UPnP service");
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, grl_init_get_option_group ());
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);

  if (error) {
    g_printerr ("Invalid arguments, %s\n", error->message);
    g_clear_error (&error);
    return -1;
  }

  /* Adjust limits */
  limit = CLAMP (limit, 0, G_MAXINT);
  if (limit == 0) {
    limit = G_MAXINT;
  }

  /* Initialize grilo */
  grl_init (&argc, &argv);
  registry = grl_registry_get_default ();
  if (!registry) {
    g_printerr ("Unable to load Grilo registry\n");
    return -1;
  }

  /* Register a key to store parent */
  GRL_METADATA_KEY_GRILO_MS2_PARENT =
    grl_registry_register_metadata_key (registry,
                                        g_param_spec_string ("grilo-mediaserver2-parent",
                                                             "GriloMediaServer2Parent",
                                                             "Object path to parent container",
                                                             NULL,
                                                             G_PARAM_READWRITE),
                                        GRL_METADATA_KEY_INVALID,
                                        NULL);

  if (GRL_METADATA_KEY_GRILO_MS2_PARENT == GRL_METADATA_KEY_INVALID) {
    g_error ("Unable to register Parent key");
    return 1;
  }

  /* Load configuration */
  load_config ();

  /* Initialize <grilo-plugin, ms2-server> pairs */
  servers = g_hash_table_new_full (g_str_hash,
                                   g_str_equal,
                                   g_free,
                                   g_object_unref);

  g_signal_connect (registry, "source-added",
                    G_CALLBACK (source_added_cb), NULL);

  g_signal_connect (registry, "source-removed",
                    G_CALLBACK (source_removed_cb), NULL);

  if (!args || !args[0]) {
    grl_registry_load_all_plugins (registry, TRUE, NULL);
  } else {
    for (i = 0; args[i]; i++) {
      grl_registry_load_plugin (registry, args[i], NULL);
    }
  }

  g_main_loop_run (g_main_loop_new (NULL, FALSE));
}
Ejemplo n.º 29
0
int main (int argc, char *argv[])
{
#if !GLIB_CHECK_VERSION(2,35,0)
  g_type_init ();
#endif

  grl_init (&argc, &argv);

  /*
   * Set the TMDB API key:
   * You must use your own TMDB API key in your own application.
   */
  GrlRegistry *reg = grl_registry_get_default ();
  GrlConfig *config = grl_config_new (TMDB_PLUGIN_ID, NULL);
  grl_config_set_api_key (config, TMDB_KEY);
  grl_registry_add_config (reg, config, NULL);

  /*
   * Get the plugin:
   */
  GError *error = NULL;
  gboolean plugin_loaded =
    grl_registry_load_plugin_by_id (reg, TMDB_PLUGIN_ID, &error);
  g_assert (plugin_loaded);
  g_assert_no_error (error);

  /*
   * Get the Grilo source:
   */
  GrlSource *src =
    grl_registry_lookup_source (reg, TMDB_PLUGIN_ID);

  /*
   * Check that it has the expected capability:
   */
  g_assert (grl_source_supported_operations (src) & GRL_OP_RESOLVE);
  GrlCaps *caps = grl_source_get_caps (src, GRL_OP_RESOLVE);
  g_assert (caps);

  GrlOperationOptions *options = grl_operation_options_new (caps);

  /*
   * A media item that we will give to the TMDB plugin,
   * to discover its details.
   */
  GrlMedia *media = grl_media_video_new ();
  grl_media_set_title (media, "Sherlock Holmes");

  /*
   * Discover what keys are provided by the source:
   */
  const GList *keys = grl_source_supported_keys (src);
  const GList* l = NULL;
  for (l = keys; l != NULL; l = l->next) {
    GrlKeyID id = GPOINTER_TO_INT (l->data);
    g_assert (id);

    const gchar *name = grl_metadata_key_get_name (id);
    printf ("Supported key: %s\n", name);

    /*
     * Remember this for later use:
     * You may instead use grl_registry_lookup_metadata_key_name().
     */
    if (g_strcmp0 (name, "tmdb-director") == 0) {
      director_key = id;
    }
  }

  /*
   * Ask the TMDB plugin for the media item's details,
   * from the TMDB online service:
   */
  grl_source_resolve (src, media,
    keys, options,
    resolve_cb, NULL);

  /*
   * Start the main loop so our callback can be called:
   */
  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);

  /*
   * Release objects:
   */
  g_object_unref (media);
  g_object_unref (config);
  g_object_unref (options);

  /*
   * Deinitialize Grilo:
   */
  grl_deinit ();
}
Ejemplo n.º 30
0
static void
photos_application_startup (GApplication *application)
{
  PhotosApplication *self = PHOTOS_APPLICATION (application);
  PhotosApplicationPrivate *priv = self->priv;
  GError *error;
  GSimpleAction *action;
  GrlRegistry *registry;
  GtkSettings *settings;
  GVariant *state;

  G_APPLICATION_CLASS (photos_application_parent_class)
    ->startup (application);

  gegl_init (NULL, NULL);

  grl_init (NULL, NULL);
  registry = grl_registry_get_default ();
  error = NULL;
  if (!grl_registry_load_plugin_by_id (registry, "grl-flickr", &error))
    {
      g_warning ("Unable to load Grilo's Flickr plugin: %s", error->message);
      g_error_free (error);
    }

  priv->settings = g_settings_new ("org.gnome.desktop.background");

  priv->resource = photos_get_resource ();
  g_resources_register (priv->resource);

  settings = gtk_settings_get_default ();
  g_object_set (settings, "gtk-application-prefer-dark-theme", TRUE, NULL);

  priv->facebook_miner = gom_miner_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                           G_DBUS_PROXY_FLAGS_NONE,
                                                           "org.gnome.OnlineMiners.Facebook",
                                                           "/org/gnome/OnlineMiners/Facebook",
                                                           NULL,
                                                           NULL);

  priv->flickr_miner = gom_miner_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                         G_DBUS_PROXY_FLAGS_NONE,
                                                         "org.gnome.OnlineMiners.Flickr",
                                                         "/org/gnome/OnlineMiners/Flickr",
                                                         NULL,
                                                         NULL);

  priv->item_mngr = photos_item_manager_dup_singleton ();

  /* A dummy reference to keep it alive during the lifetime of the
   * application.
   */
  priv->camera_cache = photos_camera_cache_dup_singleton ();

  priv->mode_cntrlr = photos_mode_controller_dup_singleton ();

  action = g_simple_action_new ("about", NULL);
  g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_application_about), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
  g_object_unref (action);

  priv->fs_action = g_simple_action_new ("fullscreen", NULL);
  g_signal_connect_swapped (priv->fs_action, "activate", G_CALLBACK (photos_application_fullscreen), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->fs_action));

  g_signal_connect_swapped (priv->mode_cntrlr,
                            "can-fullscreen-changed",
                            G_CALLBACK (photos_application_can_fullscreen_changed),
                            self);

  state = g_variant_new ("b", FALSE);
  priv->gear_action = g_simple_action_new_stateful ("gear-menu", NULL, state);
  g_signal_connect (priv->gear_action, "activate", G_CALLBACK (photos_application_action_toggle), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->gear_action));

  priv->open_action = g_simple_action_new ("open-current", NULL);
  g_signal_connect_swapped (priv->open_action, "activate", G_CALLBACK (photos_application_open_current), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->open_action));

  priv->print_action = g_simple_action_new ("print-current", NULL);
  g_signal_connect_swapped (priv->print_action, "activate", G_CALLBACK (photos_application_print_current), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->print_action));

  priv->properties_action = g_simple_action_new ("properties", NULL);
  g_signal_connect_swapped (priv->properties_action, "activate", G_CALLBACK (photos_application_properties), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->properties_action));

  priv->remote_display_action = g_simple_action_new ("remote-display-current", NULL);
  g_signal_connect_swapped (priv->remote_display_action, "activate", G_CALLBACK (photos_application_remote_display_current), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->remote_display_action));

  action = g_simple_action_new ("quit", NULL);
  g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_application_quit), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
  g_object_unref (action);

  state = g_variant_new ("b", FALSE);
  priv->search_action = g_simple_action_new_stateful ("search", NULL, state);
  g_signal_connect (priv->search_action, "activate", G_CALLBACK (photos_application_action_toggle), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->search_action));

  priv->sel_all_action = g_simple_action_new ("select-all", NULL);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_all_action));

  priv->sel_none_action = g_simple_action_new ("select-none", NULL);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_none_action));

  priv->set_bg_action = g_simple_action_new ("set-background", NULL);
  g_signal_connect_swapped (priv->set_bg_action, "activate", G_CALLBACK (photos_application_set_bg), self);
  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->set_bg_action));

  g_signal_connect_swapped (priv->mode_cntrlr,
                            "window-mode-changed",
                            G_CALLBACK (photos_application_window_mode_changed),
                            self);

  photos_application_init_app_menu (self);

  gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>q", "app.quit", NULL);
  gtk_application_add_accelerator (GTK_APPLICATION (self), "F11", "app.fullscreen", NULL);
  gtk_application_add_accelerator (GTK_APPLICATION (self), "F10", "app.gear-menu", NULL);
  gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>p", "app.print-current", NULL);
  gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>f", "app.search", NULL);
  gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>a", "app.select-all", NULL);
}