Merge branch 'master' of https://vcs.maemo.org/git/vlc-remote
authoryannux <yannux@onbebop.net>
Thu, 19 Aug 2010 07:04:50 +0000 (09:04 +0200)
committeryannux <yannux@onbebop.net>
Thu, 19 Aug 2010 07:04:50 +0000 (09:04 +0200)
playermainwindow.cpp
playermainwindow.h
playermainwindow.ui
playlistmainwindow.cpp
playlistmainwindow.h
vlcRemote.pro
vlcstatus.cpp [new file with mode: 0644]
vlcstatus.h [new file with mode: 0644]

index c8ee2e5..22e6218 100644 (file)
@@ -22,7 +22,7 @@
   #include "configdialog.h"
   #include "aboutdialog.h"
   #include "accountdialog.h"
-
+  //#include "vlcstatus.h"
 
   PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
          QMainWindow(parent),
@@ -46,9 +46,9 @@
 
       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"));
+      ui->playpauseButton->setIcon(QIcon::fromTheme("camera_playback"));
       ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
-      ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
+      //ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
       ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
       ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
       ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
@@ -80,9 +80,9 @@
       connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(show()));
       connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(showCurrentDirectory()));
 
-      connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
+      connect(ui->playpauseButton,SIGNAL(clicked()),this,SLOT(playpause()));
       connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
-      connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
+      //connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(playpause()));
       connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
       connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
       connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
       }
   }
 
