X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fstandardfeedsview.cpp;h=2fb697d9bbe3c72e044324bbeb455b348c9845cf;hb=2e524d4ed49280113efb6318b32d7f8931c5ccbd;hp=1aae3e370edf0ce5651c04b1c489f6cbe85f19f5;hpb=a8e005af0aa72f809f823bbd741bb3d0def00ced;p=minitube diff --git a/src/standardfeedsview.cpp b/src/standardfeedsview.cpp index 1aae3e3..2fb697d 100644 --- a/src/standardfeedsview.cpp +++ b/src/standardfeedsview.cpp @@ -1,66 +1,92 @@ +/* $BEGIN_LICENSE + +This file is part of Minitube. +Copyright 2009, Flavio Tordini + +Minitube is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Minitube is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Minitube. If not, see . + +$END_LICENSE */ + #include "standardfeedsview.h" +#include "mainwindow.h" +#include "painterutils.h" #include "videosourcewidget.h" #include "ytcategories.h" -#include "ytstandardfeed.h" #include "ytregions.h" -#include "mainwindow.h" +#include "ytstandardfeed.h" -namespace The { -QHash* globalActions(); -} +#include "ivvideolist.h" +#include "videoapi.h" -static const int cols = 5; +#include "ytjstrending.h" -StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent), - layout(0) { - QPalette p = palette(); - p.setBrush(QPalette::Window, Qt::black); - setPalette(p); +StandardFeedsView::StandardFeedsView(QWidget *parent) : View(parent), layout(0) { + setBackgroundRole(QPalette::Base); setAutoFillBackground(true); - connect(The::globalActions()->value("worldwide-region"), SIGNAL(triggered()), + connect(MainWindow::instance()->getAction("worldwideRegion"), SIGNAL(triggered()), SLOT(selectWorldwideRegion())); - connect(The::globalActions()->value("local-region"), SIGNAL(triggered()), + connect(MainWindow::instance()->getAction("localRegion"), SIGNAL(triggered()), SLOT(selectLocalRegion())); - - /* - QAction *regionAction = MainWindow::instance()->getRegionAction(); - connect(regionAction, SIGNAL(changed()), SLOT(load())); - */ } void StandardFeedsView::load() { - YTCategories *youTubeCategories = new YTCategories(this); - connect(youTubeCategories, SIGNAL(categoriesLoaded(const QList &)), - SLOT(layoutCategories(const QList &))); - youTubeCategories->loadCategories(); + setUpdatesEnabled(false); + resetLayout(); - if (layout) { - while (QLayoutItem *item = layout->takeAt(0)) { - delete item->widget(); - delete item; - } - delete layout; - } + YTRegion region = YTRegions::currentRegion(); - layout = new QGridLayout(this); - layout->setMargin(0); - layout->setSpacing(1); + // TODO consolidate in YT + if (VideoAPI::impl() == VideoAPI::YT3) { + YTCategories *youTubeCategories = new YTCategories(this); + connect(youTubeCategories, SIGNAL(categoriesLoaded(const QVector &)), + SLOT(layoutCategories(const QVector &))); + youTubeCategories->loadCategories(); + addVideoSourceWidget(buildStandardFeed("most_popular", tr("Most Popular"))); + } else if (VideoAPI::impl() == VideoAPI::JS) { + const QMap pages = {{"default", tr("Trending")}, + {"music", tr("Music")}, + {"movies", tr("Movies")}, + {"gaming", tr("Gaming")}}; + auto i = pages.constBegin(); + while (i != pages.constEnd()) { + addVideoSourceWidget( + new YTJSTrending(i.value(), {{"page", i.key()}, {"geoLocation", region.id}})); + ++i; + } - QList feeds = getMainFeeds(); - foreach(YTStandardFeed *feed, feeds) - addVideoSourceWidget(feed); + setUpdatesEnabled(true); + } else { + QString regionParam = "region=" + region.id; + addVideoSourceWidget(new IVVideoList("popular?" + regionParam, tr("Most Popular"))); + addVideoSourceWidget(new IVVideoList("trending?" + regionParam, tr("Trending"))); + addVideoSourceWidget(new IVVideoList("trending?type=music&" + regionParam, tr("Music"))); + addVideoSourceWidget(new IVVideoList("trending?type=news&" + regionParam, tr("News"))); + addVideoSourceWidget(new IVVideoList("trending?type=movies&" + regionParam, tr("Movies"))); + addVideoSourceWidget(new IVVideoList("trending?type=gaming&" + regionParam, tr("Gaming"))); + setUpdatesEnabled(true); + } - YTRegion region = YTRegions::currentRegion(); - QToolButton *regionButton = MainWindow::instance()->getRegionButton(); - regionButton->setText(region.name); - regionButton->setIcon(YTRegions::iconForRegionId(region.id)); + QAction *regionAction = MainWindow::instance()->getRegionAction(); + regionAction->setText(region.name); + regionAction->setIcon(YTRegions::iconForRegionId(region.id)); } -void StandardFeedsView::layoutCategories(const QList &categories) { +void StandardFeedsView::layoutCategories(const QVector &categories) { QString regionId = YTRegions::currentRegionId(); - foreach(YTCategory category, categories) { + for (const YTCategory &category : categories) { // assign a parent to this VideoSource so it won't be deleted by MediaView YTStandardFeed *feed = new YTStandardFeed(this); feed->setCategory(category.term); @@ -69,50 +95,83 @@ void StandardFeedsView::layoutCategories(const QList &categories) { feed->setFeedId("most_popular"); addVideoSourceWidget(feed); } + if (categories.size() > 1) setUpdatesEnabled(true); } void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) { VideoSourceWidget *w = new VideoSourceWidget(videoSource); - connect(w, SIGNAL(activated(VideoSource*)), - SIGNAL(activated(VideoSource*))); + connect(w, SIGNAL(activated(VideoSource *)), SIGNAL(activated(VideoSource *))); + connect(w, SIGNAL(unavailable(VideoSourceWidget *)), + SLOT(removeVideoSourceWidget(VideoSourceWidget *))); int i = layout->count(); + const int cols = VideoAPI::impl() == VideoAPI::YT3 ? 5 : 2; layout->addWidget(w, i / cols, i % cols); } -QList StandardFeedsView::getMainFeeds() { - QList feeds; +void StandardFeedsView::removeVideoSourceWidget(VideoSourceWidget *videoSourceWidget) { + qDebug() << videoSourceWidget->getVideoSource()->getName(); + layout->removeWidget(videoSourceWidget); + videoSourceWidget->deleteLater(); + + const int layoutCount = layout->count(); + QVector items; + items.reserve(layoutCount); - feeds << buildStardardFeed("most_popular", tr("Most Popular")) - << buildStardardFeed("recently_featured", tr("Featured")) - << buildStardardFeed("most_shared", tr("Most Shared")) - << buildStardardFeed("most_discussed", tr("Most Discussed")) - << buildStardardFeed("top_rated", tr("Top Rated")); + for (int i = layoutCount - 1; i >= 0; i--) { + QLayoutItem *item = layout->takeAt(i); + if (item && item->widget()) items.append(item); + } - return feeds; + const int itemCount = items.size(); + const int cols = 2; // itemCount / 3; + for (int i = itemCount - 1; i >= 0; i--) { + QLayoutItem *item = items.at(i); + int index = itemCount - 1 - i; + layout->addItem(item, index / cols, index % cols); + } } -YTStandardFeed* StandardFeedsView::buildStardardFeed(QString feedId, QString label) { +void StandardFeedsView::resetLayout() { + if (layout) { + while (QLayoutItem *item = layout->takeAt(0)) { + delete item->widget(); + delete item; + } + delete layout; + } + + layout = new QGridLayout(this); + layout->setMargin(0); + layout->setSpacing(0); +} + +YTStandardFeed * +StandardFeedsView::buildStandardFeed(const QString &feedId, const QString &label, QString time) { YTStandardFeed *feed = new YTStandardFeed(this); feed->setFeedId(feedId); feed->setLabel(label); + if (!time.isEmpty()) feed->setTime(time); feed->setRegionId(YTRegions::currentRegionId()); return feed; } void StandardFeedsView::appear() { - setFocus(); - if (!layout) load(); + if (!layout) { + update(); + qApp->processEvents(); + load(); + } QAction *regionAction = MainWindow::instance()->getRegionAction(); - regionAction->setVisible(true); + MainWindow::instance()->showActionsInStatusBar({regionAction}, true); } void StandardFeedsView::disappear() { QAction *regionAction = MainWindow::instance()->getRegionAction(); - regionAction->setVisible(false); + MainWindow::instance()->showActionsInStatusBar({regionAction}, false); } void StandardFeedsView::selectWorldwideRegion() { - YTRegions::setRegion(YTRegions::worldwideRegion().id); + YTRegions::setRegion(YTRegions::defaultRegion().id); load(); } @@ -121,4 +180,6 @@ void StandardFeedsView::selectLocalRegion() { load(); } - +void StandardFeedsView::paintEvent(QPaintEvent *event) { + QWidget::paintEvent(event); +}