Commit 81829ef8 authored by Camilo Higuita's avatar Camilo Higuita

initial work on info view and work on mobile vs desktop interactions

parent 056ad64b
......@@ -189,7 +189,7 @@ SOURCES += main.cpp \
taglib/fileref.cpp \
taglib/tag.cpp \
taglib/tagunion.cpp \
utils/utils.cpp
babe.cpp
RESOURCES += qml.qrc
......@@ -334,7 +334,7 @@ HEADERS += \
taglib/tagunion.h \
taglib/config.h \
taglib/taglib_config.h \
utils/utils.h
babe.h
#unix:!macx: LIBS += -L$$PWD/3rdparty/taglib/taglib/ -ltag
......
#include "babe.h"
#include <QPalette>
#include <QWidget>
#include <QColor>
#include "db/collectionDB.h"
#include "settings/settings.h"
#include "pulpo/pulpo.h"
using namespace BAE;
Babe::Babe(QObject *parent) : QObject(parent)
{
this->con = new CollectionDB(this);
this->set = new settings(this);
connect(set, &settings::refreshTables, [this](QVariantMap tables)
{
emit this->refreshTables(tables);
});
}
QVariantList Babe::get(const QString &queryTxt)
{
QVariantList res;
for(auto data : this->con->getDBData(queryTxt))
{
QVariantMap map;
for(auto key : data.keys())
map[BAE::KEYMAP[key]] = data[key];
res<<map;
}
return res;
}
QString Babe::trackLyrics(const QString &url)
{
auto track = this->con->getDBData(QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL], url));
if(track.isEmpty()) return "ERROR";
auto lyrics = track.first()[KEY::LYRICS];
if(!lyrics.isEmpty())
return lyrics;
return this->fetchTrackLyrics(track.first());
}
bool Babe::trackBabe(const QString &path)
{
auto babe = this->con->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::BABE],
TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL],path));
if(!babe.isEmpty())
return babe.first()[KEY::BABE].toInt();
return false;
}
QString Babe::artistArt(const QString &artist)
{
auto artwork = this->con->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::ARTWORK],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
if(!artwork.isEmpty())
if(!artwork.first()[KEY::ARTWORK].isEmpty() && artwork.first()[KEY::ARTWORK] != SLANG[W::NONE])
return artwork.first()[KEY::ARTWORK];
return "";
}
QString Babe::artistWiki(const QString &artist)
{
auto wiki = this->con->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::WIKI],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
if(!wiki.isEmpty())
return wiki.first()[KEY::WIKI];
return "";
}
QString Babe::albumArt(const QString &album, const QString &artist)
{
auto queryStr = QString("SELECT %1 FROM %2 WHERE %3 = \"%4\" AND %5 = \"%6\"").arg(KEYMAP[KEY::ARTWORK],
TABLEMAP[TABLE::ALBUMS],
KEYMAP[KEY::ALBUM],album,
KEYMAP[KEY::ARTIST],artist);
auto albumCover = this->con->getDBData(queryStr);
if(!albumCover.isEmpty())
if(!albumCover.first()[KEY::ARTWORK].isEmpty() && albumCover.first()[KEY::ARTWORK] != SLANG[W::NONE])
return albumCover.first()[KEY::ARTWORK];
return "";
}
QString Babe::fetchTrackLyrics(DB &song)
{
Pulpo pulpo;
pulpo.registerServices({SERVICES::LyricWikia, SERVICES::Genius});
pulpo.setOntology(PULPO::ONTOLOGY::TRACK);
pulpo.setInfo(PULPO::INFO::LYRICS);
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
timer.setInterval(1000);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&pulpo, &Pulpo::infoReady, [&](const BAE::DB &track, const PULPO::RESPONSE &res)
{
if(!res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS].isEmpty())
{
auto lyrics = res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS][PULPO::CONTEXT::LYRIC].toString();
this->con->lyricsTrack(track, lyrics);
song.insert(KEY::LYRICS, lyrics);
}
loop.quit();
});
pulpo.feed(song, PULPO::RECURSIVE::OFF);
timer.start();
loop.exec();
timer.stop();
return song[KEY::LYRICS];
}
QString Babe::albumWiki(const QString &album, const QString &artist)
{
auto queryStr = QString("SELECT %1 FROM %2 WHERE %3 = \"%4\" AND %5 = \"%6\"").arg(KEYMAP[KEY::WIKI],
TABLEMAP[TABLE::ALBUMS],
KEYMAP[KEY::ALBUM],album,
KEYMAP[KEY::ARTIST],artist);
auto wiki = this->con->getDBData(queryStr);
if(!wiki.isEmpty())
return wiki.first()[KEY::WIKI];
return "";
}
bool Babe::babeTrack(const QString &path, const bool &value)
{
if(this->con->update(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::BABE],
value ? 1 : 0,
KEYMAP[KEY::URL],
path)) return true;
return false;
}
void Babe::scanDir(const QString &url)
{
emit this->set->collectionPathChanged(url);
}
void Babe::savePlaylist(const QStringList &list)
{
BAE::saveSettings("PLAYLIST", list, "MAINWINDOW");
}
QStringList Babe::lastPlaylist()
{
return BAE::loadSettings("PLAYLIST","MAINWINDOW",{}).toStringList();
}
void Babe::savePlaylistPos(const int &pos)
{
BAE::saveSettings("PLAYLIST_POS", pos, "MAINWINDOW");
}
int Babe::lastPlaylistPos()
{
return BAE::loadSettings("PLAYLIST_POS","MAINWINDOW",QVariant(0)).toInt();
}
QString Babe::backgroundColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Background).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Babe::foregroundColor()
{
#if defined(Q_OS_ANDROID)
return "#FFF";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Text).name();
#elif defined(Q_OS_WIN32)
return "#FFF";
#endif
}
QString Babe::hightlightColor()
{
#if defined(Q_OS_ANDROID)
return "";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Highlight).name();
#elif defined(Q_OS_WIN32)
return "";
#endif
}
QString Babe::midColor()
{
#if defined(Q_OS_ANDROID)
return "#31363b";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Midlight).name();
#elif defined(Q_OS_WIN32)
return "#31363b";
#endif
}
QString Babe::altColor()
{
#if defined(Q_OS_ANDROID)
return "#232629";
#elif defined(Q_OS_LINUX)
QWidget widget;
return widget.palette().color(QPalette::Base).name();
#elif defined(Q_OS_WIN32)
return "#232629";
#endif
}
QString Babe::babeColor()
{
return "#E91E63";
}
QString Babe::loadCover(const QString &url)
{
auto map = this->con->getDBData(QStringList() << url);
if(map.isEmpty()) return "";
auto track = map.first();
auto artist = track[KEY::ARTIST];
auto album = track[KEY::ALBUM];
auto title = track[KEY::TITLE];
auto artistImg = this->artistArt(artist);
auto albumImg = this->albumArt(album, artist);
if(!albumImg.isEmpty())
return albumImg;
else if (!artistImg.isEmpty())
return artistImg;
else
return this->fetchCoverArt(track);
}
QString Babe::fetchCoverArt(DB &song)
{
if(BAE::artworkCache(song, KEY::ALBUM)) return song[KEY::ARTWORK];
if(BAE::artworkCache(song, KEY::ARTIST)) return song[KEY::ARTWORK];
Pulpo pulpo;
pulpo.registerServices({SERVICES::LastFm, SERVICES::Spotify});
pulpo.setOntology(PULPO::ONTOLOGY::ALBUM);
pulpo.setInfo(PULPO::INFO::ARTWORK);
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
timer.setInterval(1000);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&pulpo, &Pulpo::infoReady, [&](const BAE::DB &track,const PULPO::RESPONSE &res)
{
Q_UNUSED(track);
if(!res[PULPO::ONTOLOGY::ALBUM][PULPO::INFO::ARTWORK].isEmpty())
{
auto artwork = res[PULPO::ONTOLOGY::ALBUM][PULPO::INFO::ARTWORK][PULPO::CONTEXT::IMAGE].toByteArray();
BAE::saveArt(song, artwork, BAE::CachePath);
}
loop.quit();
});
pulpo.feed(song, PULPO::RECURSIVE::OFF);
timer.start();
loop.exec();
timer.stop();
return song[KEY::ARTWORK];
}
#ifndef BABE_H
#define BABE_H
#include <QObject>
#include <QVariantList>
#include "utils/bae.h"
class CollectionDB;
class Pulpo;
class settings;
using namespace BAE;
class Babe : public QObject
{
Q_OBJECT
public:
explicit Babe(QObject *parent = nullptr);
/* DATABASE INTERFACES */
Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE QString trackLyrics(const QString &url);
Q_INVOKABLE bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist);
Q_INVOKABLE QString albumArt(const QString &album, const QString &artist);
Q_INVOKABLE QString artistWiki(const QString &artist);
Q_INVOKABLE QString albumWiki(const QString &album, const QString &artist);
Q_INVOKABLE bool babeTrack(const QString &path, const bool &value);
/* SETTINGS */
Q_INVOKABLE void scanDir(const QString &url);
/* STATIC METHODS */
Q_INVOKABLE static void savePlaylist(const QStringList &list);
Q_INVOKABLE static QStringList lastPlaylist();
Q_INVOKABLE static void savePlaylistPos(const int &pos);
Q_INVOKABLE static int lastPlaylistPos();
Q_INVOKABLE static QString backgroundColor();
Q_INVOKABLE static QString foregroundColor();
Q_INVOKABLE static QString hightlightColor();
Q_INVOKABLE static QString midColor();
Q_INVOKABLE static QString altColor();
Q_INVOKABLE static QString babeColor();
/*USEFUL*/
Q_INVOKABLE QString loadCover(const QString &url);
private:
CollectionDB *con;
settings *set;
QString fetchCoverArt(DB &song);
QString fetchTrackLyrics(DB &song);
signals:
void refreshTables(QVariantMap tables);
public slots:
};
#endif // BABE_H
......@@ -31,7 +31,6 @@ CollectionDB::CollectionDB(QObject *parent) : QObject(parent)
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << BAE::CollectionDBPath + BAE::DBName;
this->prepareCollectionDB();
emit this->initDB(BAE::MusicPath);
}else this->openDB(this->name);
}
......@@ -315,15 +314,6 @@ bool CollectionDB::rateTrack(const QString &path, const int &value)
return false;
}
bool CollectionDB::babeTrack(const QString &path, const bool &value)
{
if(update(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::BABE],
value?1:0,
KEYMAP[KEY::URL],
path)) return true;
return false;
}
bool CollectionDB::moodTrack(const QString &path, const QString &value)
{
......@@ -537,21 +527,6 @@ DB_LIST CollectionDB::getDBData(const QStringList &urls)
return mapList;
}
QVariantList CollectionDB::get(const QString &queryTxt)
{
QVariantList res;
for(auto data : this->getDBData(queryTxt))
{
QVariantMap map;
for(auto key : data.keys())
map[BAE::KEYMAP[key]] = data[key];
res<<map;
}
return res;
}
DB_LIST CollectionDB::getDBData(const QString &queryTxt)
{
DB_LIST mapList;
......@@ -713,19 +688,6 @@ DB_LIST CollectionDB::getMostPlayedTracks(const int &greaterThan, const int &lim
return this->getDBData(queryTxt);
}
QString CollectionDB::getTrackLyrics(const QString &url)
{
QString lyrics;
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::LYRICS],
TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL],url));
for(auto track : query)
lyrics = track[KEY::LYRICS];
return lyrics;
}
QString CollectionDB::getTrackArt(const QString &path)
{
......@@ -759,47 +721,6 @@ int CollectionDB::getTrackStars(const QString &path)
return stars;
}
bool CollectionDB::getTrackBabe(const QString &path)
{
int babe = 0;
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::BABE],
TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL],path));
for(auto track : query)
babe = track[KEY::BABE].toInt();
return babe == 0 ? false : true ;
}
QString CollectionDB::getArtistArt(const QString &artist)
{
QString artistHead;
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::ARTWORK],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
for(auto track : query)
if(!track[KEY::ARTWORK].isEmpty() && track[KEY::ARTWORK] != SLANG[W::NONE])
artistHead = track[KEY::ARTWORK];
return artistHead;
}
QString CollectionDB::getArtistWiki(const QString &artist)
{
QString wiki;
auto query = this->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::WIKI],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
for(auto track : query)
wiki = track[KEY::WIKI];
return wiki;
}
//QStringList CollectionDB::getArtistTags(const QString &artist)
//{
// QStringList tags;
......@@ -820,36 +741,6 @@ QString CollectionDB::getArtistWiki(const QString &artist)
// return tags;
//}
QString CollectionDB::getAlbumArt(const QString &album, const QString &artist)
{
QString albumCover;
auto queryStr = QString("SELECT %1 FROM %2 WHERE %3 = \"%4\" AND %5 = \"%6\"").arg(KEYMAP[KEY::ARTWORK],
TABLEMAP[TABLE::ALBUMS],
KEYMAP[KEY::ALBUM],album,
KEYMAP[KEY::ARTIST],artist);
auto query = this->getDBData(queryStr);
for(auto track : query)
if(!track[KEY::ARTWORK].isEmpty() && track[KEY::ARTWORK] != SLANG[W::NONE])
albumCover = track[KEY::ARTWORK];
return albumCover;
}
QString CollectionDB::getAlbumWiki(const QString &album, const QString &artist)
{
QString wiki;
auto queryStr = QString("SELECT %1 FROM %2 WHERE %3 = \"%4\" AND %5 = \"%6\"").arg(KEYMAP[KEY::WIKI],
TABLEMAP[TABLE::ALBUMS],
KEYMAP[KEY::ALBUM],album,
KEYMAP[KEY::ARTIST],artist);
auto query = this->getDBData(queryStr);
for(auto track : query)
wiki = track[KEY::WIKI];
return wiki;
}
//QStringList CollectionDB::getAlbumTags(const QString &album, const QString &artist)
//{
......@@ -898,7 +789,7 @@ bool CollectionDB::removeTrack(const QString &path)
}
QSqlQuery CollectionDB::getQuery(const QString &queryTxt)
{
{
QSqlQuery query(queryTxt, this->m_db);
return query;
}
......
......@@ -25,9 +25,13 @@ class CollectionDB : public QObject
Q_OBJECT
public:
explicit CollectionDB(QObject *parent = nullptr);
explicit CollectionDB( QObject *parent = nullptr);
~CollectionDB() override;
bool insert(const QString &tableName, const QVariantMap &insertData);
bool update(const QString &tableName, const BAE::DB &updateData, const QVariantMap &where);
bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
bool remove();
bool execQuery(QSqlQuery &query) const;
bool execQuery(const QString &queryTxt);
......@@ -43,7 +47,6 @@ public:
void addTrack(const BAE::DB &track);
bool updateTrack(const BAE::DB &track);
bool rateTrack(const QString &path, const int &value);
Q_INVOKABLE bool babeTrack(const QString &path, const bool &value);
bool moodTrack(const QString &path, const QString &value);
bool artTrack(const QString &path, const QString &value);
bool lyricsTrack(const BAE::DB &track, const QString &value);
......@@ -64,8 +67,7 @@ public:
bool trackPlaylist(const QString &url, const QString &playlist);
BAE::DB_LIST getDBData(const QStringList &urls);
Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE BAE::DB_LIST getDBData(const QString &queryTxt);
BAE::DB_LIST getDBData(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);
......@@ -78,17 +80,11 @@ public:
BAE::DB_LIST getOnlineTracks(const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
QString getTrackLyrics(const QString &url);
QString getTrackArt(const QString &path);
QStringList getTrackTags(const QString &path);
int getTrackStars(const QString &path);
Q_INVOKABLE bool getTrackBabe(const QString &path);
Q_INVOKABLE QString getArtistArt(const QString &artist);
QString getArtistWiki(const QString &artist);
// QStringList getArtistTags(const QString &artist);
Q_INVOKABLE QString getAlbumArt(const QString &album, const QString &artist);
QString getAlbumWiki(const QString &album, const QString &artist);
// QStringList getAlbumTags(const QString &album, const QString &artist);
// QStringList getArtistTags(const QString &artist);
// QStringList getAlbumTags(const QString &album, const QString &artist);
QStringList getArtistAlbums(const QString &artist);
QStringList getPlaylists();
......@@ -110,10 +106,7 @@ private:
QString name;
QSqlDatabase m_db;
/*basic actions*/
bool insert(const QString &tableName, const QVariantMap &insertData);
bool update(const QString &tableName, const BAE::DB &updateData, const QVariantMap &where);
bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
bool remove();
public slots:
void closeConnection();
......@@ -126,7 +119,6 @@ signals:
void albumsCleaned(const int &amount);
void artistsCleaned(const int &amount);
void initDB(QString musicPath);
};
#endif // COLLECTION_H
......@@ -2,10 +2,8 @@
#include <QFontDatabase>
#include <QQmlContext>
#include <QApplication>
#include "db/collectionDB.h"
#include "utils/bae.h"
#include "utils/utils.h"
#include "settings/settings.h"
#include "babe.h"
#include "services/local/player.h"
#include <QLibrary>
//#ifdef Q_OS_ANDROID
......@@ -20,22 +18,20 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/utils/materialdesignicons-webfont.ttf");
QQmlApplicationEngine engine;
QQmlApplicationEngine engine;
auto context = engine.rootContext();
CollectionDB con;
settings settings;
Babe bae;
Player player;
Utils util;
context->setContextProperty("con", &con);
context->setContextProperty("set", &settings);
context->setContextProperty("bae", &bae);
context->setContextProperty("player", &player);
context->setContextProperty("util", &util);
//#ifdef Q_OS_ANDROID
// KirigamiPlugin::getInstance().registerTypes();
//#endif
//#ifdef Q_OS_ANDROID
// KirigamiPlugin::getInstance().registerTypes();
//#endif
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
......
......@@ -54,7 +54,7 @@ ApplicationWindow
Connections
{
target: set
target: bae
onRefreshTables:
{
tracksView.clearTable()
......@@ -87,14 +87,14 @@ ApplicationWindow
id: searchBox
width: parent.width
height: 32
color: util.midColor()
color: bae.midColor()
TextInput
{
id: searchInput
anchors.fill: parent
anchors.centerIn: parent
color: util.foregroundColor()
color: bae.foregroundColor()
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
......@@ -108,7 +108,7 @@ ApplicationWindow
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.bold: true
color: util.foregroundColor()
color: bae.foregroundColor()
}
}
......@@ -117,7 +117,7 @@ ApplicationWindow
Rectangle
{
anchors.fill: parent
color: util.altColor()
color: bae.altColor()
z: -999
}
......@@ -176,12 +176,7 @@ ApplicationWindow
onRowClicked: Player.appendTrack(track)
onPlayAlbum: Player.playAlbum(tracks)
onAppendAlbum: Player.appendAlbum(tracks)
onPlayTrack:
{
Player.appendTrack(track)
Player.playAt(mainPlaylist.list.count-1)
currentView = 0
}
onPlayTrack: Player.quickPlay(track)
}