mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-03 12:47:31 +01:00
Support removing files from ipods
This commit is contained in:
parent
1dbb1817e8
commit
1d25ee78ed
@ -150,6 +150,19 @@ void AfcDevice::FinaliseDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
bool AfcDevice::DeleteFromStorage(const Song &metadata) {
|
||||
return false;
|
||||
bool AfcDevice::DeleteFromStorage(const Song& metadata) {
|
||||
const QString path = QUrl(metadata.filename()).path();
|
||||
|
||||
if (!RemoveTrackFromITunesDb(path))
|
||||
return false;
|
||||
|
||||
// Remove the file
|
||||
iMobileDeviceConnection connection(url_.host());
|
||||
if (afc_remove_path(connection.afc(), path.toUtf8().constData()) != AFC_E_SUCCESS)
|
||||
return false;
|
||||
|
||||
// Remove it from our library model
|
||||
songs_to_remove_ << metadata;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -163,23 +163,27 @@ void GPodDevice::StartDelete() {
|
||||
StartCopy();
|
||||
}
|
||||
|
||||
bool GPodDevice::DeleteFromStorage(const Song& metadata) {
|
||||
Q_ASSERT(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 = NULL;
|
||||
for (GList* tracks = db_->tracks ; tracks != NULL ; tracks = tracks->next) {
|
||||
Itdb_Track* t = static_cast<Itdb_Track*>(tracks->data);
|
||||
|
||||
itdb_filename_ipod2fs(t->ipod_path);
|
||||
if (url_.path() + t->ipod_path == metadata.filename()) {
|
||||
qDebug() << ipod_filename << t->ipod_path;
|
||||
if (t->ipod_path == ipod_filename) {
|
||||
track = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (track == NULL) {
|
||||
qWarning() << "Couldn't find song" << metadata.filename() << "in iTunesDB";
|
||||
qWarning() << "Couldn't find song" << path << "in iTunesDB";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -195,8 +199,18 @@ bool GPodDevice::DeleteFromStorage(const Song& metadata) {
|
||||
// Remove the track from the database, this frees the struct too
|
||||
itdb_track_remove(track);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GPodDevice::DeleteFromStorage(const Song& metadata) {
|
||||
Q_ASSERT(db_);
|
||||
|
||||
if (!RemoveTrackFromITunesDb(metadata.filename(), url_.path()))
|
||||
return false;
|
||||
|
||||
// Remove the file
|
||||
QFile::remove(metadata.filename());
|
||||
if (!QFile::remove(metadata.filename()))
|
||||
return false;
|
||||
|
||||
// Remove it from our library model
|
||||
songs_to_remove_ << metadata;
|
||||
|
@ -56,6 +56,8 @@ protected slots:
|
||||
protected:
|
||||
Itdb_Track* AddTrackToITunesDb(const Song& metadata);
|
||||
void AddTrackToModel(Itdb_Track* track, const QString& prefix);
|
||||
bool RemoveTrackFromITunesDb(const QString& path,
|
||||
const QString& relative_to = QString());
|
||||
virtual void FinaliseDatabase() {}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user