]> git.sur5r.net Git - minitube/blobdiff - src/channelview.cpp
Imported Upstream version 2.2
[minitube] / src / channelview.cpp
index eba059135686298690a3ae9b96d6edaebc09330f..f5cb3ac57913a2c5b1b98c291ea3b89ac692f306 100644 (file)
@@ -95,22 +95,6 @@ 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());
 
     QMenu *sortMenu = new QMenu(this);
@@ -163,6 +147,22 @@ void ChannelView::setupActions() {
     widgetAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
     statusActions << widgetAction;
 
+    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;
+
     foreach (QAction *action, statusActions) {
         window()->addAction(action);
         Utils::setupAction(action);
@@ -182,6 +182,13 @@ void ChannelView::disappear() {
         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());
@@ -221,6 +228,38 @@ void ChannelView::itemActivated(const QModelIndex &index) {
     }
 }
 
+void ChannelView::showContextMenu(const QPoint &point) {
+    const QModelIndex index = indexAt(point);
+    if (!index.isValid()) return;
+
+    YTUser *user = channelsModel->userForIndex(index);
+    if (!user) return;
+
+    unsetCursor();
+
+    QMenu menu;
+
+    if (user->getNotifyCount() > 0) {
+        QAction *markAsWatchedAction = menu.addAction(tr("Mark as Watched"), user, 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"), user, 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;