void CURL::GetURLWithoutFilename(CStdString& strURL) const { unsigned int sizeneed = m_strProtocol.length() + m_strDomain.length() + m_strUserName.length() + m_strPassword.length() + m_strHostName.length() + 10; if( strURL.capacity() < sizeneed ) strURL.reserve(sizeneed); if (m_strProtocol == "") { #ifdef _LINUX strURL.Empty(); #else strURL = m_strFileName.substr(0, 2); // only copy 'e:' #endif return ; } strURL = m_strProtocol; strURL += "://"; if (m_strDomain != "") { strURL += m_strDomain; strURL += ";"; } else if (m_strUserName != "") { strURL += URLEncodeInline(m_strUserName); if (m_strPassword != "") { strURL += ":"; strURL += URLEncodeInline(m_strPassword); } strURL += "@"; } else if (m_strDomain != "") strURL += "@"; if (m_strHostName != "") { if( m_strProtocol.Equals("rar") || m_strProtocol.Equals("zip") || m_strProtocol.Equals("musicsearch")) strURL += URLEncodeInline(m_strHostName); else strURL += m_strHostName; if (HasPort()) { CStdString strPort; strPort.Format("%i", m_iPort); strURL += ":"; strURL += strPort; } strURL += "/"; } }
void CEditUI::PaintText(HDC hDC) { if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor(); if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor(); if( m_sText.IsEmpty() ) return; CStdString sText = m_sText; if( m_bPasswordMode ) { sText.Empty(); LPCTSTR p = m_sText.GetData(); while( *p != _T('\0') ) { sText += m_cPasswordChar; p = ::CharNext(p); } } RECT rc = m_rcItem; rc.left += m_rcTextPadding.left; rc.right -= m_rcTextPadding.right; rc.top += m_rcTextPadding.top; rc.bottom -= m_rcTextPadding.bottom; if( IsEnabled() ) { CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwTextColor, \ m_iFont, DT_SINGLELINE | m_uTextStyle); } else { CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwDisabledTextColor, \ m_iFont, DT_SINGLELINE | m_uTextStyle); } }
void DMSHelper::GetErrorDescription(HRESULT hr, CStdString& sErrReason) { sErrReason.Empty(); if( GetDocProvProxy()) { GetDocProvProxy()->GetErrorDescription(hr, sErrReason); } }
bool CAirTunesServer::StartServer(int port, bool nonlocal, bool usePassword, const CStdString &password/*=""*/) { bool success = false; CStdString pw = password; CNetworkInterface *net = g_application.getNetwork().GetFirstConnectedInterface(); StopServer(true); if (net) { m_macAddress = net->GetMacAddress(); m_macAddress.Replace(":",""); while (m_macAddress.size() < 12) { m_macAddress = CStdString("0") + m_macAddress; } } else { m_macAddress = "000102030405"; } if (!usePassword) { pw.Empty(); } ServerInstance = new CAirTunesServer(port, nonlocal); if (ServerInstance->Initialize(password)) { ServerInstance->Create(); success = true; } if (success) { CStdString appName; appName.Format("%s@XBMC", m_macAddress.c_str()); std::map<std::string, std::string> txt; txt["cn"] = "0,1"; txt["ch"] = "2"; txt["ek"] = "1"; txt["et"] = "0,1"; txt["sv"] = "false"; txt["tp"] = "UDP"; txt["sm"] = "false"; txt["ss"] = "16"; txt["sr"] = "44100"; txt["pw"] = "false"; txt["vn"] = "3"; txt["txtvers"] = "1"; CZeroconf::GetInstance()->PublishService("servers.airtunes", "_raop._tcp", appName, port, txt); } return success; }
bool N7Xml::GetString(XMLNode xRootNode, const char* strTag, CStdString& strStringValue) { XMLNode xNode = xRootNode.getChildNode(strTag ); if (!xNode.isEmpty()) { strStringValue = xNode.getText(); return true; } strStringValue.Empty(); return false; }
//////////////////////////////////////////////////////////////////////////////////// // Function: ExtractQuoteInfo() // Extracts the information in quotes from the string line, returning it in quote //////////////////////////////////////////////////////////////////////////////////// bool CCueDocument::ExtractQuoteInfo(const CStdString &line, CStdString "e) { quote.Empty(); int left = line.Find('\"'); if (left < 0) return false; int right = line.Find('\"', left + 1); if (right < 0) return false; quote = line.Mid(left + 1, right - left - 1); g_charsetConverter.unknownToUTF8(quote); return true; }
/*! Returns true if the encoding of the document is other then UTF-8. /param strEncoding Returns the encoding of the document. Empty if UTF-8 */ bool XMLUtils::GetEncoding(const CXBMCTinyXML* pDoc, CStdString& strEncoding) { const TiXmlNode* pNode=NULL; while ((pNode=pDoc->IterateChildren(pNode)) && pNode->Type()!=TiXmlNode::TINYXML_DECLARATION) {} if (!pNode) return false; const TiXmlDeclaration* pDecl=pNode->ToDeclaration(); if (!pDecl) return false; strEncoding=pDecl->Encoding(); if (strEncoding.Equals("UTF-8") || strEncoding.Equals("UTF8")) strEncoding.Empty(); strEncoding.MakeUpper(); return !strEncoding.IsEmpty(); // Other encoding then UTF8? }
bool CGUIControlFactory::GetString(const TiXmlNode* pRootNode, const char *strTag, CStdString &text) { if (!XMLUtils::GetString(pRootNode, strTag, text)) return false; if (text == "-") text.Empty(); if (StringUtils::IsNaturalNumber(text)) text = g_localizeStrings.Get(atoi(text.c_str())); else g_charsetConverter.unknownToUTF8(text); return true; }
bool XMLUtils::GetString(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue) { const TiXmlElement* pElement = pRootNode->FirstChildElement(strTag ); if (!pElement) return false; const TiXmlNode* pNode = pElement->FirstChild(); if (pNode != NULL) { strStringValue = pNode->Value(); return true; } strStringValue.Empty(); return false; }
HRESULT CNfoFile::Create(const CStdString& strPath) { if (FAILED(Load(strPath))) return E_FAIL; CStdString strURL; CFileItemList items; bool bNfo=false; if (m_strContent.Equals("albums")) { CAlbum album; bNfo = GetDetails(album); CDirectory::GetDirectory("q:\\system\\scrapers\\music",items,".xml",false); } else if (m_strContent.Equals("artists")) { CArtist artist; bNfo = GetDetails(artist); CDirectory::GetDirectory("q:\\system\\scrapers\\music",items,".xml",false); } else if (m_strContent.Equals("tvshows") || m_strContent.Equals("movies") || m_strContent.Equals("musicvideos")) { // first check if it's an XML file with the info we need CVideoInfoTag details; bNfo = GetDetails(details); CDirectory::GetDirectory(_P("q:\\system\\scrapers\\video"),items,".xml",false); if (m_strContent.Equals("tvshows") && bNfo) // need to identify which scraper strURL = details.m_strEpisodeGuide; } if (bNfo) { m_strScraper = "NFO"; if (!m_strContent.Equals("tvshows") || !CUtil::GetFileName(strPath).Equals("tvshow.nfo")) // need to identify which scraper return S_OK; } for (int i=0;i<items.Size();++i) { if (!items[i]->m_bIsFolder && !FAILED(Scrape(items[i]->m_strPath,strURL))) { strURL.Empty(); break; } } if (m_strContent.Equals("tvshows")) return (strURL.IsEmpty() && !m_strScraper.IsEmpty())?S_OK:E_FAIL; return (m_strImDbUrl.size() > 0) ? S_OK : E_FAIL; }
bool CDNSNameCache::Lookup(const CStdString& strHostName, CStdString& strIpAddress) { if (strHostName.empty() && strIpAddress.empty()) return false; // first see if this is already an ip address unsigned long address = inet_addr(strHostName.c_str()); strIpAddress.Empty(); if (address != INADDR_NONE) { strIpAddress.Format("%d.%d.%d.%d", (address & 0xFF), (address & 0xFF00) >> 8, (address & 0xFF0000) >> 16, (address & 0xFF000000) >> 24 ); return true; }
bool GUIFontManager::GetFirstFontSetUnicode(CStdString& strFontSet) { strFontSet.Empty(); // Load our font file CXBMCTinyXML xmlDoc; if (!OpenFontFile(xmlDoc)) return false; TiXmlElement* pRootElement = xmlDoc.RootElement(); const TiXmlNode *pChild = pRootElement->FirstChild(); CStdString strValue = pChild->Value(); if (strValue == "fontset") { while (pChild) { strValue = pChild->Value(); if (strValue == "fontset") { const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id"); const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode"); // Check if this is a fontset with a ttf attribute set to true if (unicodeAttr != NULL && stricmp(unicodeAttr, "true") == 0) { // This is the first ttf fontset strFontSet=idAttr; break; } } pChild = pChild->NextSibling(); } // If no fontset was loaded if (pChild == NULL) CLog::Log(LOGWARNING, "file doesnt have <fontset> with attribute unicode=\"true\""); } else { CLog::Log(LOGERROR, "file doesnt have <fontset> in <fonts>, but rather %s", strValue.c_str()); } return !strFontSet.IsEmpty(); }
bool XMLUtils::GetString(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue) { const TiXmlElement* pElement = pRootNode->FirstChildElement(strTag ); if (!pElement) return false; const char* encoded = pElement->Attribute("urlencoded"); const TiXmlNode* pNode = pElement->FirstChild(); if (pNode != NULL) { strStringValue = pNode->Value(); if (encoded && strcasecmp(encoded,"yes") == 0) CURL::Decode(strStringValue); return true; } strStringValue.Empty(); return false; }
void StringUtils::SecondsToTimeString(long lSeconds, CStdString& strHMS, TIME_FORMAT format) { int hh = lSeconds / 3600; lSeconds = lSeconds % 3600; int mm = lSeconds / 60; int ss = lSeconds % 60; if (format == TIME_FORMAT_GUESS) format = (hh >= 1) ? TIME_FORMAT_HH_MM_SS : TIME_FORMAT_MM_SS; strHMS.Empty(); if (format & TIME_FORMAT_HH) strHMS.AppendFormat("%02.2i", hh); if (format & TIME_FORMAT_MM) strHMS.AppendFormat(strHMS.IsEmpty() ? "%02.2i" : ":%02.2i", mm); if (format & TIME_FORMAT_SS) strHMS.AppendFormat(strHMS.IsEmpty() ? "%02.2i" : ":%02.2i", ss); }
bool XMLUtils::GetPath(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue) { const TiXmlElement* pElement = pRootNode->FirstChildElement(strTag); if (!pElement) return false; int pathVersion = 0; pElement->Attribute("pathversion", &pathVersion); const char* encoded = pElement->Attribute("urlencoded"); const TiXmlNode* pNode = pElement->FirstChild(); if (pNode != NULL) { strStringValue = pNode->Value(); if (encoded && strcasecmp(encoded,"yes") == 0) CURL::Decode(strStringValue); strStringValue = CSpecialProtocol::ReplaceOldPath(strStringValue, pathVersion); return true; } strStringValue.Empty(); return false; }
void Serializer::GetCsv(const char* key, std::list<CStdString>& value, bool required) { CStdString stringValue; stringValue.Trim(); CStdString element; bool first = true; GetString(key, stringValue, required); for(unsigned int i=0; i<stringValue.length(); i++) { TCHAR c = stringValue[i]; if(c == ',') { if(first) { first = false; // only erase default value if something found value.clear(); } element.Trim(); CStdString unescapedElement; UnEscapeCsv(element, unescapedElement); value.push_back(unescapedElement); element.Empty(); } else { element += c; } } if (!element.IsEmpty()) { if(first) { first = false; // only erase default value if something found value.clear(); } element.Trim(); CStdString unescapedElement; UnEscapeCsv(element, unescapedElement); value.push_back(unescapedElement); } }
void CGUIWindowMusicInfo::RefreshThumb() { CStdString thumbImage = m_albumItem->GetThumbnailImage(); if (!m_albumItem->HasThumbnail()) { if (m_bArtistInfo) thumbImage = m_albumItem->GetCachedArtistThumb(); else thumbImage = CUtil::GetCachedAlbumThumb(m_album.strAlbum, m_album.strArtist); if (!CFile::Exists(thumbImage)) { DownloadThumbnail(thumbImage); m_hasUpdatedThumb = true; } } if (!CFile::Exists(thumbImage) ) thumbImage.Empty(); m_albumItem->SetThumbnailImage(thumbImage); }
int CEnDeCode::SplitStringWithSeparator(const CStdString &strSource , const CStdString &strSeparator , std::vector<CStdString> &strVector , BOOL bIsIncludeEmpty) { CStdString strSourceTemp = strSource ; CStdString strTemp = _T("") ; strVector.clear() ; if ( strSource == _T("") ) { return 0 ; } DWORD dwSeparatorLen = strSeparator.GetLength() ; int nPostion = strSourceTemp.Find(strSeparator) ; if (nPostion == -1) { strVector.push_back(strSourceTemp) ; return strVector.size() ; } while (nPostion != -1) { strTemp = strSourceTemp.Left(nPostion) ; if ( !strTemp.IsEmpty() || bIsIncludeEmpty) { strVector.push_back(strTemp) ; } strSourceTemp.Delete(0 , strTemp.GetLength()+dwSeparatorLen) ; strTemp.Empty(); nPostion = strSourceTemp.Find(strSeparator) ; } if ( !strSourceTemp.IsEmpty() || bIsIncludeEmpty) { strVector.push_back(strSourceTemp) ; } return strVector.size() ; }
int CAddonDatabase::GetRepoChecksum(const CStdString& id, CStdString& checksum) { try { if (NULL == m_pDB.get()) return -1; if (NULL == m_pDS.get()) return -1; CStdString strSQL = PrepareSQL("select * from repo where addonID='%s'",id.c_str()); m_pDS->query(strSQL.c_str()); if (!m_pDS->eof()) { checksum = m_pDS->fv("checksum").get_asString(); return m_pDS->fv("id").get_asInt(); } } catch (...) { CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str()); } checksum.Empty(); return -1; }
void CGUIWindowVideoInfo::Refresh() { // quietly return if Internet lookups are disabled if (!g_guiSettings.GetBool("network.enableinternet")) { Update(); return ; } try { OutputDebugString("Refresh\n"); CStdString strImage = m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetFirstThumb().m_url; CStdString thumbImage = m_movieItem->GetThumbnailImage(); if (!m_movieItem->HasThumbnail()) thumbImage = m_movieItem->GetCachedVideoThumb(); if (!CFile::Exists(thumbImage) && strImage.size() > 0) { CScraperUrl::DownloadThumbnail(thumbImage,m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetFirstThumb()); CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show } if (!CFile::Exists(thumbImage) ) { thumbImage.Empty(); } m_movieItem->SetThumbnailImage(thumbImage); //OutputDebugString("update\n"); Update(); //OutputDebugString("updated\n"); } catch (...) {} }
bool CFanart::ParseColors(const CStdString &colorsIn, CStdString &colorsOut) { // Formats: // 0: XBMC ARGB Hexadecimal string comma seperated "FFFFFFFF,DDDDDDDD,AAAAAAAA" // 1: The TVDB RGB Int Triplets, pipe seperate with leading/trailing pipes "|68,69,59|69,70,58|78,78,68|" // Essentially we read the colors in using the proper format, and store them in our own fixed temporary format (3 DWORDS), and then // write them back in in the specified format. if (colorsIn.IsEmpty()) return false; // check for the TVDB RGB triplets "|68,69,59|69,70,58|78,78,68|" if (colorsIn[0] == '|') { // need conversion colorsOut.Empty(); CStdStringArray strColors; StringUtils::SplitString(colorsIn, "|", strColors); for (int i = 0; i < std::min((int)strColors.size()-1, (int)max_fanart_colors); i++) { // split up each color CStdStringArray strTriplets; StringUtils::SplitString(strColors[i+1], ",", strTriplets); if (strTriplets.size() == 3) { // convert if (colorsOut.size()) colorsOut += ","; colorsOut.AppendFormat("FF%2x%2x%2x", atol(strTriplets[0].c_str()), atol(strTriplets[1].c_str()), atol(strTriplets[2].c_str())); } } } else { // assume is our format colorsOut = colorsIn; } return true; }
JSONRPC_STATUS CPlayerOperations::GetPropertyValue(PlayerType player, const CStdString &property, CVariant &result) { if (player == None) return FailedToExecute; int playlist = GetPlaylist(player); if (property.Equals("type")) { switch (player) { case Video: result = "video"; break; case Audio: result = "audio"; break; case Picture: result = "picture"; break; default: return FailedToExecute; } } else if (property.Equals("partymode")) { switch (player) { case Video: case Audio: if (IsPVRChannel()) { result = false; break; } result = g_partyModeManager.IsEnabled(); break; case Picture: result = false; break; default: return FailedToExecute; } } else if (property.Equals("speed")) { CGUIWindowSlideShow *slideshow = NULL; switch (player) { case Video: case Audio: result = g_application.IsPaused() ? 0 : g_application.GetPlaySpeed(); break; case Picture: slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow && slideshow->IsPlaying() && !slideshow->IsPaused()) result = slideshow->GetDirection(); else result = 0; break; default: return FailedToExecute; } } else if (property.Equals("time")) { switch (player) { case Video: case Audio: { int ms = 0; if (!IsPVRChannel()) ms = (int)(g_application.GetTime() * 1000.0); else { EPG::CEpgInfoTag epg; if (GetCurrentEpg(epg)) ms = epg.Progress() * 1000; } MillisecondsToTimeObject(ms, result); break; } case Picture: MillisecondsToTimeObject(0, result); break; default: return FailedToExecute; } } else if (property.Equals("percentage")) { CGUIWindowSlideShow *slideshow = NULL; switch (player) { case Video: case Audio: { if (!IsPVRChannel()) result = g_application.GetPercentage(); else { EPG::CEpgInfoTag epg; if (GetCurrentEpg(epg)) result = epg.ProgressPercentage(); else result = 0; } break; } case Picture: slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow && slideshow->NumSlides() > 0) result = (double)slideshow->CurrentSlide() / slideshow->NumSlides(); else result = 0.0; break; default: return FailedToExecute; } } else if (property.Equals("totaltime")) { switch (player) { case Video: case Audio: { int ms = 0; if (!IsPVRChannel()) ms = (int)(g_application.GetTotalTime() * 1000.0); else { EPG::CEpgInfoTag epg; if (GetCurrentEpg(epg)) ms = epg.GetDuration() * 1000; } MillisecondsToTimeObject(ms, result); break; } case Picture: MillisecondsToTimeObject(0, result); break; default: return FailedToExecute; } } else if (property.Equals("playlistid")) { result = playlist; } else if (property.Equals("position")) { CGUIWindowSlideShow *slideshow = NULL; switch (player) { case Video: case Audio: if (!IsPVRChannel() && g_playlistPlayer.GetCurrentPlaylist() == playlist) result = g_playlistPlayer.GetCurrentSong(); else result = -1; break; case Picture: slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow && slideshow->IsPlaying()) result = slideshow->CurrentSlide() - 1; else result = -1; break; default: result = -1; break; } } else if (property.Equals("repeat")) { switch (player) { case Video: case Audio: if (IsPVRChannel()) { result = "off"; break; } switch (g_playlistPlayer.GetRepeat(playlist)) { case REPEAT_ONE: result = "one"; break; case REPEAT_ALL: result = "all"; break; default: result = "off"; break; } break; case Picture: default: result = "off"; break; } } else if (property.Equals("shuffled")) { CGUIWindowSlideShow *slideshow = NULL; switch (player) { case Video: case Audio: if (IsPVRChannel()) { result = false; break; } result = g_playlistPlayer.IsShuffled(playlist); break; case Picture: slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow && slideshow->IsPlaying()) result = slideshow->IsShuffled(); else result = -1; break; default: result = -1; break; } } else if (property.Equals("canseek")) { switch (player) { case Video: case Audio: if (g_application.m_pPlayer) result = g_application.m_pPlayer->CanSeek(); else result = false; break; case Picture: default: result = false; break; } } else if (property.Equals("canchangespeed")) { switch (player) { case Video: case Audio: result = !IsPVRChannel(); break; case Picture: default: result = false; break; } } else if (property.Equals("canmove")) { switch (player) { case Picture: result = true; break; case Video: case Audio: default: result = false; break; } } else if (property.Equals("canzoom")) { switch (player) { case Picture: result = true; break; case Video: case Audio: default: result = false; break; } } else if (property.Equals("canrotate")) { switch (player) { case Picture: result = true; break; case Video: case Audio: default: result = false; break; } } else if (property.Equals("canshuffle")) { switch (player) { case Video: case Audio: case Picture: result = !IsPVRChannel(); break; default: result = false; break; } } else if (property.Equals("canrepeat")) { switch (player) { case Video: case Audio: result = !IsPVRChannel(); break; case Picture: default: result = false; break; } } else if (property.Equals("currentaudiostream")) { switch (player) { case Video: case Audio: if (g_application.m_pPlayer) { result = CVariant(CVariant::VariantTypeObject); int index = g_application.m_pPlayer->GetAudioStream(); if (index >= 0) { result["index"] = index; CStdString value; g_application.m_pPlayer->GetAudioStreamName(index, value); result["name"] = value; value.Empty(); g_application.m_pPlayer->GetAudioStreamLanguage(index, value); result["language"] = value; } result["codec"] = g_application.m_pPlayer->GetAudioCodecName(); result["bitrate"] = g_application.m_pPlayer->GetAudioBitrate(); result["channels"] = g_application.m_pPlayer->GetChannels(); } else result = CVariant(CVariant::VariantTypeNull); break; case Picture: default: result = CVariant(CVariant::VariantTypeNull); break; } } else if (property.Equals("audiostreams")) { result = CVariant(CVariant::VariantTypeArray); switch (player) { case Video: if (g_application.m_pPlayer) { for (int index = 0; index < g_application.m_pPlayer->GetAudioStreamCount(); index++) { CVariant audioStream(CVariant::VariantTypeObject); audioStream["index"] = index; CStdString value; g_application.m_pPlayer->GetAudioStreamName(index, value); audioStream["name"] = value; value.Empty(); g_application.m_pPlayer->GetAudioStreamLanguage(index, value); audioStream["language"] = value; result.append(audioStream); } } break; case Audio: case Picture: default: break; } } else if (property.Equals("subtitleenabled")) { switch (player) { case Video: if (g_application.m_pPlayer) result = g_application.m_pPlayer->GetSubtitleVisible(); break; case Audio: case Picture: default: result = false; break; } } else if (property.Equals("currentsubtitle")) { switch (player) { case Video: if (g_application.m_pPlayer) { result = CVariant(CVariant::VariantTypeObject); int index = g_application.m_pPlayer->GetSubtitle(); if (index >= 0) { result["index"] = index; CStdString value; g_application.m_pPlayer->GetSubtitleName(index, value); result["name"] = value; value.Empty(); g_application.m_pPlayer->GetSubtitleLanguage(index, value); result["language"] = value; } } else result = CVariant(CVariant::VariantTypeNull); break; case Audio: case Picture: default: result = CVariant(CVariant::VariantTypeNull); break; } } else if (property.Equals("subtitles")) { result = CVariant(CVariant::VariantTypeArray); switch (player) { case Video: if (g_application.m_pPlayer) { for (int index = 0; index < g_application.m_pPlayer->GetSubtitleCount(); index++) { CVariant subtitle(CVariant::VariantTypeObject); subtitle["index"] = index; CStdString value; g_application.m_pPlayer->GetSubtitleName(index, value); subtitle["name"] = value; value.Empty(); g_application.m_pPlayer->GetSubtitleLanguage(index, value); subtitle["language"] = value; result.append(subtitle); } } break; case Audio: case Picture: default: break; } } else if (property.Equals("live")) result = IsPVRChannel(); else return InvalidParams; return OK; }
bool CDirectoryTuxBox::GetDirectory(const CStdString& strPath, CFileItemList &items) { // so we know that we have enigma2 static bool enigma2 = false; // Detect and delete slash at end CStdString strRoot = strPath; if (CUtil::HasSlashAtEnd(strRoot)) strRoot.Delete(strRoot.size() - 1); //Get the request strings CStdString strBQRequest; CStdString strXMLRootString; CStdString strXMLChildString; if(!GetRootAndChildString(strRoot, strBQRequest, strXMLRootString, strXMLChildString)) return false; //Set url Protocol CURL url(strRoot); CStdString strFilter; CStdString protocol = url.GetProtocol(); CStdString strOptions = url.GetOptions(); url.SetProtocol("http"); bool bIsBouquet=false; int ipoint = strOptions.Find("?path="); if (ipoint >=0) { // send Zap! return g_tuxbox.ZapToUrl(url, strOptions, ipoint); } else { ipoint = strOptions.Find("&reference="); if (ipoint >=0 || enigma2) { //List reference strFilter = strOptions.Right((strOptions.size()-(ipoint+11))); bIsBouquet = false; //On Empty is Bouquet if (enigma2) { CStdString strPort; strPort.Format(":%i",url.GetPort()); if (strRoot.Right(strPort.GetLength()) != strPort) // If not root dir, enable Channels strFilter = "e2"; // Disable Bouquets for Enigma2 GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString); url.SetOptions(""); url.SetFileName(strBQRequest); } } } if(strFilter.IsEmpty()) { url.SetOptions(strBQRequest); bIsBouquet = true; } //Open CFileCurl http; int iTryConnect = 0; int iWaitTimer = 20; bool result = false; while (iTryConnect < 4) { http.SetTimeout(iWaitTimer); if(http.Open(url)) { //We are connected! iTryConnect = 4; // restore protocol url.SetProtocol(protocol); int size_read = 0; int size_total = (int)http.GetLength(); int data_size = 0; CStdString data; data.reserve(size_total); // read response from server into string buffer char buffer[16384]; while ((size_read = http.Read(buffer, sizeof(buffer)-1)) > 0) { buffer[size_read] = 0; data += buffer; data_size += size_read; } http.Close(); // parse returned xml TiXmlDocument doc; data.Replace("></",">-</"); //FILL EMPTY ELEMENTS WITH "-"! doc.Parse(data.c_str()); TiXmlElement *root = doc.RootElement(); if(root == NULL) { CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__); CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); return false; } if( strXMLRootString.Equals(root->Value()) && bIsBouquet) { data.Empty(); if (enigma2) result = g_tuxbox.ParseBouquetsEnigma2(root, items, url, strFilter, strXMLChildString); else result = g_tuxbox.ParseBouquets(root, items, url, strFilter, strXMLChildString); } else if( strXMLRootString.Equals(root->Value()) && !strFilter.IsEmpty() ) { data.Empty(); if (enigma2) result = g_tuxbox.ParseChannelsEnigma2(root, items, url, strFilter, strXMLChildString); else result = g_tuxbox.ParseChannels(root, items, url, strFilter, strXMLChildString); } else { CLog::Log(LOGERROR, "%s - Invalid root xml element for TuxBox", __FUNCTION__); CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); data.Empty(); result = false; } } else { CLog::Log(LOGERROR, "%s - Unable to get XML structure! Try count:%i, Wait Timer:%is",__FUNCTION__, iTryConnect, iWaitTimer); iTryConnect++; if (iTryConnect == 2) //try enigma2 instead of enigma1, best entrypoint here i thought { enigma2 = true; GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString); url.SetOptions(""); url.SetFileName(strBQRequest); // iTryConnect = 0; iWaitTimer = 20; } else iWaitTimer = iWaitTimer+10; result = false; http.Close(); // Close old connections } } return result; }
void UrlSerializer::DeSerialize(CStdString& input) { // read string and extract values into map UrlState state = UrlStartState; CStdString key; CStdString value; CStdString errorDescription; input.Trim(); for(unsigned int i=0; i<input.length() && state!= UrlErrorState; i++) { TCHAR character = input[i]; switch(state) { case UrlStartState: if(character == '&') { ; // ignore ampersands } else if ( ACE_OS::ace_isalnum(character) ) { state = UrlKeyState; key = character; } else { state = UrlErrorState; errorDescription = "Cannot find key start, keys must be alphanum"; } break; case UrlKeyState: if( ACE_OS::ace_isalnum(character) ) { key += character; } else if (character == '=') { state = UrlValueState; value.Empty(); } else { state = UrlErrorState; errorDescription = "Invalid key character, keys must be alphanum"; } break; case UrlValueState: if( character == '=') { state = UrlErrorState; errorDescription = "Value followed by = sign, value should always be followed by space sign"; } else if (character == '&') { state = UrlStartState; } else { value += character; } break; default: state = UrlErrorState; errorDescription = "Non-existing state"; } // switch(state) if ( (state == UrlStartState) || (i == (input.length()-1)) ) { if (!key.IsEmpty()) { // Url unescape CStdString unescapedValue; UnEscapeUrl(value, unescapedValue); // Add pair to key-value map m_map.insert(std::make_pair(key, unescapedValue)); key.Empty(); value.Empty(); } } } // for(int i=0; i<input.length() && state!= UrlErrorState; i++) Serializer::DeSerialize(); }
BOOL CImageDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_btnMask.EnableOtherButton(_T("Other")); m_btnMask.SetColor((COLORREF)0); m_btnMask.SetColumnsNumber(10); m_ctlFade.SetRange(0,255); m_ctlFade.SetPos(255); m_pManager=g_pMainFrame->GetActiveUIView()->GetPaintManager(); m_ImagePreview.SetManager(m_pManager); g_HookAPI.EnableAddImage(false); m_strImagePathName=m_strImageProperty; LPCTSTR pStrImage=m_strImageProperty; CStdString sItem; CStdString sValue; LPTSTR pstr = NULL; while( *pStrImage != _T('\0') ) { sItem.Empty(); sValue.Empty(); while( *pStrImage != _T('\0') && *pStrImage != _T('=') ) { LPTSTR pstrTemp = ::CharNext(pStrImage); while( pStrImage < pstrTemp) { sItem += *pStrImage++; } } if( *pStrImage++ != _T('=') ) break; if( *pStrImage++ != _T('\'') ) break; while( *pStrImage != _T('\0') && *pStrImage != _T('\'') ) { LPTSTR pstrTemp = ::CharNext(pStrImage); while( pStrImage < pstrTemp) { sValue += *pStrImage++; } } if( *pStrImage++ != _T('\'') ) break; if( !sValue.IsEmpty() ) { if( sItem == _T("file")) m_strImagePathName = sValue; else if( sItem == _T("dest") ) m_strDest = sValue; else if( sItem == _T("source") ) m_strSource = sValue; else if( sItem == _T("corner") ) m_strCorner = sValue; else if( sItem == _T("mask") ) { DWORD dwMask; if( sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16); else dwMask = _tcstoul(sValue.GetData(), &pstr, 16); dwMask&=0x00FFFFFF; m_btnMask.SetColor(RGB(GetBValue(dwMask),GetGValue(dwMask),GetRValue(dwMask))); } else if( sItem == _T("fade") ) { m_nFade = (BYTE)_tcstoul(sValue.GetData(), &pstr, 10); } else if( sItem == _T("hole") ) { m_bHole = (_tcscmp(sValue.GetData(), _T("true")) == 0); } } if( *pStrImage++ != _T(' ') ) break; } m_ctlFade.SetPos(m_nFade); int nIndex=m_lstImages.AddString(_T("(无)")); m_lstImages.SetItemDataPtr(nIndex,(void*)(LPCTSTR)m_strNullImage); const CStringArray* parrImage=g_pResourceView->GetAllImage(); LPCTSTR pstrImage=NULL; LPTSTR pszFileName=NULL; for(int i=0; i<parrImage->GetSize(); i++) { pstrImage=parrImage->GetAt(i); pszFileName=_tcsrchr((LPTSTR)pstrImage,_T('\\'))+1; nIndex=m_lstImages.AddString(pszFileName); m_lstImages.SetItemDataPtr(nIndex,(void*)pstrImage); } pstrImage=m_strImagePathName; pszFileName=_tcsrchr((LPTSTR)pstrImage,_T('\\'))+1; m_strImagePathName.IsEmpty()?m_lstImages.SelectString(-1,_T("(无)")):m_lstImages.SelectString(-1,pszFileName); UpdateData(FALSE); SetImageProperty(m_strImagePathName); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
bool CShoutcastDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString strRoot = strPath; if (CUtil::HasSlashAtEnd(strRoot)) strRoot.Delete(strRoot.size() - 1); /* for old users wich doesn't have the full url */ if( strRoot.Equals("shout://www.shoutcast.com") ) strRoot = "shout://www.shoutcast.com/sbin/newxml.phtml"; if (g_directoryCache.GetDirectory(strRoot, items)) return true; CGUIDialogProgress* dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (dlgProgress) { dlgProgress->ShowProgressBar(false); dlgProgress->SetHeading(260); dlgProgress->SetLine(0, 14003); dlgProgress->SetLine(1, ""); dlgProgress->SetLine(2, ""); dlgProgress->StartModal(); } CURL url(strRoot); CStdString protocol = url.GetProtocol(); url.SetProtocol("http"); CFileCurl http; //CURL doesn't seem to understand that data is encoded.. odd // opening as text for now //http.SetContentEncoding("deflate"); if( !http.Open(url, false) ) { CLog::Log(LOGERROR, "%s - Unable to get shoutcast dir", __FUNCTION__); if (dlgProgress) dlgProgress->Close(); return false; } /* restore protocol */ url.SetProtocol(protocol); CStdString content = http.GetContent(); if( !(content.Equals("text/html") || content.Equals("text/xml") || content.Equals("text/html;charset=utf-8") || content.Equals("text/xml;charset=utf-8") )) { CLog::Log(LOGERROR, "%s - Invalid content type %s", __FUNCTION__, content.c_str()); if (dlgProgress) dlgProgress->Close(); return false; } int size_read = 0; int size_total = (int)http.GetLength(); int data_size = 0; CStdString data; data.reserve(size_total); /* read response from server into string buffer */ char buffer[16384]; while( (size_read = http.Read(buffer, sizeof(buffer)-1)) > 0 ) { buffer[size_read] = 0; data += buffer; data_size += size_read; dlgProgress->Progress(); if (dlgProgress->IsCanceled()) { dlgProgress->Close(); return false; } } /* parse returned xml */ TiXmlDocument doc; doc.Parse(data.c_str()); TiXmlElement *root = doc.RootElement(); if(root == NULL) { CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__); CLog::Log(LOGDEBUG, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); dlgProgress->Close(); return false; } /* clear data to keep memusage down, not needed anymore */ data.Empty(); bool result = false; if( strcmp(root->Value(), "genrelist") == 0 ) result = ParseGenres(root, items, url); else if( strcmp(root->Value(), "stationlist") == 0 ) result = ParseStations(root, items, url); else { CLog::Log(LOGERROR, "%s - Invalid root xml element for shoutcast",__FUNCTION__); CLog::Log(LOGDEBUG, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); } CFileItemList vecCacheItems; g_directoryCache.ClearDirectory(strRoot); for( int i = 0; i <items.Size(); i++ ) { CFileItem* pItem=items[i]; if (!pItem->IsParentFolder()) vecCacheItems.Add(new CFileItem( *pItem )); } g_directoryCache.SetDirectory(strRoot, vecCacheItems); if (dlgProgress) dlgProgress->Close(); return result; }
bool CAirTunesServer::StartServer(int port, bool nonlocal, bool usePassword, const CStdString &password/*=""*/) { bool success = false; CStdString pw = password; CNetworkInterface *net = g_application.getNetwork().GetFirstConnectedInterface(); StopServer(true); if (net) { m_macAddress = net->GetMacAddress(); m_macAddress.Replace(":",""); while (m_macAddress.size() < 12) { m_macAddress = CStdString("0") + m_macAddress; } } else { m_macAddress = "000102030405"; } if (!usePassword) { pw.Empty(); } ServerInstance = new CAirTunesServer(port, nonlocal); if (ServerInstance->Initialize(pw)) { #if !defined(HAVE_LIBSHAIRPLAY) ServerInstance->Create(); #endif success = true; } if (success) { CStdString appName; appName.Format("%s@%s", m_macAddress.c_str(), g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME).c_str()); std::vector<std::pair<std::string, std::string> > txt; txt.push_back(std::make_pair("txtvers", "1")); txt.push_back(std::make_pair("cn", "0,1")); txt.push_back(std::make_pair("ch", "2")); txt.push_back(std::make_pair("ek", "1")); txt.push_back(std::make_pair("et", "0,1")); txt.push_back(std::make_pair("sv", "false")); txt.push_back(std::make_pair("tp", "UDP")); txt.push_back(std::make_pair("sm", "false")); txt.push_back(std::make_pair("ss", "16")); txt.push_back(std::make_pair("sr", "44100")); txt.push_back(std::make_pair("pw", usePassword?"true":"false")); txt.push_back(std::make_pair("vn", "3")); txt.push_back(std::make_pair("da", "true")); txt.push_back(std::make_pair("vs", "130.14")); txt.push_back(std::make_pair("md", "0,1,2")); txt.push_back(std::make_pair("am", "Xbmc,1")); CZeroconf::GetInstance()->PublishService("servers.airtunes", "_raop._tcp", appName, port, txt); } return success; }
void CImageAnimationUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue ) { ASSERT(pstrName); ASSERT(pstrValue); if(_tcscmp(pstrName, _T("blocks")) == 0) { CStdString szKey; CStdString szValue; bool isValue = false; bool isString = false; ImageBlock* pBlock = NULL; for(LPCTSTR pCursor = pstrValue; *pCursor != _T('\0'); ++pCursor) { if(*pCursor == _T('{')) { pBlock = new ImageBlock(); } else if(*pCursor == _T('\'')) { if(isValue) isString = !isString; } else if(*pCursor == _T('=')) { isValue = true; } else if(*pCursor == _T(',')) { if(pBlock != NULL) { if(_tcscmp(szKey, _T("name")) == 0) pBlock->m_szName = szValue; else if(_tcscmp(szKey, _T("image")) == 0) pBlock->m_szImage = szValue; else if(_tcscmp(szKey, _T("bordercolor")) == 0) pBlock->m_dwBorderColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("borderwidth")) == 0) pBlock->m_fBorderWidth = static_cast<float>(_tstof(szValue)); isValue = false; szKey.Empty(); szValue.Empty(); } } else if(*pCursor == _T('}')) { if(_tcscmp(szKey, _T("name")) == 0) pBlock->m_szName = szValue; else if(_tcscmp(szKey, _T("image")) == 0) pBlock->m_szImage = szValue; else if(_tcscmp(szKey, _T("bordercolor")) == 0) pBlock->m_dwBorderColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("borderwidth")) == 0) pBlock->m_fBorderWidth = static_cast<float>(_tstof(szValue)); isValue = false; szKey.Empty(); szValue.Empty(); m_displayVector.push_back(pBlock); pBlock = NULL; } else if(*pCursor == _T(' ')) { if(isString) { szValue += *pCursor; } else { szKey.Empty(); szValue.Empty(); } } else { if(isValue) szValue += *pCursor; else szKey += *pCursor; } } } else if (_tcscmp(pstrName, _T("childrenheight")) == 0) { m_iChildrenHeight = _ttoi(pstrValue); } else if (_tcscmp(pstrName, _T("childrenwidth")) == 0) { m_iChildrenWidth = _ttoi(pstrValue); } else if (_tcscmp(pstrName, _T("childrenoffset")) == 0) { m_iChildrenOffest = _ttoi(pstrValue); } else if (_tcscmp(pstrName, _T("defaultleftOffset")) == 0) { m_iDefaultLeftOffset = _ttoi(pstrValue); m_iCurrentImageOffset = m_iDefaultLeftOffset; m_iLeftOffset = m_iDefaultLeftOffset; } else if(_tcscmp(pstrName, _T("imagemove")) == 0) { m_iBkimageMove = _ttoi(pstrValue); } else { CControlUI::SetAttribute(pstrName, pstrValue); } }
void CPieChartUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) { ASSERT(pstrName); ASSERT(pstrValue); if(_tcscmp(pstrName, _T("blocks")) == 0) { CStdString szKey; CStdString szValue; bool isValue = false; bool isString = false; PieBlock* pBlock = NULL; // Json style // Value don't contain the seperators(exception string with blank space) below for(LPCTSTR pCursor = pstrValue; *pCursor != _T('\0'); ++pCursor) { if(*pCursor == _T('{')) { pBlock = new PieBlock(); } else if(*pCursor == _T('\'')) { if(isValue) isString = !isString; } else if(*pCursor == _T('=')) { isValue = true; } else if(*pCursor == _T(',')) { if(pBlock != NULL) { if(_tcscmp(szKey, _T("name")) == 0) pBlock->m_szName = szValue; else if(_tcscmp(szKey, _T("description")) == 0) pBlock->m_szDescription = szValue; else if(_tcscmp(szKey, _T("percent")) == 0) pBlock->m_fPercent = static_cast<float>(_tstof(szValue)) / 100.0f; else if(_tcscmp(szKey, _T("fillcolor")) == 0) pBlock->m_dwFillColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("drawborder")) == 0) pBlock->m_bDrawBorder = (szValue == _T("true")); else if(_tcscmp(szKey, _T("bordercolor")) == 0) pBlock->m_dwBorderColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("borderwidth")) == 0) pBlock->m_fBorderWidth = static_cast<float>(_tstof(szValue)); isValue = false; szKey.Empty(); szValue.Empty(); } } else if(*pCursor == _T('}')) { if(_tcscmp(szKey, _T("name")) == 0) pBlock->m_szName = szValue; else if(_tcscmp(szKey, _T("description")) == 0) pBlock->m_szDescription = szValue; else if(_tcscmp(szKey, _T("percent")) == 0) pBlock->m_fPercent = static_cast<float>(_tstof(szValue)) / 100.0f; else if(_tcscmp(szKey, _T("fillcolor")) == 0) pBlock->m_dwFillColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("drawborder")) == 0) pBlock->m_bDrawBorder = (szValue == _T("true")); else if(_tcscmp(szKey, _T("bordercolor")) == 0) pBlock->m_dwBorderColor = _ColorValue(szValue); else if(_tcscmp(szKey, _T("borderwidth")) == 0) pBlock->m_fBorderWidth = static_cast<float>(_tstof(szValue)); isValue = false; szKey.Empty(); szValue.Empty(); m_displayVector.push_back(pBlock); pBlock = NULL; } else if(*pCursor == _T(' ')) { if(isString) { szValue += *pCursor; } else { szKey.Empty(); szValue.Empty(); } } else { if(isValue) szValue += *pCursor; else szKey += *pCursor; } } std::vector<PieBlock*>::iterator it = m_displayVector.begin(); for(; m_displayVector.end() != it; ++it) { std::map<CStdString, PieBlock*>::iterator mapIt = m_pieBlockMap.find((*it)->m_szName); if(m_pieBlockMap.end() != mapIt) { delete mapIt->second; } m_pieBlockMap[(*it)->m_szName] = *it; } } else { if( _tcscmp(pstrName, _T("textPadding")) == 0 ) { LPTSTR pstr = NULL; m_rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr); m_rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); m_rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); m_rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); return; } else if( _tcscmp(pstrName, _T("leftoffset")) == 0 ) { m_iLeftOffset = _ttoi(pstrValue); return; } CControlUI::SetAttribute(pstrName, pstrValue); } }