Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unotools/source/config/historyoptions.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <unotools/historyoptions.hxx>
21
#include <com/sun/star/uno/Any.hxx>
22
#include <com/sun/star/uno/Sequence.hxx>
23
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>
28
#include <comphelper/configurationhelper.hxx>
29
#include <comphelper/processfactory.hxx>
30
#include <comphelper/diagnose_ex.hxx>
31
#include <optional>
32
33
using namespace ::com::sun::star;
34
using namespace ::com::sun::star::uno;
35
using namespace ::com::sun::star::beans;
36
37
namespace {
38
    constexpr OUString s_sItemList = u"ItemList"_ustr;
39
    constexpr OUString s_sOrderList = u"OrderList"_ustr;
40
    constexpr OUString s_sHistoryItemRef = u"HistoryItemRef"_ustr;
41
    constexpr OUString s_sFilter = u"Filter"_ustr;
42
    constexpr OUString s_sTitle = u"Title"_ustr;
43
    constexpr OUString s_sThumbnail = u"Thumbnail"_ustr;
44
    constexpr OUString s_sReadOnly = u"ReadOnly"_ustr;
45
    constexpr OUString s_sPinned = u"Pinned"_ustr;
46
}
47
48
static uno::Reference<container::XNameAccess> GetConfig();
49
static uno::Reference<container::XNameAccess> GetCommonXCU();
50
static uno::Reference<container::XNameAccess> GetListAccess(
51
        uno::Reference<container::XNameAccess> const & xCfg,
52
        EHistoryType eHistory);
53
static void TruncateList(
54
        const uno::Reference<container::XNameAccess>& xCfg,
55
        const uno::Reference<container::XNameAccess>& xList,
56
        sal_uInt32 nSize);
57
58
static void PrependItem(const uno::Reference<container::XNameAccess>& xCfg,
59
                        const uno::Reference<container::XNameContainer>& xList,
60
                        std::u16string_view sURL);
61
static void MoveItemToUnpinned(const uno::Reference<container::XNameAccess>& xCfg,
62
                               const uno::Reference<container::XNameContainer>& xOrderList,
63
                               const uno::Reference<container::XNameContainer>& xItemList,
64
                               std::u16string_view sURL);
65
66
static sal_uInt32 GetCapacity(const uno::Reference<container::XNameAccess>& xCommonXCU, EHistoryType eHistory);
67
68
namespace SvtHistoryOptions
69
{
70
71
void Clear(EHistoryType eHistory, const bool bClearPinnedItems)
72
0
{
73
0
    try
74
0
    {
75
0
        uno::Reference<container::XNameAccess> xCfg = GetConfig();
76
0
        uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory));
77
78
        // Retrieve order and item lists using name access to check properties of individual items
79
0
        uno::Reference<container::XNameAccess> xItemList;
80
0
        uno::Reference<container::XNameAccess> xOrderList;
81
0
        xListAccess->getByName(s_sItemList)  >>= xItemList;
82
0
        xListAccess->getByName(s_sOrderList) >>= xOrderList;
83
84
        // Retrieve order and item lists using name container to delete individual items
85
0
        uno::Reference<container::XNameContainer> xOrderNode;
86
0
        uno::Reference<container::XNameContainer> xItemNode;
87
0
        xListAccess->getByName(s_sItemList) >>= xItemNode;
88
0
        xListAccess->getByName(s_sOrderList) >>= xOrderNode;
89
90
0
        const sal_Int32 nLength = xOrderList->getElementNames().getLength();
91
0
        for (sal_Int32 nItem = 0; nItem < nLength; ++nItem)
92
0
        {
93
            // Retrieve single item from the order list
94
0
            OUString sUrl;
95
0
            uno::Reference<beans::XPropertySet> xSet;
96
0
            xOrderList->getByName(OUString::number(nItem)) >>= xSet;
97
0
            xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
98
99
            // tdf#155698 - check if pinned items should be cleared
100
0
            bool bIsItemPinned = false;
101
0
            if (!bClearPinnedItems)
102
0
            {
103
0
                xItemList->getByName(sUrl) >>= xSet;
104
0
                if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
105
0
                    xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
106
0
            }
107
108
0
            if (!bIsItemPinned)
109
0
            {
110
0
                xItemNode->removeByName(sUrl);
111
0
                xOrderNode->removeByName(OUString::number(nItem));
112
0
            }
113
0
        }
114
115
0
        ::comphelper::ConfigurationHelper::flush(xCfg);
116
0
    }
