tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / framework / source / dispatch / loaddispatcher.cxx
blob04ea5cf5c0d07ddaf6e664b043a3bf2e3df5d174
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 <dispatch/loaddispatcher.hxx>
21 #include <loadenv/loadenvexception.hxx>
22 #include <sal/log.hxx>
24 #include <com/sun/star/frame/DispatchResultState.hpp>
25 #include <utility>
27 namespace framework{
29 LoadDispatcher::LoadDispatcher(const css::uno::Reference< css::uno::XComponentContext >& xContext ,
30 const css::uno::Reference< css::frame::XFrame >& xOwnerFrame ,
31 OUString sTargetName ,
32 sal_Int32 nSearchFlags)
33 : m_xOwnerFrame (xOwnerFrame )
34 , m_sTarget (std::move(sTargetName ))
35 , m_nSearchFlags(nSearchFlags)
36 , m_aLoader (xContext )
40 LoadDispatcher::~LoadDispatcher()
44 void SAL_CALL LoadDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
45 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
46 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
48 impl_dispatch( aURL, lArguments, xListener );
51 void SAL_CALL LoadDispatcher::dispatch(const css::util::URL& aURL ,
52 const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
54 impl_dispatch( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
57 css::uno::Any SAL_CALL LoadDispatcher::dispatchWithReturnValue( const css::util::URL& rURL,
58 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
60 return impl_dispatch( rURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
63 void SAL_CALL LoadDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
64 const css::util::URL& /*aURL*/ )
68 void SAL_CALL LoadDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
69 const css::util::URL& /*aURL*/ )
73 css::uno::Any LoadDispatcher::impl_dispatch( const css::util::URL& rURL,
74 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
75 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
77 // Attention: May be nobody outside hold such temp. dispatch object alive (because
78 // the container in which we resist isn't implemented threadsafe but updated by a timer
79 // and clear our reference...) we should hold us self alive!
80 css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::frame::XNotifyingDispatch* >(this), css::uno::UNO_QUERY);
82 osl::MutexGuard g(m_mutex);
84 // We are the only client of this load env object... but
85 // may a dispatch request before is still in progress (?!).
86 // Then we should wait a little bit and block this new request.
87 // In case we run into the timeout, we should reject this new request
88 // and return "FAILED" as result. Otherwise we can start this new operation.
89 if (!m_aLoader.waitWhileLoading(2000)) // => 2 sec.
91 if (xListener.is())
92 xListener->dispatchFinished(
93 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::DONTKNOW, css::uno::Any())); // DONTKNOW? ... not really started ... not really failed :-)
96 css::uno::Reference< css::frame::XFrame > xBaseFrame(m_xOwnerFrame.get(), css::uno::UNO_QUERY);
97 if (!xBaseFrame.is() && xListener.is())
98 xListener->dispatchFinished(
99 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
101 // OK ... now the internal loader seems to be usable for new requests
102 // and our owner frame seems to be valid for such operations.
103 // Initialize it with all new but needed properties and start the loading.
104 css::uno::Reference< css::lang::XComponent > xComponent;
107 m_aLoader.startLoading( rURL.Complete, lArguments, xBaseFrame, m_sTarget, m_nSearchFlags, LoadEnvFeatures::AllowContentHandler | LoadEnvFeatures::WorkWithUI);
108 m_aLoader.waitWhileLoading(); // wait for ever!
109 xComponent = m_aLoader.getTargetComponent();
111 // TODO thinking about asynchronous operations and listener support
113 catch(const LoadEnvException& e)
115 SAL_WARN(
116 "fwk.dispatch",
117 "caught LoadEnvException " << +e.m_nID << " \"" << e.m_sMessage
118 << "\""
119 << (e.m_exOriginal.has<css::uno::Exception>()
120 ? (", " + e.m_exOriginal.getValueTypeName() + " \""
121 + e.m_exOriginal.get<css::uno::Exception>().Message
122 + "\"")
123 : OUString())
124 << " while dispatching <" << rURL.Complete << ">");
125 xComponent.clear();
128 if (xListener.is())
130 if (xComponent.is())
131 xListener->dispatchFinished(
132 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::SUCCESS, css::uno::Any()));
133 else
134 xListener->dispatchFinished(
135 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
138 // return the model - like loadComponentFromURL()
139 css::uno::Any aRet;
140 if ( xComponent.is () )
141 aRet <<= xComponent;
143 return aRet;
146 } // namespace framework
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */