Ticket #3293: FrontendAutoDiscovery.diff
File FrontendAutoDiscovery.diff, 37.9 KB (added by , 17 years ago) |
---|
-
libs/libmyth/mythcontext.cpp
194 194 MythContextPrivate(MythContext *lparent); 195 195 ~MythContextPrivate(); 196 196 197 bool Init(bool gui );197 bool Init(bool gui, DatabaseParams *pParams = NULL ); 198 198 bool IsWideMode() const {return (m_baseWidth == 1280);} 199 199 void SetWideMode() {m_baseWidth = 1280; m_baseHeight = 720;} 200 200 bool IsSquareMode() const {return (m_baseWidth == 800);} … … 204 204 void StoreGUIsettings(void); 205 205 206 206 void LoadLogSettings(void); 207 bool LoadDatabaseSettings(bool reload );207 bool LoadDatabaseSettings(bool reload, DatabaseParams *pParams = NULL); 208 208 209 209 bool FixSettingsFile(void); 210 210 bool WriteSettingsFile(const DatabaseParams ¶ms, … … 407 407 } 408 408 } 409 409 410 bool MythContextPrivate::Init(bool gui )410 bool MythContextPrivate::Init(bool gui, DatabaseParams *pParams) 411 411 { 412 412 m_gui = gui; 413 413 … … 419 419 420 420 // Attempts to read DB info from "mysql.txt" from the 421 421 // filesystem, or create it if it does not exist. 422 if (!LoadDatabaseSettings(false ))422 if (!LoadDatabaseSettings(false, pParams )) 423 423 return false; 424 424 425 425 // Queries the user for the DB info, using the command … … 539 539 m_logprintlevel = parent->GetNumSetting("LogPrintLevel", LP_ERROR); 540 540 } 541 541 542 bool MythContextPrivate::LoadDatabaseSettings(bool reload )542 bool MythContextPrivate::LoadDatabaseSettings(bool reload, DatabaseParams *pParams) 543 543 { 544 544 if (reload) 545 545 { … … 547 547 delete m_settings; 548 548 m_settings = new Settings; 549 549 } 550 550 551 // Always load settings first from mysql.txt so LocalHostName can be used. 552 551 553 if (!parent->LoadSettingsFiles("mysql.txt")) 552 554 { 553 555 VERBOSE(VB_IMPORTANT, "Unable to read configuration file mysql.txt"); … … 557 559 parent->LoadSettingsFiles("mysql.txt"); 558 560 } 559 561 562 // Overlay mysql.txt settings if we were passed a DatabaseParams 563 564 if (pParams != NULL) 565 { 566 m_settings->SetSetting( "DBHostName" , pParams->dbHostName ); 567 m_settings->SetSetting( "DBPort" , pParams->dbPort ); 568 m_settings->SetSetting( "DBUserName" , pParams->dbUserName ); 569 m_settings->SetSetting( "DBPassword" , pParams->dbPassword ); 570 m_settings->SetSetting( "DBName" , pParams->dbName ); 571 m_settings->SetSetting( "DBType" , pParams->dbType ); 572 //m_settings->SetSetting( "wolEnabled" , pParams->wolEnabled ); 573 m_settings->SetSetting( "WOLsqlReconnectWaitTime", pParams->wolReconnect); 574 m_settings->SetSetting( "WOLsqlConnectRetry" , pParams->wolRetry ); 575 m_settings->SetSetting( "WOLsqlCommand" , pParams->wolCommand ); 576 } 577 560 578 // Even if we have loaded the settings file, it may be incomplete, 561 579 // so we check for missing values and warn user 562 580 FindSettingsProbs(); … … 823 841 : QObject(), d(NULL), app_binary_version(binversion) 824 842 { 825 843 qInitNetworkProtocols(); 844 845 d = new MythContextPrivate(this); 826 846 } 827 847 828 bool MythContext::Init(bool gui )848 bool MythContext::Init(bool gui, DatabaseParams *pParams ) 829 849 { 830 850 if (app_binary_version != MYTH_BINARY_VERSION) 831 851 { … … 838 858 return false; 839 859 } 840 860 841 d = new MythContextPrivate(this); 842 843 if (!d->Init(gui)) 861 if (!d->Init(gui, pParams)) 844 862 return false; 845 863 846 864 ActivateSettingsCache(true); … … 2440 2458 d->overriddenSettings[key] = value; 2441 2459 } 2442 2460 2443 2444 2461 bool MythContext::SendReceiveStringList(QStringList &strlist, bool quickTimeout, bool block) 2445 2462 { 2446 2463 d->serverSockLock.lock(); -
libs/libmyth/mythcontext.h
242 242 MythContext(const QString &binversion); 243 243 virtual ~MythContext(); 244 244 245 bool Init(bool gui = true );245 bool Init(bool gui = true, DatabaseParams *pParams = NULL ); 246 246 247 247 QString GetMasterHostPrefix(void); 248 248 -
programs/mythfrontend/masterselection.cpp
1 ////////////////////////////////////////////////////////////////////////////// 2 // Program Name: masterselection.cpp 3 // 4 // Purpose - Classes to Prompt user for MasterBackend 5 // 6 // Created By : David Blain Created On : Jan. 25, 2007 7 // Modified By : Modified On: 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #include "masterselection.h" 12 #include "upnp.h" 13 #include "mythxmlclient.h" 14 15 #include <qapplication.h> 16 #include <qinputdialog.h> 17 #include <qlineedit.h> 18 #include <qlabel.h> 19 #include <qfont.h> 20 21 ///////////////////////////////////////////////////////////////////////////// 22 // return values: -1 = Exit Application 23 // 0 = Continue with no Connection Infomation 24 // 1 = Connection Information found 25 ///////////////////////////////////////////////////////////////////////////// 26 27 int MasterSelection::GetConnectionInfo( MediaRenderer *pUPnp, 28 DatabaseParams *pParams, 29 bool bPromptForBackend ) 30 { 31 if ((pUPnp == NULL) || (pParams == NULL)) 32 { 33 VERBOSE( VB_IMPORTANT, "MasterSelectionDialog::GetConnectionInfo - Invalid NULL parameters." ); 34 return -1; 35 } 36 37 // ---------------------------------------------------------------------- 38 // Try to get the last selected (default) Master 39 // ---------------------------------------------------------------------- 40 41 int nRetCode = -1; 42 bool bExitLoop = false; 43 bool bTryConnectAgain = false; 44 QString sPin = ""; 45 MasterSelectionWindow *pMasterWindow = NULL; 46 DeviceLocation *pDeviceLoc = NULL; 47 48 if (!bPromptForBackend) 49 pDeviceLoc = pUPnp->GetDefaultMaster(); 50 51 if (pDeviceLoc != NULL) 52 sPin = pDeviceLoc->m_sSecurityPin; 53 54 // ---------------------------------------------------------------------- 55 // Loop until we have a valid DatabaseParams, or the user cancels 56 // ---------------------------------------------------------------------- 57 58 while (!bExitLoop) 59 { 60 bTryConnectAgain = false; 61 62 if (pDeviceLoc == NULL) 63 { 64 if ( pMasterWindow == NULL) 65 { 66 pMasterWindow = new MasterSelectionWindow(); 67 pMasterWindow->show(); 68 } 69 70 MasterSelectionDialog selectionDlg( pMasterWindow ); 71 72 // -------------------------------------------------------------- 73 // Show dialog and check for Cancel. 74 // -------------------------------------------------------------- 75 76 if ( !selectionDlg.exec() ) 77 { 78 nRetCode = -1; 79 bExitLoop = true; 80 } 81 else 82 { 83 // ---------------------------------------------------------- 84 // Did user select "No Backend" 85 // ---------------------------------------------------------- 86 87 sPin = ""; 88 89 if (( pDeviceLoc = selectionDlg.GetSelectedDevice()) == NULL) 90 { 91 nRetCode = 0; 92 bExitLoop = true; 93 } 94 } 95 } 96 97 // ------------------------------------------------------------------ 98 // If DeviceLoc != NULL... Try and retrieve ConnectionInformation 99 // ------------------------------------------------------------------ 100 101 if (pDeviceLoc != NULL) 102 { 103 MythXMLClient mythXml( pDeviceLoc->m_sLocation ); 104 105 UPnPResultCode eCode = mythXml.GetConnectionInfo( sPin, pParams ); 106 107 switch( eCode ) 108 { 109 case UPnPResult_Success: 110 { 111 cout << "Params.dbHostName = " << pParams->dbHostName << endl; 112 113 pUPnp->SetDefaultMaster( pDeviceLoc, sPin ); 114 115 bExitLoop = true; 116 nRetCode = 1; 117 118 break; 119 } 120 121 case UPnPResult_ActionNotAuthorized: 122 { 123 if ( pMasterWindow == NULL) 124 { 125 pMasterWindow = new MasterSelectionWindow(); 126 pMasterWindow->show(); 127 } 128 129 // Prompt For Pin and try again... 130 131 VERBOSE( VB_IMPORTANT, QString( "MasterSelection::GetConnectionInfo - Access Denied for %1" ) 132 .arg( pDeviceLoc->GetFriendlyName( true ) )); 133 //todo... 134 135 bool bOk; 136 137 sPin = QInputDialog::getText( pDeviceLoc->GetFriendlyName( true ), 138 "Security Pin:", 139 QLineEdit::Password, 140 sPin, 141 &bOk, 142 pMasterWindow ); 143 if ( bOk ) 144 bTryConnectAgain = true; 145 146 break; 147 } 148 149 default: 150 { 151 if ( pMasterWindow == NULL) 152 { 153 pMasterWindow = new MasterSelectionWindow(); 154 pMasterWindow->show(); 155 } 156 157 // Display Error Msg and have user select different Master. 158 159 VERBOSE( VB_IMPORTANT, QString( "MasterSelection::GetConnectionInfo - Error Retrieving ConnectionInfomation for %1 (%2) %3" ) 160 .arg( pDeviceLoc->GetFriendlyName( true ) ) 161 .arg( eCode ) 162 .arg( UPnp::GetResultDesc( eCode ))); 163 164 165 QMessageBox msgBox( "Error", 166 QString( "(%1) - %2" ) 167 .arg( eCode ) 168 .arg( UPnp::GetResultDesc( eCode )), 169 QMessageBox::Critical, 170 QMessageBox::Ok, 171 QMessageBox::NoButton, 172 QMessageBox::NoButton, 173 pMasterWindow, 174 NULL, TRUE, Qt::WStyle_Customize | Qt::WStyle_NoBorder ); 175 176 msgBox.exec(); 177 break; 178 } 179 } 180 181 if ( !bTryConnectAgain ) 182 { 183 pDeviceLoc->Release(); 184 pDeviceLoc = NULL; 185 } 186 } 187 } 188 189 if ( pMasterWindow != NULL) 190 { 191 pMasterWindow->hide(); 192 delete pMasterWindow; 193 } 194 195 return nRetCode; 196 } 197 198 ///////////////////////////////////////////////////////////////////////////// 199 // 200 ///////////////////////////////////////////////////////////////////////////// 201 202 MasterSelectionWindow::MasterSelectionWindow() : QWidget( NULL, "BackgroundWindow" ) 203 { 204 QDesktopWidget *pDesktop = QApplication::desktop(); 205 206 int nScreenHeight = pDesktop->height(); 207 208 float fhMulti = nScreenHeight / (float)600; 209 210 QFont font = QFont("Arial"); 211 212 if (!font.exactMatch()) 213 font = QFont(); 214 215 font.setStyleHint( QFont::SansSerif, QFont::PreferAntialias ); 216 font.setPointSize((int)floor(14 * fhMulti )); 217 218 QColorGroup colors( QColor( 255, 255, 255 ), // Foreground 219 QColor( 0, 64, 128 ), // background 220 QColor( 196, 196, 196 ), // light 221 QColor( 64, 64, 64 ), // dark 222 QColor( 128, 128, 128 ), // mid 223 QColor( 255, 255, 255 ), // text 224 QColor( 0, 100, 192 )); // Base 225 226 //setBackgroundColor( QColor( 0, 96, 192 )); 227 228 QApplication::setFont ( font, TRUE ); 229 QApplication::setPalette( QPalette( colors, colors, colors ), TRUE ); 230 231 showFullScreen(); 232 } 233 234 ///////////////////////////////////////////////////////////////////////////// 235 // 236 ///////////////////////////////////////////////////////////////////////////// 237 238 MasterSelectionDialog::MasterSelectionDialog( MasterSelectionWindow *pParent ) 239 : QDialog( pParent, "Master Mediaserver Selection", TRUE, WStyle_Customize | WStyle_NoBorder ) 240 { 241 242 print_verbose_messages |= VB_UPNP; 243 244 m_pListBox = new QListBox( this ); 245 m_pListBox->setFrameShape( QFrame::WinPanel ); 246 m_pListBox->setSelectionMode( QListBox::Single ); 247 248 m_pOk = new QPushButton( "OK" , this ); 249 m_pCancel = new QPushButton( "Cancel", this ); 250 m_pSearch = new QPushButton( "Search", this ); 251 252 m_pLayout = new QGridLayout( this, 7, 5, 6 ); 253 254 m_pLayout->setMargin( 50 ); 255 256 m_pLayout->addMultiCellWidget( new QLabel( tr( "Select Default Myth Backend Server:" ), this ), 1, 1, 0, 4 ); 257 258 m_pLayout->addMultiCellWidget( m_pListBox, 3, 3, 0, 4 ); 259 260 m_pLayout->addWidget( m_pSearch, 5, 0 ); 261 m_pLayout->addWidget( m_pCancel, 5, 3 ); 262 m_pLayout->addWidget( m_pOk , 5, 4 ); 263 264 connect( m_pOk , SIGNAL( clicked() ), SLOT( accept()) ); 265 connect( m_pCancel, SIGNAL( clicked() ), SLOT( reject()) ); 266 connect( m_pSearch, SIGNAL( clicked() ), SLOT( Search()) ); 267 268 showFullScreen(); 269 270 // ---------------------------------------------------------------------- 271 272 UPnp::AddListener( this ); 273 274 QListBoxItem *pItem = AddItem( NULL, "Do Not Connect To MythBackend" ); 275 276 m_pListBox->setCurrentItem( pItem ); 277 278 Search(); 279 FillListBox(); 280 } 281 282 ///////////////////////////////////////////////////////////////////////////// 283 // 284 ///////////////////////////////////////////////////////////////////////////// 285 286 MasterSelectionDialog::~MasterSelectionDialog() 287 { 288 UPnp::RemoveListener( this ); 289 290 for (ItemMap::iterator it = m_Items.begin(); 291 it != m_Items.end(); 292 ++it ) 293 { 294 ListBoxDevice *pItem = it.data(); 295 296 if (pItem != NULL) 297 delete pItem; 298 } 299 300 m_Items.clear(); 301 } 302 303 ///////////////////////////////////////////////////////////////////////////// 304 // Caller MUST call Release on returned pointer 305 ///////////////////////////////////////////////////////////////////////////// 306 307 DeviceLocation *MasterSelectionDialog::GetSelectedDevice( void ) 308 { 309 DeviceLocation *pLoc = NULL; 310 ListBoxDevice *pItem = (ListBoxDevice *)m_pListBox->selectedItem(); 311 312 if (pItem != NULL) 313 { 314 if ((pLoc = pItem->m_pLocation) != NULL) 315 pLoc->AddRef(); 316 } 317 318 return pLoc; 319 } 320 321 ///////////////////////////////////////////////////////////////////////////// 322 // 323 ///////////////////////////////////////////////////////////////////////////// 324 325 ListBoxDevice *MasterSelectionDialog::AddItem( DeviceLocation *pLoc, QString sName ) 326 { 327 ListBoxDevice *pItem = NULL; 328 QString sUSN = "None"; 329 330 if (pLoc != NULL) 331 sUSN = pLoc->m_sUSN; 332 333 ItemMap::iterator it = m_Items.find( sUSN ); 334 335 if ( it == m_Items.end()) 336 { 337 pItem = new ListBoxDevice( m_pListBox, sName, pLoc ); 338 m_Items.insert( sUSN, pItem ); 339 } 340 else 341 pItem = it.data(); 342 343 return pItem; 344 } 345 346 ///////////////////////////////////////////////////////////////////////////// 347 // 348 ///////////////////////////////////////////////////////////////////////////// 349 350 void MasterSelectionDialog::RemoveItem( QString sUSN ) 351 { 352 ItemMap::iterator it = m_Items.find( sUSN ); 353 354 if ( it != m_Items.end() ) 355 { 356 ListBoxDevice *pItem = it.data(); 357 358 if (pItem != NULL) 359 delete pItem; 360 361 m_Items.remove( it ); 362 } 363 } 364 365 ///////////////////////////////////////////////////////////////////////////// 366 // 367 ///////////////////////////////////////////////////////////////////////////// 368 369 void MasterSelectionDialog::Search( void ) 370 { 371 UPnp::PerformSearch( "urn:schemas-mythtv-org:device:MasterMediaServer:1" ); 372 } 373 374 ///////////////////////////////////////////////////////////////////////////// 375 // 376 ///////////////////////////////////////////////////////////////////////////// 377 378 void MasterSelectionDialog::FillListBox( void ) 379 { 380 381 EntryMap ourMap; 382 383 SSDPCacheEntries *pEntries = UPnp::g_SSDPCache.Find( "urn:schemas-mythtv-org:device:MasterMediaServer:1" ); 384 385 if (pEntries != NULL) 386 { 387 pEntries->AddRef(); 388 pEntries->Lock(); 389 390 EntryMap *pMap = pEntries->GetEntryMap(); 391 392 393 for (EntryMap::Iterator it = pMap->begin(); 394 it != pMap->end(); 395 ++it ) 396 { 397 DeviceLocation *pEntry = (DeviceLocation *)it.data(); 398 399 if (pEntry != NULL) 400 { 401 pEntry->AddRef(); 402 ourMap.insert( pEntry->m_sUSN, pEntry ); 403 } 404 } 405 406 pEntries->Unlock(); 407 pEntries->Release(); 408 } 409 410 // ---------------------------------------------------------------------- 411 412 for (EntryMap::Iterator it = ourMap.begin(); 413 it != ourMap.end(); 414 ++it ) 415 { 416 DeviceLocation *pEntry = (DeviceLocation *)it.data(); 417 418 if (pEntry != NULL) 419 { 420 AddItem( pEntry, pEntry->GetFriendlyName( true )); 421 422 pEntry->Release(); 423 } 424 } 425 } 426 427 ///////////////////////////////////////////////////////////////////////////// 428 // 429 ///////////////////////////////////////////////////////////////////////////// 430 431 void MasterSelectionDialog::customEvent(QCustomEvent *e) 432 { 433 434 if ((MythEvent::Type)(e->type()) == MythEvent::MythEventMessage) 435 { 436 MythEvent *me = (MythEvent *)e; 437 QString message = me->Message(); 438 439 cout << "MasterSelectionDialog::customEvent - " << message << " : " << me->ExtraData( 0 ) << " - " << me->ExtraData( 1 ) << endl; 440 441 if (message.startsWith( "SSDP_ADD" )) 442 { 443 QString sURI = me->ExtraData( 0 ); 444 QString sURN = me->ExtraData( 1 ); 445 QString sURL = me->ExtraData( 2 ); 446 447 if ( sURI.startsWith( "urn:schemas-mythtv-org:device:MasterMediaServer:" )) 448 { 449 DeviceLocation *pLoc = UPnp::g_SSDPCache.Find( sURI, sURN ); 450 451 if (pLoc != NULL) 452 { 453 pLoc->AddRef(); 454 455 AddItem( pLoc, pLoc->GetFriendlyName( true )); 456 457 pLoc->Release(); 458 } 459 } 460 } 461 else if (message.startsWith( "SSDP_REMOVE" )) 462 { 463 //-=>Note: This code will never get executed until 464 // SSDPCache is changed to handle NotifyRemove correctly 465 466 QString sURI = me->ExtraData( 0 ); 467 QString sURN = me->ExtraData( 1 ); 468 469 RemoveItem( sURN ); 470 } 471 } 472 } -
programs/mythfrontend/mediarenderer.cpp
1 ///////////////////////////////////////////////////////////////////////////// 2 // Program Name: mediarenderer.cpp 3 // 4 // Purpose - uPnp Media Renderer main Class 5 // 6 // Created By : David Blain Created On : Jan. 15, 2007 7 // Modified By : Modified On: 8 // 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #include "mediarenderer.h" 12 13 ///////////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////////// 15 // 16 // UPnp MediaRenderer Class implementaion 17 // 18 ///////////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////////// 20 21 ///////////////////////////////////////////////////////////////////////////// 22 // 23 ///////////////////////////////////////////////////////////////////////////// 24 25 MediaRenderer::MediaRenderer() 26 { 27 VERBOSE(VB_UPNP, "MediaRenderer::Begin" ); 28 29 // ---------------------------------------------------------------------- 30 // Initialize Configuration class (XML file for frontend) 31 // ---------------------------------------------------------------------- 32 33 SetConfiguration( new XmlConfiguration( "config.xml" )); 34 35 // ---------------------------------------------------------------------- 36 // Create mini HTTP Server 37 // ---------------------------------------------------------------------- 38 39 int nPort = g_pConfig->GetValue( "UPnP/MythFrontend/ServicePort", 6547 ); 40 41 m_pHttpServer = new HttpServer( nPort ); 42 43 if (!m_pHttpServer->ok()) 44 { 45 VERBOSE(VB_IMPORTANT, "MediaRenderer::HttpServer Create Error"); 46 // exit(BACKEND_BUGGY_EXIT_NO_BIND_STATUS); 47 return; 48 } 49 50 // ---------------------------------------------------------------------- 51 // Initialize UPnp Stack 52 // ---------------------------------------------------------------------- 53 54 if (Initialize( nPort, m_pHttpServer )) 55 { 56 // ------------------------------------------------------------------ 57 // Create device Description 58 // ------------------------------------------------------------------ 59 60 VERBOSE(VB_UPNP, QString( "MediaRenderer::Creating UPnp Description" )); 61 62 UPnpDevice &device = g_UPnpDeviceDesc.m_rootDevice; 63 64 device.m_sDeviceType = "urn:schemas-upnp-org:device:MediaRenderer:1"; 65 device.m_sFriendlyName = "MythTv AV Renderer"; 66 device.m_sManufacturer = "MythTV"; 67 device.m_sManufacturerURL = "http://www.mythtv.org"; 68 device.m_sModelDescription = "MythTV AV Media Renderer"; 69 device.m_sModelName = "MythTV AV Media Renderer"; 70 device.m_sModelURL = "http://www.mythtv.org"; 71 device.m_sUPC = ""; 72 device.m_sPresentationURL = ""; 73 74 // ------------------------------------------------------------------ 75 // Register any HttpServerExtensions... 76 // ------------------------------------------------------------------ 77 78 QString sSinkProtocols = "http-get:*:image/gif:*," 79 "http-get:*:image/jpeg:*," 80 "http-get:*:image/png:*," 81 "http-get:*:video/avi:*," 82 "http-get:*:audio/mpeg:*," 83 "http-get:*:audio/wav:*," 84 "http-get:*:video/mpeg:*," 85 "http-get:*:video/nupplevideo:*," 86 "http-get:*:video/x-ms-wmv:*"; 87 88 // VERBOSE(VB_UPNP, QString( "MediaRenderer::Registering AVTransport Service." )); 89 // m_pHttpServer->RegisterExtension( m_pUPnpAVT = new UPnpAVTransport( RootDevice() )); 90 91 VERBOSE(VB_UPNP, QString( "MediaRenderer::Registering CMGR Service." )); 92 m_pHttpServer->RegisterExtension( m_pUPnpCMGR= new UPnpCMGR( RootDevice(), "", sSinkProtocols )); 93 94 // VERBOSE(VB_UPNP, QString( "MediaRenderer::Registering RenderingControl Service." )); 95 // m_pHttpServer->RegisterExtension( m_pUPnpRCTL= new UPnpRCTL( RootDevice() )); 96 97 Start(); 98 99 } 100 else 101 { 102 VERBOSE(VB_IMPORTANT, "MediaRenderer::Unable to Initialize UPnp Stack"); 103 // exit(BACKEND_BUGGY_EXIT_NO_BIND_STATUS); 104 } 105 106 107 108 VERBOSE(VB_UPNP, QString( "MediaRenderer::End" )); 109 } 110 111 ///////////////////////////////////////////////////////////////////////////// 112 // 113 ///////////////////////////////////////////////////////////////////////////// 114 115 MediaRenderer::~MediaRenderer() 116 { 117 if (m_pHttpServer) 118 delete m_pHttpServer; 119 } 120 121 ///////////////////////////////////////////////////////////////////////////// 122 // Caller MUST call Release on returned pointer 123 ///////////////////////////////////////////////////////////////////////////// 124 125 DeviceLocation *MediaRenderer::GetDefaultMaster() 126 { 127 UPnp::PerformSearch( "urn:schemas-mythtv-org:device:MasterMediaServer:1" ); 128 129 QString sUSN = g_pConfig->GetValue( "UPnP/MythFrontend/DefaultBackend/USN" , "" ); 130 QString sPin = g_pConfig->GetValue( "UPnP/MythFrontend/DefaultBackend/SecurityPin", "" ); 131 132 if (sUSN.isEmpty()) 133 return NULL; 134 135 DeviceLocation *pDeviceLoc = NULL; 136 137 // Lets wait up to 2 seconds for the backend to answer our Search request; 138 139 QTime timer; 140 timer.start(); 141 142 while (timer.elapsed() < 2000 ) 143 { 144 pDeviceLoc = UPnp::g_SSDPCache.Find( "urn:schemas-mythtv-org:device:MasterMediaServer:1", 145 sUSN ); 146 147 if ( pDeviceLoc != NULL) 148 { 149 pDeviceLoc->AddRef(); 150 151 pDeviceLoc->m_sSecurityPin = sPin; 152 153 return pDeviceLoc; 154 } 155 156 usleep(10000); 157 } 158 159 return NULL; 160 } 161 162 ///////////////////////////////////////////////////////////////////////////// 163 // 164 ///////////////////////////////////////////////////////////////////////////// 165 166 void MediaRenderer::SetDefaultMaster( DeviceLocation *pDeviceLoc, const QString &sPin ) 167 { 168 if ( pDeviceLoc != NULL) 169 { 170 pDeviceLoc->m_sSecurityPin = sPin; 171 172 g_pConfig->SetValue( "UPnP/MythFrontend/DefaultBackend/USN" , pDeviceLoc->m_sUSN ); 173 g_pConfig->SetValue( "UPnP/MythFrontend/DefaultBackend/SecurityPin", sPin ); 174 g_pConfig->Save(); 175 } 176 } 177 -
programs/mythfrontend/main.cpp
50 50 51 51 #include "libmythui/myththemedmenu.h" 52 52 #include "libmythui/myththemebase.h" 53 #include "mediarenderer.h" 54 #include "masterselection.h" 53 55 54 56 #define NO_EXIT 0 55 57 #define QUIT 1 … … 59 61 static MythThemeBase *themeBase; 60 62 XBox *xbox = NULL; 61 63 64 MediaRenderer *g_pUPnp = NULL; 65 62 66 void startGuide(void) 63 67 { 64 68 uint chanid = 0; … … 757 761 758 762 int main(int argc, char **argv) 759 763 { 764 bool bPromptForBackend = false; 765 760 766 QString geometry = QString::null; 761 767 QString display = QString::null; 762 768 #ifdef Q_WS_X11 … … 814 820 return FRONTEND_EXIT_INVALID_CMDLINE; 815 821 } 816 822 } 823 else if (!strcmp(a.argv()[argpos],"--prompt") || 824 !strcmp(a.argv()[argpos],"-p" )) 825 { 826 bPromptForBackend = true; 827 } 817 828 } 818 829 819 830 if (!display.isEmpty()) … … 821 832 MythContext::SetX11Display(display); 822 833 } 823 834 835 // ---------------------------------------------------------------------- 836 824 837 gContext = new MythContext(MYTH_BINARY_VERSION); 825 if (!gContext->Init()) 838 g_pUPnp = new MediaRenderer(); 839 840 DatabaseParams *pParams = new DatabaseParams; 841 842 int nRetCode = MasterSelection::GetConnectionInfo( g_pUPnp, 843 pParams, 844 bPromptForBackend ); 845 switch( nRetCode ) 846 { 847 case -1: // Exit Application 848 return FRONTEND_EXIT_OK; 849 850 case 0: // Continue with no Connection Infomation 851 { 852 delete pParams; 853 pParams = NULL; 854 855 break; 856 } 857 858 case 1: // Connection Information found 859 default: 860 break; 861 } 862 863 // ---------------------------------------------------------------------- 864 865 866 if (!gContext->Init( true, pParams )) 826 867 { 827 868 VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting."); 828 869 return FRONTEND_EXIT_NO_MYTHCONTEXT; 829 870 } 830 871 872 if (pParams != NULL) 873 { 874 delete pParams; 875 pParams = NULL; 876 } 877 831 878 for(int argpos = 1; argpos < a.argc(); ++argpos) 832 879 { 833 880 if (!strcmp(a.argv()[argpos],"-l") || … … 974 1021 return FRONTEND_EXIT_INVALID_CMDLINE; 975 1022 } 976 1023 } 1024 else if (!strcmp(a.argv()[argpos],"--prompt") || 1025 !strcmp(a.argv()[argpos],"-p" )) 1026 { 1027 } 977 1028 else if ((argpos + 1 == a.argc()) && 978 1029 !QString(a.argv()[argpos]).startsWith("-")) 979 1030 { … … 1002 1053 " --get-setting KEY[,KEY2,etc] Returns the current database setting for 'KEY'" << endl << 1003 1054 " Use a comma seperated list to return multiple values" << endl << 1004 1055 "-v or --verbose debug-level Use '-v help' for level info" << endl << 1056 "-p or --prompt Always prompt for Mythbackend selection." << endl << 1005 1057 1006 1058 "--version Version information" << endl << 1007 1059 "<plugin> Initialize and run this plugin" << endl << … … 1257 1309 DestroyMythMainWindow(); 1258 1310 delete themeBase; 1259 1311 delete gContext; 1312 delete g_pUPnp; 1313 1260 1314 return FRONTEND_EXIT_OK; 1261 1315 } 1262 1316 -
programs/mythfrontend/mythfrontend.pro
26 26 HEADERS += manualbox.h playbackbox.h viewscheduled.h globalsettings.h 27 27 HEADERS += manualschedule.h programrecpriority.h channelrecpriority.h 28 28 HEADERS += statusbox.h networkcontrol.h custompriority.h 29 HEADERS += mediarenderer.h masterselection.h 29 30 30 31 SOURCES += main.cpp manualbox.cpp playbackbox.cpp viewscheduled.cpp 31 32 SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp 32 33 SOURCES += channelrecpriority.cpp statusbox.cpp networkcontrol.cpp 34 SOURCES += mediarenderer.cpp masterselection.cpp 33 35 SOURCES += custompriority.cpp 34 36 35 37 macx { -
programs/mythfrontend/masterselection.h
1 ////////////////////////////////////////////////////////////////////////////// 2 // Program Name: masterselection.h 3 // 4 // Purpose - Classes to Prompt user for MasterBackend 5 // 6 // Created By : David Blain Created On : Jan. 25, 2007 7 // Modified By : Modified On: 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #include <qdialog.h> 12 #include <qpushbutton.h> 13 #include <qlayout.h> 14 #include <qlistbox.h> 15 #include <qmessagebox.h> 16 #include <qmap.h> 17 #include <math.h> 18 19 #include "libmythupnp/upnpdevice.h" 20 #include "mediarenderer.h" 21 22 #ifndef __MASTERSELECTION_H__ 23 #define __MASTERSELECTION_H__ 24 25 ///////////////////////////////////////////////////////////////////////////// 26 // 27 ///////////////////////////////////////////////////////////////////////////// 28 29 class MasterSelection 30 { 31 public: 32 33 static int GetConnectionInfo( MediaRenderer *pUPnp, 34 DatabaseParams *pParams, 35 bool bPromptForBackend ); 36 }; 37 38 ///////////////////////////////////////////////////////////////////////////// 39 // 40 ///////////////////////////////////////////////////////////////////////////// 41 42 class ListBoxDevice : public QListBoxText 43 { 44 public: 45 46 DeviceLocation *m_pLocation; 47 48 ListBoxDevice( QListBox *pList, const QString &sName, DeviceLocation *pLoc ) 49 : QListBoxText( pList, sName ) 50 { 51 if ((m_pLocation = pLoc) != NULL) 52 m_pLocation->AddRef(); 53 } 54 55 virtual ~ListBoxDevice() 56 { 57 if ( m_pLocation != NULL) 58 m_pLocation->Release(); 59 } 60 }; 61 62 typedef QMap< QString, ListBoxDevice *> ItemMap; 63 64 ///////////////////////////////////////////////////////////////////////////// 65 // 66 ///////////////////////////////////////////////////////////////////////////// 67 68 class MasterSelectionWindow : public QWidget 69 { 70 public: 71 72 MasterSelectionWindow(); 73 74 }; 75 76 ///////////////////////////////////////////////////////////////////////////// 77 // 78 ///////////////////////////////////////////////////////////////////////////// 79 80 class MasterSelectionDialog : public QDialog 81 { 82 Q_OBJECT 83 84 protected: 85 86 ItemMap m_Items; 87 88 QGridLayout *m_pLayout; 89 QListBox *m_pListBox; 90 91 QPushButton *m_pOk; 92 QPushButton *m_pCancel; 93 QPushButton *m_pSearch; 94 95 ListBoxDevice *AddItem ( DeviceLocation *pLoc, QString sName ); 96 void RemoveItem( QString sURN ); 97 98 public slots: 99 100 void Search ( void ); 101 void FillListBox( void ); 102 103 public: 104 105 MasterSelectionDialog( MasterSelectionWindow *pParent ); 106 virtual ~MasterSelectionDialog(); 107 108 void customEvent(QCustomEvent *e); 109 110 DeviceLocation *GetSelectedDevice( void ); 111 112 113 }; 114 115 /* 116 ///////////////////////////////////////////////////////////////////////////// 117 // 118 ///////////////////////////////////////////////////////////////////////////// 119 120 class PswrdDialog : public QDialog 121 { 122 public: 123 124 PswrdDialog( MasterSelectionWindow *pParent, 125 ); 126 virtual ~PswrdDialog(); 127 128 QString SetPassword(); 129 QString GetPassword(); 130 }; 131 */ 132 #endif -
programs/mythfrontend/mediarenderer.h
1 ////////////////////////////////////////////////////////////////////////////// 2 // Program Name: mediarenderer.h 3 // 4 // Purpose - uPnp Media Renderer main Class 5 // 6 // Created By : David Blain Created On : Jan. 25, 2007 7 // Modified By : Modified On: 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef __MEDIARENDERER_H__ 12 #define __MEDIARENDERER_H__ 13 14 #include <qobject.h> 15 #include <qmutex.h> 16 17 #include "libmythupnp/upnp.h" 18 #include "libmythupnp/upnpcmgr.h" 19 #include "libmythupnp/mythxmlclient.h" 20 21 ////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////// 23 // 24 // 25 // 26 ////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////// 28 29 class MediaRenderer : public UPnp 30 { 31 private: 32 33 HttpServer *m_pHttpServer; 34 35 protected: 36 37 // UPnpControl *m_pUPnpControl; // Do not delete (auto deleted) 38 UPnpCMGR *m_pUPnpCMGR; // Do not delete (auto deleted) 39 40 public: 41 MediaRenderer(); 42 virtual ~MediaRenderer(); 43 44 DeviceLocation *GetDefaultMaster(); 45 void SetDefaultMaster( DeviceLocation *pDeviceLoc, const QString &sPin ); 46 47 }; 48 49 #endif