Commit 815ea525 authored by Camilo higuita's avatar Camilo higuita

more work on the new modeling

parent 2d7c74f3
......@@ -612,8 +612,11 @@ QVariantList Babe::transformData(const FMH::MODEL_LIST &dbList)
{
QVariantList res;
// for(auto data : dbList)
// res << FM::toMap(data);
// for(FMH::MODEL data : dbList)
// {
// FMH::MODEL copy = data;
// res << FM::toMap(copy);
// }
return res;
}
......
......@@ -13,10 +13,10 @@ var GET = {
tracksWhere_ : "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where %1",
// sourceTracks_: "select * from tracks where sources_url = \"%1\"",
mostPlayedTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist WHERE t.played > 0 ORDER BY played desc LIMIT 100",
favoriteTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where stars > 0 order by stars desc limit 100",
mostPlayedTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist WHERE t.count > 0 ORDER BY count desc LIMIT 100",
favoriteTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where rate > 0 order by rate desc limit 100",
recentTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist order by strftime(\"%s\", t.addDate) desc LIMIT 100",
babedTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where t.babe = 1",
babedTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where t.fav = 1",
playlistTracks_ : "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist inner join tracks_playlists pl on pl.url = t.url where pl.playlist = \"%1\" order by strftime(\"%s\", pl.addDate) desc",
playlists: "select * from playlists order by strftime(\"%s\", addDate) desc",
......
......@@ -291,7 +291,7 @@ bool CollectionDB::addTrack(const FMH::MODEL &track)
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE], QDateTime::currentDateTime()},
{FMH::MODEL_NAME[FMH::MODEL_KEY::LYRICS],""},
{FMH::MODEL_NAME[FMH::MODEL_KEY::GENRE], genre},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ARTWORK], ""},
{FMH::MODEL_NAME[FMH::MODEL_KEY::COLOR], ""},
{FMH::MODEL_NAME[FMH::MODEL_KEY::WIKI], ""},
{FMH::MODEL_NAME[FMH::MODEL_KEY::COMMENT], ""}};
......@@ -339,7 +339,7 @@ bool CollectionDB::rateTrack(const QString &path, const int &value)
bool CollectionDB::colorTagTrack(const QString &path, const QString &value)
{
if(update(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::ARTWORK],
FMH::MODEL_NAME[FMH::MODEL_KEY::COLOR],
value,
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],
path)) return true;
......@@ -571,7 +571,7 @@ FMH::MODEL_LIST CollectionDB::getDBData(const QString &queryTxt)
{
FMH::MODEL data;
for(auto key : FMH::MODEL_NAME.keys())
if(query.record().indexOf(FMH::MODEL_NAME[key])>-1)
if(query.record().indexOf(FMH::MODEL_NAME[key]) > -1)
data.insert(key, query.value(FMH::MODEL_NAME[key]).toString());
mapList << data;
......@@ -790,12 +790,12 @@ FMH::MODEL_LIST CollectionDB::getMostPlayedTracks(const int &greaterThan, const
QString CollectionDB::trackColorTag(const QString &path)
{
QString color;
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(FMH::MODEL_NAME[FMH::MODEL_KEY::ARTWORK],
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(FMH::MODEL_NAME[FMH::MODEL_KEY::COLOR],
TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],path));
for(auto track : query)
color = track[FMH::MODEL_KEY::MOOD];
color = track[FMH::MODEL_KEY::COLOR];
return color;
}
......
......@@ -72,7 +72,7 @@ releasedate DATE ,
adddate DATE NOT NULL,
lyrics TEXT NOT NULL,
genre TEXT,
artwork TEXT,
color TEXT,
wiki TEXT NOT NULL,
PRIMARY KEY (url),
FOREIGN KEY(source) REFERENCES SOURCES(url),
......
......@@ -30,6 +30,11 @@
#include "services/web/youtube.h"
#include "services/web/Spotify/spotify.h"
#include "services/local/linking.h"
#include "models/tracks/tracksmodel.h"
#include "models/baselist.h"
#include "models/basemodel.h"
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
......@@ -96,6 +101,10 @@ int main(int argc, char *argv[])
context->setContextProperty("spotify", &spotify);
context->setContextProperty("link", &bae.link);
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterType<BaseModel>("BaseModel", 1, 0, "BaseModel");
qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
qmlRegisterUncreatableMetaObject(
LINK::staticMetaObject, // static meta object
"Link.Codes", // import statement (can be any string)
......
......@@ -941,10 +941,10 @@ Maui.ApplicationWindow
{
target: bae
onRefreshTables: H.refreshCollection(size)
onRefreshTracks: H.refreshTracks()
onRefreshAlbums: H.refreshAlbums()
onRefreshArtists: H.refreshArtists()
// onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
// onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
onTrackLyricsReady:
{
......
......@@ -2,7 +2,9 @@
TracksModel::TracksModel(QObject *parent) : BaseList(parent)
{
this->db = CollectionDB::getInstance();
connect(this, &TracksModel::sortByChanged, this, &TracksModel::sortList);
connect(this, &TracksModel::queryChanged, this, &TracksModel::setList);
}
FMH::MODEL_LIST TracksModel::items() const
......@@ -39,3 +41,97 @@ uint TracksModel::getSortBy() const
{
return this->sort;
}
void TracksModel::sortList()
{
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
qDebug()<< "SORTING LIST BY"<< this->sort;
qSort(this->list.begin(), this->list.end(), [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
{
auto role = key;
switch(role)
{
case FMH::MODEL_KEY::SIZE:
{
if(e1[role].toDouble() > e2[role].toDouble())
return true;
break;
}
case FMH::MODEL_KEY::DATE:
case FMH::MODEL_KEY::ADDDATE:
case FMH::MODEL_KEY::MODIFIED:
{
auto currentTime = QDateTime::currentDateTime();
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;
break;
}
case FMH::MODEL_KEY::TITLE:
case FMH::MODEL_KEY::PLACE:
case FMH::MODEL_KEY::FORMAT:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
if(str1 < str2)
return true;
break;
}
default:
if(e1[role] < e2[role])
return true;
}
return false;
});
}
void TracksModel::setList()
{
emit this->preListChanged();
this->list = this->db->getDBData(this->query);
qDebug()<< "my LIST" ;
// this->sortList();
emit this->postListChanged();
}
QVariantMap TracksModel::get(const int &index) const
{
if(index >= this->list.size() || index < 0)
return QVariantMap();
QVariantMap res;
const auto item = this->list.at(index);
for(auto key : item.keys())
res.insert(FMH::MODEL_NAME[key], item[key]);
return res;
}
bool TracksModel::color(const int &index, const QString &color)
{
if(index >= this->list.size() || index < 0)
return false;
auto item = this->list[index];
if(this->db->colorTagTrack(item[FMH::MODEL_KEY::URL], color))
{
item[FMH::MODEL_KEY::COLOR] = color;
emit this->updateModel(index, {FMH::MODEL_KEY::COLOR});
return true;
}
return false;
}
......@@ -37,6 +37,11 @@ private:
signals:
void queryChanged();
void sortByChanged();
public slots:
QVariantMap get(const int &index) const override;
bool color(const int &index, const QString &color);
};
#endif // TRACKSMODEL_H
var player, timer, timeSpent = [], display = document.getElementById('display');
//var player, timer, timeSpent = [], display = document.getElementById('display');
function onYouTubeIframeAPIReady() {
player = new YT.Player( 'player', {
events: { 'onStateChange': onPlayerStateChange }
});
}
//function onYouTubeIframeAPIReady() {
// player = new YT.Player( 'player', {
// events: { 'onStateChange': onPlayerStateChange }
// });
//}
function onPlayerStateChange(event) {
if(event.data === 1) { // Started playing
if(!timeSpent.length){
timeSpent = new Array( parseInt(player.getDuration()) );
}
timer = setInterval(record,100);
} else {
clearInterval(timer);
}
}
//function onPlayerStateChange(event) {
// if(event.data === 1) { // Started playing
// if(!timeSpent.length){
// timeSpent = new Array( parseInt(player.getDuration()) );
// }
// timer = setInterval(record,100);
// } else {
// clearInterval(timer);
// }
//}
function record(){
timeSpent[ parseInt(player.getCurrentTime()) ] = true;
showPercentage();
}
//function record(){
// timeSpent[ parseInt(player.getCurrentTime()) ] = true;
// showPercentage();
//}
function showPercentage(){
var percent = 0;
for(var i=0, l=timeSpent.length; i<l; i++){
if(timeSpent[i]) percent++;
}
percent = Math.round(percent / timeSpent.length * 100);
console.log(percent + "%");
}
//function showPercentage(){
// var percent = 0;
// for(var i=0, l=timeSpent.length; i<l; i++){
// if(timeSpent[i]) percent++;
// }
// percent = Math.round(percent / timeSpent.length * 100);
// console.log(percent + "%");
//}
......@@ -45,12 +45,12 @@ function setStars(stars)
function refreshCollection(size)
{
if(!isMobile && size>0) bae.notify("Collection updated", size+" new tracks added...")
// if(!isMobile && size>0) bae.notify("Collection updated", size+" new tracks added...")
refreshTracks()
refreshAlbums()
refreshArtists()
refreshFolders()
// refreshTracks()
// refreshAlbums()
// refreshArtists()
// refreshFolders()
}
function refreshFolders()
......
......@@ -8,7 +8,9 @@ import org.kde.mauikit 1.0 as Maui
Maui.Page
{
id: control
property alias list : babeList
property alias listView : babeList
property alias model : babeList.model
property alias delegate : babeList.delegate
property alias count : babeList.count
......@@ -64,7 +66,7 @@ Maui.Page
boundsBehavior: !isMobile? Flickable.StopAtBounds : Flickable.OvershootBounds
flickableDirection: Flickable.AutoFlickDirection
// snapMode: isMobile? ListView.SnapToItem : ListView.NoSnap
// snapMode: isMobile? ListView.SnapToItem : ListView.NoSnap
addDisplaced: Transition
{
......
......@@ -3,6 +3,10 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
import org.kde.mauikit 1.0 as Maui
import BaseModel 1.0
import TracksList 1.0
import "../../utils/Player.js" as Player
import "../../utils/Help.js" as H
import "../../db/Queries.js" as Q
......@@ -16,6 +20,9 @@ BabeList
focus: true
property alias list : _tracksList
property bool trackNumberVisible
property bool quickPlayVisible : true
property bool coverArtVisible : false
......@@ -100,7 +107,7 @@ BabeList
text: qsTr("Select...")
onTriggered:
{
H.addToSelection(list.model.get(list.currentIndex))
H.addToSelection(listView.model.get(listView.currentIndex))
contextMenu.close()
}
},
......@@ -121,7 +128,7 @@ BabeList
onFavClicked:
{
var value = H.faveIt(paths)
model.get(list.currentIndex).babe = value ? "1" : "0"
model.get(listView.currentIndex).fav = value ? "1" : "0"
}
onQueueClicked: H.queueIt(paths)
......@@ -134,31 +141,30 @@ BabeList
onRemoveClicked:
{
listModel.remove(list.currentIndex)
listModel.remove(listView.currentIndex)
}
onRateClicked:
{
var value = H.rateIt(paths, rate)
list.currentItem.rate(H.setStars(value))
list.model.get(list.currentIndex).stars = value
listView.currentItem.rate(H.setStars(value))
listView.model.get(listView.currentIndex).rate = value
}
onColorClicked:
{
if(paths.length > 1)
H.moodIt(paths, color)
else
list.color(listView.currentIndex, color);
list.currentItem.trackMood = color
list.model.get(list.currentIndex).art = color
listView.currentItem.trackMood = color
}
}
list.highlightFollowsCurrentItem: false
list.highlightMoveDuration: 0
list.highlight: Rectangle { }
ListModel { id: listModel }
model: listModel
listView.highlightFollowsCurrentItem: false
listView.highlightMoveDuration: 0
listView.highlight: Rectangle { }
section.property : sortBy
section.criteria: ViewSection.FullString
......@@ -169,12 +175,26 @@ BabeList
boldLabel: true
}
BaseModel
{
id: _tracksModel
list: _tracksList
}
Tracks
{
id: _tracksList
}
model: _tracksModel
// property alias animBabe: delegate.animBabe
delegate: TableDelegate
{
id: delegate
width: list.width
width: listView.width
number : trackNumberVisible ? true : false
quickPlay: quickPlayVisible
......@@ -193,7 +213,7 @@ BabeList
currentIndex = index
if(selectionMode)
{
H.addToSelection(list.model.get(list.currentIndex))
H.addToSelection(listView.model.get(listView.currentIndex))
return
}
......@@ -225,9 +245,9 @@ BabeList
function openItemMenu(index)
{
currentIndex = index
contextMenu.rate = bae.getTrackStars(model.get(currentIndex).url)
contextMenu.babe = bae.trackBabe(model.get(currentIndex).url)
contextMenu.show([model.get(currentIndex).url])
contextMenu.rate = list.get(currentIndex).rate
contextMenu.fav = list.get(currentIndex).fav
contextMenu.show([list.get(currentIndex).url])
rowPressed(index)
}
......@@ -262,7 +282,7 @@ BabeList
{
root.pageStack.currentIndex = 1
root.currentView = viewsIndex.albums
var item = list.model.get(list.currentIndex)
var item = listView.model.get(listView.currentIndex)
albumsView.populateTable(item.album, item.artist)
contextMenu.close()
}
......@@ -271,7 +291,7 @@ BabeList
{
root.pageStack.currentIndex = 1
root.currentView = viewsIndex.artists
var item = list.model.get(list.currentIndex)
var item = listView.model.get(listView.currentIndex)
artistsView.populateTable(undefined, item.artist)
contextMenu.close()
}
......
......@@ -36,7 +36,7 @@ SwipeDelegate
property bool trackDurationVisible : false
property bool trackRatingVisible: false
property bool playingIndicator: false
property string trackMood : art
property string trackMood : model.color
property bool remoteArtwork: false
......@@ -88,13 +88,12 @@ SwipeDelegate
iconName: "love"
anchors.verticalCenter: parent.verticalCenter
iconColor: babe === "1" ? babeColor : textColor
iconColor: model.fav === "1" ? babeColor : textColor
onClicked:
{
babe = babe === "1" ? "0" : "1"
bae.babeTrack(url, babe)
model.fav = model.fav === "1" ? "0" : "1"
bae.babeTrack(url, model.fav)
swipe.close()
}
}
......@@ -168,10 +167,10 @@ SwipeDelegate
sourceSize.width: parent.width
sourceSize.height: parent.height
source: typeof artwork === 'undefined' ?
source: typeof model.artwork === 'undefined' ?
"qrc:/assets/cover.png" :
remoteArtwork ? artwork :
((artwork && artwork.length > 0 && artwork !== "NONE")? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png")
remoteArtwork ? model.artwork :
((model.artwork && model.artwork.length > 0 && model.artwork !== "NONE")? "file://"+encodeURIComponent(model.artwork) : "qrc:/assets/cover.png")
fillMode: Image.PreserveAspectFit
......@@ -238,6 +237,7 @@ SwipeDelegate
anchors.centerIn: parent
iconName: "media-playback-start"
iconColor: labelColor
size: iconSizes.medium
onClicked: play()
anim: true
}
......@@ -272,7 +272,7 @@ SwipeDelegate
Layout.alignment: Qt.AlignCenter
verticalAlignment: Qt.AlignVCenter
text: track + ". "
text: model.track + ". "
font.bold: true
elide: Text.ElideRight
......@@ -322,7 +322,7 @@ SwipeDelegate
id: trackBabe
font.family: "Material Design Icons"
visible: model.babe == "1"
visible: model.fav == "1"
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
......@@ -332,7 +332,7 @@ SwipeDelegate
Layout.column: /*trackDurationVisible &&*/ sameAlbum ? 4 : 3
horizontalAlignment: Qt.AlignRight
verticalAlignment: Qt.AlignVCenter
text: model.babe == "1" ? "\uf2D1" : ""
text: model.fav == "1" ? "\uf2D1" : ""
font.bold: false
elide: Text.ElideRight
font.pointSize: fontSizes.small
......@@ -354,7 +354,7 @@ SwipeDelegate
// Layout.columnSpan: trackRatingVisible && sameAlbum ? 4 : 3
horizontalAlignment: Qt.AlignRight
verticalAlignment: Qt.AlignVCenter
text: H.setStars(model.stars)
text: H.setStars(model.rate)
font.bold: false
elide: Text.ElideRight
font.pointSize: fontSizes.small
......
......@@ -13,7 +13,7 @@ Maui.Menu
property var paths : []
property int rate : 0
property bool babe : false
property bool fav : false
property string starColor : "#FFC107"
property string starReg : textColor
property string starIcon: "draw-star"
......@@ -33,7 +33,7 @@ Maui.Menu
Maui.MenuItem
{
text: babe == false ? qsTr("Fav it"): qsTr("UnFav it")
text: fav == false ? qsTr("Fav it"): qsTr("UnFav it")
onTriggered:
{
favClicked(paths)
......
......@@ -8,7 +8,7 @@ import "../../db/Queries.js" as Q
Maui.Popup
{
id: searchSuggestionsRoot
property alias model : suggestionsList.model
property alias model : suggestionsList.model
maxHeight: unit * 700
heightHint: 0.5
......
......@@ -22,14 +22,8 @@ BabeTable
holder.body: "Add new music sources"
holder.emojiSize: iconSizes.huge
function populate()
{
var map = bae.get(Q.GET.allTracks)
list.query: Q.GET.allTracks
if(map.length > 0)
for(var i in map)
tracksViewTable.model.append(map[i])
}
}
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