Playlist tweak - minimizing impact of refresh on the UI.
[vlc-remote] / playlistmainwindow.cpp
index 4d8f541..ca4ce3b 100644 (file)
@@ -19,6 +19,9 @@
 #include "ui_playlistmainwindow.h"
 #include <QPushButton>
 #include <QSettings>
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+#include <QMaemo5InformationBox>
+#endif
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "appsettings.h"
@@ -135,16 +138,27 @@ void PlayListMainWindow::onClear() {
     connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
 }
 void PlayListMainWindow::requestPlayList() {
-  mContents->clear();
-  ui->listWidget->clear();
   mResponse.clear();
   ui->removeButton->setDisabled(true);
   ui->playButton->setDisabled(true);
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
   QNetworkReply * reply =  mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml")));
   disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
   connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
+  connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError)));
   connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
 }
+void PlayListMainWindow::error(QNetworkReply::NetworkError code) {
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
+    qDebug() << code;
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout);
+#endif
+}
 void PlayListMainWindow::readReady() {
   QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
   // append to buffer
@@ -155,9 +169,13 @@ void PlayListMainWindow::finished(QNetworkReply * reply) {
   this->parseXmlPlayList();
   // only interested in finished signals
   disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
 }
 
 void PlayListMainWindow::parseXmlPlayList() {
+  mContents->clear();
   QDomDocument doc;
   doc.setContent(this->mResponse);
   QDomElement docElem = doc.documentElement();
@@ -279,7 +297,10 @@ void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, b
         else {
             el->type = "node";
             el->extension = getExtension(el->path, NULL);
-            this->mContents->append(*el);
+            // empty nodes appear in the playlist when they can't be played!
+            if (node->hasChildNodes()) {
+                this->mContents->append(*el);
+            }
             delete el;
             // now parse the child nodes as leaf.
             if (node->hasChildNodes()) {
@@ -324,6 +345,7 @@ VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
 }
 
 void PlayListMainWindow::updateList() {
+  ui->listWidget->clear();
   int ct = this->mContents->count();
   if (0 < ct) {
     QIcon icon_audio  = QIcon::fromTheme("general_audio_file");
@@ -374,9 +396,9 @@ void PlayListMainWindow::updateList() {
           else if ( 0 == QString::compare(el.extension, "flv")  ) {
               item = new QListWidgetItem(icon_flash, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .flv
           }
-          else if ( 0 == QString::compare(el.extension, "")  ) {
-              item = new QListWidgetItem(icon_unknown, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .flv
-          }
+          //else if ( 0 == QString::compare(el.extension, "")  ) {
+          //    item = new QListWidgetItem(icon_unknown, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .flv
+          //}
           else {
               if (el.name.contains("Flash")) {
                   item = new QListWidgetItem(icon_flash, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);