Commit e240bced authored by camilo higuita's avatar camilo higuita

reworking the playlists

parent c24335b7
......@@ -873,8 +873,10 @@ FMH::MODEL_LIST CollectionDB::getPlaylists()
FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE],
TABLEMAP[TABLE::PLAYLISTS]);
return this->getDBData(queryTxt);
return this->getDBData(queryTxt, [](FMH::MODEL &item)
{
item[FMH::MODEL_KEY::TYPE] = "public";
});
}
bool CollectionDB::removeTrack(const QString &path)
......
......@@ -697,13 +697,15 @@ Maui.ApplicationWindow
onAppendTrack: Player.addTrack(track)
onPlayTrack: Player.quickPlay(track)
onAppendAll: Player.appendAll(playlistsView.listModel.getAll())
onPlayAll:
onSyncAndPlay:
{
Player.playAll(playlistsView.listModel.getAll())
root.sync = true
root.syncPlaylist = playlist
}
onPlayAll: Player.playAll(playlistsView.listModel.getAll())
}
}
}
......
......@@ -40,32 +40,32 @@ void PlaylistsModel::sortList()
switch(role)
{
case FMH::MODEL_KEY::ADDDATE:
{
auto currentTime = QDateTime::currentDateTime();
case FMH::MODEL_KEY::ADDDATE:
{
auto currentTime = QDateTime::currentDateTime();
auto date1 = QDateTime::fromString(e1[role], Qt::TextDate);
auto date2 = QDateTime::fromString(e2[role], Qt::TextDate);
auto date1 = QDateTime::fromString(e1[role], Qt::TextDate);
auto date2 = QDateTime::fromString(e2[role], Qt::TextDate);
if(date1.secsTo(currentTime) < date2.secsTo(currentTime))
return true;
if(date1.secsTo(currentTime) < date2.secsTo(currentTime))
return true;
break;
}
break;
}
case FMH::MODEL_KEY::TITLE:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
case FMH::MODEL_KEY::TITLE:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
if(str1 < str2)
return true;
break;
}
if(str1 < str2)
return true;
break;
}
default:
if(e1[role] < e2[role])
return true;
default:
if(e1[role] < e2[role])
return true;
}
return false;
......@@ -74,14 +74,8 @@ void PlaylistsModel::sortList()
void PlaylistsModel::setList()
{
qDebug()<< "trying to set playlists list";
emit this->preListChanged();
this->list << this->db->getPlaylists();
this->list << this->defaultPlaylists();
qDebug()<< this->list;
// this->sortList();
emit this->postListChanged();
}
......@@ -91,68 +85,86 @@ FMH::MODEL PlaylistsModel::packPlaylist(const QString &playlist)
return FMH::MODEL
{
{FMH::MODEL_KEY::PLAYLIST, playlist},
{FMH::MODEL_KEY::TYPE, "public"},
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// {FMH::MODEL_KEY::ICON, "view-media-playlist"}
};
}
FMH::MODEL_LIST PlaylistsModel::defaultPlaylists()
QVariantList PlaylistsModel::defaultPlaylists()
{
return FMH::MODEL_LIST {
{
{FMH::MODEL_KEY::PLAYLIST, "Most Played"},
{FMH::MODEL_KEY::ICON, "view-media-playcount"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
const auto model = FMH::MODEL_LIST {
{
{FMH::MODEL_KEY::TYPE, "default"},
{FMH::MODEL_KEY::DESCRIPTION, "Favorite tracks"},
{FMH::MODEL_KEY::COLOR, "#EC407A"},
{FMH::MODEL_KEY::PLAYLIST, "Favs"},
{FMH::MODEL_KEY::ICON, "love"},
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Rating"},
{FMH::MODEL_KEY::ICON, "view-media-favorite"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::TYPE, "default"},
{FMH::MODEL_KEY::DESCRIPTION, "Top listened tracks"},
{FMH::MODEL_KEY::COLOR, "#FFA000"},
{FMH::MODEL_KEY::PLAYLIST, "Most Played"},
{FMH::MODEL_KEY::ICON, "view-media-playcount"},
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Recent"},
{FMH::MODEL_KEY::ICON, "view-media-recent"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::TYPE, "default"},
{FMH::MODEL_KEY::DESCRIPTION, "Highest rated tracks"},
{FMH::MODEL_KEY::COLOR, "#42A5F5"},
{FMH::MODEL_KEY::PLAYLIST, "Rating"},
{FMH::MODEL_KEY::ICON, "view-media-favorite"},
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Favs"},
{FMH::MODEL_KEY::ICON, "love"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
// {
// {FMH::MODEL_KEY::TYPE, "default"},
// {FMH::MODEL_KEY::PLAYLIST, "Recent"},
// {FMH::MODEL_KEY::ICON, "view-media-recent"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
{
{FMH::MODEL_KEY::PLAYLIST, "Online"},
{FMH::MODEL_KEY::ICON, "internet-services"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
// {
// {FMH::MODEL_KEY::PLAYLIST, "Tags"},
// {FMH::MODEL_KEY::ICON, "tag"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Relationships"},
// {FMH::MODEL_KEY::ICON, "view-media-similarartists"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Popular"},
// {FMH::MODEL_KEY::ICON, "view-media-chart"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Genres"},
// {FMH::MODEL_KEY::ICON, "view-media-genre"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// }
};
{
{FMH::MODEL_KEY::TYPE, "default"},
{FMH::MODEL_KEY::COLOR, "#26A69A"},
{FMH::MODEL_KEY::DESCRIPTION, "Online tracks"},
{FMH::MODEL_KEY::PLAYLIST, "YouTube"},
{FMH::MODEL_KEY::ICON, "internet-services"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
// {
// {FMH::MODEL_KEY::PLAYLIST, "Tags"},
// {FMH::MODEL_KEY::ICON, "tag"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Relationships"},
// {FMH::MODEL_KEY::ICON, "view-media-similarartists"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Popular"},
// {FMH::MODEL_KEY::ICON, "view-media-chart"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Genres"},
// {FMH::MODEL_KEY::ICON, "view-media-genre"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// }
};
return FMH::toMapList(model);
}
QVariantMap PlaylistsModel::get(const int &index) const
......@@ -168,13 +180,7 @@ void PlaylistsModel::append(const QVariantMap &item)
return;
emit this->preItemAppended();
FMH::MODEL model;
for(auto key : item.keys())
model.insert(FMH::MODEL_NAME_KEY[key], item[key].toString());
this->list << model;
this->list << FMH::toModel(item);
emit this->postItemAppended();
}
......@@ -186,16 +192,8 @@ void PlaylistsModel::append(const QVariantMap &item, const int &at)
if(at > this->list.size() || at < 0)
return;
qDebug()<< "trying to append at" << at << item["title"];
emit this->preItemAppendedAt(at);
FMH::MODEL model;
for(auto key : item.keys())
model.insert(FMH::MODEL_NAME_KEY[key], item[key].toString());
this->list.insert(at, model);
this->list.insert(at, FMH::toModel(item));
emit this->postItemAppended();
}
......@@ -206,8 +204,8 @@ void PlaylistsModel::insert(const QString &playlist)
emit this->preItemAppended();
this->list << this->packPlaylist(playlist);
if(this->db->addPlaylist(playlist))
this->list << (this->packPlaylist(playlist));
emit this->postItemAppended();
}
......
......@@ -19,7 +19,8 @@ public:
enum SORTBY : uint_fast8_t
{
ADDDATE = FMH::MODEL_KEY::ADDDATE,
TITLE = FMH::MODEL_KEY::TITLE
TITLE = FMH::MODEL_KEY::TITLE,
TYPE = FMH::MODEL_KEY::TYPE
}; Q_ENUM(SORTBY)
explicit PlaylistsModel(QObject *parent = nullptr);
......@@ -36,15 +37,14 @@ private:
void setList();
FMH::MODEL packPlaylist(const QString &playlist);
FMH::MODEL_LIST defaultPlaylists();
PlaylistsModel::SORTBY sort = PlaylistsModel::SORTBY::ADDDATE;
signals:
void sortByChanged();
public slots:
QVariantList defaultPlaylists();
QVariantMap get(const int &index) const;
void append(const QVariantMap &item);
void append(const QVariantMap &item, const int &at);
......
......@@ -29,6 +29,7 @@ Maui.Page
holder.visible: count === 0
topMargin: Maui.Style.space.medium
listView.headerPositioning: ListView.PullBackHeader
listView.footerPositioning: ListView.OverlayFooter
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
}
......
......@@ -3,6 +3,7 @@ import QtQuick.Controls 2.10
import org.kde.kirigami 2.2 as Kirigami
import org.kde.mauikit 1.0 as Maui
import QtQuick.Layouts 1.3
import PlaylistsList 1.0
import "../../view_models"
import "../../utils/Player.js" as Player
......@@ -54,7 +55,6 @@ Maui.Dialog
}
}
Maui.TextField
{
Layout.fillWidth: true
......@@ -96,14 +96,13 @@ Maui.Dialog
if (newPlaylistField.text)
{
var title = newPlaylistField.text.trim()
if(playlistsList.insertAt(title, 0))
if(playlistsList.insert(title))
{
dialogList.listView.currentIndex = 0
dialogList.listView.positionViewAtBeginning()
dialogList.currentIndex = 2
dialogList.listView.positionViewAtEnd()
}
newPlaylistField.clear()
}
}
}
......@@ -97,15 +97,17 @@ Maui.ItemDelegate
iconVisible: !control.sameAlbum && control.coverArt
imageSource: model.artwork ? model.artwork : "qrc:/assets/cover.png"
}
ToolButton
{
Layout.fillHeight: true
Layout.preferredWidth: implicitWidth
visible: showQuickActions && (Kirigami.Settings.isMobile ? true : control.hovered)
icon.name: "media-playlist-append"
onClicked: control.append()
ToolButton
{
Layout.fillHeight: true
Layout.preferredWidth: implicitWidth
visible: showQuickActions && (Kirigami.Settings.isMobile ? true : control.hovered)
icon.name: "media-playlist-append"
onClicked: control.append()
}
}
}
}
......@@ -5,111 +5,39 @@ import org.kde.mauikit 1.0 as Maui
Item
{
property int recSize: Maui.Style.iconSizes.small
property int recSize: Maui.Style.iconSizes.medium
readonly property int recRadius : recSize*0.05
signal colorClicked(string color)
RowLayout
{
width: parent.width
anchors.fill: parent
anchors.centerIn: parent
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
flat: true
Rectangle
{
anchors.centerIn: parent
width: recSize
height: recSize
color: vvave.moodColor(0)
radius: recRadius
border.color: color
border.width: 1
}
spacing: Maui.Style.space.small
onClicked: colorClicked(vvave.moodColor(0))
}
ToolButton
Repeater
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
model: vvave.moodColors()
flat: true
Rectangle
{
anchors.centerIn: parent
width: recSize
height: recSize
color: vvave.moodColor(1)
radius: recRadius
border.color: color
border.width: 1
}
onClicked: colorClicked(vvave.moodColor(1))
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
flat: true
Rectangle
MouseArea
{
anchors.centerIn: parent
width: recSize
height: recSize
color: vvave.moodColor(2)
radius: recRadius
border.color: color
border.width: 1
Layout.fillWidth: true
Layout.fillHeight: true
onClicked: colorClicked(modelData)
propagateComposedEvents: false
Rectangle
{
color: modelData
anchors.verticalCenter: parent.verticalCenter
height: recSize
width: height
radius: Maui.Style.radiusV
border.color: Qt.darker(color, 1.7)
anchors.centerIn: parent
}
}
onClicked: colorClicked(vvave.moodColor(2))
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
flat: true
Rectangle
{
anchors.centerIn: parent
width: recSize
height: recSize
color: vvave.moodColor(3)
radius: recRadius
border.color: color
border.width: 1
}
onClicked: colorClicked(vvave.moodColor(3))
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
flat: true
Rectangle
{
anchors.centerIn: parent
width: recSize
height: recSize
color: vvave.moodColor(4)
radius: recRadius
border.color: color
border.width: 1
}
onClicked: colorClicked(vvave.moodColor(4))
}
}
}
......@@ -95,6 +95,11 @@ QString vvave::moodColor(const int &index)
else return "";
}
QStringList vvave::moodColors()
{
return BAE::MoodColors;
}
void vvave::scanDir(const QStringList &paths)
{
this->checkCollection(paths, [=](uint size) {emit this->refreshTables(size);});
......
......@@ -31,6 +31,7 @@ public slots:
QVariantList sourceFolders();
bool removeSource(const QString &source);
static QString moodColor(const int &index);
static QStringList moodColors();
void scanDir(const QStringList &paths = BAE::defaultSources);
QStringList getSourceFolders();
......
......@@ -61,32 +61,59 @@ Maui.Page
onRowClicked: play(index)
showQuickActions: false
listView.footer: Maui.ToolBar
listView.header: Maui.ToolBar
{
Kirigami.Theme.inherit: false
z: table.z + 999
z: table.z +999
width: table.width
visible: table.list.count > 0
rightContent: ToolButton
{
icon.name: "edit-clear"
onClicked: mainPlaylist.table.list.clear()
}
leftContent: Label
leftContent: ToolButton
{
text: root.syncPlaylist
icon.name: "document-save"
onClicked: mainPlaylist.table.saveList()
}
}
rightContent: [
ToolButton
listView.footer: Rectangle
{
visible: root.sync
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet:Kirigami.Theme.Complementary
z: table.z + 999
width: table.width
height: Maui.Style.rowHeightAlt
color: Kirigami.Theme.backgroundColor
RowLayout
{
anchors.fill: parent
anchors.leftMargin: Maui.Style.space.small
Label
{
icon.name: "edit-clear"
onClicked: mainPlaylist.table.list.clear()
},
Layout.fillWidth: true
Layout.fillHeight: true
anchors.margins: Maui.Style.space.small
text: qsTr("Syncing to ") + root.syncPlaylist
}
ToolButton
{
Layout.fillHeight: true
icon.name: "dialog-close"
onClicked:
{
icon.name: "document-save"
onClicked: mainPlaylist.table.saveList()
root.sync = false
root.syncPlaylist = ""
}
}
]
}
}
onArtworkDoubleClicked: contextMenu.babeIt(index)
......
......@@ -3,17 +3,19 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls 2.10
import org.kde.kirigami 2.7 as Kirigami
import org.kde.mauikit 1.0 as Maui
import TracksList 1.0
import "../../view_models/BabeTable"
import "../../view_models"
import "../../db/Queries.js" as Q
import "../../utils/Help.js" as H
ColumnLayout
Maui.Page
{
id: control
spacing: 0
spacing: Maui.Style.space.medium
property string currentPlaylist
property string playlistQuery
property alias playlistModel : playlistViewModel.model
property alias playlistViewList : playlistViewModel
......@@ -22,61 +24,41 @@ ColumnLayout
signal rowClicked(var track)
signal quickPlayTrack(var track)
signal playAll(string playlist)
signal playSync(var playlist)
signal playAll()
signal syncAndPlay(string playlist)
signal appendAll()
SwipeView
{
id: playlistSwipe
Layout.fillHeight: true
Layout.fillWidth: true
interactive: false
clip: true
footBar.rightContent: [
PlaylistsViewModel
ToolButton
{
id: playlistViewModel
// onPlaySync: syncAndPlay(index)
id : createPlaylistBtn
// text: qsTr("Add")
icon.name : "list-add"
onClicked: newPlaylistDialog.open()
}
]
BabeList
{
id: playlistViewModelFilter
// headBarExitIcon: "go-previous"
headBar.leftContent: ToolButton
{
icon.name: "go-previous"
onClicked: playlistSwipe.currentIndex = 0
}
model : ListModel {}
delegate: Maui.LabelDelegate
{
id: delegate
label : tag
Connections
{
target: delegate
onClicked: {}
}
}
}
PlaylistsViewModel
{
id: playlistViewModel
anchors.fill: parent
}
ColorTagsBar
Maui.NewDialog
{
Layout.fillWidth: true
height: Maui.Style.rowHeightAlt
recSize: Kirigami.Settings.isMobile ? Maui.Style.iconSizes.medium : Maui.Style.iconSizes.small
onColorClicked: populate(Q.GET.colorTracks_.arg(color.toLowerCase()))
id: newPlaylistDialog
title: qsTr("New Playlist...")
onFinished: addPlaylist(text)
acceptText: qsTr("Create")
rejectButton.visible: false
}
Maui.Dialog
{
id: _filterDialog
property bool isPublic: true
parent: parent
maxHeight: maxWidth
maxWidth: Maui.Style.unit * 600
......@@ -90,18 +72,17 @@ ColumnLayout
clip: true
coverArtVisible: true
headBar.visible: !holder.visible
title: playlistsList.get(playlistViewModel.currentIndex).playlist
title: control.currentPlaylist
holder.emoji: "qrc:/assets/dialog-information.svg"