]> git.sur5r.net Git - minitube/blobdiff - src/mediaview.cpp
Fix updating QUrl query parameters with Qt5.
[minitube] / src / mediaview.cpp
index 9f5aafa03c1184aeedfd6bc30b0a68fb961e6ade..a0a36dbbf35c23aa3e927372ff103bea1e08e33e 100644 (file)
@@ -24,7 +24,6 @@ $END_LICENSE */
 #include "loadingwidget.h"
 #include "videoareawidget.h"
 #include "networkaccess.h"
-#include "videowidget.h"
 #include "minisplitter.h"
 #include "constants.h"
 #include "downloadmanager.h"
@@ -45,8 +44,13 @@ $END_LICENSE */
 #include "searchparams.h"
 #include "ytsinglevideosource.h"
 #include "channelaggregator.h"
-#include "utils.h"
-#include "ytuser.h"
+#include "iconutils.h"
+#include "ytchannel.h"
+#ifdef APP_SNAPSHOT
+#include "snapshotsettings.h"
+#endif
+#include "datautils.h"
+#include "compatibility/qurlqueryhelper.h"
 
 namespace The {
 NetworkAccess* http();
@@ -62,6 +66,9 @@ MediaView* MediaView::instance() {
 
 MediaView::MediaView(QWidget *parent) : QWidget(parent),
     stopped(false),
+    #ifdef APP_SNAPSHOT
+    snapshotSettings(0),
+    #endif
     downloadItem(0) { }
 
 void MediaView::initialize() {
@@ -96,13 +103,16 @@ void MediaView::initialize() {
     connect(playlistModel, SIGNAL(haveSuggestions(const QStringList &)),
             sidebar, SLOT(showSuggestions(const QStringList &)));
     connect(sidebar, SIGNAL(suggestionAccepted(QString)),
-            MainWindow::instance(), SLOT(startToolbarSearch(QString)));
+            MainWindow::instance(), SLOT(search(QString)));
     splitter->addWidget(sidebar);
 
     videoAreaWidget = new VideoAreaWidget(this);
     // videoAreaWidget->setMinimumSize(320,240);
+
+#ifdef APP_PHONON
     videoWidget = new Phonon::VideoWidget(this);
     videoAreaWidget->setVideoWidget(videoWidget);
+#endif
     videoAreaWidget->setListModel(playlistModel);
 
     loadingWidget = new LoadingWidget(this);
@@ -142,10 +152,13 @@ void MediaView::initialize() {
             << The::globalActions()->value("webpage")
             << The::globalActions()->value("pagelink")
             << The::globalActions()->value("videolink")
+            << The::globalActions()->value("open-in-browser")
+           #ifdef APP_SNAPSHOT
+            << The::globalActions()->value("snapshot")
+           #endif
             << The::globalActions()->value("findVideoParts")
             << The::globalActions()->value("skip")
             << The::globalActions()->value("previous")
-            // << The::globalActions()->value("download")
             << The::globalActions()->value("stopafterthis")
             << The::globalActions()->value("related-videos")
             << The::globalActions()->value("refine-search")
@@ -153,27 +166,23 @@ void MediaView::initialize() {
             << The::globalActions()->value("facebook")
             << The::globalActions()->value("buffer")
             << The::globalActions()->value("email");
+
+#ifndef APP_PHONON_SEEK
+    QSlider *slider = MainWindow::instance()->getSlider();
+    connect(slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)));
+#endif
 }
 
+#ifdef APP_PHONON
 void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
     this->mediaObject = mediaObject;
     Phonon::createPath(mediaObject, videoWidget);
     connect(mediaObject, SIGNAL(finished()), SLOT(playbackFinished()));
     connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
             SLOT(stateChanged(Phonon::State, Phonon::State)));
-    /*
-    const char* s = Constants::NAME;
-    const int l = strlen(s);
-    int t = The::globalActions()->count();
-    for (int i = 0; i < l; i++) {
-        t += s[i];
-        qDebug() << t << The::globalActions()->count();
-    }
-    qDebug() << t << The::globalActions()->count();
-    if (t != s[0]) return;
-    */
     connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish()));
 }
