Commit 5a6f3a0d authored by Camilo Higuita's avatar Camilo Higuita

work on search and fixes...

parent 05e912a5
......@@ -20,6 +20,7 @@ Babe::Babe(QObject *parent) : QObject(parent)
{
emit this->refreshTables(tables);
});
}
QVariantList Babe::get(const QString &queryTxt)
......@@ -148,12 +149,12 @@ bool Babe::rateTrack(const QString &path, const int &value)
int Babe::trackRate(const QString &path)
{
return this->con->getTrackStars(path);
return this->con->getTrackStars(path);
}
void Babe::scanDir(const QString &url)
{
emit this->set->collectionPathChanged(url);
emit this->set->collectionPathChanged({url});
}
void Babe::savePlaylist(const QStringList &list)
......@@ -243,21 +244,7 @@ QString Babe::babeColor()
bool Babe::isMobile()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return true;
#elif defined(Q_OS_HAIKU)
return false;
#endif
return BAE::isMobile();
}
QString Babe::loadCover(const QString &url)
......@@ -283,6 +270,71 @@ QString Babe::loadCover(const QString &url)
return this->fetchCoverArt(track);
}
QVariantList Babe::searchFor(const QStringList &queries)
{
BAE::DB_LIST mapList;
bool hasKey=false;
for(auto searchQuery : queries)
{
if(searchQuery.contains(BAE::SearchTMap[BAE::SearchT::LIKE]+":") || searchQuery.startsWith("#"))
{
if(searchQuery.startsWith("#"))
searchQuery=searchQuery.replace("#","").trimmed();
else
searchQuery=searchQuery.replace(BAE::SearchTMap[BAE::SearchT::LIKE]+":","").trimmed();
searchQuery=searchQuery.trimmed();
if(!searchQuery.isEmpty())
{
mapList += this->con->getSearchedTracks(BAE::KEY::WIKI, searchQuery);
mapList += this->con->getSearchedTracks(BAE::KEY::TAG, searchQuery);
mapList += this->con->getSearchedTracks(BAE::KEY::LYRICS, searchQuery);
}
}else if(searchQuery.contains((BAE::SearchTMap[BAE::SearchT::SIMILAR]+":")))
{
searchQuery=searchQuery.replace(BAE::SearchTMap[BAE::SearchT::SIMILAR]+":","").trimmed();
searchQuery=searchQuery.trimmed();
if(!searchQuery.isEmpty())
mapList += this->con->getSearchedTracks(BAE::KEY::TAG,searchQuery);
}else
{
BAE::KEY key;
QMapIterator<BAE::KEY, QString> k(BAE::KEYMAP);
while (k.hasNext())
{
k.next();
if(searchQuery.contains(QString(k.value()+":")))
{
hasKey=true;
key=k.key();
searchQuery=searchQuery.replace(k.value()+":","").trimmed();
}
}
searchQuery = searchQuery.trimmed();
qDebug()<<"Searching for: "<<searchQuery;
if(!searchQuery.isEmpty())
{
if(hasKey)
mapList += this->con->getSearchedTracks(key, searchQuery);
else
{
auto queryTxt = QString("SELECT * FROM tracks WHERE title LIKE \"%"+searchQuery+"%\" OR artist LIKE \"%"+searchQuery+"%\" OR album LIKE \"%"+searchQuery+"%\"OR genre LIKE \"%"+searchQuery+"%\"OR url LIKE \"%"+searchQuery+"%\" LIMIT 1000");
mapList += this->con->getDBData(queryTxt);
}
}
}
}
return this->transformData(mapList);
}
QString Babe::fetchCoverArt(DB &song)
{
if(BAE::artworkCache(song, KEY::ALBUM)) return song[KEY::ARTWORK];
......
......@@ -60,7 +60,7 @@ public:
/*USEFUL*/
Q_INVOKABLE QString loadCover(const QString &url);
Q_INVOKABLE QVariantList searchFor(const QStringList &queries);
private:
CollectionDB *con;
......
......@@ -92,7 +92,7 @@ ApplicationWindow
{
id: searchBox
width: parent.width
height: 32
height: 40
color: bae.midColor()
TextInput
......@@ -103,7 +103,11 @@ ApplicationWindow
color: bae.foregroundColor()
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
selectByMouse: !bae.isMobile()
// selectByMouseChanged: !bae.isMobile()
// canPaste: true
// canUndo: true
// canRedo: true
property string placeholderText: "Search..."
Label
......@@ -117,6 +121,25 @@ ApplicationWindow
color: bae.foregroundColor()
}
// onTextChanged:
// {
// if(searchInput.text.length===0)
// albumsView.populate()
// }
onAccepted:
{
var query = searchInput.text
var queries = query.split(",")
var res = bae.searchFor(queries)
searchView.populate(res)
// albumsView.filter(res)
currentView = 6
}
}
}
......@@ -210,6 +233,11 @@ ApplicationWindow
onIconSizeChanged: iconSize = size
}
SearchTable
{
id: searchView
}
}
}
}
......
......@@ -29,5 +29,6 @@
<file>widgets/LyricsView.qml</file>
<file>db/Queries.js</file>
<file>view_models/TableMenu.qml</file>
<file>widgets/SearchTable.qml</file>
</qresource>
</RCC>
......@@ -31,19 +31,16 @@ public:
this->t.wait();
}
void requestPath(QString path)
void requestPaths(QStringList paths)
{
qDebug()<<"FROM file loader"<< path;
this->queue << path;
for(auto url : this->queue)
qDebug()<<"FROM file loader"<< &paths;
if(!go)
{
if(!go)
{
this->go = true;
QMetaObject::invokeMethod(this, "getTracks", Q_ARG(QString, url));
this->queue.removeOne(url);
}
this->go = true;
QMetaObject::invokeMethod(this, "getTracks", Q_ARG(QStringList, paths));
}
}
void nextTrack()
......@@ -53,23 +50,28 @@ public:
public slots:
void getTracks(QString path)
void getTracks(QStringList paths)
{
qDebug()<<"GETTING TRACKS FROM SETTINGS";
QStringList urls;
if (QFileInfo(path).isDir())
for(auto path : paths)
{
QDirIterator it(path, BAE::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
if (QFileInfo(path).isDir())
{
QDirIterator it(path, BAE::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
} else if (QFileInfo(path).isFile()) urls<<path;
}
qDebug()<<"URLS SIZEW FOR:"<<paths<< urls.size();
int newTracks = 0;
if(urls.size()>0)
{
int newTracks = 0;
for(auto url : urls)
{
if(go)
......@@ -108,18 +110,16 @@ public slots:
}
}else break;
}
emit collectionSize(newTracks);
}
this->t.msleep(100);
emit this->finished();
emit this->finished(newTracks);
this->go = false;
}
signals:
void trackReady(BAE::DB track);
void finished();
void finished(int size);
void collectionSize(int size);
private:
......
......@@ -60,7 +60,10 @@ settings::settings(QObject *parent) : QObject(parent)
youtubeCache_dir.mkpath(".");
// if(!connection->check_existance(TABLEMAP[TABLE::SOURCES], KEYMAP[KEY::URL], BAE::MusicPath))
this->populateDB(BAE::MusicPath);
if(BAE::isMobile())
this->populateDB({BAE::MusicPath, BAE::DownloadsPath});
connect(this->brainDeamon, &Brain::finished, [this]()
{
......@@ -73,32 +76,34 @@ settings::settings(QObject *parent) : QObject(parent)
});
connect(this->fileLoader, &FileLoader::collectionSize, [this](int size)
// connect(this->fileLoader, &FileLoader::trackReady, [this]()
// {
// this->ui->progressBar->setValue(this->ui->progressBar->value()+1);
// });
connect(this->fileLoader, &FileLoader::finished,[this](int size)
{
this->brainzOn = true;
if(size>0)
this->brainzOn = true;
else
{
this->brainzOn = false;
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(500);
}else
{
this->dirs.clear();
this->collectionWatcher();
this->watcher->removePaths(watcher->directories());
this->startBrainz(1500);
}
});
// connect(this->fileLoader, &FileLoader::trackReady, [this]()
// {
// this->ui->progressBar->setValue(this->ui->progressBar->value()+1);
// });
connect(this->fileLoader, &FileLoader::finished,[this]()
{
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();
});
connect(this, &settings::collectionPathChanged, this, &settings::populateDB);
......@@ -126,7 +131,7 @@ void settings::on_remove_clicked()
this->collectionWatcher();
this->watcher->removePaths(watcher->directories());
emit refreshTables({{TABLEMAP[TABLE::TRACKS], true},
{TABLEMAP[TABLE::PLAYLISTS], true}});
{TABLEMAP[TABLE::PLAYLISTS], true}});
}
}
}
......@@ -186,7 +191,7 @@ void settings::handleDirectoryChanged(const QString &dir)
connect(wait, &QTimer::timeout,[=]()
{
emit collectionPathChanged(dir);
emit collectionPathChanged({dir});
wait->deleteLater();
});
......@@ -198,22 +203,27 @@ void settings::checkCollection()
{
this->refreshCollectionPaths();
this->collectionWatcher();
this->startBrainz();
this->brainzOn = true;
this->startBrainz(1500);
}
void settings::startBrainz()
void settings::startBrainz(const int &speed)
{
if(this->brainzOn)
{
this->brainDeamon->setInterval(speed);
this->brainDeamon->start();
}
}
void settings::populateDB(const QString &path)
void settings::populateDB(const QStringList &paths)
{
qDebug() << "Function Name: " << Q_FUNC_INFO
<< "new path for database action: " << path;
auto newPath = path;
if(path.startsWith("file://"))
newPath = newPath.replace("file://", "");
fileLoader->requestPath(newPath);
<< "new path for database action: " << paths;
auto newPaths = paths;
for(auto path : newPaths)
if(path.startsWith("file://"))
path.replace("file://", "");
fileLoader->requestPaths(newPaths);
}
......@@ -39,8 +39,8 @@ private slots:
void on_remove_clicked();
public slots:
void startBrainz();
void populateDB(const QString &path);
void startBrainz(const int &speed);
void populateDB(const QStringList &paths);
private:
FileLoader *fileLoader;
......@@ -62,7 +62,7 @@ private:
void addToWatcher(QStringList paths);
signals:
void collectionPathChanged(QString newPath);
void collectionPathChanged(QStringList newPaths);
void refreshTables(QVariantMap tables);
void albumArtReady(const DB &album);
void brainFinished();
......
......@@ -223,7 +223,7 @@ namespace BAE
const QString CollectionDBPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/babe/";
const QString CachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)+"/babe/";
const QString YoutubeCachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)+"/babe/youtube/";
const QString ExtensionFetchingPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
const QString DownloadsPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
const QString NotifyDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
const QString BabePort = "8483";
const QString App = "Babe";
......@@ -393,6 +393,25 @@ namespace BAE
return false;
}
inline bool isMobile()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return true;
#elif defined(Q_OS_HAIKU)
return false;
#endif
}
}
......
......@@ -44,7 +44,7 @@ bool Brain::isRunning() const
void Brain::setInterval(const uint &value)
{
qDebug()<< "reseting the interval brainz";
this->interval = value*60000;
this->interval = value;
}
void Brain::setInfo(DB_LIST dataList, ONTOLOGY ontology, QList<SERVICES> services, INFO info, RECURSIVE recursive, void (*cb)(DB))
......@@ -60,7 +60,7 @@ void Brain::setInfo(DB_LIST dataList, ONTOLOGY ontology, QList<SERVICES> service
if (cb != nullptr) cb(data);
this->pulpo.feed(data, recursive);
this->t.msleep(500);
this->t.msleep(this->interval);
if(!go) return;
}
}
......
......@@ -43,7 +43,7 @@ private:
QThread t;
CollectionDB *con;
Pulpo pulpo;
uint interval = 20000;
uint interval = 500;
bool go = false;
signals:
......
......@@ -11,11 +11,14 @@ Item
property string fillColor: bae.midColor()
property string textColor: bae.foregroundColor()
property int fontSize : bae.isMobile()? 12 : 10
property bool hide : false
id: root
width: albumSize
height: typeof album === 'undefined' ? parseInt(albumSize+(albumSize*0.3)) : parseInt(albumSize+(albumSize*0.4))
visible: !hide
DropShadow
{
anchors.fill: card
......
......@@ -119,35 +119,35 @@ Menu
onClicked: rateIt(3)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 4 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(4)
}
ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Icon
{
text: starIcon
color: rate >= 5 ? starColor :starReg
iconSize: starSize
}
onClicked: rateIt(5)
}
// ToolButton
// {
// Layout.fillHeight: true
// Layout.fillWidth: true
// Layout.alignment: Qt.AlignCenter
// Icon
// {
// text: starIcon
// color: rate >= 4 ? starColor :starReg
// iconSize: starSize
// }
// onClicked: rateIt(4)
// }
// ToolButton
// {
// Layout.fillHeight: true
// Layout.fillWidth: true
// Layout.alignment: Qt.AlignCenter
// Icon
// {
// text: starIcon
// color: rate >= 5 ? starColor :starReg
// iconSize: starSize
// }
// onClicked: rateIt(5)
// }
......
......@@ -20,6 +20,7 @@ BabeGrid
signal queueTrack(var track)
signal appendAlbum(var tracks)
Drawer
{
id: drawer
......@@ -137,7 +138,7 @@ BabeGrid
onQuickPlayTrack:
{
drawer.close()
albumsViewGrid.playTrack(model.get(index))
albumsViewGrid.playTrack(model.get(index))
}
onQueueTrack:
......@@ -173,5 +174,31 @@ BabeGrid
gridModel.append(map[i])
}
function filter(tracks)
{
var matches = []
for(var i = 0; i<tracks.length; i++)
matches.push(find(tracks[i].album))
for(var j = 0 ; j < albumsViewGrid.gridModel.count; j++)
albumsViewGrid.gridModel.remove(j,1)
// for(var match in matches)
// {
// albumsViewGrid.gridModel.get(match).hide = true
// console.log(match)
// }
}
function find(query)
{
var indexes = []
for(var i = 0 ; i < albumsViewGrid.gridModel.count; i++)
if(albumsViewGrid.gridModel.get(i).album.includes(query))
indexes.push(i)
}
Component.onCompleted: populate()
}
import QtQuick 2.9
import "../view_models"
import "../db/Queries.js" as Q
BabeTable
{
id: searchTable
trackNumberVisible: false
function populate(tracks)
{
searchTable.clearTable()
for(var i in tracks)
searchTable.model.append(tracks[i])
}
Component.onCompleted: populate()
}
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