]> git.sur5r.net Git - minitube/commitdiff
fallback to english categories
authorFlavio <flavio@odisseo.local>
Wed, 9 Jan 2013 16:49:44 +0000 (17:49 +0100)
committerFlavio <flavio@odisseo.local>
Wed, 9 Jan 2013 16:49:44 +0000 (17:49 +0100)
src/ytcategories.cpp
src/ytcategories.h

index 569fcd35f00642922ceaeaca5899c8e795b7976f..2e5bab4742c9fae839b823ad29ae2d3c6720dcfd 100644 (file)
@@ -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());
 }
index 1dec6d4bf4167e7129f51713f6aaf657c7ffe1ff..7513f2d312f69f521a0de97ddf5117ae9f132856 100644 (file)
@@ -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<YTCategory> &);
@@ -24,6 +24,9 @@ private slots:
     void parseCategories(QByteArray bytes);
     void requestError(QNetworkReply *reply);
 
+private:
+    QString lastLanguage;
+
 };
 
 #endif // YTCATEGORIES_H