]> git.sur5r.net Git - minitube/blobdiff - src/MediaView.cpp
Imported Upstream version 1.9
[minitube] / src / MediaView.cpp
index a77fba219122456205572e7d42eb4b3f5746ccec..012266cc2a262853f8f8757365ad7fb33c489d4f 100644 (file)
@@ -9,6 +9,13 @@
 #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();
@@ -31,29 +38,6 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) {
     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);
@@ -86,20 +70,19 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) {
 
     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);
 
@@ -144,6 +127,10 @@ void MediaView::initialize() {
     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) {
@@ -155,6 +142,7 @@ 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) {
@@ -171,9 +159,7 @@ 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();
@@ -185,6 +171,13 @@ void MediaView::search(SearchParams *searchParams) {
         }
     }
 
+    sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
+    sidebar->hideSuggestions();
+
+}
+
+void MediaView::searchAgain() {
+    search(searchParams);
 }
 
 void MediaView::appear() {
@@ -197,7 +190,7 @@ void MediaView::disappear() {
 
 void MediaView::handleError(QString /* message */) {
 
-    QTimer::singleShot(100, this, SLOT(startPlaying()));
+    QTimer::singleShot(500, this, SLOT(startPlaying()));
 
     /*
     videoAreaWidget->showError(message);
@@ -207,10 +200,8 @@ void MediaView::handleError(QString /* 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) {
@@ -287,6 +278,7 @@ void MediaView::stop() {
         delete downloadItem;
         downloadItem = 0;
     }
+    The::globalActions()->value("refine-search")->setChecked(false);
 }
 
 void MediaView::activeRowChanged(int row) {
@@ -300,7 +292,7 @@ void MediaView::activeRowChanged(int row) {
     workaroundTimer->stop();
     errorTimer->stop();
 
-    mediaObject->pause();
+    mediaObject->stop();
     if (downloadItem) {
         downloadItem->stop();
         delete downloadItem;
@@ -409,6 +401,9 @@ void MediaView::downloadStatusChanged() {
     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";
@@ -430,6 +425,9 @@ void MediaView::startPlaying() {
     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();
@@ -497,7 +495,19 @@ void MediaView::skipBackward() {
     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()) {
@@ -512,6 +522,7 @@ void MediaView::playbackFinished() {
 }
 
 void MediaView::playbackResume() {
+    qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
     mediaObject->seek(mediaObject->currentTime());
     mediaObject->play();
 }
@@ -608,7 +619,13 @@ void MediaView::searchMostViewed() {
 }
 
 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() {
@@ -694,6 +711,15 @@ void MediaView::downloadVideo() {
     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();
@@ -822,6 +848,18 @@ void MediaView::shareViaFacebook() {
     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;