Skip to content

Commit 6f52db9

Browse files
Paul HarrisonBeirdo
authored andcommitted
MythArchive: Change the video selector to use the same parental level checking that MythVideo uses.
1 parent 8bf0c13 commit 6f52db9

File tree

2 files changed

+28
-76
lines changed

2 files changed

+28
-76
lines changed

mythplugins/mytharchive/mytharchive/videoselector.cpp

Lines changed: 21 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ VideoSelector::VideoSelector(MythScreenStack *parent, QList<ArchiveItem *> *arch
2828
:MythScreenType(parent, "VideoSelector")
2929
{
3030
m_archiveList = archiveList;
31-
m_currentParentalLevel = 1;
31+
m_currentParentalLevel = ParentalLevel::plNone;
3232
m_videoList = NULL;
33+
34+
m_parentalLevelChecker = new ParentalLevelChangeChecker();
35+
connect(m_parentalLevelChecker, SIGNAL(SigResultReady(bool, ParentalLevel::Level)),
36+
this, SLOT(parentalLevelChanged(bool, ParentalLevel::Level)));
3337
}
3438

3539
VideoSelector::~VideoSelector(void)
@@ -40,6 +44,8 @@ VideoSelector::~VideoSelector(void)
4044
while (!m_selectedList.isEmpty())
4145
delete m_selectedList.takeFirst();
4246
m_selectedList.clear();
47+
48+
delete m_parentalLevelChecker;
4349
}
4450

4551
bool VideoSelector::Create(void)
@@ -86,6 +92,8 @@ bool VideoSelector::Create(void)
8692

8793
SetFocusWidget(m_videoButtonList);
8894

95+
setParentalLevel(ParentalLevel::plLowest);
96+
8997
updateSelectedList();
9098
updateVideoList();
9199

@@ -112,19 +120,19 @@ bool VideoSelector::keyPressEvent(QKeyEvent *event)
112120
}
113121
else if (action == "1")
114122
{
115-
setParentalLevel(1);
123+
setParentalLevel(ParentalLevel::plLowest);
116124
}
117125
else if (action == "2")
118126
{
119-
setParentalLevel(2);
127+
setParentalLevel(ParentalLevel::plLow);
120128
}
121129
else if (action == "3")
122130
{
123-
setParentalLevel(3);
131+
setParentalLevel(ParentalLevel::plMedium);
124132
}
125133
else if (action == "4")
126134
{
127-
setParentalLevel(4);
135+
setParentalLevel(ParentalLevel::plHigh);
128136
}
129137
else
130138
handled = false;
@@ -521,79 +529,20 @@ void VideoSelector::updateSelectedList()
521529
}
522530
}
523531

524-
void VideoSelector::setParentalLevel(int which_level)
532+
void VideoSelector::setParentalLevel(ParentalLevel::Level level)
525533
{
526-
if (which_level < 1)
527-
which_level = 1;
528-
529-
if (which_level > 4)
530-
which_level = 4;
531-
532-
if ((which_level > m_currentParentalLevel) && !checkParentPassword())
533-
which_level = m_currentParentalLevel;
534-
535-
536-
if (m_currentParentalLevel != which_level)
537-
{
538-
m_currentParentalLevel = which_level;
539-
updateVideoList();
540-
m_plText->SetText(QString::number(which_level));
541-
}
534+
m_parentalLevelChecker->Check(m_currentParentalLevel, level);
542535
}
543536

544-
bool VideoSelector::checkParentPassword()
537+
void VideoSelector::parentalLevelChanged(bool passwordValid, ParentalLevel::Level newLevel)
545538
{
546-
QDateTime curr_time = QDateTime::currentDateTime();
547-
QString last_time_stamp = gCoreContext->GetSetting("VideoPasswordTime");
548-
QString password = gCoreContext->GetSetting("VideoAdminPassword");
549-
if (password.length() < 1)
539+
if (passwordValid)
550540
{
551-
return true;
552-
}
553-
554-
// See if we recently (and succesfully) asked for a password
555-
if (last_time_stamp.length() < 1)
556-
{
557-
// Probably first time used
558-
}
559-
else
560-
{
561-
QDateTime last_time = QDateTime::fromString(last_time_stamp,
562-
Qt::TextDate);
563-
if (last_time.secsTo(curr_time) < 120)
564-
{
565-
// Two minute window
566-
last_time_stamp = curr_time.toString(Qt::TextDate);
567-
gCoreContext->SetSetting("VideoPasswordTime", last_time_stamp);
568-
gCoreContext->SaveSetting("VideoPasswordTime", last_time_stamp);
569-
return true;
570-
}
571-
}
572-
573-
// See if there is a password set
574-
if (password.length() > 0)
575-
{
576-
bool ok = false;
577-
MythPasswordDialog *pwd = new MythPasswordDialog(tr("Parental Pin:"),
578-
&ok,
579-
password,
580-
GetMythMainWindow());
581-
pwd->exec();
582-
pwd->deleteLater();
583-
if (ok)
584-
{
585-
// All is good
586-
last_time_stamp = curr_time.toString(Qt::TextDate);
587-
gCoreContext->SetSetting("VideoPasswordTime", last_time_stamp);
588-
gCoreContext->SaveSetting("VideoPasswordTime", last_time_stamp);
589-
return true;
590-
}
541+
m_currentParentalLevel = newLevel;
542+
updateVideoList();
543+
m_plText->SetText(QString::number(newLevel));
591544
}
592545
else
593-
{
594-
return true;
595-
}
596-
597-
return false;
546+
ShowOkPopup(tr("You need to enter a valid password for this parental level"));
598547
}
599548

mythplugins/mytharchive/mytharchive/videoselector.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// mythtv
1414
#include <mythscreentype.h>
15+
#include <metadata/parentalcontrols.h>
1516

1617
// mytharchive
1718
#include "archiveutil.h"
@@ -22,7 +23,6 @@ class MythUIButton;
2223
class MythUIButtonList;
2324
class MythUIButtonListItem;
2425

25-
2626
typedef struct
2727
{
2828
int id;
@@ -62,20 +62,23 @@ class VideoSelector : public MythScreenType
6262
void titleChanged(MythUIButtonListItem *item);
6363
void toggleSelected(MythUIButtonListItem *item);
6464

65+
void parentalLevelChanged(bool passwordValid, ParentalLevel::Level newLevel);
66+
6567
private:
6668
void updateVideoList(void);
6769
void updateSelectedList(void);
6870
void getVideoList(void);
6971
void wireUpTheme(void);
7072
std::vector<VideoInfo *> *getVideoListFromDB(void);
71-
bool checkParentPassword(void);
72-
void setParentalLevel(int which_level);
73+
void setParentalLevel(ParentalLevel::Level level);
74+
75+
ParentalLevelChangeChecker *m_parentalLevelChecker;
7376

7477
QList<ArchiveItem *> *m_archiveList;
7578
std::vector<VideoInfo *> *m_videoList;
7679
QList<VideoInfo *> m_selectedList;
7780

78-
int m_currentParentalLevel;
81+
ParentalLevel::Level m_currentParentalLevel;
7982

8083
MythUIText *m_plText;
8184
MythUIButtonList *m_videoButtonList;

0 commit comments

Comments
 (0)