117
0
    catch(const uno::Exception&)
118
0
    {
119
0
        DBG_UNHANDLED_EXCEPTION("unotools.config");
120
0
    }
121
0
}
122
123
std::vector< HistoryItem > GetList( EHistoryType eHistory )
124
0
{
125
0
    std::vector< HistoryItem > aRet;
126
0
    try
127
0
    {
128
0
        uno::Reference<container::XNameAccess> xCfg = GetConfig();
129
0
        uno::Reference<container::XNameAccess> xCommonXCU = GetCommonXCU();
130
0
        uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory));
131
132
0
        TruncateList(xCfg, xListAccess, GetCapacity(xCommonXCU, eHistory));
133
134
0
        uno::Reference<container::XNameAccess> xItemList;
135
0
        uno::Reference<container::XNameAccess> xOrderList;
136
0
        xListAccess->getByName(s_sItemList)  >>= xItemList;
137
0
        xListAccess->getByName(s_sOrderList) >>= xOrderList;
138
139
0
        const sal_Int32 nLength = xOrderList->getElementNames().getLength();
140
0
        aRet.reserve(nLength);
141
142
0
        for (sal_Int32 nItem = 0; nItem < nLength; ++nItem)
143
0
        {
144
0
            try
145
0
            {
146
0
                OUString sUrl;
147
0
                uno::Reference<beans::XPropertySet> xSet;
148
0
                xOrderList->getByName(OUString::number(nItem)) >>= xSet;
149
0
                xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
150
151
0
                xItemList->getByName(sUrl) >>= xSet;
152
0
                HistoryItem aItem;
153
0
                aItem.sURL = sUrl;
154
0
                xSet->getPropertyValue(s_sFilter) >>= aItem.sFilter;
155
0
                xSet->getPropertyValue(s_sTitle) >>= aItem.sTitle;
156
0
                xSet->getPropertyValue(s_sThumbnail) >>= aItem.sThumbnail;
157
0
                xSet->getPropertyValue(s_sReadOnly) >>= aItem.isReadOnly;
158
0
                if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
159
0
                    xSet->getPropertyValue(s_sPinned) >>= aItem.isPinned;
160
161
0
                aRet.push_back(aItem);
162
0
            }
163
0
            catch(const uno::Exception&)
164
0
            {
165
                // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
166
                // "FILEOPEN: No Recent Documents..." discusses a problem
167
                // with corrupted /org.openoffice.Office/Histories/Histories
168
                // configuration items; to work around that problem, simply
169
                // ignore such corrupted individual items here, so that at
170
                // least newly added items are successfully reported back
171
                // from this function:
172
0
                DBG_UNHANDLED_EXCEPTION("unotools.config");
173
0
            }
174
0
        }
175
0
    }
176
0
    catch(const uno::Exception&)
177
0
    {
178
0
        DBG_UNHANDLED_EXCEPTION("unotools.config");
179
0
    }
180
0
    return aRet;
181
0
}
182
183
void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFilter,
184
                const OUString& sTitle, const std::optional<OUString>& sThumbnail,
185
                ::std::optional<bool> const oIsReadOnly)
186
0
{
187
0
    try
188
0
    {
189
0
        uno::Reference<container::XNameAccess> xCfg = GetConfig();
190
0
        uno::Reference<container::XNameAccess> xCommonXCU = GetCommonXCU();
191
0
        uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory));
192
193
0
        TruncateList(xCfg, xListAccess, GetCapacity(xCommonXCU, eHistory));
194
195
0
        sal_Int32 nMaxSize = GetCapacity(xCommonXCU, eHistory);
196
0
        if (nMaxSize == 0)
197
0
            return;
198
199
0
        uno::Reference<container::XNameContainer> xItemList;
200
0
        uno::Reference<container::XNameContainer> xOrderList;
201
0
        xListAccess->getByName(s_sItemList)  >>= xItemList;
202
0
        xListAccess->getByName(s_sOrderList) >>= xOrderList;
203
0
        sal_Int32 nLength = xOrderList->getElementNames().getLength();
204
205
        // The item to be appended already exists
