Skip to content

Commit

Permalink
Make UPnP backend selector buttons work.
Browse files Browse the repository at this point in the history
I assume at some point these buttons worked, but the code to make them work was
not there anymore. I didn't bother to do any archeology I just added the functionality
back in a way that made sense to me.
  • Loading branch information
daniel-kristjansson committed May 4, 2012
1 parent 77b68d5 commit 217be24
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 59 deletions.
35 changes: 17 additions & 18 deletions mythtv/libs/libmyth/backendselect.cpp
Expand Up @@ -37,31 +37,28 @@ BackendSelection::~BackendSelection()
m_devices.clear();
}

bool BackendSelection::m_backendChanged = false;

bool BackendSelection::prompt(DatabaseParams *dbParams,
Configuration *pConfig)
BackendSelection::Decision BackendSelection::Prompt(
DatabaseParams *dbParams, Configuration *pConfig)
{
m_backendChanged = false;

Decision ret = kCancelConfigure;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
if (!mainStack)
return false;
return ret;

BackendSelection *backendSettings = new BackendSelection(mainStack,
dbParams,
pConfig, true);
BackendSelection *backendSettings =
new BackendSelection(mainStack, dbParams, pConfig, true);

if (backendSettings->Create())
{
mainStack->AddScreen(backendSettings, false);
qApp->exec();
ret = backendSettings->m_backendDecision;
mainStack->PopScreen(backendSettings, false);
}
else
delete backendSettings;

return m_backendChanged;
return ret;
}

bool BackendSelection::Create(void)
Expand Down Expand Up @@ -97,7 +94,7 @@ void BackendSelection::Accept(MythUIButtonListItem *item)
DeviceLocation *dev = qVariantValue<DeviceLocation *>(item->GetData());

if (!dev)
Close();
Cancel();

if (ConnectBackend(dev)) // this does a Release()
{
Expand All @@ -108,7 +105,7 @@ void BackendSelection::Accept(MythUIButtonListItem *item)
m_pConfig->SetValue(kDefaultUSN, m_USN);
m_pConfig->Save();
}
Close();
Close(kAcceptConfigure);
}
}

Expand Down Expand Up @@ -231,12 +228,12 @@ bool BackendSelection::ConnectBackend(DeviceLocation *dev)
return false;
}

void BackendSelection::Cancel()
void BackendSelection::Cancel(void)
{
Close();
Close(kCancelConfigure);
}

void BackendSelection::Load()
void BackendSelection::Load(void)
{
SSDP::Instance()->AddListener(this);
SSDP::Instance()->PerformSearch(gBackendURI);
Expand All @@ -259,7 +256,7 @@ void BackendSelection::Init(void)

void BackendSelection::Manual(void)
{
Close();
Close(kManualConfigure);
}

void BackendSelection::RemoveItem(QString USN)
Expand Down Expand Up @@ -361,8 +358,10 @@ void BackendSelection::PromptForPassword(void)
delete pwDialog;
}

void BackendSelection::Close(void)
void BackendSelection::Close(Decision d)
{
m_backendDecision = d;

if (m_exitOnFinish)
qApp->quit();
else
Expand Down
20 changes: 12 additions & 8 deletions mythtv/libs/libmyth/backendselect.h
Expand Up @@ -39,24 +39,27 @@ class BackendSelection : public MythScreenType
Q_OBJECT

public:
typedef enum Decision
{
kManualConfigure = -1,
kCancelConfigure = 0,
kAcceptConfigure = +1,
} BackendDecision;
static Decision Prompt(
DatabaseParams *dbParams, Configuration *pConfig);

BackendSelection(MythScreenStack *parent, DatabaseParams *params,
Configuration *pConfig, bool exitOnFinish = false);
virtual ~BackendSelection();

bool Create(void);
void customEvent(QEvent *event);

static bool prompt(DatabaseParams *dbParams, Configuration *pConfig);

signals:
// void

public slots:
protected slots:
void Accept(void);
void Accept(MythUIButtonListItem *);
void Manual(void); ///< Linked to 'Configure Manually' button
void Cancel(void); ///< Linked to 'Cancel' button
void Close(void);

private:
void Load(void);
Expand All @@ -66,6 +69,7 @@ class BackendSelection : public MythScreenType
void RemoveItem(QString URN);
bool TryDBfromURL(const QString &error, QString URL);
void PromptForPassword(void);
void Close(Decision);

DatabaseParams *m_DBparams;
Configuration *m_pConfig;
Expand All @@ -83,7 +87,7 @@ class BackendSelection : public MythScreenType

QMutex m_mutex;

static bool m_backendChanged;
BackendDecision m_backendDecision;
};

Q_DECLARE_METATYPE(DeviceLocation*)
Expand Down
59 changes: 26 additions & 33 deletions mythtv/libs/libmyth/mythcontext.cpp
Expand Up @@ -383,45 +383,37 @@ bool MythContextPrivate::FindDatabase(bool prompt, bool noAutodetect)

manualSelect &= m_gui; // no interactive command-line chooser yet

// Last, get the user to select a backend from a possible list:
if (manualSelect)
// Queries the user for the DB info
do
{
switch (ChooseBackend(QString::null))
if (manualSelect)
{
case -1: // User asked to configure database manually
if (PromptForDatabaseParams(""))
// Get the user to select a backend from a possible list:
BackendSelection::Decision d = (BackendSelection::Decision)
ChooseBackend(failure);
switch (d)
{
case BackendSelection::kAcceptConfigure:
break;
else
goto NoDBfound; // User cancelled - changed their mind?

case 0: // User cancelled. Exit application
goto NoDBfound;

case 1: // User selected a backend, so m_DBparams
break; // should now contain the database details

default:
goto NoDBfound;
case BackendSelection::kManualConfigure:
manualSelect = false;
break;
case BackendSelection::kCancelConfigure:
goto NoDBfound;
}
}
failure = TestDBconnection();
}


// Queries the user for the DB info, using the command
// line or the GUI depending on the application.
while (!failure.isEmpty())
{
LOG(VB_GENERAL, LOG_ALERT, failure);
if (( manualSelect && ChooseBackend(failure)) ||
(!manualSelect && PromptForDatabaseParams(failure)))
if (!manualSelect)
{
failure = TestDBconnection();
if (failure.length())
LOG(VB_GENERAL, LOG_ALERT, failure);
if (!PromptForDatabaseParams(failure))
goto NoDBfound;
}
else
goto NoDBfound;

failure = TestDBconnection();
if (!failure.isEmpty())
LOG(VB_GENERAL, LOG_ALERT, failure);
}
while (!failure.isEmpty());

DBfound:
LOG(VB_GENERAL, LOG_DEBUG, "FindDatabase() - Success!");
Expand Down Expand Up @@ -780,11 +772,12 @@ int MythContextPrivate::ChooseBackend(const QString &error)

LOG(VB_GENERAL, LOG_INFO, "Putting up the UPnP backend chooser");

BackendSelection::prompt(&m_DBparams, m_pConfig);
BackendSelection::Decision ret =
BackendSelection::Prompt(&m_DBparams, m_pConfig);

EndTempWindow();

return 1;
return (int)ret;
}

/**
Expand Down

0 comments on commit 217be24

Please sign in to comment.