1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #if ! defined INCLUDED_DP_INTERACT_H
25 #define INCLUDED_DP_INTERACT_H
26 
27 #include "rtl/ref.hxx"
28 #include "cppuhelper/implbase1.hxx"
29 #include "com/sun/star/uno/XComponentContext.hpp"
30 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
31 #include "com/sun/star/task/XAbortChannel.hpp"
32 #include "dp_misc_api.hxx"
33 
34 namespace css = ::com::sun::star;
35 
36 namespace dp_misc
37 {
38 
progressUpdate(::rtl::OUString const & status,css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv)39 inline void progressUpdate(
40     ::rtl::OUString const & status,
41     css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
42 {
43     if (xCmdEnv.is()) {
44         css::uno::Reference<css::ucb::XProgressHandler> xProgressHandler(
45             xCmdEnv->getProgressHandler() );
46         if (xProgressHandler.is()) {
47             xProgressHandler->update( css::uno::makeAny(status) );
48         }
49     }
50 }
51 
52 //==============================================================================
53 class ProgressLevel
54 {
55     css::uno::Reference<css::ucb::XProgressHandler> m_xProgressHandler;
56 
57 public:
58     inline ~ProgressLevel();
59     inline ProgressLevel(
60         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
61         ::rtl::OUString const & status );
62 
63     inline void update( ::rtl::OUString const & status ) const;
64     inline void update( css::uno::Any const & status ) const;
65 };
66 
67 //______________________________________________________________________________
ProgressLevel(css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,::rtl::OUString const & status)68 inline ProgressLevel::ProgressLevel(
69     css::uno::Reference< css::ucb::XCommandEnvironment > const & xCmdEnv,
70     ::rtl::OUString const & status )
71 {
72     if (xCmdEnv.is())
73         m_xProgressHandler = xCmdEnv->getProgressHandler();
74     if (m_xProgressHandler.is())
75         m_xProgressHandler->push( css::uno::makeAny(status) );
76 }
77 
78 //______________________________________________________________________________
~ProgressLevel()79 inline ProgressLevel::~ProgressLevel()
80 {
81     if (m_xProgressHandler.is())
82         m_xProgressHandler->pop();
83 }
84 
85 //______________________________________________________________________________
update(::rtl::OUString const & status) const86 inline void ProgressLevel::update( ::rtl::OUString const & status ) const
87 {
88     if (m_xProgressHandler.is())
89         m_xProgressHandler->update( css::uno::makeAny(status) );
90 }
91 
92 //______________________________________________________________________________
update(css::uno::Any const & status) const93 inline void ProgressLevel::update( css::uno::Any const & status ) const
94 {
95     if (m_xProgressHandler.is())
96         m_xProgressHandler->update( status );
97 }
98 
99 //##############################################################################
100 
101 /** @return true if ia handler is present and any selection has been chosen
102  */
103 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool interactContinuation(
104     css::uno::Any const & request,
105     css::uno::Type const & continuation,
106     css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
107     bool * pcont, bool * pabort );
108 
109 //##############################################################################
110 
111 //==============================================================================
112 class DESKTOP_DEPLOYMENTMISC_DLLPUBLIC AbortChannel :
113     public ::cppu::WeakImplHelper1<css::task::XAbortChannel>
114 {
115     bool m_aborted;
116     css::uno::Reference<css::task::XAbortChannel> m_xNext;
117 
118 public:
AbortChannel()119     inline AbortChannel() : m_aborted( false ) {}
get(css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel)120     inline static AbortChannel * get(
121         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel )
122         { return static_cast<AbortChannel *>(xAbortChannel.get()); }
123 
isAborted() const124     inline bool isAborted() const { return m_aborted; }
125 
126     // XAbortChannel
127     virtual void SAL_CALL sendAbort() throw (css::uno::RuntimeException);
128 
129     class SAL_DLLPRIVATE Chain
130     {
131         const ::rtl::Reference<AbortChannel> m_abortChannel;
132     public:
Chain(::rtl::Reference<AbortChannel> const & abortChannel,css::uno::Reference<css::task::XAbortChannel> const & xNext)133         inline Chain(
134             ::rtl::Reference<AbortChannel> const & abortChannel,
135             css::uno::Reference<css::task::XAbortChannel> const & xNext )
136             : m_abortChannel( abortChannel )
137             { if (m_abortChannel.is()) m_abortChannel->m_xNext = xNext; }
~Chain()138         inline ~Chain()
139             { if (m_abortChannel.is()) m_abortChannel->m_xNext.clear(); }
140     };
141     friend class Chain;
142 };
143 
144 }
145 
146 #endif
147