From: druid23 Date: Fri, 20 Aug 2010 00:48:52 +0000 (+0100) Subject: Support for album art, various UI improvements X-Git-Tag: v0.5~24 X-Git-Url: https://vcs.maemo.org/git/?p=vlc-remote;a=commitdiff_plain;h=503abed1e7cf3a8ae22cf4a89d13dd92b00d06d0 Support for album art, various UI improvements modified: main.cpp modified: playermainwindow.cpp modified: playermainwindow.h modified: playermainwindow.ui modified: playlistmainwindow.cpp modified: playlistmainwindow.h --- diff --git a/main.cpp b/main.cpp index ec6ea7f..8828564 100644 --- a/main.cpp +++ b/main.cpp @@ -43,8 +43,12 @@ int main(int argc, char *argv[]) PlayerMainWindow * mainwindow = new PlayerMainWindow; -// - mainwindow->showMaximized(); + + mainwindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); + //mainwindow->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); + //mainwindow->setAttribute(Qt::WA_Maemo5AutoOrientation, true); + + mainwindow->showMaximized(); return a.exec(); } diff --git a/playermainwindow.cpp b/playermainwindow.cpp index 22e6218..1157c66 100644 --- a/playermainwindow.cpp +++ b/playermainwindow.cpp @@ -17,6 +17,7 @@ */ #include #include + #include #include "playermainwindow.h" #include "ui_playermainwindow.h" #include "configdialog.h" @@ -41,6 +42,8 @@ mVolume = 100; mMuted = false; + mIsLandscape = true; + ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets")); ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder")); @@ -54,22 +57,28 @@ ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4")); ui->volMute->setIcon(QIcon::fromTheme("statusarea_volume_mute")); + ui->labelArtPortrait->setVisible(false); + ui->labelArtLandscape->setVisible(false); + + ui->labelTitle->setTextFormat(Qt::RichText); + ui->labelArtist->setTextFormat(Qt::RichText); + ui->labelAlbum->setTextFormat(Qt::RichText); + #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) + mPlayListMainWindow->setParent(this); mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow); - mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true); - 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); + connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged())); + #endif connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus())); @@ -91,7 +100,40 @@ connect(ui->volMute,SIGNAL(clicked()),this,SLOT(volMute())); connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int))); - showConfig(); + connect(mPlayListMainWindow, SIGNAL(idUpdated(int,bool,QString)), this, SLOT(playlistIdUpdated(int, bool, QString))); + + + // check if last used connection is still valid or showConfig + QSettings settings; + QString last_ip = AccountDialog::currentIp(); + if (!last_ip.isNull() && !last_ip.isEmpty()) { + QTcpSocket * socket = new QTcpSocket; + if(last_ip.contains(":")) + { + QStringList hostSplit = last_ip.split(":"); + QString ip = hostSplit.at(0); + QString port = hostSplit.at(1); + socket->connectToHost(ip,port.toInt()); + } + else { + socket->connectToHost(last_ip,8080); + } + if (!socket->waitForConnected(1000)) { + showConfig(); + } + else { + mIp= last_ip; + + mPlayListMainWindow->init(); + mBrowserMainWindow->init(); + mTimer->start(5000); + askStatus(); + } + delete socket; + } + else { + showConfig(); + } } @@ -114,6 +156,25 @@ } } + void PlayerMainWindow::orientationChanged() { + QRect screenGeometry = QApplication::desktop()->screenGeometry(); + mIsLandscape = (screenGeometry.width() > screenGeometry.height()); + if (mHasImage) { + if (mIsLandscape) { + ui->labelArtPortrait->setVisible(false); + ui->labelArtLandscape->setVisible(true); + } + else { + ui->labelArtLandscape->setVisible(false); + ui->labelArtPortrait->setVisible(true); + } + } + else { + ui->labelArtLandscape->setVisible(false); + ui->labelArtPortrait->setVisible(false); + } + } + void PlayerMainWindow::playpause() { // NB. There is no guarentee that our current state is the real current state. @@ -121,13 +182,11 @@ // 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(); } @@ -135,7 +194,6 @@ // 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(); } } @@ -235,6 +293,15 @@ QDomNode infoNode = docElem.namedItem("information"); QDomNode metaInfoNode = infoNode.namedItem("meta-information"); QString title = metaInfoNode.namedItem("title").toElement().text().replace("\\\\", "\\"); + // if it's a file style title fix it up + if (40 < title.length()) { + if (0 < title.lastIndexOf("\\")) { + title = title.right(title.length() - (title.lastIndexOf("\\") + 1)); + } + else if (0 < title.lastIndexOf("/")) { + title = title.right(title.length() - (title.lastIndexOf("/") + 1)); + } + } QString artist = metaInfoNode.namedItem("artist").toElement().text(); QString album = metaInfoNode.namedItem("album").toElement().text(); QString now_playing = metaInfoNode.namedItem("now_playing").toElement().text(); @@ -311,7 +378,9 @@ if (mCurrentStatus.position >= 0 && mCurrentStatus.position <= 100) ui->slider->setValue(mCurrentStatus.position); - ui->label->setText(mCurrentStatus.title); + ui->labelTitle->setText(mCurrentStatus.title); + ui->labelArtist->setText(mCurrentStatus.artist); + ui->labelAlbum->setText(mCurrentStatus.album); if (PLAYING == mCurrentStatus.state) { ui->playpauseButton->setIcon(QIcon::fromTheme("camera_video_pause")); @@ -324,10 +393,75 @@ // potential actions: // rebuild display layout // retrieve album art + mHasImage = false; + mPlayListMainWindow->requestPlayList(); } // Update the buttons on the playlist window if (NULL != this->mPlayListMainWindow) { this->mPlayListMainWindow->updateUiWithCurrentStatus(& mCurrentStatus); } + + } + void PlayerMainWindow::playlistIdUpdated(int id, bool hasart, QString extension) { + if (hasart) { + getCoverArt(id); + } + else { + ui->labelArtLandscape->setVisible(false); + ui->labelArtPortrait->setVisible(false); + // could use a default graphic here! + // setCoverArtFromPixmap(); + } + } + void PlayerMainWindow::readReady() { + QNetworkReply * reply = qobject_cast(sender()); + // append to buffer + mResponse += reply->readAll(); + } + void PlayerMainWindow::finished(QNetworkReply * reply) { + // now we can call setCoverArt to process the full buffers + this->setCoverArt(mResponse); + // only interested in finished signals + disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); + } + void PlayerMainWindow::getCoverArt(int id) { + mResponse.clear(); + QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/art?id=" + QString::number(id)))); + connect(reply,SIGNAL(readyRead()),this,SLOT(readReady())); + connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); + + } + void PlayerMainWindow::setCoverArt(const QByteArray data) { + QPixmap* image = new QPixmap(); + if (image->loadFromData(data)) { + mHasImage = true; + ui->labelArtLandscape->setPixmap(image->scaledToHeight(120, Qt::SmoothTransformation)); + ui->labelArtPortrait->setPixmap(image->scaledToHeight(310, Qt::SmoothTransformation)); + if (mIsLandscape) { + ui->labelArtPortrait->setVisible(false); + ui->labelArtLandscape->setVisible(true); + } + else { + ui->labelArtLandscape->setVisible(false); + ui->labelArtPortrait->setVisible(true); + } + } + else { + ui->labelArtPortrait->setVisible(false); + ui->labelArtLandscape->setVisible(false); + } + } + void PlayerMainWindow::setCoverArtFromPixmap(QPixmap image) { + mHasImage = true; + ui->labelArtLandscape->setPixmap(image.scaledToHeight(120, Qt::SmoothTransformation)); + ui->labelArtPortrait->setPixmap(image.scaledToHeight(310, Qt::SmoothTransformation)); + if (mIsLandscape) { + ui->labelArtPortrait->setVisible(false); + ui->labelArtLandscape->setVisible(true); + } + else { + ui->labelArtLandscape->setVisible(false); + ui->labelArtPortrait->setVisible(true); + } } diff --git a/playermainwindow.h b/playermainwindow.h index 4ab0541..8389002 100644 --- a/playermainwindow.h +++ b/playermainwindow.h @@ -52,6 +52,13 @@ public slots: void volMute(); void slide(int value); void updateUiWithCurrentStatus(); + void setCoverArt(const QByteArray data); + void setCoverArtFromPixmap(QPixmap image); + void getCoverArt(int id); + void finished(QNetworkReply * reply); + void readReady(); + void orientationChanged(); + void playlistIdUpdated(int id, bool hasart, QString extension); protected slots: @@ -70,6 +77,9 @@ private: int mVolume; int mMuted; VlcStatus mCurrentStatus; + QByteArray mResponse; + bool mIsLandscape; + bool mHasImage; }; diff --git a/playermainwindow.ui b/playermainwindow.ui index 4f91409..6251e68 100644 --- a/playermainwindow.ui +++ b/playermainwindow.ui @@ -16,22 +16,113 @@ - + - 0 - 200 - + 380 + 340 + s - - Information + + + 380 + 340 + - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignHCenter|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 30 + + + + Information + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 30 + + + + Information + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 30 + + + + Information + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 140 + 140 + + + + + 140 + 140 + + + + Qt::AlignHCenter|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Vertical + + + + 20 + 100 + + + + + @@ -72,19 +163,6 @@ - - - Qt::Vertical - - - - 20 - 230 - - - - - diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index 4114ca5..4ce67a7 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -164,6 +164,10 @@ void PlayListMainWindow::parseXmlPlayList() { QDomNodeList nodes = docElem.elementsByTagName("node"); int depth = 0; + int currentLeafId = 0; + bool hasArt = false; + QString extension = ""; + int ct = nodes.count(); for (int idx = 0; idx < ct; ++idx) { QDomNode node = nodes.at(idx); @@ -205,6 +209,12 @@ void PlayListMainWindow::parseXmlPlayList() { it->type = "leaf"; current = item.attributes().namedItem("current").nodeValue(); it->playing = (0 < current.length()); + if (it->playing) { + currentLeafId = it->id; + QString art = item.toElement().namedItem("art_url").toElement().text(); + hasArt = (!art.isNull() && !art.isEmpty()); + extension = getExtension(it->path, NULL); + } this->mContents->append(*it); delete it; } @@ -226,8 +236,10 @@ void PlayListMainWindow::parseXmlPlayList() { mResponse.clear(); + emit this->idUpdated(currentLeafId, hasArt, extension); this->updateList(); + } QString PlayListMainWindow::getExtension(QString path, QString extension) { diff --git a/playlistmainwindow.h b/playlistmainwindow.h index 369c464..e6dee7b 100644 --- a/playlistmainwindow.h +++ b/playlistmainwindow.h @@ -57,6 +57,9 @@ protected slots: void parseXmlPlayList(); void updateList(); +signals: + void idUpdated(int id, bool hasArt, QString extension); + protected: void changeEvent(QEvent *e); VlcPlayListElementSimple getElementFromText(QString text);