Example #1
0
bool CController::LoadLayout(void)
{
  if (!m_bLoaded)
  {
    std::string strLayoutXmlPath = LibPath();

    CLog::Log(LOGINFO, "Loading controller layout: %s", CURL::GetRedacted(strLayoutXmlPath).c_str());

    CXBMCTinyXML xmlDoc;
    if (!xmlDoc.LoadFile(strLayoutXmlPath))
    {
      CLog::Log(LOGDEBUG, "Unable to load file: %s at line %d", xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
      return false;
    }

    TiXmlElement* pRootElement = xmlDoc.RootElement();
    if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueStr() != LAYOUT_XML_ROOT)
    {
      CLog::Log(LOGERROR, "Can't find root <%s> tag", LAYOUT_XML_ROOT);
      return false;
    }

    m_layout->Deserialize(pRootElement, this, m_features);
    if (m_layout->IsValid(true))
    {
      m_bLoaded = true;
    }
    else
    {
      m_layout->Reset();
    }
  }

  return m_bLoaded;
}
Example #2
0
void CIRTranslator::MapRemote(TiXmlNode *pRemote, const std::string &szDevice)
{
  CLog::Log(LOGINFO, "* Adding remote mapping for device '%s'", szDevice.c_str());

  std::vector<std::string> remoteNames;

  auto it = m_irRemotesMap.find(szDevice);
  if (it == m_irRemotesMap.end())
    m_irRemotesMap[szDevice].reset(new IRButtonMap);

  std::shared_ptr<IRButtonMap>& buttons = m_irRemotesMap[szDevice];

  TiXmlElement *pButton = pRemote->FirstChildElement();
  while (pButton != nullptr)
  {
    if (!pButton->NoChildren())
    {
      if (pButton->ValueStr() == "altname")
        remoteNames.push_back(pButton->FirstChild()->ValueStr());
      else
        (*buttons)[pButton->FirstChild()->ValueStr()] = pButton->ValueStr();
    }
    pButton = pButton->NextSiblingElement();
  }

  for (const auto& remoteName : remoteNames)
  {
    CLog::Log(LOGINFO, "* Linking remote mapping for '%s' to '%s'", szDevice.c_str(), remoteName.c_str());
    m_irRemotesMap[remoteName] = buttons;
  }
}
Example #3
0
bool CRssReader::Parse(int iFeed)
{
    TiXmlElement* rootXmlNode = m_xml.RootElement();

    if (!rootXmlNode)
        return false;

    TiXmlElement* rssXmlNode = NULL;

    std::string strValue = rootXmlNode->ValueStr();
    if (strValue.find("rss") != std::string::npos ||
            strValue.find("rdf") != std::string::npos)
        rssXmlNode = rootXmlNode;
    else
    {
        // Unable to find root <rss> or <rdf> node
        return false;
    }

    TiXmlElement* channelXmlNode = rssXmlNode->FirstChildElement("channel");
    if (channelXmlNode)
    {
        TiXmlElement* titleNode = channelXmlNode->FirstChildElement("title");
        if (titleNode && !titleNode->NoChildren())
        {
            std::string strChannel = titleNode->FirstChild()->Value();
            std::wstring strChannelUnicode;
            g_charsetConverter.utf8ToW(strChannel, strChannelUnicode, m_rtlText);
            AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);

            AddString(L":", RSS_COLOR_CHANNEL, iFeed);
            AddString(L" ", RSS_COLOR_CHANNEL, iFeed);
        }

        GetNewsItems(channelXmlNode,iFeed);
    }

    GetNewsItems(rssXmlNode,iFeed);

    // avoid trailing ' - '
    if (m_strFeed[iFeed].size() > 3 && m_strFeed[iFeed].substr(m_strFeed[iFeed].size() - 3) == L" - ")
    {
        if (m_rtlText)
        {
            m_strFeed[iFeed].erase(0, 3);
            m_strColors[iFeed].erase(0, 3);
        }
        else
        {
            m_strFeed[iFeed].erase(m_strFeed[iFeed].length() - 3);
            m_strColors[iFeed].erase(m_strColors[iFeed].length() - 3);
        }
    }
    return true;
}
       XsdTypeToken(TiXmlNode* xmlNode)
       : ISerialized(xmlNode){
             TiXmlElement* xmlElem = xmlNode->ToElement();
             const char *pKey = xmlElem->Value();
             const char *pText = xmlElem->GetText();

             if( pText ) { this->valueStr = pText; }
             else if( xmlElem->NoChildren() ) { this->valueStr = "NULL ( empty value )"; }
             else { this->valueStr = "NULL value ( Node has Children )"; }
             #ifdef ConsolePrint
                FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "   " << xmlNode->Value() << " : " << this->valueStr.c_str() << std::endl;
             #endif
       }
