Tweaked some directory handling code.
[vlc-remote] / browsemainwindow.cpp
index 27b84b2..2c7582f 100644 (file)
@@ -123,7 +123,7 @@ void BrowseMainWindow::onListSelectionChanged() {
         }
         else {
             // can we browse?
-            if (0 == QString::compare("directory", mCurrentElement.type)) {
+            if (0 == QString::compare("directory", mCurrentElement.type) || 0 == QString::compare("dir", mCurrentElement.type)) {
                 ui->browseButton->setDisabled(false);
             }
             else {
@@ -148,7 +148,7 @@ VlcBrowseElement BrowseMainWindow::getElementFromText(QString text) {
 
 void BrowseMainWindow::onBrowse() {
     // check for directory
-    if (0 == QString::compare("directory", mCurrentElement.type)) {
+    if (0 == QString::compare("directory", mCurrentElement.type) || 0 == QString::compare("dir", mCurrentElement.type)) {
         // call browseDirectory
         mCurrentDir = mCurrentElement.path;
         browseDirectory(mCurrentDir);
@@ -160,14 +160,14 @@ void BrowseMainWindow::onBrowse() {
 
 void BrowseMainWindow::onAddToPlaylist() {
     QUrl url = QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue");
-    url.addEncodedQueryItem(QByteArray("input"), QUrl::toPercentEncoding(mCurrentElement.path.replace("\\", "\\\\")));
+    url.addEncodedQueryItem(QByteArray("input"), QUrl::toPercentEncoding(mCurrentElement.path.replace("\\", "\\\\").replace("'", "\\'")));
     mNetManager->get(QNetworkRequest(url));
     //mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path.replace("\\", "\\\\"))));
 }
 
 void BrowseMainWindow::onPlay() {
     QUrl url = QUrl("http://"+mIp+"/requests/status.xml?command=in_play");
-    url.addEncodedQueryItem(QByteArray("input"), QUrl::toPercentEncoding(mCurrentElement.path.replace("\\", "\\\\")));
+    url.addEncodedQueryItem(QByteArray("input"), QUrl::toPercentEncoding(mCurrentElement.path.replace("\\", "\\\\").replace("'", "\\'")));
     mNetManager->get(QNetworkRequest(url));
     //mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path.replace("\\", "\\\\"))));
 }
@@ -178,11 +178,17 @@ void BrowseMainWindow::browseDirectory(QString dir) {
     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("\\", "\\\\"))));
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
     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) {
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+    this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
     qDebug() << code;
 }
 void BrowseMainWindow::readReady() {
@@ -195,6 +201,10 @@ void BrowseMainWindow::finished(QNetworkReply * reply) {
     this->parseXmlDirectory();
     // 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);
+#endif
+    delete reply;
 }
 void BrowseMainWindow::parseXmlDirectory() {
     QDomDocument doc;
@@ -217,7 +227,7 @@ void BrowseMainWindow::parseXmlDirectory() {
             dir->name = node.attributes().namedItem("name").nodeValue();
             dir->extension = getExtension(dir->path, node.attributes().namedItem("extension").nodeValue());
             ++idx;
-            if (0 != QString::compare("directory", dir->type)) {
+            if (0 != QString::compare("directory", dir->type) && 0 != QString::compare("dir", dir->type)) {
                 files->append(*dir);
             }
             else if (0 == QString::compare("..", dir->name)) {
@@ -261,15 +271,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();
@@ -286,7 +287,7 @@ void BrowseMainWindow::updateList() {
             VlcBrowseElement dir = mContents->at(idx);
             QListWidgetItem* item;
             bool item_good = false;
-            if (0 == QString::compare("directory", dir.type)) {
+            if (0 == QString::compare("directory", dir.type) || 0 == QString::compare("dir", dir.type)) {
                 if (0 == QString::compare("..", dir.name)) {
                     item = new QListWidgetItem(icon_up, dir.name, ui->listWidget, 0);
                     item_good = true;