Commit d63ba249 authored by camilo higuita's avatar camilo higuita

initial work on search view, searching is now working #32 #3

parent 1a4ffda0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.4.1, 2018-04-03T22:44:49. -->
<!-- Written by QtCreator 4.4.1, 2018-04-12T23:05:11. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -13,7 +13,7 @@ var Query = {
albumPics_ : "select i.* from images_albums ia inner join images i on i.url = ia.url where ia.album = \"%1\" order by strftime(\"%s\", ia.addDate) desc",
albumPicsTags_ : "select i.* from images i inner join images_tags it on it.url = i.url inner join albums_tags at on at.tag = it.tag where at.album = \"%1\"",
favPics: "select * from images where fav = 1",
recentPics: "select * from images order by strftime(\"%s\", addDate) desc limit 50"
recentPics: "select * from images order by strftime(\"%s\", addDate) desc limit 50",
searchFor_: "select * from images where title like \"%%1%\" or url like \"%%1%\" union select distinct i.* from images i inner join images_tags it on it.url = i.url where it.tag like \"%%1%\" collate nocase limit 1000"
}
......@@ -87,34 +87,34 @@ bool DBActions::execQuery(const QString &queryTxt)
bool DBActions::insertPic(const PIX::DB &img)
{
auto url = img[PIX::KEY::URL];
auto title = img[PIX::KEY::TITLE];
auto rate = img[PIX::KEY::RATE];
auto fav = img[PIX::KEY::FAV];
auto color = img[PIX::KEY::COLOR];
auto addDate = img[PIX::KEY::ADD_DATE];
auto sourceUrl = img[PIX::KEY::SOURCES_URL];
auto picDate = img[PIX::KEY::PIC_DATE];
auto place = img[PIX::KEY::PLACE];
auto format = img[PIX::KEY::FORMAT];
qDebug()<< "writting to db: "<<title<<url;
/* first needs to insert album and artist*/
QVariantMap sourceMap {{PIX::KEYMAP[PIX::KEY::URL],sourceUrl}};
insert(PIX::TABLEMAP[PIX::TABLE::SOURCES], sourceMap);
QVariantMap imgMap {{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::SOURCES_URL], sourceUrl},
{PIX::KEYMAP[PIX::KEY::TITLE], title},
{PIX::KEYMAP[PIX::KEY::RATE], rate},
{PIX::KEYMAP[PIX::KEY::FAV], fav},
{PIX::KEYMAP[PIX::KEY::COLOR], color},
{PIX::KEYMAP[PIX::KEY::FORMAT], format},
{PIX::KEYMAP[PIX::KEY::PIC_DATE], picDate},
{PIX::KEYMAP[PIX::KEY::PLACE], place},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}};
return insert(PIX::TABLEMAP[PIX::TABLE::IMAGES], imgMap);
auto url = img[PIX::KEY::URL];
auto title = img[PIX::KEY::TITLE];
auto rate = img[PIX::KEY::RATE];
auto fav = img[PIX::KEY::FAV];
auto color = img[PIX::KEY::COLOR];
auto addDate = img[PIX::KEY::ADD_DATE];
auto sourceUrl = img[PIX::KEY::SOURCES_URL];
auto picDate = img[PIX::KEY::PIC_DATE];
auto place = img[PIX::KEY::PLACE];
auto format = img[PIX::KEY::FORMAT];
qDebug()<< "writting to db: "<<title<<url;
/* first needs to insert album and artist*/
QVariantMap sourceMap {{PIX::KEYMAP[PIX::KEY::URL],sourceUrl}};
insert(PIX::TABLEMAP[PIX::TABLE::SOURCES], sourceMap);
QVariantMap imgMap {{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::SOURCES_URL], sourceUrl},
{PIX::KEYMAP[PIX::KEY::TITLE], title},
{PIX::KEYMAP[PIX::KEY::RATE], rate},
{PIX::KEYMAP[PIX::KEY::FAV], fav},
{PIX::KEYMAP[PIX::KEY::COLOR], color},
{PIX::KEYMAP[PIX::KEY::FORMAT], format},
{PIX::KEYMAP[PIX::KEY::PIC_DATE], picDate},
{PIX::KEYMAP[PIX::KEY::PLACE], place},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}};
return insert(PIX::TABLEMAP[PIX::TABLE::IMAGES], imgMap);
}
......@@ -246,6 +246,15 @@ bool DBActions::picAlbum(const QString &album, const QString &url)
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_ALBUMS], albumPic);
}
QVariantList DBActions::searchFor(const QStringList &queries, const QString &queryTxt)
{
QVariantList res;
for(auto query : queries)
res << get(PIX::getQuery("searchFor_").arg(query));
return res;
}
QVariantList DBActions::getFolders()
{
QVariantList res;
......
......@@ -53,7 +53,7 @@ class DBActions : public DB
Q_INVOKABLE bool picAlbum(const QString &album, const QString &url);
Q_INVOKABLE QVariantList searchFor(const QStringList &queries, const QString &queryTxt);
/* utils */
Q_INVOKABLE QVariantList getFolders();
Q_INVOKABLE QVariantList get(const QString &queryTxt);
......
......@@ -31,6 +31,7 @@ import "widgets/views/Gallery"
import "widgets/views/Settings"
import "widgets/views/Tags"
import "widgets/views/Viewer"
import "widgets/views/Search"
import "view_models"
import "widgets/dialogs/share"
......@@ -87,7 +88,7 @@ Kirigami.ApplicationWindow
property string pixColor : pix.pixColor()
property int iconSize : Kirigami.Units.iconSizes.medium
property int rowHeigh : 32
property int rowHeight : 32
overlay.modal: Rectangle {
color: isMobile ? darkColor : "transparent"
......@@ -111,12 +112,12 @@ Kirigami.ApplicationWindow
currentIndex: currentView
onViewerViewClicked: currentView = 0
onGalleryViewClicked: currentView = 1
onFoldersViewClicked: currentView = 2
onAlbumsViewClicked: currentView = 3
onTagsViewClicked: currentView = 4
onSearchViewClicked: {}
onViewerViewClicked: currentView = views.viewer
onGalleryViewClicked: currentView = views.gallery
onFoldersViewClicked: currentView = views.folders
onAlbumsViewClicked: currentView = views.albums
onTagsViewClicked: currentView = views.tags
onSearchViewClicked: currentView = views.search
onMenuClicked: globalDrawer.open()
}
......@@ -160,9 +161,9 @@ Kirigami.ApplicationWindow
id: tagsView
}
SettingsView
SearchView
{
id: searchView
}
}
......
......@@ -50,5 +50,6 @@
<file>widgets/views/Viewer/ConfigurationDialog.qml</file>
<file>view_models/PixDialog.qml</file>
<file>widgets/PicMenu.qml</file>
<file>widgets/views/Search/SearchView.qml</file>
</qresource>
</RCC>
This diff is collapsed.
import QtQuick 2.9
import QtQuick.Controls 2.2
import "../utils"
import org.kde.kirigami 2.2 as Kirigami
ToolButton
......
......@@ -6,7 +6,7 @@ import org.kde.kirigami 2.2 as Kirigami
ItemDelegate
{
width: parent.width
height: rowHeigh
height: rowHeight
property bool isSection : false
property bool boldLabel : false
......
import QtQuick 2.0
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
......
......@@ -18,6 +18,7 @@ ToolBar
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumWidth: 44
PixButton
{
......@@ -112,6 +113,7 @@ ToolBar
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumWidth: 44
PixButton
{
......@@ -126,8 +128,6 @@ ToolBar
ToolTip.text: qsTr("Fullscreen")
onClicked: fullScreen = !fullScreen
}
}
......
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import org.kde.kirigami 2.2 as Kirigami
ItemDelegate
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../../db/Query.js" as Q
Page
{
contentData: PixGrid
{
id: searchResults
height: parent.height
width: parent.width
headerbarExitIcon: "edit-clear"
headerbarTitle: searchResults.grid.count + qsTr(" results")
holder.message: "<h2>No results!</h2><p>Try with another query</p>"
holder.emoji: "qrc:/img/assets/face-sleeping.png"
}
footer: ToolBar
{
position: ToolBar.Footer
RowLayout
{
anchors.fill: parent
PixButton
{
iconName: "view-filter"
Layout.alignment: Qt.AlignLeft
}
TextField
{
id: searchInput
placeholderText: qsTr("Search...")
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
selectByMouse: !isMobile
focus: true
wrapMode: TextEdit.Wrap
selectionColor: highlightColor
selectedTextColor: highlightedTextColor
onAccepted: runSearch(searchInput.text)
}
PixButton
{
iconName: "edit-clear"
Layout.alignment: Qt.AlignRight
onClicked: searchInput.clear()
}
}
}
function runSearch(query)
{
searchResults.clear()
if(query)
{
console.log(query)
searchResults.headerbarTitle = query
var queries = query.split(",")
for(var i in queries)
populate(pix.get(Q.Query.searchFor_.arg(queries[i])))
}
}
function populate(data)
{
if(data.length > 0)
for(var i in data)
searchResults.grid.model.append(data[i])
}
}
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