Example #5
0
bool loadXMLFile (TiXmlDocument &pXMLDoc, std::string XMLFilename, std::map<int,
                  std::string> * pMapXmlStrings, bool isSourceFile)
{
  if (!pXMLDoc.LoadFile(XMLFilename.c_str()))
  {
    printf ("%s %s\n", pXMLDoc.ErrorDesc(), XMLFilename.c_str());
    return false;
  }
  if (isSourceFile) GetEncoding(&pXMLDoc, sourceXMLEncoding);
    else GetEncoding(&pXMLDoc, foreignXMLEncoding);

  TiXmlElement* pRootElement = pXMLDoc.RootElement();
  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="strings")
  {
    printf ("error: No root element called: \"strings\" or no child found in input XML file: %s\n",
            XMLFilename.c_str());
    return false;
  }

  if (isSourceFile) GetComment(pRootElement->FirstChild(), -1);

  const TiXmlElement *pChildElement = pRootElement->FirstChildElement("string");
  const char* pAttrId = NULL;
  const char* pValue = NULL;
  std::string valueString;
  int id;

  while (pChildElement)
  {
    pAttrId=pChildElement->Attribute("id");
    if (pAttrId && !pChildElement->NoChildren())
    {
      id = atoi(pAttrId);
      if (pMapXmlStrings->find(id) == pMapXmlStrings->end())
      {
        pValue = pChildElement->FirstChild()->Value();
        valueString = EscapeLF(pValue);
        if (isSourceFile)
          multimapSourceXmlStrings.insert(std::pair<std::string,int>( valueString,id));

        (*pMapXmlStrings)[id] = valueString;

        if (pChildElement && isSourceFile) GetComment(pChildElement->NextSibling(), id);
      }
    }
    pChildElement = pChildElement->NextSiblingElement("string");
  }
  // Free up the allocated memory for the XML file
  pXMLDoc.Clear();
  return true;
}
//网络返回数据 刷新内存
void CMGetNewContent::OnSessionCmd(unsigned int nCmdID, unsigned int nCode, TiXmlDocument *pDoc)
{
    if (nCode == MER_OK)
    {
        TiXmlElement* pItem = pDoc->RootElement();
        
        if (pItem)
        {
            INT32 nCmdID = 0;
            
            pItem->QueryIntAttribute("no", &nCmdID);
            
            INT32 nErr = 0;
            
            if (pItem->QueryIntAttribute("errno", &nErr) == TIXML_SUCCESS)
            {
                if (nErr == 0)
                {
                    if (nCmdID == SERVICE_GETNEWCONTENT || nCmdID == SERVICE_GETRECOMMEND)
                    {
						if(!pItem->NoChildren())
                        {
                            TiXmlElement* pHeadItemList = pItem->FirstChildElement("largeimage");
                            if(pHeadItemList)
                                DoHeadItemList(pHeadItemList);
                            DoItemList(pItem);
                        }

                        if (m_lstItem && m_lstItem->size() > 0)
                        {
                        	if(m_pListener)
                        		m_pListener->OnUpdateDataFinish(m_pUserData, TResult::ESuccess);
                            return ;
                        }
                        else
                        {
                        	if(m_pListener)
                        		m_pListener->OnUpdateDataFinish(m_pUserData, TResult::ENothing);
                            return ;
                        }
                    }
                }
            }
        }
    }
    if(m_pListener)
    	m_pListener->OnUpdateDataFinish(m_pUserData, TResult::EUnknownError);
}
bool CWeather::GetSearchResults(const CStdString &strSearch, CStdString &strResult)
{
  // Check to see if the user entered a weather.com code
  if (strSearch.size() == 8)
  {
    strResult = "";
    int i = 0;
    for (i = 0; i < 4; ++i)
    {
      strResult += toupper(strSearch[i]);
      if (!isalpha(strSearch[i]))
        break;
    }
    if (i == 4)
    {
      for ( ; i < 8; ++i)
      {
        strResult += strSearch[i];
        if (!isdigit(strSearch[i]))
          break;
      }
      if (i == 8)
      {
        return true; // match
      }
    }
    // no match, wipe string
    strResult = "";
  }

  CGUIDialogSelect *pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  CGUIDialogProgress *pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);

  //do the download
  CStdString strURL;
  CStdString strXML;
  XFILE::CFileCurl httpUtil;

  if (pDlgProgress)
  {
    pDlgProgress->SetHeading(410);       //"Accessing Weather.com"
    pDlgProgress->SetLine(0, 194);       //"Searching"
    pDlgProgress->SetLine(1, strSearch);
    pDlgProgress->SetLine(2, "");
    pDlgProgress->StartModal();
    pDlgProgress->Progress();
  }

  strURL.Format("http://xoap.weather.com/search/search?where=%s", strSearch);

  if (!httpUtil.Get(strURL, strXML))
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  //some select dialog init stuff
  if (!pDlgSelect)
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  pDlgSelect->SetHeading(396); //"Select Location"
  pDlgSelect->Reset();

  ///////////////////////////////
  // load the xml file
  ///////////////////////////////
  TiXmlDocument xmlDoc;
  xmlDoc.Parse(strXML.c_str());
  if (xmlDoc.Error())
    return false;

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (pRootElement)
  {
    CStdString strItemTmp;
    TiXmlElement *pElement = pRootElement->FirstChildElement("loc");
    while (pElement)
    {
      if (!pElement->NoChildren())
      {
        strItemTmp.Format("%s - %s", pElement->Attribute("id"), pElement->FirstChild()->Value());
        pDlgSelect->Add(strItemTmp);
      }
      pElement = pElement->NextSiblingElement("loc");
    }
  }

  if (pDlgProgress)
    pDlgProgress->Close();

  pDlgSelect->EnableButton(true, 222); //'Cancel' button returns to weather settings
  pDlgSelect->DoModal();

  if (pDlgSelect->GetSelectedLabel() < 0)
  {
    if (pDlgSelect->IsButtonPressed())
    {
      pDlgSelect->Close(); //close the select dialog and return to weather settings
      return true;
    }
  }

  //copy the selected code into the settings
  if (pDlgSelect->GetSelectedLabel() >= 0)
    strResult = pDlgSelect->GetSelectedLabelText();

  if (pDlgProgress)
    pDlgProgress->Close();

  return true;
}