~ubuntu-branches/ubuntu/raring/grilo/raring-proposed

« back to all changes in this revision

Viewing changes to src/grl-source.c

  • Committer: Package Import Robot
  • Author(s): Alberto Garcia
  • Date: 2012-11-12 18:12:56 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20121112181256-2ee4rg7dbkh03a65
Tags: 0.2.3-1
* New upstream version.
* debian/rules: new API, bump package version in dh_makeshlibs.
* debian/rules: configure with --disable-debug, otherwise it's enabled
  by default.
* Drop all lintian-overrides files, there are no longer hardening
  warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
  PROP_DESC,
62
62
  PROP_PLUGIN,
63
63
  PROP_RANK,
64
 
  PROP_AUTO_SPLIT_THRESHOLD
 
64
  PROP_AUTO_SPLIT_THRESHOLD,
 
65
  PROP_SUPPORTED_MEDIA
65
66
};
66
67
 
67
68
enum {
80
81
  gchar *name;
81
82
  gchar *desc;
82
83
  gint rank;
 
84
  GrlMediaType supported_media;
83
85
  guint auto_split_threshold;
84
86
  GrlPlugin *plugin;
85
87
};
363
365
                                                      0, G_MAXUINT, 0,
364
366
                                                      G_PARAM_READWRITE |
365
367
                                                      G_PARAM_STATIC_STRINGS));
 
368
  /**
 
369
   * GrlSource:supported-media:
 
370
   *
 
371
   * List of supported media types by this source.
 
372
   *
 
373
   * Since: 0.2.3
 
374
   */
 
375
  g_object_class_install_property (gobject_class,
 
376
                                   PROP_SUPPORTED_MEDIA,
 
377
                                   g_param_spec_flags ("supported-media",
 
378
                                                       "Supported media",
 
379
                                                       "List of supported media types",
 
380
                                                       GRL_TYPE_MEDIA_TYPE,
 
381
                                                       GRL_MEDIA_TYPE_ALL,
 
382
                                                       G_PARAM_READWRITE |
 
383
                                                       G_PARAM_CONSTRUCT |
 
384
                                                       G_PARAM_STATIC_STRINGS));
366
385
 
367
386
  /**
368
387
   * GrlSource::content-changed:
478
497
  case PROP_AUTO_SPLIT_THRESHOLD:
479
498
    source->priv->auto_split_threshold = g_value_get_uint (value);
480
499
    break;
 
500
  case PROP_SUPPORTED_MEDIA:
 
501
    source->priv->supported_media = g_value_get_flags (value);
 
502
    break;
481
503
  default:
482
504
    G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
483
505
    break;
513
535
  case PROP_AUTO_SPLIT_THRESHOLD:
514
536
    g_value_set_uint (value, source->priv->auto_split_threshold);
515
537
    break;
 
538
  case PROP_SUPPORTED_MEDIA:
 
539
    g_value_set_flags (value, source->priv->supported_media);
 
540
    break;
516
541
  default:
517
542
    G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
518
543
    break;
2491
2516
  GrlRegistry *registry;
2492
2517
  GList *sources = NULL;
2493
2518
  GList *sources_iter;
 
2519
  GList *unsupported_keys;
2494
2520
  GrlSource *_source;
2495
2521
 
2496
2522
  map = g_hash_table_new_full (g_direct_hash, g_direct_equal,
2500
2526
  /* 'key_list' holds keys that can be written by this source
2501
2527
     'unsupportedy_keys' holds those that must be handled by other sources */
2502
2528
  GList *key_list = g_list_copy (keys);
2503
 
  GList *unsupported_keys = filter_writable (source, &key_list, TRUE);
 
2529
  if (grl_source_supported_operations (source) & GRL_OP_STORE_METADATA) {
 
2530
    unsupported_keys = filter_writable (source, &key_list, TRUE);
 
2531
  } else {
 
2532
    unsupported_keys = key_list;
 
2533
    key_list = NULL;
 
2534
  }
2504
2535
 
