1 #include "standardfeedsview.h"
2 #include "videosourcewidget.h"
3 #include "ytcategories.h"
4 #include "ytstandardfeed.h"
6 #include "mainwindow.h"
9 QHash<QString, QAction*>* globalActions();
12 static const int cols = 5;
14 StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent),
16 QPalette p = palette();
17 p.setBrush(QPalette::Window, Qt::black);
19 setAutoFillBackground(true);
21 connect(The::globalActions()->value("worldwide-region"), SIGNAL(triggered()),
22 SLOT(selectWorldwideRegion()));
24 connect(The::globalActions()->value("local-region"), SIGNAL(triggered()),
25 SLOT(selectLocalRegion()));
28 QAction *regionAction = MainWindow::instance()->getRegionAction();
29 connect(regionAction, SIGNAL(changed()), SLOT(load()));
33 void StandardFeedsView::load() {
34 YTCategories *youTubeCategories = new YTCategories(this);
35 connect(youTubeCategories, SIGNAL(categoriesLoaded(const QList<YTCategory> &)),
36 SLOT(layoutCategories(const QList<YTCategory> &)));
37 youTubeCategories->loadCategories();
40 while (QLayoutItem *item = layout->takeAt(0)) {
41 delete item->widget();
47 layout = new QGridLayout(this);
49 layout->setSpacing(1);
51 QList<YTStandardFeed*> feeds = getMainFeeds();
52 foreach(YTStandardFeed *feed, feeds)
53 addVideoSourceWidget(feed);
55 YTRegion region = YTRegions::currentRegion();
56 QToolButton *regionButton = MainWindow::instance()->getRegionButton();
57 regionButton->setText(region.name);
58 regionButton->setIcon(YTRegions::iconForRegionId(region.id));
61 void StandardFeedsView::layoutCategories(const QList<YTCategory> &categories) {
62 QString regionId = YTRegions::currentRegionId();
63 foreach(YTCategory category, categories) {
64 // assign a parent to this VideoSource so it won't be deleted by MediaView
65 YTStandardFeed *feed = new YTStandardFeed(this);
66 feed->setCategory(category.term);
67 feed->setLabel(category.label);
68 feed->setRegionId(regionId);
69 feed->setFeedId("most_popular");
70 addVideoSourceWidget(feed);
74 void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) {
75 VideoSourceWidget *w = new VideoSourceWidget(videoSource);
76 connect(w, SIGNAL(activated(VideoSource*)),
77 SIGNAL(activated(VideoSource*)));
78 int i = layout->count();
79 layout->addWidget(w, i / cols, i % cols);
82 QList<YTStandardFeed*> StandardFeedsView::getMainFeeds() {
83 QList<YTStandardFeed*> feeds;
85 feeds << buildStardardFeed("most_popular", tr("Most Popular"))
86 << buildStardardFeed("recently_featured", tr("Featured"))
87 << buildStardardFeed("most_shared", tr("Most Shared"))
88 << buildStardardFeed("most_discussed", tr("Most Discussed"))
89 << buildStardardFeed("top_rated", tr("Top Rated"));
94 YTStandardFeed* StandardFeedsView::buildStardardFeed(QString feedId, QString label) {
95 YTStandardFeed *feed = new YTStandardFeed(this);
96 feed->setFeedId(feedId);
97 feed->setLabel(label);
98 feed->setRegionId(YTRegions::currentRegionId());
102 void StandardFeedsView::appear() {
105 QAction *regionAction = MainWindow::instance()->getRegionAction();
106 regionAction->setVisible(true);
109 void StandardFeedsView::disappear() {
110 QAction *regionAction = MainWindow::instance()->getRegionAction();
111 regionAction->setVisible(false);
114 void StandardFeedsView::selectWorldwideRegion() {
115 YTRegions::setRegion(YTRegions::worldwideRegion().id);
119 void StandardFeedsView::selectLocalRegion() {
120 YTRegions::setRegion(YTRegions::localRegion().id);