static void impl_delete (RBSource *source) { RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (source); GList *sel; GList *tem; RBEntryView *tracks; RhythmDB *db; int ret; db = get_db_for_source (RB_MTP_SOURCE (source)); tracks = rb_source_get_entry_view (source); sel = rb_entry_view_get_selected_entries (tracks); for (tem = sel; tem != NULL; tem = tem->next) { LIBMTP_track_t *track; RhythmDBEntry *entry; const char *uri; const char *album_name; entry = (RhythmDBEntry *)tem->data; uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); track = g_hash_table_lookup (priv->entry_map, entry); if (track == NULL) { rb_debug ("Couldn't find track on mtp-device! (%s)", uri); continue; } ret = LIBMTP_Delete_Object (priv->device, track->item_id); if (ret != 0) { rb_debug ("Delete track %d failed", track->item_id); report_libmtp_errors (priv->device, TRUE); continue; } album_name = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM); if (strcmp (album_name, _("Unknown")) != 0) { remove_track_from_album (RB_MTP_SOURCE (source), album_name, track); } g_hash_table_remove (priv->entry_map, entry); rhythmdb_entry_delete (db, entry); } rhythmdb_commit (db); g_list_free (sel); g_list_free (tem); }
static gboolean run_task (RBMtpThread *thread, RBMtpThreadTask *task) { char *name = task_name (task); rb_debug ("running task: %s", name); g_free (name); switch (task->task) { case OPEN_DEVICE: open_device (thread, task); break; case CLOSE_DEVICE: return TRUE; case SET_DEVICE_NAME: if (LIBMTP_Set_Friendlyname (thread->device, task->name)) { rb_mtp_thread_report_errors (thread, TRUE); } break; case THREAD_CALLBACK: { RBMtpThreadCallback cb = (RBMtpThreadCallback)task->callback; cb (thread->device, task->user_data); } break; case ADD_TO_ALBUM: add_track_to_album_and_update (thread, task); break; case REMOVE_FROM_ALBUM: remove_track_from_album (thread, task); break; case SET_ALBUM_IMAGE: set_album_image (thread, task); break; case GET_TRACK_LIST: get_track_list (thread, task); break; case DELETE_TRACK: if (LIBMTP_Delete_Object (thread->device, task->track_id)) { rb_mtp_thread_report_errors (thread, TRUE); } break; case UPLOAD_TRACK: upload_track (thread, task); break; case DOWNLOAD_TRACK: download_track (thread, task); break; default: g_assert_not_reached (); } return FALSE; }