Commit 5b89f375 authored by Kevin Whitaker's avatar Kevin Whitaker

Implement basics of search using sql like. Now with so much data passing,...

Implement basics of search using sql like. Now with so much data passing, curtail some object deletions.
parent 8c8a6c30
......@@ -69,6 +69,8 @@ public:
std::list<PlayerEvent> lastInternalEvents;
Wt::Dbo::backend::Sqlite3* sqliteConnection;
Wt::Dbo::FixedSqlConnectionPool* connectionPool;
void getPictureFromTrack(AudioTrack* trackToFill);
private:
GroovePlayerMgr (std::string dbFile);
~GroovePlayerMgr();
......@@ -83,7 +85,6 @@ private:
void removeOrphanedTracks(Wt::Dbo::Session* session);
AudioTrack getCurrentTrackDB(Wt::Dbo::Session* session);
void getPictureFromTrack(AudioTrack* trackToFill);
};
......
......@@ -18,6 +18,11 @@
*/
#include "RequestInterface.h"
#include <Wt/Dbo/Session>
#include <Wt/Dbo/Transaction>
#include "../db/UserAction.h"
#include <Wt/Dbo/ptr>
#include <Wt/Dbo/collection>
RequestInterface::RequestInterface(WebInterface* app)
{
......@@ -40,9 +45,10 @@ RequestInterface::RequestInterface(WebInterface* app)
searchBtn->setText("&#61442;");
searchLayout->addWidget(searchBox);
searchLayout->addWidget(searchBtn);
//TODO:btn connections
searchBtn->clicked().connect(this, &RequestInterface::searchClicked);
resultBody->setLayout(resultLayout);
resultBody->setOverflow(Wt::WContainerWidget::OverflowAuto);
}
......@@ -50,3 +56,56 @@ void RequestInterface::trackRequestClicked(AudioTrack track)
{
//TODO
}
void RequestInterface::searchClicked()
{
if(!searchBox->text().empty())
{
Wt::Dbo::Session sqlSession;
sqlSession.setConnectionPool(*GroovePlayerMgr::getInstance()->connectionPool);
sqlSession.mapClass<User>("user");
sqlSession.mapClass<AudioTrack>("tracks");
sqlSession.mapClass<UserAction>("actions");
Wt::Dbo::Transaction searchTransaction(sqlSession);
//Do quick check for invalid seaches
if(searchBox->text().toUTF8().find("\"") != std::string::npos)
{
//Bad character, reject search.
searchBox->setText("");
searchTransaction.commit();
return;
}
//Do a like search on title, artist, and album on DB
Wt::Dbo::collection<Wt::Dbo::ptr<AudioTrack>> trackOptions = sqlSession.find<AudioTrack>(std::string("where tracks.name like \"%")+searchBox->text().toUTF8()+std::string("%\" OR tracks.artist like \"%")+searchBox->text().toUTF8()+std::string("%\" OR tracks.album like \"%")+searchBox->text().toUTF8()+std::string("%\""));
//Make sure all items are gone
for(RequestItem* item: foundItems)
{
delete item;
}
foundItems.clear();
resultLayout->clear();
//Put results into grid
if(trackOptions.size() > 0 && trackOptions.size() < 50) {
bool left = true;
int rowCount = 0;
for(Wt::Dbo::collection<Wt::Dbo::ptr<AudioTrack>>::const_iterator dbTrack = trackOptions.begin(); dbTrack != trackOptions.end(); ++dbTrack)
{
AudioTrack trackItem = (*(*dbTrack));
GroovePlayerMgr::getInstance()->getPictureFromTrack(&trackItem);
RequestItem* item = new RequestItem(this,trackItem);
foundItems.push_back(item);
resultLayout->addWidget(item,rowCount,left?0:1);
if(!left) rowCount += 1;
left = !left;
}
}
else
{
searchBox->setText("Not enough/too many results");
}
searchTransaction.commit();
}
}
......@@ -48,6 +48,7 @@ public:
RequestItem(RequestInterface* parent, AudioTrack track) {
this->track = new TrackDetails();
this->track->updateWithTrackDetails(track);
this->track->changeBackgroundColor(Wt::WColor("gainsboro"));
layout = new Wt::WHBoxLayout();
voteBtn = new Wt::WPushButton();
this->parent = parent;
......@@ -60,6 +61,9 @@ public:
layout->addWidget(voteBtn,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
voteBtn->clicked().connect(this, &RequestItem::requestClicked);
};
~RequestItem(){
this->clear();
}
};
Wt::WVBoxLayout* mainLayout;
......@@ -69,8 +73,10 @@ public:
Wt::WPushButton* searchBtn;
Wt::WContainerWidget* resultBody;
Wt::WGridLayout* resultLayout;
std::list<RequestItem*> foundItems;
void trackRequestClicked(AudioTrack track);
void searchClicked();
};
#endif // REQUESTINTERFACE_H
......@@ -53,6 +53,12 @@ TrackDetails::TrackDetails()
metaLayout->addWidget(trackArtist,1,Wt::AlignmentFlag::AlignBottom);
}
TrackDetails::~TrackDetails()
{
mainLayout->clear();
delete coverData;
}
void TrackDetails::updateWithTrackDetails(AudioTrack track)
{
this->animateHide(Wt::WAnimation(Wt::WAnimation::Fade));
......
......@@ -32,6 +32,7 @@ class TrackDetails : public Wt::WContainerWidget
{
public:
TrackDetails();
~TrackDetails();
Wt::WHBoxLayout* mainLayout;
Wt::WVBoxLayout* metaLayout;
......
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