Kaydet (Commit) aebf5bf2 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

fdo#52232 ConfigurationSet wrapper unusable for localized properties

The comphelper::ConfigurationSet wrapper, used by the automatically generated
headers to access the configuration data from C++, is based on
com.sun.star.configuration.ReadOnlyAccess/ReadWriteAcess that provide an all-
locales view of the configuration data, i.e., a localized property is represented as a UNO object implementing various container interfaces (to access the per-locale values) instead of a plain value.

Hence,

  xLeaveAccess->getByName(C2U("Label")) >>= sLeafLabel;

silently changed its meaning, now silently failing to extract a string and
leaving sLeafLabel empty, which in turn causes the labels of extension option
pages to disappear from the "Tools - Options..." dialog.

This partially reverts commit 161c3f17 "Some
more comphelper/configurationhelper clean up."

Change-Id: I584c682ea6a7c8b9444b34f1867cc553ad160802
üst ea968972
...@@ -138,6 +138,7 @@ struct LastPageSaver ...@@ -138,6 +138,7 @@ struct LastPageSaver
// class OfaTreeOptionsDialog -------------------------------------------- // class OfaTreeOptionsDialog --------------------------------------------
namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } } namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } }
namespace com { namespace sun { namespace star { namespace container { class XNameAccess; } } } }
namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } } } } namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } } } }
namespace com { namespace sun { namespace star { namespace awt { class XContainerWindowProvider; } } } } namespace com { namespace sun { namespace star { namespace awt { class XContainerWindowProvider; } } } }
...@@ -191,8 +192,12 @@ private: ...@@ -191,8 +192,12 @@ private:
com::sun::star::lang::XMultiServiceFactory >& xMFac, com::sun::star::lang::XMultiServiceFactory >& xMFac,
const com::sun::star::uno::Reference< const com::sun::star::uno::Reference<
com::sun::star::frame::XFrame >& xFrame ); com::sun::star::frame::XFrame >& xFrame );
Module* LoadModule( const rtl::OUString& rModuleIdentifier ); Module* LoadModule( const rtl::OUString& rModuleIdentifier,
void LoadNodes( Module* pModule, const com::sun::star::uno::Reference<
com::sun::star::container::XNameAccess >& xRoot );
void LoadNodes( const com::sun::star::uno::Reference<
com::sun::star::container::XNameAccess >& xRoot,
Module* pModule,
const rtl::OUString& rExtensionId, const rtl::OUString& rExtensionId,
VectorOfNodes& rOutNodeList ); VectorOfNodes& rOutNodeList );
void InsertNodes( const VectorOfNodes& rNodeList ); void InsertNodes( const VectorOfNodes& rNodeList );
......
...@@ -67,11 +67,11 @@ ...@@ -67,11 +67,11 @@
#include <com/sun/star/frame/XModuleManager.hpp> #include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/loader/CannotActivateFactoryException.hpp> #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
#include <com/sun/star/util/XMacroExpander.hpp> #include <com/sun/star/util/XMacroExpander.hpp>
#include <comphelper/configurationhelper.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <editeng/optitems.hxx> #include <editeng/optitems.hxx>
#include <editeng/unolingu.hxx> #include <editeng/unolingu.hxx>
#include <linguistic/misc.hxx> #include <linguistic/misc.hxx>
#include <officecfg/Office/OptionsDialog.hxx>
#include <osl/module.hxx> #include <osl/module.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <rtl/bootstrap.hxx> #include <rtl/bootstrap.hxx>
...@@ -1927,12 +1927,18 @@ void OfaTreeOptionsDialog::LoadExtensionOptions( const rtl::OUString& rExtension ...@@ -1927,12 +1927,18 @@ void OfaTreeOptionsDialog::LoadExtensionOptions( const rtl::OUString& rExtension
{ {
Module* pModule = NULL; Module* pModule = NULL;
Reference< XMultiServiceFactory > xMSFac = comphelper::getProcessServiceFactory(); Reference< XMultiServiceFactory > xMSFac = comphelper::getProcessServiceFactory();
// open optionsdialog.xcu
Reference< XNameAccess > xRoot(
::comphelper::ConfigurationHelper::openConfig(
xMSFac, C2U("org.openoffice.Office.OptionsDialog"),
::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
DBG_ASSERT( xRoot.is(), "OfaTreeOptionsDialog::LoadExtensionOptions(): no config" );
// when called by Tools - Options then load nodes of active module // when called by Tools - Options then load nodes of active module
if ( rExtensionId.isEmpty() ) if ( rExtensionId.isEmpty() )
pModule = LoadModule( GetModuleIdentifier( xMSFac, Reference< XFrame >() ) ); pModule = LoadModule( GetModuleIdentifier( xMSFac, Reference< XFrame >() ), xRoot );
VectorOfNodes aNodeList; VectorOfNodes aNodeList;
LoadNodes( pModule, rExtensionId, aNodeList ); LoadNodes( xRoot, pModule, rExtensionId, aNodeList );
InsertNodes( aNodeList ); InsertNodes( aNodeList );
} }
...@@ -1971,58 +1977,64 @@ rtl::OUString OfaTreeOptionsDialog::GetModuleIdentifier( ...@@ -1971,58 +1977,64 @@ rtl::OUString OfaTreeOptionsDialog::GetModuleIdentifier(
} }
Module* OfaTreeOptionsDialog::LoadModule( Module* OfaTreeOptionsDialog::LoadModule(
const rtl::OUString& rModuleIdentifier ) const rtl::OUString& rModuleIdentifier, const Reference< XNameAccess >& xRoot )
{ {
Module* pModule = NULL; Module* pModule = NULL;
Reference< XNameAccess > xSet( Reference< XNameAccess > xSet;
officecfg::Office::OptionsDialog::Modules::get());
Sequence< rtl::OUString > seqNames = xSet->getElementNames(); if ( xRoot->hasByName( C2U("Modules") ) )
for ( int i = 0; i < seqNames.getLength(); ++i )
{ {
rtl::OUString sModule( seqNames[i] ); xRoot->getByName( C2U("Modules") ) >>= xSet;
if ( rModuleIdentifier == sModule ) if ( xSet.is() )
{ {
// current active module found Sequence< rtl::OUString > seqNames = xSet->getElementNames();
pModule = new Module( sModule ); for ( int i = 0; i < seqNames.getLength(); ++i )
pModule->m_bActive = true;
Reference< XNameAccess > xModAccess;
xSet->getByName( seqNames[i] ) >>= xModAccess;
if ( xModAccess.is() )
{ {
// load the nodes of this module rtl::OUString sModule( seqNames[i] );
Reference< XNameAccess > xNodeAccess; if ( rModuleIdentifier == sModule )
xModAccess->getByName( C2U("Nodes") ) >>= xNodeAccess;
if ( xNodeAccess.is() )
{ {
Sequence< rtl::OUString > xTemp = xNodeAccess->getElementNames(); // current active module found
Reference< XNameAccess > xAccess; pModule = new Module( sModule );
sal_Int32 nIndex = -1; pModule->m_bActive = true;
for ( int x = 0; x < xTemp.getLength(); ++x )
Reference< XNameAccess > xModAccess;
xSet->getByName( seqNames[i] ) >>= xModAccess;
if ( xModAccess.is() )
{ {
xNodeAccess->getByName( xTemp[x] ) >>= xAccess; // load the nodes of this module
if ( xAccess.is() ) Reference< XNameAccess > xNodeAccess;
xModAccess->getByName( C2U("Nodes") ) >>= xNodeAccess;
if ( xNodeAccess.is() )
{ {
xAccess->getByName( C2U("Index") ) >>= nIndex; Sequence< rtl::OUString > xTemp = xNodeAccess->getElementNames();
if ( nIndex < 0 ) Reference< XNameAccess > xAccess;
// append nodes with index < 0 sal_Int32 nIndex = -1;
pModule->m_aNodeList.push_back( for ( int x = 0; x < xTemp.getLength(); ++x )
new OrderedEntry( nIndex, xTemp[x] ) );
else
{ {
// search position of the node xNodeAccess->getByName( xTemp[x] ) >>= xAccess;
sal_uInt32 y = 0; if ( xAccess.is() )
for ( ; y < pModule->m_aNodeList.size(); ++y )
{ {
sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex; xAccess->getByName( C2U("Index") ) >>= nIndex;
if ( nNodeIdx < 0 || nNodeIdx > nIndex ) if ( nIndex < 0 )
break; // append nodes with index < 0
pModule->m_aNodeList.push_back(
new OrderedEntry( nIndex, xTemp[x] ) );
else
{
// search position of the node
sal_uInt32 y = 0;
for ( ; y < pModule->m_aNodeList.size(); ++y )
{
sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex;
if ( nNodeIdx < 0 || nNodeIdx > nIndex )
break;
}
// and insert the node on this position
pModule->m_aNodeList.insert(
pModule->m_aNodeList.begin() + y,
new OrderedEntry( nIndex, xTemp[x] ) );
}
} }
// and insert the node on this position
pModule->m_aNodeList.insert(
pModule->m_aNodeList.begin() + y,
new OrderedEntry( nIndex, xTemp[x] ) );
} }
} }
} }
...@@ -2034,145 +2046,151 @@ Module* OfaTreeOptionsDialog::LoadModule( ...@@ -2034,145 +2046,151 @@ Module* OfaTreeOptionsDialog::LoadModule(
} }
void OfaTreeOptionsDialog::LoadNodes( void OfaTreeOptionsDialog::LoadNodes(
Module* pModule, const rtl::OUString& rExtensionId, const Reference< XNameAccess >& xRoot, Module* pModule,
VectorOfNodes& rOutNodeList ) const rtl::OUString& rExtensionId, VectorOfNodes& rOutNodeList )
{ {
Reference< XNameAccess > xSet( Reference< XNameAccess > xSet;
officecfg::Office::OptionsDialog::Nodes::get()); if ( xRoot->hasByName( C2U("Nodes") ) )
VectorOfNodes aNodeList;
Sequence< rtl::OUString > seqNames = xSet->getElementNames();
for ( int i = 0; i < seqNames.getLength(); ++i )
{ {
String sGroupName( seqNames[i] ); xRoot->getByName( C2U("Nodes") ) >>= xSet;
Reference< XNameAccess > xNodeAccess; if ( xSet.is() )
xSet->getByName( seqNames[i] ) >>= xNodeAccess;
if ( xNodeAccess.is() )
{ {
rtl::OUString sNodeId, sLabel, sPageURL, sGroupId; VectorOfNodes aNodeList;
bool bAllModules = false; Sequence< rtl::OUString > seqNames = xSet->getElementNames();
sal_Int32 nGroupIndex = 0;
sNodeId = seqNames[i];
xNodeAccess->getByName( C2U("Label") ) >>= sLabel;
xNodeAccess->getByName( C2U("OptionsPage") ) >>= sPageURL;
xNodeAccess->getByName( C2U("AllModules") ) >>= bAllModules;
xNodeAccess->getByName( C2U("GroupId") ) >>= sGroupId;
xNodeAccess->getByName( C2U("GroupIndex") ) >>= nGroupIndex;
if ( sLabel.isEmpty() ) for ( int i = 0; i < seqNames.getLength(); ++i )
sLabel = sGroupName;
String sTemp = getGroupName( sLabel, !rExtensionId.isEmpty() );
if ( sTemp.Len() > 0 )
sLabel = sTemp;
OptionsNode* pNode =
new OptionsNode( sNodeId, sLabel, sPageURL, bAllModules, sGroupId, nGroupIndex );
if ( rExtensionId.isEmpty() && !isNodeActive( pNode, pModule ) )
{ {
delete pNode; String sGroupName( seqNames[i] );
continue; Reference< XNameAccess > xNodeAccess;
} xSet->getByName( seqNames[i] ) >>= xNodeAccess;
Reference< XNameAccess > xLeavesSet; if ( xNodeAccess.is() )
xNodeAccess->getByName( C2U( "Leaves" ) ) >>= xLeavesSet;
if ( xLeavesSet.is() )
{
Sequence< rtl::OUString > seqLeaves = xLeavesSet->getElementNames();
for ( int j = 0; j < seqLeaves.getLength(); ++j )
{ {
Reference< XNameAccess > xLeaveAccess; rtl::OUString sNodeId, sLabel, sPageURL, sGroupId;
xLeavesSet->getByName( seqLeaves[j] ) >>= xLeaveAccess; bool bAllModules = false;
sal_Int32 nGroupIndex = 0;
if ( xLeaveAccess.is() )
sNodeId = seqNames[i];
xNodeAccess->getByName( C2U("Label") ) >>= sLabel;
xNodeAccess->getByName( C2U("OptionsPage") ) >>= sPageURL;
xNodeAccess->getByName( C2U("AllModules") ) >>= bAllModules;
xNodeAccess->getByName( C2U("GroupId") ) >>= sGroupId;
xNodeAccess->getByName( C2U("GroupIndex") ) >>= nGroupIndex;
if ( sLabel.isEmpty() )
sLabel = sGroupName;
String sTemp = getGroupName( sLabel, !rExtensionId.isEmpty() );
if ( sTemp.Len() > 0 )
sLabel = sTemp;
OptionsNode* pNode =
new OptionsNode( sNodeId, sLabel, sPageURL, bAllModules, sGroupId, nGroupIndex );
if ( rExtensionId.isEmpty() && !isNodeActive( pNode, pModule ) )
{ {
rtl::OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId; delete pNode;
sal_Int32 nLeafGrpIdx = 0; continue;
}
xLeaveAccess->getByName( C2U("Id") ) >>= sId;
xLeaveAccess->getByName( C2U("Label") ) >>= sLeafLabel;
xLeaveAccess->getByName( C2U("OptionsPage") ) >>= sLeafURL;
xLeaveAccess->getByName( C2U("EventHandlerService") ) >>= sEventHdl;
xLeaveAccess->getByName( C2U("GroupId") ) >>= sLeafGrpId;
xLeaveAccess->getByName( C2U("GroupIndex") ) >>= nLeafGrpIdx;
if ( rExtensionId.isEmpty() || sId == rExtensionId ) Reference< XNameAccess > xLeavesSet;
xNodeAccess->getByName( C2U( "Leaves" ) ) >>= xLeavesSet;
if ( xLeavesSet.is() )
{
Sequence< rtl::OUString > seqLeaves = xLeavesSet->getElementNames();
for ( int j = 0; j < seqLeaves.getLength(); ++j )
{ {
OptionsLeaf* pLeaf = new OptionsLeaf( Reference< XNameAccess > xLeaveAccess;
sId, sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx ); xLeavesSet->getByName( seqLeaves[j] ) >>= xLeaveAccess;
if ( !sLeafGrpId.isEmpty() ) if ( xLeaveAccess.is() )
{ {
bool bAlreadyOpened = false; rtl::OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId;
if ( pNode->m_aGroupedLeaves.size() > 0 ) sal_Int32 nLeafGrpIdx = 0;
xLeaveAccess->getByName( C2U("Id") ) >>= sId;
xLeaveAccess->getByName( C2U("Label") ) >>= sLeafLabel;
xLeaveAccess->getByName( C2U("OptionsPage") ) >>= sLeafURL;
xLeaveAccess->getByName( C2U("EventHandlerService") ) >>= sEventHdl;
xLeaveAccess->getByName( C2U("GroupId") ) >>= sLeafGrpId;
xLeaveAccess->getByName( C2U("GroupIndex") ) >>= nLeafGrpIdx;
if ( rExtensionId.isEmpty() || sId == rExtensionId )
{ {
for ( sal_uInt32 k = 0; OptionsLeaf* pLeaf = new OptionsLeaf(
k < pNode->m_aGroupedLeaves.size(); ++k ) sId, sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx );
if ( !sLeafGrpId.isEmpty() )
{ {
if ( pNode->m_aGroupedLeaves[k].size() > 0 && bool bAlreadyOpened = false;
pNode->m_aGroupedLeaves[k][0]->m_sGroupId if ( pNode->m_aGroupedLeaves.size() > 0 )
== sLeafGrpId )
{ {
sal_uInt32 l = 0; for ( sal_uInt32 k = 0;
for ( ; l < pNode->m_aGroupedLeaves[k].size(); ++l ) k < pNode->m_aGroupedLeaves.size(); ++k )
{ {
if ( pNode->m_aGroupedLeaves[k][l]-> if ( pNode->m_aGroupedLeaves[k].size() > 0 &&
m_nGroupIndex >= nLeafGrpIdx ) pNode->m_aGroupedLeaves[k][0]->m_sGroupId
== sLeafGrpId )
{
sal_uInt32 l = 0;
for ( ; l < pNode->m_aGroupedLeaves[k].size(); ++l )
{
if ( pNode->m_aGroupedLeaves[k][l]->
m_nGroupIndex >= nLeafGrpIdx )
break;
}
pNode->m_aGroupedLeaves[k].insert(
pNode->m_aGroupedLeaves[k].begin() + l, pLeaf );
bAlreadyOpened = true;
break; break;
}
} }
pNode->m_aGroupedLeaves[k].insert( }
pNode->m_aGroupedLeaves[k].begin() + l, pLeaf ); if ( !bAlreadyOpened )
bAlreadyOpened = true; {
break; VectorOfLeaves aGroupedLeaves;
aGroupedLeaves.push_back( pLeaf );
pNode->m_aGroupedLeaves.push_back( aGroupedLeaves );
} }
} }
} else
if ( !bAlreadyOpened ) pNode->m_aLeaves.push_back(
{ new OptionsLeaf(
VectorOfLeaves aGroupedLeaves; sId, sLeafLabel, sLeafURL,
aGroupedLeaves.push_back( pLeaf ); sEventHdl, sLeafGrpId, nLeafGrpIdx ) );
pNode->m_aGroupedLeaves.push_back( aGroupedLeaves );
} }
} }
else
pNode->m_aLeaves.push_back(
new OptionsLeaf(
sId, sLeafLabel, sLeafURL,
sEventHdl, sLeafGrpId, nLeafGrpIdx ) );
} }
} }
// do not insert nodes without leaves
if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
{
pModule ? aNodeList.push_back( pNode ) : rOutNodeList.push_back( pNode );
}
} }
} }
// do not insert nodes without leaves if ( pModule && aNodeList.size() > 0 )
if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
{ {
pModule ? aNodeList.push_back( pNode ) : rOutNodeList.push_back( pNode ); sal_uInt32 i = 0, j = 0;
} for ( ; i < pModule->m_aNodeList.size(); ++i )
}
}
if ( pModule && aNodeList.size() > 0 )
{
sal_uInt32 i = 0, j = 0;
for ( ; i < pModule->m_aNodeList.size(); ++i )
{
rtl::OUString sNodeId = pModule->m_aNodeList[i]->m_sId;
for ( j = 0; j < aNodeList.size(); ++j )
{
OptionsNode* pNode = aNodeList[j];
if ( pNode->m_sId == sNodeId )
{ {
rOutNodeList.push_back( pNode ); rtl::OUString sNodeId = pModule->m_aNodeList[i]->m_sId;
aNodeList.erase( aNodeList.begin() + j ); for ( j = 0; j < aNodeList.size(); ++j )
break; {
OptionsNode* pNode = aNodeList[j];
if ( pNode->m_sId == sNodeId )
{
rOutNodeList.push_back( pNode );
aNodeList.erase( aNodeList.begin() + j );
break;
}
}
} }
for ( i = 0; i < aNodeList.size(); ++i )
rOutNodeList.push_back( aNodeList[i] );
} }
} }
for ( i = 0; i < aNodeList.size(); ++i )
rOutNodeList.push_back( aNodeList[i] );
} }
} }
......
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