+#endif
 
 SearchParams* MediaView::getSearchParams() {
     VideoSource *videoSource = playlistModel->getVideoSource();
@@ -197,10 +206,13 @@ void MediaView::search(SearchParams *searchParams) {
             }
         }
     }
-    setVideoSource(new YTSearch(searchParams, this));
+    YTSearch *ytSearch = new YTSearch(searchParams, this);
+    ytSearch->setAsyncDetails(true);
+    connect(ytSearch, SIGNAL(gotDetails()), playlistModel, SLOT(emitDataChanged()));
+    setVideoSource(ytSearch);
 }
 
-void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory) {
+void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory, bool back) {
     stopped = false;
 
 #ifdef APP_ACTIVATION
@@ -224,6 +236,11 @@ void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory) {
         history.append(videoSource);
     }
 
+#ifdef APP_EXTRA
+    if (history.size() > 1)
+        Extra::slideTransition(playlistView->viewport(), playlistView->viewport(), back);
+#endif
+
     playlistModel->setVideoSource(videoSource);
 
     sidebar->showPlaylist();
@@ -232,8 +249,10 @@ void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory) {
     sidebar->getHeader()->updateInfo();
 
     SearchParams *searchParams = getSearchParams();
-    bool isChannel = searchParams && !searchParams->author().isEmpty();
+    bool isChannel = searchParams && !searchParams->channelId().isEmpty();
     playlistView->setClickableAuthors(!isChannel);
+
+
 }
 
 void MediaView::searchAgain() {
@@ -250,7 +269,7 @@ void MediaView::goBack() {
         int currentIndex = getHistoryIndex();
         if (currentIndex > 0) {
             VideoSource *previousVideoSource = history.at(currentIndex - 1);
-            setVideoSource(previousVideoSource, false);
+            setVideoSource(previousVideoSource, false, true);
         }
     }
 }
@@ -286,21 +305,29 @@ void MediaView::disappear() {
 
 }
 
-void MediaView::handleError(QString /* message */) {
+void MediaView::handleError(QString message) {
+    qWarning() << __PRETTY_FUNCTION__ << message;
+#ifdef APP_PHONON_SEEK
+    mediaObject->play();
+#else
     QTimer::singleShot(500, this, SLOT(startPlaying()));
+#endif
 }
 
+#ifdef APP_PHONON
 void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
     if (newState == Phonon::PlayingState)
         videoAreaWidget->showVideo();
     else if (newState == Phonon::ErrorState) {
-        qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
+        qWarning() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
         if (mediaObject->errorType() == Phonon::FatalError)
             handleError(mediaObject->errorString());
     }
 }
