12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52f86921cSAndrew Rist  * distributed with this work for additional information
62f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
102f86921cSAndrew Rist  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122f86921cSAndrew Rist  *
132f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist  * software distributed under the License is distributed on an
152f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
172f86921cSAndrew Rist  * specific language governing permissions and limitations
182f86921cSAndrew Rist  * under the License.
192f86921cSAndrew Rist  *
202f86921cSAndrew Rist  *************************************************************/
212f86921cSAndrew Rist 
222f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*421ed02eSdamjan #include "precompiled_tdoc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "osl/mutex.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "com/sun/star/lang/XTypeProvider.hpp"
30cdf0e10cSrcweir #include "com/sun/star/task/DocumentPasswordRequest.hpp"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "cppuhelper/typeprovider.hxx"
33cdf0e10cSrcweir #include "ucbhelper/interactionrequest.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "tdoc_passwordrequest.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir using namespace tdoc_ucp;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace tdoc_ucp
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     class InteractionSupplyPassword :
43cdf0e10cSrcweir                       public ucbhelper::InteractionContinuation,
44cdf0e10cSrcweir                       public lang::XTypeProvider,
45cdf0e10cSrcweir                       public task::XInteractionPassword
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir     public:
InteractionSupplyPassword(ucbhelper::InteractionRequest * pRequest)48cdf0e10cSrcweir         InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
49cdf0e10cSrcweir         : InteractionContinuation( pRequest ) {}
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         // XInterface
52cdf0e10cSrcweir         virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
53cdf0e10cSrcweir             throw ( uno::RuntimeException );
54cdf0e10cSrcweir         virtual void SAL_CALL acquire()
55cdf0e10cSrcweir             throw ();
56cdf0e10cSrcweir         virtual void SAL_CALL release()
57cdf0e10cSrcweir             throw ();
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         // XTypeProvider
60cdf0e10cSrcweir         virtual uno::Sequence< uno::Type > SAL_CALL getTypes()
61cdf0e10cSrcweir             throw ( uno::RuntimeException );
62cdf0e10cSrcweir         virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
63cdf0e10cSrcweir             throw ( uno::RuntimeException );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         // XInteractionContinuation
66cdf0e10cSrcweir         virtual void SAL_CALL select()
67cdf0e10cSrcweir             throw ( uno::RuntimeException );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         // XInteractionPassword
70cdf0e10cSrcweir         virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd )
71cdf0e10cSrcweir             throw ( uno::RuntimeException );
72cdf0e10cSrcweir         virtual rtl::OUString SAL_CALL getPassword()
73cdf0e10cSrcweir             throw ( uno::RuntimeException );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     private:
76cdf0e10cSrcweir         osl::Mutex m_aMutex;
77cdf0e10cSrcweir         rtl::OUString m_aPassword;
78cdf0e10cSrcweir     };
79cdf0e10cSrcweir } // namespace tdoc_ucp
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //=========================================================================
82cdf0e10cSrcweir //=========================================================================
83cdf0e10cSrcweir //
84cdf0e10cSrcweir // InteractionSupplyPassword Implementation.
85cdf0e10cSrcweir //
86cdf0e10cSrcweir //=========================================================================
87cdf0e10cSrcweir //=========================================================================
88cdf0e10cSrcweir 
89cdf0e10cSrcweir //=========================================================================
90cdf0e10cSrcweir //
91cdf0e10cSrcweir // XInterface methods.
92cdf0e10cSrcweir //
93cdf0e10cSrcweir //=========================================================================
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // virtual
acquire()96cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::acquire()
97cdf0e10cSrcweir     throw()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     OWeakObject::acquire();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //=========================================================================
103cdf0e10cSrcweir // virtual
release()104cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::release()
105cdf0e10cSrcweir     throw()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     OWeakObject::release();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //=========================================================================
111cdf0e10cSrcweir // virtual
112cdf0e10cSrcweir uno::Any SAL_CALL
queryInterface(const uno::Type & rType)113cdf0e10cSrcweir InteractionSupplyPassword::queryInterface( const uno::Type & rType )
114cdf0e10cSrcweir     throw ( uno::RuntimeException )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     uno::Any aRet = cppu::queryInterface( rType,
117cdf0e10cSrcweir                 static_cast< lang::XTypeProvider * >( this ),
118cdf0e10cSrcweir                 static_cast< task::XInteractionContinuation * >( this ),
119cdf0e10cSrcweir                 static_cast< task::XInteractionPassword * >( this ) );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     return aRet.hasValue()
122cdf0e10cSrcweir             ? aRet : InteractionContinuation::queryInterface( rType );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //=========================================================================
126cdf0e10cSrcweir //
127cdf0e10cSrcweir // XTypeProvider methods.
128cdf0e10cSrcweir //
129cdf0e10cSrcweir //=========================================================================
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // virtual
132cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL
getImplementationId()133cdf0e10cSrcweir InteractionSupplyPassword::getImplementationId()
134cdf0e10cSrcweir     throw( uno::RuntimeException )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     static cppu::OImplementationId * pId = 0;
137cdf0e10cSrcweir     if ( !pId )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
140cdf0e10cSrcweir         if ( !pId )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             static cppu::OImplementationId id( sal_False );
143cdf0e10cSrcweir             pId = &id;
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir     return (*pId).getImplementationId();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //=========================================================================
150cdf0e10cSrcweir // virtual
getTypes()151cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
152cdf0e10cSrcweir     throw( uno::RuntimeException )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     static cppu::OTypeCollection * pCollection = 0;
155cdf0e10cSrcweir     if ( !pCollection )
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
158cdf0e10cSrcweir         if ( !pCollection )
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             static cppu::OTypeCollection collection(
161cdf0e10cSrcweir                 getCppuType( static_cast<
162cdf0e10cSrcweir                     uno::Reference< lang::XTypeProvider > * >( 0 ) ),
163cdf0e10cSrcweir                 getCppuType( static_cast<
164cdf0e10cSrcweir                     uno::Reference< task::XInteractionPassword > * >( 0 ) ) );
165cdf0e10cSrcweir             pCollection = &collection;
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir     return (*pCollection).getTypes();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //=========================================================================
172cdf0e10cSrcweir //
173cdf0e10cSrcweir // XInteractionContinuation methods.
174cdf0e10cSrcweir //
175cdf0e10cSrcweir //=========================================================================
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // virtual
select()178cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::select()
179cdf0e10cSrcweir     throw( uno::RuntimeException )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     recordSelection();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir //=========================================================================
185cdf0e10cSrcweir //
186cdf0e10cSrcweir // XInteractionPassword methods.
187cdf0e10cSrcweir //
188cdf0e10cSrcweir //=========================================================================
189cdf0e10cSrcweir 
190cdf0e10cSrcweir // virtual
191cdf0e10cSrcweir void SAL_CALL
setPassword(const::rtl::OUString & aPasswd)192cdf0e10cSrcweir InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd )
193cdf0e10cSrcweir     throw ( uno::RuntimeException )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
196cdf0e10cSrcweir     m_aPassword = aPasswd;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // virtual
getPassword()200cdf0e10cSrcweir rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword()
201cdf0e10cSrcweir     throw ( uno::RuntimeException )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
204cdf0e10cSrcweir     return m_aPassword;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //=========================================================================
208cdf0e10cSrcweir //=========================================================================
209cdf0e10cSrcweir //
210cdf0e10cSrcweir // DocumentPasswordRequest Implementation.
211cdf0e10cSrcweir //
212cdf0e10cSrcweir //=========================================================================
213cdf0e10cSrcweir //=========================================================================
214cdf0e10cSrcweir 
DocumentPasswordRequest(task::PasswordRequestMode eMode,const rtl::OUString & rDocumentName)215cdf0e10cSrcweir DocumentPasswordRequest::DocumentPasswordRequest(
216cdf0e10cSrcweir     task::PasswordRequestMode eMode,
217cdf0e10cSrcweir     const rtl::OUString & rDocumentName )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     // Fill request...
220cdf0e10cSrcweir     task::DocumentPasswordRequest aRequest;
221cdf0e10cSrcweir //    aRequest.Message        = // OUString
222cdf0e10cSrcweir //    aRequest.Context        = // XInterface
223cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
224cdf0e10cSrcweir     aRequest.Mode           = eMode;
225cdf0e10cSrcweir     aRequest.Name           = rDocumentName;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     setRequest( uno::makeAny( aRequest ) );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     // Fill continuations...
230cdf0e10cSrcweir     uno::Sequence<
231cdf0e10cSrcweir         uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
232cdf0e10cSrcweir     aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
233cdf0e10cSrcweir     aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
234cdf0e10cSrcweir     aContinuations[ 2 ] = new InteractionSupplyPassword( this );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     setContinuations( aContinuations );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
239