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)
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)
{
BAE::saveSettings("PLAYLIST", list, "MAINWINDOW");
......
......@@ -54,10 +54,13 @@ public:
/* SETTINGS */
Q_INVOKABLE void scanDir(const QString &url);
Q_INVOKABLE void brainz(const bool &on);
/* 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 QStringList lastPlaylist();
......
......@@ -68,7 +68,7 @@ settings::settings(QObject *parent) : QObject(parent)
if(BAE::isMobile())
this->populateDB({BAE::MusicPath, BAE::DownloadsPath});
else
checkCollection();
checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
connect(this->brainDeamon, &Brain::finished, [this]()
{
......@@ -88,9 +88,7 @@ settings::settings(QObject *parent) : QObject(parent)
connect(this->fileLoader, &FileLoader::finished,[this](int size)
{
this->brainzOn = true;
if(size>0)
if(size > 0)
{
this->collectionWatcher();
emit refreshTables({{BAE::TABLEMAP[TABLE::TRACKS], true},
......@@ -99,13 +97,13 @@ settings::settings(QObject *parent) : QObject(parent)
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
this->startBrainz(1500);
this->startBrainz(true, 1500);
}else
{
this->dirs.clear();
this->collectionWatcher();
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)
}
void settings::checkCollection()
void settings::checkCollectionBrainz(const bool &state)
{
// this->refreshCollectionPaths();
// this->collectionWatcher();
this->brainzOn = true;
this->startBrainz(3000);
this->startBrainz(state, 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();
}
else
this->brainDeamon->pause();
}
void settings::populateDB(const QStringList &paths)
......
......@@ -31,15 +31,15 @@ class settings : public QObject
public:
explicit settings(QObject *parent = nullptr);
~settings();
void checkCollection();
void collectionWatcher();
void checkCollectionBrainz(const bool &state);
void collectionWatcher();
private slots:
void handleDirectoryChanged(const QString &dir);
void on_remove_clicked();
public slots:
void startBrainz(const uint &speed);
void startBrainz(const bool &on, const uint &speed);
void populateDB(const QStringList &paths);
private:
......@@ -48,8 +48,6 @@ private:
Brain *brainDeamon;
YouTube *ytFetch;
Socket *babeSocket;
bool brainzOn = false;
QString pathToRemove;
......
......@@ -36,6 +36,12 @@ void Brain::stop()
this->t.wait();
}
void Brain::pause()
{
this->go = false;
}
bool Brain::isRunning() const
{
return this->go;
......@@ -86,10 +92,10 @@ void Brain::connectionParser(DB track, RESPONSE response)
{
switch(res)
{
case ONTOLOGY::ALBUM: this->parseAlbumInfo(track, response[res]); break;
case ONTOLOGY::ARTIST: this->parseArtistInfo(track, response[res]); break;
case ONTOLOGY::TRACK: this->parseTrackInfo(track, response[res]); break;
default: return;
case ONTOLOGY::ALBUM: this->parseAlbumInfo(track, response[res]); break;
case ONTOLOGY::ARTIST: this->parseArtistInfo(track, response[res]); break;
case ONTOLOGY::TRACK: this->parseTrackInfo(track, response[res]); break;
default: return;
}
this->t.msleep(this->interval);
}
......@@ -101,50 +107,50 @@ void Brain::parseAlbumInfo(DB &track, const INFO_K &response)
for(auto info : response.keys())
switch(info)
{
case PULPO::INFO::TAGS:
{
for(auto context : response[info].keys())
case PULPO::INFO::TAGS:
{
for(auto context : response[info].keys())
if(!response[info][context].toMap().isEmpty())
{
for(auto tag : response[info][context].toMap().keys() )
con->tagsAlbum(track, tag, CONTEXT_MAP[context]);
if(!response[info][context].toMap().isEmpty())
{
for(auto tag : response[info][context].toMap().keys() )
con->tagsAlbum(track, tag, CONTEXT_MAP[context]);
}else if (!response[info][context].toStringList().isEmpty())
{
for(auto tag : response[info][context].toStringList() )
con->tagsAlbum(track, tag, CONTEXT_MAP[context]);
}else if (!response[info][context].toStringList().isEmpty())
{
for(auto tag : response[info][context].toStringList() )
con->tagsAlbum(track, tag, CONTEXT_MAP[context]);
} else if (!response[info][context].toString().isEmpty())
{
con->tagsAlbum(track, response[info][context].toString(), CONTEXT_MAP[context]);
}
break;
}
} else if (!response[info][context].toString().isEmpty())
{
con->tagsAlbum(track, response[info][context].toString(), CONTEXT_MAP[context]);
}
break;
}
case PULPO::INFO::ARTWORK:
{
if(!response[info].isEmpty())
case PULPO::INFO::ARTWORK:
{
if(!response[info].isEmpty())
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
{
qDebug()<<"SAVING ARTWORK FOR: " << track[KEY::ALBUM];
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(), BAE::CachePath);
con->insertArtwork(track);
}
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
{
qDebug()<<"SAVING ARTWORK FOR: " << track[KEY::ALBUM];
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(), BAE::CachePath);
con->insertArtwork(track);
}
break;
}
break;
}
case PULPO::INFO::WIKI:
{
if(!response[info].isEmpty())
for (auto context : response[info].keys())
con->wikiAlbum(track, response[info][context].toString());
break;
}
case PULPO::INFO::WIKI:
{
if(!response[info].isEmpty())
for (auto context : response[info].keys())
con->wikiAlbum(track, response[info][context].toString());
break;
}
default: continue;
default: continue;
}
}
......@@ -154,57 +160,57 @@ void Brain::parseArtistInfo(DB &track, const INFO_K &response)
{
switch(info)
{
case PULPO::INFO::TAGS:
case PULPO::INFO::TAGS:
{
if(!response[info].isEmpty())
{
if(!response[info].isEmpty())
for(auto context : response[info].keys())
{
for(auto context : response[info].keys())
if(!response[info][context].toMap().isEmpty())
{
if(!response[info][context].toMap().isEmpty())
{
for(auto tag : response[info][context].toMap().keys() )
con->tagsArtist(track, tag, CONTEXT_MAP[context]);
}else if(!response[info][context].toStringList().isEmpty())
{
for(auto tag : response[info][context].toStringList() )
con->tagsArtist(track, tag, CONTEXT_MAP[context]);
}else if(!response[info][context].toString().isEmpty())
{
con->tagsArtist(track, response[info][context].toString(), CONTEXT_MAP[context]);
}
}
for(auto tag : response[info][context].toMap().keys() )
con->tagsArtist(track, tag, CONTEXT_MAP[context]);
} break;
}
}else if(!response[info][context].toStringList().isEmpty())
{
for(auto tag : response[info][context].toStringList() )
con->tagsArtist(track, tag, CONTEXT_MAP[context]);
case PULPO::INFO::ARTWORK:
{
if(!response[info].isEmpty())
{
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
}else if(!response[info][context].toString().isEmpty())
{
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(), BAE::CachePath);
con->insertArtwork(track);
con->tagsArtist(track, response[info][context].toString(), CONTEXT_MAP[context]);
}
}
break;
}
} break;
}
case PULPO::INFO::WIKI:
case PULPO::INFO::ARTWORK:
{
if(!response[info].isEmpty())
{
if(!response[info].isEmpty())
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
{
for (auto context : response[info].keys())
con->wikiArtist(track, response[info][context].toString());
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(), BAE::CachePath);
con->insertArtwork(track);
}
}
break;
}
break;
case PULPO::INFO::WIKI:
{
if(!response[info].isEmpty())
{
for (auto context : response[info].keys())
con->wikiArtist(track, response[info][context].toString());
}
default: continue;
break;
}
default: continue;
}
}
}
......@@ -214,97 +220,97 @@ void Brain::parseTrackInfo(DB &track, const INFO_K &response)
for(auto info : response.keys())
switch(info)
{
case PULPO::INFO::TAGS:
case PULPO::INFO::TAGS:
{
if(!response[info].isEmpty())
{
if(!response[info].isEmpty())
for(auto context : response[info].keys())
{
for(auto context : response[info].keys())
if (!response[info][context].toStringList().isEmpty())
{
if (!response[info][context].toStringList().isEmpty())
{
for(auto tag : response[info][context].toStringList() )
con->tagsTrack(track, tag, CONTEXT_MAP[context]);
}
if (!response[info][context].toString().isEmpty())
con->tagsTrack(track, response[info][context].toString(), CONTEXT_MAP[context]);
for(auto tag : response[info][context].toStringList() )
con->tagsTrack(track, tag, CONTEXT_MAP[context]);
}
}
break;
if (!response[info][context].toString().isEmpty())
con->tagsTrack(track, response[info][context].toString(), CONTEXT_MAP[context]);
}
}
case PULPO::INFO::WIKI:
{
if(!response[info].isEmpty())
{
if (!response[info][CONTEXT::WIKI].toString().isEmpty())
con->wikiTrack(track, response[info][CONTEXT::WIKI].toString());
break;
}
}
case PULPO::INFO::WIKI:
{
if(!response[info].isEmpty())
{
if (!response[info][CONTEXT::WIKI].toString().isEmpty())
con->wikiTrack(track, response[info][CONTEXT::WIKI].toString());
break;
}
case PULPO::INFO::ARTWORK:
break;
}
case PULPO::INFO::ARTWORK:
{
if(!response[info].isEmpty())
{
if(!response[info].isEmpty())
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
{
if(!response[info][CONTEXT::IMAGE].toByteArray().isEmpty())
{
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(),CachePath);
con->insertArtwork(track);
}
BAE::saveArt(track, response[info][CONTEXT::IMAGE].toByteArray(),CachePath);
con->insertArtwork(track);
}
break;
}
case PULPO::INFO::METADATA:
break;
}
case PULPO::INFO::METADATA:
{
TagInfo tag;
for(auto context :response[info].keys())
{
TagInfo tag;
for(auto context :response[info].keys())
switch(context)
{
case CONTEXT::ALBUM_TITLE:
{
switch(context)
qDebug()<<"SETTING TRACK MISSING METADATA";
tag.feed(track[KEY::URL]);
if(!response[info][context].toString().isEmpty())
{
case CONTEXT::ALBUM_TITLE:
{
qDebug()<<"SETTING TRACK MISSING METADATA";
tag.feed(track[KEY::URL]);
if(!response[info][context].toString().isEmpty())
{
tag.setAlbum(response[info][context].toString());
con->albumTrack(track, response[info][context].toString());
}
break;
}
case CONTEXT::TRACK_NUMBER:
{
tag.feed(track[KEY::URL]);
if(!response[info][context].toString().isEmpty())
tag.setTrack(response[info][context].toInt());
break;
}
default: continue;
tag.setAlbum(response[info][context].toString());
con->albumTrack(track, response[info][context].toString());
}
break;
}
break;
}
case CONTEXT::TRACK_NUMBER:
{
tag.feed(track[KEY::URL]);
if(!response[info][context].toString().isEmpty())
tag.setTrack(response[info][context].toInt());
case PULPO::INFO::LYRICS:
{
if(!response[info][CONTEXT::LYRIC].toString().isEmpty())
con->lyricsTrack(track, response[info][CONTEXT::LYRIC].toString());
break;
break;
}
default: continue;
}
}
default: continue;
break;
}
case PULPO::INFO::LYRICS:
{
if(!response[info][CONTEXT::LYRIC].toString().isEmpty())
con->lyricsTrack(track, response[info][CONTEXT::LYRIC].toString());
break;
}
default: continue;
}
}
......@@ -409,6 +415,9 @@ void Brain::albumInfo()
artworks = con->getDBData(queryTxt);
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)
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],
......@@ -428,7 +437,6 @@ void Brain::albumInfo()
conn.wikiAlbum(track, SLANG[W::NONE]);
});
emit this->done(TABLE::ALBUMS);
}
void Brain::artistInfo()
......@@ -444,6 +452,9 @@ void Brain::artistInfo()
KEYMAP[KEY::ARTWORK]);
auto artworks = con->getDBData(queryTxt);
if(!artworks.isEmpty())
emit this->done(TABLE::ARTISTS);
/* BEFORE FETCHING ONLINE LOOK UP IN THE CACHE FOR THE IMAGE */
for(auto artist : artworks)
if(BAE::artworkCache(artist, KEY::ARTIST))
......@@ -470,6 +481,5 @@ void Brain::artistInfo()
conn.wikiArtist(track, SLANG[W::NONE]);
});
emit this->done(TABLE::ARTISTS);
}
......@@ -24,6 +24,7 @@ public:
~Brain();
void start();
void stop();
void pause();
bool isRunning() const;
void setInterval(const uint &value);
......
......@@ -85,7 +85,12 @@ ItemDelegate
{
id: artworkCover
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
cache: false
antialiasing: true
......
......@@ -90,7 +90,7 @@ Menu
{
height: menuItemHeight
txt: "Queue"
onTriggered: list.queueTrack(currentIndex)
onTriggered: list.queueTrack(list.currentIndex)
}
TableMenuItem
......@@ -104,7 +104,7 @@ Menu
{
height: menuItemHeight
txt: "Remove"
onTriggered: {}
onTriggered: listModel.remove(list.currentIndex)
}
TableMenuItem
......
......@@ -339,7 +339,7 @@ Item
Layout.fillWidth:true
Layout.alignment: Qt.AlignCenter
horizontalAlignment: Qt.AlignHCenter
text: currentTrack.title + " - " + currentTrack.artist
text: currentTrack.title ? currentTrack.title + " - " + currentTrack.artist : "--- - "+currentTrack.artist
color: bae.foregroundColor()
font.pointSize: 8
}
......
......@@ -225,8 +225,14 @@ Drawer
CheckBox
{
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