More infastructure for scrapers (starting to hook into GuiMetaDataEd).

This commit is contained in:
Aloshi 2013-09-17 16:50:49 -05:00
parent fe991e1b86
commit 5dfaeeabb4
8 changed files with 70 additions and 8 deletions

View file

@ -35,7 +35,9 @@ void Settings::setDefaults()
mIntMap["DIMTIME"] = 30*1000;
mIntMap["GameListSortIndex"] = 0;
mIntMap["GameListSortIndex"] = 0;
mScraper = NULL; //TODO
}
template <typename K, typename V>
@ -85,6 +87,11 @@ void Settings::loadFile()
setFloat(node.attribute("name").as_string(), node.attribute("value").as_float());
}
IScraper* Settings::getScraper()
{
return mScraper;
}
//Print a warning message if the setting we're trying to get doesn't already exist in the map, then return the value in the map.
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) type Settings::getMethodName(const std::string& name) \
{ \

View file

@ -3,6 +3,7 @@
#include <string>
#include <map>
#include "scrapers/Scraper.h"
//This is a singleton for storing settings.
class Settings
@ -22,6 +23,7 @@ public:
void setInt(const std::string& name, int value);
void setFloat(const std::string& name, float value);
IScraper* getScraper();
private:
static Settings* sInstance;
@ -33,6 +35,7 @@ private:
std::map<std::string, bool> mBoolMap;
std::map<std::string, int> mIntMap;
std::map<std::string, float> mFloatMap;
IScraper* mScraper;
};
#endif

View file

@ -129,7 +129,10 @@ bool GuiGameList::input(InputConfig* config, Input input)
if(game)
{
FolderData* root = mSystem->getRootFolder();
mWindow->pushGui(new GuiMetaDataEd(mWindow, game->metadata(), MetaDataList::getDefaultGameMDD(), game->getBaseName(),
ScraperSearchParams searchParams;
searchParams.game = game;
searchParams.system = mSystem;
mWindow->pushGui(new GuiMetaDataEd(mWindow, game->metadata(), MetaDataList::getDefaultGameMDD(), searchParams, game->getBaseName(),
[&] { updateDetailData(); },
[game, root, this] { root->removeFileRecursive(game); updateList(); }
));

View file

@ -2,11 +2,13 @@
#include "../Renderer.h"
#include "../Log.h"
#include "AsyncReqComponent.h"
#include "../Settings.h"
#define MDED_RESERVED_ROWS 3
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd,
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
mScraperParams(scraperParams),
mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF),
mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)),
mHeader(window),
@ -109,6 +111,12 @@ void GuiMetaDataEd::save()
}
void GuiMetaDataEd::fetch()
{
Settings::getInstance()->getScraper()->getResultsAsync(mScraperParams, mWindow, std::bind(&GuiMetaDataEd::fetchDone, this, std::placeholders::_1));
}
void GuiMetaDataEd::fetchDone(std::vector<MetaDataList> results)
{
}

View file

@ -8,20 +8,24 @@
#include "NinePatchComponent.h"
#include "ButtonComponent.h"
#include <functional>
#include "../scrapers/Scraper.h"
class GuiMetaDataEd : public GuiComponent
{
public:
GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd,
GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams params,
const std::string& header, std::function<void()> savedCallback, std::function<void()> deleteFunc);
virtual ~GuiMetaDataEd();
private:
void save();
void fetch();
void fetchDone(std::vector<MetaDataList> results);
void populateList(const std::vector<MetaDataDecl>& mdd);
ScraperSearchParams mScraperParams;
NinePatchComponent mBox;
ComponentListComponent mList;

View file

@ -1,9 +1,37 @@
#include "GamesDBScraper.h"
#include "../components/AsyncReqComponent.h"
std::vector<MetaDataList> GamesDBScraper::getResults(ScraperSearchParams params)
{
std::vector<MetaDataList> results;
std::shared_ptr<HttpReq> req = makeHttpReq();
while(req->status() == HttpReq::REQ_IN_PROGRESS);
return results;
return parseReq(params, req);
}
std::shared_ptr<HttpReq> GamesDBScraper::makeHttpReq()
{
return std::make_shared<HttpReq>("cdn.garcya.us", "/wp-content/uploads/2010/04/TD250.jpg");
}
std::vector<MetaDataList> GamesDBScraper::parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq> req)
{
std::vector<MetaDataList> mdl;
return mdl;
}
void GamesDBScraper::getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc)
{
std::shared_ptr<HttpReq> httpreq = makeHttpReq();
AsyncReqComponent* req = new AsyncReqComponent(window, httpreq,
[this, params, returnFunc] (std::shared_ptr<HttpReq> r)
{
returnFunc(parseReq(params, r));
}, [] ()
{
});
window->pushGui(req);
}

View file

@ -1,10 +1,16 @@
#pragma once
#include "Scraper.h"
#include "../HttpReq.h"
class GamesDBScraper : public IScraper
{
public:
std::vector<MetaDataList> getResults(ScraperSearchParams params) override;
void getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc) override;
private:
std::shared_ptr<HttpReq> makeHttpReq();
std::vector<MetaDataList> parseReq(ScraperSearchParams params, std::shared_ptr<HttpReq>);
};

View file

@ -4,14 +4,16 @@
#include "../SystemData.h"
#include "../GameData.h"
#include <vector>
#include <functional>
class Window;
struct ScraperSearchParams
{
SystemData* sys;
SystemData* system;
GameData* game;
std::string nameOverride;
bool async;
};
class IScraper
@ -19,5 +21,6 @@ class IScraper
public:
//Get a list of potential results.
virtual std::vector<MetaDataList> getResults(ScraperSearchParams params) = 0;
virtual void getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc) = 0;
};