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 setUpdatesEnabled(false);
54 YTCategories *youTubeCategories = new YTCategories(this);
55 connect(youTubeCategories, SIGNAL(categoriesLoaded(const QList<YTCategory> &)),
56 SLOT(layoutCategories(const QList<YTCategory> &)));
57 youTubeCategories->loadCategories();
60 while (QLayoutItem *item = layout->takeAt(0)) {
61 delete item->widget();
67 layout = new QGridLayout(this);
69 layout->setSpacing(1);
71 QList<YTStandardFeed*> feeds = getMainFeeds();
72 foreach(YTStandardFeed *feed, feeds)
73 addVideoSourceWidget(feed);
75 YTRegion region = YTRegions::currentRegion();
76 QToolButton *regionButton = MainWindow::instance()->getRegionButton();
77 regionButton->setText(region.name);
78 regionButton->setIcon(YTRegions::iconForRegionId(region.id));
81 void StandardFeedsView::layoutCategories(const QList<YTCategory> &categories) {
82 QString regionId = YTRegions::currentRegionId();
83 foreach(YTCategory category, categories) {
84 // assign a parent to this VideoSource so it won't be deleted by MediaView
85 YTStandardFeed *feed = new YTStandardFeed(this);
86 feed->setCategory(category.term);
87 feed->setLabel(category.label);
88 feed->setRegionId(regionId);
89 feed->setFeedId("most_popular");
90 addVideoSourceWidget(feed);
92 if (categories.size() > 1) setUpdatesEnabled(true);
95 void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) {
96 VideoSourceWidget *w = new VideoSourceWidget(videoSource);
97 connect(w, SIGNAL(activated(VideoSource*)),
98 SIGNAL(activated(VideoSource*)));
99 int i = layout->count();
100 static const int cols = 4;
101 layout->addWidget(w, i / cols, i % cols);
104 QList<YTStandardFeed*> StandardFeedsView::getMainFeeds() {
105 QList<YTStandardFeed*> feeds;
107 feeds << buildStardardFeed("most_popular", tr("Most Popular"));
108 // << buildStardardFeed("recently_featured", tr("Featured"))
109 // << buildStardardFeed("most_shared", tr("Most Shared"))
110 // << buildStardardFeed("most_discussed", tr("Most Discussed"))
111 // << buildStardardFeed("top_rated", tr("Top Rated"))
112 // << buildStardardFeed("most_popular", tr("All Time Popular"), "all_time");
117 YTStandardFeed* StandardFeedsView::buildStardardFeed(const QString &feedId, const QString &label, QString time) {
118 YTStandardFeed *feed = new YTStandardFeed(this);
119 feed->setFeedId(feedId);
120 feed->setLabel(label);
121 if (!time.isEmpty()) feed->setTime(time);
122 feed->setRegionId(YTRegions::currentRegionId());
126 void StandardFeedsView::appear() {
130 qApp->processEvents();
133 QAction *regionAction = MainWindow::instance()->getRegionAction();
134 regionAction->setVisible(true);
137 void StandardFeedsView::disappear() {
138 QAction *regionAction = MainWindow::instance()->getRegionAction();
139 regionAction->setVisible(false);
142 void StandardFeedsView::selectWorldwideRegion() {
143 YTRegions::setRegion(YTRegions::worldwideRegion().id);
147 void StandardFeedsView::selectLocalRegion() {
148 YTRegions::setRegion(YTRegions::localRegion().id);
152 void StandardFeedsView::paintEvent(QPaintEvent *event) {
153 QWidget::paintEvent(event);
154 // PainterUtils::topShadow(this);