From 0c50f27d33a67f958b61a2502ba4c393ec3456d9 Mon Sep 17 00:00:00 2001 From: Flavio Date: Wed, 9 Jan 2013 17:49:44 +0100 Subject: [PATCH] fallback to english categories --- src/ytcategories.cpp | 17 ++++++++--------- src/ytcategories.h | 5 ++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ytcategories.cpp b/src/ytcategories.cpp index 569fcd3..2e5bab4 100644 --- a/src/ytcategories.cpp +++ b/src/ytcategories.cpp @@ -8,14 +8,12 @@ NetworkAccess* http(); YTCategories::YTCategories(QObject *parent) : QObject(parent) { } -void YTCategories::loadCategories() { - QString url = "http://gdata.youtube.com/schemas/2007/categories.cat?hl="; -#if QT_VERSION >= 0x040800 - url += QLocale::system().uiLanguages().first(); -#else - url += QLocale::system().name().replace('_', '-'); -#endif - qDebug() << url; +void YTCategories::loadCategories(QString language) { + if (language.isEmpty()) + language = QLocale::system().uiLanguages().first(); + lastLanguage = language; + + QString url = "http://gdata.youtube.com/schemas/2007/categories.cat?hl=" + language; QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(parseCategories(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*))); @@ -49,5 +47,6 @@ void YTCategories::parseCategories(QByteArray bytes) { } void YTCategories::requestError(QNetworkReply *reply) { - emit error(reply->errorString()); + if (lastLanguage != "en") loadCategories("en"); + else emit error(reply->errorString()); } diff --git a/src/ytcategories.h b/src/ytcategories.h index 1dec6d4..7513f2d 100644 --- a/src/ytcategories.h +++ b/src/ytcategories.h @@ -14,7 +14,7 @@ class YTCategories : public QObject { public: YTCategories(QObject *parent = 0); - void loadCategories(); + void loadCategories(QString language = QString()); signals: void categoriesLoaded(const QList &); @@ -24,6 +24,9 @@ private slots: void parseCategories(QByteArray bytes); void requestError(QNetworkReply *reply); +private: + QString lastLanguage; + }; #endif // YTCATEGORIES_H -- 2.39.5