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:01:53 +0100
commit5fefac660ae5d978843fd7abbc6db1fce0800566 (patch)
tree206f056a85470765a643458476ac7bf01d133253
parent125ca372c1d0821139b4c682a02494294b322473 (diff)
lok: Allow setting of the language during load.
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.hxx3
5 files changed, 98 insertions, 1 deletions
diff --git a/desktop/CppunitTest_desktop_app.mk b/desktop/CppunitTest_desktop_app.mk
index b809b6a7e8c6..1e7e3e0813c5 100644
--- a/desktop/CppunitTest_desktop_app.mk
+++ b/desktop/CppunitTest_desktop_app.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_app, \
salhelper \
sb \
sfx \
+ sofficeapp \
svl \
svx \
svxcore \
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 302f54de5391..c8162c1fea2f 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -94,6 +94,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 310fe237b5e2..bbf8ac91afc7 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -109,6 +109,7 @@ public:
void testCommentsImpress();
void testCommentsCallbacksWriter();
void testRunMacro();
+ void testExtractParameter();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
CPPUNIT_TEST(testGetStyles);
@@ -148,6 +149,7 @@ public:
CPPUNIT_TEST(testCommentsImpress);
CPPUNIT_TEST(testCommentsCallbacksWriter);
CPPUNIT_TEST(testRunMacro);
+ CPPUNIT_TEST(testExtractParameter);
CPPUNIT_TEST_SUITE_END();
uno::Reference<lang::XComponent> mxComponent;
@@ -2112,6 +2114,34 @@ void DesktopLOKTest::testRunMacro()
CPPUNIT_ASSERT(!bNonExistentMacro);
}
+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 90c85b9de4ac..edbeb4a01975 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -472,6 +472,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"
{
@@ -1160,10 +1204,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( "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 d68a425f05bd..47da169f5ce5 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -477,6 +477,9 @@ 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
*/
Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)