diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-07-21 14:52:05 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-07-21 16:42:48 +0200 |
commit | 3b2b2eae863d1082a36c02851190e0846f90cdd1 (patch) | |
tree | da877b3ed5f2e80bc5b939c97828572e4d80cc7e | |
parent | 37247ffb6f255ca7f96c6110149bcf85a2cddd44 (diff) |
sw bibliography, local copy: add document model & UNO API
The idea is that a bibliography entry (field) can have not only an URL
(which might be unavailable due to lack of network connectivity,
paywall, etc) but also a local copy, which is also a URL.
The local copy doesn't replace the original URL. The local copy is
stored part of the document, since it may be a relative URL, e.g. ODT +
several PDFs copied around in the same directory.
This commit just starts this feature, up to the extent that read and
write of the new property works.
Change-Id: I3c4df2be3a1f3b02a87c097f8a0630951def09d0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119322
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | offapi/com/sun/star/text/BibliographyDataField.idl | 5 | ||||
-rw-r--r-- | sw/inc/helpids.h | 1 | ||||
-rw-r--r-- | sw/inc/strings.hrc | 1 | ||||
-rw-r--r-- | sw/inc/toxe.hxx | 1 | ||||
-rw-r--r-- | sw/qa/core/unocore/unocore.cxx | 38 | ||||
-rw-r--r-- | sw/source/core/fields/authfld.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/unocore/unoidx.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/index/cnttab.cxx | 3 | ||||
-rw-r--r-- | sw/source/ui/index/swuiidxmrk.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/utlui/initui.cxx | 3 |
10 files changed, 57 insertions, 6 deletions
diff --git a/offapi/com/sun/star/text/BibliographyDataField.idl b/offapi/com/sun/star/text/BibliographyDataField.idl index 6934bf8872e7..8923224247fc 100644 --- a/offapi/com/sun/star/text/BibliographyDataField.idl +++ b/offapi/com/sun/star/text/BibliographyDataField.idl @@ -123,6 +123,11 @@ published constants BibliographyDataField /** This field contains the ISBN data of the publishing. */ const short ISBN = 30; + /** This field contains a local copy of the publishing. + + @since LibreOffice 7.3 + */ + const short LOCAL_URL = 31; }; }; }; }; }; diff --git a/sw/inc/helpids.h b/sw/inc/helpids.h index ad9c82557dcb..8995d9f11d3d 100644 --- a/sw/inc/helpids.h +++ b/sw/inc/helpids.h @@ -97,6 +97,7 @@ #define HID_AUTH_FIELD_CUSTOM4 "SW_HID_AUTH_FIELD_CUSTOM4" #define HID_AUTH_FIELD_CUSTOM5 "SW_HID_AUTH_FIELD_CUSTOM5" #define HID_AUTH_FIELD_ISBN "SW_HID_AUTH_FIELD_ISBN" +#define HID_AUTH_FIELD_LOCAL_URL "SW_HID_AUTH_FIELD_LOCAL_URL" #define HID_BUSINESS_FMT_PAGE "SW_HID_BUSINESS_FMT_PAGE" #define HID_BUSINESS_FMT_PAGE_CONT "SW_HID_BUSINESS_FMT_PAGE_CONT" diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index de5d3da88668..a7981f2c9929 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -797,6 +797,7 @@ #define STR_AUTH_FIELD_CUSTOM4 NC_("STR_AUTH_FIELD_CUSTOM4", "User-defined4") #define STR_AUTH_FIELD_CUSTOM5 NC_("STR_AUTH_FIELD_CUSTOM5", "User-defined5") #define STR_AUTH_FIELD_ISBN NC_("STR_AUTH_FIELD_ISBN", "ISBN") +#define STR_AUTH_FIELD_LOCAL_URL NC_("STR_AUTH_FIELD_LOCAL_URL", "Local copy") #define STR_IDXMRK_EDIT NC_("STR_IDXMRK_EDIT", "Edit Index Entry") #define STR_IDXMRK_INSERT NC_("STR_IDXMRK_INSERT", "Insert Index Entry") diff --git a/sw/inc/toxe.hxx b/sw/inc/toxe.hxx index 7582970c1fac..b2f08e66c320 100644 --- a/sw/inc/toxe.hxx +++ b/sw/inc/toxe.hxx @@ -114,6 +114,7 @@ enum ToxAuthorityField AUTH_FIELD_CUSTOM4, AUTH_FIELD_CUSTOM5, AUTH_FIELD_ISBN, + AUTH_FIELD_LOCAL_URL, AUTH_FIELD_END }; diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx index cf701a25d423..a1f74d46f5a6 100644 --- a/sw/qa/core/unocore/unocore.cxx +++ b/sw/qa/core/unocore/unocore.cxx @@ -9,9 +9,13 @@ #include <swmodeltestbase.hxx> +#include <com/sun/star/text/BibliographyDataType.hpp> #include <com/sun/star/text/XTextAppend.hpp> #include <com/sun/star/text/XTextFrame.hpp> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/sequenceashashmap.hxx> + #include <wrtsh.hxx> #include <unotextrange.hxx> #include <unotxdoc.hxx> @@ -96,6 +100,40 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testRtlGutter) CPPUNIT_ASSERT(bRtlGutter); } +CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testBiblioLocalCopy) +{ + // Given an empty document: + createSwDoc(); + + // When setting the LocalURL of a biblio field: + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("ARJ00")), + comphelper::makePropertyValue("Author", OUString("Me")), + comphelper::makePropertyValue("Title", OUString("mytitle")), + comphelper::makePropertyValue("Year", OUString("2020")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf")), + comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")), + }; + xField->setPropertyValue("Fields", uno::makeAny(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // Then make sure we get that LocalURL back: + comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields")); + // Without the accompanying fix in place, this test would have failed, there was no LocalURL key + // in the map. + CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end()); + auto aActual = aMap["LocalURL"].get<OUString>(); + CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx index 7a2dea545ab9..fec3e1a2b4c4 100644 --- a/sw/source/core/fields/authfld.cxx +++ b/sw/source/core/fields/authfld.cxx @@ -678,7 +678,8 @@ const char* const aFieldNames[] = "Custom3", "Custom4", "Custom5", - "ISBN" + "ISBN", + "LocalURL" }; void SwAuthEntry::dumpAsXml(xmlTextWriterPtr pWriter) const @@ -736,7 +737,7 @@ bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ ) return false; OUStringBuffer sBuf; - comphelper::string::padToLength(sBuf, AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER); + comphelper::string::padToLength(sBuf, AUTH_FIELD_LOCAL_URL, TOX_STYLE_DELIMITER); OUString sToSet(sBuf.makeStringAndClear()); for(const PropertyValue& rParam : std::as_const(aParam)) { diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 79ce7706b241..1b6f8d7fb166 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -2788,7 +2788,7 @@ SwXDocumentIndex::TokenAccess_Impl::replaceByIndex( { sal_Int16 nType = 0; pProperties[j].Value >>= nType; - if(nType < 0 || nType > text::BibliographyDataField::ISBN) + if(nType < 0 || nType > text::BibliographyDataField::LOCAL_URL) { lang::IllegalArgumentException aExcept; aExcept.Message = "BibliographyDataField - wrong value"; diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx index 30c9407064d3..0477ab25600f 100644 --- a/sw/source/ui/index/cnttab.cxx +++ b/sw/source/ui/index/cnttab.cxx @@ -1759,7 +1759,8 @@ namespace STR_AUTH_FIELD_CUSTOM3, STR_AUTH_FIELD_CUSTOM4, STR_AUTH_FIELD_CUSTOM5, - STR_AUTH_FIELD_ISBN + STR_AUTH_FIELD_ISBN, + STR_AUTH_FIELD_LOCAL_URL, }; } diff --git a/sw/source/ui/index/swuiidxmrk.cxx b/sw/source/ui/index/swuiidxmrk.cxx index b985af79141a..3a3c5021d176 100644 --- a/sw/source/ui/index/swuiidxmrk.cxx +++ b/sw/source/ui/index/swuiidxmrk.cxx @@ -1142,6 +1142,7 @@ const TextInfo aTextInfoArr[] = {AUTH_FIELD_ANNOTE, HID_AUTH_FIELD_ANNOTE }, {AUTH_FIELD_NOTE, HID_AUTH_FIELD_NOTE }, {AUTH_FIELD_URL, HID_AUTH_FIELD_URL }, + {AUTH_FIELD_LOCAL_URL, HID_AUTH_FIELD_LOCAL_URL }, {AUTH_FIELD_CUSTOM1, HID_AUTH_FIELD_CUSTOM1 }, {AUTH_FIELD_CUSTOM2, HID_AUTH_FIELD_CUSTOM2 }, {AUTH_FIELD_CUSTOM3, HID_AUTH_FIELD_CUSTOM3 }, @@ -1554,7 +1555,8 @@ namespace STR_AUTH_FIELD_CUSTOM3, STR_AUTH_FIELD_CUSTOM4, STR_AUTH_FIELD_CUSTOM5, - STR_AUTH_FIELD_ISBN + STR_AUTH_FIELD_ISBN, + STR_AUTH_FIELD_LOCAL_URL, }; } diff --git a/sw/source/uibase/utlui/initui.cxx b/sw/source/uibase/utlui/initui.cxx index 5b015c71d9b6..4a07f75678e2 100644 --- a/sw/source/uibase/utlui/initui.cxx +++ b/sw/source/uibase/utlui/initui.cxx @@ -234,7 +234,8 @@ namespace STR_AUTH_FIELD_CUSTOM3, STR_AUTH_FIELD_CUSTOM4, STR_AUTH_FIELD_CUSTOM5, - STR_AUTH_FIELD_ISBN + STR_AUTH_FIELD_ISBN, + STR_AUTH_FIELD_LOCAL_URL, }; } |