1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "SlsCacheConfiguration.hxx"
21 #include <osl/mutex.hxx>
22 #include <rtl/instance.hxx>
23 #include <vcl/svapp.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
28 #include <com/sun/star/configuration/theDefaultProvider.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
34 namespace sd
{ namespace slidesorter
{ namespace cache
{
38 typedef ::boost::shared_ptr
<CacheConfiguration
> CacheConfigSharedPtr
;
40 public rtl::Static
<CacheConfigSharedPtr
, theInstance
> {};
43 ::boost::weak_ptr
<CacheConfiguration
> CacheConfiguration::mpWeakInstance
;
44 Timer
CacheConfiguration::maReleaseTimer
;
46 ::boost::shared_ptr
<CacheConfiguration
> CacheConfiguration::Instance()
48 SolarMutexGuard aSolarGuard
;
49 CacheConfigSharedPtr
&rInstancePtr
= theInstance::get();
50 if (rInstancePtr
.get() == NULL
)
52 // Maybe somebody else kept a previously created instance alive.
53 if ( ! mpWeakInstance
.expired())
54 rInstancePtr
= ::boost::shared_ptr
<CacheConfiguration
>(mpWeakInstance
);
55 if (rInstancePtr
.get() == NULL
)
57 // We have to create a new instance.
58 rInstancePtr
.reset(new CacheConfiguration());
59 mpWeakInstance
= rInstancePtr
;
60 // Prepare to release this instance in the near future.
61 maReleaseTimer
.SetTimeoutHdl(
62 LINK(rInstancePtr
.get(),CacheConfiguration
,TimerCallback
));
63 maReleaseTimer
.SetTimeout(5000 /* 5s */);
64 maReleaseTimer
.Start();
70 CacheConfiguration::CacheConfiguration()
72 // Get the cache size from configuration.
73 const OUString
sPathToImpressConfigurationRoot("/org.openoffice.Office.Impress/");
74 const OUString
sPathToNode("MultiPaneGUI/SlideSorter/PreviewCache");
78 // Obtain access to the configuration.
79 Reference
<lang::XMultiServiceFactory
> xProvider
=
80 configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() );
82 // Obtain access to Impress configuration.
83 Sequence
<Any
> aCreationArguments(3);
84 aCreationArguments
[0] = makeAny(beans::PropertyValue(
87 makeAny(sPathToImpressConfigurationRoot
),
88 beans::PropertyState_DIRECT_VALUE
));
89 aCreationArguments
[1] = makeAny(beans::PropertyValue(
92 makeAny((sal_Int32
)-1),
93 beans::PropertyState_DIRECT_VALUE
));
94 aCreationArguments
[2] = makeAny(beans::PropertyValue(
98 beans::PropertyState_DIRECT_VALUE
));
100 Reference
<XInterface
> xRoot (xProvider
->createInstanceWithArguments(
101 "com.sun.star.configuration.ConfigurationAccess",
102 aCreationArguments
));
105 Reference
<container::XHierarchicalNameAccess
> xHierarchy (xRoot
, UNO_QUERY
);
106 if ( ! xHierarchy
.is())
109 // Get the node for the slide sorter preview cache.
110 mxCacheNode
= Reference
<container::XNameAccess
>(
111 xHierarchy
->getByHierarchicalName(sPathToNode
),
114 catch (RuntimeException
&)
122 Any
CacheConfiguration::GetValue (const OUString
& rName
)
126 if (mxCacheNode
!= NULL
)
130 aResult
= mxCacheNode
->getByName(rName
);
140 IMPL_STATIC_LINK_NOARG_TYPED(CacheConfiguration
, TimerCallback
, Timer
*, void)
142 CacheConfigSharedPtr
&rInstancePtr
= theInstance::get();
143 // Release our reference to the instance.
144 rInstancePtr
.reset();
147 } } } // end of namespace ::sd::slidesorter::cache
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */