Commit 68535eab authored by camilo higuita's avatar camilo higuita

more fixes along the way and now sources work flawlessly

parent ab7a2405
......@@ -916,22 +916,29 @@ QSqlQuery CollectionDB::getQuery(const QString &queryTxt)
bool CollectionDB::removeSource(const QString &url)
{
auto path = url.endsWith("/") ? url.chopped(1) : url;
auto queryTxt = QString("DELETE FROM %1 WHERE %2 LIKE \"%3%\"").arg(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::SOURCE], path);
const auto path = url.endsWith("/") ? url.chopped(1) : url;
auto queryTxt = QString("DELETE FROM %1 WHERE %2 LIKE \"%3%\"").arg(TABLEMAP[TABLE::TRACKS_PLAYLISTS],
FMH::MODEL_NAME[FMH::MODEL_KEY::URL], path);
qDebug() << queryTxt;
auto query = this->getQuery(queryTxt);
if(query.exec())
{
queryTxt = QString("DELETE FROM %1 WHERE %2 LIKE \"%3%\"").arg(TABLEMAP[TABLE::SOURCES],
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],path);
queryTxt = QString("DELETE FROM %1 WHERE %2 LIKE \"%3%\"").arg(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::SOURCE], path);
query.prepare(queryTxt);
if(query.exec())
{
this->removeFolder(path);
if(cleanAlbums()) cleanArtists();
return true;
queryTxt = QString("DELETE FROM %1 WHERE %2 LIKE \"%3%\"").arg(TABLEMAP[TABLE::SOURCES],
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],path);
query.prepare(queryTxt);
if(query.exec())
{
this->removeFolder(path);
if(cleanAlbums())
cleanArtists();
return true;
}
}
}
......
......@@ -125,7 +125,6 @@ void AlbumsModel::setList()
void AlbumsModel::fetchInformation()
{
qDebug() << "RNUNGING BRAIN EFFORRTS";
QFutureWatcher<void> *watcher = new QFutureWatcher<void>;
......@@ -200,8 +199,8 @@ void AlbumsModel::fetchInformation()
// });
QObject::connect(this, &AlbumsModel::destroyed, [&]()
{
// loop.quit();
stop = true;
loop.quit();
});
for(auto i = 0; i < requests.size(); i++)
......
......@@ -104,7 +104,7 @@ FMH::MODEL_LIST PlaylistsModel::defaultPlaylists()
},
{
{FMH::MODEL_KEY::PLAYLIST, "Favorites"},
{FMH::MODEL_KEY::PLAYLIST, "Rating"},
{FMH::MODEL_KEY::ICON, "view-media-favorite"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
......
......@@ -93,6 +93,14 @@ QVariantList vvave::sourceFolders()
return res;
}
bool vvave::removeSource(const QString &source)
{
if(!this->getSourceFolders().contains(source))
return false;
return this->db->removeSource(source);
}
QString vvave::moodColor(const int &index)
{
if(index < BAE::MoodColors.size() && index > -1)
......
......@@ -30,6 +30,7 @@ public slots:
///DB Interfaces
/// useful functions for non modeled views and actions with not direct access to a tracksmodel or its own model
QVariantList sourceFolders();
bool removeSource(const QString &source);
static QString moodColor(const int &index);
void scanDir(const QStringList &paths = BAE::defaultSources);
......
......@@ -4,69 +4,79 @@ import org.kde.mauikit 1.0 as Maui
import "../view_models/BabeTable"
import "../db/Queries.js" as Q
StackView
Item
{
id: stack
property alias list : filterList
property var tracks : []
property string currentFolder : ""
initialItem: Maui.Page
Maui.GridBrowser
{
id: browser
property alias list : _filterList
property var tracks : []
property string currentFolder : ""
// headBarTitle: qsTr("Source folders")
headBar.visible: false
headBarExit: false
margins: space.large
anchors.margins: space.big
anchors.fill: parent
showEmblem: false
Maui.GridBrowser
onItemClicked:
{
var item = browser.model.get(index)
_filterList.headBarTitle= item.label
currentFolder = item.path
filter()
_listDialog.open()
}
Maui.Holder
{
anchors.fill: parent
id: browser
showEmblem: false
onItemClicked:
visible: !browser.count
emoji: "qrc:/assets/MusicCloud.png"
isMask: false
title : "No Folders!"
body: "Add new music to your sources to browse by folders"
emojiSize: iconSizes.huge
}
Maui.Dialog
{
id: _listDialog
parent: parent
maxHeight: maxWidth
maxWidth: unit * 600
defaultButtons: false
page.margins: 0
BabeTable
{
stack.push(filterList)
var item = browser.model.get(index)
filterList.headBarTitle= item.label
currentFolder = item.path
filter()
id: _filterList
anchors.fill: parent
coverArtVisible: true
headBarExit: false
holder.emoji: "qrc:/assets/MusicCloud.png"
holder.isMask: false
holder.title : "No Tracks!"
holder.body: "This source folder seems to be empty!"
holder.emojiSize: iconSizes.huge
}
}
}
BabeTable
{
id: filterList
coverArtVisible: true
headBarExitIcon: "go-previous"
holder.emoji: "qrc:/assets/MusicCloud.png"
holder.isMask: false
holder.title : "No Tracks!"
holder.body: "This source folder seems to be empty!"
holder.emojiSize: iconSizes.huge
Component.onCompleted: populate()
onExit:
function populate()
{
stack.pop()
browser.model.clear()
var folders = vvave.sourceFolders();
if(folders.length > 0)
for(var i in folders)
browser.model.append(folders[i])
}
}
Component.onCompleted: populate()
function populate()
{
browser.model.clear()
var folders = vvave.sourceFolders();
if(folders.length > 0)
for(var i in folders)
browser.model.append(folders[i])
}
function filter()
{
var where = "source = \""+currentFolder+"\""
filterList.list.query = (Q.GET.tracksWhere_.arg(where))
function filter()
{
var where = "source = \""+currentFolder+"\""
_filterList.list.query = (Q.GET.tracksWhere_.arg(where))
}
}
}
This diff is collapsed.
......@@ -82,29 +82,29 @@ BabeList
{
case "Most Played":
playlistViewRoot.populate(Q.GET.mostPlayedTracks);
populate(Q.GET.mostPlayedTracks);
filterList.list.sortBy = Tracks.COUNT
break;
case "Favorites":
case "Rating":
filterList.list.sortBy = Tracks.RATE
filterList.group = true
playlistViewRoot.populate(Q.GET.favoriteTracks);
populate(Q.GET.favoriteTracks);
break;
case "Recent":
playlistViewRoot.populate(Q.GET.recentTracks);
populate(Q.GET.recentTracks);
filterList.list.sortBy = Tracks.ADDDATE
filterList.group = true
break;
case "Favs":
playlistViewRoot.populate(Q.GET.babedTracks);
populate(Q.GET.babedTracks);
break;
case "Online":
playlistViewRoot.populate(Q.GET.favoriteTracks);
populate(Q.GET.favoriteTracks);
break;
case "Tags":
......@@ -112,11 +112,11 @@ BabeList
break;
case "Relationships":
playlistViewRoot.populate(Q.GET.favoriteTracks);
populate(Q.GET.favoriteTracks);
break;
case "Popular":
playlistViewRoot.populate(Q.GET.favoriteTracks);
populate(Q.GET.favoriteTracks);
break;
case "Genres":
......@@ -124,10 +124,12 @@ BabeList
break;
default:
playlistViewRoot.populate(Q.GET.playlistTracks_.arg(playlist));
populate(Q.GET.playlistTracks_.arg(playlist));
break;
}
_filterDialog.open()
}
}
}
......
......@@ -3,6 +3,7 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import org.kde.mauikit 1.0 as Maui
import "../../view_models"
import "../../utils/Help.js" as H
Maui.Dialog
{
......@@ -11,7 +12,34 @@ Maui.Dialog
maxWidth: unit * 600
maxHeight: unit * 500
page.margins: 0
defaultButtons: false
defaultButtons: true
acceptButton.text: qsTr("Add")
rejectButton.text: qsTr("Remove")
onRejected:
{
var index = sources.currentIndex
var url = sources.model.get(index).url
pathToRemove = url
confirmationDialog.title = "Remove source"
confirmationDialog.message = "Are you sure you want to remove the source: \n "+url
confirmationDialog.open()
}
onAccepted:
{
fmDialog.onlyDirs = true
fmDialog.show(function(paths)
{
console.log("SCAN DIR <<", paths)
for(var i in paths)
listModel.append({url: paths[i]})
vvave.scanDir([paths])
})
getSources()
}
Maui.Dialog
{
......@@ -19,17 +47,30 @@ Maui.Dialog
onAccepted:
{
if(pathToRemove.length>0)
if(bae.removeSource(pathToRemove))
bae.refreshCollection()
if(vvave.removeSource(pathToRemove))
H.refreshCollection()
getSources()
confirmationDialog.close()
}
onRejected: confirmationDialog.close()
}
Maui.Holder
{
anchors.fill: parent
visible: !sources.count
emoji: "qrc:/assets/MusicCloud.png"
isMask: false
title : "No Sources!"
body: "Add new sources to organize and play your music collection"
emojiSize: iconSizes.huge
}
BabeList
{
id: sources
anchors.fill: parent
headBar.visible: true
headBar.visible: false
headBarExit: false
headBarTitle: qsTr("Sources")
Layout.fillWidth: true
......@@ -53,55 +94,6 @@ Maui.Dialog
onClicked: sources.currentIndex = index
}
}
headBar.rightContent: [
Maui.ToolButton
{
iconName: "list-remove"
onClicked:
{
close()
var index = sources.currentIndex
var url = sources.list.model.get(index).url
confirmationDialog.title = "Remove source"
if(bae.defaultSources().indexOf(url)<0)
{
pathToRemove = url
confirmationDialog.message = "Are you sure you want to remove the source: \n "+url
}
else
{
pathToRemove = ""
confirmationDialog.message = url+"\nis a default source and cannot be removed"
}
confirmationDialog.open()
}
},
Maui.ToolButton
{
iconName: "list-add"
onClicked:
{
close()
fmDialog.onlyDirs = true
fmDialog.show(function(paths)
{
console.log("SCAN DIR <<", paths)
for(var i in paths)
listModel.append({url: paths[i]})
vvave.scanDir([paths])
close()
})
}
}
]
}
onOpened: getSources()
......
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