add Yannux version with account manager
[vlc-remote] / playermainwindow.cpp
index 1b7ddbd..874944d 100644 (file)
@@ -1,21 +1,36 @@
+/*   VLC-REMOTE for MAEMO 5
+ *   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   or (at your option) any later version, as published by the Free
+ *   Software Foundation
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details
+ *
+ *   You should have received a copy of the GNU General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
 #include <QDebug>
 #include <QTime>
 #include "playermainwindow.h"
 #include "ui_playermainwindow.h"
 #include "configdialog.h"
 #include "aboutdialog.h"
+#include "accountdialog.h"
+
 
 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
         QMainWindow(parent),
         ui(new Ui::PlayerMainWindow)
 {
     ui->setupUi(this);
+    setWindowTitle("Vlc remote");
 
-    QSettings settings;
-    mIp = settings.value("ip").toString();
-
-    if ( mIp.isEmpty())
-        showConfig();
 
 
     mTimer = new QTimer(this);
@@ -56,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()
 {
@@ -127,8 +153,12 @@ void PlayerMainWindow::slide(int value)
 
 void PlayerMainWindow::showConfig()
 {
-    ConfigDialog * dialog = new ConfigDialog;
+    mTimer->stop();
+    AccountDialog * dialog = new AccountDialog;
     dialog->exec();
+    init();
+
+
 }
 void PlayerMainWindow::showAbout()
 {
@@ -138,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());
@@ -159,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");