14 #include <com/sun/star/configuration/theDefaultProvider.hpp>
15 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
16 #include <com/sun/star/beans/NamedValue.hpp>
17 #include <com/sun/star/container/XNameAccess.hpp>
18 #include <com/sun/star/container/XNameReplace.hpp>
19 #include <com/sun/star/container/XHierarchicalName.hpp>
20 #include <com/sun/star/util/XChangesBatch.hpp>
21 #include <com/sun/star/util/SearchFlags.hpp>
22 #include <com/sun/star/util/SearchAlgorithms2.hpp>
23 #include <rtl/ustrbuf.hxx>
37 #define SHORT_LEN_LIMIT 7
38 #define LONG_LEN_LIMIT 11
39 #define HYPER_LEN_LIMIT 20
47 Prop_Impl(
const OUString& sName,
const OUString& sProperty,
const Any& aValue )
49 , Property( sProperty )
57 OUString sPropertyPath;
61 explicit UserData( OUString
const & rPropertyPath )
62 : bIsPropertyPath( true )
63 , sPropertyPath(rPropertyPath)
68 : bIsPropertyPath( false )
70 , aXNameAccess( rXNameAccess )
77 bool bNonSpace = rKeyEvent.GetKeyCode().GetCode() !=
KEY_SPACE;
78 if (m_bNumericOnly && bNonSpace )
81 sal_uInt16 nGroup = rKeyCode.
GetGroup();
82 sal_uInt16 nKey = rKeyCode.
GetCode();
121 if ( !bValid && ( rKeyCode.
IsMod1() && (
133 : GenericDialogController(pParent,
"cui/ui/aboutconfigdialog.ui",
"AboutConfig")
134 , m_xResetBtn(m_xBuilder->weld_button(
"reset"))
135 , m_xEditBtn(m_xBuilder->weld_button(
"edit"))
136 , m_xSearchBtn(m_xBuilder->weld_button(
"searchButton"))
137 , m_xSearchEdit(m_xBuilder->weld_entry(
"searchEntry"))
138 , m_xPrefBox(m_xBuilder->weld_tree_view(
"preferences"))
139 , m_xScratchIter(m_xPrefBox->make_iterator())
140 , m_vectorOfModified()
156 util::SearchFlags::REG_NOT_ENDOFLINE);
158 float fWidth =
m_xPrefBox->get_approximate_digit_width();
159 std::vector<int> aWidths;
160 aWidths.push_back(fWidth * 65);
161 aWidths.push_back(fWidth * 20);
162 aWidths.push_back(fWidth * 8);
170 m_xPrefBox->make_sorted();
174 bool bSortAtoZ = m_xPrefBox->get_sort_order();
177 if (nColumn == m_xPrefBox->get_sort_column())
179 bSortAtoZ = !bSortAtoZ;
180 m_xPrefBox->set_sort_order(bSortAtoZ);
184 int nOldSortColumn = m_xPrefBox->get_sort_column();
185 if (nOldSortColumn != -1)
187 m_xPrefBox->set_sort_column(nColumn);
202 const OUString& rType,
const OUString& rValue,
const weld::TreeIter* pParentEntry,
203 bool bInsertToPrefBox)
206 if (bInsertToPrefBox)
208 OUString
sId(OUString::number(reinterpret_cast<sal_Int64>(
m_vectorUserData.back().get())));
238 FillItems( xConfigAccess,
nullptr, 0,
true );
246 std::vector< std::shared_ptr< Prop_Impl > >::iterator pIter;
252 xNameReplace->replaceByName( (*pIter)->Property, (*pIter)->Value );
255 xChangesBatch->commitChanges();
260 int lineage,
bool bLoadAll)
263 xNameAccess, uno::UNO_QUERY_THROW )->getHierarchicalName();
264 const uno::Sequence< OUString > seqItems = xNameAccess->getElementNames();
265 for(
const OUString& item : seqItems )
267 Any aNode = xNameAccess->getByName( item );
269 bool bNotLeaf =
false;
274 xNextNameAccess.set(aNode, uno::UNO_QUERY);
275 bNotLeaf = xNextNameAccess.is();
285 FillItems(xNextNameAccess,
nullptr, lineage + 1,
true);
289 m_vectorUserData.push_back(std::make_unique<UserData>(xNextNameAccess, lineage + 1));
290 OUString
sId(OUString::number(reinterpret_cast<sal_Int64>(
m_vectorUserData.back().get())));
302 OUString sPropertyName = item;
304 [&sPath, &sPropertyName](
const prefBoxEntry& rEntry) ->
bool
306 return rEntry.pUserData->sPropertyPath == sPath
307 && rEntry.sStatus == sPropertyName;
311 OUString
sType = aNode.getValueTypeName();
312 OUStringBuffer sValue;
318 switch( aNode.getValueType().getTypeClass() )
320 case css::uno::TypeClass_VOID:
323 case css::uno::TypeClass_BOOLEAN:
324 sValue = OUString::boolean( aNode.get<
bool>() );
327 case css::uno::TypeClass_SHORT:
328 case css::uno::TypeClass_LONG:
329 case css::uno::TypeClass_HYPER:
330 sValue = OUString::number( aNode.get<sal_Int64>() );
333 case css::uno::TypeClass_DOUBLE:
334 sValue = OUString::number( aNode.get<
double>() );
337 case css::uno::TypeClass_STRING:
338 sValue = aNode.get<OUString>();
341 case css::uno::TypeClass_SEQUENCE:
342 if( sType ==
"[]boolean" )
344 uno::Sequence<sal_Bool> seq = aNode.get< uno::Sequence<sal_Bool> >();
345 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
351 sValue.append(OUString::boolean( seq[j] ));
354 else if( sType ==
"[]byte" )
356 uno::Sequence<sal_Int8> seq = aNode.get< uno::Sequence<sal_Int8> >();
359 OUString s = OUString::number(
360 static_cast<sal_uInt8>(j), 16 );
361 if( s.getLength() == 1 )
365 sValue.append(s.toAsciiUpperCase());
368 else if( sType ==
"[][]byte" )
370 uno::Sequence< uno::Sequence<sal_Int8> > seq = aNode.get< uno::Sequence< uno::Sequence<sal_Int8> > >();
371 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
379 OUString s = OUString::number(
380 static_cast<sal_uInt8>(k), 16 );
381 if( s.getLength() == 1 )
385 sValue.append(s.toAsciiUpperCase());
389 else if( sType ==
"[]short" )
391 uno::Sequence<sal_Int16> seq = aNode.get< uno::Sequence<sal_Int16> >();
392 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
398 sValue.append(OUString::number( seq[j] ));
401 else if( sType ==
"[]long" )
403 uno::Sequence<sal_Int32> seq = aNode.get< uno::Sequence<sal_Int32> >();
404 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
410 sValue.append(OUString::number( seq[j] ));
413 else if( sType ==
"[]hyper" )
415 uno::Sequence<sal_Int64> seq = aNode.get< uno::Sequence<sal_Int64> >();
416 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
422 sValue.append(OUString::number( seq[j] ));
425 else if( sType ==
"[]double" )
427 uno::Sequence<double> seq = aNode.get< uno::Sequence<double> >();
428 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
434 sValue.append(OUString::number( seq[j] ));
437 else if( sType ==
"[]string" )
439 uno::Sequence<OUString> seq = aNode.get< uno::Sequence<OUString> >();
440 for( sal_Int32 j = 0; j != seq.getLength(); ++j )
446 sValue.append(seq[j]);
453 "path \"" << sPath <<
"\" member " << item
454 <<
" of unsupported type " << sType);
461 "path \"" << sPath <<
"\" member " << item
462 <<
" of unsupported type " << sType);
469 for(
int j = 1; j < lineage; ++j)
470 index = sPath.indexOf(
"/", index + 1);
472 InsertEntry(sPath, sPath.copy(index+1), item,
sType, sValue.makeStringAndClear(), pParentEntry, !bLoadAll);
481 uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
482 css::configuration::theDefaultProvider::get( xContext ) );
484 beans::NamedValue aProperty;
485 aProperty.Name =
"nodepath";
486 aProperty.Value <<= sNodePath;
488 uno::Sequence< uno::Any > aArgumentList( 1 );
489 aArgumentList[0] <<= aProperty;
491 OUString sAccessString;
494 sAccessString =
"com.sun.star.configuration.ConfigurationUpdateAccess";
496 sAccessString =
"com.sun.star.configuration.ConfigurationAccess";
498 uno::Reference< container::XNameAccess > xNameAccess(
499 xConfigProvider->createInstanceWithArguments(
500 sAccessString, aArgumentList ),
501 uno::UNO_QUERY_THROW );
508 bool isModifiedBefore =
false;
512 if( rProp->Name == nInd->Name && rProp->Property == nInd->Property )
517 isModifiedBefore =
true;
522 if( !isModifiedBefore )
523 m_vectorOfModified.push_back( rProp );
529 std::vector<OUString> tempVector;
534 OUString word = rCommaSepString.getToken(0,
u',', index);
537 tempVector.push_back(word);
538 }
while( index >= 0 );
543 const OUString& rValue,
545 : GenericDialogController(pWindow,
"cui/ui/aboutconfigvaluedialog.ui",
"AboutConfigValueDialog")
546 , m_bNumericOnly(limit != 0)
547 , m_xEDValue(m_xBuilder->weld_entry(
"valuebox"))
566 StandardHdl_Impl(*m_xEditBtn);
572 if (!m_xPrefBox->get_selected(m_xScratchIter.get()))
575 UserData *pUserData =
reinterpret_cast<UserData*
>(m_xPrefBox->get_id(*m_xScratchIter).toInt64());
576 if (!(pUserData && pUserData->bIsPropertyPath))
580 OUString sPropertyName = m_xPrefBox->get_text(*m_xScratchIter, 1);
581 OUString sPropertyType = m_xPrefBox->get_text(*m_xScratchIter, 2);
582 OUString sPropertyValue = m_xPrefBox->get_text(*m_xScratchIter, 3);
584 auto pProperty = std::make_shared<Prop_Impl>( pUserData->sPropertyPath, sPropertyName,
Any( sPropertyValue ) );
585 bool bSaveChanges =
false;
587 bool bOpenDialog =
true;
588 OUString sDialogValue;
590 if( sPropertyType ==
"boolean" )
593 if( sPropertyValue ==
"true" )
595 sDialogValue =
"false";
600 sDialogValue =
"true";
604 pProperty->Value <<= bValue;
608 else if ( sPropertyType ==
"void" )
614 sDialogValue = sPropertyValue;
624 if( sPropertyType ==
"short" )
626 else if( sPropertyType ==
"long" )
628 else if( sPropertyType ==
"hyper" )
633 if (aValueDialog.run() ==
RET_OK )
635 OUString sNewValue = aValueDialog.
getValue();
637 if ( sPropertyType ==
"short")
640 sal_Int32 nNumb = sNewValue.toInt32();
644 throw uno::Exception(
"out of range short",
nullptr);
645 nShort =
static_cast<sal_Int16
>(nNumb);
646 pProperty->Value <<= nShort;
648 else if( sPropertyType ==
"long" )
650 sal_Int32 nLong = sNewValue.toInt32();
651 if( nLong==0 && sNewValue.getLength()!=1)
652 throw uno::Exception(
"out of range long",
nullptr);
653 pProperty->Value <<= nLong;
655 else if( sPropertyType ==
"hyper")
657 sal_Int64 nHyper = sNewValue.toInt64();
658 if( nHyper==0 && sNewValue.getLength()!=1)
659 throw uno::Exception(
"out of range hyper",
nullptr);
660 pProperty->Value <<= nHyper;
662 else if( sPropertyType ==
"double")
664 double nDoub = sNewValue.toDouble();
665 if( nDoub ==0 && sNewValue.getLength()!=1)
666 throw uno::Exception(
"out of range double",
nullptr);
667 pProperty->Value <<= nDoub;
669 else if( sPropertyType ==
"float")
671 float nFloat = sNewValue.toFloat();
672 if( nFloat ==0 && sNewValue.getLength()!=1)
673 throw uno::Exception(
"out of range float",
nullptr);
674 pProperty->Value <<= nFloat;
676 else if( sPropertyType ==
"string" )
678 pProperty->Value <<= sNewValue;
680 else if( sPropertyType ==
"[]short" )
684 std::vector< OUString > seqStr = commaStringToSequence( sNewValue );
687 uno::Sequence< sal_Int16 > seqShort( seqStr.size() );
689 for(
size_t i = 0;
i < seqStr.size(); ++
i )
691 seqShort[
i] =
static_cast<sal_Int16
>(seqStr[
i].toInt32());
693 pProperty->Value <<= seqShort;
695 else if( sPropertyType ==
"[]long" )
697 std::vector< OUString > seqStrLong = commaStringToSequence( sNewValue );
699 uno::Sequence< sal_Int32 > seqLong( seqStrLong.size() );
700 for(
size_t i = 0;
i < seqStrLong.size(); ++
i )
702 seqLong[
i] = seqStrLong[
i].toInt32();
704 pProperty->Value <<= seqLong;
706 else if( sPropertyType ==
"[]hyper" )
708 std::vector< OUString > seqStrHyper = commaStringToSequence( sNewValue );
709 uno::Sequence< sal_Int64 > seqHyper( seqStrHyper.size() );
710 for(
size_t i = 0;
i < seqStrHyper.size(); ++
i )
712 seqHyper[
i] = seqStrHyper[
i].toInt64();
714 pProperty->Value <<= seqHyper;
716 else if( sPropertyType ==
"[]double" )
718 std::vector< OUString > seqStrDoub = commaStringToSequence( sNewValue );
719 uno::Sequence< double > seqDoub( seqStrDoub.size() );
720 for(
size_t i = 0;
i < seqStrDoub.size(); ++
i )
722 seqDoub[
i] = seqStrDoub[
i].toDouble();
724 pProperty->Value <<= seqDoub;
726 else if( sPropertyType ==
"[]float" )
728 std::vector< OUString > seqStrFloat = commaStringToSequence( sNewValue );
729 uno::Sequence< sal_Int16 > seqFloat( seqStrFloat.size() );
730 for(
size_t i = 0;
i < seqStrFloat.size(); ++
i )
732 seqFloat[
i] = seqStrFloat[
i].toFloat();
734 pProperty->Value <<= seqFloat;
736 else if( sPropertyType ==
"[]string" )
741 throw uno::Exception(
"unknown property type " + sPropertyType,
nullptr);
743 sDialogValue = sNewValue;
749 AddToModifiedVector( pProperty );
752 m_xPrefBox->set_text(*m_xScratchIter, sDialogValue, 3);
754 auto it = std::find_if(m_prefBoxEntries.begin(), m_prefBoxEntries.end(),
755 [&pUserData, &sPropertyName](
const prefBoxEntry& rEntry) ->
bool
757 return rEntry.pUserData->sPropertyPath == pUserData->sPropertyPath
758 && rEntry.sStatus == sPropertyName;
761 if (it != m_prefBoxEntries.end())
763 it->sValue = sDialogValue;
765 auto modifiedIt = std::find_if(
766 m_modifiedPrefBoxEntries.begin(), m_modifiedPrefBoxEntries.end(),
767 [&pUserData, &sPropertyName](
const prefBoxEntry& rEntry) ->
bool
769 return rEntry.pUserData->sPropertyPath == pUserData->sPropertyPath
770 && rEntry.sStatus == sPropertyName;
774 if (modifiedIt != m_modifiedPrefBoxEntries.end())
776 modifiedIt->sValue = sDialogValue;
780 m_modifiedPrefBoxEntries.push_back(*it);
785 catch( uno::Exception& )
796 m_xPrefBox->freeze();
799 m_xPrefBox->make_unsorted();
801 if (m_xSearchEdit->get_text().isEmpty())
805 FillItems( xConfigAccess );
809 m_options.searchString = m_xSearchEdit->get_text();
811 for (
auto const& it : m_prefBoxEntries)
813 sal_Int32 endPos, startPos = 0;
815 for(
size_t i = 0;
i < 5; ++
i)
820 scrTxt = it.pUserData->sPropertyPath;
830 endPos = scrTxt.getLength();
842 m_xPrefBox->make_sorted();
845 m_xPrefBox->expand_row(rEntry);
853 OUString sPathWithProperty = rEntry.
pUserData->sPropertyPath;
854 sal_Int32
index = sPathWithProperty.lastIndexOf(rEntry.
sProp);
855 OUString sPath = sPathWithProperty.copy(0, index);
857 std::unique_ptr<weld::TreeIter> xParentEntry(
m_xPrefBox->make_iterator());
858 std::unique_ptr<weld::TreeIter> xGrandParentEntry;
862 int prevIndex = index;
863 index = sPath.indexOf(
"/", index+1);
867 OUString
sId(OUString::number(reinterpret_cast<sal_Int64>(rEntry.
pUserData)));
874 OUString sParentName = sPath.copy(prevIndex+1, index - prevIndex - 1);
876 bool hasEntry =
false;
879 if (!xGrandParentEntry)
880 bStartOk =
m_xPrefBox->get_iter_first(*xParentEntry);
883 m_xPrefBox->copy_iterator(*xGrandParentEntry, *xParentEntry);
884 bStartOk =
m_xPrefBox->iter_children(*xParentEntry);
891 if (
m_xPrefBox->get_text(*xParentEntry, 0) == sParentName)
896 }
while (
m_xPrefBox->iter_next_sibling(*xParentEntry));
901 m_xPrefBox->insert(xGrandParentEntry.get(), -1, &sParentName,
nullptr,
nullptr,
nullptr,
false, xParentEntry.get());
908 xGrandParentEntry =
m_xPrefBox->make_iterator(xParentEntry.get());
909 }
while(index < sPath.getLength() - 1);
911 OUString
sId(OUString::number(reinterpret_cast<sal_Int64>(rEntry.
pUserData)));
920 if (m_xPrefBox->iter_has_child(rEntry))
922 UserData *pUserData =
reinterpret_cast<UserData*
>(m_xPrefBox->get_id(rEntry).toInt64());
923 if (pUserData && !pUserData->bIsPropertyPath)
925 assert(pUserData->aXNameAccess.is());
926 FillItems(pUserData->aXNameAccess, &rEntry, pUserData->aLineage);
constexpr sal_uInt16 KEYGROUP_MISC
#define LINK(Instance, Class, Member)
std::vector< std::unique_ptr< UserData > > m_vectorUserData
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Button > m_xSearchBtn
std::unique_ptr< weld::TreeView > m_xPrefBox
constexpr sal_uInt16 KEY_C
constexpr sal_uInt16 KEY_COMMA
constexpr sal_uInt16 KEY_A
constexpr sal_uInt16 KEY_V
constexpr sal_uInt16 KEY_X
sal_uInt16 GetGroup() const
sal_uInt16 GetCode() const
virtual ~CuiAboutConfigValueDialog() override
IMPL_LINK_NOARG(CuiAboutConfigTabPage, ResetBtnHdl_Impl, weld::Button &, void)
CuiAboutConfigValueDialog(weld::Window *pWindow, const OUString &rValue, int limit)
constexpr sal_uInt16 KEY_SPACE
std::vector< prefBoxEntry > m_modifiedPrefBoxEntries
CuiAboutConfigTabPage(weld::Window *pParent)
void AddToModifiedVector(const std::shared_ptr< Prop_Impl > &rProp)
std::unique_ptr< weld::Button > m_xEditBtn
void FillItems(const css::uno::Reference< css::container::XNameAccess > &xNameAccess, const weld::TreeIter *pParentEntry=nullptr, int lineage=0, bool bLoadAll=false)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
constexpr sal_uInt16 KEYGROUP_CURSOR
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
i18nutil::SearchOptions2 m_options
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unique_ptr< weld::Button > m_xResetBtn
Prop_Impl(const OUString &sName, const OUString &sProperty, const Any &aValue)
TransliterationFlags transliterateFlags
std::unique_ptr< weld::Entry > m_xEDValue
void InsertEntry(const prefBoxEntry &rEntry)
IMPL_LINK(CuiAboutConfigValueDialog, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
virtual ~CuiAboutConfigTabPage() override
constexpr sal_uInt16 KEY_SUBTRACT
std::vector< std::shared_ptr< Prop_Impl > > m_vectorOfModified
static std::vector< OUString > commaStringToSequence(const OUString &rCommaSepString)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XExecutableDialog > m_xDialog
Reference< XComponentContext > getProcessComponentContext()
constexpr sal_uInt16 KEYGROUP_NUM
constexpr sal_uInt16 KEY_POINT
constexpr sal_uInt16 KEY_EQUAL
constexpr sal_uInt16 KEY_Z
#define SAL_WARN(area, stream)
std::unique_ptr< weld::TreeIter > m_xScratchIter
std::vector< prefBoxEntry > m_prefBoxEntries
static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const OUString &sNodePath, bool bUpdate)
OUString getValue() const