File indexing completed on 2025-02-23 04:35:14

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "channelcontroller.h"
0005 
0006 #include "plasmatube.h"
0007 
0008 #include <QFutureWatcher>
0009 
0010 ChannelController::ChannelController(QObject *parent)
0011     : QObject(parent)
0012 {
0013 }
0014 
0015 void ChannelController::loadChannel(const QString &channelId)
0016 {
0017     m_watcher = new QFutureWatcher<QInvidious::ChannelResult>();
0018 
0019     auto future = PlasmaTube::instance().sourceManager()->selectedSource()->api()->requestChannelInfo(channelId);
0020     m_watcher->setFuture(future);
0021 
0022     connect(m_watcher, &QFutureWatcherBase::finished, this, [this] {
0023         auto result = m_watcher->result();
0024         if (auto channel = std::get_if<QInvidious::Channel>(&result)) {
0025             m_channel = *channel;
0026             Q_EMIT channelLoaded();
0027         } else if (auto error = std::get_if<QInvidious::Error>(&result)) {
0028             // TODO: Log error
0029         }
0030 
0031         m_watcher->deleteLater();
0032         m_watcher = nullptr;
0033     });
0034 }
0035 
0036 QString ChannelController::name() const
0037 {
0038     return m_channel.name();
0039 }
0040 
0041 QString ChannelController::avatar() const
0042 {
0043     return m_channel.avatar();
0044 }
0045 
0046 QString ChannelController::banner() const
0047 {
0048     return m_channel.banner();
0049 }
0050 
0051 QString ChannelController::description() const
0052 {
0053     return m_channel.description();
0054 }
0055 
0056 int ChannelController::subCount() const
0057 {
0058     return m_channel.subCount();
0059 }
0060 
0061 #include "moc_channelcontroller.cpp"