206
0
        if (xItemList->hasByName(sURL))
207
0
        {
208
0
            uno::Reference<beans::XPropertySet>       xSet;
209
0
            xItemList->getByName(sURL) >>= xSet;
210
0
            if (sThumbnail)
211
0
            {
212
                // update the thumbnail
213
0
                xSet->setPropertyValue(s_sThumbnail, uno::Any(*sThumbnail));
214
0
            }
215
0
            if (oIsReadOnly)
216
0
            {
217
0
                xSet->setPropertyValue(s_sReadOnly, uno::Any(*oIsReadOnly));
218
0
            }
219
220
            // tdf#38742 - check the current pinned state of the item and move it accordingly
221
0
            bool bIsItemPinned = false;
222
0
            if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
223
0
                xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
224
0
            if (bIsItemPinned)
225
0
                PrependItem(xCfg, xOrderList, sURL);
226
0
            else
227
0
                MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL);
228
0
        }
229
0
        else // The item to be appended does not exist yet
230
0
        {
231
0
            uno::Reference<beans::XPropertySet>       xSet;
232
0
            uno::Reference<lang::XSingleServiceFactory> xFac;
233
0
            uno::Reference<uno::XInterface>             xInst;
234
0
            uno::Reference<beans::XPropertySet> xPrevSet;
235
0
            uno::Reference<beans::XPropertySet> xNextSet;
236
237
            // Append new item to OrderList.
238
0
            if ( nLength == nMaxSize )
239
0
            {
240
0
                OUString sRemove;
241
0
                xOrderList->getByName(OUString::number(nLength-1)) >>= xSet;
242
0
                xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove;
243
0
                try
244
0
                {
245
0
                    xItemList->removeByName(sRemove);
246
0
                }
247
0
                catch (container::NoSuchElementException &)
248
0
                {
249
                    // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
250
                    // "FILEOPEN: No Recent Documents..." discusses a problem
251
                    // with corrupted /org.openoffice.Office/Histories/Histories
252
                    // configuration items; to work around that problem, simply
253
                    // ignore such corrupted individual items here, so that at
254
                    // least newly added items are successfully added:
255
0
                    if (!sRemove.isEmpty())
256
0
                    {
257
0
                        throw;
258
0
                    }
259
0
                }
260
0
            }
261
0
            if (nLength != nMaxSize)
262
0
            {
263
0
                xFac.set(xOrderList, uno::UNO_QUERY);
264
0
                xInst = xFac->createInstance();
265
0
                OUString sPush = OUString::number(nLength++);
266
0
                xOrderList->insertByName(sPush, uno::Any(xInst));
267
0
            }
268
0
            for (sal_Int32 j=nLength-1; j>0; --j)
269
0
            {
270
0
                xOrderList->getByName( OUString::number(j) )   >>= xPrevSet;
271
0
                xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
272
0
                OUString sTemp;
273
0
                xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
274
0
                xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sTemp));
275
0
            }
276
0
            xOrderList->getByName( OUString::number(0) ) >>= xSet;
277
0
            xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sURL));
278
279
            // Append the item to ItemList.
280
0
            xFac.set(xItemList, uno::UNO_QUERY);
281
0
            xInst = xFac->createInstance();
282
0
            xItemList->insertByName(sURL, uno::Any(xInst));
283
284
0
            xSet.set(xInst, uno::UNO_QUERY);
285
0
            xSet->setPropertyValue(s_sFilter, uno::Any(sFilter));
286
0
            xSet->setPropertyValue(s_sTitle, uno::Any(sTitle));
287
0
            xSet->setPropertyValue(s_sThumbnail, uno::Any(sThumbnail.value_or(OUString())));
288
0
            if (oIsReadOnly)
289
0
            {
290
0
                xSet->setPropertyValue(s_sReadOnly, uno::Any(*oIsReadOnly));
291
0
            }
292
293
            // tdf#38742 - check the current pinned state of the item and move it accordingly
294
0
            bool bIsItemPinned = false;
295
0
            if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
296
0
                xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
297
0
            if (bIsItemPinned)
298
0
                PrependItem(xCfg, xOrderList, sURL);
299
0
            else
300
0
                MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL);
301
302
0
            ::comphelper::ConfigurationHelper::flush(xCfg);
303
0
        }
304
0
    }
305
0
    catch(const uno::Exception&)
306
0
    {
307
0
        DBG_UNHANDLED_EXCEPTION("unotools.config");
308
0
    }
309
0
}
310
311
void DeleteItem(EHistoryType eHistory, const OUString& sURL, const bool bClearPinned)
312
0
{
313
0
    try
314
0
    {
315
0
        uno::Reference<container::XNameAccess> xCfg = GetConfig();
316
0
        uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory));
317
318
0
        uno::Reference<container::XNameContainer> xItemList;
319
0
        uno::Reference<container::XNameContainer> xOrderList;
320
0
        xListAccess->getByName(s_sItemList)  >>= xItemList;
321
0
        xListAccess->getByName(s_sOrderList) >>= xOrderList;
322
0
        sal_Int32 nLength = xOrderList->getElementNames().getLength();
323
324
        // if it does not exist, nothing to do
325
0
        if (!xItemList->hasByName(sURL))
326
0
            return;
327
328
        // it's the last one and pinned items can be cleared, just clear the lists
329
0
        if (nLength == 1 && bClearPinned)
330
0
        {
331
0
            Clear(eHistory);
332
0
            return;
333
0
        }
334
335
        // find it in the OrderList
336
0
        sal_Int32 nFromWhere = 0;
337
0
        bool bIsItemPinned = false;
338
0
        for (; nFromWhere < nLength - 1; ++nFromWhere)
339
0
        {
340
0
            uno::Reference<beans::XPropertySet>       xSet;
341
0
            OUString aItem;
342
0
            xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet;
343
0
            xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
344
            // tdf#155698 - check if pinned item should be deleted
345
0
            if (!bClearPinned && xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
346
0
                xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
347
348
0
            if (aItem == sURL)
349
0
                break;
350
0
        }
351
352
        // tdf#155698 - check if pinned item should be deleted
353
0
        if (!bIsItemPinned)
354
0
        {
355
            // and shift the rest of the items in OrderList accordingly
356
0
            for (sal_Int32 i = nFromWhere; i < nLength - 1; ++i)
357
0
            {
358
0
                uno::Reference<beans::XPropertySet> xPrevSet;
359
0
                uno::Reference<beans::XPropertySet> xNextSet;
360
0
                xOrderList->getByName(OUString::number(i))     >>= xPrevSet;
361
0
                xOrderList->getByName(OUString::number(i + 1)) >>= xNextSet;
362
363
0
                OUString sTemp;
364
0
                xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
365
0
                xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sTemp));
366
0
            }
367
0
            xOrderList->removeByName(OUString::number(nLength - 1));
368
369
            // and finally remove it from the ItemList
370
0
            xItemList->removeByName(sURL);
371
372
0
            ::comphelper::ConfigurationHelper::flush(xCfg);
373
0
        }
374
0
    }
375
0
    catch (const uno::Exception&)
376
0
    {
377
0
        DBG_UNHANDLED_EXCEPTION("unotools.config");
378
0
    }
379
0
}
380
381
void TogglePinItem(EHistoryType eHistory, const OUString& sURL)
382
0
{
383
0
    try
384
0
    {
385
0
        uno::Reference<container::XNameAccess> xCfg = GetConfig();
386
0
        uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory));
387
388
0
        uno::Reference<container::XNameContainer> xItemList;
389
0
        xListAccess->getByName(s_sItemList)  >>= xItemList;
390
391
        // Check if item exists
392
0
        if (xItemList->hasByName(sURL))
393
0
        {
394
            // Toggle pinned option
395
0
            uno::Reference<beans::XPropertySet> xSet;
396
0
            xItemList->getByName(sURL) >>= xSet;
397
0
            bool bIsItemPinned = false;
398
0
            if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
399
0
                xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
400
0
            xSet->setPropertyValue(s_sPinned, uno::Any(!bIsItemPinned));
401
402
0
            uno::Reference<container::XNameContainer> xOrderList;
403
0
            xListAccess->getByName(s_sOrderList) >>= xOrderList;
404
405
            // Shift item to the beginning of the document list if it is not pinned now
406
0
            if (bIsItemPinned)
407
0
                MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL);
408
0
            else
409
0
                PrependItem(xCfg, xOrderList, sURL);
410
0
        }
411
0
    }
