bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / slidesorter / cache / SlsCacheConfiguration.cxx
blob583601ba25bbe70ba9733283b1b42126c9be9019
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <rtl/instance.hxx>
22 #include <vcl/svapp.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <comphelper/propertysequence.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/configuration/theDefaultProvider.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
35 namespace sd { namespace slidesorter { namespace cache {
37 namespace
39 typedef std::shared_ptr<CacheConfiguration> CacheConfigSharedPtr;
40 class theInstance :
41 public rtl::Static<CacheConfigSharedPtr, theInstance> {};
44 std::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
46 std::shared_ptr<CacheConfiguration> CacheConfiguration::Instance()
48 SolarMutexGuard aSolarGuard;
49 CacheConfigSharedPtr &rInstancePtr = theInstance::get();
50 if (rInstancePtr.get() == nullptr)
52 // Maybe somebody else kept a previously created instance alive.
53 if ( ! mpWeakInstance.expired())
54 rInstancePtr = std::shared_ptr<CacheConfiguration>(mpWeakInstance);
55 if (rInstancePtr.get() == nullptr)
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 rInstancePtr->m_ReleaseTimer.SetInvokeHandler(
62 LINK(rInstancePtr.get(),CacheConfiguration,TimerCallback));
63 rInstancePtr->m_ReleaseTimer.SetTimeout(5000 /* 5s */);
64 rInstancePtr->m_ReleaseTimer.SetDebugName("sd::CacheConfiguration maReleaseTimer");
65 rInstancePtr->m_ReleaseTimer.Start();
68 return rInstancePtr;
71 CacheConfiguration::CacheConfiguration()
73 // Get the cache size from configuration.
74 const OUString sPathToImpressConfigurationRoot("/org.openoffice.Office.Impress/");
75 const OUString sPathToNode("MultiPaneGUI/SlideSorter/PreviewCache");
77 try
79 // Obtain access to the configuration.
80 Reference<lang::XMultiServiceFactory> xProvider =
81 configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() );
83 // Obtain access to Impress configuration.
84 Sequence<Any> aCreationArguments(comphelper::InitAnyPropertySequence(
86 {"nodepath", makeAny(sPathToImpressConfigurationRoot)},
87 {"depth", makeAny(sal_Int32(-1))}
88 }));
90 Reference<XInterface> xRoot (xProvider->createInstanceWithArguments(
91 "com.sun.star.configuration.ConfigurationAccess",
92 aCreationArguments));
93 if ( ! xRoot.is())
94 return;
95 Reference<container::XHierarchicalNameAccess> xHierarchy (xRoot, UNO_QUERY);
96 if ( ! xHierarchy.is())
97 return;
99 // Get the node for the slide sorter preview cache.
100 mxCacheNode.set( xHierarchy->getByHierarchicalName(sPathToNode), UNO_QUERY);
102 catch (RuntimeException &)
105 catch (Exception &)
110 Any CacheConfiguration::GetValue (const OUString& rName)
112 Any aResult;
114 if (mxCacheNode != nullptr)
118 aResult = mxCacheNode->getByName(rName);
120 catch (Exception &)
125 return aResult;
128 IMPL_STATIC_LINK_NOARG(CacheConfiguration, TimerCallback, Timer *, void)
130 CacheConfigSharedPtr &rInstancePtr = theInstance::get();
131 // Release our reference to the instance.
132 rInstancePtr.reset();
133 // note: if there are no other references to the instance, m_ReleaseTimer
134 // will be deleted now
137 void CacheConfiguration::Shutdown()
139 CacheConfigSharedPtr &rInstancePtr = theInstance::get();
140 rInstancePtr.reset();
141 assert(mpWeakInstance.expired()); // ensure m_ReleaseTimer is destroyed
144 } } } // end of namespace ::sd::slidesorter::cache
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */