Commit cae22da8 authored by camilo higuita's avatar camilo higuita

album modeling now ready too

parent 127b53ef
......@@ -33,6 +33,7 @@
#include "services/local/player.h"
#include "models/tracks/tracksmodel.h"
#include "models/albums/albumsmodel.h"
#include "models/playlists/playlistsmodel.h"
#include "models/baselist.h"
#include "models/basemodel.h"
......@@ -107,6 +108,7 @@ int main(int argc, char *argv[])
qmlRegisterType<BaseModel>("BaseModel", 1, 0, "BaseModel");
qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
qmlRegisterType<PlaylistsModel>("PlaylistsList", 1, 0, "Playlists");
qmlRegisterType<AlbumsModel>("AlbumsList", 1, 0, "Albums");
qmlRegisterType<Player>("Player", 1, 0, "Player");
......
......@@ -696,7 +696,8 @@ Maui.ApplicationWindow
holder.title : "No Albums!"
holder.body: "Add new music sources"
holder.emojiSize: iconSizes.huge
headBarTitle: count + qsTr(" abums")
headBarTitle: count + qsTr(" albums")
list.query: Q.GET.allAlbumsAsc
Connections
{
......@@ -745,6 +746,7 @@ Maui.ApplicationWindow
holder.body: "Add new music sources"
holder.emojiSize: iconSizes.huge
headBarTitle: count + qsTr(" artists")
list.query: Q.GET.allArtistsAsc
Connections
{
......@@ -937,7 +939,7 @@ Maui.ApplicationWindow
{
target: bae
// onRefreshTables: H.refreshCollection(size)
onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
// onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
......
#include "albumsmodel.h"
#include "db/collectionDB.h"
AlbumsModel::AlbumsModel(QObject *parent) : BaseList(parent)
{
this->db = CollectionDB::getInstance();
connect(this, &AlbumsModel::queryChanged, this, &AlbumsModel::setList);
}
FMH::MODEL_LIST AlbumsModel::items() const
{
return this->list;
}
void AlbumsModel::setQuery(const QString &query)
{
if(this->query == query)
return;
this->query = query;
qDebug()<< "setting query"<< this->query;
emit this->queryChanged();
}
QString AlbumsModel::getQuery() const
{
return this->query;
}
void AlbumsModel::setSortBy(const SORTBY &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
this->preListChanged();
this->sortList();
this->postListChanged();
emit this->sortByChanged();
}
AlbumsModel::SORTBY AlbumsModel::getSortBy() const
{
return this->sort;
}
void AlbumsModel::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::RELEASEDATE:
{
if(e1[role].toDouble() > e2[role].toDouble())
return true;
break;
}
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);
if(date1.secsTo(currentTime) < date2.secsTo(currentTime))
return true;
break;
}
case FMH::MODEL_KEY::ARTIST:
case FMH::MODEL_KEY::ALBUM:
{
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 AlbumsModel::setList()
{
emit this->preListChanged();
this->list = this->db->getDBData(this->query);
qDebug()<< "my LIST" ;
this->sortList();
emit this->postListChanged();
}
QVariantMap AlbumsModel::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;
}
void AlbumsModel::append(const QVariantMap &item)
{
if(item.isEmpty())
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;
emit this->postItemAppended();
}
void AlbumsModel::append(const QVariantMap &item, const int &at)
{
if(item.isEmpty())
return;
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);
emit this->postItemAppended();
}
#ifndef ALBUMSMODEL_H
#define ALBUMSMODEL_H
#include <QObject>
#include "models/baselist.h"
class CollectionDB;
class AlbumsModel : public BaseList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(AlbumsModel::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
enum SORTBY : uint_fast8_t
{
ADDDATE = FMH::MODEL_KEY::ADDDATE,
RELEASEDATE = FMH::MODEL_KEY::RELEASEDATE,
ARTIST = FMH::MODEL_KEY::ARTIST,
ALBUM = FMH::MODEL_KEY::ALBUM
}; Q_ENUM(SORTBY)
explicit AlbumsModel(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const AlbumsModel::SORTBY &sort);
AlbumsModel::SORTBY getSortBy() const;
private:
CollectionDB *db;
FMH::MODEL_LIST list;
void sortList();
void setList();
QString query;
AlbumsModel::SORTBY sort = AlbumsModel::SORTBY::ADDDATE;
signals:
void queryChanged();
void sortByChanged();
public slots:
QVariantMap get(const int &index) const override;
void append(const QVariantMap &item);
void append(const QVariantMap &item, const int &at);
};
#endif // ALBUMSMODEL_H
......@@ -61,7 +61,14 @@ void TracksModel::sortList()
case FMH::MODEL_KEY::RATE:
case FMH::MODEL_KEY::FAV:
{
if(e1[role].toDouble() > e2[role].toDouble())
if(e1[role].toInt() > e2[role].toInt())
return true;
break;
}
case FMH::MODEL_KEY::TRACK:
{
if(e1[role].toInt() < e2[role].toInt())
return true;
break;
}
......
......@@ -22,7 +22,9 @@ public:
TITLE = FMH::MODEL_KEY::TITLE,
ALBUM = FMH::MODEL_KEY::ALBUM,
RATE = FMH::MODEL_KEY::RATE,
FAV = FMH::MODEL_KEY::FAV
FAV = FMH::MODEL_KEY::FAV,
TRACK = FMH::MODEL_KEY::TRACK
}; Q_ENUM(SORTBY)
explicit TracksModel(QObject *parent = nullptr);
......
......@@ -4,6 +4,9 @@ import ".."
import org.kde.kirigami 2.0 as Kirigami
import org.kde.mauikit 1.0 as Maui
import BaseModel 1.0
import AlbumsList 1.0
Maui.Page
{
id: gridPage
......@@ -15,7 +18,10 @@ Maui.Page
property int albumCoverRadius : radiusV
property bool albumCardVisible : true
property alias gridModel: gridModel
property alias list: _albumsList
property alias listModel: _albumsModel
property alias grid: grid
property alias holder: holder
property alias count: grid.count
......@@ -27,11 +33,6 @@ Maui.Page
margins: space.medium
topMargin: space.big
function clearGrid()
{
gridModel.clear()
}
MouseArea
{
anchors.fill: parent
......@@ -44,7 +45,16 @@ Maui.Page
visible: grid.count === 0
}
ListModel {id: gridModel}
Albums
{
id: _albumsList
}
BaseModel
{
id: _albumsModel
list: _albumsList
}
Maui.GridView
{
......@@ -60,7 +70,7 @@ Maui.Page
cellWidth: albumCoverSize + spacing
cellHeight: albumCoverSize + spacing*2
model: gridModel
model: _albumsModel
delegate: BabeAlbum
{
id: albumDelegate
......
......@@ -30,12 +30,7 @@ Maui.Page
focus: true
margins: 0
function clearTable()
{
model.clear()
}
Maui.Holder
Maui.Holder
{
id: holder
visible: babeList.count === 0
......
......@@ -86,6 +86,14 @@ BabeList
onTriggered: list.sortBy = Tracks.TITLE
}
Maui.MenuItem
{
text: qsTr("Track")
checkable: true
checked: list.sortBy === Tracks.TRACK
onTriggered: list.sortBy = Tracks.TRACK
}
Maui.MenuItem
{
text: qsTr("Artist")
......@@ -110,7 +118,6 @@ BabeList
onTriggered: list.sortBy = Tracks.RATE
}
Maui.MenuItem
{
text: qsTr("Fav")
......@@ -119,7 +126,6 @@ BabeList
onTriggered: list.sortBy = Tracks.FAV
}
Maui.MenuItem
{
text: qsTr("Release date")
......
......@@ -67,7 +67,8 @@ SOURCES += main.cpp \
models/tracks/tracksmodel.cpp \
models/basemodel.cpp \
models/baselist.cpp \
models/playlists/playlistsmodel.cpp
models/playlists/playlistsmodel.cpp \
models/albums/albumsmodel.cpp
RESOURCES += qml.qrc \
......@@ -106,7 +107,8 @@ HEADERS += \
models/tracks/tracksmodel.h \
models/basemodel.h \
models/baselist.h \
models/playlists/playlistsmodel.h
models/playlists/playlistsmodel.h \
models/albums/albumsmodel.h
include(install.pri)
......
......@@ -9,7 +9,8 @@ import "../db/Queries.js" as Q
import "../utils/Help.js" as H
import org.kde.kirigami 2.2 as Kirigami
import org.kde.mauikit 1.0 as Maui
import TracksList 1.0
import AlbumsList 1.0
BabeGrid
{
......@@ -37,14 +38,62 @@ BabeGrid
onAlbumCoverPressed: albumCoverPressedAndHold(album, artist)
headBar.visible: true
headBarExit: false
headBar.leftContent: Maui.ToolButton
{
id : playAllBtn
visible : headBar.visible && albumsViewGrid.count > 0
anim : true
iconName : "media-playlist-play"
onClicked : playAll()
}
headBar.leftContent: [
Maui.ToolButton
{
id : playAllBtn
visible : headBar.visible && albumsViewGrid.count > 0
anim : true
iconName : "media-playlist-play"
onClicked : playAll()
},
Maui.ToolButton
{
id: sortBtn
anim: true
iconName: "view-sort"
onClicked: sortMenu.popup()
Maui.Menu
{
id: sortMenu
Maui.MenuItem
{
text: qsTr("Artist")
checkable: true
checked: list.sortBy === Albums.ARTIST
onTriggered: list.sortBy = Albums.ARTIST
}
Maui.MenuItem
{
text: qsTr("Album")
checkable: true
checked: list.sortBy === Albums.ALBUM
onTriggered: list.sortBy = Albums.ALBUM
}
Maui.MenuItem
{
text: qsTr("Release date")
checkable: true
checked: list.sortBy === Albums.RELEASEDATE
onTriggered: list.sortBy = Albums.RELEASEDATE
}
Maui.MenuItem
{
text: qsTr("Add date")
checkable: true
checked: list.sortBy === Albums.ADDDATE
onTriggered: list.sortBy = Albums.ADDDATE
}
}
}
]
headBar.rightContent: [
......@@ -74,7 +123,7 @@ BabeGrid
defaultButtons: false
page.margins: 0
// verticalAlignment: Qt.AlignBottom
// verticalAlignment: Qt.AlignBottom
ColumnLayout
{
......@@ -93,6 +142,8 @@ BabeGrid
coverArtVisible: true
quickPlayVisible: true
focus: true
list.sortBy: Tracks.TRACK
holder.emoji: "qrc:/assets/ElectricPlug.png"
holder.isMask: false
......@@ -155,7 +206,6 @@ BabeGrid
{
console.log("PAPULATE ALBUMS VIEW")
albumDialog.open()
table.clearTable()
var query = ""
var tagq = ""
......@@ -177,18 +227,16 @@ BabeGrid
tagq = Q.GET.artistTags_.arg(artist)
}
tracks = bae.get(query)
if(tracks.length > 0)
{
for(var i in tracks)
albumsViewTable.model.append(tracks[i])
albumsViewTable.list.query = query
tagq = tagq.arg(artist)
var tags = bae.get(tagq)
console.log(tagq, "TAGS", tags)
tagBar.populate(tags)
}
/*dunoooo*/
// if(tracks.length > 0)
// {
// tagq = tagq.arg(artist)
// var tags = bae.get(tagq)
// console.log(tagq, "TAGS", tags)
// tagBar.populate(tags)
// }
}
function filter(tracks)
......
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