Commit 969880e0 authored by Camilo Higuita's avatar Camilo Higuita

initial work on non blocking db on large insertions

parent 8a06845a
...@@ -203,7 +203,8 @@ SOURCES += main.cpp \ ...@@ -203,7 +203,8 @@ SOURCES += main.cpp \
taglib/tagunion.cpp \ taglib/tagunion.cpp \
babe.cpp \ babe.cpp \
settings/BabeSettings.cpp \ settings/BabeSettings.cpp \
java/notificationclient.cpp java/notificationclient.cpp \
db/conthread.cpp
...@@ -361,6 +362,7 @@ HEADERS += \ ...@@ -361,6 +362,7 @@ HEADERS += \
taglib/taglib_config.h \ taglib/taglib_config.h \
babe.h \ babe.h \
settings/BabeSettings.h \ settings/BabeSettings.h \
java/notificationclient.h java/notificationclient.h \
db/conthread.h
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <QColor> #include <QColor>
#include <QIcon> #include <QIcon>
#include "db/collectionDB.h" #include "db/collectionDB.h"
#include "db/conthread.h"
#include "settings/BabeSettings.h" #include "settings/BabeSettings.h"
#include "pulpo/pulpo.h" #include "pulpo/pulpo.h"
#include <QApplication> #include <QApplication>
...@@ -28,9 +29,10 @@ Babe::Babe(QObject *parent) : CollectionDB(parent) ...@@ -28,9 +29,10 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
{ {
qDebug()<<"CONSTRUCTING ABE INTERFACE"; qDebug()<<"CONSTRUCTING ABE INTERFACE";
this->set = new BabeSettings(this); this->settings = new BabeSettings(this);
this->thread = new ConThread;
connect(set, &BabeSettings::refreshTables, [this](QVariantMap tables) connect(settings, &BabeSettings::refreshTables, [this](QVariantMap tables)
{ {
emit this->refreshTables(tables); emit this->refreshTables(tables);
}); });
...@@ -52,7 +54,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent) ...@@ -52,7 +54,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
Babe::~Babe() Babe::~Babe()
{ {
delete this->thread;
} }
QVariantList Babe::get(const QString &queryTxt) QVariantList Babe::get(const QString &queryTxt)
...@@ -65,6 +67,28 @@ QVariantList Babe::getList(const QStringList &urls) ...@@ -65,6 +67,28 @@ QVariantList Babe::getList(const QStringList &urls)
return Babe::transformData(getDBData(urls)); return Babe::transformData(getDBData(urls));
} }
void Babe::set(const QString &table, const QVariantList &wheres)
{
this->thread->start(table, wheres);
}
void Babe::trackPlaylist(const QStringList &urls, const QString &playlist)
{
QVariantList data;
for(auto url : urls)
{
QVariantMap map {{KEYMAP[KEY::PLAYLIST],playlist},
{KEYMAP[KEY::URL],url},
{KEYMAP[KEY::ADD_DATE],QDateTime::currentDateTime()}};
data << map;
}
qDebug()<<"now to send data to thread";
this->thread->start(BAE::TABLEMAP[TABLE::TRACKS_PLAYLISTS], data);
}
void Babe::trackLyrics(const QString &url) void Babe::trackLyrics(const QString &url)
{ {
auto track = getDBData(QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS], auto track = getDBData(QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
...@@ -201,12 +225,12 @@ void Babe::notifySong(const QString &url) ...@@ -201,12 +225,12 @@ void Babe::notifySong(const QString &url)
void Babe::scanDir(const QString &url) void Babe::scanDir(const QString &url)
{ {
emit this->set->collectionPathChanged({url}); emit this->settings->collectionPathChanged({url});
} }
void Babe::brainz(const bool &on) void Babe::brainz(const bool &on)
{ {
this->set->checkCollectionBrainz(on); this->settings->checkCollectionBrainz(on);
} }
bool Babe::brainzState() bool Babe::brainzState()
......
...@@ -13,7 +13,7 @@ class Notify; ...@@ -13,7 +13,7 @@ class Notify;
class CollectionDB; class CollectionDB;
class Pulpo; class Pulpo;
class BabeSettings; class BabeSettings;
class ConThread;
using namespace BAE; using namespace BAE;
class Babe : public CollectionDB class Babe : public CollectionDB
...@@ -36,6 +36,9 @@ public: ...@@ -36,6 +36,9 @@ public:
Q_INVOKABLE QVariantList get(const QString &queryTxt); Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE QVariantList getList(const QStringList &urls); Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE void set(const QString &table, const QVariantList &wheres);
Q_INVOKABLE void trackPlaylist(const QStringList &urls, const QString &playlist);
Q_INVOKABLE void trackLyrics(const QString &url); Q_INVOKABLE void trackLyrics(const QString &url);
Q_INVOKABLE bool trackBabe(const QString &path); Q_INVOKABLE bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist); Q_INVOKABLE QString artistArt(const QString &artist);
...@@ -105,7 +108,9 @@ public: ...@@ -105,7 +108,9 @@ public:
Q_INVOKABLE QVariantList searchFor(const QStringList &queries); Q_INVOKABLE QVariantList searchFor(const QStringList &queries);
private: private:
BabeSettings *set; BabeSettings *settings;
ConThread *thread;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID)) #if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Notify *nof; Notify *nof;
#endif #endif
...@@ -121,7 +126,7 @@ signals: ...@@ -121,7 +126,7 @@ signals:
void skipTrack(); void skipTrack();
void babeIt(); void babeIt();
friend class CollectionDB; friend class CollectionDB;
}; };
......
...@@ -25,6 +25,8 @@ var GET = { ...@@ -25,6 +25,8 @@ var GET = {
} }
var POST = {} var INSERT = {
trackPlaylist_ : "insert into tracks_playlists () ",
}
var UPDATE = {} var UPDATE = {}
...@@ -210,6 +210,9 @@ void CollectionDB::openDB(const QString &name) ...@@ -210,6 +210,9 @@ void CollectionDB::openDB(const QString &name)
{ {
if(!this->m_db.open()) if(!this->m_db.open())
qDebug()<<"ERROR OPENING DB"<<this->m_db.lastError().text()<<m_db.connectionName(); qDebug()<<"ERROR OPENING DB"<<this->m_db.lastError().text()<<m_db.connectionName();
}else
{
this->execQuery("PRAGMA journal_mode=WAL");
} }
} }
...@@ -492,18 +495,6 @@ bool CollectionDB::addPlaylist(const QString &title) ...@@ -492,18 +495,6 @@ bool CollectionDB::addPlaylist(const QString &title)
return false; return false;
} }
bool CollectionDB::trackPlaylist(const QString &url, const QString &playlist)
{
QVariantMap map {{KEYMAP[KEY::PLAYLIST],playlist},
{KEYMAP[KEY::URL],url},
{KEYMAP[KEY::ADD_DATE],QDateTime::currentDateTime()}};
if(insert(TABLEMAP[TABLE::TRACKS_PLAYLISTS],map))
return true;
return false;
}
bool CollectionDB::addFolder(const QString &url) bool CollectionDB::addFolder(const QString &url)
{ {
QVariantMap map {{KEYMAP[KEY::URL],url}, QVariantMap map {{KEYMAP[KEY::URL],url},
......
...@@ -65,7 +65,6 @@ public: ...@@ -65,7 +65,6 @@ public:
bool tagsAlbum(const BAE::DB &track, const QString &value, const QString &context = ""); bool tagsAlbum(const BAE::DB &track, const QString &value, const QString &context = "");
Q_INVOKABLE bool addPlaylist(const QString &title); Q_INVOKABLE bool addPlaylist(const QString &title);
Q_INVOKABLE bool trackPlaylist(const QString &url, const QString &playlist);
bool addFolder(const QString &url); bool addFolder(const QString &url);
...@@ -108,6 +107,8 @@ public: ...@@ -108,6 +107,8 @@ public:
private: private:
QString name; QString name;
QSqlDatabase m_db; QSqlDatabase m_db;
/*basic actions*/ /*basic actions*/
......
#include "conthread.h"
#include <QMap>
#include <QList>
ConThread::ConThread() : CollectionDB(nullptr)
{
this->moveToThread(&t);
this->t.start();
}
ConThread::~ConThread()
{
this->stop();
}
void ConThread::start(QString table, QVariantList wheres)
{
if(!this->go) this->go = true;
this->queue.append({{QString ("TABLE"), table}, {QString ("WHERES"), wheres}});
qDebug()<<"NOW ON THREAD<<"<< queue;
if(this->queue.size() > 1) return;
while(!this->queue.isEmpty())
{
if(this->go)
{
qDebug()<<"RUNNIGN QUERY ON CONTHREAD"<<this->queue.first()["TABLE"].toString();
QMetaObject::invokeMethod(this, "set", Q_ARG(QString, this->queue.first()["TABLE"].toString()), Q_ARG(QVariantList, this->queue.first()["WHERES"].toList()));
qDebug()<<"FINISHED SET ON QUEUE CONTHREAD"<< this->queue.first()["TABLE"].toString();
this->queue.removeFirst();
qDebug()<<this->queue.size();
}else return;
}
qDebug()<<"FINISHED SET ON CONTHREAD TOTALLY";
}
void ConThread::stop()
{
this->go = false;
this->t.quit();
this->t.wait();
}
void ConThread::pause()
{
this->go = false;
}
bool ConThread::isRunning()
{
return this->go;
}
void ConThread::setInterval()
{
}
void ConThread::get(QString query)
{
auto data = getDBDataQML(query);
emit this->dataReady(data);
}
void ConThread::set(QString tableName, QVariantList wheres)
{
for(auto variant : wheres)
{
this->insert(tableName, QVariantMap(variant.toMap()));
this->t.msleep(this->interval);
}
}
#ifndef CONTHREAD_H
#define CONTHREAD_H
#include <QObject>
#include <QThread>
#include "collectionDB.h"
class ConThread : public CollectionDB
{
Q_OBJECT
public:
explicit ConThread();
~ConThread();
void start(QString table, QVariantList wheres);
void stop();
void pause();
bool isRunning();
void setInterval();
void get(QString query);
private:
QThread t;
uint interval = 500;
bool go = false;
QList<QMap<QString, QVariant>> queue;
signals:
void finished();
void dataReady(QVariantList);
public slots:
void set(QString tableName, QVariantList wheres);
};
#endif // CONTHREAD_H
...@@ -231,7 +231,7 @@ Kirigami.ApplicationWindow ...@@ -231,7 +231,7 @@ Kirigami.ApplicationWindow
header: BabeBar header: BabeBar
{ {
id: mainToolbar id: mainToolbar
height: headerHeight height: toolBarHeight
visible: true visible: true
currentIndex: currentView currentIndex: currentView
bgColor: isMobile && pageStack.currentIndex === 0 && !pageStack.wideMode ? babeColor : babeAltColor bgColor: isMobile && pageStack.currentIndex === 0 && !pageStack.wideMode ? babeColor : babeAltColor
...@@ -433,15 +433,15 @@ Kirigami.ApplicationWindow ...@@ -433,15 +433,15 @@ Kirigami.ApplicationWindow
anchors.fill: parent anchors.fill: parent
width: parent.width width: parent.width
height: parent.height height: parent.height
Rectangle
{
visible: (!pageStack.wideMode && pageStack.currentIndex !== 0) || !mainPlaylist.cover.visible
Item
{
Layout.fillHeight: true
height: headerHeight height: headerHeight
width: headerHeight width: headerHeight
Image Image
{ {
visible: (!pageStack.wideMode && pageStack.currentIndex !== 0) || !mainPlaylist.cover.visible
height: headerHeight height: headerHeight
width: headerHeight width: headerHeight
...@@ -470,6 +470,18 @@ Kirigami.ApplicationWindow ...@@ -470,6 +470,18 @@ Kirigami.ApplicationWindow
} }
} }
Item
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
RowLayout
{
anchors.centerIn: parent
anchors.fill: parent
Item Item
{ {
Layout.fillWidth: true Layout.fillWidth: true
...@@ -523,11 +535,23 @@ Kirigami.ApplicationWindow ...@@ -523,11 +535,23 @@ Kirigami.ApplicationWindow
onClicked: shuffle = !shuffle onClicked: shuffle = !shuffle
} }
Item Item
{ {
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
}
Item
{
Layout.fillHeight: true
height: headerHeight
width: headerHeight
}
}
} }
background: Rectangle background: Rectangle
......
...@@ -184,7 +184,7 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro ...@@ -184,7 +184,7 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
CollectionDB con(nullptr); CollectionDB con(nullptr);
con.addTrack(trackMap); con.addTrack(trackMap);
con.trackPlaylist(file, track[KEY::PLAYLIST]); // con.trackPlaylist(file, track[KEY::PLAYLIST]);
if(this->ids.isEmpty()) emit this->done(); if(this->ids.isEmpty()) emit this->done();
} }
......
...@@ -81,7 +81,6 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent) ...@@ -81,7 +81,6 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
emit this->refreshTables({{BAE::TABLEMAP[type], true}}); emit this->refreshTables({{BAE::TABLEMAP[type], true}});
}); });
// connect(this->fileLoader, &FileLoader::trackReady, [this]() // connect(this->fileLoader, &FileLoader::trackReady, [this]()
// { // {
// this->ui->progressBar->setValue(this->ui->progressBar->value()+1); // this->ui->progressBar->setValue(this->ui->progressBar->value()+1);
...@@ -91,14 +90,16 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent) ...@@ -91,14 +90,16 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
{ {
if(size > 0) if(size > 0)
{ {
this->collectionWatcher(); // this->collectionWatcher();
emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true}, // emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true},
{BAE::TABLEMAP[TABLE::ALBUMS], true}, // {BAE::TABLEMAP[TABLE::ALBUMS], true},
{BAE::TABLEMAP[TABLE::ARTISTS], true}, // {BAE::TABLEMAP[TABLE::ARTISTS], true},
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}}); // {BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
// this->startBrainz(true, 1500);
this->startBrainz(true, 1500); qDebug()<<"Finished inserting into DB";
}else }else
{ {
this->dirs.clear(); this->dirs.clear();
......
...@@ -235,8 +235,10 @@ function addToPlaylist(urls, playlist) ...@@ -235,8 +235,10 @@ function addToPlaylist(urls, playlist)
{ {
if(urls.length > 0) if(urls.length > 0)
{ {
for(var i in urls) bae.trackPlaylist(urls, playlist)
bae.trackPlaylist(urls[i], playlist) // for(var i in urls)
// bae.trackPlaylist(urls[i], playlist)
if(!isMobile) if(!isMobile)
bae.notify(playlist, urls.length + " tracks added to the playlist:\n"+urls.join("\n")) bae.notify(playlist, urls.length + " tracks added to the playlist:\n"+urls.join("\n"))
......
...@@ -41,7 +41,6 @@ void Brain::pause() ...@@ -41,7 +41,6 @@ void Brain::pause()
this->go = false; this->go = false;
} }
bool Brain::isRunning() const bool Brain::isRunning() const
{ {
return this->go; return this->go;
......
...@@ -49,7 +49,7 @@ ListView ...@@ -49,7 +49,7 @@ ListView
addDisplaced: Transition addDisplaced: Transition
{ {
NumberAnimation { properties: "x,y"; duration: 1000 } NumberAnimation { properties: "x,y"; duration: 100 }
} }
function clearTable() function clearTable()
......
...@@ -53,20 +53,32 @@ ToolBar ...@@ -53,20 +53,32 @@ ToolBar
RowLayout RowLayout
{ {
anchors.fill: parent anchors.fill: parent
BabeButton BabeButton
{ {
iconName: "love" id: settingsView
iconColor: accent && currentIndex === viewsIndex.babeit ? accentColor : textColor iconName: /*"headphones"*/ /*"media-optical-audio"*/ "application-menu"
iconColor: settingsDrawer.visible ? babeColor : textColor/*(pageStack.wideMode || pageStack.currentIndex === 0 ) && !isMobile ? accentColor : textColor*/
onClicked: babeViewClicked() onClicked: settingsViewClicked()/*playlistViewClicked()*/
hoverEnabled: !isMobile hoverEnabled: !isMobile
ToolTip.delay: 1000 ToolTip.delay: 1000
ToolTip.timeout: 5000 ToolTip.timeout: 5000
ToolTip.visible: hovered && !isMobile ToolTip.visible: hovered && !isMobile
ToolTip.text: qsTr("Babe") ToolTip.text: qsTr("Settings")
} }
// BabeButton
// {
// iconName: "love"
// iconColor: accent && currentIndex === viewsIndex.babeit ? accentColor : textColor
// onClicked: babeViewClicked()
// hoverEnabled: !isMobile
// ToolTip.delay: 1000
// ToolTip.timeout: 5000
// ToolTip.visible: hovered && !isMobile
// ToolTip.text: qsTr("Babe")
// }
Item Item
{ {
......
...@@ -3,15 +3,13 @@ import QtQuick.Layouts 1.3 ...@@ -3,15 +3,13 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import org.kde.kirigami 2.2 as Kirigami import org.kde.kirigami 2.2 as Kirigami
Kirigami.GlobalDrawer Kirigami.GlobalDrawer
{ {
id: settingsView id: settingsView
handleVisible: true handleVisible: false
signal iconSizeChanged(int size) signal iconSizeChanged(int size)
readonly property bool activeBrainz : bae.brainzState() readonly property bool activeBrainz : bae.brainzState()
visible: false
y: header.height y: header.height
height: parent.height - header.height - footer.height height: parent.height - header.height - footer.height
// // width: root.pageStack.wideMode ? views.width -1: root.width // // width: root.pageStack.wideMode ? views.width -1: root.width
...@@ -19,17 +17,17 @@ Kirigami.GlobalDrawer ...@@ -19,17 +17,17 @@ Kirigami.GlobalDrawer
// interactive: true // interactive: true
// focus: true // focus: true
modal:true modal:true
// dragMargin :0 // dragMargin :0
topPadding: 0 topPadding: 0
bottomPadding: 0 bottomPadding: 0
leftPadding: 0 leftPadding: 0
rightPadding: 0 rightPadding: 0
// handle.y : 64 // handle.y : 64
// handle.anchors.verticalCenter: parent.verticalCenter // handle.anchors.verticalCenter: parent.verticalCenter
// handle.anchors.top: parent.bottom // handle.anchors.top: parent.bottom
// handle.focus: false // handle.focus: false
// handle.y : coverSize // handle.y : coverSize
//handle.parent: ApplicationWindow.overlay //handle.parent: ApplicationWindow.overlay
function scanDir(folderUrl) function scanDir(folderUrl)
......
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