Minor UI fixes for better usability and orientation support
[vlc-remote] / browsemainwindow.cpp
index 7471551..369464f 100644 (file)
@@ -130,11 +130,11 @@ void BrowseMainWindow::onBrowse() {
 }
 
 void BrowseMainWindow::onAddToPlaylist() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path)));
+    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path.replace("\\", "\\\\"))));
                              }
 
 void BrowseMainWindow::onPlay() {
-    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path)));
+    /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path.replace("\\", "\\\\"))));
                              }
 
 void BrowseMainWindow::browseDirectory(QString dir) {
@@ -174,11 +174,14 @@ void BrowseMainWindow::parseXmlDirectory() {
             dir->date = QDate::fromString(node.attributes().namedItem("date").nodeValue());
             dir->path = node.attributes().namedItem("path").nodeValue();
             dir->name = node.attributes().namedItem("name").nodeValue();
-            dir->extension = node.attributes().namedItem("extension").nodeValue();
+            dir->extension = getExtension(dir->path, node.attributes().namedItem("extension").nodeValue());
             ++idx;
             if (0 != QString::compare("directory", dir->type)) {
                 files->append(*dir);
             }
+            else if (0 == QString::compare("..", dir->name)) {
+                this->mContents->prepend(*dir);
+            }
             else {
                 this->mContents->append(*dir);
             }
@@ -195,6 +198,21 @@ void BrowseMainWindow::parseXmlDirectory() {
     this->updateList();
 }
 
+QString BrowseMainWindow::getExtension(QString path, QString extension) {
+    // return extension if exists
+    if (!extension.isNull() && !extension.isEmpty()) return extension;
+    // return blank if no path
+    if (path.isNull() || path.isEmpty()) return "";
+    // otherwise extract the extension
+    int dot_pos = path.lastIndexOf('.');
+    if (0 < dot_pos) {
+        return path.right(path.length() - (dot_pos + 1));
+    }
+    else { // no dot
+        return "";
+    }
+}
+
 void BrowseMainWindow::writeFile(QString path, QByteArray text) {
     QFile file(path);
     if (!file.open(QIODevice::WriteOnly | QIODevice::Text))