+void PlayListMainWindow::onListSelectionChanged() {
+ QList<QListWidgetItem *> items = ui->listWidget->selectedItems();
+ if (0 < items.count()) {
+ mCurrentElement = getElementFromText(items.at(0)->text());
+ 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);
+ }
+ else {
+ mCurrentVlcIndex = 0;
+ ui->removeButton->setDisabled(true);
+ ui->playButton->setDisabled(true);
+ }
+}
+
+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))));
+ this->requestPlayList();
+ }
+}
+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))));
+ }
+}
+void PlayListMainWindow::onRepeat() {
+ /*QNetworkReply * reply = */ 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")));
+}
+void PlayListMainWindow::onShuffle() {
+ /*QNetworkReply * reply = */ 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")));
+ this->requestPlayList();
+}
+void PlayListMainWindow::requestPlayList() {
+ ui->listWidget->clear();
+ ui->removeButton->setDisabled(true);
+ ui->playButton->setDisabled(true);
+ QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml")));
+ connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlPlayList()));
+}
+
+void PlayListMainWindow::parseXmlPlayList() {
+ QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
+ QDomDocument doc;
+ doc.setContent(reply->readAll());
+ QDomElement docElem = doc.documentElement();
+ QDomNodeList nodes = docElem.elementsByTagName("node");
+ mContents = new QList<VlcPlayListElementSimple>();
+
+ int depth = 0;
+
+ int ct = nodes.count();
+ qDebug() << "elements " << ct;
+ for (int idx = 0; idx < ct; ++idx) {
+ QDomNode node = nodes.at(idx);
+ QString name = node.attributes().namedItem("name").nodeValue();
+ if (0 == QString::compare("Playlist", name)) {
+ // got the main playlist, let's build it up
+ if (node.hasChildNodes()) {
+ QDomNodeList leafs = node.childNodes();
+ int leafct = leafs.count();
+ if (0 < leafct) {
+ for (int jdx = 0; jdx < leafct; ++jdx) {
+ QDomNode leaf = leafs.at(jdx);
+ VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
+ el->depth = 1;
+ el->id = leaf.attributes().namedItem("id").nodeValue().toInt();
+ el->type = "leaf";
+ el->path = leaf.attributes().namedItem("uri").nodeValue();
+ el->name = leaf.attributes().namedItem("name").nodeValue();
+ this->mContents->append(*el);
+ }
+ }
+ }
+
+ }
+ }
+
+
+
+ delete reply;
+
+ this->updateList();
+
+}
+
+VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
+ //if (0 != QString::compare("", text)) {
+ for (int idx = 0; idx < mContents->count(); ++idx) {
+ if (0 == QString::compare(text, mContents->at(idx).name)) {
+ return mContents->at(idx);
+ }
+ }
+ //}
+ return *(new VlcPlayListElementSimple());
+}
+
+void PlayListMainWindow::updateList() {
+ int ct = this->mContents->count();
+ if (0 < ct) {
+ for (int idx = 0; idx < ct; ++idx) {
+ VlcPlayListElementSimple el = mContents->at(idx);
+ QListWidgetItem* item;
+ item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);
+ ui->listWidget->addItem(item);
+ /// TODO - Work out the file / media type and use an appropriate icon instead of the default.
+ }
+ }
+}
+