]> git.sur5r.net Git - minitube/blobdiff - src/homeview.cpp
Imported Upstream version 2.3
[minitube] / src / homeview.cpp
index 4ac091dbba8abc6bedbecc701e00d7832c32210d..1d56c26553dd6d3d802895ccc313f36b16e858e7 100644 (file)
@@ -1,15 +1,40 @@
+/* $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 "homeview.h"
 #include "segmentedcontrol.h"
 #include "searchview.h"
 #include "standardfeedsview.h"
-#include "userview.h"
+#include "channelview.h"
 #include "mainwindow.h"
 #include "mediaview.h"
 #include "ytstandardfeed.h"
+#include "iconutils.h"
+#include "channelaggregator.h"
+#ifdef APP_MAC
+#include "macutils.h"
+#endif
 
-HomeView::HomeView(QWidget *parent) : QWidget(parent) {
-    standardFeedsView = 0;
-    userView = 0;
+HomeView::HomeView(QWidget *parent) : QWidget(parent),
+    standardFeedsView(0),
+    channelsView(0) {
 
     QBoxLayout *layout = new QVBoxLayout(this);
     layout->setMargin(0);
@@ -28,7 +53,7 @@ HomeView::HomeView(QWidget *parent) : QWidget(parent) {
 }
 
 void HomeView::setupBar() {
-    bar = new SegmentedControl(this);
+    bar = new SegmentedControl();
 
     QAction *action = new QAction(tr("Search"), this);
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
@@ -43,22 +68,17 @@ void HomeView::setupBar() {
     connect(action, SIGNAL(triggered()), SLOT(showStandardFeeds()));
     bar->addAction(action);
 
-    /*
-    action = new QAction(tr("User"), this);
-    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
-    action->setStatusTip(tr("Your favorite videos, subscriptions and playlists"));
-    connect(action, SIGNAL(triggered()), SLOT(showUser()));
-    bar->addAction(action);
-    */
+    subscriptionsAction = new QAction(tr("Subscriptions"), this);
+    subscriptionsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
+    subscriptionsAction->setStatusTip(tr("Channel subscriptions"));
+    connect(subscriptionsAction, SIGNAL(triggered()), SLOT(showChannels()));
+    bar->addAction(subscriptionsAction);
+    connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
+            SLOT(unwatchedCountChanged(int)));
 
     foreach (QAction* action, bar->actions()) {
-        // action->setEnabled(false);
         addAction(action);
-        action->setAutoRepeat(false);
-        if (!action->shortcut().isEmpty())
-            action->setStatusTip(
-                        action->statusTip() + " (" +
-                        action->shortcut().toString(QKeySequence::NativeText) + ")");
+        IconUtils::setupAction(action);
     }
 }
 
@@ -70,8 +90,6 @@ void HomeView::showWidget(QWidget *widget) {
     stackedWidget->setCurrentWidget(widget);
     widget->setEnabled(true);
     QMetaObject::invokeMethod(widget, "appear");
-    bar->setCheckedAction(stackedWidget->currentIndex());
-    // autoChosenView = false;
     widget->setFocus();
 }
 
@@ -85,6 +103,7 @@ void HomeView::disappear() {
 
 void HomeView::showSearch() {
     showWidget(searchView);
+    bar->setCheckedAction(0);
 }
 
 void HomeView::showStandardFeeds() {
@@ -96,12 +115,31 @@ void HomeView::showStandardFeeds() {
         stackedWidget->addWidget(standardFeedsView);
     }
     showWidget(standardFeedsView);
+    bar->setCheckedAction(1);
+}
+
+void HomeView::showChannels() {
+    if (!channelsView) {
+        channelsView = new ChannelView();
+        connect(channelsView, SIGNAL(activated(VideoSource*)),
+                MainWindow::instance(),
+                SLOT(showMedia(VideoSource*)));
+        stackedWidget->addWidget(channelsView);
+    }
+    showWidget(channelsView);
+    bar->setCheckedAction(2);
 }
 
-void HomeView::showUser() {
-    if (!userView) {
-        userView = new UserView(this);
-        stackedWidget->addWidget(userView);
+void HomeView::unwatchedCountChanged(int count) {
+    QVariant v;
+    QString s;
+    if (count > 0) {
+        s = QString::number(count);
+        v = s;
     }
-    showWidget(userView);
+    subscriptionsAction->setProperty("notifyCount", v);
+    bar->update();
+#ifdef APP_MAC
+    mac::dockBadge(s);
+#endif
 }