X-Git-Url: https://git.sur5r.net/?p=minitube;a=blobdiff_plain;f=src%2FMediaView.cpp;h=a77fba219122456205572e7d42eb4b3f5746ccec;hp=324adfcabef2086fef94a9691fb13ceaf2fed66a;hb=3c8c537559e6bef5f019196b0989e95863ddd3ee;hpb=57c25e20a8f10a98a18dbc2b64ce55cf87d4fd7c diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 324adfc..a77fba2 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -1,4 +1,5 @@ #include "MediaView.h" +#include "playlistview.h" #include "playlist/PrettyItemDelegate.h" #include "networkaccess.h" #include "videowidget.h" @@ -24,13 +25,13 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { reallyStopped = false; downloadItem = 0; - QBoxLayout *layout = new QHBoxLayout(); + QBoxLayout *layout = new QVBoxLayout(); layout->setMargin(0); splitter = new MiniSplitter(this); splitter->setChildrenCollapsible(false); - sortBar = new THBlackBar(this); + sortBar = new SegmentedControl(this); mostRelevantAction = new QAction(tr("Most relevant"), this); QKeySequence keySequence(Qt::CTRL + Qt::Key_1); mostRelevantAction->setShortcut(keySequence); @@ -53,7 +54,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { connect(mostViewedAction, SIGNAL(triggered()), this, SLOT(searchMostViewed()), Qt::QueuedConnection); sortBar->addAction(mostViewedAction); - listView = new QListView(this); + listView = new PlaylistView(this); listView->setItemDelegate(new PrettyItemDelegate(this)); listView->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -83,6 +84,8 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), this, SLOT(selectionChanged ( const QItemSelection & , const QItemSelection & ))); + connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex))); + playlistWidget = new PlaylistWidget(this, sortBar, listView); splitter->addWidget(playlistWidget); @@ -160,17 +163,9 @@ void MediaView::search(SearchParams *searchParams) { #ifdef APP_DEMO demoTimer->stop(); #endif - - videoAreaWidget->clear(); workaroundTimer->stop(); errorTimer->stop(); - mediaObject->pause(); - if (downloadItem) { - delete downloadItem; - downloadItem = 0; - } - this->searchParams = searchParams; // start serching for videos @@ -181,7 +176,6 @@ void MediaView::search(SearchParams *searchParams) { listView->setFocus(); - QString keyword = searchParams->keywords(); QString display = keyword; if (keyword.startsWith("http://") || keyword.startsWith("https://")) { @@ -189,14 +183,14 @@ void MediaView::search(SearchParams *searchParams) { if (separator > 0 && separator + 1 < keyword.length()) { display = keyword.mid(separator+1); } - - // also hide sidebar - // playlistWidget->hide(); } - // tr("You're watching \"%1\"").arg(searchParams->keywords()) } +void MediaView::appear() { + listView->setFocus(); +} + void MediaView::disappear() { timerPlayFlag = true; } @@ -259,8 +253,6 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) qDebug("loading"); break; - default: - ; } } @@ -332,7 +324,6 @@ void MediaView::activeRowChanged(int row) { QMainWindow* mainWindow = dynamic_cast(window()); if (mainWindow) mainWindow->statusBar()->showMessage(video->title()); - The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0); // ensure active item is visible // int row = listModel->activeRow(); @@ -341,6 +332,12 @@ void MediaView::activeRowChanged(int row) { listView->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("previous")->setEnabled(row > 0); + The::globalActions()->value("stopafterthis")->setEnabled(true); + // see you in gotStreamUrl... } @@ -451,10 +448,21 @@ void MediaView::startPlaying() { } void MediaView::itemActivated(const QModelIndex &index) { - if (listModel->rowExists(index.row())) - listModel->setActiveRow(index.row()); + if (listModel->rowExists(index.row())) { + + // if it's the current video, just rewind and play + Video *activeVideo = listModel->activeVideo(); + Video *video = listModel->videoAt(index.row()); + if (activeVideo && video && activeVideo == video) { + mediaObject->seek(0); + mediaObject->play(); + } else listModel->setActiveRow(index.row()); + // the user doubleclicked on the "Search More" item - else listModel->searchMore(); + } else { + listModel->searchMore(); + listView->selectionModel()->clearSelection(); + } } void MediaView::currentSourceChanged(const Phonon::MediaSource /* source */ ) { @@ -483,13 +491,24 @@ void MediaView::skip() { listModel->setActiveRow(nextRow); } +void MediaView::skipBackward() { + int prevRow = listModel->previousRow(); + if (prevRow == -1) return; + listModel->setActiveRow(prevRow); +} + void MediaView::playbackFinished() { // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime(); // add 10 secs for imprecise Phonon backends (VLC, Xine) if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) { // mediaObject->seek(mediaObject->currentTime()); - QTimer::singleShot(3000, this, SLOT(playbackResume())); - } else skip(); + QTimer::singleShot(500, this, SLOT(playbackResume())); + } else { + QAction* stopAfterThisAction = The::globalActions()->value("stopafterthis"); + if (stopAfterThisAction->isChecked()) { + stopAfterThisAction->setChecked(false); + } else skip(); + } } void MediaView::playbackResume() { @@ -815,3 +834,18 @@ void MediaView::shareViaEmail() { url.addQueryItem("body", body); QDesktopServices::openUrl(url); } + +void MediaView::authorPushed(QModelIndex index) { + Video* video = listModel->videoAt(index.row()); + if (!video) return; + + QString channel = video->author(); + if (channel.isEmpty()) return; + + SearchParams *searchParams = new SearchParams(); + searchParams->setAuthor(channel); + searchParams->setSortBy(SearchParams::SortByNewest); + + // go! + search(searchParams); +}