]> git.sur5r.net Git - minitube/blobdiff - src/channelview.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / channelview.cpp
index 6203dbeaea73213eed1dff8edbf3c900152170ab..c9e1e8bf4348ac4f5c33858dc436d582a59f6b44 100644 (file)
@@ -19,29 +19,31 @@ along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
 $END_LICENSE */
 
 #include "channelview.h"
-#include "ytchannel.h"
-#include "ytsearch.h"
-#include "searchparams.h"
-#include "channelmodel.h"
+#include "aggregatevideosource.h"
+#include "channelaggregator.h"
 #include "channelitemdelegate.h"
+#include "channelmodel.h"
 #include "database.h"
-#include "ytsearch.h"
-#include "channelaggregator.h"
-#include "aggregatevideosource.h"
-#include "mainwindow.h"
 #include "iconutils.h"
+#include "mainwindow.h"
+#include "searchparams.h"
+#include "ytchannel.h"
+#include "ytsearch.h"
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
 #include "channellistview.h"
 
-static const char *sortByKey = "subscriptionsSortBy";
-static const char *showUpdatedKey = "subscriptionsShowUpdated";
+#include "ivchannelsource.h"
+#include "videoapi.h"
+#include "ytjschannelsource.h"
 
-ChannelView::ChannelView(QWidget *parent) : View(parent),
-    showUpdated(false),
-    sortBy(SortByName) {
+namespace {
+const QString sortByKey = "subscriptionsSortBy";
+const QString showUpdatedKey = "subscriptionsShowUpdated";
+} // namespace
 
+ChannelView::ChannelView(QWidget *parent) : View(parent), showUpdated(false), sortBy(SortByName) {
     QBoxLayout *layout = new QVBoxLayout(this);
     layout->setMargin(0);
     layout->setSpacing(0);
@@ -52,7 +54,8 @@ ChannelView::ChannelView(QWidget *parent) : View(parent),
     channelsModel = new ChannelModel(this);
     listView->setModel(channelsModel);
 
-    connect(listView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemActivated(const QModelIndex &)));
+    connect(listView, SIGNAL(clicked(const QModelIndex &)),
+            SLOT(itemActivated(const QModelIndex &)));
     connect(listView, SIGNAL(contextMenu(QPoint)), SLOT(showContextMenu(QPoint)));
     connect(listView, SIGNAL(viewportEntered()), channelsModel, SLOT(clearHover()));
 
@@ -60,8 +63,8 @@ ChannelView::ChannelView(QWidget *parent) : View(parent),
 
     setupActions();
 
-    connect(ChannelAggregator::instance(), SIGNAL(channelChanged(YTChannel*)),
-            channelsModel, SLOT(updateChannel(YTChannel*)));
+    connect(ChannelAggregator::instance(), SIGNAL(channelChanged(YTChannel *)), channelsModel,
+            SLOT(updateChannel(YTChannel *)));
     connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)),
             SLOT(unwatchedCountChanged(int)));
 
@@ -71,6 +74,8 @@ ChannelView::ChannelView(QWidget *parent) : View(parent),
 void ChannelView::setupActions() {
     QSettings settings;
 
+    statusActions << MainWindow::instance()->getAction("importSubscriptions");
+
     sortBy = static_cast<SortBy>(settings.value(sortByKey, SortByName).toInt());
 
     QMenu *sortMenu = new QMenu(this);
@@ -113,7 +118,7 @@ void ChannelView::setupActions() {
 
     QToolButton *sortButton = new QToolButton(this);
     sortButton->setText(tr("Sort by"));
-    sortButton->setIcon(IconUtils::icon("sort"));
+    IconUtils::setIcon(sortButton, "sort");
     sortButton->setIconSize(QSize(16, 16));
     sortButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     sortButton->setPopupMode(QToolButton::InstantPopup);
@@ -123,39 +128,42 @@ 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 = new QAction(tr("Mark all as watched"), this);
+    IconUtils::setIcon(markAsWatchedAction, "mark-watched");
     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);
+    QAction *showUpdatedAction = new QAction(tr("Show Updated"), this);
+    IconUtils::setIcon(showUpdatedAction, "show-updated");
     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) {
+    for (QAction *action : statusActions) {
         window()->addAction(action);
-        IconUtils::setupAction(action);
+        MainWindow::instance()->setupAction(action);
     }
 }
 
