Add static currentIP() in AccountDialog and change all
[vlc-remote] / playermainwindow.cpp
index 1b7ddbd..5df823d 100644 (file)
@@ -1,29 +1,49 @@
+/*   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);
     mNetManager = new QNetworkAccessManager(this);
     mPlayListMainWindow = new PlayListMainWindow;
+    mBrowserMainWindow = new BrowseMainWindow;
 
+    mVolume = 100;
+    mMuted = false;
 
     ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
+    ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder"));
+
     ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
     ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
     ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
@@ -32,6 +52,8 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
     ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
     ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
     ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
+    ui->volMute->setIcon(QIcon::fromTheme("statusarea_volume_mute"));
+
 
 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
     mPlayListMainWindow->setParent(this);
@@ -40,12 +62,22 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
     mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
     setAttribute(Qt::WA_Maemo5StackedWindow);
     mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
+
+    mBrowserMainWindow->setParent(this);
+    mBrowserMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
+    mBrowserMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
+    mBrowserMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
+    mBrowserMainWindow->setWindowFlags(mBrowserMainWindow->windowFlags() | Qt::Window);
+
 #endif
 
     connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
     connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
     connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
     connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
+    connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(show()));
+
     connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
     connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
     connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
@@ -54,9 +86,26 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
     connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
     connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
     connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
+    connect(ui->volMute,SIGNAL(clicked()),this,SLOT(volMute()));
     connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
 
-    mTimer->start(5000);
+    init();
+
+}
+void PlayerMainWindow::init()
+{
+
+    mIp= AccountDialog::currentIp();
+
+    if ( mIp.isEmpty())
+        showConfig();
+
+    else
+    {
+        mTimer->start(5000);
+        mPlayListMainWindow->init();
+        mBrowserMainWindow->init();
+    }
 
 }
 
@@ -110,8 +159,9 @@ void PlayerMainWindow::fullscreen()
 }
 void PlayerMainWindow::volUp()
 {
-    mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
-
+    QUrl url = QUrl("http://"+mIp+"/requests/status.xml?command=volume");
+    url.addEncodedQueryItem(QByteArray("val"), QByteArray("%2B20"));
+    mNetManager->get(QNetworkRequest(url));
 }
 void PlayerMainWindow::volDown()
 {
@@ -119,6 +169,17 @@ void PlayerMainWindow::volDown()
     mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
 
 }
+void PlayerMainWindow::volMute()
+{
+    this->mMuted = !this->mMuted;
+    if (this->mMuted) {
+        mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=0")));
+    }
+    else {
+        mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val="+QString::number(this->mVolume))));
+    }
+
+}
 void PlayerMainWindow::slide(int value)
 {
     mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
@@ -127,8 +188,13 @@ 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 +204,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());
@@ -158,10 +224,20 @@ void PlayerMainWindow::parseXmlStatus()
     int position = docElem.namedItem("position").toElement().text().toInt();
     QString state  =docElem.namedItem("state").toElement().text();
 
+
+    if (0 < volume) {
+        this->mVolume = volume;
+        this->mMuted = false;
+    }
+    else {
+        this->mMuted = true;
+    }
+
+
     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");