summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-03-23 21:27:18 +0100
committerJan Holesovsky <kendy@collabora.com>2017-03-24 19:05:42 +0100
commita9d218fd74f4fd4f934fecbbc16af9111ded5e67 (patch)
tree7359d35e87a4a41c982a93a9ba4929d831feee0a
parent4ea53461a8b573d5254c25eab2ffdd5c88032c6b (diff)
lok: Allow setting of the language during load.
Conflicts: desktop/CppunitTest_desktop_app.mk desktop/qa/desktop_lib/test_desktop_lib.cxx include/LibreOfficeKit/LibreOfficeKit.hxx Change-Id: I9dbb62950e639376c26122ceb9fcec2982b3ca82
-rw-r--r--desktop/CppunitTest_desktop_app.mk1
-rw-r--r--desktop/inc/lib/init.hxx5
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx30
-rw-r--r--desktop/source/lib/init.cxx60
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx4
5 files changed, 99 insertions, 1 deletions
diff --git a/desktop/CppunitTest_desktop_app.mk b/desktop/CppunitTest_desktop_app.mk
index af036f8696cc..d00848814968 100644
--- a/desktop/CppunitTest_desktop_app.mk
+++ b/desktop/CppunitTest_desktop_app.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_app, \
cppu \
cppuhelper \
sal \
+ sofficeapp \
ucbhelper \
sofficeapp \
))
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index db281688c2f9..437fcdd6918f 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -95,6 +95,11 @@ namespace desktop {
return (mOptionalFeatures & feature) != 0;
}
};
+
+ /// Helper function to extract the value from parameters delimited by
+ /// comma, like: Name1=Value1,Name2=Value2,Name3=Value3.
+ /// @param rOptions When exctacted, the Param=Value is removed from it.
+ DESKTOP_DLLPUBLIC OUString extractParameter(OUString& aOptions, const OUString& rName);
}
#endif
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index ad7cf926f747..6a2cd225f603 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -106,6 +106,7 @@ public:
void testPaintPartTile();
void testWriterCommentInsertCursor();
void testGetFontSubset();
+ void testExtractParameter();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
CPPUNIT_TEST(testGetStyles);
@@ -140,6 +141,7 @@ public:
CPPUNIT_TEST(testPaintPartTile);
CPPUNIT_TEST(testWriterCommentInsertCursor);
CPPUNIT_TEST(testGetFontSubset);
+ CPPUNIT_TEST(testExtractParameter);
CPPUNIT_TEST_SUITE_END();
uno::Reference<lang::XComponent> mxComponent;
@@ -1445,6 +1447,34 @@ void DesktopLOKTest::testGetFontSubset()
comphelper::LibreOfficeKit::setActive(false);
}
+void DesktopLOKTest::testExtractParameter()
+{
+ OUString aOptions("Language=de-DE");
+ OUString aValue = extractParameter(aOptions, "Language");
+ CPPUNIT_ASSERT_EQUAL(OUString("de-DE"), aValue);
+ CPPUNIT_ASSERT_EQUAL(OUString(), aOptions);
+
+ aOptions = "Language=en-US,Something";
+ aValue = extractParameter(aOptions, "Language");
+ CPPUNIT_ASSERT_EQUAL(OUString("en-US"), aValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("Something"), aOptions);
+
+ aOptions = "SomethingElse,Language=cs-CZ";
+ aValue = extractParameter(aOptions, "Language");
+ CPPUNIT_ASSERT_EQUAL(OUString("cs-CZ"), aValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("SomethingElse"), aOptions);
+
+ aOptions = "Something1,Language=hu-HU,Something2";
+ aValue = extractParameter(aOptions, "Language");
+ CPPUNIT_ASSERT_EQUAL(OUString("hu-HU"), aValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("Something1,Something2"), aOptions);
+
+ aOptions = "Something1,Something2=blah,Something3";
+ aValue = extractParameter(aOptions, "Language");
+ CPPUNIT_ASSERT_EQUAL(OUString(), aValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("Something1,Something2=blah,Something3"), aOptions);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 597a225f20b2..7d2df83a60e3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -432,6 +432,50 @@ int lcl_getViewId(const std::string& payload)
} // end anonymous namespace
+// Could be anonymous in principle, but for the unit testing purposes, we
+// declare it in init.hxx.
+OUString desktop::extractParameter(OUString& rOptions, const OUString& rName)
+{
+ OUString aValue;
+
+ OUString aNameEquals(rName + "=");
+ OUString aCommaNameEquals("," + rName + "=");
+
+ int nIndex = -1;
+ if (rOptions.startsWith(aNameEquals))
+ {
+ size_t nLen = aNameEquals.getLength();
+ int nComma = rOptions.indexOf(",", nLen);
+ if (nComma >= 0)
+ {
+ aValue = rOptions.copy(nLen, nComma - nLen);
+ rOptions = rOptions.copy(nComma + 1);
+ }
+ else
+ {
+ aValue = rOptions.copy(nLen);
+ rOptions.clear();
+ }
+ }
+ else if ((nIndex = rOptions.indexOf(aCommaNameEquals)) >= 0)
+ {
+ size_t nLen = aCommaNameEquals.getLength();
+ int nComma = rOptions.indexOf(",", nIndex + nLen);
+ if (nComma >= 0)
+ {
+ aValue = rOptions.copy(nIndex + nLen, nComma - nIndex - nLen);
+ rOptions = rOptions.copy(0, nIndex) + rOptions.copy(nComma);
+ }
+ else
+ {
+ aValue = rOptions.copy(nIndex + nLen);
+ rOptions = rOptions.copy(0, nIndex);
+ }
+ }
+
+ return aValue;
+}
+
extern "C"
{
@@ -1057,10 +1101,24 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
try
{
+ // 'Language=...' is an option that LOK consumes by itself, and does
+ // not pass it as a parameter to the filter
+ OUString aOptions = getUString(pOptions);
+ OUString aLanguage = extractParameter(aOptions, "Language");
+
+ if (!aLanguage.isEmpty())
+ {
+ // use with care - it sets it for the entire core, not just the
+ // document
+ SvtSysLocaleOptions aSysLocaleOptions;
+ aSysLocaleOptions.SetLocaleConfigString(aLanguage);
+ aSysLocaleOptions.SetUILocaleConfigString(aLanguage);
+ }
+
uno::Sequence<css::beans::PropertyValue> aFilterOptions(2);
aFilterOptions[0] = css::beans::PropertyValue( OUString("FilterOptions"),
0,
- uno::makeAny(OUString::createFromAscii(pOptions)),
+ uno::makeAny(aOptions),
beans::PropertyState_DIRECT_VALUE);
rtl::Reference<LOKInteractionHandler> const pInteraction(
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index eaee8a3c17c2..889f1601568e 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -477,6 +477,10 @@ public:
*
* @param pUrl the URL of the document to load
* @param pFilterOptions options for the import filter, e.g. SkipImages.
+ * Another useful FilterOption is "Language=...". It is consumed
+ * by the documentLoad() itself, and when provided, LibreOfficeKit
+ * switches the language accordingly first.
+ * @since pFilterOptions argument added in LibreOffice 5.0
*/
inline Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
{