From: Flavio Date: Wed, 9 Jan 2013 16:49:44 +0000 (+0100) Subject: fallback to english categories X-Git-Tag: 2.0~37 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0c50f27d33a67f958b61a2502ba4c393ec3456d9;p=minitube fallback to english categories --- 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