X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=browsemainwindow.cpp;h=599b632571ac1199519b0db3d7a6cf09b5973b6b;hb=6d3f86ab9916dd1c2dec669dafb3ee86e72d2a8a;hp=7bb6cbb7ec0c43cfa23445f4eab7f672b34e363d;hpb=60b3d4ea6aba9d95da33830baed530cfe29418cd;p=vlc-remote 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; } } }