#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
namespace The {
NetworkAccess* http();
splitter = new MiniSplitter(this);
splitter->setChildrenCollapsible(false);
- sortBar = new SegmentedControl(this);
- mostRelevantAction = new QAction(tr("Most relevant"), this);
- QKeySequence keySequence(Qt::CTRL + Qt::Key_1);
- mostRelevantAction->setShortcut(keySequence);
- mostRelevantAction->setStatusTip(mostRelevantAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
- addAction(mostRelevantAction);
- connect(mostRelevantAction, SIGNAL(triggered()), this, SLOT(searchMostRelevant()), Qt::QueuedConnection);
- sortBar->addAction(mostRelevantAction);
- mostRecentAction = new QAction(tr("Most recent"), this);
- keySequence = QKeySequence(Qt::CTRL + Qt::Key_2);
- mostRecentAction->setShortcut(keySequence);
- mostRecentAction->setStatusTip(mostRecentAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
- addAction(mostRecentAction);
- connect(mostRecentAction, SIGNAL(triggered()), this, SLOT(searchMostRecent()), Qt::QueuedConnection);
- sortBar->addAction(mostRecentAction);
- mostViewedAction = new QAction(tr("Most viewed"), this);
- keySequence = QKeySequence(Qt::CTRL + Qt::Key_3);
- mostViewedAction->setShortcut(keySequence);
- mostViewedAction->setStatusTip(mostViewedAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
- addAction(mostViewedAction);
- connect(mostViewedAction, SIGNAL(triggered()), this, SLOT(searchMostViewed()), Qt::QueuedConnection);
- sortBar->addAction(mostViewedAction);
-
listView = new PlaylistView(this);
listView->setItemDelegate(new PrettyItemDelegate(this));
listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
- playlistWidget = new PlaylistWidget(this, sortBar, listView);
-
- splitter->addWidget(playlistWidget);
+ sidebar = new SidebarWidget(this);
+ sidebar->setPlaylist(listView);
+ connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
+ SLOT(searchAgain()));
+ connect(listModel, SIGNAL(haveSuggestions(const QStringList &)),
+ sidebar, SLOT(showSuggestions(const QStringList &)));
+ connect(sidebar, SIGNAL(suggestionAccepted(QString)),
+ MainWindow::instance(), SLOT(startToolbarSearch(QString)));
+ splitter->addWidget(sidebar);
videoAreaWidget = new VideoAreaWidget(this);
- videoAreaWidget->setMinimumSize(320,240);
-
-#ifdef APP_MAC_NO
- // mouse autohide does not work on the Mac (no mouseMoveEvent)
+ // videoAreaWidget->setMinimumSize(320,240);
videoWidget = new Phonon::VideoWidget(this);
-#else
- videoWidget = new VideoWidget(this);
-#endif
-
videoAreaWidget->setVideoWidget(videoWidget);
videoAreaWidget->setListModel(listModel);
connect(videoAreaWidget, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(showVideoContextMenu(QPoint)));
*/
+
+ QAction* refineSearchAction = The::globalActions()->value("refine-search");
+ connect(refineSearchAction, SIGNAL(toggled(bool)),
+ sidebar, SLOT(toggleRefineSearch(bool)));
}
void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
this, SLOT(currentSourceChanged(Phonon::MediaSource)));
// connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
+ connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish()));
}
void MediaView::search(SearchParams *searchParams) {
// start serching for videos
listModel->search(searchParams);
- // this implies that the enum and the bar action order is the same
- sortBar->setCheckedAction(searchParams->sortBy()-1);
-
+ sidebar->showPlaylist();
listView->setFocus();
QString keyword = searchParams->keywords();
}
}
+ sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
+ sidebar->hideSuggestions();
+
+}
+
+void MediaView::searchAgain() {
+ search(searchParams);
}
void MediaView::appear() {
void MediaView::handleError(QString /* message */) {
- QTimer::singleShot(100, this, SLOT(startPlaying()));
+ QTimer::singleShot(500, this, SLOT(startPlaying()));
/*
videoAreaWidget->showError(message);
*/
}
-void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
-{
-
- // qDebug() << "Phonon state: " << newState << oldState;
+void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
+ // qDebug() << "Phonon state: " << newState;
// slider->setEnabled(newState == Phonon::PlayingState);
switch (newState) {
delete downloadItem;
downloadItem = 0;
}
+ The::globalActions()->value("refine-search")->setChecked(false);
}
void MediaView::activeRowChanged(int row) {
workaroundTimer->stop();
errorTimer->stop();
- mediaObject->pause();
+ mediaObject->stop();
if (downloadItem) {
downloadItem->stop();
delete downloadItem;
case Finished:
// qDebug() << "Finished" << mediaObject->state();
// if (mediaObject->state() == Phonon::StoppedState) startPlaying();
+#ifdef Q_WS_X11
+ seekSlider->setEnabled(mediaObject->isSeekable());
+#endif
break;
case Failed:
// qDebug() << "Failed";
qDebug() << "Playing" << source;
mediaObject->setCurrentSource(source);
mediaObject->play();
+#ifdef Q_WS_X11
+ seekSlider->setEnabled(false);
+#endif
// ensure we always have 10 videos ahead
listModel->searchNeeded();
listModel->setActiveRow(prevRow);
}
+void MediaView::aboutToFinish() {
+ qint64 currentTime = mediaObject->currentTime();
+ qDebug() << __PRETTY_FUNCTION__ << currentTime;
+ if (currentTime + 10000 < mediaObject->totalTime()) {
+ // mediaObject->seek(mediaObject->currentTime());
+ // QTimer::singleShot(500, this, SLOT(playbackResume()));
+ mediaObject->seek(currentTime);
+ mediaObject->play();
+ }
+}
+
void MediaView::playbackFinished() {
+ qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
// qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime();
// add 10 secs for imprecise Phonon backends (VLC, Xine)
if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) {
}
void MediaView::playbackResume() {
+ qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
mediaObject->seek(mediaObject->currentTime());
mediaObject->play();
}
}
void MediaView::setPlaylistVisible(bool visible) {
- playlistWidget->setVisible(visible);
+ if (splitter->widget(0)->isVisible() == visible) return;
+ splitter->widget(0)->setVisible(visible);
+ listView->setFocus();
+}
+
+bool MediaView::isPlaylistVisible() {
+ return splitter->widget(0)->isVisible();
}
void MediaView::timerPlay() {
if (mainWindow) mainWindow->statusBar()->showMessage(message);
}
+void MediaView::snapshot() {
+ QImage image = videoWidget->snapshot();
+ qDebug() << image.size();
+
+ const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId());
+ // qDebug() << pixmap.size();
+ videoAreaWidget->showSnapshotPreview(pixmap);
+}
+
void MediaView::fullscreen() {
videoAreaWidget->setParent(0);
videoAreaWidget->showFullScreen();
QDesktopServices::openUrl(url);
}
+void MediaView::shareViaBuffer() {
+ Video* video = listModel->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());
+ QDesktopServices::openUrl(url);
+}
+
void MediaView::shareViaEmail() {
Video* video = listModel->activeVideo();
if (!video) return;