21#include <com/sun/star/uno/Any.hxx>
22#include <com/sun/star/uno/Sequence.hxx>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/container/XNameAccess.hpp>
26#include <com/sun/star/container/XNameContainer.hpp>
27#include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 constexpr OUStringLiteral s_sItemList =
u"ItemList";
39 constexpr OUStringLiteral s_sOrderList =
u"OrderList";
40 constexpr OUStringLiteral s_sHistoryItemRef =
u"HistoryItemRef";
41 constexpr OUStringLiteral s_sFilter =
u"Filter";
42 constexpr OUStringLiteral s_sTitle =
u"Title";
43 constexpr OUStringLiteral s_sPassword =
u"Password";
44 constexpr OUStringLiteral s_sThumbnail =
u"Thumbnail";
45 constexpr OUStringLiteral s_sReadOnly =
u"ReadOnly";
46 constexpr OUStringLiteral s_sPinned =
u"Pinned";
49static uno::Reference<container::XNameAccess>
GetConfig();
50static uno::Reference<container::XNameAccess>
GetCommonXCU();
52 uno::Reference<container::XNameAccess>
const & xCfg,
55 const uno::Reference<container::XNameAccess>& xCfg,
56 const uno::Reference<container::XNameAccess>& xList,
59static void PrependItem(
const uno::Reference<container::XNameAccess>& xCfg,
60 uno::Reference<container::XNameContainer>& xList, std::u16string_view sURL);
62 uno::Reference<container::XNameContainer>& xOrderList,
63 uno::Reference<container::XNameContainer>& xItemList,
64 std::u16string_view sURL);
75 uno::Reference<container::XNameAccess> xCfg =
GetConfig();
76 uno::Reference<container::XNameAccess> xListAccess(
GetListAccess(xCfg, eHistory));
79 uno::Reference<container::XNameContainer> xNode;
80 xListAccess->getByName(s_sItemList) >>= xNode;
81 Sequence<OUString> aStrings(xNode->getElementNames());
83 for (
const auto& rString : std::as_const(aStrings))
84 xNode->removeByName(rString);
87 xListAccess->getByName(s_sOrderList) >>= xNode;
88 aStrings = xNode->getElementNames();
90 for (
const auto& rString : std::as_const(aStrings))
91 xNode->removeByName(rString);
95 catch(
const uno::Exception&)
103 std::vector< HistoryItem > aRet;
106 uno::Reference<container::XNameAccess> xCfg =
GetConfig();
107 uno::Reference<container::XNameAccess> xCommonXCU =
GetCommonXCU();
108 uno::Reference<container::XNameAccess> xListAccess(
GetListAccess(xCfg, eHistory));
112 uno::Reference<container::XNameAccess> xItemList;
113 uno::Reference<container::XNameAccess> xOrderList;
114 xListAccess->getByName(s_sItemList) >>= xItemList;
115 xListAccess->getByName(s_sOrderList) >>= xOrderList;
117 const sal_Int32
nLength = xOrderList->getElementNames().getLength();
120 for (sal_Int32 nItem = 0; nItem <
nLength; ++nItem)
125 uno::Reference<beans::XPropertySet> xSet;
126 xOrderList->getByName(OUString::number(nItem)) >>= xSet;
127 xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
129 xItemList->getByName(sUrl) >>= xSet;
132 xSet->getPropertyValue(s_sFilter) >>= aItem.
sFilter;
133 xSet->getPropertyValue(s_sTitle) >>= aItem.
sTitle;
134 xSet->getPropertyValue(s_sPassword) >>= aItem.
sPassword;
135 xSet->getPropertyValue(s_sThumbnail) >>= aItem.
sThumbnail;
136 xSet->getPropertyValue(s_sReadOnly) >>= aItem.
isReadOnly;
137 if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
138 xSet->getPropertyValue(s_sPinned) >>= aItem.
isPinned;
140 aRet.push_back(aItem);
142 catch(
const uno::Exception&)
155 catch(
const uno::Exception&)
163 const OUString& sTitle,
const std::optional<OUString>& sThumbnail,
164 ::std::optional<bool>
const oIsReadOnly)
168 uno::Reference<container::XNameAccess> xCfg =
GetConfig();
169 uno::Reference<container::XNameAccess> xCommonXCU =
GetCommonXCU();
170 uno::Reference<container::XNameAccess> xListAccess(
GetListAccess(xCfg, eHistory));
174 sal_Int32 nMaxSize =
GetCapacity(xCommonXCU, eHistory);
178 uno::Reference<container::XNameContainer> xItemList;
179 uno::Reference<container::XNameContainer> xOrderList;
180 xListAccess->getByName(s_sItemList) >>= xItemList;
181 xListAccess->getByName(s_sOrderList) >>= xOrderList;
182 sal_Int32
nLength = xOrderList->getElementNames().getLength();
185 if (xItemList->hasByName(sURL))
187 uno::Reference<beans::XPropertySet> xSet;
188 xItemList->getByName(sURL) >>= xSet;
192 xSet->setPropertyValue(s_sThumbnail,
uno::Any(*sThumbnail));
196 xSet->setPropertyValue(s_sReadOnly,
uno::Any(*oIsReadOnly));
200 bool bIsItemPinned =
false;
201 if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
202 xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
210 uno::Reference<beans::XPropertySet> xSet;
211 uno::Reference<lang::XSingleServiceFactory> xFac;
212 uno::Reference<uno::XInterface> xInst;
213 uno::Reference<beans::XPropertySet> xPrevSet;
214 uno::Reference<beans::XPropertySet> xNextSet;
220 xOrderList->getByName(OUString::number(
nLength-1)) >>= xSet;
221 xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove;
224 xItemList->removeByName(sRemove);
226 catch (container::NoSuchElementException &)
234 if (!sRemove.isEmpty())
242 xFac.set(xOrderList, uno::UNO_QUERY);
243 xInst = xFac->createInstance();
244 OUString sPush = OUString::number(
nLength++);
245 xOrderList->insertByName(sPush,
uno::Any(xInst));
247 for (sal_Int32 j=
nLength-1; j>0; --j)
249 xOrderList->getByName( OUString::number(j) ) >>= xPrevSet;
250 xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
252 xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
253 xPrevSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(sTemp));
255 xOrderList->getByName( OUString::number(0) ) >>= xSet;
256 xSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(sURL));
259 xFac.set(xItemList, uno::UNO_QUERY);
260 xInst = xFac->createInstance();
261 xItemList->insertByName(sURL,
uno::Any(xInst));
263 xSet.set(xInst, uno::UNO_QUERY);
264 xSet->setPropertyValue(s_sFilter,
uno::Any(sFilter));
265 xSet->setPropertyValue(s_sTitle,
uno::Any(sTitle));
266 xSet->setPropertyValue(s_sPassword,
uno::Any(OUString()));
267 xSet->setPropertyValue(s_sThumbnail,
uno::Any(sThumbnail.value_or(OUString())));
270 xSet->setPropertyValue(s_sReadOnly,
uno::Any(*oIsReadOnly));
274 bool bIsItemPinned =
false;
275 if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
276 xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
285 catch(
const uno::Exception&)
295 uno::Reference<container::XNameAccess> xCfg =
GetConfig();
296 uno::Reference<container::XNameAccess> xListAccess(
GetListAccess(xCfg, eHistory));
298 uno::Reference<container::XNameContainer> xItemList;
299 uno::Reference<container::XNameContainer> xOrderList;
300 xListAccess->getByName(s_sItemList) >>= xItemList;
301 xListAccess->getByName(s_sOrderList) >>= xOrderList;
302 sal_Int32
nLength = xOrderList->getElementNames().getLength();
305 if (!xItemList->hasByName(sURL))
316 sal_Int32 nFromWhere = 0;
317 for (; nFromWhere <
nLength - 1; ++nFromWhere)
319 uno::Reference<beans::XPropertySet> xSet;
321 xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet;
322 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
329 for (sal_Int32
i = nFromWhere;
i <
nLength - 1; ++
i)
331 uno::Reference<beans::XPropertySet> xPrevSet;
332 uno::Reference<beans::XPropertySet> xNextSet;
333 xOrderList->getByName(OUString::number(
i)) >>= xPrevSet;
334 xOrderList->getByName(OUString::number(
i + 1)) >>= xNextSet;
337 xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
338 xPrevSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(sTemp));
340 xOrderList->removeByName(OUString::number(
nLength - 1));
343 xItemList->removeByName(sURL);
347 catch (
const uno::Exception&)
357 uno::Reference<container::XNameAccess> xCfg =
GetConfig();
358 uno::Reference<container::XNameAccess> xListAccess(
GetListAccess(xCfg, eHistory));
360 uno::Reference<container::XNameContainer> xItemList;
361 xListAccess->getByName(s_sItemList) >>= xItemList;
364 if (xItemList->hasByName(sURL))
367 uno::Reference<beans::XPropertySet> xSet;
368 xItemList->getByName(sURL) >>= xSet;
369 bool bIsItemPinned =
false;
370 if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
371 xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
372 xSet->setPropertyValue(s_sPinned,
uno::Any(!bIsItemPinned));
374 uno::Reference<container::XNameContainer> xOrderList;
375 xListAccess->getByName(s_sOrderList) >>= xOrderList;
384 catch (
const uno::Exception&)
393static uno::Reference<container::XNameAccess>
GetConfig()
395 return uno::Reference<container::XNameAccess>(
397 ::comphelper::getProcessComponentContext(),
398 "org.openoffice.Office.Histories/Histories",
400 uno::UNO_QUERY_THROW);
405 return uno::Reference<container::XNameAccess>(
407 ::comphelper::getProcessComponentContext(),
408 "org.openoffice.Office.Common/History",
410 uno::UNO_QUERY_THROW);
414 const uno::Reference<container::XNameAccess>& xCfg,
417 uno::Reference<container::XNameAccess> xListAccess;
421 xCfg->getByName(
"PickList") >>= xListAccess;
425 xCfg->getByName(
"HelpBookmarks") >>= xListAccess;
432 const uno::Reference<container::XNameAccess>& xCfg,
433 const uno::Reference<container::XNameAccess>& xList,
436 uno::Reference<container::XNameContainer> xItemList;
437 uno::Reference<container::XNameContainer> xOrderList;
438 xList->getByName(s_sOrderList) >>= xOrderList;
439 xList->getByName(s_sItemList) >>= xItemList;
441 const sal_uInt32
nLength = xOrderList->getElementNames().getLength();
447 uno::Reference<beans::XPropertySet> xSet;
449 const OUString sRemove = OUString::number(
i);
450 xOrderList->getByName(sRemove) >>= xSet;
451 xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
452 xItemList->removeByName(sTmp);
453 xOrderList->removeByName(sRemove);
459static void PrependItem(
const uno::Reference<container::XNameAccess>& xCfg,
460 uno::Reference<container::XNameContainer>& xList, std::u16string_view sURL)
462 uno::Reference<beans::XPropertySet> xSet;
463 const sal_Int32
nLength = xList->getElementNames().getLength();
467 xList->getByName(OUString::number(
i)) >>= xSet;
468 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
472 for (sal_Int32 j =
i - 1; j >= 0; --j)
474 uno::Reference<beans::XPropertySet> xPrevSet;
475 uno::Reference<beans::XPropertySet> xNextSet;
476 xList->getByName(OUString::number(j + 1)) >>= xPrevSet;
477 xList->getByName(OUString::number(j)) >>= xNextSet;
480 xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
481 xPrevSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(sTemp));
483 xList->getByName(OUString::number(0)) >>= xSet;
484 xSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(aItem));
492 uno::Reference<container::XNameContainer>& xOrderList,
493 uno::Reference<container::XNameContainer>& xItemList,
494 std::u16string_view sURL)
496 uno::Reference<beans::XPropertySet> xSet;
497 const sal_Int32
nLength = xOrderList->getElementNames().getLength();
502 xOrderList->getByName(OUString::number(
i)) >>= xSet;
503 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
508 for (sal_Int32 j =
i + 1; j <
nLength; j++)
510 uno::Reference<beans::XPropertySet> xNextSet;
511 xOrderList->getByName(OUString::number(j)) >>= xNextSet;
514 xNextSet->getPropertyValue(s_sHistoryItemRef) >>= aNextItem;
516 uno::Reference<beans::XPropertySet> xNextItemSet;
517 xItemList->getByName(aNextItem) >>= xNextItemSet;
518 bool bIsItemPinned =
false;
519 if (xNextItemSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
520 xNextItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
523 xOrderList->getByName(OUString::number(j - 1)) >>= xSet;
524 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
525 xSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(aNextItem));
526 xNextSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(aItem));
533 for (sal_Int32 j =
i - 1; j >= 0; --j)
535 uno::Reference<beans::XPropertySet> xPrevSet;
536 xOrderList->getByName(OUString::number(j)) >>= xPrevSet;
539 xPrevSet->getPropertyValue(s_sHistoryItemRef) >>= aPrevItem;
541 uno::Reference<beans::XPropertySet> xPrevItemSet;
542 xItemList->getByName(aPrevItem) >>= xPrevItemSet;
543 bool bIsItemPinned =
false;
544 if (xPrevItemSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
545 xPrevItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
548 xOrderList->getByName(OUString::number(j + 1)) >>= xSet;
549 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
550 xSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(aPrevItem));
551 xPrevSet->setPropertyValue(s_sHistoryItemRef,
uno::Any(aItem));
565 uno::Reference<beans::XPropertySet> xListAccess(xCommonXCU, uno::UNO_QUERY_THROW);
567 sal_uInt32 nSize = 0;
572 xListAccess->getPropertyValue(
"PickListSize") >>= nSize;
576 xListAccess->getPropertyValue(
"HelpBookmarkSize") >>= nSize;
static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, EConfigurationModes eMode)
static void flush(const css::uno::Reference< css::uno::XInterface > &xCFG)
#define DBG_UNHANDLED_EXCEPTION(...)
static uno::Reference< container::XNameAccess > GetConfig()
static sal_uInt32 GetCapacity(const uno::Reference< container::XNameAccess > &xCommonXCU, EHistoryType eHistory)
static uno::Reference< container::XNameAccess > GetListAccess(uno::Reference< container::XNameAccess > const &xCfg, EHistoryType eHistory)
static void PrependItem(const uno::Reference< container::XNameAccess > &xCfg, uno::Reference< container::XNameContainer > &xList, std::u16string_view sURL)
static void TruncateList(const uno::Reference< container::XNameAccess > &xCfg, const uno::Reference< container::XNameAccess > &xList, sal_uInt32 nSize)
static void MoveItemToUnpinned(const uno::Reference< container::XNameAccess > &xCfg, uno::Reference< container::XNameContainer > &xOrderList, uno::Reference< container::XNameContainer > &xItemList, std::u16string_view sURL)
static uno::Reference< container::XNameAccess > GetCommonXCU()
EHistoryType
You can use these enum values to specify right history if you call our interface methods.
Collect information about history features.
void Clear(EHistoryType eHistory)
Clear complete specified list.
void DeleteItem(EHistoryType eHistory, const OUString &sURL)
Delete item from the specified list.
void TogglePinItem(EHistoryType eHistory, const OUString &sURL)
std::vector< HistoryItem > GetList(EHistoryType eHistory)
void AppendItem(EHistoryType eHistory, const OUString &sURL, const OUString &sFilter, const OUString &sTitle, const std::optional< OUString > &sThumbnail, ::std::optional< bool > const oIsReadOnly)
Return the complete specified history list.