#include <GoogleSearcher.h>
Public Slots | |
void | search (QString searchString=QString()) |
Signals | |
void | parsedResult (QHash< QString, QString >) |
void | doParsing (QString rawData) |
Public Member Functions | |
CGoogleSearcher (QObject *parent=0) | |
~CGoogleSearcher () | |
void | setSearchString (const QString &searchString) |
Private Slots | |
void | searchComplete () |
void | parse (QString rawData) |
Private Member Functions | |
bool | isImageData (const QString &imageData) |
QString | fetchDataFromRawChunk (const QString &key, const QString &rawData) |
Private Attributes | |
QWebView * | m_pGoogleAJAXapiMedia |
int | searchResultLabel |
QString | searchString |
CGoogleSearcher class emit signal for every single search result parsedResult. emited result contains thumbnail view URL and original image URL.
As google image search API is using AJAX. CGoogleSearcher class uses QWebView class object to query over google which fetches the result from it. This feature is available in Qt4.5.x onwards.
CGoogleSearcher::CGoogleSearcher | ( | QObject * | parent = 0 |
) |
References doParsing(), m_pGoogleAJAXapiMedia, parse(), searchComplete(), and searchResultLabel.
CGoogleSearcher::~CGoogleSearcher | ( | ) |
References m_pGoogleAJAXapiMedia.
void CGoogleSearcher::setSearchString | ( | const QString & | searchString | ) |
This function set the new query that will queried to google for images.
searchString | query string that need to be queried to google for images |
Referenced by CPictureWallMainWindow::startNewGoogleSearch().
void CGoogleSearcher::search | ( | QString | searchString = QString() |
) | [slot] |
If called from outside, it will start new search using the passes query string, if the passes parameter is empty then deafault query will be used to start the search
This slot iterate over 20 iteration once started and same query is queried to google image server for more results
searchString |
References m_pGoogleAJAXapiMedia, and searchResultLabel.
Referenced by searchComplete(), and CPictureWallMainWindow::startNewGoogleSearch().
void CGoogleSearcher::searchComplete | ( | ) | [private, slot] |
This slot is called internally when the query result is fetched from the google server.
References doParsing(), m_pGoogleAJAXapiMedia, and search().
Referenced by CGoogleSearcher().
void CGoogleSearcher::parse | ( | QString | rawData | ) | [private, slot] |
This slot is called when query result is fetched from the server and raw data need to be parsed. This slot only extracts thumbnail view URL and Original image URL from the raw data. Rest of the data is ignored.
rawData | result query data from google server |
References fetchDataFromRawChunk(), isImageData(), and parsedResult().
Referenced by CGoogleSearcher().
void CGoogleSearcher::parsedResult | ( | QHash< QString, QString > | ) | [signal] |
This signal is emiited for single record found in the searched query result. Record emited by this function is QHash which is key value pair based data. Emited data only contains thumbnail view URL and original image URL
For Example: To access original image URL key is "url" To access thumbnail view URL key is "tbUrl"
Referenced by parse().
void CGoogleSearcher::doParsing | ( | QString | rawData | ) | [signal] |
This signal is emited when google server has responded with query result.
rawData | google server return response for the query |
Referenced by CGoogleSearcher(), and searchComplete().
bool CGoogleSearcher::isImageData | ( | const QString & | imageData | ) | [private] |
imageData | Query result from google server |
Referenced by parse().
QString CGoogleSearcher::fetchDataFromRawChunk | ( | const QString & | key, | |
const QString & | rawData | |||
) | [private] |
This function parsed the required key within the raw data or query result from google server
key | Key that need to be searched withing raw data | |
rawData | Query response from google server where key needs to be searched |
Referenced by parse().
QWebView* CGoogleSearcher::m_pGoogleAJAXapiMedia [private] |
Referenced by CGoogleSearcher(), search(), searchComplete(), and ~CGoogleSearcher().
int CGoogleSearcher::searchResultLabel [private] |
Referenced by CGoogleSearcher(), and search().
QString CGoogleSearcher::searchString [private] |