]> git.sur5r.net Git - minitube/commitdiff
Display title and description while video is loading.
authorFlavio Tordini <flavio.tordini@gmail.com>
Sun, 21 Jun 2009 16:19:14 +0000 (18:19 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Sun, 21 Jun 2009 16:19:14 +0000 (18:19 +0200)
initial unfinished impl, lots of bugs.

src/MediaView.cpp
src/MediaView.h
src/loadingwidget.cpp [new file with mode: 0644]
src/loadingwidget.h [new file with mode: 0644]
src/youtubestreamreader.cpp

index 1ebe801cc01e518fbb8bcad9c26880a8ef0eab70..c6c47df82023aeb5ec6b858ce213ee85f0008778 100644 (file)
@@ -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<int> 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();
 
index d810ce5a95aee04e8352e9a074ef07187cd1d362..9f6e5d6d88f6760de652fda19fb6f00e240338b2 100644 (file)
@@ -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 (file)
index 0000000..59fc58b
--- /dev/null
@@ -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(" - ", "<p>");
+    title = title.replace("] ", "]<p>");
+    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 (file)
index 0000000..254717f
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef LOADINGWIDGET_H
+#define LOADINGWIDGET_H
+
+#include <QtGui>
+#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
index 0a3289cbfde342c643c4758ab5d6feff535d8d4d..fd0ce99e71c04dd48db78ae5770b0f4bf89f0d39 100644 (file)
@@ -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;