modified: browsemainwindow.cpp
authordruid23 <usr@dru-id.co.uk>
Mon, 16 Aug 2010 21:29:33 +0000 (22:29 +0100)
committerdruid23 <usr@dru-id.co.uk>
Mon, 16 Aug 2010 21:29:33 +0000 (22:29 +0100)
modified:   browsemainwindow.ui
modified:   playermainwindow.ui
modified:   playlistmainwindow.cpp
modified:   playlistmainwindow.ui

Fixed a couple of minor memory leaks.
Removed an unused status var from each of the 3 main UIs.
Relayed out Playlist window for clarity on destructive actions.
Improved bwose list widget sorting to folder alpha, then file alpha.

browsemainwindow.cpp
browsemainwindow.ui
playermainwindow.ui
playlistmainwindow.cpp
playlistmainwindow.ui

index c561533..7bb6cbb 100644 (file)
@@ -18,7 +18,6 @@
 #include "browsemainwindow.h"
 #include "ui_browsemainwindow.h"
 #include <QSettings>
-#include <QDebug>
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "vlcbrowseelement.h"
@@ -34,13 +33,12 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
     setWindowTitle("Vlc remote");
 
     QSettings settings;
-
-    QString currentKey = settings.value("config/currentKey").toString();
-    mIp = settings.value("account/"+currentKey).toString();
-
+    mIp = settings.value("ip").toString();
 
     mNetManager = new QNetworkAccessManager(this);
 
+    mContents = new QList<VlcBrowseElement>();
+
     ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
     ui->addButton->setIcon(QIcon::fromTheme("general_add"));
     ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder"));
@@ -102,11 +100,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());
 }
@@ -117,15 +115,18 @@ void BrowseMainWindow::onBrowse() {
         // call browseDirectory
         this->browseDirectory(mCurrentElement.path);
     }
+    else {
+        ui->browseButton->setDisabled(true);
+    }
 }
 
 void BrowseMainWindow::onAddToPlaylist() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path)));
-                             }
+}
 
 void BrowseMainWindow::onPlay() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path)));
-                             }
+}
 
 void BrowseMainWindow::browseDirectory(QString dir) {
     ui->listWidget->clear();
@@ -133,12 +134,17 @@ void BrowseMainWindow::browseDirectory(QString dir) {
     connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlDirectory()));
 }
 void BrowseMainWindow::parseXmlDirectory() {
+    qDebug() << "got called!";
     QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
     QDomDocument doc;
     doc.setContent(reply->readAll());
     QDomElement docElem = doc.documentElement();
     QDomNodeList elements = docElem.elementsByTagName("element");
-    mContents = new QList<VlcBrowseElement>();
+    mContents->clear();
+    //mContents = new QList<VlcBrowseElement>();
+    // we can sort by filders 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<VlcBrowseElement>* files = new QList<VlcBrowseElement>();
     if (0 < elements.count()) {
         int idx = 0;
         do {
@@ -151,9 +157,20 @@ void BrowseMainWindow::parseXmlDirectory() {
             dir->name = node.attributes().namedItem("name").nodeValue();
             dir->extension = node.attributes().namedItem("extension").nodeValue();
             ++idx;
-            this->mContents->append(*dir);
+            if (0 != QString::compare("directory", dir->type)) {
+                files->append(*dir);
+            }
+            else {
+                this->mContents->append(*dir);
+            }
+            delete dir;
         } while (idx < elements.count());
+        if (0 < files->count()) {
+            mContents->append(*files);
+        }
     }
+    delete files;
+    //reply->deleteLater();
     delete reply;
 
     // Update UI
index 0b3b7a8..6153415 100644 (file)
@@ -64,7 +64,6 @@
    </widget>
    <addaction name="menuConfiguration"/>
   </widget>
-  <widget class="QStatusBar" name="statusbar"/>
   <action name="actionConfiguration">
    <property name="text">
     <string>configuration</string>
index 06765a4..7907b1c 100644 (file)
    </widget>
    <addaction name="menuMenu"/>
   </widget>
-  <widget class="QStatusBar" name="statusbar"/>
   <action name="actionConfiguration">
    <property name="text">
     <string>Configuration</string>
index cefca98..ce22140 100644 (file)
@@ -43,6 +43,8 @@ PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
 
     mNetManager = new QNetworkAccessManager(this);
 
+    mContents = new QList<VlcPlayListElementSimple>();
+
     ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
     ui->clearButton->setIcon(QIcon::fromTheme("general_delete"));
     ui->shuffleButton->setIcon(QIcon::fromTheme("mediaplayer_default_shuffle"));
@@ -138,7 +140,7 @@ void PlayListMainWindow::parseXmlPlayList() {
     doc.setContent(reply->readAll());
     QDomElement docElem = doc.documentElement();
     QDomNodeList nodes = docElem.elementsByTagName("node");
-    mContents = new QList<VlcPlayListElementSimple>();
+    mContents->clear();
 
     int depth = 0;
 
@@ -162,6 +164,7 @@ void PlayListMainWindow::parseXmlPlayList() {
                         el->path = leaf.attributes().namedItem("uri").nodeValue();
                         el->name = leaf.attributes().namedItem("name").nodeValue();
                         this->mContents->append(*el);
+                        delete el;
                     }
                 }
             }
index fb89673..dd76af9 100644 (file)
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout">
       <item>
-       <widget class="QToolButton" name="clearButton">
-        <property name="text">
-         <string>Clear</string>
-        </property>
-       </widget>
-      </item>
-      <item>
        <widget class="QToolButton" name="shuffleButton">
         <property name="text">
          <string>Shuffle</string>
        </widget>
       </item>
       <item>
-       <widget class="QToolButton" name="removeButton">
-        <property name="text">
-         <string>Remove</string>
-        </property>
-       </widget>
-      </item>
-      <item>
        <spacer name="horizontalSpacer">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
       </item>
      </layout>
     </item>
+    <item>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <widget class="QPushButton" name="clearButton">
+        <property name="text">
+         <string>Clear all</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="removeButton">
+        <property name="text">
+         <string>Remove</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </item>
    </layout>
   </widget>
   <widget class="QMenuBar" name="menubar">
    </widget>
    <addaction name="menuConfiguration"/>
   </widget>
-  <widget class="QStatusBar" name="statusbar"/>
   <action name="actionConfiguration">
    <property name="text">
     <string>configuration</string>