From: Flavio Tordini Date: Sun, 21 Jun 2009 16:19:14 +0000 (+0200) Subject: Display title and description while video is loading. X-Git-Tag: 0.4~44 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d6e0a89670dd1fc404d18b7e52aefc9bef65a2e5;p=minitube Display title and description while video is loading. initial unfinished impl, lots of bugs. --- diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 1ebe801..c6c47df 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -17,8 +17,6 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { splitter = new MiniSplitter(this); splitter->setChildrenCollapsible(false); - // splitter->setBackgroundRole(QPalette::Text); - // splitter->setAutoFillBackground(true); sortBar = new THBlackBar(this); mostRelevantAction = new THAction(tr("Most relevant"), this); @@ -61,14 +59,24 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { this, SLOT(selectionChanged ( const QItemSelection & , const QItemSelection & ))); playlistWidget = new PlaylistWidget(this, sortBar, listView); + // playlistWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); splitter->addWidget(playlistWidget); videoWidget = new VideoWidget(this); videoWidget->setMinimumSize(320,240); + // videoWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + videoWidget->hide(); splitter->addWidget(videoWidget); - // expand video by default - // splitter->setStretchFactor (1, 2); + + loadingWidget = new LoadingWidget(this); + loadingWidget->setMinimumSize(320,240); + // loadingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + splitter->addWidget(loadingWidget); + + QList sizes; + sizes << 320 << 640 << 640; + splitter->setSizes(sizes); layout->addWidget(splitter); setLayout(layout); @@ -95,6 +103,7 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)), this, SLOT(currentSourceChanged(Phonon::MediaSource))); // connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); + connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int))); } void MediaView::search(SearchParams *searchParams) { @@ -123,11 +132,13 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /* oldState * case Phonon::PlayingState: qDebug("playing"); + loadingWidget->hide(); + videoWidget->show(); break; case Phonon::StoppedState: qDebug("stopped"); - // Play() has already been called when setting the source + // play() has already been called when setting the source // but Phonon on Linux needs a little more help to start playback mediaObject->play(); break; @@ -194,6 +205,12 @@ void MediaView::stop() { void MediaView::activeRowChanged(int row) { Video *video = listModel->videoAt(row); if (!video) return; + + // immediately show the loading widget + videoWidget->hide(); + loadingWidget->setVideo(video); + loadingWidget->show(); + QUrl streamUrl = video->streamUrl(); // qDebug() << "setCurrentSource" << streamUrl.toString(); diff --git a/src/MediaView.h b/src/MediaView.h index d810ce5..9f6e5d6 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -10,6 +10,7 @@ #include "thblackbar.h" #include "searchparams.h" #include "playlistwidget.h" +#include "loadingwidget.h" class MediaView : public QWidget, public View { Q_OBJECT @@ -82,6 +83,9 @@ private: Phonon::MediaObject *mediaObject; Phonon::VideoWidget *videoWidget; + // loadingWidget + LoadingWidget *loadingWidget; + QNetworkReply *networkReply; }; diff --git a/src/loadingwidget.cpp b/src/loadingwidget.cpp new file mode 100644 index 0000000..59fc58b --- /dev/null +++ b/src/loadingwidget.cpp @@ -0,0 +1,67 @@ +#include "loadingwidget.h" + +LoadingWidget::LoadingWidget(QWidget *parent) : QWidget(parent) { + + QPalette p = palette(); + p.setBrush(QPalette::Window, Qt::black); + p.setBrush(QPalette::Text, Qt::white); + setPalette(p); + + setAutoFillBackground(true); + + QBoxLayout *layout = new QVBoxLayout(); + layout->setAlignment(Qt::AlignCenter); + + QFont bigFont; + bigFont.setPointSize(bigFont.pointSize()*4); + + titleLabel = new QLabel(this); + titleLabel->setAlignment(Qt::AlignCenter); + titleLabel->setForegroundRole(QPalette::Text); + titleLabel->setWordWrap(true); + titleLabel->setFont(bigFont); + titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + layout->addWidget(titleLabel); + + QFont biggerFont; + biggerFont.setPointSize(biggerFont.pointSize()*2); + + descriptionLabel = new QLabel(this); + descriptionLabel->setAlignment(Qt::AlignCenter); + descriptionLabel->setForegroundRole(QPalette::Text); + descriptionLabel->setWordWrap(true); + descriptionLabel->setFont(biggerFont); + descriptionLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + layout->addWidget(descriptionLabel); + + progressBar = new QProgressBar(this); + progressBar->hide(); + layout->addWidget(progressBar); + + setLayout(layout); +} + +void LoadingWidget::setVideo(Video *video) { + QString title = video->title(); + // enhance legibility by splitting the title + title = title.replace(" - ", "

"); + title = title.replace("] ", "]

"); + titleLabel->setText(title); + descriptionLabel->setText(video->description()); + progressBar->hide(); +} + +void LoadingWidget::bufferStatus(int percent) { + qDebug() << percent; + progressBar->setShown(percent > 0); + progressBar->setValue(percent); +} + +void LoadingWidget::paintEvent(QPaintEvent *) { + + /* + QPainter painter(this); + painter.fillRect(0, 0, width(), height(), Qt::black); + */ + +} diff --git a/src/loadingwidget.h b/src/loadingwidget.h new file mode 100644 index 0000000..254717f --- /dev/null +++ b/src/loadingwidget.h @@ -0,0 +1,28 @@ +#ifndef LOADINGWIDGET_H +#define LOADINGWIDGET_H + +#include +#include "video.h" + +class LoadingWidget : public QWidget { + + Q_OBJECT + +public: + LoadingWidget(QWidget *parent); + void setVideo(Video *video); + +public slots: + void bufferStatus(int); + +protected: + void paintEvent(QPaintEvent *event); + +private: + QLabel *titleLabel; + QLabel *descriptionLabel; + QProgressBar *progressBar; + +}; + +#endif // LOADINGWIDGET_H diff --git a/src/youtubestreamreader.cpp b/src/youtubestreamreader.cpp index 0a3289c..fd0ce99 100644 --- a/src/youtubestreamreader.cpp +++ b/src/youtubestreamreader.cpp @@ -86,12 +86,11 @@ void YouTubeStreamReader::readEntry() { // qDebug() << "Title: " << title; video->setTitle(title); } - /* else if (name() == "description") { QString desc = readElementText(); - qDebug() << "Description: " << desc; + // qDebug() << "Description: " << desc; video->setDescription(desc); - } */ + } else if (name() == "duration") { QString duration = attributes().value("seconds").toString(); // qDebug() << "Duration: " << duration;