2505
2536
  if (key_list) {
2506
2537
    g_hash_table_insert (map, g_object_ref (source), key_list);
2629
2660
store_metadata_idle (gpointer user_data)
2630
2661
{
2631
2662
  GrlSourceStoreMetadataSpec *sms;
 
2663
  gboolean stop;
2632
2664
  struct StoreMetadataRelayCb *smrc;
2633
2665
 
2634
2666
  GRL_DEBUG (__FUNCTION__);
2647
2679
  smrc->use_sources = g_list_remove_link (smrc->use_sources, smrc->use_sources);
2648
2680
  smrc->specs = g_list_prepend (smrc->specs, sms);
2649
2681
 
 
2682
  stop = smrc->use_sources == NULL;
2650
2683
  GRL_SOURCE_GET_CLASS (sms->source)->store_metadata (sms->source, sms);
2651
2684
 
2652
 
  return (smrc->use_sources != NULL);
 
2685
  return !stop;
2653
2686
}
2654
2687
 
2655
2688
static void
2706
2739
  if (grl_operation_options_get_count (options) == 0)
2707
2740
    return FALSE;
2708
2741
 
2709
 
  caps = grl_source_get_caps (source, operation);
 
2742
  /* Check only if the source supports the operation */
 
2743
  if (grl_source_supported_operations (source) & operation) {
 
2744
    caps = grl_source_get_caps (source, operation);
2710
2745
 
2711
 
  return grl_operation_options_obey_caps (options, caps, NULL, NULL);
 
2746
    return grl_operation_options_obey_caps (options, caps, NULL, NULL);
 
2747
  } else {
 
2748
    return TRUE;
 
2749
  }
2712
2750
}
2713
2751
 
2714
2752
/* ============= API ============= */
2868
2906
}
2869
2907
 
2870
2908
/**
 
2909
 * grl_source_get_supported_media:
 
2910
 * @source: a source
 
2911
 *
 
2912
 * Gets the supported type of medias @source can deal with.
 
2913
 *
 
2914
 * Returns: a #GrlMediaType value
 
2915
 *
 
2916
 * Since: 0.2.3
 
2917
 **/
 
2918
GrlMediaType
 
2919
grl_source_get_supported_media (GrlSource *source)
 
2920
{
 
2921
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
2922
 
 
2923
  return source->priv->supported_media;
 
2924
}
 
2925
 
 
2926
/**
2871
2927
 * grl_source_supported_operations:
2872
2928
 * @source: a source
2873
2929
 *
3006
3062
  GList *delete_key;
3007
3063
  struct ResolveRelayCb *rrc;
3008
3064
  guint operation_id;
3009
 
  GList *sources;
 
3065
  GList *sources = NULL;
3010
3066
  GrlResolutionFlags flags;
3011
3067
  GrlOperationOptions *resolve_options;
3012
3068
 
3013
3069
  GRL_DEBUG (__FUNCTION__);
3014
3070
 
3015
3071
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
3072
  g_return_val_if_fail (GRL_IS_OPERATION_OPTIONS (options), 0);
3016
3073
  g_return_val_if_fail (keys != NULL, 0);
3017
3074
  g_return_val_if_fail (callback != NULL, 0);
3018
 
  g_return_val_if_fail (grl_source_supported_operations (source) &
3019
 
                        GRL_OP_RESOLVE, 0);
3020
3075
  g_return_val_if_fail (check_options (source, GRL_OP_RESOLVE, options), 0);
3021
3076
 
3022
3077
  if (!media) {
3038
3093
    sources = grl_registry_get_sources_by_operations (grl_registry_get_default (),
3039
3094
                                                      GRL_OP_RESOLVE,
3040
3095
                                                      TRUE);
3041
 
    /* Put current source on top */
3042
 
    sources = g_list_remove (sources, source);
3043
 
    sources = g_list_prepend (sources, source);
 
3096
    /* Put current source on top, if it supports resolve() */
 
3097
    if (grl_source_supported_operations (source) & GRL_OP_RESOLVE) {
 
3098
      sources = g_list_remove (sources, source);
 
3099
      sources = g_list_prepend (sources, source);
 
3100
    }
3044
3101
    flags &= ~GRL_RESOLVE_FULL;
3045
3102
    resolve_options = grl_operation_options_copy (options);
3046
3103
    grl_operation_options_set_flags (resolve_options, flags);
3047
3104
  } else {
3048
 
    /* Consider only this source */
3049
 
    sources = g_list_prepend (NULL, source);
 
3105
    /* Consider only this source, if it supports resolve() */
 
3106
    if (grl_source_supported_operations (source) & GRL_OP_RESOLVE) {
 
3107
      sources = g_list_prepend (NULL, source);
 
3108
    }
3050
3109
    resolve_options = g_object_ref (options);
3051
3110
  }
3052
3111
 
3054
3113
    GRL_DEBUG ("requested fast keys");
