137
137
static void source_activated_cb (RBSourceList *sourcelist,
138
138
RBSource *source,
140
static void rb_shell_activate_source (RBShell *shell,
140
static gboolean rb_shell_activate_source (RBShell *shell,
142
144
static void rb_shell_db_save_error_cb (RhythmDB *db,
143
145
const char *uri, const GError *error,
145
static void rb_shell_db_entry_added_cb (RhythmDB *db,
146
RhythmDBEntry *entry,
149
148
static void rb_shell_playlist_added_cb (RBPlaylistManager *mgr, RBSource *source, RBShell *shell);
150
149
static void rb_shell_playlist_created_cb (RBPlaylistManager *mgr, RBSource *source, RBShell *shell);
855
854
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN);
856
* RBShell::database-load-complete:
857
* @shell: the #RBShell
859
* Emitted when the database has been loaded. This is intended to allow
860
* DBus clients that start a new instance of the application to wait until
861
* a reasonable amount of state has been loaded before making further requests.
863
rb_shell_signals[DATABASE_LOAD_COMPLETE] =
864
g_signal_new ("database-load-complete",
865
G_OBJECT_CLASS_TYPE (object_class),
867
G_STRUCT_OFFSET (RBShellClass, database_load_complete),
869
g_cclosure_marshal_VOID__VOID,
857
873
g_type_class_add_private (klass, sizeof (RBShellPrivate));
1874
1892
rb_debug ("source activated");
1876
rb_shell_activate_source (shell, source);
1894
rb_shell_activate_source (shell, source, 2, NULL);
1880
rb_shell_activate_source (RBShell *shell, RBSource *source)
1898
rb_shell_activate_source (RBShell *shell, RBSource *source, guint play, GError **error)
1900
RhythmDBEntry *entry;
1884
1903
* this doesn't work correctly yet, but it's still an improvement on the
1888
1907
* doesn't start the new one.
1891
/* Select the new one, and start it playing */
1910
/* Select the new one, and optionally start it playing */
1892
1911
rb_shell_select_source (shell, source);
1893
rb_shell_player_set_playing_source (shell->priv->player_shell, source);
1894
/* Ignore error from here */
1895
rb_shell_player_playpause (shell->priv->player_shell, FALSE, NULL);
1918
entry = rb_shell_player_get_playing_entry (shell->priv->player_shell);
1919
if (entry != NULL) {
1920
rhythmdb_entry_unref (entry);
1925
rb_shell_player_set_playing_source (shell->priv->player_shell, source);
1926
return rb_shell_player_playpause (shell->priv->player_shell, FALSE, error);
1905
1940
"%s", error->message);
1909
rb_shell_db_entry_added_cb (RhythmDB *db,
1910
RhythmDBEntry *entry,
1915
if (shell->priv->pending_entry == NULL)
1918
loc = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
1919
rb_debug ("got entry added for %s", loc);
1920
if (strcmp (loc, shell->priv->pending_entry) == 0) {
1921
rb_shell_play_entry (shell, entry);
1923
g_free (shell->priv->pending_entry);
1924
shell->priv->pending_entry = NULL;
1929
1944
* rb_shell_get_source_by_entry_type:
1930
1945
* @shell: the #RBShell
3257
3287
if (result == TOTEM_PL_PARSER_RESULT_SUCCESS) {
3258
3288
if (data.can_use_playlist && data.playlist_source) {
3259
3289
rb_debug ("adding playlist %s to source", uri);
3260
rb_source_add_uri (data.playlist_source, uri, NULL, NULL);
3290
rb_source_add_uri (data.playlist_source, uri, NULL, NULL, NULL, NULL, NULL);
3262
3292
/* FIXME: We need some way to determine whether the URI as
3263
3293
* given will appear in the db, or whether something else will.
3276
} else if ((result == TOTEM_PL_PARSER_RESULT_IGNORED && rb_uri_is_local (uri))
3277
|| result == TOTEM_PL_PARSER_RESULT_UNHANDLED) {
3278
/* That happens for directories and unhandled schemes, such as CDDA */
3279
playlist_source = rb_shell_guess_source_for_uri (shell, uri);
3280
if (playlist_source == NULL || rb_source_uri_is_source (playlist_source, uri) == FALSE) {
3281
rb_debug ("%s doesn't have a source, adding", uri);
3282
if (!rb_shell_add_uri (shell, uri, NULL, NULL, error))
3286
rb_debug ("%s didn't parse as a playlist", uri);
3287
if (!rb_shell_add_uri (shell, uri, NULL, NULL, error))
3309
source = rb_shell_guess_source_for_uri (shell, uri);
3310
if (source != NULL) {
3312
g_object_get (source, "name", &name, NULL);
3313
if (rb_source_uri_is_source (source, uri)) {
3314
rb_debug ("%s identifies source %s", uri, name);
3315
entry_source = source;
3317
rb_debug ("adding %s to source %s, will play it when it shows up", uri, name);
3318
rb_source_add_uri (source, uri, NULL, NULL, (RBSourceAddCallback) shell_load_uri_done, g_object_ref (shell), g_object_unref);
3321
rb_debug ("just adding %s to source %s", uri, name);
3322
rb_source_add_uri (source, uri, NULL, NULL, NULL, NULL, NULL);
3326
rb_debug ("couldn't find a source for %s, trying to add it anyway", uri);
3327
if (!rb_shell_add_uri (shell, uri, NULL, NULL, error)) {
3328
rb_debug ("couldn't do it: %s", (*error)->message);
3291
3334
if (data.source_is_entry != FALSE) {
3292
playlist_source = data.playlist_source;
3335
entry_source = data.playlist_source;
3293
3336
} else if (data.playlist_source != NULL) {
3294
3337
g_object_unref (data.playlist_source);
3299
if (playlist_source != NULL) {
3342
if (entry_source != NULL) {
3302
rb_shell_activate_source (shell, playlist_source);
3304
g_object_get (playlist_source, "name", &name, NULL);
3345
if (entry == NULL) {
3346
/* we don't have a specific entry to play, so just play something */
3350
if (rb_shell_activate_source (shell, entry_source, play_type, error) == FALSE) {
3354
g_object_get (entry_source, "name", &name, NULL);
3305
3355
rb_debug ("Activated source '%s' for uri %s", name, uri);
3312
entry = rhythmdb_entry_lookup_by_location (shell->priv->db, uri);
3315
3362
rb_shell_play_entry (shell, entry);
3317
/* wait for the entry to be added, and then play it */
3318
if (shell->priv->pending_entry)
3319
g_free (shell->priv->pending_entry);
3321
shell->priv->pending_entry = g_strdup (uri);
3425
3466
const gchar *uri,
3426
3467
GError **error)
3469
RhythmDBEntry *entry;
3471
entry = rhythmdb_entry_lookup_by_location (shell->priv->db, uri);
3472
if (entry == NULL) {
3474
source = rb_shell_guess_source_for_uri (shell, uri);
3475
if (source != NULL) {
3476
rb_source_add_uri (source, uri, NULL, NULL, NULL, NULL, NULL);
3480
RB_SHELL_ERROR_NO_SOURCE_FOR_URI,
3481
_("No registered source can handle URI %s"),
3428
3486
rb_static_playlist_source_add_location (RB_STATIC_PLAYLIST_SOURCE (shell->priv->queue_source),
3558
* rb_shell_activate_source_by_uri:
3559
* @shell: the #RBShell
3560
* @source_uri: URI for the source to activate
3561
* @play: 0: select source, 1: play source if not playing, 2: play source
3562
* @error: returns error information
3564
* Searches for a source matching @source_uri and if found, selects it,
3565
* and depending on the value of @play, may start playing from it.
3566
* Device-based sources will match the device node or mount point URI.
3567
* Other types of sources may have their own URI scheme or format.
3568
* This is part of the DBus interface.
3570
* Return value: %TRUE if successful
3573
rb_shell_activate_source_by_uri (RBShell *shell,
3574
const char *source_uri,
3582
/* ensure the argument is actually a URI */
3583
f = g_file_new_for_commandline_arg (source_uri);
3584
uri = g_file_get_uri (f);
3587
for (t = shell->priv->sources; t != NULL; t = t->next) {
3590
source = (RBSource *)t->data;
3591
if (rb_source_uri_is_source (source, uri)) {
3592
rb_debug ("found source for uri %s", uri);
3594
return rb_shell_activate_source (shell, source, play, error);
3600
RB_SHELL_ERROR_NO_SOURCE_FOR_URI,
3601
_("No registered source matches URI %s"),
3500
3608
* rb_shell_get_song_properties:
3501
3609
* @shell: the #RBShell
3502
3610
* @uri: the URI to query