#include "MediaView.h"
+#include "playlistview.h"
#include "playlist/PrettyItemDelegate.h"
#include "networkaccess.h"
#include "videowidget.h"
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);
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);
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);
#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
listView->setFocus();
-
QString keyword = searchParams->keywords();
QString display = keyword;
if (keyword.startsWith("http://") || keyword.startsWith("https://")) {
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;
}
qDebug("loading");
break;
- default:
- ;
}
}
QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(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();
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...
}
}
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 */ ) {
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() {
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);
+}