Commit bb706240 authored by camilo higuita's avatar camilo higuita
Browse files

deal with missing files. remove them and notify

parent 8ca9faab
......@@ -110,15 +110,18 @@ Maui.ApplicationWindow
model: mainPlaylist.listModel.list
onCurrentTrackChanged: Player.playTrack()
onMissingFile:
{
var message = i18n("Missing file")
var messageBody = track.title + " by " + track.artist + " is missing.\nDo you want to remove it from your collection?"
notify("dialog-question", message, messageBody, function ()
{
mainPlaylist.listModel.list.remove(mainPlaylist.table.currentIndex)
})
}
// onMissingFile:
// {
// var message = i18n("Missing file")
// var messageBody = track.title + " by " + track.artist + " is missing.\nDo you want to remove it from your collection?"
// notify("dialog-question", message, messageBody, function ()
// {
// console.log("REMOVE TIU MSISING")
// mainPlaylist.table.list.remove(mainPlaylist.table.currentIndex)
// console.log("REMOVE TIU MSISING 2")
// })
// }
}
Player
......
......@@ -54,6 +54,7 @@ void TracksModel::setList()
emit this->preListChanged();
this->list.clear();
QStringList missingFiles;
qDebug() << "GETTIN TRACK LIST" << this->query;
if (this->query.startsWith("#")) {
......@@ -66,22 +67,30 @@ void TracksModel::setList()
}
} else {
// const auto checker = [&](FMH::MODEL &item) {
// const auto url = QUrl(item[FMH::MODEL_KEY::URL]);
// if(FMH::fileExists(url))
// {
// return true;
// } else
// {
// this->db->removeTrack(url.toString());
// return false;
// }
// };
this->list = this->db->getDBData(this->query /*, checker*/);
const auto checker = [&](FMH::MODEL &item) {
const auto url = QUrl(item[FMH::MODEL_KEY::URL]);
if(FMH::fileExists(url))
{
return true;
} else
{
missingFiles << url.toString();
return false;
}
};
this->list = this->db->getDBData(this->query ,checker);
}
qDebug() << "missing files" << missingFiles;
emit this->postListChanged();
emit this->countChanged();
if(missingFiles.size() > 0)
{
this->removeMissingFiles(missingFiles);
emit this->missingFiles(missingFiles);
}
}
void TracksModel::copy(const TracksModel *model)
......@@ -174,11 +183,16 @@ bool TracksModel::countUp(const int &index)
bool TracksModel::remove(const int &index)
{
qDebug() << "REMOVE AT" << index;
if (index >= this->list.size() || index < 0)
return false;
const auto index_ = this->mappedIndex(index);
qDebug() << "REMOVE AT" << index << index_;
emit this->preItemRemoved(index_);
this->list.removeAt(index_);
emit this->postItemRemoved();
......@@ -186,6 +200,14 @@ bool TracksModel::remove(const int &index)
return true;
}
void TracksModel::removeMissingFiles(const QStringList &urls)
{
for(const auto &url : urls)
{
this->db->removeTrack(url);
}
}
void TracksModel::refresh()
{
this->setList();
......
......@@ -37,6 +37,7 @@ private:
signals:
void queryChanged();
void limitChanged(int limit);
void missingFiles(QStringList urls);
public slots:
void copy(const TracksModel *model);
......@@ -48,6 +49,9 @@ public slots:
bool fav(const int &index, const bool &value);
bool countUp(const int &index);
bool remove(const int &index);
void removeMissingFiles(const QStringList &urls);
void refresh();
bool update(const QVariantMap &data, const int &index);
......
......@@ -248,13 +248,19 @@ Maui.Page
}
}
model: Maui.BaseModel
{
id: _listModel
list: Tracks {id: _tracksList}
// sort: "title"
// sortOrder: Qt.AscendingOrder
list: Tracks
{
id: _tracksList
onMissingFiles:
{
var message = i18n("%1 Missing files", urls.length)
var messageBody = "Missing files have been removed from the collection."
notify("dialog-question", message, messageBody)
}
}
recursiveFilteringEnabled: true
sortCaseSensitivity: Qt.CaseInsensitive
filterCaseSensitivity: Qt.CaseInsensitive
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment