From 217be2413a2638566ccdc7b12472976d18fe1f6a Mon Sep 17 00:00:00 2001 From: Daniel Kristjansson Date: Thu, 3 May 2012 10:46:15 -0400 Subject: [PATCH] Make UPnP backend selector buttons work. 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. --- mythtv/libs/libmyth/backendselect.cpp | 35 ++++++++-------- mythtv/libs/libmyth/backendselect.h | 20 +++++---- mythtv/libs/libmyth/mythcontext.cpp | 59 ++++++++++++--------------- 3 files changed, 55 insertions(+), 59 deletions(-) diff --git a/mythtv/libs/libmyth/backendselect.cpp b/mythtv/libs/libmyth/backendselect.cpp index 309a7a3a8cf..1d010e6a16e 100644 --- a/mythtv/libs/libmyth/backendselect.cpp +++ b/mythtv/libs/libmyth/backendselect.cpp @@ -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) @@ -97,7 +94,7 @@ void BackendSelection::Accept(MythUIButtonListItem *item) DeviceLocation *dev = qVariantValue(item->GetData()); if (!dev) - Close(); + Cancel(); if (ConnectBackend(dev)) // this does a Release() { @@ -108,7 +105,7 @@ void BackendSelection::Accept(MythUIButtonListItem *item) m_pConfig->SetValue(kDefaultUSN, m_USN); m_pConfig->Save(); } - Close(); + Close(kAcceptConfigure); } } @@ -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); @@ -259,7 +256,7 @@ void BackendSelection::Init(void) void BackendSelection::Manual(void) { - Close(); + Close(kManualConfigure); } void BackendSelection::RemoveItem(QString USN) @@ -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 diff --git a/mythtv/libs/libmyth/backendselect.h b/mythtv/libs/libmyth/backendselect.h index c96fdb9c3dd..6a8bae1d317 100644 --- a/mythtv/libs/libmyth/backendselect.h +++ b/mythtv/libs/libmyth/backendselect.h @@ -39,6 +39,15 @@ 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(); @@ -46,17 +55,11 @@ class BackendSelection : public MythScreenType 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); @@ -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; @@ -83,7 +87,7 @@ class BackendSelection : public MythScreenType QMutex m_mutex; - static bool m_backendChanged; + BackendDecision m_backendDecision; }; Q_DECLARE_METATYPE(DeviceLocation*) diff --git a/mythtv/libs/libmyth/mythcontext.cpp b/mythtv/libs/libmyth/mythcontext.cpp index d452c286646..9f012cf8129 100644 --- a/mythtv/libs/libmyth/mythcontext.cpp +++ b/mythtv/libs/libmyth/mythcontext.cpp @@ -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!"); @@ -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; } /**