+  void PlayerMainWindow::playpause()
+  {
+      // NB. There is no guarentee that our current state is the real current state.
+      // This is due to the polling frequency and possibility of user interaction directly on the server.
+      // Still this is probably better than nothing and our next real poll will set us straight again.
+      if (PAUSED == mCurrentStatus.state) {
+        mCurrentStatus.state = PLAYING;
+        qDebug() << "pause() from PAUSED";
+        pause();
+        updateUiWithCurrentStatus();
+      }
+      else if (PLAYING == mCurrentStatus.state) {
+        mCurrentStatus.state = PAUSED;
+        qDebug() << "pause() from PLAYING";
+        pause();
+        updateUiWithCurrentStatus();
+      }
+      else {
+        // could be STOP or UNKNOWN, either way there is no guarentee we will enter a playing state next.
+        // So don't update the current state or UI
+        // Ideally we would try to find a way to check the current state again but this could lead to an infinite loop!
+        qDebug() << "play() from " << ((STOP == mCurrentStatus.state) ? "STOP" : "UNKNOWN");
+        play();
+      }
+  }
   void PlayerMainWindow::play()
   {
       mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
       QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
       QDomDocument doc;
       doc.setContent(reply->readAll());
+      delete reply;
       QDomElement docElem = doc.documentElement();
-
+      // Get the raw values
       int volume = docElem.namedItem("volume").toElement().text().toInt();
       int length = docElem.namedItem("length").toElement().text().toInt();
       int time = docElem.namedItem("time").toElement().text().toInt();
       int position = docElem.namedItem("position").toElement().text().toInt();
-      QString state  =docElem.namedItem("state").toElement().text();
-
-
-      if (0 < volume) {
-         this->mVolume = volume;
+      int random = docElem.namedItem("random").toElement().text().toInt();
+      int loop = docElem.namedItem("loop").toElement().text().toInt();
+      int repeat = docElem.namedItem("repeat").toElement().text().toInt();
+      QString state = docElem.namedItem("state").toElement().text();
+      QDomNode infoNode =  docElem.namedItem("information");
+      QDomNode metaInfoNode =  infoNode.namedItem("meta-information");
+      QString title = metaInfoNode.namedItem("title").toElement().text().replace("\\\\", "\\");
+      QString artist = metaInfoNode.namedItem("artist").toElement().text();
+      QString album = metaInfoNode.namedItem("album").toElement().text();
+      QString now_playing = metaInfoNode.namedItem("now_playing").toElement().text();
+      QString art_url = metaInfoNode.namedItem("art_url").toElement().text();
+      // Populate the current status structure
+      // now would be a good time to work out if we are a new track / file or not.
+      // key if we are going to look for album art later
+      // for now we check length and title this will require further examination later
+      mCurrentStatus.newtrack = true;
+      if (mCurrentStatus.length == length && !mCurrentStatus.title.isNull() && 0 == QString::compare(mCurrentStatus.title, title)) {
+        mCurrentStatus.newtrack = false;
+      }
+      mCurrentStatus.volume = volume;
+      mCurrentStatus.length = length;
+      mCurrentStatus.time = time;
+      mCurrentStatus.position = position;
+      mCurrentStatus.random = (1 == random);
+      mCurrentStatus.loop = (1 == loop);
+      mCurrentStatus.repeat = (1 == repeat);
+      mCurrentStatus.title = title;
+      mCurrentStatus.artist = artist;
+      mCurrentStatus.album = album;
+      mCurrentStatus.nowplaying = now_playing;
+      mCurrentStatus.hasart = (!art_url.isNull() && !art_url.isEmpty());
+      if (!state.isNull() && !state.isEmpty()) {
+          if (0 == QString::compare("playing", state, Qt::CaseInsensitive)) {
+            mCurrentStatus.state = PLAYING;
+          }
+          else if (0 == QString::compare("paused", state, Qt::CaseInsensitive)) {
+            mCurrentStatus.state = PAUSED;
+          }
+          else if (0 == QString::compare("stop", state, Qt::CaseInsensitive)) {
+            mCurrentStatus.state = STOP;
+          }
+          else {
+            mCurrentStatus.state = UNKNOWN;
+          }
+      }
+      else {
+          mCurrentStatus.state = UNKNOWN;
+      }
+      // What's our mute status?
+      if (0 < mCurrentStatus.volume) {
+          this->mVolume = mCurrentStatus.volume;
          this->mMuted = false;
       }
       else {
          this->mMuted = true;
       }
+      // Update the UI
+      updateUiWithCurrentStatus();
 
+  }
 
-      QTime timeLength(0,0,0) ;
-      timeLength =  timeLength.addSecs(time);
+  void PlayerMainWindow::updateUiWithCurrentStatus() {
+      // position
+      QTime timePosition(0,0,0) ;
+      timePosition =  timePosition.addSecs(mCurrentStatus.time);
 
-      ui->timeLabel->setText(timeLength.toString("h:mm:ss"));
+      ui->timeLabel->setText(timePosition.toString("h:mm:ss"));
 
+      // duration
+      if (0 < mCurrentStatus.length) {
+          QTime timeDuration(0,0,0) ;
+          timeDuration =  timeDuration.addSecs(mCurrentStatus.length);
 
-      QDomNode infoNode =  docElem.namedItem("information");
-      QDomNode metaInfoNode =  infoNode.namedItem("meta-information");
-      QString title = metaInfoNode.namedItem("title").toElement().text().replace("\\\\", "\\");
+          ui->durationLabel->setText(timeDuration.toString("h:mm:ss"));
+      }
+      else {
+          ui->durationLabel->setText("0:00:00");
+      }
 
-      if ( position >= 0 && position <=100)
-         ui->slider->setValue(position);
 
-      ui->label->setText(title);
-      delete reply;
+      if (mCurrentStatus.position >= 0 && mCurrentStatus.position <= 100)
+          ui->slider->setValue(mCurrentStatus.position);
+
+      ui->label->setText(mCurrentStatus.title);
+
+      if (PLAYING == mCurrentStatus.state) {
+          ui->playpauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
+      }
+      else {
+          ui->playpauseButton->setIcon(QIcon::fromTheme("camera_playback"));
+      }
 
+      if (mCurrentStatus.newtrack) {
+          // potential actions:
+          //   rebuild display layout
+          //   retrieve album art
+      }
+      // Update the buttons on the playlist window
+      if (NULL != this->mPlayListMainWindow) {
+        this->mPlayListMainWindow->updateUiWithCurrentStatus(& mCurrentStatus);
+      }
   }
 
index 0f44d1b..4ab0541 100644 (file)
@@ -24,6 +24,7 @@
 #include <QTimer>
 #include "playlistmainwindow.h"
 #include "browsemainwindow.h"
+#include "vlcstatus.h"
 
 namespace Ui {
     class PlayerMainWindow;
@@ -40,6 +41,7 @@ public slots:
     void showConfig();
     void showAbout();
     void play();
+    void playpause();
     void stop();
     void pause();
     void previous();
@@ -49,6 +51,7 @@ public slots:
     void volDown();
     void volMute();
     void slide(int value);
+    void updateUiWithCurrentStatus();
 
 
 protected slots:
@@ -66,6 +69,7 @@ private:
     QTimer * mTimer;
     int mVolume;
     int mMuted;
+    VlcStatus mCurrentStatus;
 
 };
 
index 7907b1c..4f91409 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>800</width>
-    <height>600</height>
+    <width>798</width>
+    <height>598</height>
    </rect>
   </property>
   <property name="windowTitle">
       <property name="text">
        <string>Information</string>
       </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
      </widget>
     </item>
     <item>
-     <widget class="QLabel" name="timeLabel">
-      <property name="styleSheet">
-       <string notr="true">color: rgb(201, 201, 201);</string>
-      </property>
-      <property name="text">
-       <string/>
-      </property>
-     </widget>
+     <layout class="QHBoxLayout" name="horizontalLayoutTime">
+      <item>
+       <widget class="QLabel" name="timeLabel">
+        <property name="styleSheet">
+         <string notr="true">color: rgb(201, 201, 201);</string>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLabel" name="durationLabel">
+        <property name="styleSheet">
+         <string notr="true">color: rgb(201, 201, 201);</string>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+       </widget>
+      </item>
+     </layout>
     </item>
     <item>
      <widget class="QSlider" name="slider">
@@ -74,9 +94,9 @@
        </widget>
       </item>
       <item>
-       <widget class="QToolButton" name="playButton">
+       <widget class="QToolButton" name="playpauseButton">
         <property name="text">
-         <string>play</string>
+         <string>play/pause</string>
         </property>
        </widget>
       </item>
        </widget>
       </item>
       <item>
-       <widget class="QToolButton" name="pauseButton">
+       <widget class="QToolButton" name="stopButton">
         <property name="text">
-         <string>Pause</string>
+         <string>Stop</string>
         </property>
        </widget>
       </item>
       <item>
-       <widget class="QToolButton" name="stopButton">
-        <property name="text">
-         <string>Stop</string>
+       <spacer name="horizontalSpacer1">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
         </property>
-       </widget>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
       </item>
       <item>
        <widget class="QToolButton" name="fullscreenButton">
        </widget>
       </item>
       <item>
-       <spacer name="horizontalSpacer">
+       <spacer name="horizontalSpacer2">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>800</width>
-     <height>24</height>
+     <width>798</width>
+     <height>20</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuMenu">
index 8a9d978..4114ca5 100644 (file)
@@ -22,6 +22,7 @@
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "accountdialog.h"
+#include "vlcstatus.h"
 
 PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
         QMainWindow(parent),
@@ -315,3 +316,8 @@ void PlayListMainWindow::updateList() {
     }
   }
 }
