Skip to content

Commit

Permalink
Display loss of connection to backend as a notification instead of a …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jyavenard committed Jul 8, 2013
1 parent 4a2de2e commit 7dcf2a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
65 changes: 38 additions & 27 deletions mythtv/libs/libmyth/mythcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QFileInfo>
#include <QDebug>
#include <QMutex>
#include <QDateTime>

#include <cmath>
#include <iostream>
Expand Down Expand Up @@ -38,6 +39,7 @@ using namespace std;
#include "mythlogging.h"
#include "mythsystemlegacy.h"
#include "mythmiscutil.h"
#include "mythuinotificationcenter.h"

#include "mythplugin.h"

Expand All @@ -50,6 +52,8 @@ using namespace std;

MythContext *gContext = NULL;

static const QString _Location = "MythContext";

class MythContextPrivate : public QObject
{
friend class MythContextSlotHandler;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -179,16 +184,18 @@ 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)
{
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)
Expand All @@ -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();
}
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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());
Expand All @@ -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)
Expand Down Expand Up @@ -1044,11 +1060,6 @@ void MythContextPrivate::ShowVersionMismatchPopup(uint remote_version)
}
}

void MythContextSlotHandler::ConnectFailurePopupClosed(void)
{
d->MBEconnectPopup = NULL;
}

void MythContextSlotHandler::VersionMismatchPopupClosed(void)
{
d->MBEversionPopup = NULL;
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmyth/mythcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class MythContextSlotHandler : public QObject
MythContextSlotHandler(MythContextPrivate *x) : d(x) { }

private slots:
void ConnectFailurePopupClosed(void);
void VersionMismatchPopupClosed(void);

private:
Expand Down

0 comments on commit 7dcf2a5

Please sign in to comment.