]> git.sur5r.net Git - minitube/blobdiff - src/homeview.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / homeview.cpp
index 1d56c26553dd6d3d802895ccc313f36b16e858e7..8ee32410f5641ed7428acca3cfabe3a403d5f29c 100644 (file)
@@ -19,23 +19,21 @@ along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
 $END_LICENSE */
 
 #include "homeview.h"
-#include "segmentedcontrol.h"
-#include "searchview.h"
-#include "standardfeedsview.h"
+#include "channelaggregator.h"
 #include "channelview.h"
+#include "iconutils.h"
 #include "mainwindow.h"
 #include "mediaview.h"
+#include "searchview.h"
+#include "segmentedcontrol.h"
+#include "standardfeedsview.h"
 #include "ytstandardfeed.h"
-#include "iconutils.h"
-#include "channelaggregator.h"
 #ifdef APP_MAC
 #include "macutils.h"
 #endif
 
-HomeView::HomeView(QWidget *parent) : QWidget(parent),
-    standardFeedsView(0),
-    channelsView(0) {
-
+HomeView::HomeView(QWidget *parent)
+    : View(parent), searchView(nullptr), standardFeedsView(nullptr), channelsView(nullptr) {
     QBoxLayout *layout = new QVBoxLayout(this);
     layout->setMargin(0);
     layout->setSpacing(0);
@@ -45,11 +43,6 @@ HomeView::HomeView(QWidget *parent) : QWidget(parent),
 
     stackedWidget = new QStackedWidget();
     layout->addWidget(stackedWidget);
-
-    searchView = new SearchView();
-    connect(searchView, SIGNAL(search(SearchParams*)),
-            MainWindow::instance(), SLOT(showMedia(SearchParams*)));
-    stackedWidget->addWidget(searchView);
 }
 
 void HomeView::setupBar() {
@@ -76,25 +69,29 @@ void HomeView::setupBar() {
     connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
             SLOT(unwatchedCountChanged(int)));
 
-    foreach (QAction* action, bar->actions()) {
+    const auto &a = bar->actions();
+    for (QAction *action : a) {
         addAction(action);
-        IconUtils::setupAction(action);
+        MainWindow::instance()->setupAction(action);
     }
 }
 
 void HomeView::showWidget(QWidget *widget) {
-    QWidget* currentWidget = stackedWidget->currentWidget();
-    if (currentWidget == widget) return;
-    QMetaObject::invokeMethod(currentWidget, "disappear");
-    currentWidget->setEnabled(false);
+    QWidget *currentWidget = stackedWidget->currentWidget();
+    if (currentWidget && currentWidget != widget) {
+        QMetaObject::invokeMethod(currentWidget, "disappear");
+        currentWidget->setEnabled(false);
+    }
     stackedWidget->setCurrentWidget(widget);
     widget->setEnabled(true);
-    QMetaObject::invokeMethod(widget, "appear");
-    widget->setFocus();
+    QMetaObject::invokeMethod(widget, "appear", Qt::QueuedConnection);
 }
 
 void HomeView::appear() {
-    QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear");
+    if (stackedWidget->count() == 0)
+        showSearch();
+    else
+        QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear", Qt::QueuedConnection);
 }
 
 void HomeView::disappear() {
@@ -102,6 +99,12 @@ void HomeView::disappear() {
 }
 
 void HomeView::showSearch() {
+    if (!searchView) {
+        searchView = new SearchView(this);
+        connect(searchView, SIGNAL(search(SearchParams *)), MainWindow::instance(),
+                SLOT(showMedia(SearchParams *)));
+        stackedWidget->addWidget(searchView);
+    }
     showWidget(searchView);
     bar->setCheckedAction(0);
 }
@@ -109,9 +112,8 @@ void HomeView::showSearch() {
 void HomeView::showStandardFeeds() {
     if (!standardFeedsView) {
         standardFeedsView = new StandardFeedsView();
-        connect(standardFeedsView, SIGNAL(activated(VideoSource*)),
-                MainWindow::instance(),
-                SLOT(showMedia(VideoSource*)));
+        connect(standardFeedsView, SIGNAL(activated(VideoSource *)), MainWindow::instance(),
+                SLOT(showMedia(VideoSource *)));
         stackedWidget->addWidget(standardFeedsView);
     }
     showWidget(standardFeedsView);
@@ -121,9 +123,8 @@ void HomeView::showStandardFeeds() {
 void HomeView::showChannels() {
     if (!channelsView) {
         channelsView = new ChannelView();
-        connect(channelsView, SIGNAL(activated(VideoSource*)),
-                MainWindow::instance(),
-                SLOT(showMedia(VideoSource*)));
+        connect(channelsView, SIGNAL(activated(VideoSource *)), MainWindow::instance(),
+                SLOT(showMedia(VideoSource *)));
         stackedWidget->addWidget(channelsView);
     }
     showWidget(channelsView);