add Yannux version with account manager
[vlc-remote] / playermainwindow.cpp
index e54076a..874944d 100644 (file)
@@ -21,6 +21,7 @@
 #include "ui_playermainwindow.h"
 #include "configdialog.h"
 #include "aboutdialog.h"
+#include "accountdialog.h"
 
 
 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
@@ -30,11 +31,6 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
     ui->setupUi(this);
     setWindowTitle("Vlc remote");
 
-    QSettings settings;
-    mIp = settings.value("ip").toString();
-
-    if ( mIp.isEmpty())
-        showConfig();
 
 
     mTimer = new QTimer(this);
@@ -75,9 +71,20 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
     connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
     connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
 
-    mTimer->start(5000);
+    init();
 
 }
+void PlayerMainWindow::init()
+{
+    QSettings settings;
+    QString currentKey = settings.value("config/currentKey").toString();
+    mIp = settings.value("account/"+currentKey).toString()+":8080";
+
+    if ( mIp.isEmpty())
+        showConfig();
+    else
+        mTimer->start(5000);
+}
 
 PlayerMainWindow::~PlayerMainWindow()
 {
@@ -146,8 +153,12 @@ void PlayerMainWindow::slide(int value)
 
 void PlayerMainWindow::showConfig()
 {
-//     ConfigDialog * dialog = new AccountDialog;
-//     dialog->exec();
+    mTimer->stop();
+    AccountDialog * dialog = new AccountDialog;
+    dialog->exec();
+    init();
+
+
 }
 void PlayerMainWindow::showAbout()
 {
@@ -157,13 +168,13 @@ void PlayerMainWindow::showAbout()
 
 }
 
-
 void PlayerMainWindow::askStatus()
 {
 
     QNetworkReply * reply =  mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
     connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
 }
+
 void PlayerMainWindow::parseXmlStatus()
 {
     QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
@@ -178,9 +189,9 @@ void PlayerMainWindow::parseXmlStatus()
     QString state  =docElem.namedItem("state").toElement().text();
 
     QTime timeLength(0,0,0) ;
-   timeLength =  timeLength.addSecs(time);
+    timeLength =  timeLength.addSecs(time);
 
-ui->timeLabel->setText(timeLength.toString("mm:ss"));
+    ui->timeLabel->setText(timeLength.toString("mm:ss"));
 
 
     QDomNode infoNode =  docElem.namedItem("information");