Kaydet (Commit) d1f7124c authored tarafından Matúš Kukan's avatar Matúš Kukan Kaydeden (comit) Michael Meeks

Get Labels.xcu out of configuration data.

Modify the file format, install separately into share/labels,
and parse it using xmlreader when needed.
Saves time on startup and reduces pointless configurarion size.
üst 8cefe14f
......@@ -13,6 +13,7 @@ $(eval $(call gb_Module_add_targets,extras,\
AllLangZip_autotextshare \
CustomTarget_autocorr \
Package_fonts \
Package_labels \
Package_newfiles \
Package_wordbook \
Zip_autocorr \
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Package_Package,extras_labels,$(SRCDIR)/extras/source/labels))
$(eval $(call gb_Package_add_file,extras_labels,pck/labels.xml,labels.xml))
# vim: set noet sw=4 ts=4:
This diff is collapsed.
......@@ -102,8 +102,6 @@ bool passesNegativeList(OUString const & url) {
{ RTL_CONSTASCII_STRINGPARAM(
"/officecfg/registry/data/org/openoffice/Office/"
"Accelerators.xcu") },
{ RTL_CONSTASCII_STRINGPARAM(
"/officecfg/registry/data/org/openoffice/Office/Labels.xcu") },
{ RTL_CONSTASCII_STRINGPARAM(
"/officecfg/registry/data/org/openoffice/Office/SFX.xcu") }
};
......
......@@ -36,7 +36,6 @@ $(eval $(call gb_Configuration_add_datas,registry,officecfg/registry/data,\
org/openoffice/Office/ExtensionManager.xcu \
org/openoffice/Office/Impress.xcu \
org/openoffice/Office/Jobs.xcu \
org/openoffice/Office/Labels.xcu \
org/openoffice/Office/Linguistic.xcu \
org/openoffice/Office/Logging.xcu \
org/openoffice/Office/Math.xcu \
......
......@@ -224,7 +224,6 @@ postprocess_FILES_main := \
$(postprocess_XCU)/Office/Histories.xcu \
$(postprocess_XCU)/Office/Impress.xcu \
$(postprocess_XCU)/Office/Jobs.xcu \
$(postprocess_XCU)/Office/Labels.xcu \
$(postprocess_XCU)/Office/Logging.xcu \
$(postprocess_XCU)/Office/Math.xcu \
$(postprocess_XCU)/Office/Paths.xcu \
......
......@@ -42,6 +42,7 @@ Module gid_Module_Root_Brand
gid_Brand_Dir_Share_Extensions,
gid_Brand_Dir_Share_Uno_Packages,
gid_Brand_Dir_Share_Uno_Packages_Cache,
gid_Brand_Dir_Share_Labels,
gid_Brand_Dir_Share_Registry,
gid_Brand_Dir_Share_Xdg);
Files = (gid_Brand_File_Bin_Crashreport,
......@@ -418,6 +419,11 @@ Directory gid_Brand_Dir_Share_Uno_Packages_Cache_Uno_Packages
Styles = (CREATE);
End
Directory gid_Brand_Dir_Share_Labels
ParentID = gid_Brand_Dir_Share;
DosName = "labels";
End
Directory gid_Brand_Dir_Share_Registry
ParentID = gid_Brand_Dir_Share;
DosName = "registry";
......
......@@ -625,6 +625,13 @@ End
#endif
File gid_File_Share_Labels_Xml
TXT_FILE_BODY;
Styles = (PACKED);
Dir = gid_Brand_Dir_Share_Labels;
Name = "labels.xml";
End
File gid_File_Share_Registry_Main_Xcd
TXT_FILE_BODY;
Styles = (PACKED, SCPZIP_REPLACE);
......
......@@ -536,6 +536,7 @@ Module gid_Module_Root_Files_6
gid_File_Mod_Text,
gid_File_Oo_Ldap_Xcd_Sample,
gid_File_Oo_Ad_Ldap_Xcd_Sample,
gid_File_Share_Labels_Xml,
gid_File_Share_Registry_Main_Xcd,
gid_File_Share_Registry_Forcedefault_Xcd,
gid_File_Pymailmerge,
......
......@@ -66,6 +66,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uwriter, \
utl \
vbahelper \
vcl \
xmlreader \
xo \
$(gb_UWINAPI) \
))
......
......@@ -68,6 +68,7 @@ $(eval $(call gb_Library_use_libraries,sw,\
utl \
vbahelper \
vcl \
xmlreader \
xo \
$(gb_UWINAPI) \
))
......
......@@ -153,13 +153,12 @@ SwLabDlg::SwLabDlg(Window* pParent, const SfxItemSet& rSet,
pRecs->insert( pRecs->begin(), pRec );
sal_uInt16 nLstGroup = 0;
const ::com::sun::star::uno::Sequence<rtl::OUString>& rMan = aLabelsCfg.GetManufacturers();
const rtl::OUString* pMan = rMan.getConstArray();
for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
const std::vector<rtl::OUString>& rMan = aLabelsCfg.GetManufacturers();
for(sal_uInt16 nMan = 0; nMan < rMan.size(); nMan++)
{
aMakes.push_back(pMan[nMan]);
if ( pMan[nMan] == aItem.aLstMake )
nLstGroup = (sal_uInt16) nMan;
aMakes.push_back(rMan[nMan]);
if ( rMan[nMan] == aItem.aLstMake )
nLstGroup = nMan;
}
if ( !aMakes.empty() )
......
......@@ -21,7 +21,9 @@
#include <labelcfg.hxx>
#include <labimp.hxx>
#include <comphelper/string.hxx>
#include <rtl/bootstrap.hxx>
#include <unotools/configpaths.hxx>
#include <xmlreader/xmlreader.hxx>
#include <unomid.h>
......@@ -29,25 +31,116 @@ using namespace utl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using ::rtl::OUString;
static inline void lcl_assertEndingItem(xmlreader::XmlReader& reader)
{
#if OSL_DEBUG_LEVEL > 0
int nsId;
xmlreader::Span name;
assert(reader.nextItem(xmlreader::XmlReader::TEXT_NONE, &name, &nsId)
== xmlreader::XmlReader::RESULT_END);
#else
(void)reader;
#endif
}
static inline OUString lcl_getValue(xmlreader::XmlReader& reader,
const xmlreader::Span& span)
{
int nsId;
xmlreader::Span name;
xmlreader::XmlReader::Result res;
res = reader.nextItem(xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
assert(res == xmlreader::XmlReader::RESULT_BEGIN && name.equals(span));
res = reader.nextItem(xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
assert(res == xmlreader::XmlReader::RESULT_TEXT);
(void) res; (void) span;
OUString sTmp = name.convertFromUtf8();
lcl_assertEndingItem(reader);
return sTmp;
}
SwLabelConfig::SwLabelConfig() :
ConfigItem("Office.Labels/Manufacturer")
{
aNodeNames = GetNodeNames(OUString());
OUString uri("$BRAND_BASE_DIR/share/labels/labels.xml");
rtl::Bootstrap::expandMacros(uri);
xmlreader::XmlReader reader(uri);
int nsId;
xmlreader::Span name;
xmlreader::XmlReader::Result res;
OUString sManufacturer;
OUString sName;
OUString sMeasure;
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("manufacturers")));
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
while (res != xmlreader::XmlReader::RESULT_END)
{
// Opening manufacturer
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("manufacturer")));
// Get the name
reader.nextAttribute(&nsId, &name);
assert(nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("name")));
sManufacturer = reader.getAttributeValue(false).convertFromUtf8();
for(;;) {
// Opening label or ending manufacturer
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
if (res == xmlreader::XmlReader::RESULT_END)
break;
assert(res == xmlreader::XmlReader::RESULT_BEGIN &&
name.equals(RTL_CONSTASCII_STRINGPARAM("label")));
// Get name value
sName = lcl_getValue(reader,
xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("name")));
// Get measure value
sMeasure = lcl_getValue(reader,
xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("measure")));
// Ending label mark
lcl_assertEndingItem(reader);
m_aLabels[sManufacturer][sName] = sMeasure;
}
// Get next manufacturer or end
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
};
res = reader.nextItem(
xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
assert(res == xmlreader::XmlReader::RESULT_DONE);
FillManufacturers();
}
SwLabelConfig::~SwLabelConfig()
{
}
void SwLabelConfig::Commit()
{
// the config item is not writable yet
}
// the config item is not writable ?:
void SwLabelConfig::Commit() {}
void SwLabelConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
void SwLabelConfig::FillManufacturers()
{
m_aManufacturers.clear();
for (std::map< OUString, std::map<OUString, OUString> >::iterator it =
m_aLabels.begin(); it != m_aLabels.end(); ++it)
m_aManufacturers.push_back( it->first );
const com::sun::star::uno::Sequence<rtl::OUString>& rMan = GetNodeNames(OUString());
const rtl::OUString* pMan = rMan.getConstArray();
for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
if (m_aLabels.find( pMan[nMan] ) == m_aLabels.end())
m_aManufacturers.push_back( pMan[nMan] );
}
static Sequence<OUString> lcl_CreatePropertyNames(const OUString& rPrefix)
{
Sequence<OUString> aProperties(2);
......@@ -60,27 +153,16 @@ static Sequence<OUString> lcl_CreatePropertyNames(const OUString& rPrefix)
return aProperties;
}
static SwLabRec* lcl_CreateSwLabRec(Sequence<Any>& rValues, const OUString& rManufacturer)
static SwLabRec* lcl_CreateSwLabRec(const OUString& rType, const OUString& rMeasure, const OUString& rManufacturer)
{
SwLabRec* pNewRec = new SwLabRec;
const Any* pValues = rValues.getConstArray();
OUString sTmp;
pNewRec->aMake = rManufacturer;
pNewRec->lPWidth = 0;
pNewRec->lPHeight = 0;
for(sal_Int32 nProp = 0; nProp < rValues.getLength(); nProp++)
{
if(pValues[nProp].hasValue())
{
switch(nProp)
{
case 0: pValues[nProp] >>= sTmp; pNewRec->aType = sTmp; break;
case 1:
{
pNewRec->aType = rType;
//all values are contained as colon-separated 1/100 mm values
//except for the continuous flag ('C'/'S')
pValues[nProp] >>= sTmp;
String sMeasure(sTmp);
String sMeasure(rMeasure);
sal_uInt16 nTokenCount = comphelper::string::getTokenCount(sMeasure, ';');
for(sal_uInt16 i = 0; i < nTokenCount; i++)
{
......@@ -101,11 +183,6 @@ static SwLabRec* lcl_CreateSwLabRec(Sequence<Any>& rValues, const OUString& rMan
case 10 : pNewRec->lPHeight = MM100_TO_TWIP(nVal); break;
}
}
}
break;
}
}
}
// lines added for compatibility with custom label defintions saved before patch 44516
if (pNewRec->lPWidth == 0 || pNewRec->lPHeight == 0)
{
......@@ -165,18 +242,39 @@ void SwLabelConfig::FillLabels(const OUString& rManufacturer, SwLabRecs& rLab
sPrefix += "/";
Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
Sequence<Any> aValues = GetProperties(aPropNames);
SwLabRec* pNewRec = lcl_CreateSwLabRec(aValues, rManufacturer);
rLabArr.push_back( pNewRec );
const Any* pValues = aValues.getConstArray();
OUString sType;
OUString sMeasure;
if (aValues.getLength() >= 1)
if(pValues[0].hasValue())
pValues[0] >>= sType;
if (aValues.getLength() >= 2)
if(pValues[1].hasValue())
pValues[1] >>= sMeasure;
// Remove default value if we have one from configuration
if(m_aLabels.find(rManufacturer) != m_aLabels.end())
m_aLabels[rManufacturer].erase(sType);
rLabArr.push_back( lcl_CreateSwLabRec(sType, sMeasure, rManufacturer) );
}
// Add default labels
if (m_aLabels.find(rManufacturer) == m_aLabels.end())
return;
for (std::map<OUString, OUString>::iterator it =
m_aLabels[rManufacturer].begin();
it != m_aLabels[rManufacturer].end(); ++it)
rLabArr.push_back( lcl_CreateSwLabRec(it->first, it->second, rManufacturer) );
}
sal_Bool SwLabelConfig::HasLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType)
{
const OUString* pNode = aNodeNames.getConstArray();
if (m_aLabels.find(rManufacturer) != m_aLabels.end())
if (m_aLabels[rManufacturer].find(rType) != m_aLabels[rManufacturer].end())
return true;
bool bFound = false;
for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
for (size_t nNode = 0; nNode < m_aManufacturers.size() && !bFound; nNode++)
{
if(pNode[nNode] == rManufacturer)
if (m_aManufacturers[nNode] == rManufacturer)
bFound = true;
}
if(bFound)
......@@ -219,11 +317,10 @@ static bool lcl_Exists(const OUString& rNode, const Sequence<OUString>& rLabels)
void SwLabelConfig::SaveLabel( const rtl::OUString& rManufacturer,
const rtl::OUString& rType, const SwLabRec& rRec)
{
const OUString* pNode = aNodeNames.getConstArray();
bool bFound = false;
for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
for (size_t nNode = 0; nNode < m_aManufacturers.size() && !bFound; nNode++)
{
if(pNode[nNode] == rManufacturer)
if (m_aManufacturers[nNode] == rManufacturer)
bFound = true;
}
if(!bFound)
......@@ -235,7 +332,7 @@ void SwLabelConfig::SaveLabel( const rtl::OUString& rManufacturer,
}
else
{
aNodeNames = GetNodeNames(OUString());
FillManufacturers();
}
}
......
......@@ -576,14 +576,11 @@ IMPL_LINK_NOARG(SwLabFmtPage, SaveHdl)
if(pSaveDlg->GetLabel(aItem))
{
bModified = false;
const Sequence<OUString>& rMan = GetParentSwLabDlg()->GetLabelsConfig().GetManufacturers();
const std::vector<OUString>& rMan = GetParentSwLabDlg()->GetLabelsConfig().GetManufacturers();
std::vector<rtl::OUString>& rMakes(GetParentSwLabDlg()->Makes());
if(rMakes.size() < (sal_uInt16)rMan.getLength())
if(rMakes.size() < rMan.size())
{
rMakes.clear();
const OUString* pMan = rMan.getConstArray();
for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
rMakes.push_back(pMan[nMan]);
rMakes = rMan;
}
aMakeFI.SetText(aItem.aMake);
aTypeFI.SetText(aItem.aType);
......@@ -618,10 +615,9 @@ SwSaveLabelDlg::SwSaveLabelDlg(SwLabFmtPage* pParent, SwLabRec& rRec) :
aTypeED.SetModifyHdl(aLk);
SwLabelConfig& rCfg = pLabPage->GetParentSwLabDlg()->GetLabelsConfig();
const Sequence<OUString>& rMan = rCfg.GetManufacturers();
const OUString* pMan = rMan.getConstArray();
for(sal_Int32 i = 0; i < rMan.getLength(); i++)
aMakeCB.InsertEntry(pMan[i]);
const std::vector<OUString>& rMan = rCfg.GetManufacturers();
for (sal_uInt16 i = 0; i < rMan.size(); i++)
aMakeCB.InsertEntry(rMan[i]);
}
IMPL_LINK_NOARG(SwSaveLabelDlg, OkHdl)
......
......@@ -22,14 +22,16 @@
#include <unotools/configitem.hxx>
#include "swdllapi.h"
#include <map>
#include <vector>
class SwLabRecs;
class SwLabRec;
class SW_DLLPUBLIC SwLabelConfig : public utl::ConfigItem
{
com::sun::star::uno::Sequence<rtl::OUString> aNodeNames;
SW_DLLPRIVATE com::sun::star::uno::Sequence<rtl::OUString> GetPropertyNames();
std::vector<rtl::OUString> m_aManufacturers;
std::map< OUString, std::map<OUString, OUString> > m_aLabels;
public:
SwLabelConfig();
......@@ -38,9 +40,9 @@ public:
virtual void Commit();
virtual void Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
void FillManufacturers();
void FillLabels(const rtl::OUString& rManufacturer, SwLabRecs& rLabArr);
const com::sun::star::uno::Sequence<rtl::OUString>&
GetManufacturers() const {return aNodeNames;}
const std::vector<rtl::OUString>& GetManufacturers() const {return m_aManufacturers;}
sal_Bool HasLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType);
void SaveLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment