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 "configinit.hxx"
21 :
22 : #include "desktop.hrc"
23 : #include "app.hxx"
24 : #include <comphelper/processfactory.hxx>
25 : #include <uno/current_context.hxx>
26 : #include <cppuhelper/implbase1.hxx>
27 : #include <rtl/ustrbuf.hxx>
28 : #include <osl/diagnose.h>
29 : #include <stdio.h>
30 : #include <com/sun/star/task/InteractionHandler.hpp>
31 :
32 :
33 :
34 : namespace uno = ::com::sun::star::uno;
35 : namespace lang = ::com::sun::star::lang;
36 : using uno::UNO_QUERY;
37 :
38 :
39 :
40 : // must be aligned with configmgr/source/misc/configinteractionhandler
41 : static char const CONFIG_ERROR_HANDLER[] = "configuration.interaction-handler";
42 :
43 :
44 :
45 : // ConfigurationErrorHandler
46 :
47 :
48 : namespace
49 : {
50 : typedef uno::Reference< uno::XCurrentContext > CurrentContext;
51 0 : class SimpleCurrentContext : public cppu::WeakImplHelper1< uno::XCurrentContext >
52 : {
53 : CurrentContext m_xChainedContext;
54 : public:
55 : explicit
56 0 : SimpleCurrentContext(const CurrentContext & xChainedContext)
57 0 : : m_xChainedContext(xChainedContext)
58 0 : {}
59 :
60 0 : void install() { uno::setCurrentContext(this); }
61 0 : void deinstall() { uno::setCurrentContext(m_xChainedContext); }
62 :
63 0 : uno::Any getChainedValueByName( OUString const & aName) const
64 : {
65 0 : return m_xChainedContext.is()
66 0 : ? m_xChainedContext->getValueByName(aName)
67 0 : : uno::Any();
68 : }
69 :
70 : // XCurrentContext
71 : virtual uno::Any SAL_CALL
72 : getValueByName( OUString const & aName)
73 : throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
74 : };
75 :
76 : uno::Any SAL_CALL
77 0 : SimpleCurrentContext::getValueByName( OUString const & aName)
78 : throw (uno::RuntimeException, std::exception)
79 : {
80 0 : return getChainedValueByName(aName);
81 : }
82 :
83 : }
84 :
85 :
86 : class ConfigurationErrorHandler::Context : public SimpleCurrentContext
87 : {
88 : public:
89 0 : Context()
90 0 : : SimpleCurrentContext( uno::getCurrentContext() )
91 : {
92 0 : }
93 :
94 0 : virtual ~Context()
95 0 : {
96 0 : }
97 :
98 : // XCurrentContext
99 : virtual uno::Any SAL_CALL
100 : getValueByName( OUString const & aName)
101 : throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
102 :
103 : private:
104 : InteractionHandler m_xHandler;
105 : };
106 :
107 :
108 0 : uno::Any SAL_CALL ConfigurationErrorHandler::Context::getValueByName( OUString const & aName)
109 : throw (uno::RuntimeException, std::exception)
110 : {
111 0 : if ( aName == CONFIG_ERROR_HANDLER )
112 : {
113 0 : if ( !m_xHandler.is() )
114 0 : m_xHandler = ConfigurationErrorHandler::getDefaultInteractionHandler();
115 0 : return uno::Any( m_xHandler );
116 : }
117 0 : return SimpleCurrentContext::getValueByName( aName );
118 : }
119 :
120 :
121 232 : ConfigurationErrorHandler::~ConfigurationErrorHandler()
122 : {
123 116 : deactivate();
124 116 : }
125 :
126 :
127 : /// installs the handler into the current context
128 0 : void ConfigurationErrorHandler::activate()
129 : {
130 0 : if (!m_pContext)
131 : {
132 0 : m_pContext = new Context;
133 0 : m_pContext->acquire();
134 : }
135 0 : m_pContext->install();
136 0 : }
137 :
138 :
139 : /// deinstalls the handler from the current context, restoring the previous context
140 180 : void ConfigurationErrorHandler::deactivate()
141 : {
142 180 : if (m_pContext)
143 : {
144 0 : m_pContext->deinstall();
145 0 : m_pContext->release();
146 0 : m_pContext = 0;
147 : }
148 180 : }
149 :
150 :
151 0 : ConfigurationErrorHandler::InteractionHandler ConfigurationErrorHandler::getDefaultInteractionHandler()
152 : {
153 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
154 0 : InteractionHandler xHandler( com::sun::star::task::InteractionHandler::createWithParent(xContext, 0), UNO_QUERY );
155 0 : return xHandler;
156 : }
157 :
158 :
159 :
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|