Update async methods! Now valid ip is detected
[vlc-remote] / browsemainwindow.cpp
index 599b632..90f09a7 100644 (file)
@@ -21,7 +21,7 @@
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "vlcbrowseelement.h"
-
+#include "accountdialog.h"
 
 BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
         QMainWindow(parent),
@@ -32,8 +32,6 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
     mCurrentDir = "~/"; // This works on win as well as linux, would guess mac too.
     setWindowTitle("Vlc remote");
 
-    QSettings settings;
-    mIp = settings.value("ip").toString();
 
     mNetManager = new QNetworkAccessManager(this);
 
@@ -53,7 +51,17 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
     connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay()));
     connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
 
-    this->browseDirectory(mCurrentDir);
+    init();
+
+
+}
+void BrowseMainWindow::init()  // THIS METHOD IS CALLED WHEN CONFIG CHANGED...
+{
+    mIp = AccountDialog::currentIp();
+}
+void BrowseMainWindow::showCurrentDirectory()  // THIS METHOD IS CALLED WHEN WINDOW IS OPENED...
+{
+    browseDirectory(mCurrentDir);
 }
 
 BrowseMainWindow::~BrowseMainWindow()
@@ -122,18 +130,17 @@ void BrowseMainWindow::onBrowse() {
 
 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) {
     mContents->clear();
     ui->listWidget->clear();
     mResponse.clear();
     QNetworkReply * reply =  mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir)));
-    //reply->setReadBufferSize(1024 * 500);
     connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
     connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
 }
@@ -189,11 +196,11 @@ void BrowseMainWindow::parseXmlDirectory() {
 
 void BrowseMainWindow::writeFile(QString path, QByteArray text) {
     QFile file(path);
-         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
-             return;
+    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
+        return;
 
-         QTextStream out(&file);
-         out << text;
+    QTextStream out(&file);
+    out << text;
 }
 
 void BrowseMainWindow::updateList() {