Commit a64320e6 authored by Camilo higuita's avatar Camilo higuita

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);
......
This diff is collapsed.
......@@ -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
property string playlistQuery
property alias playlistViewModel : playlistViewModel
property alias playlistModel : playlistViewModel.model
property alias playlistList : playlistViewModel.list
property alias playlistViewList : playlistViewModel
// property alias list : _playlistsList
// property alias listModel: _playlistsModel
......@@ -30,14 +32,14 @@ Kirigami.PageRow
clip: true
separatorVisible: wideMode
initialPage: [playlistList, filterList]
initialPage: [playlistLayout, filterList]
defaultColumnWidth: Kirigami.Units.gridUnit * 15
interactive: currentIndex === 1 && !wideMode
ColumnLayout
{
id: playlistList
id: playlistLayout
clip: true
anchors.fill: parent
spacing: 0
......@@ -110,7 +112,7 @@ Kirigami.PageRow
headBar.visible: !holder.visible
headBarExitIcon: "go-previous"
headBarExit: !playlistViewRoot.wideMode
headBarTitle: playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
headBarTitle: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist
onExit: if(!playlistViewRoot.wideMode)
playlistViewRoot.currentIndex = 0
......@@ -189,7 +191,7 @@ Kirigami.PageRow
onRemoveClicked:
{
bae.removePlaylistTrack(url, playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
bae.removePlaylistTrack(url, playlistViewModel.model.get(playlistViewList.currentIndex).playlist)
populate(playlistQuery)
}
}
......@@ -223,36 +225,19 @@ Kirigami.PageRow
}
function refresh()
{
for(var i=9; i < playlistViewModel.count; i++)
playlistViewModel.model.remove(i)
setPlaylists()
}
function setPlaylists()
{
var playlists = bae.get(Q.GET.playlists)
if(playlists.length > 0)
for(var i in playlists)
playlistViewModel.model.append(playlists[i])
}
{
}
function syncAndPlay(index)
{
if(!playlistViewModel.model.get(index).playlistIcon)
playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
if(!playlistList.get(index).playlistIcon)
playlistViewRoot.playSync(playlistList.get(index).playlist)
}
function removePlaylist()
{
bae.removePlaylist(playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
bae.removePlaylist(playlistList.get(playlistViewList.currentIndex).playlist)
filterList.clearTable()
refresh()
}
Component.onCompleted: setPlaylists()
}
......@@ -16,7 +16,9 @@ import "../../utils/Help.js" as H
BabeList
{
id: playlistListRoot
id: control
property alias list: _playlistsList
headBarExit: false
headBarTitle: "Playlists"
......@@ -30,7 +32,8 @@ BabeList
rejectButton.visible: false
}
signal playSync(int index)
signal playSync(int index)
headBar.plegable: false
headBar.leftContent: Maui.ToolButton
{
......@@ -46,7 +49,6 @@ BabeList
onClicked: removePlaylist()
}
BaseModel
{
id: _playlistsModel
......@@ -63,7 +65,7 @@ BabeList
delegate : Maui.ListDelegate
{
id: delegate
width: playlistListRoot.width
width: control.width
label: model.playlist
Connections
......@@ -88,7 +90,7 @@ BabeList
filterList.list.sortBy = Tracks.RATE
filterList.group = true
playlistViewRoot.populate(Q.GET.favoriteTracks);
playlistViewRoot.populate(Q.GET.favoriteTracks);
break;
case "Recent":
......@@ -133,8 +135,7 @@ BabeList
function addPlaylist(text)
{
var title = text.trim()
if(bae.addPlaylist(title))
model.insert(9, {playlist: title})
list.positionViewAtEnd()
if(list.insertAt(title, 0))
control.listView.positionViewAtEnd()
}
}
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