bool UPnpCDSVideo::LoadSeasons(const UPnpCDSRequest* pRequest, UPnpCDSExtensionResults* pResults, IDTokenMap tokens) { QString sRequestId = pRequest->m_sObjectId; uint16_t nCount = pRequest->m_nRequestedCount; uint16_t nOffset = pRequest->m_nStartingIndex; // We must use a dedicated connection to get an acccurate value from // FOUND_ROWS() MSqlQuery query(MSqlQuery::InitCon(MSqlQuery::kDedicatedConnection)); QString sql = "SELECT SQL_CALC_FOUND_ROWS " "v.season, COUNT(DISTINCT v.intid), v.intid " "FROM videometadata v " "%1 " // whereString "GROUP BY v.season " "ORDER BY v.season " "LIMIT :OFFSET,:COUNT "; QStringList clauses; QString whereString = BuildWhereClause(clauses, tokens); query.prepare(sql.arg(whereString)); BindValues(query, tokens); query.bindValue(":OFFSET", nOffset); query.bindValue(":COUNT", nCount); if (!query.exec()) return false; while (query.next()) { int nSeason = query.value(0).toInt(); int nVideoCount = query.value(1).toInt(); int nVidID = query.value(2).toInt(); QString sTitle = QObject::tr("Season %1").arg(nSeason); // TODO Album or plain old container? CDSObject* pContainer = CDSObject::CreateAlbum( CreateIDString(sRequestId, "Season", nSeason), sTitle, pRequest->m_sParentId, NULL ); pContainer->SetPropValue("description", QObject::tr("%n Episode(s)", "", nVideoCount)); pContainer->SetPropValue("longdescription", QObject::tr("%n Episode(s)", "", nVideoCount)); pContainer->SetPropValue("storageMedium", "HDD"); pContainer->SetChildCount(nVideoCount); pContainer->SetChildContainerCount(0); PopulateArtworkURIS(pContainer, nVidID, m_URIBase); pResults->Add(pContainer); pContainer->DecrRef(); } // Just in case FOUND_ROWS() should fail, ensure m_nTotalMatches contains // at least the size of this result set if (query.size() >= 0) pResults->m_nTotalMatches = query.size(); // Fetch the total number of matches ignoring any LIMITs query.prepare("SELECT FOUND_ROWS()"); if (query.exec() && query.next()) pResults->m_nTotalMatches = query.value(0).toUInt(); return true; }
bool UPnpCDSVideo::LoadGenres(const UPnpCDSRequest* pRequest, UPnpCDSExtensionResults* pResults, IDTokenMap tokens) { QString sRequestId = pRequest->m_sObjectId; uint16_t nCount = pRequest->m_nRequestedCount; uint16_t nOffset = pRequest->m_nStartingIndex; // We must use a dedicated connection to get an acccurate value from // FOUND_ROWS() MSqlQuery query(MSqlQuery::InitCon(MSqlQuery::kDedicatedConnection)); QString sql = "SELECT SQL_CALC_FOUND_ROWS " "v.category, g.genre, COUNT(DISTINCT v.intid) " "FROM videometadata v " "LEFT JOIN videogenre g ON g.intid=v.category " "%1 " // whereString "GROUP BY g.intid " "ORDER BY g.genre " "LIMIT :OFFSET,:COUNT "; QStringList clauses; clauses.append("v.category != 0"); QString whereString = BuildWhereClause(clauses, tokens); query.prepare(sql.arg(whereString)); BindValues(query, tokens); query.bindValue(":OFFSET", nOffset); query.bindValue(":COUNT", nCount); if (!query.exec()) return false; while (query.next()) { int nGenreID = query.value(0).toInt(); QString sName = query.value(1).toString(); int nVideoCount = query.value(2).toInt(); // TODO Album or plain old container? CDSObject* pContainer = CDSObject::CreateMovieGenre( CreateIDString(sRequestId, "Genre", nGenreID), sName, pRequest->m_sParentId, NULL ); pContainer->SetChildCount(nVideoCount); pContainer->SetChildContainerCount(0); pResults->Add(pContainer); pContainer->DecrRef(); } // Just in case FOUND_ROWS() should fail, ensure m_nTotalMatches contains // at least the size of this result set if (query.size() >= 0) pResults->m_nTotalMatches = query.size(); // Fetch the total number of matches ignoring any LIMITs query.prepare("SELECT FOUND_ROWS()"); if (query.exec() && query.next()) pResults->m_nTotalMatches = query.value(0).toUInt(); return true; }
void UPnpCDSVideo::CreateRoot() { if (m_pRoot) return; m_pRoot = CDSObject::CreateContainer(m_sExtensionId, m_sName, "0"); CDSObject* pContainer; QString containerId = m_sExtensionId + "/%1"; // HACK: I'm not entirely happy with this solution, but it's at least // tidier than passing through half a dozen extra args to Load[Foo] // or having yet more methods just to load the counts UPnpCDSRequest *pRequest = new UPnpCDSRequest(); pRequest->m_nRequestedCount = 0; // We don't want to load any results, we just want the TotalCount UPnpCDSExtensionResults *pResult = new UPnpCDSExtensionResults(); IDTokenMap tokens; // END HACK // ----------------------------------------------------------------------- // All Videos // ----------------------------------------------------------------------- pContainer = CDSObject::CreateContainer ( containerId.arg("Video"), QObject::tr("All Videos"), m_sExtensionId, // Parent Id NULL ); // HACK LoadVideos(pRequest, pResult, tokens); pContainer->SetChildCount(pResult->m_nTotalMatches); pContainer->SetChildContainerCount(0); // END HACK m_pRoot->AddChild(pContainer); // ----------------------------------------------------------------------- // Films // ----------------------------------------------------------------------- pContainer = CDSObject::CreateContainer ( containerId.arg("Movie"), QObject::tr("Movies"), m_sExtensionId, // Parent Id NULL ); // HACK LoadMovies(pRequest, pResult, tokens); pContainer->SetChildCount(pResult->m_nTotalMatches); pContainer->SetChildContainerCount(0); // END HACK m_pRoot->AddChild(pContainer); // ----------------------------------------------------------------------- // Series // ----------------------------------------------------------------------- pContainer = CDSObject::CreateContainer ( containerId.arg("Series"), QObject::tr("Series"), m_sExtensionId, // Parent Id NULL ); // HACK LoadSeries(pRequest, pResult, tokens); pContainer->SetChildCount(pResult->m_nTotalMatches); pContainer->SetChildContainerCount(0); // END HACK m_pRoot->AddChild(pContainer); // ----------------------------------------------------------------------- // Other (Home videos?) // ----------------------------------------------------------------------- // pContainer = CDSObject::CreateContainer ( containerId.arg("Other"), // QObject::tr("Other"), // m_sExtensionId, // Parent Id // NULL ); // m_pRoot->AddChild(pContainer); // ----------------------------------------------------------------------- // Genre // ----------------------------------------------------------------------- pContainer = CDSObject::CreateContainer ( containerId.arg("Genre"), QObject::tr("Genre"), m_sExtensionId, // Parent Id NULL ); // HACK LoadGenres(pRequest, pResult, tokens); pContainer->SetChildCount(pResult->m_nTotalMatches); pContainer->SetChildContainerCount(0); // END HACK m_pRoot->AddChild(pContainer); // ----------------------------------------------------------------------- // By Directory // ----------------------------------------------------------------------- // pContainer = CDSObject::CreateStorageSystem ( containerId.arg("Directory"), // QObject::tr("Directory"), // m_sExtensionId, // Parent Id // NULL ); // m_pRoot->AddChild(pContainer); // HACK delete pRequest; delete pResult; // END HACK }