Commit 6bd86ad4 authored by Camilo higuita's avatar Camilo higuita

push latest changes to the modeling upgrade

parent d18c572b
......@@ -310,16 +310,6 @@ QVariantList Babe::getFolders()
return res;
}
bool Babe::babeTrack(const QString &path, const bool &value)
{
if(this->db->update(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::FAV],
value ? 1 : 0,
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],
path)) return true;
return false;
}
void Babe::notify(const QString &title, const QString &body)
{
......
......@@ -49,7 +49,6 @@ public:
Q_INVOKABLE QString albumWiki(const QString &album, const QString &artist);
Q_INVOKABLE QVariantList getFolders();
Q_INVOKABLE bool babeTrack(const QString &path, const bool &value);
/* SETTINGS */
Q_INVOKABLE void scanDir(const QString &url);
......
......@@ -712,8 +712,8 @@ QVariantList CollectionDB::getSearchedTracks(const FMH::MODEL_KEY &where, const
FMH::MODEL_NAME[FMH::MODEL_KEY::ARTIST],
TABLEMAP[TABLE::ARTISTS_TAGS]);
// else if(where == FMH::MODEL_KEY::SQL)
// queryTxt = search;
// else if(where == FMH::MODEL_KEY::SQL)
// queryTxt = search;
else
queryTxt = QString("SELECT t.*, al.artwork FROM %1 t inner join albums al on al.album = t.album and t.artist = al.artist WHERE t.%2 LIKE \"%%3%\" ORDER BY strftime(\"%s\", t.addDate) desc LIMIT 1000").arg(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[where],
......@@ -1044,6 +1044,16 @@ bool CollectionDB::removeFolder(const QString &url)
return query.exec();
}
bool CollectionDB::favTrack(const QString &path, const bool &value)
{
if(this->update(TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::FAV],
value ? 1 : 0,
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],
path)) return true;
return false;
}
bool CollectionDB::removeAlbum(const QString &album, const QString &artist)
{
auto queryTxt = QString("DELETE FROM %1 WHERE %2 = \"%3\" AND %4 = \"%5\"").arg(TABLEMAP[TABLE::ALBUMS],
......
......@@ -68,6 +68,8 @@ class CollectionDB : public QObject
bool addFolder(const QString &url);
bool removeFolder(const QString &url);
bool favTrack(const QString &path, const bool &value);
FMH::MODEL_LIST getDBData(const QStringList &urls);
FMH::MODEL_LIST getDBData(const QString &queryTxt);
QVariantList getDBDataQML(const QString &queryTxt);
......
......@@ -169,9 +169,6 @@ Maui.ApplicationWindow
id: player
volume: 100
// onTestChanged: console.log("new value:", player.test)
onPositionChanged: console.log("new value:", player.position)
// onFinishedChanged: if (!mainlistEmpty)
// {
// if (currentTrack.url)
......@@ -682,11 +679,11 @@ Maui.ApplicationWindow
Connections
{
target: tracksView
onRowClicked: Player.addTrack(tracksView.model.get(index))
onQuickPlayTrack: Player.quickPlay(tracksView.model.get(index))
onRowClicked: Player.addTrack(tracksView.list.get(index))
onQuickPlayTrack: Player.quickPlay(tracksView.list.get(index))
onPlayAll: Player.playAll(bae.get(Q.GET.allTracks))
onAppendAll: Player.appendAll(bae.get(Q.GET.allTracks))
onQueueTrack: Player.queueTracks([tracksView.model.get(index)], index)
onQueueTrack: Player.queueTracks([tracksView.list.get(index)], index)
}
}
......
......@@ -3,7 +3,6 @@
TracksModel::TracksModel(QObject *parent) : BaseList(parent)
{
this->db = CollectionDB::getInstance();
connect(this, &TracksModel::sortByChanged, this, &TracksModel::sortList);
connect(this, &TracksModel::queryChanged, this, &TracksModel::setList);
}
......@@ -28,16 +27,20 @@ QString TracksModel::getQuery() const
return this->query;
}
void TracksModel::setSortBy(const uint &sort)
void TracksModel::setSortBy(const SORTBY &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
this->preListChanged();
this->sortList();
this->postListChanged();
emit this->sortByChanged();
}
uint TracksModel::getSortBy() const
TracksModel::SORTBY TracksModel::getSortBy() const
{
return this->sort;
}
......@@ -52,16 +55,16 @@ void TracksModel::sortList()
switch(role)
{
case FMH::MODEL_KEY::SIZE:
case FMH::MODEL_KEY::RELEASEDATE:
case FMH::MODEL_KEY::RATE:
case FMH::MODEL_KEY::FAV:
{
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();
......@@ -75,7 +78,8 @@ void TracksModel::sortList()
}
case FMH::MODEL_KEY::TITLE:
case FMH::MODEL_KEY::PLACE:
case FMH::MODEL_KEY::ARTIST:
case FMH::MODEL_KEY::ALBUM:
case FMH::MODEL_KEY::FORMAT:
{
const auto str1 = QString(e1[role]).toLower();
......@@ -102,7 +106,7 @@ void TracksModel::setList()
this->list = this->db->getDBData(this->query);
qDebug()<< "my LIST" ;
// this->sortList();
this->sortList();
emit this->postListChanged();
}
......@@ -144,10 +148,27 @@ bool TracksModel::color(const int &index, const QString &color)
auto item = this->list[index];
if(this->db->colorTagTrack(item[FMH::MODEL_KEY::URL], color))
{
item[FMH::MODEL_KEY::COLOR] = color;
list[index][FMH::MODEL_KEY::COLOR] = color;
emit this->updateModel(index, {FMH::MODEL_KEY::COLOR});
return true;
}
return false;
}
bool TracksModel::fav(const int &index, const bool &value)
{
if(index >= this->list.size() || index < 0)
return false;
auto item = this->list[index];
if(this->db->favTrack(item[FMH::MODEL_KEY::URL], value))
{
list[index].insert(FMH::MODEL_KEY::FAV, value ? "1" : "0");
emit this->updateModel(index, {FMH::MODEL_KEY::FAV});
return true;
}
return false;
}
......@@ -9,9 +9,22 @@ class TracksModel : public BaseList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(uint sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(TracksModel::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
enum SORTBY : uint_fast8_t
{
ADDDATE = FMH::MODEL_KEY::ADDDATE,
RELEASEDATE = FMH::MODEL_KEY::RELEASEDATE,
FORMAT = FMH::MODEL_KEY::FORMAT,
ARTIST = FMH::MODEL_KEY::ARTIST,
TITLE = FMH::MODEL_KEY::TITLE,
ALBUM = FMH::MODEL_KEY::ALBUM,
RATE = FMH::MODEL_KEY::RATE,
FAV = FMH::MODEL_KEY::FAV
}; Q_ENUM(SORTBY)
explicit TracksModel(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
......@@ -19,8 +32,8 @@ public:
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const uint &sort);
uint getSortBy() const;
void setSortBy(const TracksModel::SORTBY &sort);
TracksModel::SORTBY getSortBy() const;
private:
CollectionDB *db;
......@@ -29,7 +42,7 @@ private:
void setList();
QString query;
uint sort = FMH::MODEL_KEY::DATE;
TracksModel::SORTBY sort = TracksModel::SORTBY::ADDDATE;
bool addDoc(const FMH::MODEL &doc);
void refreshCollection();
......@@ -43,6 +56,7 @@ public slots:
void append(const QVariantMap &item);
bool color(const int &index, const QString &color);
bool fav(const int &index, const bool &value);
};
#endif // TRACKSMODEL_H
......@@ -102,8 +102,8 @@ void Player::setUrl(const QString &value)
this->url = value;
emit this->urlChanged();
// this->position = 0;
// emit this->positionChanged();
this->pos = 0;
emit this->posChanged();
auto media = QMediaContent(QUrl::fromLocalFile(this->url));
this->player->setMedia(media);
......@@ -135,19 +135,6 @@ int Player::getDuration() const
return static_cast<int>(this->player->duration());
}
void Player::setPosition(const int &value)
{
// this->position = value;
// this->player->setPosition( this->player->duration() / 1000 * position);
// this->emitState();
// this->positionChanged();
}
int Player::getPosition() const
{
return static_cast<int>(this->player->position());
}
Player::STATE Player::getState() const
{
......@@ -178,10 +165,10 @@ bool Player::getFinished()
void Player::setPos(const int &value)
{
this->position = value;
this->player->setPosition( this->player->duration() / 1000 * position);
this->pos = value;
this->player->setPosition( this->player->duration() / 1000 * this->pos);
this->emitState();
this->positionChanged();
this->posChanged();
}
int Player::getPos() const
......@@ -207,9 +194,6 @@ void Player::update()
this->pos = static_cast<int>(static_cast<double>(this->player->position())/this->player->duration()*1000);;
emit this->posChanged();
qDebug() << "Setting value:" << this->position;
}
if(this->player->state() == QMediaPlayer::StoppedState && this->updater->isActive())
......
......@@ -11,7 +11,6 @@ class Player : public QObject
Q_OBJECT
Q_PROPERTY(QString url READ getUrl WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(int volume READ getVolume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(int position READ getPosition WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(Player::STATE state READ getState NOTIFY stateChanged)
Q_PROPERTY(int duration READ getDuration NOTIFY durationChanged)
Q_PROPERTY(bool playing READ getPlaying WRITE setPlaying NOTIFY playingChanged)
......@@ -40,9 +39,6 @@ public:
int getDuration() const;
void setPosition(const int &value);
int getPosition() const;
Player::STATE getState() const;
void setPlaying(const bool &value);
......@@ -63,7 +59,6 @@ private:
QString url;
int volume = 100;
int position = 0;
Player::STATE state = STATE::STOPED;
bool playing = false;
bool finished = false;
......@@ -79,7 +74,7 @@ signals:
void durationChanged();
void urlChanged();
void volumeChanged();
void positionChanged();
void stateChanged();
void playingChanged();
void finishedChanged();
......
......@@ -132,7 +132,7 @@ function quickPlay(track)
{
// root.pageStack.currentIndex = 0
appendTrack(track)
playAt(mainPlaylist.list.count-1)
playAt(mainPlaylist.listView.count-1)
mainPlaylist.listView.positionViewAtEnd()
mainPlaylist.albumsRoll.positionViewAtEnd()
......
......@@ -12,10 +12,14 @@ Maui.Page
property alias listView : babeList
property alias model : babeList.model
property alias delegate : babeList.delegate
property alias count : babeList.count
property alias currentIndex : babeList.currentIndex
property alias currentItem : babeList.currentItem
property alias holder : holder
property alias section : babeList.section
......@@ -86,7 +90,8 @@ Maui.Page
// Scroll is too fast on desktop, see QTBUG-56075
// https://bugreports.qt.io/browse/QTBUG-56075
ScrollHelper {
ScrollHelper
{
enabled: !isMobile
id: scrollHelper
flickable: babeList
......
......@@ -18,9 +18,6 @@ BabeList
id: babeTableRoot
// cacheBuffer : 300
focus: true
property alias list : _tracksList
property alias listModel : _tracksModel
property alias listView : babeTableRoot.listView
......@@ -34,7 +31,7 @@ BabeList
property bool isArtworkRemote : false
property bool showIndicator : false
property string sortBy: "undefined"
property bool group : false
property alias headerMenu: headerMenu
property alias contextMenu : contextMenu
......@@ -55,14 +52,102 @@ BabeList
// altToolBars: true
headBar.leftContent: Maui.ToolButton
{
id : playAllBtn
visible : headBar.visible && count > 0
anim : true
iconName : "media-playlist-play"
onClicked : playAll()
}
onGroupChanged: groupBy()
focus: true
headBar.leftContent: [
Maui.ToolButton
{
id : playAllBtn
visible : headBar.visible && 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("Title")
checkable: true
checked: list.sortBy === Tracks.TITLE
onTriggered: list.sortBy = Tracks.TITLE
}
Maui.MenuItem
{
text: qsTr("Artist")
checkable: true
checked: list.sortBy === Tracks.ARTIST
onTriggered: list.sortBy = Tracks.ARTIST
}
Maui.MenuItem
{
text: qsTr("Album")
checkable: true
checked: list.sortBy === Tracks.ALBUM
onTriggered: list.sortBy = Tracks.ALBUM
}
Maui.MenuItem
{
text: qsTr("Rate")
checkable: true
checked: list.sortBy === Tracks.RATE
onTriggered: list.sortBy = Tracks.RATE
}
Maui.MenuItem
{
text: qsTr("Fav")
checkable: true
checked: list.sortBy === Tracks.FAV
onTriggered: list.sortBy = Tracks.FAV
}
Maui.MenuItem
{
text: qsTr("Release date")
checkable: true
checked: list.sortBy === Tracks.RELEASEDATE
onTriggered: list.sortBy = Tracks.RELEASEDATE
}
Maui.MenuItem
{
text: qsTr("Add date")
checkable: true
checked: list.sortBy === Tracks.ADDDATE
onTriggered: list.sortBy = Tracks.ADDDATE
}
MenuSeparator{}
Maui.MenuItem
{
text: qsTr("Group")
checkable: true
checked: group
onTriggered: group = !group
}
}
}
]
headBar.rightContent: [
......@@ -88,14 +173,6 @@ BabeList
id: headerMenu
onSaveListClicked: saveList()
onQueueListClicked: queueList()
onSortClicked: groupDialog.popup()
}
GroupDialog
{
id: groupDialog
onSortBy: sortBy = babeTableRoot.sortBy = text
}
TableMenu
......@@ -128,8 +205,7 @@ BabeList
onFavClicked:
{
var value = H.faveIt(paths)
model.get(listView.currentIndex).fav = value ? "1" : "0"
list.fav(listView.currentIndex, !(list.get(listView.currentIndex).fav == "1"))
}
onQueueClicked: H.queueIt(paths)
......@@ -151,15 +227,10 @@ BabeList
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);
listView.currentItem.trackMood = color
}
}
......@@ -167,13 +238,20 @@ BabeList
listView.highlightMoveDuration: 0
listView.highlight: Rectangle { }
section.property : sortBy
section.criteria: ViewSection.FullString
section.delegate: Maui.LabelDelegate
{
label: section
isSection: true
boldLabel: true
colorScheme.backgroundColor: "#333"
colorScheme.textColor: "#fafafa"
background: Rectangle
{
color: colorScheme.backgroundColor
}
}
......@@ -186,6 +264,7 @@ BabeList
Tracks
{
id: _tracksList
onSortByChanged: if(babeTableRoot.group) babeTableRoot.groupBy()
}
model: _tracksModel
......@@ -247,10 +326,12 @@ BabeList
{
currentIndex = index
contextMenu.rate = list.get(currentIndex).rate
contextMenu.fav = list.get(currentIndex).fav
contextMenu.fav = list.get(currentIndex).fav == "1"
contextMenu.show([list.get(currentIndex).url])
rowPressed(index)
console.log(list.get(currentIndex).fav)
}
function saveList()
......@@ -297,5 +378,36 @@ BabeList
contextMenu.close()
}
// Component.onCompleted: forceActiveFocus()
function groupBy()
{
var prop = "undefined"
if(group)
switch(list.sortBy)
{
case Tracks.TITLE:
prop = "title"
break
case Tracks.ARTIST:
prop = "artist"
break
case Tracks.ALBUM:
prop = "album"
break
case Tracks.RATE:
prop = "rate"
break
case Tracks.FAV:
prop = "fav"
break
case Tracks.ADDDATE:
prop = "adddate"
break
case Tracks.RELEASEDATE:
prop = "releasedate"
break
}
section.property = prop
}
}
......@@ -12,7 +12,6 @@ Maui.Menu
{
signal saveListClicked()
signal queueListClicked()
signal sortClicked()
property alias menuItem : customItems.children
......@@ -51,15 +50,6 @@ Maui.Menu
MenuSeparator {}
Maui.MenuItem
{
text: "Sort..."
onTriggered:
{
sortClicked()
close()
}
}
Maui.MenuItem
{
......
......@@ -33,7 +33,7 @@ Maui.Menu
Maui.MenuItem
{
text: fav == false ? qsTr("Fav it"): qsTr("UnFav it")
text: !fav ? qsTr("Fav it"): qsTr("UnFav it")
onTriggered:
{
favClicked(paths)
......
......@@ -384,12 +384,11 @@ Maui.Page
value: player.pos
spacing: 0
focus: true
// onMoved:
// {
// player.position = value
// }
onMoved:
{
player.pos = value
}
// onValueChanged: console.log("new value:", value)
background: Rectangle
{
......
......@@ -9,37 +9,37 @@ Maui.Menu
signal callibrate()
signal hideCover()
signal saveToClicked()
MenuItem
Maui.MenuItem
{
text: qsTr("Clear out...")
onTriggered: clearOut()
}
MenuItem
Maui.MenuItem
{
text: qsTr("Clean...")
onTriggered: clean()
}
MenuItem
Maui.MenuItem
{
text: cover.visible ? qsTr("Hide cover...") : qsTr("Show cover...")
onTriggered: hideCover()
}
MenuItem
Maui.MenuItem
{
text: qsTr("Callibrate")
onTriggered: callibrate()
}
MenuItem
Maui.MenuItem
{
text: qsTr("Save list to...")
onTriggered: saveToClicked()
}
MenuItem
Maui.MenuItem
{
enabled: syncPlaylist.length > 0
text: syncPlaylist.length > 0 && sync ? qsTr("Pause syncing") : qsTr("Continue syncing")
......
......@@ -15,7 +15,6 @@ BabeTable
headBarTitle: count + " tracks"
headBarExit: false
coverArtVisible: false
sortBy: "album"
holder.emoji: "qrc:/assets/MusicCloud.png"
holder.isMask: false
holder.title : "No 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