Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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 \
taglib/tagunion.cpp \
babe.cpp \
settings/BabeSettings.cpp \
java/notificationclient.cpp
java/notificationclient.cpp \
db/conthread.cpp
......@@ -361,6 +362,7 @@ HEADERS += \
taglib/taglib_config.h \
babe.h \
settings/BabeSettings.h \
java/notificationclient.h
java/notificationclient.h \
db/conthread.h
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
......@@ -5,6 +5,7 @@
#include <QColor>
#include <QIcon>
#include "db/collectionDB.h"
#include "db/conthread.h"
#include "settings/BabeSettings.h"
#include "pulpo/pulpo.h"
#include <QApplication>
......@@ -28,9 +29,10 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
{
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);
});
......@@ -52,7 +54,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
Babe::~Babe()
{
delete this->thread;
}
QVariantList Babe::get(const QString &queryTxt)
......@@ -65,10 +67,32 @@ QVariantList Babe::getList(const QStringList &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)
{
auto track = getDBData(QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL], url));
KEYMAP[KEY::URL], url));
if(track.isEmpty()) return;
......@@ -78,7 +102,7 @@ void Babe::trackLyrics(const QString &url)
bool Babe::trackBabe(const QString &path)
{
auto babe = getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::BABE],
TABLEMAP[TABLE::TRACKS],
TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL],path));
if(!babe.isEmpty())
......@@ -90,7 +114,7 @@ bool Babe::trackBabe(const QString &path)
QString Babe::artistArt(const QString &artist)
{
auto artwork = getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::ARTWORK],
TABLEMAP[TABLE::ARTISTS],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
if(!artwork.isEmpty())
......@@ -103,7 +127,7 @@ QString Babe::artistArt(const QString &artist)
QString Babe::artistWiki(const QString &artist)
{
auto wiki = getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(KEYMAP[KEY::WIKI],
TABLEMAP[TABLE::ARTISTS],
TABLEMAP[TABLE::ARTISTS],
KEYMAP[KEY::ARTIST],artist));
if(!wiki.isEmpty())
......@@ -168,10 +192,10 @@ QString Babe::albumWiki(const QString &album, const QString &artist)
bool Babe::babeTrack(const QString &path, const bool &value)
{
if(update(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::BABE],
value ? 1 : 0,
KEYMAP[KEY::URL],
path)) return true;
KEYMAP[KEY::BABE],
value ? 1 : 0,
KEYMAP[KEY::URL],
path)) return true;
return false;
}
......@@ -201,12 +225,12 @@ void Babe::notifySong(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)
{
this->set->checkCollectionBrainz(on);
this->settings->checkCollectionBrainz(on);
}
bool Babe::brainzState()
......
......@@ -13,7 +13,7 @@ class Notify;
class CollectionDB;
class Pulpo;
class BabeSettings;
class ConThread;
using namespace BAE;
class Babe : public CollectionDB
......@@ -36,6 +36,9 @@ public:
Q_INVOKABLE QVariantList get(const QString &queryTxt);
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 bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist);
......@@ -105,7 +108,9 @@ public:
Q_INVOKABLE QVariantList searchFor(const QStringList &queries);
private:
BabeSettings *set;
BabeSettings *settings;
ConThread *thread;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Notify *nof;
#endif
......@@ -121,7 +126,7 @@ signals:
void skipTrack();
void babeIt();
friend class CollectionDB;
friend class CollectionDB;
};
......
......@@ -25,6 +25,8 @@ var GET = {
}
var POST = {}
var INSERT = {
trackPlaylist_ : "insert into tracks_playlists () ",
}
var UPDATE = {}
......@@ -210,6 +210,9 @@ void CollectionDB::openDB(const QString &name)
{
if(!this->m_db.open())
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)
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)
{
QVariantMap map {{KEYMAP[KEY::URL],url},
......
......@@ -65,7 +65,6 @@ public:
bool tagsAlbum(const BAE::DB &track, const QString &value, const QString &context = "");
Q_INVOKABLE bool addPlaylist(const QString &title);
Q_INVOKABLE bool trackPlaylist(const QString &url, const QString &playlist);
bool addFolder(const QString &url);
......@@ -108,6 +107,8 @@ public:
private:
QString name;
QSqlDatabase m_db;
/*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
header: BabeBar
{
id: mainToolbar
height: headerHeight
height: toolBarHeight
visible: true
currentIndex: currentView
bgColor: isMobile && pageStack.currentIndex === 0 && !pageStack.wideMode ? babeColor : babeAltColor
......@@ -433,15 +433,15 @@ Kirigami.ApplicationWindow
anchors.fill: parent
width: parent.width
height: parent.height
Rectangle
{
visible: (!pageStack.wideMode && pageStack.currentIndex !== 0) || !mainPlaylist.cover.visible
Item
{
Layout.fillHeight: true
height: headerHeight
width: headerHeight
Image
{
visible: (!pageStack.wideMode && pageStack.currentIndex !== 0) || !mainPlaylist.cover.visible
height: headerHeight
width: headerHeight
......@@ -470,63 +470,87 @@ Kirigami.ApplicationWindow
}
}
Item
{
Layout.fillHeight: true
Layout.fillWidth: true
}
Layout.alignment: Qt.AlignCenter
BabeButton
{
id: babeBtnIcon
iconName: "love" //"love-amarok"
iconColor: currentBabe ? babeColor : defaultColor
onClicked:
RowLayout
{
var value = mainPlaylist.list.contextMenu.babeIt(currentTrackIndex)
// iconColor = value ? babeColor : foregroundColor
currentTrack.babe = value ? "1" : "0"
currentBabe = value
}
}
anchors.centerIn: parent
anchors.fill: parent
BabeButton
{
id: previousBtn
iconName: "media-skip-backward"
onClicked: Player.previousTrack()
onPressAndHold: Player.playAt(prevTrackIndex)
}
Item
{
Layout.fillWidth: true
}
BabeButton
{
id: playIcon
iconName: "media-playback-start"
onClicked:
{
if(player.isPaused()) Player.resumeTrack()
else Player.pauseTrack()
}
}
BabeButton
{
id: babeBtnIcon
iconName: "love" //"love-amarok"
iconColor: currentBabe ? babeColor : defaultColor
onClicked:
{
var value = mainPlaylist.list.contextMenu.babeIt(currentTrackIndex)
// iconColor = value ? babeColor : foregroundColor
currentTrack.babe = value ? "1" : "0"
currentBabe = value
}
}
BabeButton
{
id: nextBtn
iconName: "media-skip-forward"
onClicked: Player.nextTrack()
onPressAndHold: Player.playAt(Player.shuffle())
}
BabeButton
{
id: previousBtn
iconName: "media-skip-backward"
onClicked: Player.previousTrack()
onPressAndHold: Player.playAt(prevTrackIndex)
}
BabeButton
{
id: playIcon
iconName: "media-playback-start"
onClicked:
{
if(player.isPaused()) Player.resumeTrack()
else Player.pauseTrack()
}
}
BabeButton
{
id: nextBtn
iconName: "media-skip-forward"
onClicked: Player.nextTrack()
onPressAndHold: Player.playAt(Player.shuffle())
}
BabeButton
{
id: shuffleBtn
iconName: shuffle ? "media-playlist-shuffle" : "media-playlist-repeat"
onClicked: shuffle = !shuffle
}
Item
{
Layout.fillWidth: true
}
}
BabeButton
{
id: shuffleBtn
iconName: shuffle ? "media-playlist-shuffle" : "media-playlist-repeat"
onClicked: shuffle = !shuffle
}
Item
{
Layout.fillWidth: true
Layout.fillHeight: true
height: headerHeight
width: headerHeight
}
}
}
......
......@@ -184,7 +184,7 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
CollectionDB con(nullptr);
con.addTrack(trackMap);
con.trackPlaylist(file, track[KEY::PLAYLIST]);
// con.trackPlaylist(file, track[KEY::PLAYLIST]);
if(this->ids.isEmpty()) emit this->done();
}
......
......@@ -81,7 +81,6 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
emit this->refreshTables({{BAE::TABLEMAP[type], true}});
});
// connect(this->fileLoader, &FileLoader::trackReady, [this]()
// {
// this->ui->progressBar->setValue(this->ui->progressBar->value()+1);
......@@ -91,14 +90,16 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
{
if(size > 0)
{
this->collectionWatcher();
emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true},
{BAE::TABLEMAP[TABLE::ALBUMS], true},
{BAE::TABLEMAP[TABLE::ARTISTS], true},
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
// this->collectionWatcher();
// emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true},
// {BAE::TABLEMAP[TABLE::ALBUMS], true},
// {BAE::TABLEMAP[TABLE::ARTISTS], true},
// {BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
// this->startBrainz(true, 1500);
this->startBrainz(true, 1500);
qDebug()<<"Finished inserting into DB";
}else
{
this->dirs.clear();
......
......@@ -235,8 +235,10 @@ function addToPlaylist(urls, playlist)
{
if(urls.length > 0)
{
for(var i in urls)
bae.trackPlaylist(urls[i], playlist)
bae.trackPlaylist(urls, playlist)
// for(var i in urls)
// bae.trackPlaylist(urls[i], playlist)
if(!isMobile)
bae.notify(playlist, urls.length + " tracks added to the playlist:\n"+urls.join("\n"))
......
......@@ -41,7 +41,6 @@ void Brain::pause()
this->go = false;
}
bool Brain::isRunning() const
{
return this->go;
......
......@@ -49,7 +49,7 @@ ListView
addDisplaced: Transition
{
NumberAnimation { properties: "x,y"; duration: 1000 }
NumberAnimation { properties: "x,y"; duration: 100 }
}
function clearTable()
......
......@@ -53,20 +53,32 @@ ToolBar
RowLayout
{
anchors.fill: parent
BabeButton
{
iconName: "love"
iconColor: accent && currentIndex === viewsIndex.babeit ? accentColor : textColor
onClicked: babeViewClicked()
id: settingsView
iconName: /*"headphones"*/ /*"media-optical-audio"*/ "application-menu"
iconColor: settingsDrawer.visible ? babeColor : textColor/*(pageStack.wideMode || pageStack.currentIndex === 0 ) && !isMobile ? accentColor : textColor*/
onClicked: settingsViewClicked()/*playlistViewClicked()*/
hoverEnabled: !isMobile
ToolTip.delay: 1000
ToolTip.timeout: 5000
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
{
......
......@@ -3,33 +3,31 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import org.kde.kirigami 2.2 as Kirigami
Kirigami.GlobalDrawer
{
id: settingsView
handleVisible: true
handleVisible: false
signal iconSizeChanged(int size)
readonly property bool activeBrainz : bae.brainzState()
y: header.height
height: parent.height - header.height - footer.height
visible: false
y: header.height
height: parent.height - header.height - footer.height
// // width: root.pageStack.wideMode ? views.width -1: root.width
// edge: Qt.RightEdge
// interactive: true
// focus: true
modal:true
// dragMargin :0
// dragMargin :0
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
// handle.y : 64
// handle.anchors.verticalCenter: parent.verticalCenter
// handle.anchors.top: parent.bottom
// handle.focus: false
// handle.y : 64
// handle.anchors.verticalCenter: parent.verticalCenter
// handle.anchors.top: parent.bottom
// handle.focus: false
// handle.y : coverSize
//handle.parent: ApplicationWindow.overlay
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