Commit 72b842fa authored by Camilo Higuita's avatar Camilo Higuita

search suggestions popup initial work

parent eaebb485
......@@ -271,6 +271,7 @@ QVariant Babe::loadSetting(const QString &key, const QString &group, const QVari
void Babe::saveSetting(const QString &key, const QVariant &value, const QString &group)
{
bDebug::Instance()->msg("Setting saved: "+ key+" "+value.toString()+" "+group);
BAE::saveSettings(key, value, group);
}
......@@ -627,9 +628,10 @@ QVariantList Babe::searchFor(const QStringList &queries)
{
QVariantList mapList;
bool hasKey = false;
for(auto searchQuery : queries)
{
searchQuery = searchQuery.toLower();
if(searchQuery.contains(BAE::SearchTMap[BAE::SearchT::LIKE]+":") || searchQuery.startsWith("#"))
{
if(searchQuery.startsWith("#"))
......@@ -677,7 +679,7 @@ QVariantList Babe::searchFor(const QStringList &queries)
mapList += getSearchedTracks(key, searchQuery);
else
{
auto queryTxt = QString("SELECT t.*, al.artwork FROM tracks t INNER JOIN albums al ON t.album = al.album AND t.artist = al.artist WHERE t.title LIKE \"%"+searchQuery+"%\" OR t.artist LIKE \"%"+searchQuery+"%\" OR t.album LIKE \"%"+searchQuery+"%\"OR t.genre LIKE \"%"+searchQuery+"%\"OR t.url LIKE \"%"+searchQuery+"%\" LIMIT 1000");
auto queryTxt = QString("SELECT t.*, al.artwork FROM tracks t INNER JOIN albums al ON t.album = al.album AND t.artist = al.artist WHERE t.title LIKE \"%"+searchQuery+"%\" OR t.artist LIKE \"%"+searchQuery+"%\" OR t.album LIKE \"%"+searchQuery+"%\"OR t.genre LIKE \"%"+searchQuery+"%\"OR t.url LIKE \"%"+searchQuery+"%\" ORDER BY strftime(\"%s\", t.addDate) desc LIMIT 1000");
mapList += getDBDataQML(queryTxt);
}
}
......
......@@ -20,6 +20,7 @@
#include <QUuid>
#include <QString>
#include <QStringList>
#include "../../utils/babeconsole.h"
using namespace BAE;
......@@ -208,7 +209,7 @@ void CollectionDB::openDB(const QString &name)
}
if (!this->m_db.isOpen())
{
{
if(!this->m_db.open())
qDebug()<<"ERROR OPENING DB"<<this->m_db.lastError().text()<<m_db.connectionName();
else
......@@ -567,7 +568,7 @@ QVariantList CollectionDB::getDBDataQML(const QString &queryTxt)
mapList<< data;
}
}else qDebug()<< query.lastError()<< query.lastQuery();
}else bDebug::Instance()->msg(query.lastError().text()+" "+query.lastQuery());
return mapList;
}
......@@ -655,12 +656,14 @@ QVariantList CollectionDB::getSearchedTracks(const KEY &where, const QString &se
KEYMAP[KEY::ARTIST],
TABLEMAP[TABLE::ARTISTS_TAGS]);
else if(where == KEY::SQL)
queryTxt = search;
else
queryTxt = QString("SELECT t.*, al.artwork FROM %1 t inner join albums al on al.album = t.album and t.artist = al.artist WHERE %2 LIKE \"%%3%\"").arg(TABLEMAP[TABLE::TRACKS],
queryTxt = QString("SELECT t.*, al.artwork FROM %1 t inner join albums al on al.album = t.album and t.artist = al.artist WHERE %2 LIKE \"%%3%\" ORDER BY strftime(\"%s\", t.addDate) desc LIMIT 1000").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[where],
search);
qDebug()<<"SEARCH QUERY:"<<queryTxt;
bDebug::Instance()->msg("SEARCH QUERY: " + queryTxt);
return this->getDBDataQML(queryTxt);
......
......@@ -7,7 +7,7 @@
#include "services/local/player.h"
#include <QLibrary>
#include <QQuickStyle>
#include <QStyleHints>
#ifdef Q_OS_ANDROID
#include "./3rdparty/kirigami/src/kirigamiplugin.h"
//#include "java/notificationclient.h"
......@@ -26,6 +26,12 @@ int main(int argc, char *argv[])
app.setWindowIcon(QIcon("qrc:/assets/babe.png"));
app.setDesktopFileName(BAE::App);
/*needed for mobile*/
if(BAE::isMobile())
{
int pressAndHoldInterval = 1000; // in [ms]
QGuiApplication::styleHints()->setMousePressAndHoldInterval(pressAndHoldInterval);
}
QCommandLineParser parser;
parser.setApplicationDescription("Babe music player");
......
......@@ -13,6 +13,7 @@ import "widgets/MyBeatView"
import "widgets/PlaylistsView"
import "widgets/MainPlaylist"
import "widgets/SettingsView"
import "widgets/SearchView"
import "view_models"
import "view_models/BabeDialog"
......@@ -220,7 +221,7 @@ Kirigami.ApplicationWindow
onRefreshTables:
{
console.log("Clearing tables")
tracksView.list.clearTable()
tracksView.clearTable()
albumsView.clearGrid()
artistsView.clearGrid()
......@@ -231,9 +232,8 @@ Kirigami.ApplicationWindow
onTrackLyricsReady:
{
console.log("TRACKS READY SIGNAL2")
// if(url === currentTrack.url)
Player.setLyrics(lyrics)
if(url === currentTrack.url)
Player.setLyrics(lyrics)
}
onSkipTrack: Player.nextTrack()
......@@ -535,6 +535,7 @@ Kirigami.ApplicationWindow
iconName: "media-skip-forward"
onClicked: Player.nextTrack()
onPressAndHold: Player.playAt(Player.shuffle())
}
......
......@@ -83,7 +83,6 @@ bool Pulpo::initServices()
}else qDebug()<<"error settingUp lastfm service";
break;
}
......
......@@ -14,7 +14,6 @@
<file>assets/face.png</file>
<file>view_models/BabeHolder.qml</file>
<file>db/Queries.js</file>
<file>widgets/SearchTable.qml</file>
<file>utils/Help.js</file>
<file>assets/Babe.notifyrc</file>
<file>utils/BabeIcon.qml</file>
......@@ -71,5 +70,7 @@
<file>widgets/PlaybackBar.qml</file>
<file>assets/banner-yellow.png</file>
<file>widgets/SettingsView/BabeConsole.qml</file>
<file>widgets/SearchView/SearchTable.qml</file>
<file>widgets/SearchView/SearchSuggestions.qml</file>
</qresource>
</RCC>
......@@ -184,7 +184,7 @@ function savePlaylist()
function clearOutPlaylist()
{
root.mainPlaylist.list.clearTable()
mainPlaylist.tabe.clearTable()
stop()
}
......@@ -206,11 +206,11 @@ function playAll(tracks)
{
if(tracks)
{
root.sync = false
root.syncPlaylist = ""
root.infoMsg = ""
sync = false
syncPlaylist = ""
infoMsg = ""
root.mainPlaylist.list.clearTable()
mainPlaylist.table.clearTable()
root.pageStack.currentIndex = 0
for(var i in tracks)
......@@ -219,7 +219,7 @@ function playAll(tracks)
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
root.mainPlaylist.list.positionViewAtBeginning()
mainPlaylist.list.positionViewAtBeginning()
playAt(0)
}
......
......@@ -168,7 +168,8 @@ enum class KEY :uint8_t
RETRIEVAL_DATE = 22,
COMMENT = 23,
ID = 24,
NONE = 25
SQL = 25,
NONE = 26
};
typedef QMap<BAE::KEY, QString> DB;
......@@ -200,7 +201,8 @@ static const DB KEYMAP =
{KEY::CONTEXT, "context"},
{KEY::RETRIEVAL_DATE, "retrieval_date"},
{KEY::ID, "id"},
{KEY::COMMENT, "comment"}
{KEY::COMMENT, "comment"},
{KEY::SQL, "sql"}
};
static const DB TracksColsMap =
......
......@@ -33,6 +33,12 @@ Item
focus: true
function clearTable()
{
list.model.clear()
}
ColumnLayout
{
anchors.fill: parent
......@@ -162,11 +168,6 @@ Item
NumberAnimation { properties: "x,y"; duration: 100 }
}
function clearTable()
{
listModel.clear()
}
BabeHolder
{
id: holder
......
......@@ -34,12 +34,12 @@ Popup
enter: Transition
{
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; duration: 150 }
}
exit: Transition
{
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; duration: 150 }
}
Material.accent: babeColor
......
......@@ -84,7 +84,7 @@ BabeDialog
onOpened:
{
newPlaylistField.clear()
playlistsList.list.clearTable()
playlistsList.clearTable()
var playlists = bae.get(Q.GET.playlists)
if(playlists.length > 0)
for(var i in playlists)
......
......@@ -88,7 +88,7 @@ BabePopup
function load(folderUrl)
{
dirList.list.clearTable()
dirList.clearTable()
var dirs = bae.getDirs(folderUrl)
for(var path in dirs)
dirList.model.append(dirs[path])
......
......@@ -156,7 +156,7 @@ BabeGrid
{
drawerList.headerBarTitle = album
drawer.open()
list.clearTable()
table.clearTable()
var query = Q.GET.albumTracks_.arg(album)
query = query.arg(artist)
......
......@@ -151,7 +151,7 @@ BabeGrid
{
drawerList.headerBarTitle = artist
drawer.open()
list.clearTable()
table.clearTable()
var query = Q.GET.artistTracks_.arg(artist)
var map = bae.get(query)
......
......@@ -153,7 +153,7 @@ Kirigami.PageRow
function populate(query)
{
playlistQuery = query
filterList.list.clearTable()
filterList.clearTable()
var tracks = bae.get(query)
......
import QtQuick 2.0
import "../../view_models"
BabePopup
{
id: searchSuggestionsRoot
property alias model : suggestionsList.model
BabeList
{
id: suggestionsList
anchors.fill: parent
headerBarVisible: false
model: ListModel {id: suggestionsModel}
delegate: BabeDelegate
{
id: delegate
label: suggestion
Connections
{
target: delegate
onClicked:
{
suggestionsList.currentIndex = index
searchInput.text = suggestionsList.model.get(index).suggestion
runSearch()
}
}
}
}
onOpened:
{
suggestionsList.clearTable()
var qq = bae.loadSetting("QUERIES", "BABE", {})
savedQueries = qq.split(",")
for(var i=0; i < 5; i++)
if(i < savedQueries.length )
suggestionsList.model.append({suggestion: savedQueries[i]})
}
}
import QtQuick 2.9
import QtQuick.Controls 2.2
import org.kde.kirigami 2.2 as Kirigami
import QtQuick.Layouts 1.3
import "../view_models"
import "../../view_models"
import QtGraphicalEffects 1.0
import "../view_models/BabeTable"
import "../db/Queries.js" as Q
import "../../view_models/BabeTable"
import "../../db/Queries.js" as Q
Item
{
property alias searchInput : searchInput
property alias searchTable : searchTable
property var searchRes : []
property var savedQueries : []
function runSearch()
{
if(searchInput.text)
{
if(searchInput !== searchTable.headerBarTitle)
if(searchInput.text !== searchTable.headerBarTitle)
{
suggestionsPopup.close()
if(savedQueries.indexOf(searchInput.text) < 0)
{
savedQueries.unshift(searchInput.text)
// suggestionsPopup.model.insert(0, {suggestion: searchInput.text})
bae.saveSetting("QUERIES", savedQueries.join(","), "BABE")
}
var query = searchInput.text
searchTable.headerBarTitle = query
searchTable.headerBarTitle = '"'+query+"'"
var queries = query.split(",")
searchRes = bae.searchFor(queries)
populate(searchView.searchRes)
}
}
}
function clearSearch()
{
searchInput.clear()
searchTable.list.clearTable()
searchTable.clearTable()
searchTable.headerBarTitle = ""
searchRes = []
suggestionsPopup.close()
}
function populate(tracks)
{
searchTable.list.clearTable()
searchTable.clearTable()
for(var i in tracks)
searchTable.model.append(tracks[i])
}
SearchSuggestions
{
id: suggestionsPopup
focus: false
parent: searchBox
width: parent.width*0.9
height: 200
modal: false
closePolicy: Popup.CloseOnPressOutsideParent
y: -(height+contentMargins*2)
}
Rectangle
{
anchors.fill: parent
color: altColor
z: -999
}
ColumnLayout
{
anchors.fill: parent
......@@ -112,19 +135,20 @@ Item
selectByMouse: !root.isMobile
selectionColor: babeHighlightColor
selectedTextColor: foregroundColor
//focus: true
//activeFocusOnPress: true
onAccepted: runSearch()
onTextChanged: if(searchInput.text.length>0) suggestionsPopup.open()
}
BabeButton
{
Layout.rightMargin: contentMargins
visible: searchInput.text.length > 0
iconName: "edit-clear"
onClicked: clearSearch()
}
}
}
}
}
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