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