Further Playlist interface improvements for usability.
authordruid23 <usr@dru-id.co.uk>
Sat, 21 Aug 2010 22:50:07 +0000 (23:50 +0100)
committerdruid23 <usr@dru-id.co.uk>
Sat, 21 Aug 2010 22:50:07 +0000 (23:50 +0100)
modified:   browsemainwindow.cpp
modified:   browsemainwindow.h
modified:   playermainwindow.cpp
modified:   playlistmainwindow.cpp
modified:   playlistmainwindow.h

browsemainwindow.cpp
browsemainwindow.h
playermainwindow.cpp
playlistmainwindow.cpp
playlistmainwindow.h

index 51437de..e960cab 100644 (file)
@@ -270,15 +270,6 @@ QString BrowseMainWindow::getExtension(QString path, QString extension) {
     }
 }
 
-void BrowseMainWindow::writeFile(QString path, QByteArray text) {
-    QFile file(path);
-    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
-        return;
-
-    QTextStream out(&file);
-    out << text;
-}
-
 void BrowseMainWindow::updateList() {
     ui->listWidget->clear();
     int ct = this->mContents->count();
index 86cd057..002eba8 100644 (file)
@@ -58,7 +58,6 @@ protected slots:
 protected:
     void changeEvent(QEvent *e);
     VlcBrowseElement getElementFromText(QString text);
-    void writeFile(QString path, QByteArray text);
     QString getExtension(QString path, QString extension);
 
 private:
index a7c284e..9ee1480 100644 (file)
 
   void PlayerMainWindow::askStatus()
   {
-
+      qDebug() << "Status requested. at:" << QTime::currentTime().toString("hh::mm:ss");
       QNetworkReply * reply =  mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
       connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
   }
index ca4ce3b..fd2569a 100644 (file)
@@ -25,7 +25,7 @@
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "appsettings.h"
-#include "vlcstatus.h"
+//#include "vlcstatus.h"
 
 PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
         QMainWindow(parent),
@@ -101,10 +101,19 @@ void PlayListMainWindow::changeEvent(QEvent *e)
 void PlayListMainWindow::onListSelectionChanged() {
     QList<QListWidgetItem *> items = ui->listWidget->selectedItems();
     if (0 < items.count()) {
-        mCurrentElement = getElementFromText(items.at(0)->text());
+        // TODO VLC doesn't seem to support removing nodes!
+        // Playing nodes works fine, however.
+        // should check to see if it is a leaf or not and disable the remove button
         mCurrentVlcIndex = items.at(0)->type() - LIST_ITEM_TYPE_OFFSET; // Qt reserves types up to 1000, we use an offset beyond that for index tracking. May prove to be too hacky!
-        ui->removeButton->setDisabled(false);
-        ui->playButton->setDisabled(false);
+        mCurrentElement = getElementFromId(mCurrentVlcIndex);
+        if (0 == QString::compare("node", mCurrentElement.type)) {
+            ui->removeButton->setDisabled(true);
+            ui->playButton->setDisabled(false);
+        }
+        else {
+            ui->removeButton->setDisabled(false);
+            ui->playButton->setDisabled(false);
+        }
     }
     else {
         mCurrentVlcIndex = 0;
@@ -115,34 +124,38 @@ void PlayListMainWindow::onListSelectionChanged() {
 
 void PlayListMainWindow::onRemove() {
     if (0 < this->mCurrentVlcIndex) {
-        /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex))));
-        connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
+        mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex))));
+        //connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
+        // don't refresh just clear the item!
+        delete ui->listWidget->takeItem(ui->listWidget->currentRow());
     }
 }
 void PlayListMainWindow::onPlay() {
     if (0 < this->mCurrentVlcIndex) {
-        /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play&id=" + QString::number(this->mCurrentVlcIndex))));
+        mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play&id=" + QString::number(this->mCurrentVlcIndex))));
     }
 }
 void PlayListMainWindow::onRepeat() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_repeat")));
+    mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_repeat")));
 }
 void PlayListMainWindow::onLoop() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_loop")));
+    mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_loop")));
 }
 void PlayListMainWindow::onShuffle() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_random")));
+    mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_random")));
 }
 void PlayListMainWindow::onClear() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty")));
-    connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
+    mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty")));
+    mContents->clear();
+    ui->listWidget->clear();
+    //connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
 }
 void PlayListMainWindow::requestPlayList() {
   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);
