]> git.sur5r.net Git - minitube/blobdiff - src/channelview.cpp
Imported Upstream version 2.4
[minitube] / src / channelview.cpp
index eba059135686298690a3ae9b96d6edaebc09330f..893f891288ee2764f19e98215898023ce0dbd7f5 100644 (file)
@@ -19,7 +19,7 @@ along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
 $END_LICENSE */
 
 #include "channelview.h"
-#include "ytuser.h"
+#include "ytchannel.h"
 #include "ytsearch.h"
 #include "searchparams.h"
 #include "channelmodel.h"
@@ -30,7 +30,7 @@ $END_LICENSE */
 #include "aggregatevideosource.h"
 #include "painterutils.h"
 #include "mainwindow.h"
-#include "utils.h"
+#include "iconutils.h"
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
@@ -84,8 +84,8 @@ ChannelView::ChannelView(QWidget *parent) : QListView(parent),
 
     setupActions();
 
-    connect(ChannelAggregator::instance(), SIGNAL(channelChanged(YTUser*)),
-            channelsModel, SLOT(updateChannel(YTUser*)));
+    connect(ChannelAggregator::instance(), SIGNAL(channelChanged(YTChannel*)),
+            channelsModel, SLOT(updateChannel(YTChannel*)));
     connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
             SLOT(unwatchedCountChanged(int)));
 
