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/>.
21 #include "standardfeedsview.h"
22 #include "videosourcewidget.h"
23 #include "ytcategories.h"
24 #include "ytstandardfeed.h"
25 #include "ytregions.h"
26 #include "mainwindow.h"
27 #include "painterutils.h"
30 QHash<QString, QAction*>* globalActions();
33 StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent),
35 QPalette p = palette();
36 p.setBrush(QPalette::Window, Qt::black);
38 setAutoFillBackground(true);
40 connect(The::globalActions()->value("worldwide-region"), SIGNAL(triggered()),
41 SLOT(selectWorldwideRegion()));
43 connect(The::globalActions()->value("local-region"), SIGNAL(triggered()),
44 SLOT(selectLocalRegion()));
47 QAction *regionAction = MainWindow::instance()->getRegionAction();
48 connect(regionAction, SIGNAL(changed()), SLOT(load()));
52 void StandardFeedsView::load() {
53 YTCategories *youTubeCategories = new YTCategories(this);
54 connect(youTubeCategories, SIGNAL(categoriesLoaded(const QList<YTCategory> &)),
55 SLOT(layoutCategories(const QList<YTCategory> &)));
56 youTubeCategories->loadCategories();
59 while (QLayoutItem *item = layout->takeAt(0)) {
60 delete item->widget();
66 layout = new QGridLayout(this);
68 layout->setSpacing(1);
70 QList<YTStandardFeed*> feeds = getMainFeeds();
71 foreach(YTStandardFeed *feed, feeds)
72 addVideoSourceWidget(feed);
74 YTRegion region = YTRegions::currentRegion();
75 QToolButton *regionButton = MainWindow::instance()->getRegionButton();
76 regionButton->setText(region.name);
77 regionButton->setIcon(YTRegions::iconForRegionId(region.id));
80 void StandardFeedsView::layoutCategories(const QList<YTCategory> &categories) {
81 QString regionId = YTRegions::currentRegionId();
82 foreach(YTCategory category, categories) {
83 // assign a parent to this VideoSource so it won't be deleted by MediaView
84 YTStandardFeed *feed = new YTStandardFeed(this);
85 feed->setCategory(category.term);
86 feed->setLabel(category.label);
87 feed->setRegionId(regionId);
88 feed->setFeedId("most_popular");
89 addVideoSourceWidget(feed);
93 void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) {
94 VideoSourceWidget *w = new VideoSourceWidget(videoSource);
95 connect(w, SIGNAL(activated(VideoSource*)),
96 SIGNAL(activated(VideoSource*)));
97 int i = layout->count();
98 static const int cols = 5;
99 layout->addWidget(w, i / cols, i % cols);
102 QList<YTStandardFeed*> StandardFeedsView::getMainFeeds() {
103 QList<YTStandardFeed*> feeds;
105 feeds << buildStardardFeed("most_popular", tr("Most Popular"))
106 // << buildStardardFeed("recently_featured", tr("Featured"))
107 << buildStardardFeed("most_shared", tr("Most Shared"))
108 << buildStardardFeed("most_discussed", tr("Most Discussed"))
109 << buildStardardFeed("top_rated", tr("Top Rated"))
110 << buildStardardFeed("most_popular", tr("All Time Popular"), "all_time");
115 YTStandardFeed* StandardFeedsView::buildStardardFeed(
116 QString feedId, QString label, QString time) {
117 YTStandardFeed *feed = new YTStandardFeed(this);
118 feed->setFeedId(feedId);
119 feed->setLabel(label);
120 if (!time.isEmpty()) feed->setTime(time);
121 feed->setRegionId(YTRegions::currentRegionId());
125 void StandardFeedsView::appear() {
128 QAction *regionAction = MainWindow::instance()->getRegionAction();
129 regionAction->setVisible(true);
132 void StandardFeedsView::disappear() {
133 QAction *regionAction = MainWindow::instance()->getRegionAction();
134 regionAction->setVisible(false);
137 void StandardFeedsView::selectWorldwideRegion() {
138 YTRegions::setRegion(YTRegions::worldwideRegion().id);
142 void StandardFeedsView::selectLocalRegion() {
143 YTRegions::setRegion(YTRegions::localRegion().id);
147 void StandardFeedsView::paintEvent(QPaintEvent *event) {
148 QWidget::paintEvent(event);
149 PainterUtils::topShadow(this);