3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
22 #include "segmentedcontrol.h"
23 #include "searchview.h"
24 #include "standardfeedsview.h"
25 #include "channelview.h"
26 #include "mainwindow.h"
27 #include "mediaview.h"
28 #include "ytstandardfeed.h"
29 #include "iconutils.h"
30 #include "channelaggregator.h"
35 HomeView::HomeView(QWidget *parent) : View(parent),
39 QBoxLayout *layout = new QVBoxLayout(this);
41 layout->setSpacing(0);
44 layout->addWidget(bar);
46 stackedWidget = new QStackedWidget();
47 layout->addWidget(stackedWidget);
49 searchView = new SearchView(this);
50 connect(searchView, SIGNAL(search(SearchParams*)),
51 MainWindow::instance(), SLOT(showMedia(SearchParams*)));
52 stackedWidget->addWidget(searchView);
55 void HomeView::setupBar() {
56 bar = new SegmentedControl();
58 QAction *action = new QAction(tr("Search"), this);
59 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
60 action->setStatusTip(tr("Find videos and channels by keyword"));
61 connect(action, SIGNAL(triggered()), SLOT(showSearch()));
62 bar->addAction(action);
63 bar->setCheckedAction(action);
65 action = new QAction(tr("Browse"), this);
66 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
67 action->setStatusTip(tr("Browse videos by category"));
68 connect(action, SIGNAL(triggered()), SLOT(showStandardFeeds()));
69 bar->addAction(action);
71 subscriptionsAction = new QAction(tr("Subscriptions"), this);
72 subscriptionsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
73 subscriptionsAction->setStatusTip(tr("Channel subscriptions"));
74 connect(subscriptionsAction, SIGNAL(triggered()), SLOT(showChannels()));
75 bar->addAction(subscriptionsAction);
76 connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
77 SLOT(unwatchedCountChanged(int)));
79 const auto a = bar->actions();
80 for (QAction* action : a) {
82 IconUtils::setupAction(action);
86 void HomeView::showWidget(QWidget *widget) {
87 QWidget* currentWidget = stackedWidget->currentWidget();
88 if (currentWidget == widget) return;
89 QMetaObject::invokeMethod(currentWidget, "disappear");
90 currentWidget->setEnabled(false);
91 stackedWidget->setCurrentWidget(widget);
92 widget->setEnabled(true);
93 QMetaObject::invokeMethod(widget, "appear");
94 QTimer::singleShot(0, widget, SLOT(setFocus()));
97 // Workaround cursor bug on macOS
98 window()->unsetCursor();
102 void HomeView::appear() {
103 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear", Qt::QueuedConnection);
106 void HomeView::disappear() {
107 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "disappear");
110 void HomeView::showSearch() {
111 showWidget(searchView);
112 bar->setCheckedAction(0);
115 void HomeView::showStandardFeeds() {
116 if (!standardFeedsView) {
117 standardFeedsView = new StandardFeedsView();
118 connect(standardFeedsView, SIGNAL(activated(VideoSource*)),
119 MainWindow::instance(),
120 SLOT(showMedia(VideoSource*)));
121 stackedWidget->addWidget(standardFeedsView);
123 showWidget(standardFeedsView);
124 bar->setCheckedAction(1);
127 void HomeView::showChannels() {
129 channelsView = new ChannelView();
130 connect(channelsView, SIGNAL(activated(VideoSource*)),
131 MainWindow::instance(),
132 SLOT(showMedia(VideoSource*)));
133 stackedWidget->addWidget(channelsView);
135 showWidget(channelsView);
136 bar->setCheckedAction(2);
139 void HomeView::unwatchedCountChanged(int count) {
143 s = QString::number(count);
146 subscriptionsAction->setProperty("notifyCount", v);