Commit 610a3225 authored by Camilo Higuita's avatar Camilo Higuita

pause brainz dreamon from interface

parent e909e066
...@@ -214,6 +214,24 @@ void Babe::scanDir(const QString &url) ...@@ -214,6 +214,24 @@ void Babe::scanDir(const QString &url)
emit this->set->collectionPathChanged({url}); emit this->set->collectionPathChanged({url});
} }
void Babe::brainz(const bool &on)
{
this->set->checkCollectionBrainz(on);
}
QVariant Babe::loadSetting(const QString &key, const QString &group, const QVariant &defaultValue)
{
auto res = BAE::loadSettings(key, group, defaultValue);
qDebug()<<res<<"LOADSET RES";
return res;
}
void Babe::saveSetting(const QString &key, const QVariant &value, const QString &group)
{
qDebug()<<key<<value<<group;
BAE::saveSettings(key, value, group);
}
void Babe::savePlaylist(const QStringList &list) void Babe::savePlaylist(const QStringList &list)
{ {
BAE::saveSettings("PLAYLIST", list, "MAINWINDOW"); BAE::saveSettings("PLAYLIST", list, "MAINWINDOW");
......
...@@ -54,10 +54,13 @@ public: ...@@ -54,10 +54,13 @@ public:
/* SETTINGS */ /* SETTINGS */
Q_INVOKABLE void scanDir(const QString &url); Q_INVOKABLE void scanDir(const QString &url);
Q_INVOKABLE void brainz(const bool &on);
/* STATIC METHODS */ /* STATIC METHODS */
Q_INVOKABLE static void saveSetting(const QString &key, const QVariant &value, const QString &group);
Q_INVOKABLE static QVariant loadSetting(const QString &key, const QString &group, const QVariant &defaultValue);
Q_INVOKABLE static void savePlaylist(const QStringList &list); Q_INVOKABLE static void savePlaylist(const QStringList &list);
Q_INVOKABLE static QStringList lastPlaylist(); Q_INVOKABLE static QStringList lastPlaylist();
......
...@@ -68,7 +68,7 @@ settings::settings(QObject *parent) : QObject(parent) ...@@ -68,7 +68,7 @@ settings::settings(QObject *parent) : QObject(parent)
if(BAE::isMobile()) if(BAE::isMobile())
this->populateDB({BAE::MusicPath, BAE::DownloadsPath}); this->populateDB({BAE::MusicPath, BAE::DownloadsPath});
else else
checkCollection(); checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
connect(this->brainDeamon, &Brain::finished, [this]() connect(this->brainDeamon, &Brain::finished, [this]()
{ {
...@@ -88,9 +88,7 @@ settings::settings(QObject *parent) : QObject(parent) ...@@ -88,9 +88,7 @@ settings::settings(QObject *parent) : QObject(parent)
connect(this->fileLoader, &FileLoader::finished,[this](int size) connect(this->fileLoader, &FileLoader::finished,[this](int size)
{ {
this->brainzOn = true; if(size > 0)
if(size>0)
{ {
this->collectionWatcher(); this->collectionWatcher();
emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true}, emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true},
...@@ -99,13 +97,13 @@ settings::settings(QObject *parent) : QObject(parent) ...@@ -99,13 +97,13 @@ settings::settings(QObject *parent) : QObject(parent)
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}}); {BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
this->startBrainz(1500); this->startBrainz(true, 1500);
}else }else
{ {
this->dirs.clear(); this->dirs.clear();
this->collectionWatcher(); this->collectionWatcher();
this->watcher->removePaths(watcher->directories()); this->watcher->removePaths(watcher->directories());
this->startBrainz(3000); this->startBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool(), 3000);
} }
...@@ -204,21 +202,21 @@ void settings::handleDirectoryChanged(const QString &dir) ...@@ -204,21 +202,21 @@ void settings::handleDirectoryChanged(const QString &dir)
} }
void settings::checkCollection() void settings::checkCollectionBrainz(const bool &state)
{ {
// this->refreshCollectionPaths(); // this->refreshCollectionPaths();
// this->collectionWatcher(); // this->collectionWatcher();
this->brainzOn = true; this->startBrainz(state, 3000);
this->startBrainz(3000);
} }
void settings::startBrainz(const uint &speed) void settings::startBrainz(const bool &on, const uint &speed)
{ {
if(this->brainzOn)
{
this->brainDeamon->setInterval(speed); this->brainDeamon->setInterval(speed);
if(on)
this->brainDeamon->start(); this->brainDeamon->start();
} else
this->brainDeamon->pause();
} }
void settings::populateDB(const QStringList &paths) void settings::populateDB(const QStringList &paths)
......
...@@ -31,7 +31,7 @@ class settings : public QObject ...@@ -31,7 +31,7 @@ class settings : public QObject
public: public:
explicit settings(QObject *parent = nullptr); explicit settings(QObject *parent = nullptr);
~settings(); ~settings();
void checkCollection(); void checkCollectionBrainz(const bool &state);
void collectionWatcher(); void collectionWatcher();
private slots: private slots:
...@@ -39,7 +39,7 @@ private slots: ...@@ -39,7 +39,7 @@ private slots:
void on_remove_clicked(); void on_remove_clicked();
public slots: public slots:
void startBrainz(const uint &speed); void startBrainz(const bool &on, const uint &speed);
void populateDB(const QStringList &paths); void populateDB(const QStringList &paths);
private: private:
...@@ -49,8 +49,6 @@ private: ...@@ -49,8 +49,6 @@ private:
YouTube *ytFetch; YouTube *ytFetch;
Socket *babeSocket; Socket *babeSocket;
bool brainzOn = false;
QString pathToRemove; QString pathToRemove;
......
...@@ -36,6 +36,12 @@ void Brain::stop() ...@@ -36,6 +36,12 @@ void Brain::stop()
this->t.wait(); this->t.wait();
} }
void Brain::pause()
{
this->go = false;
}
bool Brain::isRunning() const bool Brain::isRunning() const
{ {
return this->go; return this->go;
...@@ -409,6 +415,9 @@ void Brain::albumInfo() ...@@ -409,6 +415,9 @@ void Brain::albumInfo()
artworks = con->getDBData(queryTxt); artworks = con->getDBData(queryTxt);
this->setInfo(artworks, ontology, services, PULPO::INFO::ARTWORK, PULPO::RECURSIVE::OFF, nullptr); this->setInfo(artworks, ontology, services, PULPO::INFO::ARTWORK, PULPO::RECURSIVE::OFF, nullptr);
if(!artworks.isEmpty())
emit this->done(TABLE::ALBUMS);
//select album, artist from albums where album not in (select album from albums_tags) and artist not in (select artist from albums_tags) //select album, artist from albums where album not in (select album from albums_tags) and artist not in (select artist from albums_tags)
qDebug()<<"getting missing album tags"; qDebug()<<"getting missing album tags";
queryTxt = QString("SELECT %1, %2 FROM %3 WHERE %1 NOT IN ( SELECT %1 FROM %4 ) AND %2 NOT IN ( SELECT %2 FROM %4 )").arg(KEYMAP[KEY::ALBUM], queryTxt = QString("SELECT %1, %2 FROM %3 WHERE %1 NOT IN ( SELECT %1 FROM %4 ) AND %2 NOT IN ( SELECT %2 FROM %4 )").arg(KEYMAP[KEY::ALBUM],
...@@ -428,7 +437,6 @@ void Brain::albumInfo() ...@@ -428,7 +437,6 @@ void Brain::albumInfo()
conn.wikiAlbum(track, SLANG[W::NONE]); conn.wikiAlbum(track, SLANG[W::NONE]);
}); });
emit this->done(TABLE::ALBUMS);
} }
void Brain::artistInfo() void Brain::artistInfo()
...@@ -444,6 +452,9 @@ void Brain::artistInfo() ...@@ -444,6 +452,9 @@ void Brain::artistInfo()
KEYMAP[KEY::ARTWORK]); KEYMAP[KEY::ARTWORK]);
auto artworks = con->getDBData(queryTxt); auto artworks = con->getDBData(queryTxt);
if(!artworks.isEmpty())
emit this->done(TABLE::ARTISTS);
/* BEFORE FETCHING ONLINE LOOK UP IN THE CACHE FOR THE IMAGE */ /* BEFORE FETCHING ONLINE LOOK UP IN THE CACHE FOR THE IMAGE */
for(auto artist : artworks) for(auto artist : artworks)
if(BAE::artworkCache(artist, KEY::ARTIST)) if(BAE::artworkCache(artist, KEY::ARTIST))
...@@ -470,6 +481,5 @@ void Brain::artistInfo() ...@@ -470,6 +481,5 @@ void Brain::artistInfo()
conn.wikiArtist(track, SLANG[W::NONE]); conn.wikiArtist(track, SLANG[W::NONE]);
}); });
emit this->done(TABLE::ARTISTS);
} }
...@@ -24,6 +24,7 @@ public: ...@@ -24,6 +24,7 @@ public:
~Brain(); ~Brain();
void start(); void start();
void stop(); void stop();
void pause();
bool isRunning() const; bool isRunning() const;
void setInterval(const uint &value); void setInterval(const uint &value);
......
...@@ -85,7 +85,12 @@ ItemDelegate ...@@ -85,7 +85,12 @@ ItemDelegate
{ {
id: artworkCover id: artworkCover
anchors.fill: parent anchors.fill: parent
source: (artwork.length>0 && artwork !== "none" && artwork)? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png" source:
{
if(artwork)
(artwork.length>0 && artwork !== "none")? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png"
else "qrc:/assets/cover.png"
}
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
cache: false cache: false
antialiasing: true antialiasing: true
......
...@@ -90,7 +90,7 @@ Menu ...@@ -90,7 +90,7 @@ Menu
{ {
height: menuItemHeight height: menuItemHeight
txt: "Queue" txt: "Queue"
onTriggered: list.queueTrack(currentIndex) onTriggered: list.queueTrack(list.currentIndex)
} }
TableMenuItem TableMenuItem
...@@ -104,7 +104,7 @@ Menu ...@@ -104,7 +104,7 @@ Menu
{ {
height: menuItemHeight height: menuItemHeight
txt: "Remove" txt: "Remove"
onTriggered: {} onTriggered: listModel.remove(list.currentIndex)
} }
TableMenuItem TableMenuItem
......
...@@ -339,7 +339,7 @@ Item ...@@ -339,7 +339,7 @@ Item
Layout.fillWidth:true Layout.fillWidth:true
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
text: currentTrack.title + " - " + currentTrack.artist text: currentTrack.title ? currentTrack.title + " - " + currentTrack.artist : "--- - "+currentTrack.artist
color: bae.foregroundColor() color: bae.foregroundColor()
font.pointSize: 8 font.pointSize: 8
} }
......
...@@ -225,11 +225,17 @@ Drawer ...@@ -225,11 +225,17 @@ Drawer
CheckBox CheckBox
{ {
id: brainzCheck id: brainzCheck
checkState: bae.loadSetting("BRAINZ", "BABE", false) === "true" ? Qt.Checked : Qt.Unchecked
onCheckStateChanged:
{
bae.saveSetting("BRAINZ",brainzCheck.checkState === Qt.Checked ? true : false, "BABE")
bae.brainz(brainzCheck.checkState === Qt.Checked ? true : false)
} }
} }
} }
}
} }
......
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