+#endif
 
 void MediaView::pause() {
+#ifdef APP_PHONON
     switch( mediaObject->state() ) {
     case Phonon::PlayingState:
         mediaObject->pause();
@@ -309,6 +336,7 @@ void MediaView::pause() {
         mediaObject->play();
         break;
     }
+#endif
 }
 
 QRegExp MediaView::wordRE(QString s) {
@@ -332,6 +360,7 @@ void MediaView::stop() {
         downloadItem->stop();
         delete downloadItem;
         downloadItem = 0;
+        currentVideoSize = 0;
     }
     The::globalActions()->value("refine-search")->setChecked(false);
     updateSubscriptionAction(0, false);
@@ -346,8 +375,21 @@ void MediaView::stop() {
     a->setEnabled(false);
     a->setVisible(false);
 
+#ifdef APP_PHONON
     mediaObject->stop();
+#endif
     currentVideoId.clear();
+
+#ifndef APP_PHONON_SEEK
+    QSlider *slider = MainWindow::instance()->getSlider();
+    slider->setEnabled(false);
+    slider->setValue(0);
+#endif
+
+    if (snapshotSettings) {
+        delete snapshotSettings;
+        snapshotSettings = 0;
+    }
 }
 
 const QString & MediaView::getCurrentVideoId() {
@@ -359,11 +401,14 @@ void MediaView::activeRowChanged(int row) {
 
     errorTimer->stop();
 
+#ifdef APP_PHONON
     mediaObject->stop();
+#endif
     if (downloadItem) {
         downloadItem->stop();
         delete downloadItem;
         downloadItem = 0;
+        currentVideoSize = 0;
     }
 
     Video *video = playlistModel->videoAt(row);
@@ -374,7 +419,7 @@ void MediaView::activeRowChanged(int row) {
     connect(video, SIGNAL(gotStreamUrl(QUrl)),
             SLOT(gotStreamUrl(QUrl)), Qt::UniqueConnection);
     connect(video, SIGNAL(errorStreamUrl(QString)),
-            SLOT(handleError(QString)), Qt::UniqueConnection);
+            SLOT(skip()), Qt::UniqueConnection);
     video->loadStreamUrl();
 
     // video title in titlebar
@@ -390,12 +435,10 @@ void MediaView::activeRowChanged(int row) {
     // enable/disable actions
     The::globalActions()->value("download")->setEnabled(
                 DownloadManager::instance()->itemForVideo(video) == 0);
-    // The::globalActions()->value("skip")->setEnabled(true);
     The::globalActions()->value("previous")->setEnabled(row > 0);
     The::globalActions()->value("stopafterthis")->setEnabled(true);
     The::globalActions()->value("related-videos")->setEnabled(true);
 
-#ifndef APP_NO_DOWNLOADS
     bool enableDownload = video->license() == Video::LicenseCC;
 #ifdef APP_ACTIVATION
     enableDownload = enableDownload || Activation::instance().isLegacy();
@@ -406,13 +449,23 @@ void MediaView::activeRowChanged(int row) {
     QAction *a = The::globalActions()->value("download");
     a->setEnabled(enableDownload);
     a->setVisible(enableDownload);
-#endif
 
-    updateSubscriptionAction(video, YTUser::isSubscribed(video->userId()));
+    updateSubscriptionAction(video, YTChannel::isSubscribed(video->channelId()));
 
     foreach (QAction *action, currentVideoActions)
         action->setEnabled(true);
 
+#ifndef APP_PHONON_SEEK
+    QSlider *slider = MainWindow::instance()->getSlider();
+    slider->setEnabled(false);
+    slider->setValue(0);
+#endif
+
+    if (snapshotSettings) {
+        delete snapshotSettings;
+        snapshotSettings = 0;
+    }
+
     // see you in gotStreamUrl...
 }
 
@@ -432,31 +485,14 @@ void MediaView::gotStreamUrl(QUrl streamUrl) {
 
     currentVideoId = video->id();
 
-#ifdef Q_WS_X11_NO
+#ifdef APP_PHONON_SEEK
     mediaObject->setCurrentSource(streamUrl);
     mediaObject->play();
 #else
-    QString tempFile = Temporary::filename();
-    Video *videoCopy = video->clone();
-    if (downloadItem) {
-        downloadItem->stop();
-        delete downloadItem;
-    }
-    downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
-    connect(downloadItem, SIGNAL(statusChanged()),
-            SLOT(downloadStatusChanged()), Qt::UniqueConnection);
-    // connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
-    connect(downloadItem, SIGNAL(bufferProgress(int)),
-            loadingWidget, SLOT(bufferStatus(int)), Qt::UniqueConnection);
-    // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
-    connect(video, SIGNAL(errorStreamUrl(QString)),
-            SLOT(handleError(QString)), Qt::UniqueConnection);
-    connect(downloadItem, SIGNAL(error(QString)),
-            SLOT(handleError(QString)), Qt::UniqueConnection);
-    downloadItem->start();
+    startDownloading();
 #endif
 
-    // ensure we always have 10 videos ahead
+    // ensure we always have videos ahead
     playlistModel->searchNeeded();
 
     // ensure active item is visible
@@ -472,56 +508,39 @@ void MediaView::gotStreamUrl(QUrl streamUrl) {
 #endif
 
 #ifdef APP_EXTRA
-    Extra::notify(video->title(), video->author(), video->formattedDuration());
+    Extra::notify(video->title(), video->channelTitle(), video->formattedDuration());
 #endif
 
     ChannelAggregator::instance()->videoWatched(video);
 }
 
-/*
-void MediaView::downloadProgress(int percent) {
-    MainWindow* mainWindow = dynamic_cast<MainWindow*>(window());
-
-    mainWindow->getSeekSlider()->setStyleSheet(" QSlider::groove:horizontal {"
-        "border: 1px solid #999999;"
-        // "border-left: 50px solid rgba(255, 0, 0, 128);"
-        "height: 8px;"
-        "background: qlineargradient(x1:0, y1:0, x2:.5, y2:0, stop:0 rgba(255, 0, 0, 92), stop:"
-        + QString::number(percent/100.0) +
-
-        " rgba(255, 0, 0, 92), stop:" + QString::number((percent+1)/100.0) + " transparent, stop:1 transparent);"
-        "margin: 2px 0;"
-    "}"
-    "QSlider::handle:horizontal {"
-        "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);"
-        "border: 1px solid #5c5c5c;"
-        "width: 16px;"
-        "height: 16px;"
-        "margin: -2px 0;"
-        "border-radius: 8px;"
-    "}"
-
-    );
-}
-*/
-
 void MediaView::downloadStatusChanged() {
+    // qDebug() << __PRETTY_FUNCTION__;
     switch(downloadItem->status()) {
     case Downloading:
-        startPlaying();
+        // qDebug() << "Downloading";
+        if (downloadItem->offset() == 0) startPlaying();
+        else {
+#ifdef APP_PHONON
+            // qDebug() << "Seeking to" << downloadItem->offset();
+            mediaObject->seek(offsetToTime(downloadItem->offset()));
+            mediaObject->play();
+#endif
+        }
         break;
     case Starting:
         // qDebug() << "Starting";
         break;
     case Finished:
         // qDebug() << "Finished" << mediaObject->state();
-        // if (mediaObject->state() == Phonon::StoppedState) startPlaying();
-#ifdef Q_WS_X11
+#ifdef APP_PHONON_SEEK
         MainWindow::instance()->getSeekSlider()->setEnabled(mediaObject->isSeekable());
 #endif
         break;
     case Failed:
         // qDebug() << "Failed";
+        skip();
+        break;
     case Idle:
         // qDebug() << "Idle";
         break;
@@ -529,21 +548,31 @@ void MediaView::downloadStatusChanged() {
 }
 
 void MediaView::startPlaying() {
+    // qDebug() << __PRETTY_FUNCTION__;
     if (stopped) return;
     if (!downloadItem) {
         skip();
         return;
     }
 
+    if (downloadItem->offset() == 0) {
+        currentVideoSize = downloadItem->bytesTotal();
+        // qDebug() << "currentVideoSize" << currentVideoSize;
+    }
+
     // go!
     QString source = downloadItem->currentFilename();
-    // qDebug() << "Playing" << source;
-    mediaObject->setCurrentSource(source);
+    qDebug() << "Playing" << source << QFile::exists(source);
+#ifdef APP_PHONON
+    mediaObject->setCurrentSource(QUrl::fromLocalFile(source));
     mediaObject->play();
-#ifdef Q_WS_X11
+#endif
+#ifdef APP_PHONON_SEEK
     MainWindow::instance()->getSeekSlider()->setEnabled(false);
+#else
+    QSlider *slider = MainWindow::instance()->getSlider();
+    slider->setEnabled(true);
 #endif
-
 }
 
 void MediaView::itemActivated(const QModelIndex &index) {
@@ -553,8 +582,11 @@ void MediaView::itemActivated(const QModelIndex &index) {
         Video *activeVideo = playlistModel->activeVideo();
         Video *video = playlistModel->videoAt(index.row());
         if (activeVideo && video && activeVideo == video) {
-            mediaObject->seek(0);
+            // mediaObject->seek(0);
+            sliderMoved(0);
+#ifdef APP_PHONON
             mediaObject->play();
+#endif
         } else playlistModel->setActiveRow(index.row());
 
         // the user doubleclicked on the "Search More" item
@@ -593,21 +625,24 @@ void MediaView::skipBackward() {
 }
 
 void MediaView::aboutToFinish() {
+#ifdef APP_PHONON
     qint64 currentTime = mediaObject->currentTime();
     qint64 totalTime = mediaObject->totalTime();
     qDebug() << __PRETTY_FUNCTION__ << currentTime << totalTime;
     if (totalTime < 1 || currentTime + 10000 < totalTime) {
-        // mediaObject->seek(mediaObject->currentTime());
         // QTimer::singleShot(500, this, SLOT(playbackResume()));
         mediaObject->seek(currentTime);
         mediaObject->play();
     }
+#endif
 }
 
 void MediaView::playbackFinished() {
     if (stopped) return;
-    const int totalTime = mediaObject->totalTime();
-    const int currentTime = mediaObject->currentTime();
+
+#ifdef APP_PHONON
+    const qint64 totalTime = mediaObject->totalTime();
+    const qint64 currentTime = mediaObject->currentTime();
     qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime() << totalTime;
     // add 10 secs for imprecise Phonon backends (VLC, Xine)
     if (totalTime < 1 || (currentTime > 0 && currentTime + 10000 < totalTime)) {
@@ -619,26 +654,33 @@ void MediaView::playbackFinished() {
             stopAfterThisAction->setChecked(false);
         } else skip();
     }
+#endif
 }
 
 void MediaView::playbackResume() {
     if (stopped) return;
-    qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
-    mediaObject->seek(mediaObject->currentTime());
+#ifdef APP_PHONON
+    const qint64 currentTime = mediaObject->currentTime();
+    qDebug() << __PRETTY_FUNCTION__ << currentTime;
+    if (currentTime > 0)
+        mediaObject->seek(currentTime);
     mediaObject->play();
+#endif
 }
 
 void MediaView::openWebPage() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
+#ifdef APP_PHONON
     mediaObject->pause();
+#endif
     QDesktopServices::openUrl(video->webpage());
 }
 
 void MediaView::copyWebPage() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
-    QString address = video->webpage().toString();
+    QString address = video->webpage();
     QApplication::clipboard()->setText(address);
     QString message = tr("You can now paste the YouTube link into another application");
     MainWindow::instance()->showMessage(message);
@@ -653,6 +695,15 @@ void MediaView::copyVideoLink() {
     MainWindow::instance()->showMessage(message);
 }
 
+void MediaView::openInBrowser() {
+    Video* video = playlistModel->activeVideo();
+    if (!video) return;
+#ifdef APP_PHONON
+    mediaObject->pause();
+#endif
+    QDesktopServices::openUrl(video->getStreamUrl());
+}
+
 void MediaView::removeSelected() {
     if (!playlistView->selectionModel()->hasSelection()) return;
     QModelIndexList indexes = playlistView->selectionModel()->selectedIndexes();
@@ -722,8 +773,10 @@ void MediaView::saveSplitterState() {
 static QPushButton *continueButton;
 
 void MediaView::demoMessage() {
+#ifdef APP_PHONON
     if (mediaObject->state() != Phonon::PlayingState) return;
     mediaObject->pause();
+#endif
 
     QMessageBox msgBox(this);
     msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
@@ -748,7 +801,9 @@ void MediaView::demoMessage() {
     if (msgBox.clickedButton() == buyButton) {
         MainWindow::instance()->showActivationView();
     } else {
+#ifdef APP_PHONON
         mediaObject->play();
+#endif
         demoTimer->start(600000);
     }
 
@@ -776,68 +831,112 @@ void MediaView::downloadVideo() {
     MainWindow::instance()->showMessage(message);
 }
 
-/*
+#ifdef APP_SNAPSHOT
 void MediaView::snapshot() {
+    qint64 currentTime = mediaObject->currentTime() / 1000;
+
     QImage image = videoWidget->snapshot();
-    qDebug() << image.size();
+    if (image.isNull()) {
+        qWarning() << "Null snapshot";
+        return;
+    }
 
-    const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId());
-    // qDebug() << pixmap.size();
+    // QPixmap pixmap = QPixmap::grabWindow(videoWidget->winId());
+    QPixmap pixmap = QPixmap::fromImage(image.scaled(videoWidget->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
     videoAreaWidget->showSnapshotPreview(pixmap);
+
+    Video* video = playlistModel->activeVideo();
+    if (!video) return;
+
+    QString location = SnapshotSettings::getCurrentLocation();
+    QDir dir(location);
+    if (!dir.exists()) dir.mkpath(location);
+    QString basename = video->title();
+    QString format = video->duration() > 3600 ? "h_mm_ss" : "m_ss";
+    basename += " (" + QTime().addSecs(currentTime).toString(format) + ")";
+    basename = DataUtils::stringToFilename(basename);
+    QString filename = location + "/" + basename + ".png";
+    qDebug() << filename;
+    image.save(filename, "PNG");
+
+    if (snapshotSettings) delete snapshotSettings;
+    snapshotSettings = new SnapshotSettings(videoWidget);
+    snapshotSettings->setSnapshot(pixmap, filename);
+    QStatusBar *statusBar = MainWindow::instance()->statusBar();
+#ifdef APP_EXTRA
+    Extra::fadeInWidget(statusBar, statusBar);
+#endif
+    statusBar->clearMessage();
+    statusBar->insertPermanentWidget(0, snapshotSettings);
+    snapshotSettings->show();
 }
-*/
+#endif
 
 void MediaView::fullscreen() {
     videoAreaWidget->setParent(0);
     videoAreaWidget->showFullScreen();
 }
 
-/*
-void MediaView::setSlider(QSlider *slider) {
-    this->slider = slider;
-    // slider->setEnabled(false);
-    slider->setTracking(false);
-    // connect(slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)));
+void MediaView::startDownloading() {
+    Video *video = playlistModel->activeVideo();
+    if (!video) return;
+    Video *videoCopy = video->clone();
+    if (downloadItem) {
+        downloadItem->stop();
+        delete downloadItem;
+    }
+    QString tempFile = Temporary::filename();
+    downloadItem = new DownloadItem(videoCopy, video->getStreamUrl(), tempFile, this);
+    connect(downloadItem, SIGNAL(statusChanged()),
+            SLOT(downloadStatusChanged()), Qt::UniqueConnection);
+    connect(downloadItem, SIGNAL(bufferProgress(int)),
+            loadingWidget, SLOT(bufferStatus(int)), Qt::UniqueConnection);
+    // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
+    connect(video, SIGNAL(errorStreamUrl(QString)),
+            SLOT(handleError(QString)), Qt::UniqueConnection);
+    connect(downloadItem, SIGNAL(error(QString)),
+            SLOT(handleError(QString)), Qt::UniqueConnection);
+    downloadItem->start();
 }
 
 void MediaView::sliderMoved(int value) {
-    qDebug() << __func__;
-    int sliderPercent = (value * 100) / (slider->maximum() - slider->minimum());
-    qDebug() << slider->minimum() << value << slider->maximum();
-    if (sliderPercent <= downloadItem->currentPercent()) {
-        qDebug() << sliderPercent << downloadItem->currentPercent();
-        mediaObject->seek(value);
+#ifdef APP_PHONON
+#ifndef APP_PHONON_SEEK
+
+    if (currentVideoSize <= 0 || !downloadItem || !mediaObject->isSeekable())
+        return;
+
+    QSlider *slider = MainWindow::instance()->getSlider();
+    if (slider->isSliderDown()) return;
+
+    qint64 offset = (currentVideoSize * value) / slider->maximum();
+
+    bool needsDownload = downloadItem->needsDownload(offset);
+    if (needsDownload) {
+        if (downloadItem->isBuffered(offset)) {
+            qint64 realOffset = downloadItem->blankAtOffset(offset);
+            if (offset < currentVideoSize)
+                downloadItem->seekTo(realOffset, false);
+            mediaObject->seek(offsetToTime(offset));
+        } else {
+            mediaObject->pause();
+            downloadItem->seekTo(offset);
+        }
     } else {
-        seekTo(value);
+        // qDebug() << "simple seek";
+        mediaObject->seek(offsetToTime(offset));
     }
+#endif
+#endif
 }
 
-void MediaView::seekTo(int value) {
-    qDebug() << __func__;
-    mediaObject->pause();
-    errorTimer->stop();
-    // mediaObject->clear();
-
-    QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
-    QString tempFile = tempDir + "/minitube" + QString::number(value) + ".mp4";
-    if (!QFile::remove(tempFile)) {
-        qDebug() << "Cannot remove temp file";
-    }
-    Video *videoCopy = downloadItem->getVideo()->clone();
-    QUrl streamUrl = videoCopy->getStreamUrl();
-    streamUrl.addQueryItem("begin", QString::number(value));
-    if (downloadItem) delete downloadItem;
-    downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
-    connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
-    // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
-    downloadItem->start();
-
-    // slider->setMinimum(value);
-
+qint64 MediaView::offsetToTime(qint64 offset) {
+#ifdef APP_PHONON
+    const qint64 totalTime = mediaObject->totalTime();
+    return ((offset * totalTime) / currentVideoSize);
+#endif
 }
 
-*/
-
 void MediaView::findVideoParts() {
 
     // parts
@@ -884,7 +983,7 @@ void MediaView::findVideoParts() {
     SearchParams *searchParams = new SearchParams();
     searchParams->setTransient(true);
     searchParams->setKeywords(query);
-    searchParams->setAuthor(video->author());
+    searchParams->setChannelId(video->channelId());
 
     /*
     if (!numberAsWords) {
@@ -903,7 +1002,8 @@ void MediaView::relatedVideos() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource();
-    singleVideoSource->setVideoId(video->id());
+    singleVideoSource->setVideo(video->clone());
+    singleVideoSource->setAsyncDetails(true);
     setVideoSource(singleVideoSource);
     The::globalActions()->value("related-videos")->setEnabled(false);
 }
@@ -912,9 +1012,12 @@ void MediaView::shareViaTwitter() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     QUrl url("https://twitter.com/intent/tweet");
-    url.addQueryItem("via", "minitubeapp");
-    url.addQueryItem("text", video->title());
-    url.addQueryItem("url", video->webpage().toString());
+    {
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("via", "minitubeapp");
+        urlHelper.addQueryItem("text", video->title());
+        urlHelper.addQueryItem("url", video->webpage());
+    }
     QDesktopServices::openUrl(url);
 }
 
@@ -922,8 +1025,11 @@ void MediaView::shareViaFacebook() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     QUrl url("https://www.facebook.com/sharer.php");
-    url.addQueryItem("t", video->title());
-    url.addQueryItem("u", video->webpage().toString());
+    {
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("t", video->title());
+        urlHelper.addQueryItem("u", video->webpage());
+    }
     QDesktopServices::openUrl(url);
 }
 
@@ -931,10 +1037,13 @@ void MediaView::shareViaBuffer() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     QUrl url("http://bufferapp.com/add");
-    url.addQueryItem("via", "minitubeapp");
-    url.addQueryItem("text", video->title());
-    url.addQueryItem("url", video->webpage().toString());
-    url.addQueryItem("picture", video->thumbnailUrl());
+    {
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("via", "minitubeapp");
+        urlHelper.addQueryItem("text", video->title());
+        urlHelper.addQueryItem("url", video->webpage());
+        urlHelper.addQueryItem("picture", video->thumbnailUrl());
+    }
     QDesktopServices::openUrl(url);
 }
 
@@ -942,12 +1051,15 @@ void MediaView::shareViaEmail() {
     Video* video = playlistModel->activeVideo();
     if (!video) return;
     QUrl url("mailto:");
-    url.addQueryItem("subject", video->title());
-    QString body = video->title() + "\n" +
-            video->webpage().toString() + "\n\n" +
-            tr("Sent from %1").arg(Constants::NAME) + "\n" +
-            Constants::WEBSITE;
-    url.addQueryItem("body", body);
+    {
+        QUrlQueryHelper urlHelper(url);
+        urlHelper.addQueryItem("subject", video->title());
+        const QString body = video->title() + "\n" +
+                video->webpage() + "\n\n" +
+                tr("Sent from %1").arg(Constants::NAME) + "\n" +
+                Constants::WEBSITE;
+        urlHelper.addQueryItem("body", body);
+    }
     QDesktopServices::openUrl(url);
 }
 
@@ -955,12 +1067,12 @@ void MediaView::authorPushed(QModelIndex index) {
     Video* video = playlistModel->videoAt(index.row());
     if (!video) return;
 
-    QString channel = video->userId();
-    if (channel.isEmpty()) channel = video->author();
-    if (channel.isEmpty()) return;
+    QString channelId = video->channelId();
+    // if (channelId.isEmpty()) channelId = video->channelTitle();
+    if (channelId.isEmpty()) return;
 
     SearchParams *searchParams = new SearchParams();
-    searchParams->setAuthor(channel);
+    searchParams->setChannelId(channelId);
     searchParams->setSortBy(SearchParams::SortByNewest);
 
     // go!
@@ -976,11 +1088,11 @@ void MediaView::updateSubscriptionAction(Video *video, bool subscribed) {
         subscribeText = subscribeAction->property("originalText").toString();
         subscribeAction->setEnabled(false);
     } else if (subscribed) {
-        subscribeText = tr("Unsubscribe from %1").arg(video->author());
+        subscribeText = tr("Unsubscribe from %1").arg(video->channelTitle());
         subscribeTip = subscribeText;
         subscribeAction->setEnabled(true);
     } else {
-        subscribeText = tr("Subscribe to %1").arg(video->author());
+        subscribeText = tr("Subscribe to %1").arg(video->channelTitle());
         subscribeTip = subscribeText;
         subscribeAction->setEnabled(true);
     }
@@ -988,31 +1100,31 @@ void MediaView::updateSubscriptionAction(Video *video, bool subscribed) {
     subscribeAction->setStatusTip(subscribeTip);
 
     if (subscribed) {
-#ifdef Q_WS_X11
+#ifdef Q_OS_LINUX
         static QIcon tintedIcon;
         if (tintedIcon.isNull()) {
             QList<QSize> sizes;
             sizes << QSize(16, 16);
-            tintedIcon = Utils::tintedIcon("bookmark-new", QColor(254, 240, 0), sizes);
+            tintedIcon = IconUtils::tintedIcon("bookmark-new", QColor(254, 240, 0), sizes);
         }
         subscribeAction->setIcon(tintedIcon);
 #else
-        subscribeAction->setIcon(Utils::icon("bookmark-remove"));
+        subscribeAction->setIcon(IconUtils::icon("bookmark-remove"));
 #endif
     } else {
-        subscribeAction->setIcon(Utils::icon("bookmark-new"));
+        subscribeAction->setIcon(IconUtils::icon("bookmark-new"));
     }
 
-    Utils::setupAction(subscribeAction);
+    IconUtils::setupAction(subscribeAction);
 }
 
 void MediaView::toggleSubscription() {
     Video *video = playlistModel->activeVideo();
     if (!video) return;
-    QString userId = video->userId();
+    QString userId = video->channelId();
     if (userId.isEmpty()) return;
-    bool subscribed = YTUser::isSubscribed(userId);
-    if (subscribed) YTUser::unsubscribe(userId);
-    else YTUser::subscribe(userId);
+    bool subscribed = YTChannel::isSubscribed(userId);
+    if (subscribed) YTChannel::unsubscribe(userId);
+    else YTChannel::subscribe(userId);
     updateSubscriptionAction(video, !subscribed);
 }