+QString ChannelView::noSubscriptionsMessage() {
+    return tr("You have no subscriptions. "
+              "Use the star symbol to subscribe to channels.");
+}
+
 void ChannelView::appear() {
-    updateQuery();
-    foreach (QAction* action, statusActions)
-        MainWindow::instance()->showActionInStatusBar(action, true);
+    updateQuery(true);
+    MainWindow::instance()->showActionsInStatusBar(statusActions, true);
     setFocus();
     ChannelAggregator::instance()->start();
 }
 
 void ChannelView::disappear() {
-    foreach (QAction* action, statusActions)
-        MainWindow::instance()->showActionInStatusBar(action, false);
+    MainWindow::instance()->showActionsInStatusBar(statusActions, false);
 }
 
 void ChannelView::itemActivated(const QModelIndex &index) {
@@ -166,16 +174,24 @@ void ChannelView::itemActivated(const QModelIndex &index) {
         params->setChannelId(channel->getChannelId());
         params->setSortBy(SearchParams::SortByNewest);
         params->setTransient(true);
-        YTSearch *videoSource = new YTSearch(params, this);
-        videoSource->setAsyncDetails(true);
-        emit activated(videoSource);
+        VideoSource *vs = nullptr;
+        if (VideoAPI::impl() == VideoAPI::YT3) {
+            YTSearch *videoSource = new YTSearch(params);
+            videoSource->setAsyncDetails(true);
+            vs = videoSource;
+        } else if (VideoAPI::impl() == VideoAPI::IV) {
+            vs = new IVChannelSource(params);
+        } else if (VideoAPI::impl() == VideoAPI::JS) {
+            vs = new YTJSChannelSource(params);
+        }
+        emit activated(vs);
         channel->updateWatched();
     } else if (itemType == ChannelModel::ItemAggregate) {
-        AggregateVideoSource *videoSource = new AggregateVideoSource(this);
+        AggregateVideoSource *videoSource = new AggregateVideoSource();
         videoSource->setName(tr("All Videos"));
         emit activated(videoSource);
     } else if (itemType == ChannelModel::ItemUnwatched) {
-        AggregateVideoSource *videoSource = new AggregateVideoSource(this);
+        AggregateVideoSource *videoSource = new AggregateVideoSource();
         videoSource->setName(tr("Unwatched Videos"));
         videoSource->setUnwatched(true);
         emit activated(videoSource);
@@ -194,22 +210,23 @@ void ChannelView::showContextMenu(const QPoint &point) {
     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()));
+        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);
+    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()));
+    connect(unsubscribeAction, SIGNAL(triggered()), ChannelAggregator::instance(),
+            SLOT(updateUnwatchedCount()));
 
     menu.exec(mapToGlobal(point));
 }
@@ -224,11 +241,14 @@ void ChannelView::toggleShowUpdated(bool enable) {
 void ChannelView::updateQuery(bool transition) {
     Q_UNUSED(transition);
     listView->clearErrorMessage();
-    if (!Database::exists()) return;
+
+    if (!Database::exists()) {
+        listView->setErrorMessage(noSubscriptionsMessage());
+        return;
+    }
 
     QString sql = "select user_id from subscriptions";
-    if (showUpdated)
-        sql += " where notify_count>0";
+    if (showUpdated) sql += " where notify_count>0";
 
     switch (sortBy) {
     case SortByUpdated:
@@ -249,8 +269,7 @@ void ChannelView::updateQuery(bool transition) {
     }
 
 #ifdef APP_EXTRA
-    if (transition)
-        Extra::fadeInWidget(this, this);
+    if (transition) Extra::fadeInWidget(this, this);
 #endif
 
     channelsModel->setQuery(sql, Database::instance().getConnection());
@@ -262,8 +281,7 @@ void ChannelView::updateQuery(bool transition) {
         if (showUpdated)
             msg = tr("There are no updated subscriptions at this time.");
         else
-            msg = tr("You have no subscriptions. "
-                     "Use the star symbol to subscribe to channels.");
+            msg = noSubscriptionsMessage();
         listView->setErrorMessage(msg);
     }
 }