From 2efa3a5e20a4d715f6e9174182d51214fab5fb8b Mon Sep 17 00:00:00 2001 From: druid23 Date: Wed, 18 Aug 2010 23:30:08 +0100 Subject: [PATCH 1/1] Consolidated play / pause to single button Now updating button states to reflect status in playlist modified: playermainwindow.cpp modified: playermainwindow.h modified: playermainwindow.ui modified: playlistmainwindow.cpp modified: playlistmainwindow.h modified: vlcRemote.pro modified: vlcstatus.h --- playermainwindow.cpp | 125 ++++++++++++++++++++++++++++++++++++++++-------- playermainwindow.h | 4 ++ playermainwindow.ui | 23 +++++++-- playlistmainwindow.cpp | 6 +++ playlistmainwindow.h | 2 + vlcRemote.pro | 6 ++- vlcstatus.h | 1 + 7 files changed, 141 insertions(+), 26 deletions(-) diff --git a/playermainwindow.cpp b/playermainwindow.cpp index c8ee2e5..3f58f03 100644 --- a/playermainwindow.cpp +++ b/playermainwindow.cpp @@ -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())); @@ -114,6 +114,31 @@ } } + 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"))); @@ -196,39 +221,101 @@ QNetworkReply * reply = qobject_cast(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(); + } + void PlayerMainWindow::updateUiWithCurrentStatus() { QTime timeLength(0,0,0) ; - timeLength = timeLength.addSecs(time); + timeLength = timeLength.addSecs(mCurrentStatus.time); ui->timeLabel->setText(timeLength.toString("h:mm:ss")); - QDomNode infoNode = docElem.namedItem("information"); - QDomNode metaInfoNode = infoNode.namedItem("meta-information"); - QString title = metaInfoNode.namedItem("title").toElement().text().replace("\\\\", "\\"); - if ( position >= 0 && position <=100) - ui->slider->setValue(position); + if (mCurrentStatus.position >= 0 && mCurrentStatus.position <= 100) + ui->slider->setValue(mCurrentStatus.position); - ui->label->setText(title); - delete reply; + 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 + } + + if (NULL != this->mPlayListMainWindow) { + this->mPlayListMainWindow->updateUiWithCurrentStatus(& mCurrentStatus); + } } diff --git a/playermainwindow.h b/playermainwindow.h index 0f44d1b..4ab0541 100644 --- a/playermainwindow.h +++ b/playermainwindow.h @@ -24,6 +24,7 @@ #include #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; }; diff --git a/playermainwindow.ui b/playermainwindow.ui index 7907b1c..787f791 100644 --- a/playermainwindow.ui +++ b/playermainwindow.ui @@ -74,9 +74,9 @@ - + - play + play/pause @@ -87,13 +87,13 @@ - + @@ -102,6 +102,19 @@ + + + Qt::Horizontal + + + + 40 + 20 + + + + + FS @@ -109,7 +122,7 @@ - + Qt::Horizontal diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index 8a9d978..4114ca5 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -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); +} diff --git a/playlistmainwindow.h b/playlistmainwindow.h index 69cc24c..369c464 100644 --- a/playlistmainwindow.h +++ b/playlistmainwindow.h @@ -23,6 +23,7 @@ #include #include #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(); diff --git a/vlcRemote.pro b/vlcRemote.pro index 790b205..8cd8145 100644 --- a/vlcRemote.pro +++ b/vlcRemote.pro @@ -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.h b/vlcstatus.h index e97d322..738780a 100644 --- a/vlcstatus.h +++ b/vlcstatus.h @@ -27,6 +27,7 @@ enum VlcStatusState { }; struct VlcStatus { + bool newtrack; bool random; bool loop; bool repeat; -- 1.7.9.5