Permalink
Browse files

Don't allow dismissing the notification if it's been created for less…

… than 1s.

This would help prevent accidentally dismissing an important notification when the user was about to press ESC.

Fixes #11658
  • Loading branch information...
jyavenard committed Jul 10, 2013
1 parent 3b618cd commit 81fb515fd5596f692d550ff82bc3ee0f50a0d643
@@ -152,7 +152,7 @@ void MythUINotificationScreen::SetNotification(MythNotification &notification)
m_priority = notification.GetPriority();
// Set timer if need be
SetSingleShotTimer(m_duration);
SetSingleShotTimer(m_duration, update);
}
bool MythUINotificationScreen::Create(void)
@@ -450,7 +450,7 @@ MythUINotificationScreen &MythUINotificationScreen::operator=(const MythUINotifi
return *this;
}
void MythUINotificationScreen::SetSingleShotTimer(int s)
void MythUINotificationScreen::SetSingleShotTimer(int s, bool update)
{
// only registered application can display non-expiring notification
if (m_id > 0 && s < 0)
@@ -459,13 +459,39 @@ void MythUINotificationScreen::SetSingleShotTimer(int s)
int ms = s * 1000;
ms = ms <= DEFAULT_DURATION ? DEFAULT_DURATION : ms;
if (!update)
{
m_creation = MythDate::current();
}
m_expiry = MythDate::current().addMSecs(ms);
m_timer->stop();
m_timer->setSingleShot(true);
m_timer->start(ms);
}
// Public event handling
bool MythUINotificationScreen::keyPressEvent(QKeyEvent *event)
{
QStringList actions;
bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
if (action == "ESCAPE")
{
if (MythDate::current() < m_creation.addMSecs(MIN_LIFE))
return true; // was updated less than 1s ago, ignore
}
}
if (!handled)
{
handled = MythScreenType::keyPressEvent(event);
}
return handled;
}
/////////////////////// NCPrivate
@@ -1011,6 +1037,9 @@ bool NCPrivate::RemoveFirst(void)
return false;
MythUINotificationScreen *screen = m_screens.first();
if (MythDate::current() < screen->m_creation.addMSecs(MIN_LIFE))
return false;
// simulate time-out
screen->ProcessTimer();
return true;
@@ -27,6 +27,8 @@
class MythUINotificationScreen;
class MythNotificationScreenStack;
#define MIN_LIFE 1000
class NCPrivate : public QObject
{
Q_OBJECT
@@ -154,6 +156,8 @@ class MythUINotificationScreen : public MythScreenType
virtual ~MythUINotificationScreen();
bool keyPressEvent(QKeyEvent *event);
// These two methods are declared by MythScreenType and their signatures
// should not be changed
virtual bool Create(void);
@@ -166,7 +170,7 @@ class MythUINotificationScreen : public MythScreenType
void UpdateMetaData(const DMAP &data);
void UpdatePlayback(float progress, const QString &text);
void SetSingleShotTimer(int s);
void SetSingleShotTimer(int s, bool update = false);
// UI methods
void AdjustYPosition(void);
@@ -213,7 +217,7 @@ public slots:
MythUIText *m_extraText;
MythUIText *m_progresstextText;
MythUIProgressBar *m_progressBar;
QDateTime m_expiry;
QDateTime m_creation, m_expiry;
int m_index;
MythPoint m_position;
QTimer *m_timer;

0 comments on commit 81fb515

Please sign in to comment.