]> git.sur5r.net Git - minitube/blobdiff - src/standardfeedsview.cpp
Merge tag 'upstream/2.5.1'
[minitube] / src / standardfeedsview.cpp
index 1aae3e370edf0ce5651c04b1c489f6cbe85f19f5..799e54ddef9e7c2db09d1d793ce917f182602284 100644 (file)
@@ -1,17 +1,36 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+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 <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include "standardfeedsview.h"
 #include "videosourcewidget.h"
 #include "ytcategories.h"
 #include "ytstandardfeed.h"
 #include "ytregions.h"
 #include "mainwindow.h"
+#include "painterutils.h"
 
 namespace The {
 QHash<QString, QAction*>* globalActions();
 }
 
-static const int cols = 5;
-
-StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent),
+StandardFeedsView::StandardFeedsView(QWidget *parent) : View(parent),
     layout(0) {
     QPalette p = palette();
     p.setBrush(QPalette::Window, Qt::black);
@@ -31,6 +50,7 @@ StandardFeedsView::StandardFeedsView(QWidget *parent) : QWidget(parent),
 }
 
 void StandardFeedsView::load() {
+    setUpdatesEnabled(false);
     YTCategories *youTubeCategories = new YTCategories(this);
     connect(youTubeCategories, SIGNAL(categoriesLoaded(const QList<YTCategory> &)),
             SLOT(layoutCategories(const QList<YTCategory> &)));
@@ -53,9 +73,9 @@ void StandardFeedsView::load() {
         addVideoSourceWidget(feed);
 
     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<YTCategory> &categories) {
@@ -69,6 +89,7 @@ void StandardFeedsView::layoutCategories(const QList<YTCategory> &categories) {
         feed->setFeedId("most_popular");
         addVideoSourceWidget(feed);
     }
+    if (categories.size() > 1) setUpdatesEnabled(true);
 }
 
 void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) {
@@ -76,39 +97,46 @@ void StandardFeedsView::addVideoSourceWidget(VideoSource *videoSource) {
     connect(w, SIGNAL(activated(VideoSource*)),
             SIGNAL(activated(VideoSource*)));
     int i = layout->count();
+    static const int cols = 4;
     layout->addWidget(w, i / cols, i % cols);
 }
 
 QList<YTStandardFeed*> StandardFeedsView::getMainFeeds() {
     QList<YTStandardFeed*> feeds;
 
-    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"));
+    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"))
+          // << buildStardardFeed("most_popular", tr("All Time Popular"), "all_time");
 
     return feeds;
 }
 
-YTStandardFeed* StandardFeedsView::buildStardardFeed(QString feedId, QString label) {
+YTStandardFeed* StandardFeedsView::buildStardardFeed(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()->showActionInStatusBar(regionAction, true);
 }
 
 void StandardFeedsView::disappear() {
     QAction *regionAction = MainWindow::instance()->getRegionAction();
-    regionAction->setVisible(false);
+    MainWindow::instance()->showActionInStatusBar(regionAction, false);
 }
 
 void StandardFeedsView::selectWorldwideRegion() {
@@ -121,4 +149,7 @@ void StandardFeedsView::selectLocalRegion() {
     load();
 }
 
+void StandardFeedsView::paintEvent(QPaintEvent *event) {
+    QWidget::paintEvent(event);
+}