| 1 |
/* |
| 2 |
* Copyright (C) 2005-2021 Team Kodi (https://kodi.tv) |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
* See LICENSE.md for more information. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "GUIDialogRecordSettings.h" |
| 9 |
#include "timers.h" |
| 10 |
#include "utils.h" |
| 11 |
#include "DateTime.h" |
| 12 |
|
| 13 |
#include <kodi/General.h> |
| 14 |
#include <kodi/tools/StringUtils.h> |
| 15 |
|
| 16 |
/* Dialog item identifiers */ |
| 17 |
#define BUTTON_OK 1 |
| 18 |
#define BUTTON_CANCEL 2 |
| 19 |
|
| 20 |
#define SPIN_CONTROL_FREQUENCY 10 |
| 21 |
#define SPIN_CONTROL_AIRTIME 11 |
| 22 |
#define SPIN_CONTROL_CHANNELS 12 |
| 23 |
#define SPIN_CONTROL_KEEP 13 |
| 24 |
#define SPIN_CONTROL_PRERECORD 14 |
| 25 |
#define SPIN_CONTROL_POSTRECORD 15 |
| 26 |
|
| 27 |
#define LABEL_PROGRAM_TITLE 20 |
| 28 |
#define LABEL_PROGRAM_START_TIME 21 |
| 29 |
#define LABEL_PROGRAM_CHANNEL 22 |
| 30 |
|
| 31 |
using namespace MPTV; |
| 32 |
|
| 33 |
CGUIDialogRecordSettings::CGUIDialogRecordSettings(const kodi::addon::PVRTimer& timerinfo, cTimer& timer, const std::string& channelName) : |
| 34 |
kodi::gui::CWindow("DialogRecordSettings.xml", "skin.fallback", true, true), |
| 35 |
m_frequency(Once), |
| 36 |
m_airtime(ThisTime), |
| 37 |
m_channels(ThisChannel), |
| 38 |
m_timerinfo(timerinfo), |
| 39 |
m_timer(timer) |
| 40 |
{ |
| 41 |
CDateTime startTime(m_timerinfo.GetStartTime()); |
| 42 |
CDateTime endTime(m_timerinfo.GetEndTime()); |
| 43 |
startTime.GetAsLocalizedTime(m_startTime); |
| 44 |
startTime.GetAsLocalizedDate(m_startDate); |
| 45 |
endTime.GetAsLocalizedTime(m_endTime); |
| 46 |
|
| 47 |
m_title = m_timerinfo.GetTitle(); |
| 48 |
m_channel = channelName; |
| 49 |
|
| 50 |
// needed for every dialog |
| 51 |
m_retVal = -1; // init to failed load value (due to xml file not being found) |
| 52 |
} |
| 53 |
|
| 54 |
bool CGUIDialogRecordSettings::OnInit() |
| 55 |
{ |
| 56 |
m_spinFrequency = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_FREQUENCY); |
| 57 |
m_spinAirtime = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_AIRTIME); |
| 58 |
m_spinChannels = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_CHANNELS); |
| 59 |
m_spinKeep = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_KEEP); |
| 60 |
m_spinPreRecord = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_PRERECORD); |
| 61 |
m_spinPostRecord = std::make_shared<kodi::gui::controls::CSpin>(this, SPIN_CONTROL_POSTRECORD); |
| 62 |
|
| 63 |
// Display the recording details in the window |
| 64 |
SetControlLabel(LABEL_PROGRAM_TITLE, m_title); |
| 65 |
std::string strTimeSlot = m_startDate + " " + m_startTime + " - " + m_endTime; |
| 66 |
SetControlLabel(LABEL_PROGRAM_START_TIME, strTimeSlot); |
| 67 |
SetControlLabel(LABEL_PROGRAM_CHANNEL, m_channel); |
| 68 |
|
| 69 |
// Populate Frequency spin control |
| 70 |
m_spinFrequency->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 71 |
for (int i = 0; i < 5; i++) |
| 72 |
{ // show localized recording options |
| 73 |
m_spinFrequency->AddLabel(kodi::addon::GetLocalizedString(30110 + i), i); |
| 74 |
} |
| 75 |
// set the default value |
| 76 |
m_spinFrequency->SetIntValue(CGUIDialogRecordSettings::Once); |
| 77 |
|
| 78 |
// Populate Airtime spin control |
| 79 |
std::string strThisTime = kodi::addon::GetLocalizedString(30120); |
| 80 |
strThisTime += "(" + m_startTime + ")"; |
| 81 |
m_spinAirtime->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 82 |
m_spinAirtime->AddLabel(strThisTime, CGUIDialogRecordSettings::ThisTime); |
| 83 |
m_spinAirtime->AddLabel(kodi::addon::GetLocalizedString(30121), CGUIDialogRecordSettings::AnyTime); |
| 84 |
// Set the default values |
| 85 |
m_spinAirtime->SetIntValue(CGUIDialogRecordSettings::ThisTime); |
| 86 |
m_spinAirtime->SetVisible(false); |
| 87 |
|
| 88 |
// Populate Channels spin control |
| 89 |
m_spinChannels->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 90 |
for (int i = 0; i < 2; i++) |
| 91 |
{ // show localized recording options |
| 92 |
m_spinChannels->AddLabel(kodi::addon::GetLocalizedString(30125 + i), i); |
| 93 |
} |
| 94 |
// Set the default values |
| 95 |
m_spinChannels->SetIntValue(CGUIDialogRecordSettings::ThisChannel); |
| 96 |
m_spinChannels->SetVisible(false); |
| 97 |
|
| 98 |
// Populate Keep spin control |
| 99 |
m_spinKeep->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 100 |
for (int i = 0; i < 4; i++) |
| 101 |
{ // show localized recording options |
| 102 |
m_spinKeep->AddLabel(kodi::addon::GetLocalizedString(30130 + i), i); |
| 103 |
} |
| 104 |
// Set the default values |
| 105 |
m_spinKeep->SetIntValue(TvDatabase::Always); |
| 106 |
|
| 107 |
// Populate PreRecord spin control |
| 108 |
std::string marginStart; |
| 109 |
marginStart = kodi::tools::StringUtils::Format("%d (%s)", m_timerinfo.GetMarginStart(), kodi::addon::GetLocalizedString(30136).c_str()); |
| 110 |
m_spinPreRecord->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 111 |
m_spinPreRecord->AddLabel(kodi::addon::GetLocalizedString(30135), -1); |
| 112 |
m_spinPreRecord->AddLabel(marginStart, m_timerinfo.GetMarginStart()); //value from XBMC |
| 113 |
m_spinPreRecord->AddLabel("0", 0); |
| 114 |
m_spinPreRecord->AddLabel("3", 3); |
| 115 |
m_spinPreRecord->AddLabel("5", 5); |
| 116 |
m_spinPreRecord->AddLabel("7", 7); |
| 117 |
m_spinPreRecord->AddLabel("10", 10); |
| 118 |
m_spinPreRecord->AddLabel("15", 15); |
| 119 |
m_spinPreRecord->SetIntValue(m_timerinfo.GetMarginStart()); // Set the default value |
| 120 |
|
| 121 |
// Populate PostRecord spin control |
| 122 |
std::string marginEnd; |
| 123 |
marginEnd = kodi::tools::StringUtils::Format("%d (%s)", m_timerinfo.GetMarginEnd(), kodi::addon::GetLocalizedString(30136).c_str()); |
| 124 |
m_spinPostRecord->SetType(kodi::gui::controls::ADDON_SPIN_CONTROL_TYPE_TEXT); |
| 125 |
m_spinPostRecord->AddLabel(kodi::addon::GetLocalizedString(30135), -1); |
| 126 |
m_spinPostRecord->AddLabel(marginEnd, m_timerinfo.GetMarginEnd()); //value from XBMC |
| 127 |
m_spinPostRecord->AddLabel("0", 0); |
| 128 |
m_spinPostRecord->AddLabel("3", 3); |
| 129 |
m_spinPostRecord->AddLabel("5", 5); |
| 130 |
m_spinPostRecord->AddLabel("7", 7); |
| 131 |
m_spinPostRecord->AddLabel("10", 10); |
| 132 |
m_spinPostRecord->AddLabel("15", 15); |
| 133 |
m_spinPostRecord->AddLabel("20", 20); |
| 134 |
m_spinPostRecord->AddLabel("30", 30); |
| 135 |
m_spinPostRecord->AddLabel("45", 45); |
| 136 |
m_spinPostRecord->AddLabel("60", 60); |
| 137 |
m_spinPostRecord->SetIntValue(m_timerinfo.GetMarginEnd()); // Set the default value |
| 138 |
|
| 139 |
return true; |
| 140 |
} |
| 141 |
|
| 142 |
bool CGUIDialogRecordSettings::OnClick(int controlId) |
| 143 |
{ |
| 144 |
switch(controlId) |
| 145 |
{ |
| 146 |
case BUTTON_OK: // save value from GUI, then FALLS THROUGH TO CANCEL |
| 147 |
m_frequency = (RecordingFrequency) m_spinFrequency->GetIntValue(); |
| 148 |
m_airtime = (RecordingAirtime) m_spinAirtime->GetIntValue(); |
| 149 |
m_channels = (RecordingChannels) m_spinChannels->GetIntValue(); |
| 150 |
|
| 151 |
/* Update the Timer settings */ |
| 152 |
UpdateTimerSettings(); |
| 153 |
|
| 154 |
m_retVal = 1; |
| 155 |
Close(); |
| 156 |
break; |
| 157 |
case BUTTON_CANCEL: |
| 158 |
m_retVal = 0; |
| 159 |
Close(); |
| 160 |
break; |
| 161 |
/* Limit the available options based on the SPIN settings |
| 162 |
* MediaPortal does not support all combinations |
| 163 |
*/ |
| 164 |
case SPIN_CONTROL_FREQUENCY: |
| 165 |
m_frequency = (RecordingFrequency) m_spinFrequency->GetIntValue(); |
| 166 |
|
| 167 |
switch (m_frequency) |
| 168 |
{ |
| 169 |
case Once: |
| 170 |
case Weekends: |
| 171 |
case WeekDays: |
| 172 |
m_spinAirtime->SetVisible(false); |
| 173 |
m_spinChannels->SetVisible(false); |
| 174 |
break; |
| 175 |
case Weekly: |
| 176 |
m_spinAirtime->SetVisible(true); |
| 177 |
m_spinChannels->SetVisible(false); |
| 178 |
break; |
| 179 |
case Daily: |
| 180 |
m_spinAirtime->SetVisible(true); |
| 181 |
m_spinChannels->SetVisible(true); |
| 182 |
break; |
| 183 |
} |
| 184 |
break; |
| 185 |
case SPIN_CONTROL_CHANNELS: |
| 186 |
m_channels = (RecordingChannels) m_spinChannels->GetIntValue(); |
| 187 |
|
| 188 |
//switch (m_frequency) |
| 189 |
//{ |
| 190 |
// case Once: |
| 191 |
// case Weekends: |
| 192 |
// case WeekDays: |
| 193 |
// case Weekly: |
| 194 |
// m_channels = ThisChannel; |
| 195 |
// m_spinChannels->SetValue(m_channels); |
| 196 |
// break; |
| 197 |
//} |
| 198 |
|
| 199 |
/* This time on any channel is not supported by MediaPortal */ |
| 200 |
if (m_channels == AnyChannel) |
| 201 |
m_spinAirtime->SetIntValue(AnyTime); |
| 202 |
break; |
| 203 |
case SPIN_CONTROL_AIRTIME: |
| 204 |
m_airtime = (RecordingAirtime) m_spinAirtime->GetIntValue(); |
| 205 |
|
| 206 |
if (m_airtime == ThisTime) |
| 207 |
m_spinChannels->SetIntValue(ThisChannel); |
| 208 |
break; |
| 209 |
} |
| 210 |
|
| 211 |
return true; |
| 212 |
} |
| 213 |
|
| 214 |
bool CGUIDialogRecordSettings::Show() |
| 215 |
{ |
| 216 |
kodi::gui::CWindow::Show(); |
| 217 |
return false; |
| 218 |
} |
| 219 |
|
| 220 |
void CGUIDialogRecordSettings::Close() |
| 221 |
{ |
| 222 |
kodi::gui::CWindow::Close(); |
| 223 |
} |
| 224 |
|
| 225 |
int CGUIDialogRecordSettings::DoModal() |
| 226 |
{ |
| 227 |
kodi::gui::CWindow::DoModal(); |
| 228 |
return m_retVal; |
| 229 |
} |
| 230 |
|
| 231 |
bool CGUIDialogRecordSettings::OnFocus(int controlId) |
| 232 |
{ |
| 233 |
return true; |
| 234 |
} |
| 235 |
|
| 236 |
/* |
| 237 |
* This callback is called by XBMC before executing its internal OnAction() function |
| 238 |
* Returning "true" tells XBMC that we already handled the action, returing "false" |
| 239 |
* passes action to the XBMC internal OnAction() function |
| 240 |
*/ |
| 241 |
bool CGUIDialogRecordSettings::OnAction(ADDON_ACTION actionId) |
| 242 |
{ |
| 243 |
//kodi::Log(ADDON_ADDON::LOG_DEBUG, "%s: action = %i\n", __FUNCTION__, actionId); |
| 244 |
if (actionId == ADDON_ACTION_PREVIOUS_MENU || actionId == ADDON_ACTION_NAV_BACK) |
| 245 |
return OnClick(BUTTON_CANCEL); |
| 246 |
else |
| 247 |
/* return false to tell XBMC that it should take over */ |
| 248 |
return false; |
| 249 |
} |
| 250 |
|
| 251 |
void CGUIDialogRecordSettings::UpdateTimerSettings(void) |
| 252 |
{ |
| 253 |
switch(m_frequency) |
| 254 |
{ |
| 255 |
case Once: |
| 256 |
m_timer.SetScheduleRecordingType(TvDatabase::Once); |
| 257 |
break; |
| 258 |
case Weekends: |
| 259 |
m_timer.SetScheduleRecordingType(TvDatabase::Weekends); |
| 260 |
break; |
| 261 |
case WeekDays: |
| 262 |
m_timer.SetScheduleRecordingType(TvDatabase::WorkingDays); |
| 263 |
break; |
| 264 |
case Weekly: |
| 265 |
if (m_airtime == ThisTime) |
| 266 |
m_timer.SetScheduleRecordingType(TvDatabase::Weekly); |
| 267 |
else |
| 268 |
m_timer.SetScheduleRecordingType(TvDatabase::WeeklyEveryTimeOnThisChannel); |
| 269 |
break; |
| 270 |
case Daily: |
| 271 |
switch (m_airtime) |
| 272 |
{ |
| 273 |
case ThisTime: |
| 274 |
m_timer.SetScheduleRecordingType(TvDatabase::Daily); |
| 275 |
break; |
| 276 |
case AnyTime: |
| 277 |
if (m_channels == ThisChannel) |
| 278 |
m_timer.SetScheduleRecordingType(TvDatabase::EveryTimeOnThisChannel); |
| 279 |
else |
| 280 |
m_timer.SetScheduleRecordingType(TvDatabase::EveryTimeOnEveryChannel); |
| 281 |
break; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
m_timer.SetKeepMethod((TvDatabase::KeepMethodType) m_spinKeep->GetIntValue()); |
| 286 |
m_timer.SetPreRecordInterval(m_spinPreRecord->GetIntValue()); |
| 287 |
m_timer.SetPostRecordInterval(m_spinPostRecord->GetIntValue()); |
| 288 |
} |