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))
}
}
}
......@@ -11,9 +11,13 @@ import "../../db/Queries.js" as Q
import "../../utils/Help.js" as H
Kirigami.PageRow
ColumnLayout
{
id: playlistViewRoot
id: control
clip: true
spacing: 0
property string playlistQuery
property alias playlistModel : playlistViewModel.model
......@@ -26,172 +30,162 @@ Kirigami.PageRow
signal playSync(var playlist)
signal appendAll()
clip: true
separatorVisible: wideMode
initialPage: [playlistLayout, filterList]
defaultColumnWidth: Kirigami.Units.gridUnit * 15
ColumnLayout
SwipeView
{
id: playlistLayout
id: playlistSwipe
Layout.fillHeight: true
Layout.fillWidth: true
interactive: false
clip: true
spacing: 0
Layout.margins: 0
SwipeView
PlaylistsViewModel
{
id: playlistSwipe
id: playlistViewModel
onPlaySync: syncAndPlay(index)
}
Layout.fillHeight: true
Layout.fillWidth: true
BabeList
{
id: playlistViewModelFilter
interactive: false
clip: true
headBarExitIcon: "go-previous"
PlaylistsViewModel
model : ListModel {}
delegate: Maui.LabelDelegate
{
id: playlistViewModel
onPlaySync: syncAndPlay(index)
}
BabeList
{
id: playlistViewModelFilter
headBarExitIcon: "go-previous"
model : ListModel {}
delegate: Maui.LabelDelegate
id: delegate
label : tag
Connections
{
id: delegate
label : tag
Connections
{
target: delegate
onClicked: {}
}
}
target: delegate
onExit: playlistSwipe.currentIndex = 0
onClicked: {}
}
}
onExit: playlistSwipe.currentIndex = 0
}
ColorTagsBar
{
Layout.fillWidth: true
height: rowHeightAlt
recSize: isMobile ? iconSize : 16
onColorClicked:
{
populate(Q.GET.colorTracks_.arg(color))
if(!playlistViewRoot.wideMode)
playlistViewRoot.currentIndex = 1
}
}
}
BabeTable
ColorTagsBar
{
id: filterList
clip: true
quickPlayVisible: true
coverArtVisible: true
trackRating: true
trackDuration: false
headBar.visible: !holder.visible
headBarExitIcon: "go-previous"
headBarExit: !playlistViewRoot.wideMode
headBarTitle: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist
onExit: if(!playlistViewRoot.wideMode)
playlistViewRoot.currentIndex = 0
holder.emoji: "qrc:/assets/Electricity.png"
holder.isMask: false
holder.title : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
holder.body: "Your playlist is empty,<br>start adding new music to it"
holder.emojiSize: iconSizes.huge
contextMenuItems:
Maui.MenuItem
{
text: qsTr("Remove from playlist")
}
Layout.fillWidth: true
height: rowHeightAlt
recSize: isMobile ? iconSize : 16
onColorClicked: populate(Q.GET.colorTracks_.arg(color))
}
// headerMenu.menuItem: [
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Sync tags"
// onTriggered: {}
// },
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Play-n-Sync"
// onTriggered:
// {
// filterList.headerMenu.close()
// syncAndPlay(playlistViewModel.currentIndex)
// }
// },
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Remove playlist"
// onTriggered: removePlaylist()
// }
// ]
// contextMenu.menuItem: [
// MenuItem
// {
// text: qsTr("Remove from playlist")
// onTriggered:
// {
// bae.removePlaylistTrack(filterList.model.get(filterList.currentIndex).url, playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
// populate(playlistQuery)
// }
// }
// ]
section.criteria: ViewSection.FullString
section.delegate: Maui.LabelDelegate
Maui.Dialog
{
id: _filterDialog
parent: parent
maxHeight: maxWidth
maxWidth: unit * 600
defaultButtons: false
page.margins: 0
BabeTable
{
label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
isSection: true
boldLabel: true
labelTxt.font.family: "Material Design Icons"
id: filterList
anchors.fill: parent
clip: true
quickPlayVisible: true
coverArtVisible: true
trackRating: true
trackDuration: false
headBar.visible: !holder.visible
headBarExit: false
headBarTitle: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist
holder.emoji: "qrc:/assets/Electricity.png"
holder.isMask: false
holder.title : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
holder.body: "Your playlist is empty,<br>start adding new music to it"
holder.emojiSize: iconSizes.huge
contextMenuItems:
Maui.MenuItem
{
text: qsTr("Remove from playlist")
}
}
Connections
{
target: filterList
onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
onQuickPlayTrack:
// headerMenu.menuItem: [
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Sync tags"
// onTriggered: {}
// },
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Play-n-Sync"
// onTriggered:
// {
// filterList.headerMenu.close()
// syncAndPlay(playlistViewModel.currentIndex)
// }
// },
// Maui.MenuItem
// {
// enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
// text: "Remove playlist"
// onTriggered: removePlaylist()
// }
// ]
// contextMenu.menuItem: [
// MenuItem
// {
// text: qsTr("Remove from playlist")
// onTriggered:
// {
// bae.removePlaylistTrack(filterList.model.get(filterList.currentIndex).url, playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
// populate(playlistQuery)
// }
// }
// ]
section.criteria: ViewSection.FullString
section.delegate: Maui.LabelDelegate
{
playlistViewRoot.quickPlayTrack(filterList.model.get(filterList.currentIndex))
label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
isSection: true
boldLabel: true
labelTxt.font.family: "Material Design Icons"
}
onPlayAll: playAll()
onAppendAll: appendAll()
onPulled: populate(playlistQuery)
}
Connections
{
target: filterList.contextMenu
Connections
{
target: filterList
onRowClicked: control.rowClicked(filterList.model.get(index))
onQuickPlayTrack: control.quickPlayTrack(filterList.model.get(filterList.currentIndex))
onRemoveClicked:
onPlayAll: playAll()
onAppendAll: appendAll()
onPulled: populate(playlistQuery)
}
Connections
{
playlistList.removeTrack(playlistViewList.currentIndex, filterList.list.get(filterList.currentIndex).url)
populate(playlistQuery)
target: filterList.contextMenu
onRemoveClicked:
{
playlistList.removeTrack(playlistViewList.currentIndex, filterList.list.get(filterList.currentIndex).url)
populate(playlistQuery)
}
}
}
}
......@@ -216,21 +210,15 @@ Kirigami.PageRow
function populate(query)
{
if(!playlistViewRoot.wideMode)
playlistViewRoot.currentIndex = 1
playlistViewRoot.playlistQuery = query
filterList.list.query = playlistViewRoot.playlistQuery
}
function refresh()
{
playlistQuery = query
filterList.list.query = playlistQuery
}
function syncAndPlay(index)
{
if(!playlistList.get(index).playlistIcon)
playlistViewRoot.playSync(playlistList.get(index).playlist)
playSync(playlistList.get(index).playlist)
}
function removePlaylist()
......
......@@ -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