void COptions::SetServer(wxString path, const CServer& server) { if (!m_pXmlFile) return; if (path == _T("")) return; TiXmlElement *element = m_pXmlFile->GetElement(); while (path != _T("")) { wxString sub; int pos = path.Find('/'); if (pos != -1) { sub = path.Left(pos); path = path.Mid(pos + 1); } else { sub = path; path = _T(""); } char *utf8 = ConvUTF8(sub); if (!utf8) return; TiXmlElement *newElement = element->FirstChildElement(utf8); delete [] utf8; if (newElement) element = newElement; else { char *utf8 = ConvUTF8(sub); if (!utf8) return; TiXmlNode *node = element->LinkEndChild(new TiXmlElement(utf8)); delete [] utf8; if (!node || !node->ToElement()) return; element = node->ToElement(); } } ::SetServer(element, server); if (GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) return; CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile->Save(); }
void COptions::SetXmlValue(unsigned int nID, wxString value) { if (!m_pXmlFile) return; // No checks are made about the validity of the value, that's done in SetOption char *utf8 = ConvUTF8(value); if (!utf8) return; TiXmlElement *settings = m_pXmlFile->GetElement()->FirstChildElement("Settings"); if (!settings) { TiXmlNode *node = m_pXmlFile->GetElement()->LinkEndChild(new TiXmlElement("Settings")); if (!node) { delete [] utf8; return; } settings = node->ToElement(); if (!settings) { delete [] utf8; return; } } else { TiXmlNode *node = 0; while ((node = settings->IterateChildren("Setting", node))) { TiXmlElement *setting = node->ToElement(); if (!setting) continue; const char *attribute = setting->Attribute("name"); if (!attribute) continue; if (strcmp(attribute, options[nID].name)) continue; //setting->RemoveAttribute("type"); setting->Clear(); //setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number"); setting->LinkEndChild(new TiXmlText(utf8)); delete [] utf8; return; } } wxASSERT(options[nID].name[0]); TiXmlElement *setting = new TiXmlElement("Setting"); setting->SetAttribute("name", options[nID].name); //setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number"); setting->LinkEndChild(new TiXmlText(utf8)); settings->LinkEndChild(setting); delete [] utf8; }
void SetTextAttribute(TiXmlElement* node, const char* name, const wxString& value) { wxASSERT(node); char* utf8 = ConvUTF8(value); if (!utf8) return; node->SetAttribute(name, utf8); delete [] utf8; }
void AddTextElement(TiXmlElement* node, const char* name, const wxString& value, bool overwrite) { wxASSERT(node); char* utf8 = ConvUTF8(value); if (!utf8) return; AddTextElementRaw(node, name, utf8, overwrite); delete [] utf8; }
void AddTextElement(TiXmlElement* node, const wxString& value) { wxASSERT(node); wxASSERT(value); char* utf8 = ConvUTF8(value); if (!utf8) return; AddTextElementRaw(node, utf8); delete [] utf8; }
void AddTextElement(TiXmlElement* node, const char* name, const wxString& value) { wxASSERT(node); TiXmlElement element(name); char* utf8 = ConvUTF8(value); if (!utf8) return; element.InsertEndChild(TiXmlText(utf8)); delete [] utf8; node->InsertEndChild(element); }
/* * Determine for a character is display string and columns width */ static void rl_analyze_ucs (wint_tt ucs, const char **display, UWORD *columns) { char *utf = NULL; #if HAVE_WCWIDTH int width; #endif utf = strdup (ConvUTF8 (ucs)); *display = ConvTo (utf, ENC(enc_loc))->txt; if (ucs < 32 || ucs == 127 || ucs == 173) /* control code */ { *display = s_sprintf ("%s^%c%s", COLINVCHAR, (char)((ucs - 1 + 'A') & 0x7f), COLNONE); *columns = 2; } else if (ucs < 127) *columns = 1; #if HAVE_WCWIDTH else if (!prG->locale_broken && (width = rl_wcwidth (ucs, *display)) != -1) *columns = 256 | width; #else else if (ucs >= 160) /* no way I'll hard-code double-width or combining marks here */ *columns = 257; #endif else if (prG->locale_broken && !strcmp (ConvFrom (ConvTo (utf, ENC(enc_loc)), ENC(enc_loc))->txt, utf)) *columns = 257; else if (!(ucs & 0xffff0000)) /* more control code, or unknown */ { *display = s_sprintf ("%s\\u%c%c%c%c%s", COLINVCHAR, rl_hex (ucs / 4096), rl_hex (ucs / 256), rl_hex (ucs / 16), rl_hex (ucs), COLNONE); *columns = 6; } else /* unknown stellar planes */ { *display = s_sprintf ("%s\\U%c%c%c%c%c%c%c%c%s", COLINVCHAR, rl_hex (ucs / 268435456), rl_hex (ucs / 16777216), rl_hex (ucs / 1048576), rl_hex (ucs / 65536), rl_hex (ucs / 4096), rl_hex (ucs / 256), rl_hex (ucs / 16), rl_hex (ucs), COLNONE); *columns = 10; } free (utf); }
void AddTextElement(TiXmlElement* node, const wxString& value) { wxASSERT(node); char* utf8 = ConvUTF8(value); if (!utf8) return; for (TiXmlNode* pChild = node->FirstChild(); pChild; pChild = pChild->NextSibling()) { if (!pChild->ToText()) continue; node->RemoveChild(pChild); break; } node->InsertEndChild(TiXmlText(utf8)); delete [] utf8; }
/* * Compresses part of the current edited line into an UTF8 string */ static void rl_linecompress (str_t line, UDWORD from, UDWORD to) { UDWORD i; wint_tt ucs; if (to == (UDWORD)-1) to = rl_ucscol.len; s_init (line, "", 0); for (i = from; i < to; i++) { ucs = rl_ucs_at (&rl_ucs, i); #if DEBUG_RL fprintf (stderr, "ucs %x\n", ucs); #endif if (ucs != WEOF) s_cat (line, ConvUTF8 (ucs)); } #if DEBUG_RL fprintf (stderr, "compress %s\n", s_qquote (line->txt)); #endif }
bool COptions::GetServer(wxString path, CServer& server) { if (path == _T("")) return false; if (!m_pXmlFile) return false; TiXmlElement *element = m_pXmlFile->GetElement(); while (path != _T("")) { wxString sub; int pos = path.Find('/'); if (pos != -1) { sub = path.Left(pos); path = path.Mid(pos + 1); } else { sub = path; path = _T(""); } char *utf8 = ConvUTF8(sub); if (!utf8) return false; element = element->FirstChildElement(utf8); delete [] utf8; if (!element) return false; } bool res = ::GetServer(element, server); return res; }
/* * Determine width and correct display for given (UTF8) string */ strc_t ReadLineAnalyzeWidth (const char *text, UWORD *width) { static str_s str = { NULL, 0, 0 }; wchar_tt ucs; UWORD twidth, swidth = 0; const char *dis; int off = 0; str_s in; in.txt = (char *)text; in.len = strlen (text); in.max = 0; s_init (&str, "", 100); for (off = 0; off < in.len; ) { ucs = ConvGetUTF8 (&in, &off); rl_analyze_ucs (ucs, &dis, &twidth); swidth += twidth & 0xff; s_cat (&str, twidth & 0x100 ? ConvUTF8 (ucs) : dis); } *width = swidth; return &str; }
wxString CSiteManager::AddServer(CServer server) { // We have to synchronize access to sitemanager.xml so that multiple processed don't write // to the same file or one is reading while the other one writes. CInterProcessMutex mutex(MUTEX_SITEMANAGER); CXmlFile file; TiXmlElement* pDocument = file.Load(_T("sitemanager")); if (!pDocument) { wxString msg = file.GetError() + _T("\n") + _("The server could not be added."); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); return _T(""); } TiXmlElement* pElement = pDocument->FirstChildElement("Servers"); if (!pElement) return _T(""); std::list<wxString> names; for (TiXmlElement* pChild = pElement->FirstChildElement("Server"); pChild; pChild = pChild->NextSiblingElement("Server")) { wxString name = GetTextElement(pChild, "Name"); if (name.empty()) continue; names.push_back(name); } wxString name = _("New site"); int i = 1; for (;;) { std::list<wxString>::const_iterator iter; for (iter = names.begin(); iter != names.end(); ++iter) { if (*iter == name) break; } if (iter == names.end()) break; name = _("New site") + wxString::Format(_T(" %d"), ++i); } server.SetName(name); TiXmlElement* pServer = pElement->LinkEndChild(new TiXmlElement("Server"))->ToElement(); SetServer(pServer, server); char* utf8 = ConvUTF8(name); if (utf8) { pServer->LinkEndChild(new TiXmlText(utf8)); delete [] utf8; } wxString error; if (!file.Save(&error)) { if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) return _T(""); wxString msg = wxString::Format(_("Could not write \"%s\", any changes to the Site Manager could not be saved: %s"), file.GetFileName().GetFullPath().c_str(), error.c_str()); wxMessageBox(msg, _("Error writing xml file"), wxICON_ERROR); return _T(""); } return _T("0/") + EscapeSegment(name); }