Commit 05e912a5 authored by Camilo Higuita's avatar Camilo Higuita

ranking system, detect mobileVSdesktop, and fixes

parent dc1771c4
......@@ -24,17 +24,12 @@ Babe::Babe(QObject *parent) : QObject(parent)
QVariantList Babe::get(const QString &queryTxt)
{
QVariantList res;
for(auto data : this->con->getDBData(queryTxt))
{
QVariantMap map;
for(auto key : data.keys())
map[BAE::KEYMAP[key]] = data[key];
res << map;
}
return Babe::transformData(this->con->getDBData(queryTxt));
}
return res;
QVariantList Babe::getList(const QStringList &urls)
{
return Babe::transformData(this->con->getDBData(urls));
}
void Babe::trackLyrics(const QString &url)
......@@ -146,6 +141,16 @@ bool Babe::babeTrack(const QString &path, const bool &value)
return false;
}
bool Babe::rateTrack(const QString &path, const int &value)
{
return this->con->rateTrack(path, value);
}
int Babe::trackRate(const QString &path)
{
return this->con->getTrackStars(path);
}
void Babe::scanDir(const QString &url)
{
emit this->set->collectionPathChanged(url);
......@@ -236,6 +241,25 @@ QString Babe::babeColor()
return "#E91E63";
}
bool Babe::isMobile()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return true;
#elif defined(Q_OS_HAIKU)
return false;
#endif
}
QString Babe::loadCover(const QString &url)
{
auto map = this->con->getDBData(QStringList() << url);
......@@ -297,3 +321,19 @@ QString Babe::fetchCoverArt(DB &song)
return song[KEY::ARTWORK];
}
QVariantList Babe::transformData(const DB_LIST &dbList)
{
QVariantList res;
for(auto data : dbList)
{
QVariantMap map;
for(auto key : data.keys())
map[BAE::KEYMAP[key]] = data[key];
res << map;
}
return res;
}
......@@ -22,6 +22,7 @@ public:
/* DATABASE INTERFACES */
Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE void trackLyrics(const QString &url);
Q_INVOKABLE bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist);
......@@ -30,6 +31,8 @@ public:
Q_INVOKABLE QString albumWiki(const QString &album, const QString &artist);
Q_INVOKABLE bool babeTrack(const QString &path, const bool &value);
Q_INVOKABLE bool rateTrack(const QString &path, const int &value);
Q_INVOKABLE int trackRate(const QString &path);
/* SETTINGS */
......@@ -52,6 +55,8 @@ public:
Q_INVOKABLE static QString altColor();
Q_INVOKABLE static QString babeColor();
Q_INVOKABLE static bool isMobile();
/*USEFUL*/
Q_INVOKABLE QString loadCover(const QString &url);
......@@ -62,7 +67,7 @@ private:
settings *set;
QString fetchCoverArt(DB &song);
static QVariantList transformData(const DB_LIST &dbList);
void fetchTrackLyrics(DB &song);
......
var Query = {
allTracks : "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist",
allTracksSimple : "select * from tracks",
allAlbums : "select * from albums",
allAlbumsAsc : "select * from albums order by album asc",
allArtists : "select * from artists",
allArtistsAsc : "select * from artists order by artist asc",
albumTracks_ : "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where t.album = \"%1\" and t.artist = \"%2\" order by t.track asc",
artistTracks_ : "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where t.artist = \"%1\" order by t.album asc, t.track asc",
albumTracksSimple_ : "select * from tracks where album = \"%1\" and artist = \"%2\"",
artistTracksSimple_ : "select * from tracks where artist = \"%1\"",
tracksWhere_ : "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where %1",
}
......@@ -34,7 +34,7 @@ ApplicationWindow
// pageStack.defaultColumnWidth: columnWidth
// pageStack.initialPage: [playlistPage, views]
onWidthChanged: if(Qt.platform.os === "android")
onWidthChanged: if(bae.isMobile())
{
if(root.width>root.height)
mainPlaylist.cover.visible = false
......@@ -147,13 +147,7 @@ ApplicationWindow
onCurrentIndexChanged: currentView = currentIndex
Component.onCompleted:
{
if(Qt.platform.os === "linux")
contentItem.interactive = false
else if(Qt.platform.os === "android")
contentItem.interactive = true
}
Component.onCompleted: contentItem.interactive = bae.isMobile()
currentIndex: currentView
......@@ -161,6 +155,12 @@ ApplicationWindow
MainPlaylist
{
id: mainPlaylist
Connections
{
target: mainPlaylist
onCoverPressed: Player.appendAlbum(tracks)
onCoverDoubleClicked: Player.playAlbum(tracks)
}
}
......
......@@ -27,5 +27,7 @@
<file>view_models/BabeDialog.qml</file>
<file>widgets/PlaylistMenu.qml</file>
<file>widgets/LyricsView.qml</file>
<file>db/Queries.js</file>
<file>view_models/TableMenu.qml</file>
</qresource>
</RCC>
......@@ -7,7 +7,7 @@ function playTrack(track)
player.source(root.mainPlaylist.currentTrack.url);
player.play()
root.title = root.mainPlaylist.currentTrack.title + " - " +root.mainPlaylist.currentTrack.artist
root.mainPlaylist.currentArtwork = bae.loadCover(root.mainPlaylist.currentTrack.url)
root.mainPlaylist.currentArtwork = root.mainPlaylist.currentTrack.artwork || bae.loadCover(root.mainPlaylist.currentTrack.url)
root.mainPlaylist.playIcon.text = Icon.pause
......@@ -17,13 +17,15 @@ function playTrack(track)
root.mainPlaylist.babeBtnIcon.color = root.mainPlaylist.babeBtnIcon.defaultColor
var lyrics = root.mainPlaylist.currentTrack.lyrics
if(!lyrics)
bae.trackLyrics(root.mainPlaylist.currentTrack.url)
else
root.mainPlaylist.infoView.lyrics = lyrics
// root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// // root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
}
......@@ -153,15 +155,14 @@ function cleanPlaylist()
function playAlbum(tracks)
{
root.mainPlaylist.list.clearTable()
root.currentView = 0
for(var i = 0; i< tracks.length; i++)
appendTrack(tracks[i])
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
root.mainPlaylist.list.positionViewAtBeginning()
......
......@@ -10,7 +10,7 @@ Item
property int borderRadius : 2
property string fillColor: bae.midColor()
property string textColor: bae.foregroundColor()
property int fontSize :Qt.platform.os === "android"? 12 : 10
property int fontSize : bae.isMobile()? 12 : 10
id: root
width: albumSize
......
......@@ -99,7 +99,7 @@ Pane
}
}
ScrollBar.vertical: ScrollBar{ visible: !(Qt.platform.os === "android")}
ScrollBar.vertical: ScrollBar{ visible: !bae.isMobile()}
}
}
......@@ -72,57 +72,10 @@ ListView
}
}
Menu
{
id: contextMenu
x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 2
modal: true
Label
{
padding: 10
font.bold: true
width: parent.width
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
text: currentRow >= 0 ? list.model.get(currentRow).title : ""
}
MenuItem
{
text: qsTr("Babe it")
onTriggered: ;
}
MenuItem
{
text: qsTr("Queue")
onTriggered:
{
console.log(currentRow)
list.queueTrack(currentRow)
}
}
MenuItem
{
text: qsTr("Edit...")
onTriggered: ;
}
MenuItem
{
text: qsTr("Remove")
onTriggered: ;
}
MenuItem
{
text: qsTr("Edit...")
onTriggered: ;
}
MenuItem
{
text: qsTr("Remove")
onTriggered: ;
}
}
TableMenu
{
id: contextMenu
}
ListModel { id: listModel }
......@@ -140,7 +93,7 @@ ListView
target: delegate
onPressAndHold:
{
if(Qt.platform.os === "linux")
if(!bae.isMobile())
list.quickPlayTrack(currentIndex)
}
......@@ -154,6 +107,7 @@ ListView
onMenuClicked:
{
currentRow = index
contextMenu.rate = bae.trackRate(list.model.get(currentRow).url)
contextMenu.open()
list.rowPressed(index)
}
......
......@@ -22,7 +22,7 @@ ItemDelegate
acceptedButtons: Qt.RightButton
onClicked:
{
if(Qt.platform.os === "linux")
if(!bae.isMobile())
if (mouse.button === Qt.RightButton)
menuClicked()
}
......@@ -115,7 +115,7 @@ ItemDelegate
ToolButton
{
id: menuBtn
visible: Qt.platform.os === "android"
visible: bae.isMobile()
Icon { text: MdiFont.Icon.dotsVertical }
onClicked: menuClicked()
}
......
import QtQuick 2.0
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../utils/Icons.js" as MdiFont
import "../utils"
Menu
{
id: rootMenu
x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 2
modal: true
property int rate : 0
property string starColor : "#FFC107"
property string starReg : "gray"
property string starIcon: MdiFont.Icon.star
property int starSize : 22
signal rated(int value)
function rateIt(rank)
{
rate = rank
bae.rateTrack(list.model.get(currentRow).url, rate)
}
Label
{
padding: 10
font.bold: true
width: parent.width
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
text: currentRow >= 0 ? list.model.get(currentRow).title : ""
}
MenuItem
{
text: qsTr("Babe it")
onTriggered: ;
}
MenuItem
{
text: qsTr("Queue")
onTriggered:
{
console.log(currentRow)
list.queueTrack(currentRow)
}
}
MenuItem
{
text: qsTr("Edit...")
onTriggered: ;
}
MenuItem
{
text: qsTr("Remove")
onTriggered: ;
}
MenuItem
{
text: qsTr("Edit...")
onTriggered: ;
}
MenuItem
{
text: qsTr("Remove")
onTriggered: ;
}
MenuItem
{
RowLayout
{
anchors.fill: parent
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 1 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(1)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 2 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(2)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 3 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(3)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 4 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(4)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 5 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(5)
}
}
}
}
......@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import "../view_models"
import "../utils/Icons.js" as MdiFont
import "../utils"
import "../db/Queries.js" as Q
BabeGrid
{
......@@ -63,7 +64,8 @@ BabeGrid
drawer.close()
var data = albumsViewGrid.gridModel.get(albumsViewGrid.grid.currentIndex)
var query = "select * from tracks where album = \""+data.album+"\" and artist = \""+data.artist+"\" order by track asc"
var query = Q.Query.albumTracks_.arg(data.album)
query = query.arg(data.artist)
var tracks = bae.get(query)
albumsViewGrid.playAlbum(tracks)
......@@ -82,7 +84,8 @@ BabeGrid
onClicked:
{
var data = albumsView.gridModel.get(albumsViewGrid.grid.currentIndex)
var query = "select * from tracks where album = \""+data.album+"\" and artist = \""+data.artist+"\""
var query = Q.Query.albumTracks_.arg(data.album)
query = query.arg(data.artist)
var tracks = bae.get(query)
albumsViewGrid.appendAlbum(tracks)
drawer.close()
......@@ -153,19 +156,19 @@ BabeGrid
drawer.open()
drawerList.clearTable()
var query = "select * from tracks where album = \""+album+"\" and artist = \""+artist+"\" order by track"
console.log(query)
var query = Q.Query.albumTracks_.arg(album)
query = query.arg(artist)
var map = bae.get(query)
for(var i in map)
drawerList.model.append(map[i])
}
function populate()
{
var map = bae.get("select * from albums order by album asc")
var map = bae.get(Q.Query.allAlbumsAsc)
for(var i in map)
gridModel.append(map[i])
}
......
......@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import "../view_models"
import "../utils/Icons.js" as MdiFont
import "../utils"
import "../db/Queries.js" as Q
BabeGrid
{
......@@ -56,9 +57,9 @@ BabeGrid
drawer.close()
var data = artistsViewGrid.gridModel.get(artistsViewGrid.grid.currentIndex)
var query = "select * from tracks where artist = \""+data.artist+"\""
var query = Q.Query.artistTracks_.arg(data.artist)
var tracks = bae.get(query)
playAlbum(tracks)
artistsViewGrid.playAlbum(tracks)
}
}
......@@ -74,9 +75,9 @@ BabeGrid
onClicked:
{
var data = artistsViewGrid.gridModel.get(artistsViewGrid.grid.currentIndex)
var query = "select * from tracks where artist = \""+data.artist+"\""
var query = Q.Query.artistTracks_.arg(data.artist)
var tracks = bae.get(query)
appendAlbum(tracks)
artistsViewGrid.appendAlbum(tracks)
drawer.close()
}
......@@ -150,8 +151,7 @@ BabeGrid
artistTitle.text = artist
drawer.open()
drawerList.clearTable()
var query = "select * from tracks where artist = \""+artist+"\" order by album, track"
var query = Q.Query.artistTracks_.arg(artist)
var map = bae.get(query)
for(var i in map)
......@@ -161,7 +161,7 @@ BabeGrid
function populate()
{
var map = bae.get("select * from artists order by artist asc")
var map = bae.get(Q.Query.allArtistsAsc)
for(var i in map)
gridModel.append(map[i])
}
......
......@@ -6,6 +6,7 @@ import QtGraphicalEffects 1.0
import "../utils/Icons.js" as MdiFont
import "../utils/Player.js" as Player
import "../db/Queries.js" as Q
import "../utils"
import "../view_models"
import "../widgets"
......@@ -23,6 +24,8 @@ Item
property alias playIcon : playIcon
property alias babeBtnIcon: babeBtnIcon
property alias infoView : infoView
signal coverDoubleClicked(var tracks)
signal coverPressed(var tracks)
// Component.onCompleted:
// {
// if(list.count>0)
......@@ -71,20 +74,32 @@ Item
anchors.fill: parent
onDoubleClicked:
{
var query = Q.Query.albumTracks_.arg(currentTrack.album)
query = query.arg(currentTrack.artist)
var tracks = bae.get(query)
coverDoubleClicked(tracks)
}
onClicked:
onPressAndHold:
{
if(stackView.currentItem !== list)
stackView.pop(list)
else
{
stackView.push(infoView)
infoView.currentView = 1
}
var query = Q.Query.albumTracks_.arg(currentTrack.album)
query = query.arg(currentTrack.artist)
var tracks = bae.get(query)
coverPressed(tracks)
}
// onClicked:
// {
// if(stackView.currentItem !== list)
// stackView.pop(list)
// else
// {
// stackView.push(infoView)
// infoView.currentView = 1
// }
// }
}
}
......@@ -155,7 +170,7 @@ Item
drag.maximumY: columnWidth
onClicked:
{
if(Qt.platform.os === "linux")
if(!bae.isMobile())
cover.visible = !cover.visible
}
}
......@@ -180,7 +195,7 @@ Item
onClicked:
{
if(stackView.currentItem !== list)
{
{
stackView.pop(list)
cover.visible = true
......@@ -287,10 +302,25 @@ Item
{
var list = bae.lastPlaylist()
var n = list.length
for(var i = 0; i < n; i++)
if(n>0)
{
var track = bae.get("select * from tracks where url = \""+list[i]+"\"")
Player.appendTrack(track[0])
for(var i = 0; i < n; i++)
{
var where = "url = \""+list[i]+"\""
var query = Q.Query.tracksWhere_.arg(where)
var track = bae.get(query)
Player.appendTrack(track[0])
}
}else
{
var where = "babe = 1"
var query = Q.Query.tracksWhere_.arg(where)
var tracks = bae.get(query)
for(var pos=0; pos< tracks.length; pos++)
Player.appendTrack(tracks[pos])
}
// var pos = bae.lastPlaylistPos()
......
......@@ -33,5 +33,12 @@ Menu
{
text: qsTr("Callibrate")
onTriggered: callibrate()
}
MenuItem
{
text: qsTr("Save as playlist...")
onTriggered: {}
}
}
import QtQuick 2.9
import "../view_models"
import "../db/Queries.js" as Q
BabeTable
{
......@@ -8,7 +8,7 @@ BabeTable
trackNumberVisible: false
function populate()
{
var map = bae.get("select * from tracks")
var map = bae.get(Q.Query.allTracks)
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