]> git.sur5r.net Git - minitube/blobdiff - src/MainWindow.cpp
Imported Upstream version 1.9
[minitube] / src / MainWindow.cpp
index 20bd4a75a53ed21c6a6ebe0b2dd113b6679e50f7..e5d78d22533d7df0fd5ef4b272c4795b91965f18 100644 (file)
@@ -30,6 +30,7 @@
 #else
 #include "searchlineedit.h"
 #endif
+#include <iostream>
 
 static MainWindow *singleton = 0;
 
@@ -39,12 +40,12 @@ MainWindow* MainWindow::instance() {
 }
 
 MainWindow::MainWindow() :
+        updateChecker(0),
         aboutView(0),
         downloadView(0),
         mediaObject(0),
         audioOutput(0),
-        m_fullscreen(false),
-        updateChecker(0) {
+        m_fullscreen(false) {
 
     singleton = this;
 
@@ -124,6 +125,11 @@ MainWindow::MainWindow() :
 
     setAcceptDrops(true);
 
+    mouseTimer = new QTimer(this);
+    mouseTimer->setInterval(5000);
+    mouseTimer->setSingleShot(true);
+    connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse()));
+
     QTimer::singleShot(0, this, SLOT(checkForUpdate()));
 
 }
@@ -142,25 +148,44 @@ void MainWindow::changeEvent(QEvent* event) {
 }
 
 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
-#ifdef Q_WS_X11
-    if (event->type() == QEvent::MouseMove && this->m_fullscreen) {
+
+    if (m_fullscreen && event->type() == QEvent::MouseMove) {
+
         QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
-        int x = mouseEvent->pos().x();
-        int y = mouseEvent->pos().y();
+        const int x = mouseEvent->pos().x();
+        const QString className = QString(obj->metaObject()->className());
+        const bool isHoveringVideo = (className == "QGLWidget") || (className == "VideoAreaWidget");
 
-        if (y < 0 && (obj == this->mainToolBar || !(y <= 10-this->mainToolBar->height() && y >= 0-this->mainToolBar->height() )))
-           this->mainToolBar->setVisible(false);
-        if (x < 0)
-            this->mediaView->setPlaylistVisible(false);
-    }
+        // qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible();
+
+        if (mediaView->isPlaylistVisible()) {
+            if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false);
+        } else {
+            if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
+        }
+
+#ifndef APP_MAC
+        const int y = mouseEvent->pos().y();
+        if (mainToolBar->isVisible()) {
+            if (isHoveringVideo && y > 5) mainToolBar->setVisible(false);
+        } else {
+            if (isHoveringVideo && y >= 0 && y < 5) mainToolBar->setVisible(true);
+        }
 #endif
 
+        // show the normal cursor
+        unsetCursor();
+        // then hide it again after a few seconds
+        mouseTimer->start();
+
+    }
+
     if (event->type() == QEvent::ToolTip) {
         // kill tooltips
         return true;
     }
     // standard event processing
-    return QObject::eventFilter(obj, event);
+    return QMainWindow::eventFilter(obj, event);
 }
 
 void MainWindow::createActions() {
@@ -388,6 +413,13 @@ void MainWindow::createActions() {
     connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo()));
     actions->insert("download", action);
 
+    /*
+    action = new QAction(tr("&Snapshot"), this);
+    action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S));
+    actions->insert("snapshot", action);
+    connect(action, SIGNAL(triggered()), mediaView, SLOT(snapshot()));
+    */
+
     QString shareTip = tr("Share the current video using %1");
 
     action = new QAction("&Twitter", this);
@@ -400,6 +432,11 @@ void MainWindow::createActions() {
     actions->insert("facebook", action);
     connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaFacebook()));
 
+    action = new QAction("&Buffer", this);
+    action->setStatusTip(shareTip.arg("Buffer"));
+    actions->insert("buffer", action);
+    connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaBuffer()));
+
     action = new QAction(tr("&Email"), this);
     action->setStatusTip(shareTip.arg(tr("Email")));
     actions->insert("email", action);
@@ -427,6 +464,15 @@ void MainWindow::createActions() {
     actions->insert("stopafterthis", action);
     connect(action, SIGNAL(toggled(bool)), SLOT(showStopAfterThisInStatusBar(bool)));
 
+    action = new QAction(tr("&Report an Issue..."), this);
+    actions->insert("report-issue", action);
+    connect(action, SIGNAL(triggered()), SLOT(reportIssue()));
+
+    action = new QAction(tr("&Refine Search..."), this);
+    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
+    action->setCheckable(true);
+    actions->insert("refine-search", action);
+
     // common action properties
     foreach (QAction *action, actions->values()) {
 
@@ -490,17 +536,20 @@ void MainWindow::createMenus() {
     playlistMenu->addSeparator();
     playlistMenu->addAction(moveUpAct);
     playlistMenu->addAction(moveDownAct);
+    playlistMenu->addSeparator();
+    playlistMenu->addAction(The::globalActions()->value("refine-search"));
 
     QMenu* videoMenu = menuBar()->addMenu(tr("&Video"));
     menus->insert("video", videoMenu);
     videoMenu->addAction(findVideoPartsAct);
     videoMenu->addSeparator();
     videoMenu->addAction(webPageAct);
-#ifndef APP_NO_DOWNLOADS
     videoMenu->addSeparator();
+#ifndef APP_NO_DOWNLOADS
     videoMenu->addAction(The::globalActions()->value("download"));
-    videoMenu->addAction(copyLinkAct);
+    // videoMenu->addAction(copyLinkAct);
 #endif
+    // videoMenu->addAction(The::globalActions()->value("snapshot"));
 
     QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
     menus->insert("view", viewMenu);
@@ -515,6 +564,8 @@ void MainWindow::createMenus() {
     shareMenu->addSeparator();
     shareMenu->addAction(The::globalActions()->value("twitter"));
     shareMenu->addAction(The::globalActions()->value("facebook"));
+    shareMenu->addAction(The::globalActions()->value("buffer"));
+    shareMenu->addSeparator();
     shareMenu->addAction(The::globalActions()->value("email"));
 
 #ifdef APP_MAC
@@ -526,6 +577,7 @@ void MainWindow::createMenus() {
 #if !defined(APP_MAC) && !defined(APP_WIN)
     helpMenu->addAction(donateAct);
 #endif
+    helpMenu->addAction(The::globalActions()->value("report-issue"));
     helpMenu->addAction(aboutAct);
 }
 
@@ -732,6 +784,7 @@ void MainWindow::showWidget ( QWidget* widget ) {
 
     The::globalActions()->value("twitter")->setEnabled(widget == mediaView);
     The::globalActions()->value("facebook")->setEnabled(widget == mediaView);
+    The::globalActions()->value("buffer")->setEnabled(widget == mediaView);
     The::globalActions()->value("email")->setEnabled(widget == mediaView);
 
     aboutAct->setEnabled(widget != aboutView);
@@ -780,6 +833,11 @@ void MainWindow::donate() {
     QDesktopServices::openUrl(url);
 }
 
+void MainWindow::reportIssue() {
+    QUrl url("http://flavio.tordini.org/forums/forum/minitube-forums/minitube-troubleshooting");
+    QDesktopServices::openUrl(url);
+}
+
 void MainWindow::quit() {
 #ifdef APP_MAC
     if (!confirmQuit()) {
@@ -1003,6 +1061,13 @@ void MainWindow::updateUIForFullscreen() {
 
     if (views->currentWidget() == mediaView)
         mediaView->setFocus();
+
+    if (m_fullscreen) {
+        hideMouse();
+    } else {
+        mouseTimer->stop();
+        unsetCursor();
+    }
 }
 
 void MainWindow::compactView(bool enable) {
@@ -1066,7 +1131,6 @@ void MainWindow::compactView(bool enable) {
 }
 
 void MainWindow::searchFocus() {
-    QWidget *view = views->currentWidget();
     toolbarSearch->selectAll();
     toolbarSearch->setFocus();
 }
@@ -1251,7 +1315,6 @@ void MainWindow::toggleDownloads(bool show) {
 }
 
 void MainWindow::startToolbarSearch(QString query) {
-
     query = query.trimmed();
 
     // check for empty query
@@ -1390,9 +1453,32 @@ void MainWindow::messageReceived(const QString &message) {
         if (skipAct->isEnabled()) skipAct->trigger();
     } else if (message == "--previous") {
         if (skipBackwardAct->isEnabled()) skipBackwardAct->trigger();
+    }  else if (message.startsWith("--")) {
+        MainWindow::printHelp();
     } else if (!message.isEmpty()) {
         SearchParams *searchParams = new SearchParams();
         searchParams->setKeywords(message);
         showMedia(searchParams);
     }
 }
+
+void MainWindow::hideMouse() {
+    setCursor(Qt::BlankCursor);
+    mediaView->setPlaylistVisible(false);
+#ifndef APP_MAC
+    mainToolBar->setVisible(false);
+#endif
+}
+
+void MainWindow::printHelp() {
+    QString msg = QString("%1 %2\n\n").arg(Constants::NAME, Constants::VERSION);
+    msg += "Usage: minitube [options]\n";
+    msg += "Options:\n";
+    msg += "  --toggle-playing\t";
+    msg += "Start or pause playback.\n";
+    msg += "  --next\t\t";
+    msg += "Skip to the next video.\n";
+    msg += "  --previous\t\t";
+    msg += "Go back to the previous video.\n";
+    std::cout << msg.toLocal8Bit().data();
+}