+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube. If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
#include "mediaview.h"
+#include "playlistmodel.h"
#include "playlistview.h"
-#include "playlistitemdelegate.h"
+#include "loadingwidget.h"
+#include "videoareawidget.h"
#include "networkaccess.h"
-#include "videowidget.h"
#include "minisplitter.h"
#include "constants.h"
#include "downloadmanager.h"
#include "downloaditem.h"
#include "mainwindow.h"
#include "temporary.h"
-#include "sidebarwidget.h"
-#include "playlistwidget.h"
#include "refinesearchwidget.h"
#include "sidebarwidget.h"
-#ifdef APP_MAC
-#include "macfullscreen.h"
-#endif
+#include "sidebarheader.h"
#ifdef APP_ACTIVATION
#include "activation.h"
#endif
+#ifdef APP_EXTRA
+#include "extra.h"
+#endif
+#include "videosource.h"
+#include "ytsearch.h"
+#include "searchparams.h"
+#include "ytsinglevideosource.h"
+#include "channelaggregator.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();
-}
-
-namespace The {
-QMap<QString, QAction*>* globalActions();
-QMap<QString, QMenu*>* globalMenus();
+QHash<QString, QAction*>* globalActions();
+QHash<QString, QMenu*>* globalMenus();
QNetworkAccessManager* networkAccessManager();
}
-MediaView::MediaView(QWidget *parent) : QWidget(parent) {
+MediaView* MediaView::instance() {
+ static MediaView *i = new MediaView();
+ return i;
+}
- reallyStopped = false;
- downloadItem = 0;
+MediaView::MediaView(QWidget *parent) : View(parent)
+ , stopped(false)
+ , downloadItem(0)
+ #ifdef APP_SNAPSHOT
+ , snapshotSettings(0)
+ #endif
+ , pauseTime(0)
+{ }
- QBoxLayout *layout = new QVBoxLayout();
+void MediaView::initialize() {
+ QBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
- splitter = new MiniSplitter(this);
- splitter->setChildrenCollapsible(false);
-
- listView = new PlaylistView(this);
- listView->setItemDelegate(new PlaylistItemDelegate(this));
- listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
-
- // dragndrop
- listView->setDragEnabled(true);
- listView->setAcceptDrops(true);
- listView->setDropIndicatorShown(true);
- listView->setDragDropMode(QAbstractItemView::DragDrop);
-
- // cosmetics
- listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- listView->setFrameShape( QFrame::NoFrame );
- listView->setAttribute(Qt::WA_MacShowFocusRect, false);
- listView->setMinimumSize(320,240);
- listView->setUniformItemSizes(true);
+ splitter = new MiniSplitter();
+ playlistView = new PlaylistView(this);
// respond to the user doubleclicking a playlist item
- connect(listView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
+ connect(playlistView, SIGNAL(activated(const QModelIndex &)),
+ SLOT(itemActivated(const QModelIndex &)));
- listModel = new ListModel(this);
- connect(listModel, SIGNAL(activeRowChanged(int)), this, SLOT(activeRowChanged(int)));
+ playlistModel = new PlaylistModel();
+ connect(playlistModel, SIGNAL(activeRowChanged(int)),
+ SLOT(activeRowChanged(int)));
// needed to restore the selection after dragndrop
- connect(listModel, SIGNAL(needSelectionFor(QList<Video*>)), this, SLOT(selectVideos(QList<Video*>)));
- listView->setModel(listModel);
+ connect(playlistModel, SIGNAL(needSelectionFor(QList<Video*>)),
+ SLOT(selectVideos(QList<Video*>)));
+ playlistView->setModel(playlistModel);
- connect(listView->selectionModel(),
- SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )),
- this, SLOT(selectionChanged ( const QItemSelection & , const QItemSelection & )));
+ connect(playlistView->selectionModel(),
+ SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+ SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));
- connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
+ connect(playlistView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
sidebar = new SidebarWidget(this);
- sidebar->setPlaylist(listView);
+ sidebar->setPlaylist(playlistView);
connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
SLOT(searchAgain()));
- connect(listModel, SIGNAL(haveSuggestions(const QStringList &)),
+ 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);
+ // videoAreaWidget->setMinimumSize(320,240);
+
+#ifdef APP_PHONON
videoWidget = new Phonon::VideoWidget(this);
videoAreaWidget->setVideoWidget(videoWidget);
- videoAreaWidget->setListModel(listModel);
+#endif
+ videoAreaWidget->setListModel(playlistModel);
loadingWidget = new LoadingWidget(this);
videoAreaWidget->setLoadingWidget(loadingWidget);
splitter->addWidget(videoAreaWidget);
- layout->addWidget(splitter);
- setLayout(layout);
-
- splitter->setStretchFactor(0, 1);
- splitter->setStretchFactor(1, 6);
+ splitter->setStretchFactor(0, 0);
+ splitter->setStretchFactor(1, 8);
// restore splitter state
QSettings settings;
splitter->restoreState(settings.value("splitter").toByteArray());
+ splitter->setChildrenCollapsible(false);
+ connect(splitter, SIGNAL(splitterMoved(int,int)), SLOT(maybeAdjustWindowSize()));
+
+ layout->addWidget(splitter);
errorTimer = new QTimer(this);
errorTimer->setSingleShot(true);
errorTimer->setInterval(3000);
connect(errorTimer, SIGNAL(timeout()), SLOT(skipVideo()));
- workaroundTimer = new QTimer(this);
- workaroundTimer->setSingleShot(true);
- workaroundTimer->setInterval(3000);
- connect(workaroundTimer, SIGNAL(timeout()), SLOT(timerPlay()));
-
#ifdef APP_ACTIVATION
demoTimer = new QTimer(this);
demoTimer->setSingleShot(true);
connect(demoTimer, SIGNAL(timeout()), SLOT(demoMessage()));
#endif
-}
-
-void MediaView::initialize() {
- connect(videoAreaWidget, SIGNAL(doubleClicked()), The::globalActions()->value("fullscreen"), SLOT(trigger()));
-
- /*
- videoAreaWidget->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(videoAreaWidget, SIGNAL(customContextMenuRequested(QPoint)),
- this, SLOT(showVideoContextMenu(QPoint)));
- */
+ connect(videoAreaWidget, SIGNAL(doubleClicked()),
+ The::globalActions()->value("fullscreen"), SLOT(trigger()));
QAction* refineSearchAction = The::globalActions()->value("refine-search");
connect(refineSearchAction, SIGNAL(toggled(bool)),
sidebar, SLOT(toggleRefineSearch(bool)));
+
+ currentVideoActions
+ << 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("stopafterthis")
+ << The::globalActions()->value("related-videos")
+ << The::globalActions()->value("refine-search")
+ << The::globalActions()->value("twitter")
+ << 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(this->mediaObject, videoWidget);
- connect(mediaObject, SIGNAL(finished()), this, SLOT(playbackFinished()));
+ Phonon::createPath(mediaObject, videoWidget);
+ connect(mediaObject, SIGNAL(finished()), SLOT(playbackFinished()));
connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
- this, SLOT(stateChanged(Phonon::State, Phonon::State)));
- connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
- this, SLOT(currentSourceChanged(Phonon::MediaSource)));
- // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
+ SLOT(stateChanged(Phonon::State, Phonon::State)));
connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish()));
}
+#endif
+
+SearchParams* MediaView::getSearchParams() {
+ VideoSource *videoSource = playlistModel->getVideoSource();
+ if (videoSource && videoSource->metaObject()->className() == QLatin1String("YTSearch")) {
+ YTSearch *search = qobject_cast<YTSearch *>(videoSource);
+ return search->getSearchParams();
+ }
+ return 0;
+}
void MediaView::search(SearchParams *searchParams) {
- reallyStopped = false;
+ if (!searchParams->keywords().isEmpty()) {
+ if (searchParams->keywords().startsWith("http://") ||
+ searchParams->keywords().startsWith("https://")) {
+ QString videoId = YTSearch::videoIdFromUrl(searchParams->keywords());
+ if (!videoId.isEmpty()) {
+ YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource(this);
+ singleVideoSource->setVideoId(videoId);
+ setVideoSource(singleVideoSource);
+ return;
+ }
+ }
+ }
+ 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, bool back) {
+ Q_UNUSED(back);
+ stopped = false;
#ifdef APP_ACTIVATION
demoTimer->stop();
#endif
- workaroundTimer->stop();
errorTimer->stop();
- this->searchParams = searchParams;
-
- // start serching for videos
- listModel->search(searchParams);
-
- sidebar->showPlaylist();
- listView->setFocus();
-
- QString keyword = searchParams->keywords();
- QString display = keyword;
- if (keyword.startsWith("http://") || keyword.startsWith("https://")) {
- int separator = keyword.indexOf("|");
- if (separator > 0 && separator + 1 < keyword.length()) {
- display = keyword.mid(separator+1);
+ // qDebug() << "Adding VideoSource" << videoSource->getName() << videoSource;
+
+ if (addToHistory) {
+ int currentIndex = getHistoryIndex();
+ if (currentIndex >= 0 && currentIndex < history.size() - 1) {
+ while (history.size() > currentIndex + 1) {
+ VideoSource *vs = history.takeLast();
+ if (!vs->parent()) {
+ qDebug() << "Deleting VideoSource" << vs->getName() << vs;
+ delete vs;
+ }
+ }
}
+ history.append(videoSource);
}
- sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
+#ifdef APP_EXTRA
+ if (history.size() > 1)
+ Extra::slideTransition(playlistView->viewport(), playlistView->viewport(), back);
+#endif
+
+ playlistModel->setVideoSource(videoSource);
+
+ sidebar->showPlaylist();
+ sidebar->getRefineSearchWidget()->setSearchParams(getSearchParams());
sidebar->hideSuggestions();
+ sidebar->getHeader()->updateInfo();
+
+ SearchParams *searchParams = getSearchParams();
+ bool isChannel = searchParams && !searchParams->channelId().isEmpty();
+ playlistView->setClickableAuthors(!isChannel);
+
}
void MediaView::searchAgain() {
- search(searchParams);
+ VideoSource *currentVideoSource = playlistModel->getVideoSource();
+ setVideoSource(currentVideoSource, false);
}
-void MediaView::appear() {
- listView->setFocus();
+bool MediaView::canGoBack() {
+ return getHistoryIndex() > 0;
}
-void MediaView::disappear() {
- timerPlayFlag = true;
+void MediaView::goBack() {
+ if (history.size() > 1) {
+ int currentIndex = getHistoryIndex();
+ if (currentIndex > 0) {
+ VideoSource *previousVideoSource = history.at(currentIndex - 1);
+ setVideoSource(previousVideoSource, false, true);
+ }
+ }
}
-void MediaView::handleError(QString /* message */) {
+bool MediaView::canGoForward() {
+ int currentIndex = getHistoryIndex();
+ return currentIndex >= 0 && currentIndex < history.size() - 1;
+}
- QTimer::singleShot(500, this, SLOT(startPlaying()));
+void MediaView::goForward() {
+ if (canGoForward()) {
+ int currentIndex = getHistoryIndex();
+ VideoSource *nextVideoSource = history.at(currentIndex + 1);
+ setVideoSource(nextVideoSource, false);
+ }
+}
- /*
- videoAreaWidget->showError(message);
- skippedVideo = listModel->activeVideo();
- // recover from errors by skipping to the next video
- errorTimer->start(2000);
- */
+int MediaView::getHistoryIndex() {
+ return history.lastIndexOf(playlistModel->getVideoSource());
}
-void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
- // qDebug() << "Phonon state: " << newState;
- // slider->setEnabled(newState == Phonon::PlayingState);
+void MediaView::appear() {
+ Video *currentVideo = playlistModel->activeVideo();
+ if (currentVideo) {
+ MainWindow::instance()->setWindowTitle(
+ currentVideo->title() + " - " + Constants::NAME);
+ }
- switch (newState) {
+ // optimize window for 16:9 video
+ QTimer::singleShot(50, this, SLOT(maybeAdjustWindowSize()));
- case Phonon::ErrorState:
- qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
- if (mediaObject->errorType() == Phonon::FatalError)
- handleError(mediaObject->errorString());
- break;
+ playlistView->setFocus();
+}
- case Phonon::PlayingState:
- // qDebug("playing");
- videoAreaWidget->showVideo();
- break;
+void MediaView::disappear() {
- case Phonon::StoppedState:
- // qDebug("stopped");
- // play() has already been called when setting the source
- // but Phonon on Linux needs a little more help to start playback
- // if (!reallyStopped) mediaObject->play();
+}
-#ifdef APP_MAC
- // Workaround for Mac playback start problem
- if (!timerPlayFlag) {
- // workaroundTimer->start();
- }
+void MediaView::handleError(const QString &message) {
+ qWarning() << __PRETTY_FUNCTION__ << message;
+#ifdef APP_PHONON_SEEK
+ mediaObject->play();
+#else
+ QTimer::singleShot(500, this, SLOT(startPlaying()));
#endif
+}
- break;
-
- case Phonon::PausedState:
- qDebug("paused");
- break;
-
- case Phonon::BufferingState:
- qDebug("buffering");
- break;
-
- case Phonon::LoadingState:
- qDebug("loading");
- break;
-
+#ifdef APP_PHONON
+void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
+ if (pauseTime > 0 && (newState == Phonon::PlayingState || newState == Phonon::BufferingState)) {
+ mediaObject->seek(pauseTime);
+ pauseTime = 0;
+ }
+ if (newState == Phonon::PlayingState) {
+ videoAreaWidget->showVideo();
+ } else if (newState == Phonon::ErrorState) {
+ qWarning() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
+ if (mediaObject->errorType() == Phonon::FatalError)
+ handleError(mediaObject->errorString());
}
}
+#endif
void MediaView::pause() {
- // qDebug() << "pause() called" << mediaObject->state();
-
+#ifdef APP_PHONON
switch( mediaObject->state() ) {
case Phonon::PlayingState:
mediaObject->pause();
+ pauseTimer.start();
break;
default:
- mediaObject->play();
+ if (pauseTimer.hasExpired(60000)) {
+ pauseTimer.invalidate();
+ connect(playlistModel->activeVideo(), SIGNAL(gotStreamUrl(QUrl)), SLOT(resumeWithNewStreamUrl(QUrl)));
+ playlistModel->activeVideo()->loadStreamUrl();
+ } else mediaObject->play();
break;
}
-
+#endif
}
-QRegExp MediaView::wordRE(QString s) {
+QRegExp MediaView::wordRE(const QString &s) {
return QRegExp("\\W" + s + "\\W?", Qt::CaseInsensitive);
}
void MediaView::stop() {
- listModel->abortSearch();
- reallyStopped = true;
- mediaObject->stop();
+ stopped = true;
+
+ while (!history.isEmpty()) {
+ VideoSource *videoSource = history.takeFirst();
+ if (!videoSource->parent()) delete videoSource;
+ }
+
+ playlistModel->abortSearch();
videoAreaWidget->clear();
- workaroundTimer->stop();
+ videoAreaWidget->update();
errorTimer->stop();
- listView->selectionModel()->clearSelection();
+ playlistView->selectionModel()->clearSelection();
if (downloadItem) {
downloadItem->stop();
delete downloadItem;
downloadItem = 0;
+ currentVideoSize = 0;
}
The::globalActions()->value("refine-search")->setChecked(false);
+ updateSubscriptionAction(0, false);
+#ifdef APP_ACTIVATION
+ demoTimer->stop();
+#endif
+
+ foreach (QAction *action, currentVideoActions)
+ action->setEnabled(false);
+
+ QAction *a = The::globalActions()->value("download");
+ 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);
+#else
+ Phonon::SeekSlider *slider = MainWindow::instance()->getSeekSlider();
+#endif
+
+ if (snapshotSettings) {
+ delete snapshotSettings;
+ snapshotSettings = 0;
+ }
}
-void MediaView::activeRowChanged(int row) {
- if (reallyStopped) return;
+const QString & MediaView::getCurrentVideoId() {
+ return currentVideoId;
+}
- Video *video = listModel->videoAt(row);
- if (!video) return;
+void MediaView::activeRowChanged(int row) {
+ if (stopped) return;
- // now that we have a new video to play
- // stop all the timers
- workaroundTimer->stop();
errorTimer->stop();
+#ifdef APP_PHONON
mediaObject->stop();
+#endif
if (downloadItem) {
downloadItem->stop();
delete downloadItem;
downloadItem = 0;
+ currentVideoSize = 0;
}
- // slider->setMinimum(0);
- // immediately show the loading widget
- videoAreaWidget->showLoading(video);
+ Video *video = playlistModel->videoAt(row);
+ if (!video) return;
- connect(video, SIGNAL(gotStreamUrl(QUrl)), SLOT(gotStreamUrl(QUrl)), Qt::UniqueConnection);
- // TODO handle signal in a proper slot and impl item error status
- connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString)), Qt::UniqueConnection);
+ videoAreaWidget->showLoading(video);
+ connect(video, SIGNAL(gotStreamUrl(QUrl)),
+ SLOT(gotStreamUrl(QUrl)), Qt::UniqueConnection);
+ connect(video, SIGNAL(errorStreamUrl(QString)),
+ SLOT(skip()), Qt::UniqueConnection);
video->loadStreamUrl();
- // reset the timer flag
- timerPlayFlag = false;
-
- // video title in the statusbar
- MainWindow::instance()->showMessage(video->title());
+ // video title in titlebar
+ MainWindow::instance()->setWindowTitle(video->title() + " - " + Constants::NAME);
// ensure active item is visible
- // int row = listModel->activeRow();
if (row != -1) {
- QModelIndex index = listModel->index(row, 0, QModelIndex());
- listView->scrollTo(index, QAbstractItemView::EnsureVisible);
+ QModelIndex index = playlistModel->index(row, 0, QModelIndex());
+ playlistView->scrollTo(index, QAbstractItemView::EnsureVisible);
}
// enable/disable actions
- The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0);
- The::globalActions()->value("skip")->setEnabled(true);
+ The::globalActions()->value("download")->setEnabled(
+ DownloadManager::instance()->itemForVideo(video) == 0);
The::globalActions()->value("previous")->setEnabled(row > 0);
The::globalActions()->value("stopafterthis")->setEnabled(true);
+ The::globalActions()->value("related-videos")->setEnabled(true);
- // see you in gotStreamUrl...
+ bool enableDownload = video->license() == Video::LicenseCC;
+#ifdef APP_ACTIVATION
+ enableDownload = enableDownload || Activation::instance().isLegacy();
+#endif
+#ifdef APP_DOWNLOADS
+ enableDownload = true;
+#endif
+ QAction *a = The::globalActions()->value("download");
+ a->setEnabled(enableDownload);
+ a->setVisible(enableDownload);
+
+ 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;
+ MainWindow::instance()->adjustStatusBarVisibility();
+ }
+
+ // see you in gotStreamUrl...
}
void MediaView::gotStreamUrl(QUrl streamUrl) {
- if (reallyStopped) return;
+ if (stopped) return;
+ if (!streamUrl.isValid()) {
+ skip();
+ return;
+ }
Video *video = static_cast<Video *>(sender());
if (!video) {
- qDebug() << "Cannot get sender";
+ qDebug() << "Cannot get sender in" << __PRETTY_FUNCTION__;
return;
}
video->disconnect(this);
- QString tempFile = Temporary::filename();
+ currentVideoId = video->id();
- 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();
+#ifdef APP_PHONON_SEEK
+ mediaObject->setCurrentSource(streamUrl);
+ mediaObject->play();
+#else
+ startDownloading();
+#endif
-}
+ // ensure we always have videos ahead
+ playlistModel->searchNeeded();
-/*
-void MediaView::downloadProgress(int percent) {
- MainWindow* mainWindow = dynamic_cast<MainWindow*>(window());
+ // ensure active item is visible
+ int row = playlistModel->activeRow();
+ if (row != -1) {
+ QModelIndex index = playlistModel->index(row, 0, QModelIndex());
+ playlistView->scrollTo(index, QAbstractItemView::EnsureVisible);
+ }
- 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) +
+#ifdef APP_ACTIVATION
+ if (!Activation::instance().isActivated())
+ demoTimer->start(180000);
+#endif
- " 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;"
- "}"
+#ifdef APP_EXTRA
+ Extra::notify(video->title(), video->channelTitle(), video->formattedDuration());
+#endif
- );
+ ChannelAggregator::instance()->videoWatched(video);
}
-*/
-
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
- seekSlider->setEnabled(mediaObject->isSeekable());
+#ifdef APP_PHONON_SEEK
+ MainWindow::instance()->getSeekSlider()->setEnabled(mediaObject->isSeekable());
#endif
break;
case Failed:
// qDebug() << "Failed";
+ skip();
+ break;
case Idle:
// qDebug() << "Idle";
break;
}
void MediaView::startPlaying() {
- if (reallyStopped) return;
+ // 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
- seekSlider->setEnabled(false);
#endif
-
- // ensure we always have 10 videos ahead
- listModel->searchNeeded();
-
- // ensure active item is visible
- int row = listModel->activeRow();
- if (row != -1) {
- QModelIndex index = listModel->index(row, 0, QModelIndex());
- listView->scrollTo(index, QAbstractItemView::EnsureVisible);
- }
-
-#ifdef APP_ACTIVATION
- if (!Activation::instance().isActivated())
- demoTimer->start(180000);
+#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) {
- if (listModel->rowExists(index.row())) {
+ if (playlistModel->rowExists(index.row())) {
// if it's the current video, just rewind and play
- Video *activeVideo = listModel->activeVideo();
- Video *video = listModel->videoAt(index.row());
+ 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();
- } else listModel->setActiveRow(index.row());
+#endif
+ } else playlistModel->setActiveRow(index.row());
- // the user doubleclicked on the "Search More" item
+ // the user doubleclicked on the "Search More" item
} else {
- listModel->searchMore();
- listView->selectionModel()->clearSelection();
+ playlistModel->searchMore();
+ playlistView->selectionModel()->clearSelection();
}
}
-void MediaView::currentSourceChanged(const Phonon::MediaSource /* source */ ) {
-
-}
-
void MediaView::skipVideo() {
// skippedVideo is useful for DELAYED skip operations
// in order to be sure that we're skipping the video we wanted
// and not another one
if (skippedVideo) {
- if (listModel->activeVideo() != skippedVideo) {
+ if (playlistModel->activeVideo() != skippedVideo) {
qDebug() << "Skip of video canceled";
return;
}
- int nextRow = listModel->rowForVideo(skippedVideo);
+ int nextRow = playlistModel->rowForVideo(skippedVideo);
nextRow++;
if (nextRow == -1) return;
- listModel->setActiveRow(nextRow);
+ playlistModel->setActiveRow(nextRow);
}
}
void MediaView::skip() {
- int nextRow = listModel->nextRow();
+ int nextRow = playlistModel->nextRow();
if (nextRow == -1) return;
- listModel->setActiveRow(nextRow);
+ playlistModel->setActiveRow(nextRow);
}
void MediaView::skipBackward() {
- int prevRow = listModel->previousRow();
+ int prevRow = playlistModel->previousRow();
if (prevRow == -1) return;
- listModel->setActiveRow(prevRow);
+ playlistModel->setActiveRow(prevRow);
}
void MediaView::aboutToFinish() {
+#ifdef APP_PHONON
qint64 currentTime = mediaObject->currentTime();
- qDebug() << __PRETTY_FUNCTION__ << currentTime;
- if (currentTime + 10000 < mediaObject->totalTime()) {
- // mediaObject->seek(mediaObject->currentTime());
+ qint64 totalTime = mediaObject->totalTime();
+ qDebug() << __PRETTY_FUNCTION__ << currentTime << totalTime;
+ if (totalTime < 1 || currentTime + 10000 < totalTime) {
// QTimer::singleShot(500, this, SLOT(playbackResume()));
mediaObject->seek(currentTime);
mediaObject->play();
}
+#endif
}
void MediaView::playbackFinished() {
- qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
- // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime();
+ if (stopped) return;
+
+#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 (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) {
- // mediaObject->seek(mediaObject->currentTime());
+ if (currentTime > 0 && currentTime + 10000 < totalTime) {
+ // mediaObject->seek(currentTime);
QTimer::singleShot(500, this, SLOT(playbackResume()));
} else {
QAction* stopAfterThisAction = The::globalActions()->value("stopafterthis");
stopAfterThisAction->setChecked(false);
} else skip();
}
+#endif
}
void MediaView::playbackResume() {
- qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
- mediaObject->seek(mediaObject->currentTime());
+ if (stopped) return;
+#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 = listModel->activeVideo();
+ Video* video = playlistModel->activeVideo();
if (!video) return;
+#ifdef APP_PHONON
mediaObject->pause();
- QDesktopServices::openUrl(video->webpage());
+#endif
+ QString url = video->webpage() + QLatin1String("&t=") + QString::number(mediaObject->currentTime() / 1000);
+ QDesktopServices::openUrl(url);
}
void MediaView::copyWebPage() {
- Video* video = listModel->activeVideo();
+ 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);
}
void MediaView::copyVideoLink() {
- Video* video = listModel->activeVideo();
+ Video* video = playlistModel->activeVideo();
if (!video) return;
QApplication::clipboard()->setText(video->getStreamUrl().toEncoded());
QString message = tr("You can now paste the video stream URL into another application")
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 (!listView->selectionModel()->hasSelection()) return;
- QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
- listModel->removeIndexes(indexes);
+ if (!playlistView->selectionModel()->hasSelection()) return;
+ QModelIndexList indexes = playlistView->selectionModel()->selectedIndexes();
+ playlistModel->removeIndexes(indexes);
}
void MediaView::selectVideos(QList<Video*> videos) {
foreach (Video *video, videos) {
- QModelIndex index = listModel->indexForVideo(video);
- listView->selectionModel()->select(index, QItemSelectionModel::Select);
- listView->scrollTo(index, QAbstractItemView::EnsureVisible);
+ QModelIndex index = playlistModel->indexForVideo(video);
+ playlistView->selectionModel()->select(index, QItemSelectionModel::Select);
+ playlistView->scrollTo(index, QAbstractItemView::EnsureVisible);
}
}
-void MediaView::selectionChanged(const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/) {
- const bool gotSelection = listView->selectionModel()->hasSelection();
+void MediaView::selectionChanged(const QItemSelection & /*selected*/,
+ const QItemSelection & /*deselected*/) {
+ const bool gotSelection = playlistView->selectionModel()->hasSelection();
The::globalActions()->value("remove")->setEnabled(gotSelection);
The::globalActions()->value("moveUp")->setEnabled(gotSelection);
The::globalActions()->value("moveDown")->setEnabled(gotSelection);
}
void MediaView::moveUpSelected() {
- if (!listView->selectionModel()->hasSelection()) return;
+ if (!playlistView->selectionModel()->hasSelection()) return;
- QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+ QModelIndexList indexes = playlistView->selectionModel()->selectedIndexes();
qStableSort(indexes.begin(), indexes.end());
- listModel->move(indexes, true);
+ playlistModel->move(indexes, true);
// set current index after row moves to something more intuitive
int row = indexes.first().row();
- listView->selectionModel()->setCurrentIndex(listModel->index(row>1?row:1), QItemSelectionModel::NoUpdate);
+ playlistView->selectionModel()->setCurrentIndex(playlistModel->index(row>1?row:1),
+ QItemSelectionModel::NoUpdate);
}
void MediaView::moveDownSelected() {
- if (!listView->selectionModel()->hasSelection()) return;
+ if (!playlistView->selectionModel()->hasSelection()) return;
- QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+ QModelIndexList indexes = playlistView->selectionModel()->selectedIndexes();
qStableSort(indexes.begin(), indexes.end(), qGreater<QModelIndex>());
- listModel->move(indexes, false);
-
- // set current index after row moves to something more intuitive (respect 1 static item on bottom)
- int row = indexes.first().row()+1, max = listModel->rowCount() - 2;
- listView->selectionModel()->setCurrentIndex(listModel->index(row>max?max:row), QItemSelectionModel::NoUpdate);
-}
+ playlistModel->move(indexes, false);
-void MediaView::showVideoContextMenu(QPoint point) {
- The::globalMenus()->value("video")->popup(videoWidget->mapToGlobal(point));
-}
-
-void MediaView::searchMostRelevant() {
- searchParams->setSortBy(SearchParams::SortByRelevance);
- search(searchParams);
-}
-
-void MediaView::searchMostRecent() {
- searchParams->setSortBy(SearchParams::SortByNewest);
- search(searchParams);
-}
-
-void MediaView::searchMostViewed() {
- searchParams->setSortBy(SearchParams::SortByViewCount);
- search(searchParams);
+ // set current index after row moves to something more intuitive
+ // (respect 1 static item on bottom)
+ int row = indexes.first().row()+1, max = playlistModel->rowCount() - 2;
+ playlistView->selectionModel()->setCurrentIndex(
+ playlistModel->index(row>max?max:row), QItemSelectionModel::NoUpdate);
}
void MediaView::setPlaylistVisible(bool visible) {
if (splitter->widget(0)->isVisible() == visible) return;
splitter->widget(0)->setVisible(visible);
- listView->setFocus();
+ playlistView->setFocus();
}
bool MediaView::isPlaylistVisible() {
return splitter->widget(0)->isVisible();
}
-void MediaView::timerPlay() {
- // Workaround Phonon bug on Mac OSX
- // qDebug() << mediaObject->currentTime();
- if (mediaObject->currentTime() <= 0 && mediaObject->state() == Phonon::PlayingState) {
- // qDebug() << "Mac playback workaround";
- mediaObject->pause();
- // QTimer::singleShot(1000, mediaObject, SLOT(play()));
- mediaObject->play();
- }
-}
-
void MediaView::saveSplitterState() {
QSettings settings;
settings.setValue("splitter", splitter->saveState());
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));
+ msgBox.setIconPixmap(IconUtils::pixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::NAME));
msgBox.setInformativeText(tr("It allows you to test the application and see if it works for you."));
msgBox.setModal(true);
if (msgBox.clickedButton() == buyButton) {
MainWindow::instance()->showActivationView();
} else {
+#ifdef APP_PHONON
mediaObject->play();
+#endif
demoTimer->start(600000);
}
#endif
void MediaView::downloadVideo() {
- Video* video = listModel->activeVideo();
+ Video* video = playlistModel->activeVideo();
if (!video) return;
DownloadManager::instance()->addItem(video);
- The::globalActions()->value("downloads")->setVisible(true);
+ MainWindow::instance()->showActionInStatusBar(The::globalActions()->value("downloads"), true);
QString message = tr("Downloading %1").arg(video->title());
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->insertPermanentWidget(0, snapshotSettings);
+ snapshotSettings->show();
+ MainWindow::instance()->setStatusBarVisibility(true);
}
+#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);
- } else {
- seekTo(value);
+void MediaView::resumeWithNewStreamUrl(const QUrl &streamUrl) {
+ pauseTime = mediaObject->currentTime();
+ mediaObject->setCurrentSource(streamUrl);
+ mediaObject->play();
+
+ Video *video = static_cast<Video *>(sender());
+ if (!video) {
+ qDebug() << "Cannot get sender in" << __PRETTY_FUNCTION__;
+ return;
}
+ video->disconnect(this);
}
-void MediaView::seekTo(int value) {
- qDebug() << __func__;
- mediaObject->pause();
- workaroundTimer->stop();
- 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();
+void MediaView::maybeAdjustWindowSize() {
+ QSettings settings;
+ if (settings.value("adjustWindowSize", true).toBool())
+ adjustWindowSize();
+}
+
+void MediaView::sliderMoved(int value) {
+ Q_UNUSED(value);
+#ifdef APP_PHONON
+#ifndef APP_PHONON_SEEK
- // slider->setMinimum(value);
+ 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 {
+ // qDebug() << "simple seek";
+ mediaObject->seek(offsetToTime(offset));
+ }
+#endif
+#endif
}
-*/
+qint64 MediaView::offsetToTime(qint64 offset) {
+#ifdef APP_PHONON
+ const qint64 totalTime = mediaObject->totalTime();
+ return ((offset * totalTime) / currentVideoSize);
+#endif
+}
void MediaView::findVideoParts() {
// parts
- Video* video = listModel->activeVideo();
+ Video* video = playlistModel->activeVideo();
if (!video) return;
QString query = video->title();
static QString counterNumber = "([1-9]|1[0-5])";
// query.remove(QRegExp(counterSeparators + optionalSpace + counterNumber));
- query.remove(QRegExp(counterNumber + optionalSpace + counterSeparators + optionalSpace + counterNumber));
+ query.remove(QRegExp(counterNumber + optionalSpace +
+ counterSeparators + optionalSpace + counterNumber));
query.remove(wordRE("pr?t\\.?" + optionalSpace + counterNumber));
query.remove(wordRE("ep\\.?" + optionalSpace + counterNumber));
query.remove(wordRE("part" + optionalSpace + counterNumber));
query.remove(wordRE("episode" + optionalSpace + counterNumber));
query.remove(wordRE(tr("part", "This is for video parts, as in 'Cool video - part 1'") +
optionalSpace + counterNumber));
- query.remove(wordRE(tr("episode", "This is for video parts, as in 'Cool series - episode 1'") +
+ query.remove(wordRE(tr("episode",
+ "This is for video parts, as in 'Cool series - episode 1'") +
optionalSpace + counterNumber));
query.remove(QRegExp("[\\(\\)\\[\\]]"));
#define NUMBERS "one|two|three|four|five|six|seven|eight|nine|ten"
- QRegExp englishNumberRE = QRegExp(QLatin1String(".*(") + NUMBERS + ").*", Qt::CaseInsensitive);
+ QRegExp englishNumberRE = QRegExp(QLatin1String(".*(") + NUMBERS + ").*",
+ Qt::CaseInsensitive);
// bool numberAsWords = englishNumberRE.exactMatch(query);
query.remove(englishNumberRE);
- QRegExp localizedNumberRE = QRegExp(QLatin1String(".*(") + tr(NUMBERS) + ").*", Qt::CaseInsensitive);
+ QRegExp localizedNumberRE = QRegExp(QLatin1String(".*(") + tr(NUMBERS) + ").*",
+ Qt::CaseInsensitive);
// if (!numberAsWords) numberAsWords = localizedNumberRE.exactMatch(query);
query.remove(localizedNumberRE);
SearchParams *searchParams = new SearchParams();
searchParams->setTransient(true);
searchParams->setKeywords(query);
- searchParams->setAuthor(video->author());
+ searchParams->setChannelId(video->channelId());
/*
if (!numberAsWords) {
}
+void MediaView::relatedVideos() {
+ Video* video = playlistModel->activeVideo();
+ if (!video) return;
+ YTSingleVideoSource *singleVideoSource = new YTSingleVideoSource();
+ singleVideoSource->setVideo(video->clone());
+ singleVideoSource->setAsyncDetails(true);
+ setVideoSource(singleVideoSource);
+ The::globalActions()->value("related-videos")->setEnabled(false);
+}
+
void MediaView::shareViaTwitter() {
- Video* video = listModel->activeVideo();
+ 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);
}
void MediaView::shareViaFacebook() {
- Video* video = listModel->activeVideo();
+ 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);
}
void MediaView::shareViaBuffer() {
- Video* video = listModel->activeVideo();
+ 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());
- if (!video->thumbnailUrls().isEmpty())
- url.addQueryItem("picture", video->thumbnailUrls().first().toString());
+ {
+ 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);
}
void MediaView::shareViaEmail() {
- Video* video = listModel->activeVideo();
+ 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);
}
void MediaView::authorPushed(QModelIndex index) {
- Video* video = listModel->videoAt(index.row());
+ Video* video = playlistModel->videoAt(index.row());
if (!video) return;
- QString channel = video->authorUri();
- 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!
search(searchParams);
}
+
+void MediaView::updateSubscriptionAction(Video *video, bool subscribed) {
+ QAction *subscribeAction = The::globalActions()->value("subscribe-channel");
+
+ QString subscribeTip;
+ QString subscribeText;
+ if (!video) {
+ subscribeText = subscribeAction->property("originalText").toString();
+ subscribeAction->setEnabled(false);
+ } else if (subscribed) {
+ subscribeText = tr("Unsubscribe from %1").arg(video->channelTitle());
+ subscribeTip = subscribeText;
+ subscribeAction->setEnabled(true);
+ } else {
+ subscribeText = tr("Subscribe to %1").arg(video->channelTitle());
+ subscribeTip = subscribeText;
+ subscribeAction->setEnabled(true);
+ }
+ subscribeAction->setText(subscribeText);
+ subscribeAction->setStatusTip(subscribeTip);
+
+ if (subscribed) {
+#ifdef APP_LINUX
+ static QIcon tintedIcon;
+ if (tintedIcon.isNull()) {
+ QList<QSize> sizes;
+ sizes << QSize(16, 16);
+ tintedIcon = IconUtils::tintedIcon("bookmark-new", QColor(254, 240, 0), sizes);
+ }
+ subscribeAction->setIcon(tintedIcon);
+#else
+ subscribeAction->setIcon(IconUtils::icon("bookmark-remove"));
+#endif
+ } else {
+ subscribeAction->setIcon(IconUtils::icon("bookmark-new"));
+ }
+
+ IconUtils::setupAction(subscribeAction);
+}
+
+void MediaView::toggleSubscription() {
+ Video *video = playlistModel->activeVideo();
+ if (!video) return;
+ QString userId = video->channelId();
+ if (userId.isEmpty()) return;
+ bool subscribed = YTChannel::isSubscribed(userId);
+ if (subscribed) {
+ YTChannel::unsubscribe(userId);
+ MainWindow::instance()->showMessage(tr("Unsubscribed from %1").arg(video->channelTitle()));
+ } else {
+ YTChannel::subscribe(userId);
+ MainWindow::instance()->showMessage(tr("Subscribed to %1").arg(video->channelTitle()));
+ }
+ updateSubscriptionAction(video, !subscribed);
+}
+
+void MediaView::adjustWindowSize() {
+ if (!MainWindow::instance()->isMaximized() && !MainWindow::instance()->isFullScreen()) {
+ const double ratio = 16. / 9.;
+ const int w = videoAreaWidget->width();
+ const int h = videoAreaWidget->height();
+ const double currentVideoRatio = (double)w / (double)h;
+ if (currentVideoRatio != ratio) {
+ if (false && currentVideoRatio > ratio) {
+ // we have vertical black bars
+ int newWidth = (MainWindow::instance()->width() - w) + (h * ratio);
+ MainWindow::instance()->resize(newWidth, MainWindow::instance()->height());
+ } else {
+ // horizontal black bars
+ int newHeight = (MainWindow::instance()->height() - h) + (w / ratio);
+ MainWindow::instance()->resize(MainWindow::instance()->width(), newHeight);
+ }
+ }
+ }
+}