1 #include "youtubesuggest.h"
3 #include "networkaccess.h"
5 #define GSUGGEST_URL "http://suggestqueries.google.com/complete/search?ds=yt&output=toolbar&hl=%1&q=%2"
11 YouTubeSuggest::YouTubeSuggest(QObject *parent) : Suggester() {
15 void YouTubeSuggest::suggest(QString query) {
16 QString locale = QLocale::system().name().replace("_", "-");
17 // case for system locales such as "C"
18 if (locale.length() < 2) {
22 QString url = QString(GSUGGEST_URL).arg(locale, query);
24 QObject *reply = The::http()->get(url);
25 connect(reply, SIGNAL(data(QByteArray)), SLOT(handleNetworkData(QByteArray)));
28 void YouTubeSuggest::handleNetworkData(QByteArray response) {
31 QXmlStreamReader xml(response);
32 while (!xml.atEnd()) {
34 if (xml.tokenType() == QXmlStreamReader::StartElement) {
35 if (xml.name() == "suggestion") {
36 QStringRef str = xml.attributes().value("data");
37 choices << str.toString();