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 "channelaggregator.h"
23 #include "channelview.h"
24 #include "iconutils.h"
25 #include "mainwindow.h"
26 #include "mediaview.h"
27 #include "searchview.h"
28 #include "segmentedcontrol.h"
29 #include "standardfeedsview.h"
30 #include "ytstandardfeed.h"
35 HomeView::HomeView(QWidget *parent)
36 : View(parent), searchView(nullptr), standardFeedsView(nullptr), channelsView(nullptr) {
37 QBoxLayout *layout = new QVBoxLayout(this);
39 layout->setSpacing(0);
42 layout->addWidget(bar);
44 stackedWidget = new QStackedWidget();
45 layout->addWidget(stackedWidget);
48 void HomeView::setupBar() {
49 bar = new SegmentedControl();
51 QAction *action = new QAction(tr("Search"), this);
52 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
53 action->setStatusTip(tr("Find videos and channels by keyword"));
54 connect(action, SIGNAL(triggered()), SLOT(showSearch()));
55 bar->addAction(action);
56 bar->setCheckedAction(action);
58 action = new QAction(tr("Browse"), this);
59 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
60 action->setStatusTip(tr("Browse videos by category"));
61 connect(action, SIGNAL(triggered()), SLOT(showStandardFeeds()));
62 bar->addAction(action);
64 subscriptionsAction = new QAction(tr("Subscriptions"), this);
65 subscriptionsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
66 subscriptionsAction->setStatusTip(tr("Channel subscriptions"));
67 connect(subscriptionsAction, SIGNAL(triggered()), SLOT(showChannels()));
68 bar->addAction(subscriptionsAction);
69 connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
70 SLOT(unwatchedCountChanged(int)));
72 const auto &a = bar->actions();
73 for (QAction *action : a) {
75 MainWindow::instance()->setupAction(action);
79 void HomeView::showWidget(QWidget *widget) {
80 QWidget *currentWidget = stackedWidget->currentWidget();
81 if (currentWidget && currentWidget != widget) {
82 QMetaObject::invokeMethod(currentWidget, "disappear");
83 currentWidget->setEnabled(false);
85 stackedWidget->setCurrentWidget(widget);
86 widget->setEnabled(true);
87 QMetaObject::invokeMethod(widget, "appear", Qt::QueuedConnection);
90 void HomeView::appear() {
91 if (stackedWidget->count() == 0)
94 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear", Qt::QueuedConnection);
97 void HomeView::disappear() {
98 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "disappear");
101 void HomeView::showSearch() {
103 searchView = new SearchView(this);
104 connect(searchView, SIGNAL(search(SearchParams *)), MainWindow::instance(),
105 SLOT(showMedia(SearchParams *)));
106 stackedWidget->addWidget(searchView);
108 showWidget(searchView);
109 bar->setCheckedAction(0);
112 void HomeView::showStandardFeeds() {
113 if (!standardFeedsView) {
114 standardFeedsView = new StandardFeedsView();
115 connect(standardFeedsView, SIGNAL(activated(VideoSource *)), MainWindow::instance(),
116 SLOT(showMedia(VideoSource *)));
117 stackedWidget->addWidget(standardFeedsView);
119 showWidget(standardFeedsView);
120 bar->setCheckedAction(1);
123 void HomeView::showChannels() {
125 channelsView = new ChannelView();
126 connect(channelsView, SIGNAL(activated(VideoSource *)), MainWindow::instance(),
127 SLOT(showMedia(VideoSource *)));
128 stackedWidget->addWidget(channelsView);
130 showWidget(channelsView);
131 bar->setCheckedAction(2);
134 void HomeView::unwatchedCountChanged(int count) {
138 s = QString::number(count);
141 subscriptionsAction->setProperty("notifyCount", v);