412
0
    catch (const uno::Exception&)
413
0
    {
414
0
        DBG_UNHANDLED_EXCEPTION("unotools.config");
415
0
    }
416
0
}
417
418
} // namespace
419
420
421
static uno::Reference<container::XNameAccess> GetConfig()
422
0
{
423
0
    return uno::Reference<container::XNameAccess>(
424
0
            ::comphelper::ConfigurationHelper::openConfig(
425
0
                ::comphelper::getProcessComponentContext(),
426
0
                u"org.openoffice.Office.Histories/Histories"_ustr,
427
0
                ::comphelper::EConfigurationModes::Standard),
428
0
            uno::UNO_QUERY_THROW);
429
0
}
430
431
static uno::Reference<container::XNameAccess> GetCommonXCU()
432
0
{
433
0
    return uno::Reference<container::XNameAccess>(
434
0
            ::comphelper::ConfigurationHelper::openConfig(
435
0
                ::comphelper::getProcessComponentContext(),
436
0
                u"org.openoffice.Office.Common/History"_ustr,
437
0
                ::comphelper::EConfigurationModes::Standard),
438
0
            uno::UNO_QUERY_THROW);
439
0
}
440
441
static uno::Reference<container::XNameAccess> GetListAccess(
442
    const uno::Reference<container::XNameAccess>& xCfg,
443
    EHistoryType eHistory)
444
0
{
445
0
    uno::Reference<container::XNameAccess> xListAccess;
446
0
    switch (eHistory)
447
0
    {
448
0
    case EHistoryType::PickList:
449
0
        xCfg->getByName(u"PickList"_ustr) >>= xListAccess;
450
0
        break;
451
452
0
    case EHistoryType::HelpBookmarks:
453
0
        xCfg->getByName(u"HelpBookmarks"_ustr) >>= xListAccess;
454
0
        break;
455
0
    }
456
0
    return xListAccess;
457
0
}
458
459
static void TruncateList(
460
    const uno::Reference<container::XNameAccess>& xCfg,
461
    const uno::Reference<container::XNameAccess>& xList,
462
    sal_uInt32 nSize)
463
0
{
464
0
    uno::Reference<container::XNameContainer> xItemList;
465
0
    uno::Reference<container::XNameContainer> xOrderList;
466
0
    xList->getByName(s_sOrderList) >>= xOrderList;
467
0
    xList->getByName(s_sItemList)  >>= xItemList;
468
469
0
    const sal_uInt32 nLength = xOrderList->getElementNames().getLength();
470
0
    if (nSize >= nLength)
471
0
        return;
472
473
0
    for (sal_uInt32 i=nLength-1; i>=nSize; --i)
474
0
    {
475
0
        uno::Reference<beans::XPropertySet>       xSet;
476
0
        OUString sTmp;
477
0
        const OUString sRemove = OUString::number(i);
478
0
        xOrderList->getByName(sRemove) >>= xSet;
479
0
        xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
480
0
        xItemList->removeByName(sTmp);
481
0
        xOrderList->removeByName(sRemove);
482
0
    }
483
484
0
    ::comphelper::ConfigurationHelper::flush(xCfg);
485
0
}
486
487
static void PrependItem(const uno::Reference<container::XNameAccess>& xCfg,
488
                        const uno::Reference<container::XNameContainer>& xList, std::u16string_view sURL)
489
0
{
490
0
    uno::Reference<beans::XPropertySet> xSet;
491
0
    const sal_Int32 nLength = xList->getElementNames().getLength();
492
0
    for (sal_Int32 i = 0; i < nLength; i++)
493
0
    {
494
0
        OUString aItem;
495
0
        xList->getByName(OUString::number(i)) >>= xSet;
496
0
        xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
497
498
0
        if (aItem == sURL)
499
0
        {
500
0
            for (sal_Int32 j = i - 1; j >= 0; --j)
501
0
            {
502
0
                uno::Reference<beans::XPropertySet> xPrevSet;
503
0
                uno::Reference<beans::XPropertySet> xNextSet;
504
0
                xList->getByName(OUString::number(j + 1)) >>= xPrevSet;
505
0
                xList->getByName(OUString::number(j)) >>= xNextSet;
506
507
0
                OUString sTemp;
508
0
                xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
509
0
                xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sTemp));
510
0
            }
511
0
            xList->getByName(OUString::number(0)) >>= xSet;
512
0
            xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aItem));
