Permalink
Browse files

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.
  • Loading branch information...
1 parent 77b68d5 commit 217be2413a2638566ccdc7b12472976d18fe1f6a @daniel-kristjansson daniel-kristjansson committed May 3, 2012
Showing with 55 additions and 59 deletions.
  1. +17 −18 mythtv/libs/libmyth/backendselect.cpp
  2. +12 −8 mythtv/libs/libmyth/backendselect.h
  3. +26 −33 mythtv/libs/libmyth/mythcontext.cpp
View
35 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<DeviceLocation *>(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
View
20 mythtv/libs/libmyth/backendselect.h
@@ -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);
@@ -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*)
View
59 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;
}
/**

0 comments on commit 217be24

Please sign in to comment.