Commits

Kitty Barnett committed 84c2456

STORM-276 Ease-of-use importing of Open Office dictionary extensions

  • Participants
  • Parent commits c535088

Comments (0)

Files changed (3)

indra/newview/llfilepicker.cpp

 #define RAW_FILTER L"RAW files (*.raw)\0*.raw\0"
 #define MODEL_FILTER L"Model files (*.dae)\0*.dae\0"
 #define SCRIPT_FILTER L"Script files (*.lsl)\0*.lsl\0"
-#define DICTIONARY_FILTER L"Dictionary files (*.dic)\0*.dic\0"
+#define DICTIONARY_FILTER L"Dictionary files (*.dic; *.xcu)\0*.dic;*.xcu\0"
 #endif
 
 //
 						else if (filter == FFLOAD_DICTIONARY)
 						{
 							if (fileInfo.filetype != 'DIC ' &&
-								(fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("dic"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) )
+								fileInfo.filetype != 'XCU ' &&
+								(fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("dic"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) &&
+								 fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("xcu"), kCFCompareCaseInsensitive) != kCFCompareEqualTo))
 							{
 								result = false;
 							}
 static std::string add_dictionary_filter_to_gtkchooser(GtkWindow *picker)
 {
 	return add_simple_mime_filter_to_gtkchooser(picker,  "text/plain",
-							LLTrans::getString("dictionary_files") + " (*.dic)");
+							LLTrans::getString("dictionary_files") + " (*.dic; *.xcu)");
 }
 
 BOOL LLFilePicker::getSaveFile( ESaveFilter filter, const std::string& filename )

indra/newview/llfloaterspellchecksettings.cpp

 		return;
 	}
 
-	const std::string filepath = file_picker.getFirstFile();
+	std::string filepath = file_picker.getFirstFile();
+
+	const std::string extension = gDirUtilp->getExtension(filepath);
+	if ("xcu" == extension)
+	{
+		filepath = parseXcuFile(filepath);
+		if (filepath.empty())
+		{
+			return;
+		}
+	}
+
 	getChild<LLUICtrl>("dictionary_path")->setValue(filepath);
 	
 	mDictionaryDir = gDirUtilp->getDirName(filepath);
 	fclose(in);
 	return copied;
 }
+
+std::string LLFloaterSpellCheckerImport::parseXcuFile(const std::string& file_path) const
+{
+	LLXMLNodePtr xml_root;
+	if ( (!LLUICtrlFactory::getLayeredXMLNode(file_path, xml_root)) || (xml_root.isNull()) )
+	{
+		return LLStringUtil::null;
+	}
+
+	// Bury down to the "Dictionaries" parent node
+	LLXMLNode* dict_node = NULL;
+	for (LLXMLNode* outer_node = xml_root->getFirstChild(); outer_node && !dict_node; outer_node = outer_node->getNextSibling())
+	{
+		std::string temp;
+		if ( (outer_node->getAttributeString("oor:name", temp)) && ("ServiceManager" == temp) )
+		{
+			for (LLXMLNode* inner_node = outer_node->getFirstChild(); inner_node && !dict_node; inner_node = inner_node->getNextSibling())
+			{
+				if ( (inner_node->getAttributeString("oor:name", temp)) && ("Dictionaries" == temp) )
+				{
+					dict_node = inner_node;
+					break;
+				}
+			}
+		}
+	}
+
+	if (dict_node)
+	{
+		// Iterate over all child nodes until we find one that has a <value>DICT_SPELL</value> node
+		for (LLXMLNode* outer_node = dict_node->getFirstChild(); outer_node; outer_node = outer_node->getNextSibling())
+		{
+			std::string temp;
+			LLXMLNodePtr location_node, format_node;
+			for (LLXMLNode* inner_node = outer_node->getFirstChild(); inner_node; inner_node = inner_node->getNextSibling())
+			{
+				if (inner_node->getAttributeString("oor:name", temp))
+				{
+					if ("Locations" == temp)
+					{
+						inner_node->getChild("value", location_node, false);
+					}
+					else if ("Format" == temp)
+					{
+						inner_node->getChild("value", format_node, false);
+					}
+				}
+			}
+			if ( (format_node.isNull()) || ("DICT_SPELL" != format_node->getValue()) || (location_node.isNull()) )
+			{
+				continue;
+			}
+
+			// Found a list of file locations, return the .dic (if present)
+			std::list<std::string> location_list;
+			boost::split(location_list, location_node->getValue(), boost::is_any_of(std::string(" ")));
+			for (std::list<std::string>::iterator it = location_list.begin(); it != location_list.end(); ++it)
+			{
+				std::string& location = *it;
+				if ("\\" != gDirUtilp->getDirDelimiter())
+					LLStringUtil::replaceString(location, "\\", gDirUtilp->getDirDelimiter());
+				else
+					LLStringUtil::replaceString(location, "/", gDirUtilp->getDirDelimiter());
+				LLStringUtil::replaceString(location, "%origin%", gDirUtilp->getDirName(file_path));
+				if ("dic" == gDirUtilp->getExtension(location))
+				{
+					return location;
+				}
+			}
+		}
+	}
+
+	return LLStringUtil::null;
+}

indra/newview/llfloaterspellchecksettings.h

 	void onBtnCancel();
 	void onBtnOK();
 	bool copyFile(const std::string from, const std::string to);
+	std::string parseXcuFile(const std::string& file_path) const;
 
 	std::string mDictionaryDir;
 	std::string mDictionaryBasename;