Applying patches by Michi to Enigma

This commit is contained in:
pelya
2010-10-15 14:23:30 +03:00
parent 679f64d3a0
commit ebaff58990
15 changed files with 141 additions and 84 deletions

View File

@@ -16,7 +16,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "PreferenceManager.hh"
#include "main.hh"
#include "DOMErrorReporter.hh"
@@ -60,13 +59,14 @@ namespace enigma {
PreferenceManager::PreferenceManager() {
std::string prefTemplatePath;
bool haveXMLProperties = (ecl::FileExists(app.prefPath)) ? true : false;
if (!app.systemFS->findFile( std::string("schemas/") + PREFFILENAME , prefTemplatePath)) {
cerr << "Preferences: no template found\n";
exit(-1);
}
try {
app.domParserErrorHandler->resetErrors();
app.domParserErrorHandler->reportToErr();
app.domParserSchemaResolver->resetResolver();
@@ -76,14 +76,14 @@ namespace enigma {
// update existing XML prefs from possibly newer template:
// use user prefs and copy new properties from template
doc = app.domParser->parseURI(app.prefPath.c_str());
propertiesElem = dynamic_cast<DOMElement *>(doc->getElementsByTagName(
propertiesElem = reinterpret_cast<DOMElement *>(doc->getElementsByTagName(
Utf8ToXML("properties").x_str())->item(0));
// The following algorithm is not optimized - O(n^2)!
DOMDocument * prefTemplate = app.domParser->parseURI(prefTemplatePath.c_str());
DOMNodeList * tmplPropList = prefTemplate->getElementsByTagName(
Utf8ToXML("property").x_str());
for (int i = 0, l = tmplPropList-> getLength(); i < l; i++) {
DOMElement *tmplProperty = dynamic_cast<DOMElement *>(tmplPropList->item(i));
DOMElement *tmplProperty = reinterpret_cast<DOMElement *>(tmplPropList->item(i));
const XMLCh * key = tmplProperty->getAttribute(Utf8ToXML("key").x_str());
DOMElement * lastUserProperty;
if ((key[0] != chUnderscore) && !hasProperty(key, &lastUserProperty)) {
@@ -95,20 +95,21 @@ namespace enigma {
Log << "Preferences: copy new Property failed!\n";
} else {
// insert it at the end of the existing user properties
propertiesElem->appendChild(dynamic_cast<DOMElement *>(newProperty));
propertiesElem->appendChild(reinterpret_cast<DOMElement *>(newProperty));
}
}
}
prefTemplate->release();
} else {
// update from LUA options to XML preferences:
// use the template, copy LUA option values and save it later as prefs
doc = app.domParser->parseURI(prefTemplatePath.c_str());
propertiesElem = dynamic_cast<DOMElement *>(doc->getElementsByTagName(
propertiesElem = reinterpret_cast<DOMElement *>(doc->getElementsByTagName(
Utf8ToXML("properties").x_str())->item(0));
DOMNodeList * propList = propertiesElem->getElementsByTagName(Utf8ToXML("property").x_str());
for (int i = 0, l = propList-> getLength(); i < l; i++) {
DOMElement * property = dynamic_cast<DOMElement *>(propList->item(i));
DOMElement * property = reinterpret_cast<DOMElement *>(propList->item(i));
const XMLCh * key = property->getAttribute(Utf8ToXML("key").x_str());
std::string optionValue;
if (options::HasOption(XMLtoLocal(key).c_str(), optionValue)) {