Commit 34b67bad authored by Camilo higuita's avatar Camilo higuita

migration to mauikit fm interfacesfor modeling data is now done

parent 46b8eab9
......@@ -43,6 +43,9 @@ add_executable(vvave
settings/fileloader.cpp
utils/brain.cpp
utils/babeconsole.cpp
models/tracks/tracksmodel.cpp
models/basemodel.cpp
models/baselist.cpp
)
if (ANDROID)
......
This diff is collapsed.
......@@ -21,7 +21,7 @@ class ConThread;
using namespace BAE;
class Babe : public CollectionDB
class Babe : public QObject
{
Q_OBJECT
......@@ -99,16 +99,17 @@ public slots:
private:
Pulpo *pulpo;
ConThread *thread;
CollectionDB *db;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Notify *nof;
#elif defined (Q_OS_ANDROID)
// NotificationClient *nof;
#endif
QString fetchCoverArt(DB &song);
static QVariantList transformData(const DB_LIST &dbList);
QString fetchCoverArt(FMH::MODEL &song);
static QVariantList transformData(const FMH::MODEL_LIST &dbList);
void fetchTrackLyrics(DB &song);
void fetchTrackLyrics(FMH::MODEL &song);
void linkDecoder(QString json);
signals:
......
This diff is collapsed.
......@@ -25,11 +25,11 @@ class CollectionDB : public QObject
Q_OBJECT
public:
explicit CollectionDB( QObject *parent = nullptr);
~CollectionDB() override;
static CollectionDB *getInstance();
bool insert(const QString &tableName, const QVariantMap &insertData);
bool update(const QString &tableName, const BAE::DB &updateData, const QVariantMap &where);
bool update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where);
bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
bool remove();
......@@ -42,46 +42,46 @@ class CollectionDB : public QObject
/* usefull actions */
void insertArtwork(const BAE::DB &track);
void insertArtwork(const FMH::MODEL &track);
bool addTrack(const BAE::DB &track);
bool updateTrack(const BAE::DB &track);
bool addTrack(const FMH::MODEL &track);
bool updateTrack(const FMH::MODEL &track);
Q_INVOKABLE bool rateTrack(const QString &path, const int &value);
Q_INVOKABLE bool colorTagTrack(const QString &path, const QString &value);
Q_INVOKABLE QString trackColorTag(const QString &path);
bool lyricsTrack(const BAE::DB &track, const QString &value);
bool lyricsTrack(const FMH::MODEL &track, const QString &value);
Q_INVOKABLE bool playedTrack(const QString &url, const int &increment = 1);
bool wikiTrack(const BAE::DB &track, const QString &value);
bool tagsTrack(const BAE::DB &track, const QString &value, const QString &context);
bool albumTrack(const BAE::DB &track, const QString &value);
bool trackTrack(const BAE::DB &track, const QString &value);
bool wikiArtist(const BAE::DB &track, const QString &value);
bool tagsArtist(const BAE::DB &track, const QString &value, const QString &context = "");
bool wikiTrack(const FMH::MODEL &track, const QString &value);
bool tagsTrack(const FMH::MODEL &track, const QString &value, const QString &context);
bool albumTrack(const FMH::MODEL &track, const QString &value);
bool trackTrack(const FMH::MODEL &track, const QString &value);
bool wikiArtist(const FMH::MODEL &track, const QString &value);
bool tagsArtist(const FMH::MODEL &track, const QString &value, const QString &context = "");
bool wikiAlbum(const BAE::DB &track, QString value);
bool tagsAlbum(const BAE::DB &track, const QString &value, const QString &context = "");
bool wikiAlbum(const FMH::MODEL &track, QString value);
bool tagsAlbum(const FMH::MODEL &track, const QString &value, const QString &context = "");
Q_INVOKABLE bool addPlaylist(const QString &title);
bool trackPlaylist(const QString &url, const QString &playlist);
bool addFolder(const QString &url);
bool removeFolder(const QString &url);
BAE::DB_LIST getDBData(const QStringList &urls);
BAE::DB_LIST getDBData(const QString &queryTxt);
FMH::MODEL_LIST getDBData(const QStringList &urls);
FMH::MODEL_LIST getDBData(const QString &queryTxt);
QVariantList getDBDataQML(const QString &queryTxt);
QStringList dataToList(const BAE::DB_LIST &list, const BAE::KEY &key);
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);
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);
BAE::DB_LIST getRecentTracks(const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
BAE::DB_LIST getOnlineTracks(const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
QStringList dataToList(const FMH::MODEL_LIST &list, const FMH::MODEL_KEY &key);
FMH::MODEL_LIST getAlbumTracks(const QString &album, const QString &artist, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::TRACK, const BAE::W &order = BAE::W::ASC);
FMH::MODEL_LIST getArtistTracks(const QString &artist, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::ALBUM, const BAE::W &order = BAE::W::ASC);
FMH::MODEL_LIST getBabedTracks(const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::COUNT, const BAE::W &order = BAE::W::DESC);
QVariantList getSearchedTracks(const FMH::MODEL_KEY &where, const QString &search);
FMH::MODEL_LIST getPlaylistTracks(const QString &playlist, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::ADDDATE, const BAE::W &order = BAE::W::DESC);
FMH::MODEL_LIST getMostPlayedTracks(const int &greaterThan = 1, const int &limit = 50, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::COUNT, const BAE::W &order = BAE::W::DESC);
FMH::MODEL_LIST getFavTracks(const int &stars = 1, const int &limit = 50, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::RATE, const BAE::W &order = BAE::W::DESC);
FMH::MODEL_LIST getRecentTracks(const int &limit = 50, const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::ADDDATE, const BAE::W &order = BAE::W::DESC);
FMH::MODEL_LIST getOnlineTracks(const FMH::MODEL_KEY &orderBy = FMH::MODEL_KEY::ADDDATE, const BAE::W &order = BAE::W::DESC);
Q_INVOKABLE QStringList getSourcesFolders();
......@@ -108,20 +108,19 @@ class CollectionDB : public QObject
void openDB(const QString &name);
private:
static CollectionDB* instance;
QString name;
QSqlDatabase m_db;
/*basic actions*/
explicit CollectionDB( QObject *parent = nullptr);
~CollectionDB() override;
void init();
public slots:
void closeConnection();
void test();
signals:
void trackInserted();
void artworkInserted(const BAE::DB &albumMap);
void artworkInserted(const FMH::MODEL &albumMap);
void DBactionFinished();
void albumsCleaned(const int &amount);
void artistsCleaned(const int &amount);
......
#include "conthread.h"
#include <QMap>
#include <QList>
#include "collectionDB.h"
ConThread::ConThread() : CollectionDB(nullptr)
ConThread::ConThread() : QObject(nullptr)
{
this->db = CollectionDB::getInstance();
this->moveToThread(&t);
this->t.start();
}
......@@ -53,7 +55,7 @@ void ConThread::setInterval(const uint &interval)
void ConThread::get(QString query)
{
auto data = getDBDataQML(query);
auto data = this->db->getDBDataQML(query);
emit this->dataReady(data);
}
......@@ -61,7 +63,7 @@ void ConThread::set(QString tableName, QVariantList wheres)
{
for(auto variant : wheres)
{
this->insert(tableName, QVariantMap(variant.toMap()));
this->db->insert(tableName, QVariantMap(variant.toMap()));
this->t.msleep(this->interval);
}
......
......@@ -3,9 +3,9 @@
#include <QObject>
#include <QThread>
#include "collectionDB.h"
class ConThread : public CollectionDB
class CollectionDB;
class ConThread : public QObject
{
Q_OBJECT
public:
......@@ -21,6 +21,7 @@ public:
private:
QThread t;
CollectionDB *db;
uint interval = 0;
bool go = false;
QList<QMap<QString, QVariant>> queue;
......
......@@ -33,7 +33,7 @@ mood TEXT PRIMARY KEY
CREATE TABLE PLAYLISTS
(
playlist TEXT PRIMARY KEY ,
addDate DATE NOT NULL
adddate DATE NOT NULL
) ;
CREATE TABLE SOURCES_TYPES
......@@ -45,37 +45,37 @@ name TEXT NOT NULL
CREATE TABLE FOLDERS
(
url TEXT PRIMARY KEY,
addDate DATE NOT NULL
adddate DATE NOT NULL
) ;
CREATE TABLE SOURCES
(
url TEXT PRIMARY KEY ,
SOURCE_TYPES_id INTEGER NOT NULL,
FOREIGN KEY(SOURCE_TYPES_id) REFERENCES SOURCES_TYPES(id)
sourcetype INTEGER NOT NULL,
FOREIGN KEY(sourcetype) REFERENCES SOURCES_TYPES(id)
) ;
CREATE TABLE TRACKS
(
url TEXT ,
sources_url TEXT ,
source TEXT ,
track INTEGER ,
title TEXT NOT NULL,
artist TEXT NOT NULL,
album TEXT NOT NULL,
duration INTEGER ,
comment TEXT,
played INTEGER ,
babe INTEGER NOT NULL,
stars INTEGER NOT NULL,
releaseDate DATE ,
addDate DATE NOT NULL,
count INTEGER ,
fav INTEGER NOT NULL,
rate INTEGER NOT NULL,
releasedate DATE ,
adddate DATE NOT NULL,
lyrics TEXT NOT NULL,
genre TEXT,
art TEXT,
artwork TEXT,
wiki TEXT NOT NULL,
PRIMARY KEY (url),
FOREIGN KEY(sources_url) REFERENCES SOURCES(url),
FOREIGN KEY(source) REFERENCES SOURCES(url),
FOREIGN KEY(album, artist) REFERENCES albums(album, artist)
) ;
......@@ -136,7 +136,7 @@ CREATE TABLE TRACKS_PLAYLISTS
(
playlist TEXT NOT NULL ,
url TEXT NOT NULL ,
addDate DATE NOT NULL,
adddate DATE NOT NULL,
PRIMARY KEY (playlist, url),
FOREIGN KEY(playlist) REFERENCES PLAYLISTS(playlist),
FOREIGN KEY(url) REFERENCES TRACKS(url)
......@@ -146,7 +146,7 @@ FOREIGN KEY(url) REFERENCES TRACKS(url)
CREATE TABLE LOG
(
id INTEGER NOT NULL,
retrieval_date DATE NOT NULL,
adddate DATE NOT NULL,
PRIMARY KEY(id)
);
......
......@@ -35,21 +35,21 @@ void Notify::notify(const QString &title, const QString &body)
notification->sendEvent();
}
void Notify::notifySong(const BAE::DB &trackMap)
void Notify::notifySong(const FMH::MODEL &trackMap)
{
this->track = trackMap;
// notification->setComponentName(QStringLiteral("Babe"));
auto notification = new KNotification(QStringLiteral("Notify"),KNotification::CloseOnTimeout, this);
connect(notification, &KNotification::closed, notification, &KNotification::deleteLater);
notification->setTitle(QStringLiteral("%1").arg(track[BAE::KEY::TITLE]));
notification->setText(QStringLiteral("%1\n%2").arg(track[BAE::KEY::ARTIST],track[BAE::KEY::ALBUM]));
notification->setTitle(QStringLiteral("%1").arg(track[FMH::MODEL_KEY::TITLE]));
notification->setText(QStringLiteral("%1\n%2").arg(track[FMH::MODEL_KEY::ARTIST],track[FMH::MODEL_KEY::ALBUM]));
QPixmap pixmap;
pixmap.load(trackMap[BAE::KEY::ARTWORK]);
pixmap.load(trackMap[FMH::MODEL_KEY::ARTWORK]);
if(!pixmap.isNull()) notification->setPixmap(pixmap);
QStringList actions;
if(track[BAE::KEY::BABE].toInt()==1) actions<<i18n("Un-Babe it \xe2\x99\xa1");
if(track[FMH::MODEL_KEY::FAV].toInt()==1) actions<<i18n("Un-Babe it \xe2\x99\xa1");
else actions<<i18n("Babe it \xe2\x99\xa1");
actions<<i18n("Skip");
......
......@@ -21,11 +21,11 @@ class Notify : public QObject
public:
explicit Notify(QObject *parent = nullptr);
~Notify();
void notifySong(const BAE::DB &);
void notifySong(const FMH::MODEL &);
void notify(const QString &title, const QString &body);
private:
BAE::DB track;
FMH::MODEL track;
signals:
void babeSong();
......
#include "baselist.h"
BaseList::BaseList(QObject *parent) : QObject(parent)
{
}
#ifndef BASELIST_H
#define BASELIST_H
#ifdef STATIC_MAUIKIT
#include "fm.h"
#include "fmh.h"
#else
#include <MauiKit/fm.h>
#include <MauiKit/fmh.h>
#endif
class BaseList : public QObject
{
Q_OBJECT
public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual FMH::MODEL_LIST items() const {return FMH::MODEL_LIST({{}});}
protected:
signals:
void preItemAppended();
void postItemAppended();
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
virtual QVariantMap get(const int &index) const
{
Q_UNUSED(index);
return QVariantMap();
}
virtual bool update(const int &index, const QVariant &value, const int &role)
{
Q_UNUSED(index);
Q_UNUSED(value);
Q_UNUSED(role);
return false;
}
virtual bool update(const QVariantMap &data, const int &index)
{
Q_UNUSED(index);
Q_UNUSED(data);
return false;
}
virtual bool update(const FMH::MODEL &data)
{
Q_UNUSED(data);
return false;
}
virtual bool insert(const QVariantMap &map)
{
Q_UNUSED(map);
return false;
}
virtual bool remove(const int &index)
{
Q_UNUSED(index);
return false;
}
};
#endif // BASELIST_H
#include "basemodel.h"
#include "baselist.h"
BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int BaseModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant BaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mList)
return QVariant();
return mList->items().at(index.row())[static_cast<FMH::MODEL_KEY>(role)];
}
bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mList)
return false;
if (mList->update(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
BaseList *BaseModel::getList() const
{
return this->mList;
}
void BaseModel::setList(BaseList *value)
{
beginResetModel();
if(mList)
mList->disconnect(this);
mList = value;
if(mList)
{
connect(this->mList, &BaseList::preItemAppended, this, [=]()
{
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemAppended, this, [=]()
{
endInsertRows();
});
connect(this->mList, &BaseList::preItemRemoved, this, [=](int index)
{
beginRemoveRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemRemoved, this, [=]()
{
endRemoveRows();
});
connect(this->mList, &BaseList::updateModel, this, [=](int index, QVector<int> roles)
{
emit this->dataChanged(this->index(index), this->index(index), roles);
});
connect(this->mList, &BaseList::preListChanged, this, [=]()
{
beginResetModel();
});
connect(this->mList, &BaseList::postListChanged, this, [=]()
{
endResetModel();
});
}
endResetModel();
}
QVariantMap BaseModel::get(const int &index) const
{
return this->mList->get(index);
}
#ifndef BASEMODEL_H
#define BASEMODEL_H
#include <QAbstractListModel>
#include <QList>
class BaseList;
class BaseModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(BaseList *list READ getList WRITE setList)
public:
explicit BaseModel(QObject *parent = nullptr);
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual QHash<int, QByteArray> roleNames() const override;
BaseList* getList() const;
void setList(BaseList *value);
private:
BaseList *mList;
signals:
void listChanged();
public slots:
QVariantMap get(const int &index) const;
};
#endif // NOTESMODEL_H
#include "tracksmodel.h"
TracksModel::TracksModel(QObject *parent) : BaseList(parent)
{
}
FMH::MODEL_LIST TracksModel::items() const
{
return this->list;
}
void TracksModel::setQuery(const QString &query)
{
if(this->query == query)
return;
this->query = query;
qDebug()<< "setting query"<< this->query;
emit this->queryChanged();
}
QString TracksModel::getQuery() const
{
return this->query;
}
void TracksModel::setSortBy(const uint &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
emit this->sortByChanged();
}
uint TracksModel::getSortBy() const
{
return this->sort;
}
#ifndef TRACKSMODEL_H
#define TRACKSMODEL_H
#include <QObject>
#include "models/baselist.h"
#include "db/collectionDB.h"
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)
public:
explicit TracksModel(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const uint &sort);
uint getSortBy() const;
private:
CollectionDB *db;
FMH::MODEL_LIST list;
void sortList();
void setList();
QString query;
uint sort = FMH::MODEL_KEY::DATE;
bool addDoc(const FMH::MODEL &doc);
void refreshCollection();
signals:
void queryChanged();
void sortByChanged();
};
#endif // TRACKSMODEL_H
......@@ -26,14 +26,14 @@
//#include "qgumbodocument.h"
//#include "qgumbonode.h"
Pulpo::Pulpo(const BAE::DB &song,QObject *parent)
Pulpo::Pulpo(const FMH::MODEL &song,QObject *parent)
: QObject(parent), track(song) {}
Pulpo::Pulpo(QObject *parent): QObject(parent) {}
Pulpo::~Pulpo() {}
bool Pulpo::feed(const BAE::DB &song, const RECURSIVE &recursive)
bool Pulpo::feed(const FMH::MODEL &song, const RECURSIVE &recursive)
{
this->track = song;
this->recursive = recursive;
......@@ -204,7 +204,7 @@ void Pulpo::initServices()
}
}
void Pulpo::passSignal(const BAE::DB &track, const PULPO::RESPONSE &response)
void Pulpo::passSignal(const FMH::MODEL &track, const PULPO::RESPONSE &response)
{
emit this->infoReady(track, response);
}
......
......@@ -26,11 +26,11 @@ class Pulpo : public QObject
Q_OBJECT
public:
explicit Pulpo(const BAE::DB &song, QObject *parent = nullptr);
explicit Pulpo(const FMH::MODEL &song, QObject *parent = nullptr);
explicit Pulpo(QObject *parent = nullptr);
~Pulpo();
bool feed(const BAE::DB &song, const PULPO::RECURSIVE &recursive = PULPO::RECURSIVE::ON );
bool feed(const FMH::MODEL &song, const PULPO::RECURSIVE &recursive = PULPO::RECURSIVE::ON );
void registerServices(const QList<PULPO::SERVICES> &services);
void setInfo(const PULPO::INFO &info);
void setOntology(const PULPO::ONTOLOGY &ontology);
......@@ -44,11 +44,11 @@ class Pulpo : public QObject
PULPO::RECURSIVE recursive = PULPO::RECURSIVE::ON;
QList<SERVICES> registeredServices = {};
void passSignal(const BAE::DB &track, const PULPO::RESPONSE &response);
void passSignal(const FMH::MODEL &track, const PULPO::RESPONSE &response);
protected:
QByteArray array;
BAE::DB track;
FMH::MODEL track;
PULPO::INFO info = INFO::NONE;
PULPO::ONTOLOGY ontology = ONTOLOGY::NONE;
PULPO::AVAILABLE availableInfo;
......@@ -66,7 +66,7 @@ class Pulpo : public QObject
virtual bool parseTrack() {return false;}