@@ -95,23 +95,7 @@ ChannelView::ChannelView(QWidget *parent) : QListView(parent),
 void ChannelView::setupActions() {
     QSettings settings;
 
-    markAsWatchedAction = new QAction(
-                Utils::icon("mark-watched"), tr("Mark all as watched"), this);
-    markAsWatchedAction->setEnabled(false);
-    markAsWatchedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
-    connect(markAsWatchedAction, SIGNAL(triggered()), SLOT(markAllAsWatched()));
-    statusActions << markAsWatchedAction;
-
-    showUpdated = settings.value(showUpdatedKey, false).toBool();
-    QAction *showUpdatedAction = new QAction(
-                Utils::icon("show-updated"), tr("Show Updated"), this);
-    showUpdatedAction->setCheckable(true);
-    showUpdatedAction->setChecked(showUpdated);
-    showUpdatedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
-    connect(showUpdatedAction, SIGNAL(toggled(bool)), SLOT(toggleShowUpdated(bool)));
-    statusActions << showUpdatedAction;
-
-    SortBy sortBy = static_cast<SortBy>(settings.value(sortByKey, SortByName).toInt());
+    sortBy = static_cast<SortBy>(settings.value(sortByKey, SortByName).toInt());
 
     QMenu *sortMenu = new QMenu(this);
     QActionGroup *sortGroup = new QActionGroup(this);
@@ -153,7 +137,7 @@ void ChannelView::setupActions() {
 
     QToolButton *sortButton = new QToolButton(this);
     sortButton->setText(tr("Sort by"));
-    sortButton->setIcon(Utils::icon("sort"));
+    sortButton->setIcon(IconUtils::icon("sort"));
     sortButton->setIconSize(QSize(16, 16));
     sortButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     sortButton->setPopupMode(QToolButton::InstantPopup);
@@ -163,9 +147,25 @@ void ChannelView::setupActions() {
     widgetAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
     statusActions << widgetAction;
 
+    markAsWatchedAction = new QAction(
+                IconUtils::icon("mark-watched"), tr("Mark all as watched"), this);
+    markAsWatchedAction->setEnabled(false);
+    markAsWatchedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
+    connect(markAsWatchedAction, SIGNAL(triggered()), SLOT(markAllAsWatched()));
+    statusActions << markAsWatchedAction;
+
+    showUpdated = settings.value(showUpdatedKey, false).toBool();
+    QAction *showUpdatedAction = new QAction(
+                IconUtils::icon("show-updated"), tr("Show Updated"), this);
+    showUpdatedAction->setCheckable(true);
+    showUpdatedAction->setChecked(showUpdated);
+    showUpdatedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
+    connect(showUpdatedAction, SIGNAL(toggled(bool)), SLOT(toggleShowUpdated(bool)));
+    statusActions << showUpdatedAction;
+
     foreach (QAction *action, statusActions) {
         window()->addAction(action);
-        Utils::setupAction(action);
+        IconUtils::setupAction(action);
     }
 }
 
@@ -174,14 +174,22 @@ void ChannelView::appear() {
     foreach (QAction* action, statusActions)
         MainWindow::instance()->showActionInStatusBar(action, true);
     setFocus();
-    ChannelAggregator::instance()->run();
+    ChannelAggregator::instance()->start();
 }
 
 void ChannelView::disappear() {
+    ChannelAggregator::instance()->stop();
     foreach (QAction* action, statusActions)
         MainWindow::instance()->showActionInStatusBar(action, false);
 }
 
+void ChannelView::mousePressEvent(QMouseEvent *event) {
+    if (event->button() == Qt::RightButton)
+        showContextMenu(event->pos());
+    else
+        QListView::mousePressEvent(event);
+}
+
 void ChannelView::mouseMoveEvent(QMouseEvent *event) {
     QListView::mouseMoveEvent(event);
     const QModelIndex index = indexAt(event->pos());
@@ -201,14 +209,15 @@ void ChannelView::itemEntered(const QModelIndex &index) {
 void ChannelView::itemActivated(const QModelIndex &index) {
     ChannelModel::ItemTypes itemType = channelsModel->typeForIndex(index);
     if (itemType == ChannelModel::ItemChannel) {
-        YTUser *user = channelsModel->userForIndex(index);
+        YTChannel *channel = channelsModel->channelForIndex(index);
         SearchParams *params = new SearchParams();
-        params->setAuthor(user->getUserId());
+        params->setChannelId(channel->getChannelId());
         params->setSortBy(SearchParams::SortByNewest);
         params->setTransient(true);
         YTSearch *videoSource = new YTSearch(params, this);
+        videoSource->setAsyncDetails(true);
         emit activated(videoSource);
-        user->updateWatched();
+        channel->updateWatched();
     } else if (itemType == ChannelModel::ItemAggregate) {
         AggregateVideoSource *videoSource = new AggregateVideoSource(this);
         videoSource->setName(tr("All Videos"));
@@ -221,6 +230,38 @@ void ChannelView::itemActivated(const QModelIndex &index) {
     }
 }
 
+void ChannelView::showContextMenu(const QPoint &point) {
+    const QModelIndex index = indexAt(point);
+    if (!index.isValid()) return;
+
+    YTChannel *channel = channelsModel->channelForIndex(index);
+    if (!channel) return;
+
+    unsetCursor();
+
+    QMenu menu;
+
+    if (channel->getNotifyCount() > 0) {
+        QAction *markAsWatchedAction = menu.addAction(tr("Mark as Watched"), channel, SLOT(updateWatched()));
+        connect(markAsWatchedAction, SIGNAL(triggered()),
+                ChannelAggregator::instance(), SLOT(updateUnwatchedCount()));
+        menu.addSeparator();
+    }
+
+    /*
+    // TODO
+    QAction *notificationsAction = menu.addAction(tr("Receive Notifications"), user, SLOT(unsubscribe()));
+    notificationsAction->setCheckable(true);
+    notificationsAction->setChecked(true);
+    */
+
+    QAction *unsubscribeAction = menu.addAction(tr("Unsubscribe"), channel, SLOT(unsubscribe()));
+    connect(unsubscribeAction, SIGNAL(triggered()),
+            ChannelAggregator::instance(), SLOT(updateUnwatchedCount()));
+
+    menu.exec(mapToGlobal(point));
+}
+
 void ChannelView::paintEvent(QPaintEvent *event) {
     if (model()->rowCount() < 3) {
         QString msg;