Commit 105501ee authored by Camilo Higuita's avatar Camilo Higuita

collect db data directly, ui fixes on settings view, scale ui on mobile devices with small screens

parent 53c0407e
......@@ -10,7 +10,7 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QDirIterator>
#include <QtQml>
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif
......@@ -19,6 +19,7 @@ using namespace BAE;
Babe::Babe(QObject *parent) : QObject(parent)
{
qDebug()<<"CONSTRUCTING ABE INTERFACE";
this->con = new CollectionDB(this);
this->set = new settings(this);
......@@ -52,7 +53,7 @@ Babe::~Babe()
QVariantList Babe::get(const QString &queryTxt)
{
return Babe::transformData(this->con->getDBData(queryTxt));
return this->con->getDBDataQML(queryTxt);
}
QVariantList Babe::getList(const QStringList &urls)
......@@ -320,6 +321,11 @@ int Babe::cursorPos(QString &axis)
else return 0;
}
QString Babe::homeDir()
{
return BAE::MusicPath;
}
QVariantList Babe::getDirs(const QString &pathUrl)
{
auto path = pathUrl;
......@@ -339,7 +345,6 @@ QVariantList Babe::getDirs(const QString &pathUrl)
QVariantMap map = { {"url", url }, {"name", name} };
paths << map;
}
}
return paths;
......@@ -347,7 +352,31 @@ QVariantList Babe::getDirs(const QString &pathUrl)
QVariantMap Babe::getParentDir(const QString &path)
{
return {{"url",QFileInfo(path).dir().absolutePath()}, {"name", QFileInfo(path).dir().dirName()}};
auto dirUrl = QFileInfo(path).dir().absolutePath();
auto dir = QDir(dirUrl);
if(dir.exists() && dir.isReadable() && !dir.isRoot())
return {{"url", dirUrl}, {"name", QFileInfo(path).dir().dirName()}};
else
return {{"url", path}, {"name", QDir(path).dirName()}};
}
void Babe::registerTypes()
{
qmlRegisterUncreatableType<Babe>("Babe", 1, 0, "Babe", "ERROR ABE");
}
uint Babe::sizeHint(const uint &hint)
{
if(hint>=BAE::BIG_ALBUM_FACTOR)
return BAE::getWidgetSizeHint(BAE::AlbumSizeHint::BIG_ALBUM);
else if(hint>=BAE::MEDIUM_ALBUM_FACTOR)
return BAE::getWidgetSizeHint(BAE::AlbumSizeHint::MEDIUM_ALBUM);
else if(hint>=BAE::SMALL_ALBUM_FACTOR)
return BAE::getWidgetSizeHint(BAE::AlbumSizeHint::SMALL_ALBUM);
else return hint;
}
QString Babe::loadCover(const QString &url)
......@@ -364,10 +393,9 @@ QString Babe::loadCover(const QString &url)
auto artistImg = this->artistArt(artist);
auto albumImg = this->albumArt(album, artist);
if(!albumImg.isEmpty())
if(!albumImg.isEmpty() && albumImg != BAE::SLANG[W::NONE])
return albumImg;
else if (!artistImg.isEmpty())
else if (!artistImg.isEmpty() && artistImg != BAE::SLANG[W::NONE])
return artistImg;
else
return this->fetchCoverArt(track);
......@@ -375,8 +403,8 @@ QString Babe::loadCover(const QString &url)
QVariantList Babe::searchFor(const QStringList &queries)
{
BAE::DB_LIST mapList;
bool hasKey=false;
QVariantList mapList;
bool hasKey = false;
for(auto searchQuery : queries)
{
......@@ -388,7 +416,7 @@ QVariantList Babe::searchFor(const QStringList &queries)
searchQuery=searchQuery.replace(BAE::SearchTMap[BAE::SearchT::LIKE]+":","").trimmed();
searchQuery=searchQuery.trimmed();
searchQuery = searchQuery.trimmed();
if(!searchQuery.isEmpty())
{
mapList += this->con->getSearchedTracks(BAE::KEY::WIKI, searchQuery);
......@@ -401,7 +429,7 @@ QVariantList Babe::searchFor(const QStringList &queries)
searchQuery=searchQuery.replace(BAE::SearchTMap[BAE::SearchT::SIMILAR]+":","").trimmed();
searchQuery=searchQuery.trimmed();
if(!searchQuery.isEmpty())
mapList += this->con->getSearchedTracks(BAE::KEY::TAG,searchQuery);
mapList += this->con->getSearchedTracks(BAE::KEY::TAG, searchQuery);
}else
{
......@@ -415,7 +443,7 @@ QVariantList Babe::searchFor(const QStringList &queries)
{
hasKey=true;
key=k.key();
searchQuery=searchQuery.replace(k.value()+":","").trimmed();
searchQuery = searchQuery.replace(k.value()+":","").trimmed();
}
}
......@@ -429,13 +457,13 @@ QVariantList Babe::searchFor(const QStringList &queries)
else
{
auto queryTxt = QString("SELECT * FROM tracks WHERE title LIKE \"%"+searchQuery+"%\" OR artist LIKE \"%"+searchQuery+"%\" OR album LIKE \"%"+searchQuery+"%\"OR genre LIKE \"%"+searchQuery+"%\"OR url LIKE \"%"+searchQuery+"%\" LIMIT 1000");
mapList += this->con->getDBData(queryTxt);
mapList += this->con->getDBDataQML(queryTxt);
}
}
}
}
return this->transformData(mapList);
return mapList;
}
QString Babe::fetchCoverArt(DB &song)
......
......@@ -23,6 +23,14 @@ public:
explicit Babe(QObject *parent = nullptr);
~Babe();
enum class HINT : uint
{
BIG_ALBUM = 200,
MEDIUM_ALBUM = 120,
SMALL_ALBUM = 80
};
Q_ENUM(HINT)
/* DATABASE INTERFACES */
Q_INVOKABLE QVariantList get(const QString &queryTxt);
......@@ -64,11 +72,12 @@ public:
Q_INVOKABLE static int screenGeometry(QString &side);
Q_INVOKABLE static int cursorPos(QString &axis);
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
static void registerTypes();
Q_INVOKABLE static uint sizeHint(const uint &hint);
/*USEFUL*/
Q_INVOKABLE QString loadCover(const QString &url);
......
......@@ -550,6 +550,29 @@ DB_LIST CollectionDB::getDBData(const QString &queryTxt)
return mapList;
}
QVariantList CollectionDB::getDBDataQML(const QString &queryTxt)
{
QVariantList mapList;
auto query = this->getQuery(queryTxt);
if(query.exec())
{
while(query.next())
{
QVariantMap data;
for(auto key : KEYMAP.keys())
if(query.record().indexOf(KEYMAP[key])>-1)
data[BAE::KEYMAP[key]] = query.value(KEYMAP[key]).toString();
mapList<< data;
}
}else qDebug()<< query.lastError()<< query.lastQuery();
return mapList;
}
DB_LIST CollectionDB::getAlbumTracks(const QString &album, const QString &artist, const KEY &orderBy, const BAE::W &order)
{
......@@ -589,7 +612,7 @@ DB_LIST CollectionDB::getBabedTracks(const KEY &orderBy, const BAE::W &order)
return this->getDBData(queryTxt);
}
DB_LIST CollectionDB::getSearchedTracks(const KEY &where, const QString &search)
QVariantList CollectionDB::getSearchedTracks(const KEY &where, const QString &search)
{
QString queryTxt;
......@@ -640,7 +663,7 @@ DB_LIST CollectionDB::getSearchedTracks(const KEY &where, const QString &search)
qDebug()<<"SEARCH QUERY:"<<queryTxt;
return this->getDBData(queryTxt);
return this->getDBDataQML(queryTxt);
}
......
......@@ -68,11 +68,12 @@ public:
BAE::DB_LIST getDBData(const QStringList &urls);
BAE::DB_LIST getDBData(const QString &queryTxt);
QVariantList getDBDataQML(const QString &queryTxt);
BAE::DB_LIST getAlbumTracks(const QString &album, const QString &artist, const BAE::KEY &orderBy = BAE::KEY::TRACK, const BAE::W &order = BAE::W::ASC);
BAE::DB_LIST getArtistTracks(const QString &artist, const BAE::KEY &orderBy = BAE::KEY::ALBUM, const BAE::W &order = BAE::W::ASC);
BAE::DB_LIST getBabedTracks(const BAE::KEY &orderBy = BAE::KEY::PLAYED, const BAE::W &order = BAE::W::DESC);
BAE::DB_LIST getSearchedTracks(const BAE::KEY &where, const QString &search);
QVariantList getSearchedTracks(const BAE::KEY &where, const QString &search);
BAE::DB_LIST getPlaylistTracks(const QString &playlist, const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
BAE::DB_LIST getMostPlayedTracks(const int &greaterThan = 1,const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::PLAYED, const BAE::W &order = BAE::W::DESC);
BAE::DB_LIST getFavTracks(const int &stars = 1,const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::STARS, const BAE::W &order = BAE::W::DESC);
......
......@@ -42,9 +42,14 @@ id INTEGER PRIMARY KEY ,
name TEXT NOT NULL
) ;
CREATE TABLE FOLDERS
(
url TEXT PRIMARY KEY
) ;
CREATE TABLE SOURCES
(
url TEXT PRIMARY KEY ,
url TEXT PRIMARY KEY ,
SOURCE_TYPES_id INTEGER NOT NULL,
FOREIGN KEY(SOURCE_TYPES_id) REFERENCES SOURCES_TYPES(id)
) ;
......
......@@ -6,13 +6,14 @@
#include "babe.h"
#include "services/local/player.h"
#include <QLibrary>
//#ifdef Q_OS_ANDROID
//#include "./3rdparty/kirigami/src/kirigamiplugin.h"
//#endif
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
......@@ -24,9 +25,9 @@ int main(int argc, char *argv[])
Babe bae;
Player player;
// bae.registerTypes();
context->setContextProperty("bae", &bae);
context->setContextProperty("player", &player);
//#ifdef Q_OS_ANDROID
......
......@@ -25,7 +25,7 @@ ApplicationWindow
// property int columnWidth: Kirigami.Units.gridUnit * 13
property int columnWidth: 250
property int columnWidth: Math.sqrt(root.width*root.height)*0.4
property int currentView : 0
property int iconSize
property alias mainPlaylist : mainPlaylist
......@@ -103,7 +103,21 @@ ApplicationWindow
onAlbumsViewClicked: currentView = 2
onArtistsViewClicked: currentView = 3
onPlaylistsViewClicked: currentView = 4
onSettingsViewClicked: currentView = 5
onSettingsViewClicked:
{
if(settingsDrawer.visible )
{
settingsDrawer.close()
settingsIcon.color = textColor
}
else
{
settingsDrawer.open()
settingsIcon.color = accentColor
}
}
}
footer: Rectangle
......@@ -165,6 +179,15 @@ ApplicationWindow
z: -999
}
SettingsView
{
id: settingsDrawer
onIconSizeChanged: iconSize = size
}
Page
{
id: views
......@@ -172,6 +195,10 @@ ApplicationWindow
height: parent.height
clip: true
transform: Translate {
x: (settingsDrawer.position * views.width * 0.33)*-1
}
Column
{
width: parent.width
......@@ -243,10 +270,6 @@ ApplicationWindow
PlaylistsView {}
SettingsView
{
onIconSizeChanged: iconSize = size
}
SearchTable
{
......
......@@ -99,13 +99,13 @@ settings::settings(QObject *parent) : QObject(parent)
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
this->startBrainz(500);
this->startBrainz(1000);
}else
{
this->dirs.clear();
this->collectionWatcher();
this->watcher->removePaths(watcher->directories());
this->startBrainz(1500);
this->startBrainz(2000);
}
......@@ -209,7 +209,7 @@ void settings::checkCollection()
// this->refreshCollectionPaths();
// this->collectionWatcher();
this->brainzOn = true;
this->startBrainz(1500);
this->startBrainz(2000);
}
void settings::startBrainz(const int &speed)
......@@ -219,7 +219,6 @@ void settings::startBrainz(const int &speed)
this->brainDeamon->setInterval(speed);
this->brainDeamon->start();
}
}
void settings::populateDB(const QStringList &paths)
......
......@@ -7,7 +7,10 @@ function playTrack(track)
player.source(root.mainPlaylist.currentTrack.url);
player.play()
root.title = root.mainPlaylist.currentTrack.title + " - " +root.mainPlaylist.currentTrack.artist
root.mainPlaylist.currentArtwork = root.mainPlaylist.currentTrack.artwork || bae.loadCover(root.mainPlaylist.currentTrack.url)
var artwork = root.mainPlaylist.currentTrack.artwork
root.mainPlaylist.currentArtwork = artwork ? artwork : bae.loadCover(root.mainPlaylist.currentTrack.url)
if(!root.active)
bae.notifySong(root.mainPlaylist.currentTrack.url)
......
......@@ -10,7 +10,8 @@
#include <QTime>
#include <QSettings>
#include <QDirIterator>
#include <QApplication>
#include <QScreen>
#include <cmath>
using namespace std;
......@@ -178,14 +179,7 @@ namespace BAE
{KEY::ART, KEYMAP[KEY::ART]}
};
enum class AlbumSizeHint : uint
{
BIG_ALBUM = 200,
MEDIUM_ALBUM = 120,
SMALL_ALBUM = 80
};
inline QString transformTime(const qint64 &value)
inline QString transformTime(const qint64 &value)
{
QString tStr;
if (value)
......@@ -413,6 +407,46 @@ namespace BAE
return false;
#endif
}
enum class AlbumSizeHint : uint
{
BIG_ALBUM = 200,
MEDIUM_ALBUM = 120,
SMALL_ALBUM = 80
};
static const uint MAX_BIG_ALBUM_SIZE = 300;
static const uint MAX_MID_ALBUM_SIZE = 200;
static const uint MAX_MIN_ALBUM_SIZE = 100;
typedef double ALBUM_FACTOR;
static const ALBUM_FACTOR BIG_ALBUM_FACTOR = 0.039;
static const ALBUM_FACTOR BIG_ALBUM_FACTOR_SUBWIDGET = 0.27;
static const ALBUM_FACTOR MEDIUM_ALBUM_FACTOR = 0.013;
static const ALBUM_FACTOR MEDIUM_ALBUM_FACTOR_SUBWIDGET = 0.4;
static const ALBUM_FACTOR SMALL_ALBUM_FACTOR = 0.006;
static const ALBUM_FACTOR SMALL_ALBUM_FACTOR_SUBWIDGET = 0.5;
inline uint getWidgetSizeHint(const AlbumSizeHint &deafultValue)
{
QScreen *screenSize = QApplication::screens().at(0);
auto screen = static_cast<uint>(sqrt((screenSize->availableSize().height()*screenSize->availableSize().width())));
switch(deafultValue)
{
case AlbumSizeHint::BIG_ALBUM:
return screen * 0.3 ;
case AlbumSizeHint::MEDIUM_ALBUM:
return screen * 0.1 ;
case AlbumSizeHint::SMALL_ALBUM:
return screen * 0.05 ;
}
}
}
......
......@@ -3,6 +3,9 @@ import QtQuick 2.9
Pane
{
id: gridPage
property int albumSize : 150
property int albumSpacing: 20
property int borderRadius : 4
......@@ -13,7 +16,7 @@ Pane
width: 500
height: 400
id: gridPage
background: Rectangle
{
......@@ -86,6 +89,7 @@ Pane
{
id: delegate
albumSize : gridPage.albumSize
Connections
{
target: delegate
......
......@@ -7,13 +7,10 @@ Rectangle
{
property string emoji
property string message
clip: true
anchors.fill: parent
color: bae.backgroundColor()
anchors.fill: parent
color: "transparent"
GridLayout
{
......
......@@ -101,8 +101,8 @@ ListView
onClicked:
{
list.rowClicked(index)
currentIndex = index
list.rowClicked(index)
}
onPlay: list.quickPlayTrack(index)
......
......@@ -11,7 +11,7 @@ BabeGrid
{
id: albumsViewGrid
visible: true
albumSize: 150
albumSize:Math.sqrt(root.width*root.height)*0.25
borderRadius: 20
signal rowClicked(var track)
......
......@@ -11,7 +11,7 @@ BabeGrid
{
id:artistsViewGrid
visible: true
albumSize: 150
albumSize:Math.sqrt(root.width*root.height)*0.25
borderRadius: 20
signal rowClicked(var track)
......
......@@ -8,6 +8,7 @@ import "../utils"
ToolBar
{
property alias babeBar : babeBar
property alias settingsIcon : settingsIcon
property string accentColor : bae.babeColor()
property string textColor : bae.foregroundColor()
property string backgroundColor : bae.backgroundColor()
......@@ -162,7 +163,7 @@ ToolBar
{
id: settingsIcon
text: MdiFont.Icon.settings
color: currentIndex === 5? accentColor : textColor
color: textColor
iconSize: size
}
......
......@@ -181,12 +181,6 @@ Page
}
}
}
}
......@@ -36,27 +36,24 @@ Item
Rectangle
{
anchors.fill: parent
color: bae.altColor()
color: bae.midColor()
z: -999
}
GridLayout
ColumnLayout
{
id: playlistLayout
width: parent.width
height: parent.height
columns: 1
rows: 4
rowSpacing: 0
anchors.fill: parent
Rectangle
{
id: cover
Layout.row: 1
height: columnWidth
width: parent.width
Layout.preferredHeight: columnWidth
Layout.minimumHeight: columnWidth
Layout.maximumHeight: columnWidth
Layout.fillWidth: true
color: bae.altColor()
visible: list.count>0
FastBlur
......@@ -112,69 +109,19 @@ Item
}
Slider
{
id: progressBar
Layout.fillWidth: true
Layout.row: 3
height: 16
from: 0
to: 1000
value: 0
visible: list.count>0
spacing: 0
onMoved: player.seek(player.duration() / 1000 * value);
Rectangle
{
anchors.fill: parent
color: bae.midColor()
z: -999
}
background: Rectangle
{
x: progressBar.leftPadding
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 2
width: progressBar.availableWidth
height: implicitHeight
color: bae.foregroundColor()
Rectangle
{
width: progressBar.visualPosition * parent.width
height: parent.height
color: bae.babeColor()
}
}
handle: Rectangle
{
x: progressBar.leftPadding + progressBar.visualPosition * (progressBar.availableWidth - width)
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
implicitWidth: 16
implicitHeight: 16
radius: 13
color: bae.babeColor()
}
}
Rectangle
{
id: playbackControls
Layout.fillWidth: true
Layout.row: 2
height: 48
Layout.preferredHeight: 48
Layout.minimumHeight: 48
Layout.maximumHeight: 48
visible: list.count>0
color: bae.midColor()
onYChanged:
{
if(playbackControls.y<columnWidth/4)
{
cover.visible = false
......@@ -308,13 +255,64 @@ Item
}
}
Rectangle
{
Layout.fillWidth: true
Layout.preferredHeight: 22
Layout.minimumHeight: 22
Layout.maximumHeight: 22
color: "transparent"
Slider
{
id: progressBar
anchors.fill: parent
from: 0
to: 1000
value: 0
visible: list.count>0
spacing: 0
onMoved: player.seek(player.duration() / 1000 * value);
background: Rectangle
{
x: progressBar.leftPadding
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 2
width: progressBar.availableWidth
height: implicitHeight
color: bae.foregroundColor()
Rectangle
{
width: progressBar.visualPosition * parent.width
height: parent.height
color: bae.babeColor()
}
}
handle: Rectangle
{
x: progressBar.leftPadding + progressBar.visualPosition * (progressBar.availableWidth - width)
y: progressBar.topPadding + progressBar.availableHeight / 2 - height / 2
implicitWidth: 16
implicitHeight: 16
radius: 13
color: bae.babeColor()
}
}
}
Rectangle
{
id: mainPlaylist
Layout.fillWidth: true
Layout.fillHeight: true
Layout.row: 4
color: "transparent"
color: bae.altColor()
StackView
{
......@@ -323,37 +321,37 @@ Item
focus: true
pushEnter: Transition {
PropertyAnimation {
property: "opacity"
from: 0