From 7dcf2a591579394a8fe42df4ff675d415477bb9b Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Mon, 8 Jul 2013 20:26:22 +1000 Subject: [PATCH] Display loss of connection to backend as a notification instead of a popup. The popup would re-appear as soon as dismissed, now the notification will only appear if it's been already showing for more than 5s Fixes #11651 --- mythtv/libs/libmyth/mythcontext.cpp | 65 +++++++++++++++++------------ mythtv/libs/libmyth/mythcontext.h | 1 - 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/mythtv/libs/libmyth/mythcontext.cpp b/mythtv/libs/libmyth/mythcontext.cpp index ac1d90b9b07..d14729ee841 100644 --- a/mythtv/libs/libmyth/mythcontext.cpp +++ b/mythtv/libs/libmyth/mythcontext.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,7 @@ using namespace std; #include "mythlogging.h" #include "mythsystemlegacy.h" #include "mythmiscutil.h" +#include "mythuinotificationcenter.h" #include "mythplugin.h" @@ -50,6 +52,8 @@ using namespace std; MythContext *gContext = NULL; +static const QString _Location = "MythContext"; + class MythContextPrivate : public QObject { friend class MythContextSlotHandler; @@ -106,8 +110,9 @@ class MythContextPrivate : public QObject MythContextSlotHandler *m_sh; private: - MythConfirmationDialog *MBEconnectPopup; MythConfirmationDialog *MBEversionPopup; + int m_registration; + QDateTime m_lastCheck; }; static void exec_program_cb(const QString &cmd) @@ -179,7 +184,8 @@ static void configplugin_cb(const QString &cmd) MythPluginManager *pmanager = gCoreContext->GetPluginManager(); if (pmanager) if (pmanager->config_plugin(cmd.trimmed())) - ShowOkPopup(QObject::tr("Failed to configure plugin %1").arg(cmd)); + ShowNotificationError(cmd, _Location, + QObject::tr("Failed to configure plugin")); } static void plugin_cb(const QString &cmd) @@ -187,8 +193,9 @@ static void plugin_cb(const QString &cmd) MythPluginManager *pmanager = gCoreContext->GetPluginManager(); if (pmanager) if (pmanager->run_plugin(cmd.trimmed())) - ShowOkPopup(QObject::tr("The plugin %1 has failed " - "to run for some reason...").arg(cmd)); + ShowNotificationError(QObject::tr("Plugin failure"), + _Location, + QObject::tr("%1 failed to run for some reason").arg(cmd)); } static void eject_cb(void) @@ -203,8 +210,8 @@ MythContextPrivate::MythContextPrivate(MythContext *lparent) disableeventpopup(false), m_ui(NULL), m_sh(new MythContextSlotHandler(this)), - MBEconnectPopup(NULL), - MBEversionPopup(NULL) + MBEversionPopup(NULL), + m_registration(-1) { InitializeMythDirs(); } @@ -217,6 +224,10 @@ MythContextPrivate::~MythContextPrivate() DestroyMythUI(); if (m_sh) m_sh->deleteLater(); + if (HasMythMainWindow() && m_registration > 0) + { + MythUINotificationCenter::GetInstance()->UnRegister(this, m_registration, true); + } } /** @@ -974,6 +985,12 @@ bool MythContextPrivate::event(QEvent *e) if (disableeventpopup) return true; + if (HasMythMainWindow() && m_registration < 0) + { + m_registration = + MythUINotificationCenter::GetInstance()->Register(this); + } + MythEvent *me = (MythEvent*)e; if (me->Message() == "VERSION_MISMATCH" && (1 == me->ExtraDataCount())) ShowVersionMismatchPopup(me->ExtraData(0).toUInt()); @@ -991,32 +1008,31 @@ bool MythContextPrivate::event(QEvent *e) void MythContextPrivate::ShowConnectionFailurePopup(bool persistent) { - if (MBEconnectPopup) + QDateTime now = MythDate::current(); + + if (m_lastCheck.isValid() && now < m_lastCheck) return; - QString message = (persistent) ? - QObject::tr( - "The connection to the master backend " - "server has gone away for some reason. " - "Is it running?") : - QObject::tr( - "Could not connect to the master backend server. Is " - "it running? Is the IP address set for it in " - "mythtv-setup correct?"); + m_lastCheck = now.addMSecs(5000); // don't refresh notification more than every 5s + QString message = QObject::tr("Could not connect to master backend"); if (HasMythMainWindow() && m_ui && m_ui->IsScreenSetup()) { - MBEconnectPopup = ShowOkPopup( - message, m_sh, SLOT(ConnectFailurePopupClosed())); + MythErrorNotification n(message, _Location, + QObject::tr("Is it running? Check IP address set in mythtv-setup")); + n.SetId(m_registration); + n.SetParent(this); + MythUINotificationCenter::GetInstance()->Queue(n); } } void MythContextPrivate::HideConnectionFailurePopup(void) { - MythConfirmationDialog *dlg = this->MBEconnectPopup; - this->MBEconnectPopup = NULL; - if (dlg) - dlg->Close(); + MythNotification n(QObject::tr("Backend is online"), _Location); + n.SetId(m_registration); + n.SetParent(this); + n.SetDuration(5); + MythUINotificationCenter::GetInstance()->Queue(n); } void MythContextPrivate::ShowVersionMismatchPopup(uint remote_version) @@ -1044,11 +1060,6 @@ void MythContextPrivate::ShowVersionMismatchPopup(uint remote_version) } } -void MythContextSlotHandler::ConnectFailurePopupClosed(void) -{ - d->MBEconnectPopup = NULL; -} - void MythContextSlotHandler::VersionMismatchPopupClosed(void) { d->MBEversionPopup = NULL; diff --git a/mythtv/libs/libmyth/mythcontext.h b/mythtv/libs/libmyth/mythcontext.h index c779fb25764..788781eb4a8 100644 --- a/mythtv/libs/libmyth/mythcontext.h +++ b/mythtv/libs/libmyth/mythcontext.h @@ -19,7 +19,6 @@ class MythContextSlotHandler : public QObject MythContextSlotHandler(MythContextPrivate *x) : d(x) { } private slots: - void ConnectFailurePopupClosed(void); void VersionMismatchPopupClosed(void); private: