android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / slidesorter / cache / SlsCacheConfiguration.cxx
blobfd08c76276c9f9ef616c2fbfcf5b8444e3ce76b1
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 <vcl/svapp.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <comphelper/propertysequence.hxx>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/configuration/theDefaultProvider.hpp>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
33 namespace sd::slidesorter::cache {
35 namespace
37 typedef std::shared_ptr<CacheConfiguration> CacheConfigSharedPtr;
38 CacheConfigSharedPtr& theInstance()
40 static CacheConfigSharedPtr SINGLETON;
41 return SINGLETON;
45 std::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
47 std::shared_ptr<CacheConfiguration> CacheConfiguration::Instance()
49 SolarMutexGuard aSolarGuard;
50 CacheConfigSharedPtr &rInstancePtr = theInstance();
51 if (!rInstancePtr)
53 // Maybe somebody else kept a previously created instance alive.
54 if ( ! mpWeakInstance.expired())
55 rInstancePtr = std::shared_ptr<CacheConfiguration>(mpWeakInstance);
56 if (!rInstancePtr)
58 // We have to create a new instance.
59 rInstancePtr.reset(new CacheConfiguration());
60 mpWeakInstance = rInstancePtr;
61 // Prepare to release this instance in the near future.
62 rInstancePtr->m_ReleaseTimer.SetInvokeHandler(
63 LINK(rInstancePtr.get(),CacheConfiguration,TimerCallback));
64 rInstancePtr->m_ReleaseTimer.SetTimeout(5000 /* 5s */);
65 rInstancePtr->m_ReleaseTimer.Start();
68 return rInstancePtr;
71 CacheConfiguration::CacheConfiguration()
72 : m_ReleaseTimer("sd::CacheConfiguration maReleaseTimer")
74 // Get the cache size from configuration.
75 try
77 // Obtain access to the configuration.
78 Reference<lang::XMultiServiceFactory> xProvider =
79 configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() );
81 // Obtain access to Impress configuration.
82 Sequence<Any> aCreationArguments(comphelper::InitAnyPropertySequence(
84 {"nodepath", Any(OUString("/org.openoffice.Office.Impress/"))},
85 {"depth", Any(sal_Int32(-1))}
86 }));
88 Reference<XInterface> xRoot (xProvider->createInstanceWithArguments(
89 "com.sun.star.configuration.ConfigurationAccess",
90 aCreationArguments));
91 if ( ! xRoot.is())
92 return;
93 Reference<container::XHierarchicalNameAccess> xHierarchy (xRoot, UNO_QUERY);
94 if ( ! xHierarchy.is())
95 return;
97 // Get the node for the slide sorter preview cache.
98 mxCacheNode.set( xHierarchy->getByHierarchicalName("MultiPaneGUI/SlideSorter/PreviewCache"), UNO_QUERY);
100 catch (RuntimeException &)
103 catch (Exception &)
108 Any CacheConfiguration::GetValue (const OUString& rName)
110 Any aResult;
112 if (mxCacheNode != nullptr)
116 aResult = mxCacheNode->getByName(rName);
118 catch (Exception &)
123 return aResult;
126 IMPL_STATIC_LINK_NOARG(CacheConfiguration, TimerCallback, Timer *, void)
128 CacheConfigSharedPtr &rInstancePtr = theInstance();
129 // Release our reference to the instance.
130 rInstancePtr.reset();
131 // note: if there are no other references to the instance, m_ReleaseTimer
132 // will be deleted now
135 void CacheConfiguration::Shutdown()
137 CacheConfigSharedPtr &rInstancePtr = theInstance();
138 rInstancePtr.reset();
139 assert(mpWeakInstance.expired()); // ensure m_ReleaseTimer is destroyed
142 } // end of namespace ::sd::slidesorter::cache
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */