Commit a64320e6 authored by Camilo higuita's avatar Camilo higuita
Browse files

now playlists action working too

parent ca7b6321
......@@ -35,7 +35,7 @@ Babe::Babe(QObject *parent) : QObject(parent)
/*use another thread for the db to perfom heavy dutty actions*/
this->thread = new ConThread;
this->pulpo = new Pulpo;
this->pulpo = new Pulpo(this);
this->db = CollectionDB::getInstance();
connect(pulpo, &Pulpo::infoReady, [&](const FMH::MODEL &track, const PULPO::RESPONSE &res)
......
......@@ -418,7 +418,9 @@ bool CollectionDB::albumTrack(const FMH::MODEL &track, const QString &value)
bool CollectionDB::playedTrack(const QString &url, const int &increment)
{
auto queryTxt = QString("UPDATE %1 SET %2 = %2 + %3 WHERE %4 = \"%5\"").arg(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::COUNT], QString::number(increment), FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url);
FMH::MODEL_NAME[FMH::MODEL_KEY::COUNT],
QString::number(increment),
FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url);
auto query = this->getQuery(queryTxt);
......
......@@ -93,10 +93,11 @@ Maui.ApplicationWindow
playlists: 3,
search: 4,
folders: 5,
vvave: 6,
linking: 7,
youtube: 8,
spotify: 9
cloud: 6,
vvave: 7,
linking: 8,
youtube: 9,
spotify: 10
})
......@@ -114,7 +115,7 @@ Maui.ApplicationWindow
/***************************************************/
/******************** UI COLORS *******************/
/*************************************************/
property string babeColor: bae.babeColor() //"#140032"
readonly property string babeColor: bae.babeColor() //"#140032"
/*SIGNALS*/
signal missingAlert(var track)
......@@ -127,33 +128,17 @@ Maui.ApplicationWindow
/*HANDLE EVENTS*/
onWidthChanged: if (isMobile) {
if (width > height)
mainPlaylist.cover.visible = false
else
mainPlaylist.cover.visible = true
}
onClosing: Player.savePlaylist()
// pageStack.onCurrentIndexChanged:
// {
// if(pageStack.currentIndex === 0 && isMobile && !pageStack.wideMode)
// {
// bae.androidStatusBarColor(babeColor)
// Material.background = babeColor
// }else
// {
// bae.androidStatusBarColor(babeAltColor)
// Material.background = babeAltColor
// }
// }
onMissingAlert:
{
missingDialog.message = track.title + " by " + track.artist + " is missing"
missingDialog.messageBody = "Do you want to remove it from your collection?"
missingDialog.open()
var message = track.title + " by " + track.artist + " is missing"
var messageBody = "Do you want to remove it from your collection?"
notify("alert", message, messageBody, function ()
{
bae.removeTrack(currentTrack.url) //todo
mainPlaylist.table.model.remove(mainPlaylist.table.currentIndex)
})
}
/*COMPONENTS*/
......@@ -162,29 +147,19 @@ Maui.ApplicationWindow
{
id: player
volume: 100
// onFinishedChanged: if (!mainlistEmpty)
// {
// if (currentTrack.url)
// bae.playedTrack(currentTrack.url)
// Player.nextTrack()
// }
onFinishedChanged: if (!mainlistEmpty)
{
console.log("track fully played")
if (currentTrack.url)
mainPlaylist.list.countUp(currentTrackIndex)
Player.nextTrack()
}
}
BabeNotify
{
id: babeNotify
}
Maui.Dialog
{
id: missingDialog
title: "Missing file"
onAccepted: {
bae.removeTrack(currentTrack.url)
mainPlaylist.table.model.remove(mainPlaylist.table.currentIndex)
}
id: babeNotify //todo
}
......@@ -200,27 +175,10 @@ Maui.ApplicationWindow
headBar.middleContent : [
// Row
// {
// Image
// {
// height: iconSizes.medium
// width: height
// source: "file://" + encodeURIComponent(
// currentArtwork)
// }
// Label
// {
// text: "Now"
// }
// },
Maui.ToolButton
{
iconName: "headphones"
iconColor: !accent ? babeColor : altColorText
iconColor: !accent || isPlaying ? babeColor : altColorText
onClicked: pageStack.currentIndex = 0
text: qsTr("Now")
......@@ -279,6 +237,7 @@ Maui.ApplicationWindow
tooltipText: pageStack.wideMode ? "" : text
}
]
footBar.visible: !mainlistEmpty
footBar.middleContent: [
......@@ -342,18 +301,8 @@ Maui.ApplicationWindow
pageStack.currentIndex = 1
currentView = viewsIndex.search
searchView.searchInput.forceActiveFocus()
riseContent()
}
// FloatingDisk
// {
// id: floatingDisk
// x: space.big
// y: pageStack.height - height
// z: 999
// }
Maui.ShareDialog
{
id: shareDialog
......@@ -429,15 +378,27 @@ Maui.ApplicationWindow
Maui.MenuItem
{
text: qsTr("Spotify")
icon.name: "internet-services"
text: qsTr("Cloud")
icon.name: "folder-cloud"
onTriggered:
{
pageStack.currentIndex = 1
currentView = viewsIndex.spotify
currentView = viewsIndex.cloud
}
},
// Maui.MenuItem
// {
// text: qsTr("Spotify")
// icon.name: "internet-services"
// onTriggered:
// {
// pageStack.currentIndex = 1
// currentView = viewsIndex.spotify
// }
// },
MenuSeparator{},
Maui.MenuItem
......@@ -445,87 +406,87 @@ Maui.ApplicationWindow
text: qsTr("Sources...")
icon.name: "folder-add"
onTriggered: sourcesDialog.open()
},
Maui.Menu
{
title: qsTr("Collection")
// icon.name: "settings-configure"
Maui.MenuItem
{
text: qsTr("Re-Scan")
onTriggered: bae.refreshCollection();
}
Maui.MenuItem
{
text: qsTr("Refresh...")
onTriggered: H.refreshCollection();
}
Maui.MenuItem
{
text: qsTr("Clean")
onTriggered: bae.removeMissingTracks();
}
},
Maui.Menu
{
title: qsTr("Settings...")
// Kirigami.Action
// {
// text: "Brainz"
// Kirigami.Action
// {
// id: brainzToggle
// text: checked ? "Turn OFF" : "Turn ON"
// checked: bae.brainzState()
// checkable: true
// onToggled:
// {
// checked = !checked
// bae.saveSetting("AUTO", checked, "BRAINZ")
//// bae.brainz(checked)
// }
// }
// }
Maui.MenuItem
{
text: "Info label" + checked ? "ON" : "OFF"
checked: infoLabels
checkable: true
onToggled:
{
infoLabels = checked
bae.saveSetting("LABELS", infoLabels ? true : false, "PLAYBACK")
}
}
Maui.MenuItem
{
text: "Autoplay"
checked: autoplay
checkable: true
onToggled:
{
autoplay = checked
bae.saveSetting("AUTOPLAY", autoplay ? true : false, "BABE")
}
}
}
// Maui.Menu
// {
// title: qsTr("Collection")
// // icon.name: "settings-configure"
// Maui.MenuItem
// {
// text: qsTr("Re-Scan")
// onTriggered: bae.refreshCollection();
// }
// Maui.MenuItem
// {
// text: qsTr("Refresh...")
// onTriggered: H.refreshCollection();
// }
// Maui.MenuItem
// {
// text: qsTr("Clean")
// onTriggered: bae.removeMissingTracks();
// }
// },
// Maui.Menu
// {
// title: qsTr("Settings...")
// // Kirigami.Action
// // {
// // text: "Brainz"
// // Kirigami.Action
// // {
// // id: brainzToggle
// // text: checked ? "Turn OFF" : "Turn ON"
// // checked: bae.brainzState()
// // checkable: true
// // onToggled:
// // {
// // checked = !checked
// // bae.saveSetting("AUTO", checked, "BRAINZ")
// //// bae.brainz(checked)
// // }
// // }
// // }
// Maui.MenuItem
// {
// text: "Info label" + checked ? "ON" : "OFF"
// checked: infoLabels
// checkable: true
// onToggled:
// {
// infoLabels = checked
// bae.saveSetting("LABELS", infoLabels ? true : false, "PLAYBACK")
// }
// }
// Maui.MenuItem
// {
// text: "Autoplay"
// checked: autoplay
// checkable: true
// onToggled:
// {
// autoplay = checked
// bae.saveSetting("AUTOPLAY", autoplay ? true : false, "BABE")
// }
// }
// }
]
Item
{
id: message
visible: infoMsg.length > 0 && sync
visible: infoMsg.length && sync
anchors.bottom: parent.bottom
width: pageStack.wideMode ? columnWidth : parent.width
height: iconSize
......
......@@ -77,13 +77,23 @@ void PlaylistsModel::setList()
qDebug()<< "trying to set playlists list";
emit this->preListChanged();
this->list = this->defaultPlaylists();
// this->list << this->db->getPlaylists();
this->list << this->db->getPlaylists();
this->list << this->defaultPlaylists();
// this->sortList();
// this->sortList();
emit this->postListChanged();
}
FMH::MODEL PlaylistsModel::packPlaylist(const QString &playlist)
{
return FMH::MODEL
{
{FMH::MODEL_KEY::PLAYLIST, playlist},
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// {FMH::MODEL_KEY::ICON, "view-media-playlist"}
};
}
FMH::MODEL_LIST PlaylistsModel::defaultPlaylists()
{
return FMH::MODEL_LIST {
......@@ -117,12 +127,6 @@ FMH::MODEL_LIST PlaylistsModel::defaultPlaylists()
{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"},
......@@ -199,3 +203,41 @@ void PlaylistsModel::append(const QVariantMap &item, const int &at)
emit this->postItemAppended();
}
void PlaylistsModel::insert(const QString &playlist)
{
if(playlist.isEmpty())
return;
emit this->preItemAppended();
this->list << this->packPlaylist(playlist);
emit this->postItemAppended();
}
void PlaylistsModel::insertAt(const QString &playlist, const int &at)
{
if(playlist.isEmpty())
return;
if(at > this->list.size() || at < 0)
return;
emit this->preItemAppendedAt(at);
if(this->db->addPlaylist(playlist))
this->list.insert(at, this->packPlaylist(playlist));
emit this->postItemAppended();
}
void PlaylistsModel::addTrack(const int &index, const QStringList &urls)
{
if(index >= this->list.size() || index < 0)
return;
for(auto url : urls)
this->db->trackPlaylist(url, this->list[index][FMH::MODEL_KEY::PLAYLIST]);
}
......@@ -30,6 +30,8 @@ private:
void sortList();
void setList();
FMH::MODEL packPlaylist(const QString &playlist);
FMH::MODEL_LIST defaultPlaylists();
PlaylistsModel::SORTBY sort = PlaylistsModel::SORTBY::ADDDATE;
......@@ -41,6 +43,9 @@ public slots:
QVariantMap get(const int &index) const override;
void append(const QVariantMap &item);
void append(const QVariantMap &item, const int &at);
void insert(const QString &playlist);
void insertAt(const QString &playlist, const int &at);
void addTrack(const int &index, const QStringList &urls);
};
#endif // PLAYLISTSMODEL_H
......@@ -63,6 +63,7 @@ void TracksModel::sortList()
case FMH::MODEL_KEY::RELEASEDATE:
case FMH::MODEL_KEY::RATE:
case FMH::MODEL_KEY::FAV:
case FMH::MODEL_KEY::COUNT:
{
if(e1[role].toInt() > e2[role].toInt())
return true;
......@@ -311,3 +312,20 @@ bool TracksModel::rate(const int &index, const int &value)
return false;
}
bool TracksModel::countUp(const int &index)
{
if(index >= this->list.size() || index < 0)
return false;
auto item = this->list[index];
if(this->db->playedTrack(item[FMH::MODEL_KEY::URL]))
{
this->list[index][FMH::MODEL_KEY::COUNT] = QString::number(item[FMH::MODEL_KEY::COUNT].toInt() + 1);
emit this->updateModel(index, {FMH::MODEL_KEY::COUNT});
return true;
}
return false;
}
......@@ -62,6 +62,7 @@ public slots:
bool color(const int &index, const QString &color);
bool fav(const int &index, const bool &value);
bool rate(const int &index, const int &value);
bool countUp(const int &index);
};
#endif // TRACKSMODEL_H
......@@ -191,12 +191,11 @@ void Player::update()
{
if(this->player->isAvailable())
{
this->pos = static_cast<int>(static_cast<double>(this->player->position())/this->player->duration()*1000);;
emit this->posChanged();
}
if(this->player->state() == QMediaPlayer::StoppedState && this->updater->isActive())
if(this->player->state() == QMediaPlayer::StoppedState && this->updater->isActive() && this->player->position() == this->player->duration())
{
this->finished = true;
emit this->finishedChanged();
......
......@@ -112,6 +112,14 @@ BabeList
onTriggered: list.sortBy = Tracks.ALBUM
}
Maui.MenuItem
{
text: qsTr("Most played")
checkable: true
checked: list.sortBy === Tracks.COUNT
onTriggered: list.sortBy = Tracks.COUNT
}
Maui.MenuItem
{
text: qsTr("Rate")
......@@ -412,6 +420,9 @@ BabeList
break
case Tracks.RELEASEDATE:
prop = "releasedate"
break;
case Tracks.COUNT:
prop = "count"
break
}
......
......@@ -27,14 +27,15 @@ Maui.Dialog
Layout.fillWidth: true
headBar.visible: false
holder.message: "<h2>There's not playlists</h2><br><p>Create a new one and start adding tracks to it<p/>"
ListModel { id: listModel }
model: listModel
holder.title: "There's not playlists"
holder.body: "Create a new one and start adding tracks to it"
model: playlistsView.playlistModel
delegate: Maui.LabelDelegate
{
id: delegate
label: playlist
label: model.playlist
Connections
{
......@@ -63,6 +64,7 @@ Maui.Dialog
onAccepted:
{
addPlaylist()
playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
clear()
close()
}
......@@ -78,28 +80,13 @@ Maui.Dialog
}
onOpened:
{
newPlaylistField.clear()
playlistsList.clearTable()
var playlists = bae.get(Q.GET.playlists)
if(playlists.length > 0)
for(var i in playlists)
playlistsList.model.append(playlists[i])
// newPlaylistField.forceActiveFocus()
}
onAccepted:
{
if(newPlaylistField.text && newPlaylistField.text.length > 0)
{
if(newPlaylistField.text.length)
addPlaylist()
Player.addToPlaylist(tracks,newPlaylistField.text.trim())
}
else
Player.addToPlaylist(tracks, playlistsList.model.get(playlistsList.currentIndex).playlist)
playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
close()
}
function addPlaylist()
......@@ -107,11 +94,10 @@ Maui.Dialog
if (newPlaylistField.text)
{
var title = newPlaylistField.text.trim()
if(bae.addPlaylist(title))
if( playlistsView.playlistList.insertAt(title, 0))
{
playlistsList.model.insert(0, {playlist: title})
playlistsView.playlistViewModel.model.insert(9, {playlist: title})
playlistsList.list.positionViewAtBeginning()
playlistsList.listView.currentIndex = 0
playlistsList.listView.positionViewAtBeginning()
}
newPlaylistField.clear()
......
......@@ -16,7 +16,9 @@ Kirigami.PageRow
id: playlistViewRoot