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["DIMTIME"] = 30*1000;
mIntMap["GameListSortIndex"] = 0; mIntMap["GameListSortIndex"] = 0;
mScraper = NULL; //TODO
} }
template <typename K, typename V> template <typename K, typename V>
@ -85,6 +87,11 @@ void Settings::loadFile()
setFloat(node.attribute("name").as_string(), node.attribute("value").as_float()); 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. //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) \ #define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) type Settings::getMethodName(const std::string& name) \
{ \ { \

View file

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

View file

@ -129,7 +129,10 @@ bool GuiGameList::input(InputConfig* config, Input input)
if(game) if(game)
{ {
FolderData* root = mSystem->getRootFolder(); 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(); }, [&] { updateDetailData(); },
[game, root, this] { root->removeFileRecursive(game); updateList(); } [game, root, this] { root->removeFileRecursive(game); updateList(); }
)); ));

View file

@ -2,11 +2,13 @@
#include "../Renderer.h" #include "../Renderer.h"
#include "../Log.h" #include "../Log.h"
#include "AsyncReqComponent.h" #include "AsyncReqComponent.h"
#include "../Settings.h"
#define MDED_RESERVED_ROWS 3 #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), const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
mScraperParams(scraperParams),
mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF), mBox(mWindow, ":/frame.png", 0xAAAAAAFF, 0xCCCCCCFF),
mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)), mList(window, Eigen::Vector2i(3, mdd.size() + MDED_RESERVED_ROWS)),
mHeader(window), mHeader(window),
@ -109,6 +111,12 @@ void GuiMetaDataEd::save()
} }
void GuiMetaDataEd::fetch() 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 "NinePatchComponent.h"
#include "ButtonComponent.h" #include "ButtonComponent.h"
#include <functional> #include <functional>
#include "../scrapers/Scraper.h"
class GuiMetaDataEd : public GuiComponent class GuiMetaDataEd : public GuiComponent
{ {
public: 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); const std::string& header, std::function<void()> savedCallback, std::function<void()> deleteFunc);
virtual ~GuiMetaDataEd(); virtual ~GuiMetaDataEd();
private: private:
void save(); void save();
void fetch(); void fetch();
void fetchDone(std::vector<MetaDataList> results);
void populateList(const std::vector<MetaDataDecl>& mdd); void populateList(const std::vector<MetaDataDecl>& mdd);
ScraperSearchParams mScraperParams;
NinePatchComponent mBox; NinePatchComponent mBox;
ComponentListComponent mList; ComponentListComponent mList;

View file

@ -1,9 +1,37 @@
#include "GamesDBScraper.h" #include "GamesDBScraper.h"
#include "../components/AsyncReqComponent.h"
std::vector<MetaDataList> GamesDBScraper::getResults(ScraperSearchParams params) 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 #pragma once
#include "Scraper.h" #include "Scraper.h"
#include "../HttpReq.h"
class GamesDBScraper : public IScraper class GamesDBScraper : public IScraper
{ {
public: public:
std::vector<MetaDataList> getResults(ScraperSearchParams params) override; 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 "../SystemData.h"
#include "../GameData.h" #include "../GameData.h"
#include <vector> #include <vector>
#include <functional>
class Window;
struct ScraperSearchParams struct ScraperSearchParams
{ {
SystemData* sys; SystemData* system;
GameData* game; GameData* game;
std::string nameOverride; std::string nameOverride;
bool async;
}; };
class IScraper class IScraper
@ -19,5 +21,6 @@ class IScraper
public: public:
//Get a list of potential results. //Get a list of potential results.
virtual std::vector<MetaDataList> getResults(ScraperSearchParams params) = 0; virtual std::vector<MetaDataList> getResults(ScraperSearchParams params) = 0;
virtual void getResultsAsync(ScraperSearchParams params, Window* window, std::function<void(std::vector<MetaDataList>)> returnFunc) = 0;
}; };