3055
3114
  }
3056
3115
 
3057
 
  _keys = filter_unresolvable_keys (sources, &_keys);
3058
 
 
3059
3116
  operation_id = grl_operation_generate_id ();
3060
3117
 
3061
3118
  operation_set_ongoing (source, operation_id);
3063
3120
  /* Always hook an own relay callback so we can do some
3064
3121
     post-processing before handing out the results
3065
3122
     to the user */
3066
 
  rrc = g_slice_new (struct ResolveRelayCb);
 
3123
  rrc = g_slice_new0 (struct ResolveRelayCb);
3067
3124
  rrc->source = g_object_ref (source);
3068
3125
  rrc->operation_type = GRL_OP_RESOLVE;
3069
3126
  rrc->operation_id = operation_id;
3070
3127
  rrc->media = g_object_ref (media);
3071
 
  rrc->keys = _keys;
 
3128
  rrc->user_callback = callback;
 
3129
  rrc->user_data = user_data;
3072
3130
  rrc->options = resolve_options;
3073
 
  rrc->user_callback = callback;
3074
 
  rrc->user_data = user_data;
3075
 
  rrc->cancel_invoked = FALSE;
 
3131
 
 
3132
  /* If there are no sources able to solve just send the media */
 
3133
  if (g_list_length (sources) == 0) {
 
3134
    g_idle_add_full (flags & GRL_RESOLVE_IDLE_RELAY?
 
3135
                     G_PRIORITY_DEFAULT_IDLE: G_PRIORITY_HIGH_IDLE,
 
3136
                     resolve_all_done,
 
3137
                     rrc,
 
3138
                     NULL);
 
3139
    return operation_id;
 
3140
  }
 
3141
 
 
3142
  _keys = filter_unresolvable_keys (sources, &_keys);
 
3143
 
 
3144
  rrc->keys = _keys;
3076
3145
  rrc->map = map_keys_new ();
3077
3146
  rrc->resolve_specs = map_sources_new ();
3078
 
  rrc->error = NULL;
3079
 
  rrc->specs_to_invoke = NULL;
3080
3147
 
3081
3148
  map_keys_to_sources (rrc->map, _keys, sources, media, flags & GRL_RESOLVE_FAST_ONLY);
3082
3149
  g_list_free (sources);
3303
3370
  GRL_DEBUG (__FUNCTION__);
3304
3371
 
3305
3372
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
3373
  g_return_val_if_fail (GRL_IS_OPERATION_OPTIONS (options), 0);
3306
3374
  g_return_val_if_fail (uri != NULL, 0);
3307
3375
  g_return_val_if_fail (keys != NULL, 0);
3308
3376
  g_return_val_if_fail (callback != NULL, 0);
3452
3520
  GrlResolutionFlags flags;
3453
3521
 
3454
3522
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
3523
  g_return_val_if_fail (GRL_IS_OPERATION_OPTIONS (options), 0);
3455
3524
  g_return_val_if_fail (callback != NULL, 0);
3456
3525
  g_return_val_if_fail (grl_source_supported_operations (source) &
3457
3526
                        GRL_OP_BROWSE, 0);
3617
3686
  GrlResolutionFlags flags;
3618
3687
 
3619
3688
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
3689
  g_return_val_if_fail (GRL_IS_OPERATION_OPTIONS (options), 0);
3620
3690
  g_return_val_if_fail (callback != NULL, 0);
3621
3691
  g_return_val_if_fail (grl_source_supported_operations (source) &
3622
3692
                        GRL_OP_SEARCH, 0);
3776
3846
  GrlResolutionFlags flags;
3777
3847
 
3778
3848
  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
 
3849
  g_return_val_if_fail (GRL_IS_OPERATION_OPTIONS (options), 0);
3779
3850
  g_return_val_if_fail (query != NULL, 0);
3780
3851
  g_return_val_if_fail (callback != NULL, 0);
3781
3852
  g_return_val_if_fail (grl_source_supported_operations (source) &
4126
4197
  g_return_val_if_fail (GRL_IS_SOURCE (source), FALSE);
4127
4198
  g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
4128
4199
  g_return_val_if_fail (keys != NULL, FALSE);
4129
 
  g_return_val_if_fail (grl_source_supported_operations (source) &
4130
 
                        GRL_OP_STORE_METADATA, FALSE);
4131
4200
 
4132
4201
  run_store_metadata (source, media, keys, flags, callback, user_data);
4133
4202