513
0
            ::comphelper::ConfigurationHelper::flush(xCfg);
514
0
            return;
515
0
        }
516
0
    }
517
0
}
518
519
static void MoveItemToUnpinned(const uno::Reference<container::XNameAccess>& xCfg,
520
                               const uno::Reference<container::XNameContainer>& xOrderList,
521
                               const uno::Reference<container::XNameContainer>& xItemList,
522
                               std::u16string_view sURL)
523
0
{
524
0
    uno::Reference<beans::XPropertySet> xSet;
525
0
    const sal_Int32 nLength = xOrderList->getElementNames().getLength();
526
    // Search for item in the ordered list
527
0
    for (sal_Int32 i = 0; i < nLength; i++)
528
0
    {
529
0
        OUString aItem;
530
0
        xOrderList->getByName(OUString::number(i)) >>= xSet;
531
0
        xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
532
533
0
        if (aItem == sURL)
534
0
        {
535
            // Move item to the unpinned document section to the right if it was previously pinned
536
0
            for (sal_Int32 j = i + 1; j < nLength; j++)
537
0
            {
538
0
                uno::Reference<beans::XPropertySet> xNextSet;
539
0
                xOrderList->getByName(OUString::number(j)) >>= xNextSet;
540
541
0
                OUString aNextItem;
542
0
                xNextSet->getPropertyValue(s_sHistoryItemRef) >>= aNextItem;
543
544
0
                uno::Reference<beans::XPropertySet> xNextItemSet;
545
0
                xItemList->getByName(aNextItem) >>= xNextItemSet;
546
0
                bool bIsItemPinned = false;
547
0
                if (xNextItemSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
548
0
                    xNextItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
549
0
                if (bIsItemPinned)
550
0
                {
551
0
                    xOrderList->getByName(OUString::number(j - 1)) >>= xSet;
552
0
                    xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
553
0
                    xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aNextItem));
554
0
                    xNextSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aItem));
555
0
                }
556
0
                else
557
0
                    break;
558
0
            }
559
560
            // Move item to the unpinned document section to the left if it was previously unpinned
561
0
            for (sal_Int32 j = i - 1; j >= 0; --j)
562
0
            {
563
0
                uno::Reference<beans::XPropertySet> xPrevSet;
564
0
                xOrderList->getByName(OUString::number(j)) >>= xPrevSet;
565
566
0
                OUString aPrevItem;
567
0
                xPrevSet->getPropertyValue(s_sHistoryItemRef) >>= aPrevItem;
568
569
0
                uno::Reference<beans::XPropertySet> xPrevItemSet;
570
0
                xItemList->getByName(aPrevItem) >>= xPrevItemSet;
571
0
                bool bIsItemPinned = false;
572
0
                if (xPrevItemSet->getPropertySetInfo()->hasPropertyByName(s_sPinned))
573
0
                    xPrevItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned;
574
0
                if (!bIsItemPinned)
575
0
                {
576
0
                    xOrderList->getByName(OUString::number(j + 1)) >>= xSet;
577
0
                    xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
578
0
                    xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aPrevItem));
579
0
                    xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aItem));
580
0
                }
581
0
                else
582
0
                    break;
583
0
            }
584
585
0
            ::comphelper::ConfigurationHelper::flush(xCfg);
586
0
            return;
587
0
        }
588
0
    }
589
0
}
590
591
static sal_uInt32 GetCapacity(const uno::Reference<container::XNameAccess>& xCommonXCU, EHistoryType eHistory)
592
0
{
593
0
    uno::Reference<beans::XPropertySet> xListAccess(xCommonXCU, uno::UNO_QUERY_THROW);
594
595
0
    sal_uInt32 nSize = 0;
596
597
0
    switch (eHistory)
598
0
    {
599
0
    case EHistoryType::PickList:
600
0
        xListAccess->getPropertyValue(u"PickListSize"_ustr) >>= nSize;
601
0
        break;
602
603
0
    case EHistoryType::HelpBookmarks:
604
0
        xListAccess->getPropertyValue(u"HelpBookmarkSize"_ustr) >>= nSize;
605
0
        break;
606
0
    }
607
608
0
    return nSize;
609
0
}
610
611
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */