[rhythmbox] generic-player: handle eject better while still scanning
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] generic-player: handle eject better while still scanning
- Date: Wed, 9 Oct 2013 23:22:46 +0000 (UTC)
commit aae76be4fe8877b4e149b7d24208efd0f7723172
Author: Jonathan Matthew <jonathan d14n org>
Date: Thu Oct 10 09:21:25 2013 +1000
generic-player: handle eject better while still scanning
Before ejecting, cancel the import job and wait for it to finish,
so we're not still trying to access the device while ejecting it.
plugins/generic-player/rb-generic-player-source.c | 43 ++++++++++++++++-----
sources/rb-device-source.c | 14 +++++-
sources/rb-device-source.h | 2 +
3 files changed, 46 insertions(+), 13 deletions(-)
---
diff --git a/plugins/generic-player/rb-generic-player-source.c
b/plugins/generic-player/rb-generic-player-source.c
index 47a842b..fb6e6ce 100644
--- a/plugins/generic-player/rb-generic-player-source.c
+++ b/plugins/generic-player/rb-generic-player-source.c
@@ -83,6 +83,8 @@ static RBTrackTransferBatch *impl_paste (RBSource *source, GList *entries);
static gboolean impl_can_delete (RBSource *source);
static void impl_delete (RBSource *source);
+static void impl_eject (RBDeviceSource *source);
+
static char* impl_build_dest_uri (RBTransferTarget *target,
RhythmDBEntry *entry,
const char *media_type,
@@ -139,6 +141,7 @@ typedef struct
MPIDDevice *device_info;
GMount *mount;
+ gboolean ejecting;
GSimpleAction *new_playlist_action;
char *new_playlist_action_name;
@@ -155,6 +158,7 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (
#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_GENERIC_PLAYER_SOURCE,
RBGenericPlayerSourcePrivate))
+
static void
rb_generic_player_source_class_init (RBGenericPlayerSourceClass *klass)
{
@@ -227,7 +231,7 @@ rb_generic_player_source_class_init (RBGenericPlayerSourceClass *klass)
static void
rb_generic_player_device_source_init (RBDeviceSourceInterface *interface)
{
- /* nothing */
+ interface->eject = impl_eject;
}
static void
@@ -596,19 +600,23 @@ import_complete_cb (RhythmDBImportJob *job, int total, RBGenericPlayerSource *so
GDK_THREADS_ENTER ();
- g_object_get (source, "shell", &shell, NULL);
- rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (priv->import_errors), RB_DISPLAY_PAGE (source));
- g_object_unref (shell);
+ if (priv->ejecting) {
+ rb_device_source_default_eject (RB_DEVICE_SOURCE (source));
+ } else {
+ g_object_get (source, "shell", &shell, NULL);
+ rb_shell_append_display_page (shell, RB_DISPLAY_PAGE (priv->import_errors), RB_DISPLAY_PAGE
(source));
+ g_object_unref (shell);
- if (klass->impl_load_playlists)
- klass->impl_load_playlists (source);
+ if (klass->impl_load_playlists)
+ klass->impl_load_playlists (source);
- g_object_unref (priv->import_job);
- priv->import_job = NULL;
+ g_object_set (source, "load-status", RB_SOURCE_LOAD_STATUS_LOADED, NULL);
- g_object_set (source, "load-status", RB_SOURCE_LOAD_STATUS_LOADED, NULL);
+ rb_transfer_target_transfer (RB_TRANSFER_TARGET (source), NULL, FALSE);
+ }
- rb_transfer_target_transfer (RB_TRANSFER_TARGET (source), NULL, FALSE);
+ g_object_unref (priv->import_job);
+ priv->import_job = NULL;
GDK_THREADS_LEAVE ();
}
@@ -1080,6 +1088,21 @@ impl_delete (RBSource *source)
g_list_free (sel);
}
+
+static void
+impl_eject (RBDeviceSource *source)
+{
+ RBGenericPlayerSourcePrivate *priv = GET_PRIVATE (source);
+
+ if (priv->import_job != NULL) {
+ rhythmdb_import_job_cancel (priv->import_job);
+ priv->ejecting = TRUE;
+ } else {
+ rb_device_source_default_eject (source);
+ }
+}
+
+
static char *
sanitize_path (const char *str)
{
diff --git a/sources/rb-device-source.c b/sources/rb-device-source.c
index 577a2de..284c964 100644
--- a/sources/rb-device-source.c
+++ b/sources/rb-device-source.c
@@ -129,8 +129,16 @@ unmount_cb (GObject *object, GAsyncResult *result, gpointer nothing)
}
}
-static void
-default_eject (RBDeviceSource *source)
+/**
+ * rb_device_source_default_eject:
+ * @source: a #RBDeviceSource
+ *
+ * Default method for ejecting devices. Implementations can
+ * perform any required work before ejecting, then call this do
+ * eject the device.
+ */
+void
+rb_device_source_default_eject (RBDeviceSource *source)
{
GVolume *volume = NULL;
GMount *mount = NULL;
@@ -374,5 +382,5 @@ static void
rb_device_source_default_init (RBDeviceSourceInterface *interface)
{
interface->can_eject = default_can_eject;
- interface->eject = default_eject;
+ interface->eject = rb_device_source_default_eject;
}
diff --git a/sources/rb-device-source.h b/sources/rb-device-source.h
index e9b7994..6a57ce0 100644
--- a/sources/rb-device-source.h
+++ b/sources/rb-device-source.h
@@ -60,6 +60,8 @@ gboolean rb_device_source_uri_is_source (RBSource *source, const char *uri);
void rb_device_source_set_display_details (RBDeviceSource *source);
+void rb_device_source_default_eject (RBDeviceSource *source);
+
G_END_DECLS
#endif /* RB_DEVICE_SOURCE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]