]> git.sur5r.net Git - minitube/blob - src/homeview.cpp
Imported Upstream version 2.3
[minitube] / src / homeview.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
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.
10
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.
15
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/>.
18
19 $END_LICENSE */
20
21 #include "homeview.h"
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"
31 #ifdef APP_MAC
32 #include "macutils.h"
33 #endif
34
35 HomeView::HomeView(QWidget *parent) : QWidget(parent),
36     standardFeedsView(0),
37     channelsView(0) {
38
39     QBoxLayout *layout = new QVBoxLayout(this);
40     layout->setMargin(0);
41     layout->setSpacing(0);
42
43     setupBar();
44     layout->addWidget(bar);
45
46     stackedWidget = new QStackedWidget();
47     layout->addWidget(stackedWidget);
48
49     searchView = new SearchView();
50     connect(searchView, SIGNAL(search(SearchParams*)),
51             MainWindow::instance(), SLOT(showMedia(SearchParams*)));
52     stackedWidget->addWidget(searchView);
53 }
54
55 void HomeView::setupBar() {
56     bar = new SegmentedControl();
57
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);
64
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);
70
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)));
78
79     foreach (QAction* action, bar->actions()) {
80         addAction(action);
81         IconUtils::setupAction(action);
82     }
83 }
84
85 void HomeView::showWidget(QWidget *widget) {
86     QWidget* currentWidget = stackedWidget->currentWidget();
87     if (currentWidget == widget) return;
88     QMetaObject::invokeMethod(currentWidget, "disappear");
89     currentWidget->setEnabled(false);
90     stackedWidget->setCurrentWidget(widget);
91     widget->setEnabled(true);
92     QMetaObject::invokeMethod(widget, "appear");
93     widget->setFocus();
94 }
95
96 void HomeView::appear() {
97     QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear");
98 }
99
100 void HomeView::disappear() {
101     QMetaObject::invokeMethod(stackedWidget->currentWidget(), "disappear");
102 }
103
104 void HomeView::showSearch() {
105     showWidget(searchView);
106     bar->setCheckedAction(0);
107 }
108
109 void HomeView::showStandardFeeds() {
110     if (!standardFeedsView) {
111         standardFeedsView = new StandardFeedsView();
112         connect(standardFeedsView, SIGNAL(activated(VideoSource*)),
113                 MainWindow::instance(),
114                 SLOT(showMedia(VideoSource*)));
115         stackedWidget->addWidget(standardFeedsView);
116     }
117     showWidget(standardFeedsView);
118     bar->setCheckedAction(1);
119 }
120
121 void HomeView::showChannels() {
122     if (!channelsView) {
123         channelsView = new ChannelView();
124         connect(channelsView, SIGNAL(activated(VideoSource*)),
125                 MainWindow::instance(),
126                 SLOT(showMedia(VideoSource*)));
127         stackedWidget->addWidget(channelsView);
128     }
129     showWidget(channelsView);
130     bar->setCheckedAction(2);
131 }
132
133 void HomeView::unwatchedCountChanged(int count) {
134     QVariant v;
135     QString s;
136     if (count > 0) {
137         s = QString::number(count);
138         v = s;
139     }
140     subscriptionsAction->setProperty("notifyCount", v);
141     bar->update();
142 #ifdef APP_MAC
143     mac::dockBadge(s);
144 #endif
145 }