+void PlayListMainWindow::updateUiWithCurrentStatus(VlcStatus * status) {
+    ui->loopButton->setChecked(status->loop);
+    ui->repeatButton->setChecked(status->repeat);
+    ui->shuffleButton->setChecked(status->random);
+}
index 69cc24c..369c464 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtNetwork>
 #include <QtXml>
 #include "vlcplaylistelementsimple.h"
+#include "vlcstatus.h"
 
 #ifndef LIST_ITEM_TYPE_OFFSET
 #define LIST_ITEM_TYPE_OFFSET 1000
@@ -50,6 +51,7 @@ public slots:
     void finished(QNetworkReply * reply);
     void readReady();
     void showPlayList();
+    void updateUiWithCurrentStatus(VlcStatus * status);
 
 protected slots:
     void parseXmlPlayList();
index 790b205..8cd8145 100644 (file)
@@ -17,7 +17,8 @@ SOURCES += main.cpp \
     newaccountdialog.cpp \
     browsemainwindow.cpp \
     vlcbrowseelement.cpp \
-    vlcplaylistelementsimple.cpp
+    vlcplaylistelementsimple.cpp \
+    vlcstatus.cpp
 HEADERS += playlistmainwindow.h \
     playermainwindow.h \
     configdialog.h \
@@ -26,7 +27,8 @@ HEADERS += playlistmainwindow.h \
     newaccountdialog.h \
     browsemainwindow.h \
     vlcbrowseelement.h \
-    vlcplaylistelementsimple.h
+    vlcplaylistelementsimple.h \
+    vlcstatus.h
 FORMS += playlistmainwindow.ui \
     playermainwindow.ui \
     configdialog.ui \
diff --git a/vlcstatus.cpp b/vlcstatus.cpp
new file mode 100644 (file)
index 0000000..0857f0b
--- /dev/null
@@ -0,0 +1,18 @@
+/*   VLC-REMOTE for MAEMO 5
+*   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
+*   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 "vlcstatus.h"
diff --git a/vlcstatus.h b/vlcstatus.h
new file mode 100644 (file)
index 0000000..738780a
--- /dev/null
@@ -0,0 +1,46 @@
+/*   VLC-REMOTE for MAEMO 5
+*   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
+*   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.
+*/
+#ifndef VLCSTATUS_H
+#define VLCSTATUS_H
+#include <QString>
+
+enum VlcStatusState {
+    UNKNOWN,
+    STOP,
+    PLAYING,
+    PAUSED
+};
+
+struct VlcStatus {
+    bool newtrack;
+    bool random;
+    bool loop;
+    bool repeat;
+    bool hasart;
+    int volume;
+    int length;
+    int time;
+    int position;
+    VlcStatusState state;
+    QString title;
+    QString artist;
+    QString album;
+    QString nowplaying;
+};
+
+#endif // VLCSTATUS_H