summaryrefslogtreecommitdiffstats
path: root/xbmc/pvr/channels/PVRChannelGroupSettings.cpp
blob: 3cbc0bdfa9925db8f32d2ed60a9e3c5953457aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *  Copyright (C) 2012-2021 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "PVRChannelGroupSettings.h"

#include "ServiceBroker.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
#include "settings/Settings.h"
#include "settings/lib/Setting.h"

using namespace PVR;

CPVRChannelGroupSettings::CPVRChannelGroupSettings()
  : m_settings({CSettings::SETTING_PVRMANAGER_SYNCCHANNELGROUPS,
                CSettings::SETTING_PVRMANAGER_BACKENDCHANNELORDER,
                CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERS,
                CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERSALWAYS,
                CSettings::SETTING_PVRMANAGER_STARTGROUPCHANNELNUMBERSFROMONE})
{
  UpdateSyncChannelGroups();
  UpdateUseBackendChannelOrder();
  UpdateUseBackendChannelNumbers();
  UpdateStartGroupChannelNumbersFromOne();

  m_settings.RegisterCallback(this);
}

CPVRChannelGroupSettings::~CPVRChannelGroupSettings()
{
  m_settings.UnregisterCallback(this);
}

void CPVRChannelGroupSettings::OnSettingChanged(const std::shared_ptr<const CSetting>& setting)
{
  if (!setting)
    return;

  const std::string& settingId = setting->GetId();
  if (settingId == CSettings::CSettings::SETTING_PVRMANAGER_SYNCCHANNELGROUPS)
  {
    if (SyncChannelGroups() != UpdateSyncChannelGroups())
    {
      for (const auto& callback : m_callbacks)
        callback->SyncChannelGroupsChanged();
    }
  }
  else if (settingId == CSettings::CSettings::SETTING_PVRMANAGER_BACKENDCHANNELORDER)
  {
    if (UseBackendChannelOrder() != UpdateUseBackendChannelOrder())
    {
      for (const auto& callback : m_callbacks)
        callback->UseBackendChannelOrderChanged();
    }
  }
  else if (settingId == CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERS ||
           settingId == CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERSALWAYS)
  {
    if (UseBackendChannelNumbers() != UpdateUseBackendChannelNumbers())
    {
      for (const auto& callback : m_callbacks)
        callback->UseBackendChannelNumbersChanged();
    }
  }
  else if (settingId == CSettings::SETTING_PVRMANAGER_STARTGROUPCHANNELNUMBERSFROMONE)
  {
    if (StartGroupChannelNumbersFromOne() != UpdateStartGroupChannelNumbersFromOne())
    {
      for (const auto& callback : m_callbacks)
        callback->StartGroupChannelNumbersFromOneChanged();
    }
  }
}

void CPVRChannelGroupSettings::RegisterCallback(IChannelGroupSettingsCallback* callback)
{
  m_callbacks.insert(callback);
}

void CPVRChannelGroupSettings::UnregisterCallback(IChannelGroupSettingsCallback* callback)
{
  m_callbacks.erase(callback);
}

bool CPVRChannelGroupSettings::UpdateSyncChannelGroups()
{
  m_bSyncChannelGroups = m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_SYNCCHANNELGROUPS);
  return m_bSyncChannelGroups;
}

bool CPVRChannelGroupSettings::UpdateUseBackendChannelOrder()
{
  m_bUseBackendChannelOrder =
      m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_BACKENDCHANNELORDER);
  return m_bUseBackendChannelOrder;
}

bool CPVRChannelGroupSettings::UpdateUseBackendChannelNumbers()
{
  const int enabledClientAmount = CServiceBroker::GetPVRManager().Clients()->EnabledClientAmount();
  m_bUseBackendChannelNumbers =
      m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERS) &&
      (enabledClientAmount == 1 ||
       (m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_USEBACKENDCHANNELNUMBERSALWAYS) &&
        enabledClientAmount > 1));
  return m_bUseBackendChannelNumbers;
}

bool CPVRChannelGroupSettings::UpdateStartGroupChannelNumbersFromOne()
{
  m_bStartGroupChannelNumbersFromOne =
      m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_STARTGROUPCHANNELNUMBERSFROMONE) &&
      !UseBackendChannelNumbers();
  return m_bStartGroupChannelNumbersFromOne;
}