2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIWindowPVRTimersBase.h"
12 #include "FileItemList.h"
13 #include "GUIInfoManager.h"
14 #include "ServiceBroker.h"
15 #include "guilib/GUIComponent.h"
16 #include "guilib/GUIMessage.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "input/actions/Action.h"
19 #include "input/actions/ActionIDs.h"
20 #include "pvr/PVRManager.h"
21 #include "pvr/guilib/PVRGUIActionsTimers.h"
22 #include "pvr/timers/PVRTimerInfoTag.h"
23 #include "pvr/timers/PVRTimersPath.h"
24 #include "settings/Settings.h"
25 #include "settings/SettingsComponent.h"
26 #include "utils/URIUtils.h"
33 CGUIWindowPVRTimersBase::CGUIWindowPVRTimersBase(bool bRadio
, int id
, const std::string
& xmlFile
)
34 : CGUIWindowPVRBase(bRadio
, id
, xmlFile
)
38 CGUIWindowPVRTimersBase::~CGUIWindowPVRTimersBase() = default;
40 bool CGUIWindowPVRTimersBase::OnAction(const CAction
& action
)
42 if (action
.GetID() == ACTION_PARENT_DIR
|| action
.GetID() == ACTION_NAV_BACK
)
44 CPVRTimersPath
path(m_vecItems
->GetPath());
45 if (path
.IsValid() && path
.IsTimerRule())
47 m_currentFileItem
.reset();
52 return CGUIWindowPVRBase::OnAction(action
);
55 void CGUIWindowPVRTimersBase::OnPrepareFileItems(CFileItemList
& items
)
57 const CPVRTimersPath
path(m_vecItems
->GetPath());
58 if (path
.IsValid() && path
.IsTimersRoot())
60 const auto item
= std::make_shared
<CFileItem
>(CPVRTimersPath::PATH_ADDTIMER
, false);
61 item
->SetLabel(g_localizeStrings
.Get(19026)); // "Add timer..."
62 item
->SetLabelPreformatted(true);
63 item
->SetSpecialSort(SortSpecialOnTop
);
64 item
->SetArt("icon", "DefaultTVShows.png");
66 items
.AddFront(item
, 0);
70 bool CGUIWindowPVRTimersBase::Update(const std::string
& strDirectory
,
71 bool updateFilterPath
/* = true */)
73 int iOldCount
= m_vecItems
->GetObjectCount();
74 const std::string oldPath
= m_vecItems
->GetPath();
76 bool bReturn
= CGUIWindowPVRBase::Update(strDirectory
);
78 if (bReturn
&& iOldCount
> 0 && m_vecItems
->GetObjectCount() == 0 &&
79 oldPath
== m_vecItems
->GetPath())
81 /* go to the parent folder if we're in a subdirectory and for instance just deleted the last item */
82 const CPVRTimersPath
path(m_vecItems
->GetPath());
83 if (path
.IsValid() && path
.IsTimerRule())
85 m_currentFileItem
.reset();
93 void CGUIWindowPVRTimersBase::UpdateButtons()
95 SET_CONTROL_SELECTED(GetID(), CONTROL_BTNHIDEDISABLEDTIMERS
,
96 CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
97 CSettings::SETTING_PVRTIMERS_HIDEDISABLEDTIMERS
));
99 CGUIWindowPVRBase::UpdateButtons();
101 std::string strHeaderTitle
;
102 if (m_currentFileItem
&& m_currentFileItem
->HasPVRTimerInfoTag())
104 std::shared_ptr
<CPVRTimerInfoTag
> timer
= m_currentFileItem
->GetPVRTimerInfoTag();
105 strHeaderTitle
= timer
->Title();
108 SET_CONTROL_LABEL(CONTROL_LABEL_HEADER1
, strHeaderTitle
);
111 bool CGUIWindowPVRTimersBase::OnMessage(CGUIMessage
& message
)
113 bool bReturn
= false;
114 switch (message
.GetMessage())
116 case GUI_MSG_CLICKED
:
117 if (message
.GetSenderId() == m_viewControl
.GetCurrentControl())
119 int iItem
= m_viewControl
.GetSelectedItem();
120 if (iItem
>= 0 && iItem
< m_vecItems
->Size())
123 switch (message
.GetParam1())
125 case ACTION_SHOW_INFO
:
126 case ACTION_SELECT_ITEM
:
127 case ACTION_MOUSE_LEFT_CLICK
:
129 CFileItemPtr
item(m_vecItems
->Get(iItem
));
130 if (item
->m_bIsFolder
&& (message
.GetParam1() != ACTION_SHOW_INFO
))
132 m_currentFileItem
= item
;
133 bReturn
= false; // folders are handled by base class
137 m_currentFileItem
.reset();
138 ActionShowTimer(*item
);
142 case ACTION_CONTEXT_MENU
:
143 case ACTION_MOUSE_RIGHT_CLICK
:
146 case ACTION_DELETE_ITEM
:
147 CServiceBroker::GetPVRManager().Get
<PVR::GUI::Timers
>().DeleteTimer(
148 *(m_vecItems
->Get(iItem
)));
156 else if (message
.GetSenderId() == CONTROL_BTNHIDEDISABLEDTIMERS
)
158 const std::shared_ptr
<CSettings
> settings
=
159 CServiceBroker::GetSettingsComponent()->GetSettings();
160 settings
->ToggleBool(CSettings::SETTING_PVRTIMERS_HIDEDISABLEDTIMERS
);
162 Update(GetDirectoryPath());
166 case GUI_MSG_REFRESH_LIST
:
168 switch (static_cast<PVREvent
>(message
.GetParam1()))
170 case PVREvent::CurrentItem
:
172 case PVREvent::EpgActiveItem
:
173 case PVREvent::EpgContainer
:
174 case PVREvent::Timers
:
178 case PVREvent::TimersInvalidated
:
189 return bReturn
|| CGUIWindowPVRBase::OnMessage(message
);
192 bool CGUIWindowPVRTimersBase::ActionShowTimer(const CFileItem
& item
)
194 bool bReturn
= false;
196 /* Check if "Add timer..." entry is selected, if yes
197 create a new timer and open settings dialog, otherwise
198 open settings for selected timer entry */
199 if (URIUtils::PathEquals(item
.GetPath(), CPVRTimersPath::PATH_ADDTIMER
))
200 bReturn
= CServiceBroker::GetPVRManager().Get
<PVR::GUI::Timers
>().AddTimer(m_bRadio
);
202 bReturn
= CServiceBroker::GetPVRManager().Get
<PVR::GUI::Timers
>().EditTimer(item
);