+  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()));
@@ -152,11 +165,11 @@ void PlayListMainWindow::requestPlayList() {
 }
 void PlayListMainWindow::error(QNetworkReply::NetworkError code) {
 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
-    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+  this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
-    qDebug() << code;
+  qDebug() << code;
 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
-    QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout);
+  QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout);
 #endif
 }
 void PlayListMainWindow::readReady() {
@@ -170,7 +183,7 @@ void PlayListMainWindow::finished(QNetworkReply * reply) {
   // 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);
+  this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
 }
 
@@ -202,60 +215,6 @@ void PlayListMainWindow::parseXmlPlayList() {
           for (int jdx = 0; jdx < leafct; ++jdx) {
             QDomNode leaf = leafs.at(jdx);
             parsePlayListItem(&leaf, &extension, &hasArt, &currentLeafId, 1);
-            /*
-            VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
-            el->id = leaf.attributes().namedItem("id").nodeValue().toInt();
-            el->path = leaf.attributes().namedItem("uri").nodeValue();
-            el->name = leaf.attributes().namedItem("name").nodeValue().replace("\\\\", "\\");
-            current = leaf.attributes().namedItem("current").nodeValue();
-            el->playing = (0 < current.length());
-            el->depth = depth;
-            if (0 == QString::compare(leaf.nodeName(), "node")) {
-              el->type = "node";
-              el->extension = getExtension(el->path, NULL);
-              this->mContents->append(*el);
-              // now parse the child nodes as leafs.
-              if (leaf.hasChildNodes()) {
-                QDomNodeList items = leaf.childNodes();
-                int itemct = items.count();
-                if (0 < itemct) {
-                  depth = 2;
-                  for (int kdx = 0; kdx < itemct; ++kdx) {
-                    QDomNode item = items.at(kdx);
-                    VlcPlayListElementSimple* it = new VlcPlayListElementSimple();
-                    it->id = item.attributes().namedItem("id").nodeValue().toInt();
-                    it->path = item.attributes().namedItem("uri").nodeValue();
-                    it->name = item.attributes().namedItem("name").nodeValue().replace("\\\\", "\\");
-                    it->extension = getExtension(it->path, NULL);
-                    it->depth = 2;
-                    it->type = "leaf";
-                    current = item.attributes().namedItem("current").nodeValue();
-                    it->playing = (0 < current.length());
-                    if (it->playing) {
-                        currentLeafId = it->id;
-                        QString art = item.toElement().namedItem("art_url").toElement().text();
-                        hasArt = (!art.isNull() && !art.isEmpty());
-                        extension = getExtension(it->path, NULL);
-                    }
-                    this->mContents->append(*it);
-                    delete it;
-                  }
-                }
-              }
-            }
-            else {
-              el->type = "leaf";
-              el->extension = getExtension(el->path, NULL);
-              if (el->playing) {
-                  currentLeafId = el->id;
-                  QString art = leaf.toElement().namedItem("art_url").toElement().text();
-                  hasArt = (!art.isNull() && !art.isEmpty());
-                  extension = getExtension(el->path, NULL);
-              }
-              this->mContents->append(*el);
-            }
-            delete el;
-            */
           }
         }
       }
@@ -272,7 +231,8 @@ void PlayListMainWindow::parseXmlPlayList() {
 }
 
 
-void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth) {
+int PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth) {
+    int leafCt = 0;
     if (NULL != node) {
         QString current;
         VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
@@ -292,6 +252,7 @@ void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, b
                 *extension = getExtension(el->path, NULL);
             }
             this->mContents->append(*el);
+            ++leafCt;
             delete el;
         }
         else {
@@ -300,22 +261,33 @@ void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, b
             // empty nodes appear in the playlist when they can't be played!
             if (node->hasChildNodes()) {
                 this->mContents->append(*el);
+                ++leafCt;
             }
             delete el;
             // now parse the child nodes as leaf.
             if (node->hasChildNodes()) {
                 QDomNodeList items = node->childNodes();
                 int itemct = items.count();
+                int added = 0;
                 if (0 < itemct) {
                   ++depth;
                   for (int kdx = 0; kdx < itemct; ++kdx) {
                     QDomNode item = items.at(kdx);
-                    parsePlayListItem(&item, extension, hasArt, currentLeafId, depth);
+                    added += parsePlayListItem(&item, extension, hasArt, currentLeafId, depth);
+                  }
+                  if (1 > added) {
+                      // should remove the last PlayListElement
+                      this->mContents->removeLast();
+                      --leafCt;
+                  }
+                  else {
+                      leafCt += added;
                   }
                 }
             }
         }
     }
+    return leafCt;
 }
 
 QString PlayListMainWindow::getExtension(QString path, QString extension) {
@@ -333,10 +305,10 @@ QString PlayListMainWindow::getExtension(QString path, QString extension) {
     }
 }
 
-VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
+VlcPlayListElementSimple PlayListMainWindow::getElementFromId(int id) {
   //if (0 != QString::compare("", text)) {
     for (int idx = 0; idx < mContents->count(); ++idx) {
-      if (0 == QString::compare(text, mContents->at(idx).name)) {
+      if (0 < id && (id == mContents->at(idx).id)) {
         return mContents->at(idx);
       }
     }
index 6341fb6..a6a444f 100644 (file)
@@ -57,14 +57,14 @@ public slots:
 protected slots:
     void parseXmlPlayList();
     void updateList();
-    void parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth);
+    int parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth);
 
 signals:
     void idUpdated(int id, bool hasArt, QString extension);
 
 protected:
     void changeEvent(QEvent *e);
-    VlcPlayListElementSimple getElementFromText(QString text);
+    VlcPlayListElementSimple getElementFromId(int id);
     QString getExtension(QString path, QString extension);
 
 private: