Line data Source code
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 <osl/file.hxx>
21 : #include <sal/log.hxx>
22 : #include <unotools/historyoptions.hxx>
23 : #include <unotools/configmgr.hxx>
24 : #include <unotools/configitem.hxx>
25 : #include <com/sun/star/uno/Any.hxx>
26 : #include <com/sun/star/uno/Sequence.hxx>
27 :
28 : #include <cassert>
29 : #include <deque>
30 : #include <algorithm>
31 :
32 : #include "itemholder1.hxx"
33 :
34 : #include <com/sun/star/beans/XPropertySet.hpp>
35 : #include <com/sun/star/container/XNameAccess.hpp>
36 : #include <com/sun/star/container/XNameContainer.hpp>
37 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 : #include <comphelper/configurationhelper.hxx>
39 : #include <comphelper/processfactory.hxx>
40 :
41 : using namespace ::std;
42 : using namespace ::utl;
43 : using namespace ::osl;
44 : using namespace ::com::sun::star;
45 : using namespace ::com::sun::star::uno;
46 : using namespace ::com::sun::star::beans;
47 :
48 : namespace {
49 : static const ::sal_Int32 s_nOffsetURL = 0;
50 : static const ::sal_Int32 s_nOffsetFilter = 1;
51 : static const ::sal_Int32 s_nOffsetTitle = 2;
52 : static const ::sal_Int32 s_nOffsetPassword = 3;
53 : static const ::sal_Int32 s_nOffsetThumbnail = 4;
54 :
55 : const char s_sCommonHistory[] = "org.openoffice.Office.Common/History";
56 : const char s_sHistories[] = "org.openoffice.Office.Histories/Histories";
57 : const char s_sPickListSize[] = "PickListSize";
58 : const char s_sHelpBookmarksSize[] = "HelpBookmarkSize";
59 : const char s_sPickList[] = "PickList";
60 : const char s_sHelpBookmarks[] = "HelpBookmarks";
61 : const char s_sItemList[] = "ItemList";
62 : const char s_sOrderList[] = "OrderList";
63 : const char s_sHistoryItemRef[] = "HistoryItemRef";
64 : const char s_sFilter[] = "Filter";
65 : const char s_sTitle[] = "Title";
66 : const char s_sPassword[] = "Password";
67 : const char s_sThumbnail[] = "Thumbnail";
68 :
69 : class theHistoryOptionsMutex : public rtl::Static<osl::Mutex, theHistoryOptionsMutex>{};
70 : }
71 :
72 : /// Internal implementation of the SvtHistoryOptions.
73 : class SvtHistoryOptions_Impl
74 : {
75 : public:
76 : SvtHistoryOptions_Impl();
77 : ~SvtHistoryOptions_Impl();
78 :
79 : /// Returns the maximum size of the internal lists, ie. the capacity not the size.
80 : sal_uInt32 GetCapacity(EHistoryType eHistory);
81 :
82 : /// Clear the specified history list.
83 : void Clear(EHistoryType eHistory);
84 :
85 : /// Get a sequence list from the items.
86 : Sequence< Sequence<PropertyValue> > GetList(EHistoryType eHistory);
87 :
88 : void AppendItem(EHistoryType eHistory,
89 : const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
90 : const OUString& sPassword, const OUString& sThumbnail);
91 :
92 : void DeleteItem(EHistoryType eHistory, const OUString& sURL);
93 :
94 : private:
95 : /// Return the appropriate list of recent documents (based on eHistory).
96 : uno::Reference<container::XNameAccess> GetListAccess(EHistoryType eHistory) const;
97 :
98 : void impl_truncateList(EHistoryType eHistory, sal_uInt32 nSize);
99 :
100 : private:
101 : uno::Reference<container::XNameAccess> m_xCfg;
102 : uno::Reference<container::XNameAccess> m_xCommonXCU;
103 : };
104 :
105 208 : SvtHistoryOptions_Impl::SvtHistoryOptions_Impl()
106 : {
107 : try
108 : {
109 416 : m_xCfg = Reference<container::XNameAccess> (
110 : ::comphelper::ConfigurationHelper::openConfig(
111 : ::comphelper::getProcessComponentContext(),
112 : s_sHistories,
113 : ::comphelper::ConfigurationHelper::E_STANDARD),
114 208 : uno::UNO_QUERY);
115 :
116 416 : m_xCommonXCU = Reference<container::XNameAccess> (
117 : ::comphelper::ConfigurationHelper::openConfig(
118 : ::comphelper::getProcessComponentContext(),
119 : s_sCommonHistory,
120 : ::comphelper::ConfigurationHelper::E_STANDARD),
121 208 : uno::UNO_QUERY);
122 : }
123 0 : catch(const uno::Exception& ex)
124 : {
125 0 : m_xCfg.clear();
126 0 : m_xCommonXCU.clear();
127 :
128 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
129 : }
130 208 : }
131 :
132 206 : SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl()
133 : {
134 206 : }
135 :
136 6519 : sal_uInt32 SvtHistoryOptions_Impl::GetCapacity(EHistoryType eHistory)
137 : {
138 6519 : uno::Reference<beans::XPropertySet> xListAccess(m_xCommonXCU, uno::UNO_QUERY);
139 :
140 6519 : if (!xListAccess.is())
141 0 : return 0;
142 :
143 6519 : sal_uInt32 nSize = 0;
144 :
145 : try
146 : {
147 6519 : switch (eHistory)
148 : {
149 : case ePICKLIST:
150 6519 : xListAccess->getPropertyValue(s_sPickListSize) >>= nSize;
151 6519 : break;
152 :
153 : case eHELPBOOKMARKS:
154 0 : xListAccess->getPropertyValue(s_sHelpBookmarksSize) >>= nSize;
155 0 : break;
156 :
157 : default:
158 0 : break;
159 : }
160 : }
161 0 : catch (const uno::Exception& ex)
162 : {
163 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
164 : }
165 :
166 6519 : return nSize;
167 : }
168 :
169 6312 : uno::Reference<container::XNameAccess> SvtHistoryOptions_Impl::GetListAccess(EHistoryType eHistory) const
170 : {
171 6312 : uno::Reference<container::XNameAccess> xListAccess;
172 :
173 : try
174 : {
175 6312 : switch (eHistory)
176 : {
177 : case ePICKLIST:
178 6312 : m_xCfg->getByName(s_sPickList) >>= xListAccess;
179 6312 : break;
180 :
181 : case eHELPBOOKMARKS:
182 0 : m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess;
183 0 : break;
184 :
185 : default:
186 0 : break;
187 : }
188 : }
189 0 : catch (const uno::Exception& ex)
190 : {
191 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
192 : }
193 :
194 6312 : return xListAccess;
195 : }
196 :
197 3156 : void SvtHistoryOptions_Impl::impl_truncateList(EHistoryType eHistory, sal_uInt32 nSize)
198 : {
199 3156 : uno::Reference<container::XNameAccess> xList(GetListAccess(eHistory));
200 3156 : if (!xList.is())
201 3156 : return;
202 :
203 6312 : uno::Reference<container::XNameContainer> xItemList;
204 6312 : uno::Reference<container::XNameContainer> xOrderList;
205 6312 : uno::Reference<beans::XPropertySet> xSet;
206 :
207 : try
208 : {
209 3156 : xList->getByName(s_sOrderList) >>= xOrderList;
210 3156 : xList->getByName(s_sItemList) >>= xItemList;
211 :
212 3156 : const sal_uInt32 nLength = xOrderList->getElementNames().getLength();
213 3156 : if (nSize < nLength)
214 : {
215 0 : for (sal_uInt32 i=nLength-1; i>=nSize; --i)
216 : {
217 0 : OUString sTmp;
218 0 : const OUString sRemove = OUString::number(i);
219 0 : xOrderList->getByName(sRemove) >>= xSet;
220 0 : xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
221 0 : xItemList->removeByName(sTmp);
222 0 : xOrderList->removeByName(sRemove);
223 0 : }
224 :
225 0 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
226 : }
227 : }
228 0 : catch(const uno::Exception& ex)
229 : {
230 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
231 3156 : }
232 : }
233 :
234 0 : void SvtHistoryOptions_Impl::Clear( EHistoryType eHistory )
235 : {
236 0 : uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
237 0 : if (!xListAccess.is())
238 0 : return;
239 :
240 0 : uno::Reference<container::XNameContainer> xNode;
241 :
242 : try
243 : {
244 : // clear ItemList
245 0 : xListAccess->getByName(s_sItemList) >>= xNode;
246 0 : Sequence<OUString> aStrings(xNode->getElementNames());
247 :
248 0 : const sal_Int32 nLength = aStrings.getLength();
249 0 : for (sal_Int32 i = 0; i < nLength; ++i)
250 0 : xNode->removeByName(aStrings[i]);
251 :
252 : // clear OrderList
253 0 : xListAccess->getByName(s_sOrderList) >>= xNode;
254 0 : aStrings = xNode->getElementNames();
255 :
256 0 : for (sal_Int32 j = 0; j < nLength; ++j)
257 0 : xNode->removeByName(aStrings[j]);
258 :
259 0 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
260 : }
261 0 : catch(const uno::Exception& ex)
262 : {
263 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
264 0 : }
265 : }
266 :
267 0 : static bool lcl_fileOpenable(const OUString &rURL)
268 : {
269 0 : osl::File aRecentFile(rURL);
270 0 : if(!aRecentFile.open(osl_File_OpenFlag_Read))
271 : {
272 0 : aRecentFile.close();
273 0 : return true;
274 : }
275 : else
276 0 : return false;
277 : }
278 :
279 1 : Sequence< Sequence<PropertyValue> > SvtHistoryOptions_Impl::GetList(EHistoryType eHistory)
280 : {
281 1 : uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
282 1 : if (!xListAccess.is())
283 0 : return Sequence< Sequence<PropertyValue> >();
284 :
285 1 : impl_truncateList(eHistory, GetCapacity(eHistory));
286 :
287 2 : Sequence<PropertyValue> seqProperties(5);
288 1 : seqProperties[s_nOffsetURL ].Name = HISTORY_PROPERTYNAME_URL;
289 1 : seqProperties[s_nOffsetFilter ].Name = HISTORY_PROPERTYNAME_FILTER;
290 1 : seqProperties[s_nOffsetTitle ].Name = HISTORY_PROPERTYNAME_TITLE;
291 1 : seqProperties[s_nOffsetPassword ].Name = HISTORY_PROPERTYNAME_PASSWORD;
292 1 : seqProperties[s_nOffsetThumbnail ].Name = HISTORY_PROPERTYNAME_THUMBNAIL;
293 :
294 2 : uno::Reference<container::XNameAccess> xItemList;
295 2 : uno::Reference<container::XNameAccess> xOrderList;
296 : try
297 : {
298 1 : xListAccess->getByName(s_sItemList) >>= xItemList;
299 1 : xListAccess->getByName(s_sOrderList) >>= xOrderList;
300 : }
301 0 : catch(const uno::Exception& ex)
302 : {
303 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
304 : }
305 :
306 1 : const sal_Int32 nLength = xOrderList->getElementNames().getLength();
307 2 : Sequence< Sequence<PropertyValue> > aRet(nLength);
308 1 : sal_Int32 nCount = 0;
309 :
310 1 : for (sal_Int32 nItem = 0; nItem < nLength; ++nItem)
311 : {
312 : try
313 : {
314 0 : OUString sUrl;
315 0 : uno::Reference<beans::XPropertySet> xSet;
316 0 : xOrderList->getByName(OUString::number(nItem)) >>= xSet;
317 0 : xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
318 :
319 : // Check if file is openable, but for performance reasons try to
320 : // only do so for files on a local filesystem. For Windows,
321 : // checking for "file:///" nicely filters out UNC paths (that only
322 : // have two slashes), but of course misses to filter out remote
323 : // mounts on Unix-like systems:
324 0 : if (!sUrl.startsWith("file:///") || lcl_fileOpenable(sUrl))
325 : {
326 0 : xItemList->getByName(sUrl) >>= xSet;
327 0 : seqProperties[s_nOffsetURL ].Value <<= sUrl;
328 :
329 0 : xSet->getPropertyValue(s_sFilter) >>= seqProperties[s_nOffsetFilter ].Value;
330 0 : xSet->getPropertyValue(s_sTitle) >>= seqProperties[s_nOffsetTitle ].Value;
331 0 : xSet->getPropertyValue(s_sPassword) >>= seqProperties[s_nOffsetPassword ].Value;
332 0 : xSet->getPropertyValue(s_sThumbnail)>>= seqProperties[s_nOffsetThumbnail].Value;
333 0 : aRet[nCount++] = seqProperties;
334 0 : }
335 : }
336 0 : catch(const uno::Exception& ex)
337 : {
338 : // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
339 : // "FILEOPEN: No Recent Documents..." discusses a problem
340 : // with corrupted /org.openoffice.Office/Histories/Histories
341 : // configuration items; to work around that problem, simply
342 : // ignore such corrupted individual items here, so that at
343 : // least newly added items are successfully reported back
344 : // from this function:
345 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
346 : }
347 : }
348 : assert(nCount <= nLength);
349 1 : aRet.realloc(nCount);
350 2 : return aRet;
351 : }
352 :
353 3155 : void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory,
354 : const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
355 : const OUString& sPassword, const OUString& sThumbnail)
356 : {
357 3155 : uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
358 3155 : if (!xListAccess.is())
359 0 : return;
360 :
361 3155 : impl_truncateList(eHistory, GetCapacity(eHistory));
362 :
363 3155 : sal_Int32 nMaxSize = GetCapacity(eHistory);
364 3155 : if (nMaxSize == 0)
365 0 : return;
366 :
367 6310 : uno::Reference<container::XNameContainer> xItemList;
368 6310 : uno::Reference<container::XNameContainer> xOrderList;
369 6310 : uno::Reference<beans::XPropertySet> xSet;
370 :
371 : try
372 : {
373 3155 : xListAccess->getByName(s_sItemList) >>= xItemList;
374 3155 : xListAccess->getByName(s_sOrderList) >>= xOrderList;
375 3155 : sal_Int32 nLength = xOrderList->getElementNames().getLength();
376 :
377 : // The item to be appended already exists
378 3155 : if (xItemList->hasByName(sURL))
379 : {
380 : // update the thumbnail
381 1299 : xItemList->getByName(sURL) >>= xSet;
382 1299 : xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail));
383 :
384 1392 : for (sal_Int32 i=0; i<nLength; ++i)
385 : {
386 1392 : OUString aItem;
387 1392 : xOrderList->getByName(OUString::number(i)) >>= xSet;
388 1392 : xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
389 :
390 1392 : if (aItem == sURL)
391 : {
392 1392 : for (sal_Int32 j = i - 1; j >= 0; --j)
393 : {
394 93 : uno::Reference<beans::XPropertySet> xPrevSet;
395 186 : uno::Reference<beans::XPropertySet> xNextSet;
396 93 : xOrderList->getByName(OUString::number(j+1)) >>= xPrevSet;
397 93 : xOrderList->getByName(OUString::number(j)) >>= xNextSet;
398 :
399 186 : OUString sTemp;
400 93 : xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
401 93 : xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
402 93 : }
403 1299 : xOrderList->getByName(OUString::number(0)) >>= xSet;
404 1299 : xSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(aItem));
405 1299 : break;
406 : }
407 93 : }
408 :
409 1299 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
410 : }
411 : else // The item to be appended does not exist yet
412 : {
413 1856 : uno::Reference<lang::XSingleServiceFactory> xFac;
414 3712 : uno::Reference<uno::XInterface> xInst;
415 3712 : uno::Reference<beans::XPropertySet> xPrevSet;
416 3712 : uno::Reference<beans::XPropertySet> xNextSet;
417 :
418 : // Append new item to OrderList.
419 1856 : if ( nLength == nMaxSize )
420 : {
421 1249 : OUString sRemove;
422 1249 : xOrderList->getByName(OUString::number(nLength-1)) >>= xSet;
423 1249 : xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove;
424 : try
425 : {
426 1249 : xItemList->removeByName(sRemove);
427 : }
428 0 : catch (container::NoSuchElementException &)
429 : {
430 : // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
431 : // "FILEOPEN: No Recent Documents..." discusses a problem
432 : // with corrupted /org.openoffice.Office/Histories/Histories
433 : // configuration items; to work around that problem, simply
434 : // ignore such corrupted individual items here, so that at
435 : // least newly added items are successfully added:
436 0 : if (!sRemove.isEmpty())
437 : {
438 0 : throw;
439 : }
440 1249 : }
441 : }
442 1856 : if (nLength != nMaxSize)
443 : {
444 607 : xFac = uno::Reference<lang::XSingleServiceFactory>(xOrderList, uno::UNO_QUERY);
445 607 : xInst = xFac->createInstance();
446 607 : OUString sPush = OUString::number(nLength++);
447 607 : xOrderList->insertByName(sPush, uno::makeAny(xInst));
448 : }
449 38367 : for (sal_Int32 j=nLength-1; j>0; --j)
450 : {
451 36511 : xOrderList->getByName( OUString::number(j) ) >>= xPrevSet;
452 36511 : xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
453 36511 : OUString sTemp;
454 36511 : xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
455 36511 : xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
456 36511 : }
457 1856 : xOrderList->getByName( OUString::number(0) ) >>= xSet;
458 1856 : xSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sURL));
459 :
460 : // Append the item to ItemList.
461 1856 : xFac = uno::Reference<lang::XSingleServiceFactory>(xItemList, uno::UNO_QUERY);
462 1856 : xInst = xFac->createInstance();
463 1856 : xItemList->insertByName(sURL, uno::makeAny(xInst));
464 :
465 1856 : xSet = uno::Reference<beans::XPropertySet>(xInst, uno::UNO_QUERY);
466 1856 : xSet->setPropertyValue(s_sFilter, uno::makeAny(sFilter));
467 1856 : xSet->setPropertyValue(s_sTitle, uno::makeAny(sTitle));
468 1856 : xSet->setPropertyValue(s_sPassword, uno::makeAny(sPassword));
469 1856 : xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail));
470 :
471 3712 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
472 : }
473 : }
474 0 : catch(const uno::Exception& ex)
475 : {
476 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
477 3155 : }
478 : }
479 :
480 0 : void SvtHistoryOptions_Impl::DeleteItem(EHistoryType eHistory, const OUString& sURL)
481 : {
482 0 : uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
483 0 : if (!xListAccess.is())
484 0 : return;
485 :
486 0 : uno::Reference<container::XNameContainer> xItemList;
487 0 : uno::Reference<container::XNameContainer> xOrderList;
488 0 : uno::Reference<beans::XPropertySet> xSet;
489 :
490 : try
491 : {
492 0 : xListAccess->getByName(s_sItemList) >>= xItemList;
493 0 : xListAccess->getByName(s_sOrderList) >>= xOrderList;
494 0 : sal_Int32 nLength = xOrderList->getElementNames().getLength();
495 :
496 : // if it does not exist, nothing to do
497 0 : if (!xItemList->hasByName(sURL))
498 0 : return;
499 :
500 : // it's the last one, just clear the lists
501 0 : if (nLength == 1)
502 : {
503 0 : Clear(eHistory);
504 0 : return;
505 : }
506 :
507 : // find it in the OrderList
508 0 : sal_Int32 nFromWhere = 0;
509 0 : for (; nFromWhere < nLength - 1; ++nFromWhere)
510 : {
511 0 : OUString aItem;
512 0 : xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet;
513 0 : xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
514 :
515 0 : if (aItem == sURL)
516 0 : break;
517 0 : }
518 :
519 : // and shift the rest of the items in OrderList accordingly
520 0 : for (sal_Int32 i = nFromWhere; i < nLength - 1; ++i)
521 : {
522 0 : uno::Reference<beans::XPropertySet> xPrevSet;
523 0 : uno::Reference<beans::XPropertySet> xNextSet;
524 0 : xOrderList->getByName(OUString::number(i)) >>= xPrevSet;
525 0 : xOrderList->getByName(OUString::number(i + 1)) >>= xNextSet;
526 :
527 0 : OUString sTemp;
528 0 : xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
529 0 : xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
530 0 : }
531 0 : xOrderList->removeByName(OUString::number(nLength - 1));
532 :
533 : // and finally remove it from the ItemList
534 0 : xItemList->removeByName(sURL);
535 :
536 0 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
537 : }
538 0 : catch (const uno::Exception& ex)
539 : {
540 : SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
541 0 : }
542 : }
543 :
544 : // initialize static member
545 : // DON'T DO IT IN YOUR HEADER!
546 : // see definition for further information
547 :
548 : SvtHistoryOptions_Impl* SvtHistoryOptions::m_pDataContainer = NULL;
549 : sal_Int32 SvtHistoryOptions::m_nRefCount = 0;
550 :
551 : // constructor
552 :
553 3572 : SvtHistoryOptions::SvtHistoryOptions()
554 : {
555 3572 : MutexGuard aGuard(theHistoryOptionsMutex::get());
556 :
557 : // Increase our refcount ...
558 3572 : ++m_nRefCount;
559 : // ... and initialize our data container only if it not already exist!
560 3572 : if( m_pDataContainer == NULL )
561 : {
562 208 : m_pDataContainer = new SvtHistoryOptions_Impl;
563 :
564 208 : ItemHolder1::holdConfigItem(E_HISTORYOPTIONS);
565 3572 : }
566 3572 : }
567 :
568 : // destructor
569 :
570 7346 : SvtHistoryOptions::~SvtHistoryOptions()
571 : {
572 3570 : MutexGuard aGuard(theHistoryOptionsMutex::get());
573 :
574 : // Decrease our refcount.
575 3570 : --m_nRefCount;
576 : // If last instance was deleted ...
577 : // we must destroy our static data container!
578 3570 : if( m_nRefCount <= 0 )
579 : {
580 206 : delete m_pDataContainer;
581 206 : m_pDataContainer = NULL;
582 3570 : }
583 3776 : }
584 :
585 208 : sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const
586 : {
587 208 : MutexGuard aGuard(theHistoryOptionsMutex::get());
588 :
589 208 : return m_pDataContainer->GetCapacity(eHistory);
590 : }
591 :
592 0 : void SvtHistoryOptions::Clear( EHistoryType eHistory )
593 : {
594 0 : MutexGuard aGuard(theHistoryOptionsMutex::get());
595 :
596 0 : m_pDataContainer->Clear( eHistory );
597 0 : }
598 :
599 1 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const
600 : {
601 1 : MutexGuard aGuard(theHistoryOptionsMutex::get());
602 :
603 1 : return m_pDataContainer->GetList( eHistory );
604 : }
605 :
606 3155 : void SvtHistoryOptions::AppendItem(EHistoryType eHistory,
607 : const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
608 : const OUString& sPassword, const OUString& sThumbnail)
609 : {
610 3155 : MutexGuard aGuard(theHistoryOptionsMutex::get());
611 :
612 3155 : m_pDataContainer->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail);
613 3155 : }
614 :
615 0 : void SvtHistoryOptions::DeleteItem(EHistoryType eHistory, const OUString& sURL)
616 : {
617 0 : MutexGuard aGuard(theHistoryOptionsMutex::get());
618 :
619 0 : m_pDataContainer->DeleteItem(eHistory, sURL);
620 0 : }
621 :
622 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|