void GGWrapper::onRecvContacts(gg_event_userlist100_reply& data) { std::map<std::string,bool> convertSBMap; std::vector<unsigned int> contactList; convertSBMap.insert(std::make_pair("true",1)); convertSBMap.insert(std::make_pair("false",0)); pugi::xml_document doc; doc.load(data.reply); auto contactBookNode = doc.child("ContactBook"); auto groups = contactBookNode.child("Groups"); auto contacts = contactBookNode.child("Contacts"); std::list<ContactGroup> groupList; std::map<std::string,std::multiset<ContactInfo>> mapContacts; for(auto it = contacts.begin(); it != contacts.end(); ++it) { std::string guid = it->child("Guid").child_value(); // dunno what it is auto ggNode = it->child("GGNumber"); if(strlen(ggNode.child_value()) == 0) continue; unsigned int uin = boost::lexical_cast<unsigned int>(ggNode.child_value()); contactList.push_back(uin); std::string showName = it->child("ShowName").child_value(); std::string nickName = it->child("NickName").child_value(); bool isBuddy = convertSBMap[it->child("FlagBuddy").child_value()]; bool isNormal = convertSBMap[it->child("FlagNormal").child_value()]; bool isFriend = convertSBMap[it->child("FlagFriend").child_value()]; std::string groupId = it->child("Groups").child("GroupId").child_value(); mapContacts[groupId].insert(ContactInfo(uin,showName,nickName,isBuddy,isNormal,isFriend)); } for(auto it = groups.begin(); it != groups.end(); ++it) { std::string id = it->child("Id").child_value(); auto groupName = it->child("Name").child_value(); auto isExpanded = convertSBMap[it->child("IsExpanded").child_value()]; auto isRemovable = convertSBMap[it->child("IsRemovable").child_value()]; Logger::log(id + " groupIdGroups"); groupList.push_back(ContactGroup(isExpanded,isRemovable,groupName,mapContacts[id])); } notifyAllRcvContacts(contactList); mpEventSignal->emit(spEvent(new ContactImportEvent(groupList))); }
void configuration_parser::option_dictionnary_parser(const pugi::xml_node& doc) { for(auto& item : doc) { auto key_found = item.find_child([](const pugi::xml_node& n) { return std::string(n.name()) == "key"; }); auto value_found = item.find_child([](const pugi::xml_node& n) { return std::string(n.name()) == "value"; }); std::string key_str = key_found.child_value(); std::transform( key_str.begin(), key_str.end(), key_str.begin(), ::toupper); results.back().option_dictionnary[std::move(key_str)] = value_found.child_value(); } }
BaseObject* GameObjectFactory::create(const pugi::xml_node& xml, GameSectorStorage* sect_storage) { auto it = m_object_creators.find(xml.attribute("type").value()); if (it == m_object_creators.end()) { throw ESearchItem(xml.attribute("type").value(), "GameObjectFactoryCreators"); } auto sector_name = xml.child("sector"); if (NULL == sector_name) { throw ESearchItem("no <sector> tag", "some object"); } auto target_sector = sect_storage->fetch_sector(sector_name.child_value()); BaseObject* result = it->second->create(xml, target_sector); target_sector->arrive(result); return result; }
bool GetServer(pugi::xml_node node, CServer& server) { wxASSERT(node); std::wstring host = GetTextElement(node, "Host"); if (host.empty()) { return false; } int port = GetTextElementInt(node, "Port"); if (port < 1 || port > 65535) { return false; } if (!server.SetHost(host, port)) { return false; } int const protocol = GetTextElementInt(node, "Protocol"); if (protocol < 0 || protocol > ServerProtocol::MAX_VALUE) { return false; } server.SetProtocol(static_cast<ServerProtocol>(protocol)); int type = GetTextElementInt(node, "Type"); if (type < 0 || type >= SERVERTYPE_MAX) { return false; } server.SetType(static_cast<ServerType>(type)); int logonType = GetTextElementInt(node, "Logontype"); if (logonType < 0 || logonType >= LOGONTYPE_MAX) { return false; } server.SetLogonType(static_cast<LogonType>(logonType)); if (server.GetLogonType() != ANONYMOUS) { std::wstring user = GetTextElement(node, "User"); std::wstring pass, key; if ((long)NORMAL == logonType || (long)ACCOUNT == logonType) { auto passElement = node.child("Pass"); if (passElement) { std::wstring encoding = GetTextAttribute(passElement, "encoding"); if (encoding == _T("base64")) { std::string decoded = fz::base64_decode(passElement.child_value()); pass = fz::to_wstring_from_utf8(decoded); } else if (!encoding.empty()) { server.SetLogonType(ASK); } else { pass = GetTextElement(passElement); } } } else if ((long)KEY == logonType) { key = GetTextElement(node, "Keyfile"); // password should be empty if we're using a key file pass.clear(); server.SetKeyFile(key); } if (!server.SetUser(user, pass)) { return false; } if ((long)ACCOUNT == logonType) { std::wstring account = GetTextElement(node, "Account"); if (account.empty()) { return false; } if (!server.SetAccount(account)) { return false; } } } int timezoneOffset = GetTextElementInt(node, "TimezoneOffset"); if (!server.SetTimezoneOffset(timezoneOffset)) { return false; } wxString pasvMode = GetTextElement(node, "PasvMode"); if (pasvMode == _T("MODE_PASSIVE")) server.SetPasvMode(MODE_PASSIVE); else if (pasvMode == _T("MODE_ACTIVE")) server.SetPasvMode(MODE_ACTIVE); else server.SetPasvMode(MODE_DEFAULT); int maximumMultipleConnections = GetTextElementInt(node, "MaximumMultipleConnections"); server.MaximumMultipleConnections(maximumMultipleConnections); wxString encodingType = GetTextElement(node, "EncodingType"); if (encodingType == _T("Auto")) { server.SetEncodingType(ENCODING_AUTO); } else if (encodingType == _T("UTF-8")) { server.SetEncodingType(ENCODING_UTF8); } else if (encodingType == _T("Custom")) { std::wstring customEncoding = GetTextElement(node, "CustomEncoding"); if (customEncoding.empty()) { return false; } if (!server.SetEncodingType(ENCODING_CUSTOM, customEncoding)) { return false; } } else { server.SetEncodingType(ENCODING_AUTO); } if (CServer::SupportsPostLoginCommands(server.GetProtocol())) { std::vector<std::wstring> postLoginCommands; auto element = node.child("PostLoginCommands"); if (element) { for (auto commandElement = element.child("Command"); commandElement; commandElement = commandElement.next_sibling("Command")) { std::wstring command = fz::to_wstring_from_utf8(commandElement.child_value()); if (!command.empty()) { postLoginCommands.emplace_back(std::move(command)); } } } if (!server.SetPostLoginCommands(postLoginCommands)) { return false; } } server.SetBypassProxy(GetTextElementInt(node, "BypassProxy", false) == 1); server.SetName(GetTextElement_Trimmed(node, "Name")); if (server.GetName().empty()) { server.SetName(GetTextElement_Trimmed(node)); } return true; }
void AvailableUpdateInfoDialog::updateCheckFinished(UpdateCheckStatus status, mtx_release_version_t releaseVersion) { auto statusStr = UpdateCheckStatus::NoNewReleaseAvailable == status ? QY("Currently no newer version is available online.") : UpdateCheckStatus::NewReleaseAvailable == status ? QY("There is a new version available online.") : QY("There was an error querying the update status."); ui->status->setText(statusStr); if (UpdateCheckStatus::Failed == status) return; ui->currentVersion->setText(to_qs(releaseVersion.current_version.to_string())); ui->availableVersion->setText(to_qs(releaseVersion.latest_source.to_string())); ui->close->setText(QY("&Close")); auto url = releaseVersion.urls.find("general"); if ((url != releaseVersion.urls.end()) && !url->second.empty()) { m_downloadURL = to_qs(url->second); ui->downloadURL->setText(Q("<html><body><a href=\"%1\">%1</a></body></html>").arg(m_downloadURL.toHtmlEscaped())); ui->download->setEnabled(true); } if (!m_releasesInfo) return; auto html = QStringList{}; auto numReleasesOutput = 0; auto releases = m_releasesInfo->select_nodes("/mkvtoolnix-releases/release[not(@version='HEAD')]"); auto re_released = boost::regex{"^released\\s+v?[\\d\\.]+", boost::regex::perl | boost::regex::icase}; auto re_bug = boost::regex{"(#\\d+)", boost::regex::perl | boost::regex::icase}; auto bug_formatter = [](boost::smatch const &matches) -> std::string { auto number_str = matches[1].str().substr(1); return (boost::format("<a href=\"https://github.com/mbunkus/mkvtoolnix/issues/%1%\">#%1%</a>") % number_str).str(); }; releases.sort(); for (auto &release : releases) { auto version_str = std::string{release.node().attribute("version").value()}; auto version_str_q = to_qs(version_str).toHtmlEscaped(); auto codename_q = to_qs(release.node().attribute("codename").value()).toHtmlEscaped(); auto heading = !codename_q.isEmpty() ? QY("Version %1 \"%2\"").arg(version_str_q).arg(codename_q) : QY("Version %1").arg(version_str_q); html << Q("<h2>%1</h2>").arg(heading) << Q("<p><ul>"); for (auto change = release.node().child("changes").first_child() ; change ; change = change.next_sibling()) { if ( (std::string{change.name()} != "change") || boost::regex_search(change.child_value(), re_released)) continue; auto text = boost::regex_replace(to_utf8(to_qs(change.child_value()).toHtmlEscaped()), re_bug, bug_formatter); html << Q("<li>%1</li>").arg(to_qs(text)); } html << Q("</ul></p>"); numReleasesOutput++; if ((10 < numReleasesOutput) && (version_number_t{version_str} < releaseVersion.current_version)) break; } html << Q("<p><a href=\"%1\">%2</a></h1>").arg(MTX_CHANGELOG_URL).arg(QY("Read full ChangeLog online")); setChangeLogContent(html.join(Q("\n"))); }