Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PVR] Search window improvements and fixes #12001

Merged
merged 2 commits into from Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -854,7 +854,6 @@ msgstr ""


#. label for "searching" message box heading
#: xbmc/pvr/windows/GUIWindowPVRSearch.cpp
#: xbmc/video/dialogs/GUIDialogVideoInfo.cpp
#: xbmc/video/windows/GUIWindowVideoBase.cpp
msgctxt "#194"
Expand Down
33 changes: 9 additions & 24 deletions xbmc/pvr/epg/EpgSearchFilter.cpp
Expand Up @@ -48,6 +48,15 @@ void CPVREpgSearchFilter::Reset()
m_iGenreSubType = EPG_SEARCH_UNSET;
m_iMinimumDuration = EPG_SEARCH_UNSET;
m_iMaximumDuration = EPG_SEARCH_UNSET;

m_startDateTime.SetFromUTCDateTime(CServiceBroker::GetPVRManager().EpgContainer().GetFirstEPGDate());
if (!m_startDateTime.IsValid())
m_startDateTime.SetFromUTCDateTime(CDateTime::GetUTCDateTime()); // default to 'now'

m_endDateTime.SetFromUTCDateTime(CServiceBroker::GetPVRManager().EpgContainer().GetLastEPGDate());
if (!m_endDateTime.IsValid())
m_endDateTime.SetFromUTCDateTime(m_startDateTime + CDateTimeSpan(10, 0, 0, 0)); // default to start + 10 days

m_bIncludeUnknownGenres = false;
m_bRemoveDuplicates = false;

Expand All @@ -61,30 +70,6 @@ void CPVREpgSearchFilter::Reset()
m_iUniqueBroadcastId = EPG_TAG_INVALID_UID;
}

void CPVREpgSearchFilter::ValidateStartAndEndDate()
{
const CDateTime start = CServiceBroker::GetPVRManager().EpgContainer().GetFirstEPGDate();
const CDateTime end = CServiceBroker::GetPVRManager().EpgContainer().GetLastEPGDate();

if (m_startDateTime < start || m_startDateTime > end)
m_startDateTime.SetFromUTCDateTime(start);

if (m_endDateTime > end || m_endDateTime < start)
m_endDateTime.SetFromUTCDateTime(end);
}

const CDateTime& CPVREpgSearchFilter::GetStartDateTime()
{
ValidateStartAndEndDate();
return m_startDateTime;
}

const CDateTime& CPVREpgSearchFilter::GetEndDateTime()
{
ValidateStartAndEndDate();
return m_endDateTime;
}

bool CPVREpgSearchFilter::MatchGenre(const CPVREpgInfoTagPtr &tag) const
{
bool bReturn(true);
Expand Down
9 changes: 2 additions & 7 deletions xbmc/pvr/epg/EpgSearchFilter.h
Expand Up @@ -76,10 +76,10 @@ namespace PVR
int GetMaximumDuration() const { return m_iMaximumDuration; }
void SetMaximumDuration(int iMaximumDuration) { m_iMaximumDuration = iMaximumDuration; }

const CDateTime &GetStartDateTime();
const CDateTime &GetStartDateTime() const { return m_startDateTime; }
void SetStartDateTime(const CDateTime &startDateTime) { m_startDateTime = startDateTime; }

const CDateTime &GetEndDateTime();
const CDateTime &GetEndDateTime() const { return m_endDateTime; }
void SetEndDateTime(const CDateTime &endDateTime) { m_endDateTime = endDateTime; }

bool ShouldIncludeUnknownGenres() const { return m_bIncludeUnknownGenres; }
Expand Down Expand Up @@ -110,11 +110,6 @@ namespace PVR
void SetUniqueBroadcastId(unsigned int iUniqueBroadcastId) { m_iUniqueBroadcastId = iUniqueBroadcastId; }

private:
/*!
* @brief Make sure that start and end time match current epg data boundaries.
*/
void ValidateStartAndEndDate();

bool MatchGenre(const CPVREpgInfoTagPtr &tag) const;
bool MatchDuration(const CPVREpgInfoTagPtr &tag) const;
bool MatchStartAndEndTimes(const CPVREpgInfoTagPtr &tag) const;
Expand Down
51 changes: 34 additions & 17 deletions xbmc/pvr/windows/GUIWindowPVRSearch.cpp
Expand Up @@ -22,7 +22,7 @@

#include "ServiceBroker.h"
#include "dialogs/GUIDialogOK.h"
#include "dialogs/GUIDialogProgress.h"
#include "dialogs/GUIDialogBusy.h"
#include "guilib/GUIWindowManager.h"
#include "input/Key.h"
#include "utils/URIUtils.h"
Expand All @@ -38,6 +38,35 @@

using namespace PVR;

namespace
{
class AsyncSearchAction : private IRunnable
{
public:
AsyncSearchAction() = delete;
AsyncSearchAction(CFileItemList* items, CPVREpgSearchFilter* filter) : m_items(items), m_filter(filter) {}
bool Execute();

private:
// IRunnable implementation
void Run() override;

CFileItemList* m_items;
CPVREpgSearchFilter* m_filter;
};

bool AsyncSearchAction::Execute()
{
CGUIDialogBusy::Wait(this, 100, false);
return true;
}

void AsyncSearchAction::Run()
{
CServiceBroker::GetPVRManager().EpgContainer().GetEPGSearch(*m_items, *m_filter);
}
} // unnamed namespace

CGUIWindowPVRSearch::CGUIWindowPVRSearch(bool bRadio) :
CGUIWindowPVRBase(bRadio, bRadio ? WINDOW_RADIO_SEARCH : WINDOW_TV_SEARCH, "MyPVRSearch.xml"),
m_bSearchConfirmed(false)
Expand All @@ -49,7 +78,7 @@ void CGUIWindowPVRSearch::GetContextButtons(int itemNumber, CContextButtons &but
if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
return;

buttons.Add(CONTEXT_BUTTON_CLEAR, 19232); /* Clear search results */
buttons.Add(CONTEXT_BUTTON_CLEAR, 19232); /* Clear search results */

CGUIWindowPVRBase::GetContextButtons(itemNumber, buttons);
}
Expand Down Expand Up @@ -94,24 +123,12 @@ void CGUIWindowPVRSearch::OnPrepareFileItems(CFileItemList &items)
bAddSpecialSearchItem = true;

items.Clear();
CGUIDialogProgress* dlgProgress = g_windowManager.GetWindow<CGUIDialogProgress>();
if (dlgProgress)
{
dlgProgress->SetHeading(CVariant{194}); // "Searching..."
dlgProgress->SetText(CVariant{m_searchfilter.GetSearchTerm()});
dlgProgress->Open();
dlgProgress->Progress();
}

//! @todo should we limit the find similar search to the selected group?
CServiceBroker::GetPVRManager().EpgContainer().GetEPGSearch(items, m_searchfilter);

if (dlgProgress)
dlgProgress->Close();
AsyncSearchAction(&items, &m_searchfilter).Execute();

if (items.IsEmpty())
CGUIDialogOK::ShowAndGetInput(CVariant{194}, // "Searching..."
CVariant{284}); // "No results found"
CGUIDialogOK::ShowAndGetInput(CVariant{284}, // "No results found"
m_searchfilter.GetSearchTerm());
}

if (bAddSpecialSearchItem)
Expand Down