]> git.sur5r.net Git - minitube/blobdiff - src/MediaView.cpp
Imported Upstream version 1.9
[minitube] / src / MediaView.cpp
index 2418db6ba73403a6c52351c91cf3ae14fbdf0360..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
-    // mouse autohide does not work on the Mac (no mouseMoveEvent)
     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) {
@@ -172,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();
@@ -186,6 +171,13 @@ void MediaView::search(SearchParams *searchParams) {
         }
     }
 
+    sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
+    sidebar->hideSuggestions();
+
+}
+
+void MediaView::searchAgain() {
+    search(searchParams);
 }
 
 void MediaView::appear() {
@@ -286,6 +278,7 @@ void MediaView::stop() {
         delete downloadItem;
         downloadItem = 0;
     }
+    The::globalActions()->value("refine-search")->setChecked(false);
 }
 
 void MediaView::activeRowChanged(int row) {
@@ -626,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() {
@@ -712,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();
@@ -840,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;