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