bool GPodDevice::CopyToStorage(const CopyJob& job) { Q_ASSERT(db_); Itdb_Track* track = AddTrackToITunesDb(job.metadata_); // Copy the file GError* error = nullptr; itdb_cp_track_to_ipod( track, QDir::toNativeSeparators(job.source_).toLocal8Bit().constData(), &error); if (error) { qLog(Error) << "copying failed:" << error->message; app_->AddError(QString::fromUtf8(error->message)); g_error_free(error); // Need to remove the track from the db again itdb_track_remove(track); return false; } AddTrackToModel(track, url_.path()); // Remove the original if it was requested if (job.remove_original_) { QFile::remove(job.source_); } return true; }
static void rb_ipod_db_remove_track_internal (RbIpodDb *ipod_db, Itdb_Track *track) { GList *it; for (it = track->itdb->playlists; it != NULL; it = it->next) { itdb_playlist_remove_track ((Itdb_Playlist *)it->data, track); } itdb_track_remove (track); rb_ipod_db_save_async (ipod_db); }
bool GPodDevice::RemoveTrackFromITunesDb(const QString& path, const QString& relative_to) { QString ipod_filename = path; if (!relative_to.isEmpty() && path.startsWith(relative_to)) ipod_filename.remove( 0, relative_to.length() + (relative_to.endsWith('/') ? -1 : 0)); ipod_filename.replace('/', ':'); // Find the track in the itdb, identify it by its filename Itdb_Track* track = nullptr; for (GList* tracks = db_->tracks; tracks != nullptr; tracks = tracks->next) { Itdb_Track* t = static_cast<Itdb_Track*>(tracks->data); if (t->ipod_path == ipod_filename) { track = t; break; } } if (track == nullptr) { qLog(Warning) << "Couldn't find song" << path << "in iTunesDB"; return false; } // Remove the track from all playlists for (GList* playlists = db_->playlists; playlists != nullptr; playlists = playlists->next) { Itdb_Playlist* playlist = static_cast<Itdb_Playlist*>(playlists->data); if (itdb_playlist_contains_track(playlist, track)) { itdb_playlist_remove_track(playlist, track); } } // Remove the track from the database, this frees the struct too itdb_track_remove(track); return true; }