From 1e0d0f92d5d6e921aba644d49ce027f8e88ab5ab Mon Sep 17 00:00:00 2001 From: druid23 Date: Sat, 21 Aug 2010 17:44:28 +0100 Subject: [PATCH] Added error handling for unbrowsable directories modified: browsemainwindow.cpp modified: browsemainwindow.h --- browsemainwindow.cpp | 26 ++++++++++++++++++++------ browsemainwindow.h | 1 + 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index d429502..d4c034f 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -18,6 +18,9 @@ #include "browsemainwindow.h" #include "ui_browsemainwindow.h" #include +#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) +#include +#endif #include "configdialog.h" #include "aboutdialog.h" #include "vlcbrowseelement.h" @@ -170,16 +173,18 @@ void BrowseMainWindow::onPlay() { } void BrowseMainWindow::browseDirectory(QString dir) { - mContents->clear(); - ui->listWidget->clear(); mResponse.clear(); QUrl url = QUrl("http://"+mIp+"/requests/browse.xml"); url.addEncodedQueryItem(QByteArray("dir"), QUrl::toPercentEncoding(dir)); QNetworkReply * reply = mNetManager->get(QNetworkRequest(url)); //QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir.replace("&", "%26").replace("\\", "\\\\")))); 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 BrowseMainWindow::error(QNetworkReply::NetworkError code) { + qDebug() << code; +} void BrowseMainWindow::readReady() { QNetworkReply * reply = qobject_cast(sender()); // append to buffer @@ -198,9 +203,10 @@ void BrowseMainWindow::parseXmlDirectory() { QDomNodeList elements = docElem.elementsByTagName("element"); // 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()) { + QList* files = new QList(); int idx = 0; + mContents->clear(); do { QDomNode node = elements.at(idx); VlcBrowseElement* dir = new VlcBrowseElement(); @@ -225,12 +231,19 @@ void BrowseMainWindow::parseXmlDirectory() { if (0 < files->count()) { mContents->append(*files); } + delete files; + // Update UI + this->updateList(); + } + else { + // alert user of error / empty directory + qDebug() << "can't browse dir: " << mCurrentDir; +#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) + QMaemo5InformationBox::information(this, tr("Directory could not be browsed!"), QMaemo5InformationBox::DefaultTimeout); +#endif } - delete files; mResponse.clear(); - // Update UI - this->updateList(); } QString BrowseMainWindow::getExtension(QString path, QString extension) { @@ -258,6 +271,7 @@ void BrowseMainWindow::writeFile(QString path, QByteArray text) { } void BrowseMainWindow::updateList() { + ui->listWidget->clear(); int ct = this->mContents->count(); if (0 < ct) { QIcon icon_up = QIcon::fromTheme("filemanager_folder_up"); diff --git a/browsemainwindow.h b/browsemainwindow.h index dc802da..86cd057 100644 --- a/browsemainwindow.h +++ b/browsemainwindow.h @@ -43,6 +43,7 @@ public slots: void onListSelectionChanged(); void finished(QNetworkReply * reply); void readReady(); + void error(QNetworkReply::NetworkError code); void showCurrentDirectory(); void setHomeFolder(); void showHomeFolder(); -- 1.7.9.5