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

0001 // SPDX-FileCopyrightText: 2021 Linus Jahn <lnj@kaidan.im>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "subscriptionwatcher.h"
0005 
0006 #include "plasmatube.h"
0007 
0008 SubscriptionWatcher::SubscriptionWatcher(QObject *parent)
0009     : QObject(parent)
0010 {
0011     connect(PlasmaTube::instance().selectedSource(), &VideoSource::subscriptionsChanged, this, [=] {
0012         if (m_channelId.isEmpty()) {
0013             return;
0014         }
0015         setIsSubscribed();
0016     });
0017 }
0018 
0019 QString SubscriptionWatcher::channelId() const
0020 {
0021     return m_channelId;
0022 }
0023 
0024 void SubscriptionWatcher::setChannelId(const QString &channelId)
0025 {
0026     if (m_channelId != channelId) {
0027         m_channelId = channelId;
0028         Q_EMIT channelIdChanged();
0029 
0030         setIsSubscribed();
0031     }
0032 }
0033 
0034 bool SubscriptionWatcher::isSubscribed() const
0035 {
0036     return m_isSubscribed;
0037 }
0038 
0039 void SubscriptionWatcher::setIsSubscribed(bool isSubscribed)
0040 {
0041     if (m_isSubscribed != isSubscribed) {
0042         m_isSubscribed = isSubscribed;
0043         Q_EMIT isSubscribedChanged();
0044     }
0045 }
0046 
0047 void SubscriptionWatcher::setIsSubscribed(std::optional<bool> isSubscribed)
0048 {
0049     setIsSubscribed(isSubscribed.value_or(false));
0050 }
0051 
0052 void SubscriptionWatcher::setIsSubscribed()
0053 {
0054     setIsSubscribed(PlasmaTube::instance().selectedSource()->isSubscribedToChannel(m_channelId));
0055 }
0056 
0057 #include "moc_subscriptionwatcher.cpp"