From: druid23 Date: Mon, 16 Aug 2010 23:42:09 +0000 (+0100) Subject: Browser working correctly from a functional perspective. X-Git-Tag: v0.5~51 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=6d3f86ab9916dd1c2dec669dafb3ee86e72d2a8a;hp=60b3d4ea6aba9d95da33830baed530cfe29418cd;p=vlc-remote Browser working correctly from a functional perspective. modified: browsemainwindow.cpp modified: browsemainwindow.h --- diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index 7bb6cbb..599b632 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -39,6 +39,8 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) : mContents = new QList(); + //mResponse = new QByteArray(); + ui->playButton->setIcon(QIcon::fromTheme("camera_playback")); ui->addButton->setIcon(QIcon::fromTheme("general_add")); ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder")); @@ -99,13 +101,11 @@ void BrowseMainWindow::onListSelectionChanged() { } VlcBrowseElement BrowseMainWindow::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); - } + for (int idx = 0; idx < mContents->count(); ++idx) { + if (0 == QString::compare(text, mContents->at(idx).name)) { + return mContents->at(idx); } - //} + } return *(new VlcBrowseElement()); } @@ -129,20 +129,31 @@ void BrowseMainWindow::onPlay() { } void BrowseMainWindow::browseDirectory(QString dir) { + mContents->clear(); ui->listWidget->clear(); + mResponse.clear(); QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir))); - connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlDirectory())); + //reply->setReadBufferSize(1024 * 500); + connect(reply,SIGNAL(readyRead()),this,SLOT(readReady())); + connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); } -void BrowseMainWindow::parseXmlDirectory() { - qDebug() << "got called!"; +void BrowseMainWindow::readReady() { QNetworkReply * reply = qobject_cast(sender()); + // append to buffer + mResponse += reply->readAll(); +} +void BrowseMainWindow::finished(QNetworkReply * reply) { + // now we can call parseXmlDirectory to process the full buffers + this->parseXmlDirectory(); + // only interested in finished signals + disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); +} +void BrowseMainWindow::parseXmlDirectory() { QDomDocument doc; - doc.setContent(reply->readAll()); + doc.setContent(this->mResponse); QDomElement docElem = doc.documentElement(); QDomNodeList elements = docElem.elementsByTagName("element"); - mContents->clear(); - //mContents = new QList(); - // we can sort by filders then files alphabetically by running to lists and appending them at the end + // we can sort by folders then files alphabetically by running to lists and appending them at the end // vlc alpha sorts everything in the incoming stream, we just need to seperate files from folders. QList* files = new QList(); if (0 < elements.count()) { @@ -170,8 +181,7 @@ void BrowseMainWindow::parseXmlDirectory() { } } delete files; - //reply->deleteLater(); - delete reply; + mResponse.clear(); // Update UI this->updateList(); @@ -256,7 +266,6 @@ void BrowseMainWindow::updateList() { ui->listWidget->addItem(item); } // other types ignored - //if (item) delete item; } } } diff --git a/browsemainwindow.h b/browsemainwindow.h index 5f91467..d287019 100644 --- a/browsemainwindow.h +++ b/browsemainwindow.h @@ -40,6 +40,8 @@ public slots: void onPlay(); void onAddToPlaylist(); void onListSelectionChanged(); + void finished(QNetworkReply * reply); + void readReady(); protected slots: void parseXmlDirectory(); @@ -57,6 +59,7 @@ private: QString mIp; QList* mContents; VlcBrowseElement mCurrentElement; + QByteArray mResponse; }; #endif // BROWSEMAINWINDOW_H