]> git.sur5r.net Git - minitube/blobdiff - src/videosourcewidget.cpp
New upstream version 2.9
[minitube] / src / videosourcewidget.cpp
index ce1a92fc498b143b56a1de64638bfc74df9c1e26..0e39560fbc24ca7906eaca2334bf85797579189b 100644 (file)
@@ -23,17 +23,14 @@ $END_LICENSE */
 #include "video.h"
 #include "fontutils.h"
 #include "iconutils.h"
-#include "networkaccess.h"
-
-namespace The {
-NetworkAccess* http();
-}
+#include "http.h"
+#include "httputils.h"
 
 VideoSourceWidget::VideoSourceWidget(VideoSource *videoSource, QWidget *parent)
     : GridWidget(parent),
       videoSource(videoSource),
       lastPixelRatio(0) {
-
+    videoSource->setParent(this);
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
     loadPreview();
@@ -45,16 +42,19 @@ void VideoSourceWidget::activate() {
     emit activated(videoSource);
 }
 
-void VideoSourceWidget::previewVideo(const QList<Video *> &videos) {
+void VideoSourceWidget::previewVideo(const QVector<Video *> &videos) {
     videoSource->disconnect();
-    if (videos.isEmpty()) return;
-    Video *video = videos.first();
+    if (videos.isEmpty()) {
+        emit unavailable(this);
+        return;
+    }
+    Video *video = videos.at(0);
     lastPixelRatio = window()->devicePixelRatio();
-    bool needLargeThumb = lastPixelRatio > 1.0 || window()->width() > 2000;
-    QString url =  needLargeThumb ? video->largeThumbnailUrl() : video->mediumThumbnailUrl();
-    if (url.isEmpty()) url = video->mediumThumbnailUrl();
+    bool needLargeThumb = lastPixelRatio > 1.0 || window()->width() > 1000;
+    QString url =  needLargeThumb ? video->getLargeThumbnailUrl() : video->getMediumThumbnailUrl();
+    if (url.isEmpty()) url = video->getMediumThumbnailUrl();
     video->deleteLater();
-    QObject *reply = The::http()->get(url);
+    QObject *reply = HttpUtils::yt().get(url);
     connect(reply, SIGNAL(data(QByteArray)), SLOT(setPixmapData(QByteArray)));
 }
 
@@ -65,8 +65,8 @@ void VideoSourceWidget::setPixmapData(const QByteArray &bytes) {
 }
 
 void VideoSourceWidget::loadPreview() {
-    connect(videoSource, SIGNAL(gotVideos(QList<Video*>)),
-            SLOT(previewVideo(QList<Video*>)), Qt::UniqueConnection);
+    connect(videoSource, SIGNAL(gotVideos(QVector<Video*>)),
+            SLOT(previewVideo(QVector<Video*>)), Qt::UniqueConnection);
     videoSource->loadVideos(1, 1);
 }
 
@@ -117,7 +117,7 @@ void VideoSourceWidget::paintEvent(QPaintEvent *event) {
     int yOffset = 0;
     int yOrigin = 0;
     int hDiff = pixmap.height() - h;
-    if (hDiff > 0) yOffset = hDiff / 4;
+    if (hDiff > 0) yOffset = hDiff / 2;
     else yOrigin = -hDiff / 2;
     p.drawPixmap(xOrigin, yOrigin, pixmap, xOffset, yOffset, w, h);