]> git.sur5r.net Git - minitube/blobdiff - src/mainwindow.cpp
Removed debug statements
[minitube] / src / mainwindow.cpp
index a77ac272e2a470fc95249bf544350a38dadcb4bc..437571638bc72698518282238b8f8b3b42d1ebc0 100644 (file)
@@ -95,8 +95,9 @@ MainWindow::MainWindow() :
     mediaObject(0),
     audioOutput(0),
     #endif
-    m_fullscreen(false),
-    m_compact(false) {
+    fullscreenFlag(false),
+    m_compact(false),
+    initialized(false) {
 
     singleton = this;
 
@@ -105,7 +106,6 @@ MainWindow::MainWindow() :
 #endif
 
     // views mechanism
-    history = new QStack<QWidget*>();
     views = new QStackedWidget();
     views->hide();
     setCentralWidget(views);
@@ -165,10 +165,6 @@ MainWindow::MainWindow() :
     QTimer::singleShot(0, this, SLOT(lazyInit()));
 }
 
-MainWindow::~MainWindow() {
-    delete history;
-}
-
 void MainWindow::lazyInit() {
 #ifdef APP_PHONON
     initPhonon();
@@ -221,15 +217,24 @@ void MainWindow::lazyInit() {
 
     JsFunctions::instance();
 
-    checkForUpdate();
-
     // Hack to give focus to searchlineedit
     QMetaObject::invokeMethod(views->currentWidget(), "appear");
     View* view = qobject_cast<View *> (views->currentWidget());
     QString desc = view->metadata().value("description").toString();
     if (!desc.isEmpty()) showMessage(desc);
 
+#ifdef APP_INTEGRITY
+    if (!Extra::integrityCheck()) {
+        deleteLater();
+        return;
+    }
+#endif
+
     ChannelAggregator::instance()->start();
+
+    checkForUpdate();
+
+    initialized = true;
 }
 
 void MainWindow::changeEvent(QEvent *e) {
@@ -243,37 +248,39 @@ void MainWindow::changeEvent(QEvent *e) {
 
 bool MainWindow::eventFilter(QObject *obj, QEvent *e) {
 
-    if (m_fullscreen && e->type() == QEvent::MouseMove) {
-
-        QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (e);
-        const int x = mouseEvent->pos().x();
-        const QString className = QString(obj->metaObject()->className());
+    if (fullscreenFlag && e->type() == QEvent::MouseMove) {
+        const char *className = obj->metaObject()->className();
         const bool isHoveringVideo =
                 (className == QLatin1String("QGLWidget")) ||
                 (className == QLatin1String("VideoAreaWidget"));
 
         // qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible();
 
-        if (mediaView && mediaView->isPlaylistVisible()) {
-            if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false);
-        } else {
-            if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
-        }
+        if (isHoveringVideo) {
+            QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (e);
+            const int x = mouseEvent->pos().x();
+
+            if (mediaView->isPlaylistVisible()) {
+                if (x > 5) mediaView->setPlaylistVisible(false);
+            } else {
+                if (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);
-        }
+            const int y = mouseEvent->pos().y();
+            if (mainToolBar->isVisible()) {
+                if (y > 5) mainToolBar->setVisible(false);
+            } else {
+                if (y >= 0 && y < 5) mainToolBar->setVisible(true);
+            }
 #endif
 
+        }
+
         // show the normal cursor
         unsetCursor();
         // then hide it again after a few seconds
         mouseTimer->start();
-
     }
 
     if (e->type() == QEvent::ToolTip) {
@@ -492,7 +499,6 @@ void MainWindow::createActions() {
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
     action->setCheckable(true);
     action->setIcon(IconUtils::icon("document-save"));
-    action->setVisible(false);
     connect(action, SIGNAL(toggled(bool)), SLOT(toggleDownloads(bool)));
     actions->insert("downloads", action);
 
@@ -759,7 +765,6 @@ void MainWindow::createToolBars() {
     toolbarSearch = searchWrapper->getSearchLineEdit();
 #else
     toolbarSearch = new SearchLineEdit(this);
-    qDebug() << "Qt SearchLineEdit" << toolbarSearch;
 #endif
     toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
     toolbarSearch->setSuggester(new YTSuggester(this));
@@ -841,7 +846,6 @@ void MainWindow::createStatusBar() {
     statusToolBar = new QToolBar(this);
     statusToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     statusToolBar->setIconSize(QSize(16, 16));
-    // statusToolBar->addAction(The::globalActions()->value("downloads"));
 
     regionAction = new QAction(this);
     regionAction->setStatusTip(tr("Choose your content location"));
@@ -879,13 +883,12 @@ void MainWindow::showActionInStatusBar(QAction* action, bool show) {
 #endif
     if (show) {
         statusToolBar->insertAction(statusToolBar->actions().first(), action);
-        if (statusBar()->isHidden() && !m_fullscreen)
+        if (statusBar()->isHidden() && !fullscreenFlag)
             setStatusBarVisibility(true);
     } else {
         statusToolBar->removeAction(action);
         if (statusBar()->isVisible() && !needStatusBar())
-            if (m_fullscreen && views->currentWidget() == mediaView)
-                setStatusBarVisibility(false);
+            setStatusBarVisibility(false);
     }
 }
 
@@ -927,7 +930,8 @@ void MainWindow::readSettings() {
 void MainWindow::writeSettings() {
     QSettings settings;
 
-    settings.setValue("geometry", saveGeometry());
+    if (!isReallyFullScreen())
+        settings.setValue("geometry", saveGeometry());
     mediaView->saveSplitterState();
 
 #ifdef APP_PHONON
@@ -940,9 +944,9 @@ void MainWindow::writeSettings() {
 }
 
 void MainWindow::goBack() {
-    if ( history->size() > 1 ) {
-        history->pop();
-        QWidget *widget = history->pop();
+    if (history.size() > 1) {
+        history.pop();
+        QWidget *widget = history.pop();
         showWidget(widget);
     }
 }
@@ -987,6 +991,8 @@ void MainWindow::showWidget(QWidget* widget, bool transition) {
         else title += QLatin1String(" - ") + Constants::NAME;
         setWindowTitle(title);
 
+        statusToolBar->setUpdatesEnabled(false);
+
         // dynamic view actions
         foreach (QAction* action, viewActions)
             showActionInStatusBar(action, false);
@@ -999,13 +1005,15 @@ void MainWindow::showWidget(QWidget* widget, bool transition) {
         adjustStatusBarVisibility();
         messageLabel->hide();
 
+        statusToolBar->setUpdatesEnabled(true);
+
         /*
         QString desc = metadata.value("description").toString();
         if (!desc.isEmpty()) showMessage(desc);
         */
     }
 
-    history->push(widget);
+    history.push(widget);
 }
 
 void MainWindow::about() {
@@ -1040,7 +1048,7 @@ void MainWindow::quit() {
     }
 #endif
     // do not save geometry when in full screen or in compact mode
-    if (!m_fullscreen && !compactViewAct->isChecked()) {
+    if (!fullscreenFlag && !compactViewAct->isChecked()) {
         writeSettings();
     }
     // mediaView->stop();
@@ -1076,7 +1084,7 @@ void MainWindow::showEvent(QShowEvent *e) {
 bool MainWindow::confirmQuit() {
     if (DownloadManager::instance()->activeItems() > 0) {
         QMessageBox msgBox(this);
-        msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+        msgBox.setIconPixmap(IconUtils::pixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
         msgBox.setText(tr("Do you want to exit %1 with a download in progress?").arg(Constants::NAME));
         msgBox.setInformativeText(tr("If you close %1 now, this download will be cancelled.").arg(Constants::NAME));
         msgBox.setModal(true);
@@ -1177,17 +1185,17 @@ void MainWindow::stop() {
     mediaView->stop();
 }
 
-void MainWindow::resizeEvent(QResizeEvent*e) {
+void MainWindow::resizeEvent(QResizeEvent *e) {
     Q_UNUSED(e);
 #ifdef APP_MAC
-    if (mac::CanGoFullScreen(winId())) {
+    if (initialized && mac::CanGoFullScreen(winId())) {
         bool isFullscreen = mac::IsFullScreen(winId());
-        if (isFullscreen != m_fullscreen) {
+        if (isFullscreen != fullscreenFlag) {
             if (compactViewAct->isChecked()) {
                 compactViewAct->setChecked(false);
                 compactView(false);
             }
-            m_fullscreen = isFullscreen;
+            fullscreenFlag = isFullscreen;
             updateUIForFullscreen();
         }
     }
@@ -1208,8 +1216,6 @@ void MainWindow::fullscreen() {
     if (compactViewAct->isChecked())
         compactViewAct->toggle();
 
-    m_fullscreen = !m_fullscreen;
-
 #ifdef APP_MAC
     WId handle = winId();
     if (mac::CanGoFullScreen(handle)) {
@@ -1219,7 +1225,9 @@ void MainWindow::fullscreen() {
     }
 #endif
 
-    if (m_fullscreen) {
+    fullscreenFlag = !fullscreenFlag;
+
+    if (fullscreenFlag) {
         // Enter full screen
 
         m_maximized = isMaximized();
@@ -1259,9 +1267,10 @@ void MainWindow::updateUIForFullscreen() {
     static QList<QKeySequence> fsShortcuts;
     static QString fsText;
 
-    if (m_fullscreen) {
+    if (fullscreenFlag) {
         fsShortcuts = fullscreenAct->shortcuts();
         fsText = fullscreenAct->text();
+        if (fsText.isEmpty()) qDebug() << "[taking Empty!]";
         fullscreenAct->setShortcuts(QList<QKeySequence>(fsShortcuts)
                                     << QKeySequence(Qt::Key_Escape));
         fullscreenAct->setText(tr("Leave &Full Screen"));
@@ -1269,6 +1278,7 @@ void MainWindow::updateUIForFullscreen() {
         setStatusBarVisibility(false);
     } else {
         fullscreenAct->setShortcuts(fsShortcuts);
+        if (fsText.isEmpty()) fsText = "[Empty!]";
         fullscreenAct->setText(fsText);
         fullscreenAct->setIcon(IconUtils::icon("view-fullscreen"));
 
@@ -1276,31 +1286,31 @@ void MainWindow::updateUIForFullscreen() {
     }
 
     // No compact view action when in full screen
-    compactViewAct->setVisible(!m_fullscreen);
+    compactViewAct->setVisible(!fullscreenFlag);
     compactViewAct->setChecked(false);
 
     // Hide anything but the video
-    mediaView->setPlaylistVisible(!m_fullscreen);
-    if (mainToolBar) mainToolBar->setVisible(!m_fullscreen);
+    mediaView->setPlaylistVisible(!fullscreenFlag);
+    if (mainToolBar) mainToolBar->setVisible(!fullscreenFlag);
 
 #ifndef APP_MAC
-    menuBar()->setVisible(!m_fullscreen);
+    menuBar()->setVisible(!fullscreenFlag);
 #endif
 
-    if (m_fullscreen) {
+    if (fullscreenFlag) {
         stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
     } else {
         stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
     }
 
 #ifdef Q_OS_MAC
-    MacSupport::fullScreenActions(The::globalActions()->values(), m_fullscreen);
+    MacSupport::fullScreenActions(The::globalActions()->values(), fullscreenFlag);
 #endif
 
     if (views->currentWidget() == mediaView)
         mediaView->setFocus();
 
-    if (m_fullscreen) {
+    if (fullscreenFlag) {
         hideMouse();
     } else {
         mouseTimer->stop();
@@ -1575,12 +1585,12 @@ void MainWindow::toggleDefinitionMode() {
 }
 
 void MainWindow::showFullscreenToolbar(bool show) {
-    if (!m_fullscreen) return;
+    if (!fullscreenFlag) return;
     mainToolBar->setVisible(show);
 }
 
 void MainWindow::showFullscreenPlaylist(bool show) {
-    if (!m_fullscreen) return;
+    if (!fullscreenFlag) return;
     mediaView->setPlaylistVisible(show);
 }
 
@@ -1716,7 +1726,7 @@ void MainWindow::gotNewVersion(const QString &version) {
 void MainWindow::simpleUpdateDialog(const QString &version) {
     QMessageBox msgBox(this);
     msgBox.setIconPixmap(
-                QPixmap(":/images/app.png")
+                IconUtils::pixmap(":/images/app.png")
                 .scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
     msgBox.setText(tr("%1 version %2 is now available.").arg(Constants::NAME, version));
     msgBox.setModal(true);