LibreOffice Module ucb (master)  1
tdoc_passwordrequest.cxx
Go to the documentation of this file.
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 
21 #include <osl/mutex.hxx>
22 
23 #include <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
25 #include <com/sun/star/task/XInteractionPassword.hpp>
26 
30 
31 #include "tdoc_passwordrequest.hxx"
32 
33 using namespace com::sun::star;
34 using namespace tdoc_ucp;
35 
36 namespace tdoc_ucp
37 {
40  public lang::XTypeProvider,
41  public task::XInteractionPassword
42  {
43  public:
45  : InteractionContinuation( pRequest ) {}
46 
47  // XInterface
48  virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType ) override;
49  virtual void SAL_CALL acquire()
50  throw () override;
51  virtual void SAL_CALL release()
52  throw () override;
53 
54  // XTypeProvider
55  virtual uno::Sequence< uno::Type > SAL_CALL getTypes() override;
56  virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
57 
58  // XInteractionContinuation
59  virtual void SAL_CALL select() override;
60 
61  // XInteractionPassword
62  virtual void SAL_CALL setPassword( const OUString & aPasswd ) override;
63  virtual OUString SAL_CALL getPassword() override;
64 
65  private:
66  osl::Mutex m_aMutex;
67  OUString m_aPassword;
68  };
69 } // namespace tdoc_ucp
70 
71 
72 // InteractionSupplyPassword Implementation.
73 
74 
75 // XInterface methods.
76 
77 
78 // virtual
79 void SAL_CALL InteractionSupplyPassword::acquire()
80  throw()
81 {
82  OWeakObject::acquire();
83 }
84 
85 
86 // virtual
87 void SAL_CALL InteractionSupplyPassword::release()
88  throw()
89 {
90  OWeakObject::release();
91 }
92 
93 
94 // virtual
95 uno::Any SAL_CALL
96 InteractionSupplyPassword::queryInterface( const uno::Type & rType )
97 {
98  uno::Any aRet = cppu::queryInterface( rType,
99  static_cast< lang::XTypeProvider * >( this ),
100  static_cast< task::XInteractionContinuation * >( this ),
101  static_cast< task::XInteractionPassword * >( this ) );
102 
103  return aRet.hasValue()
104  ? aRet : InteractionContinuation::queryInterface( rType );
105 }
106 
107 
108 // XTypeProvider methods.
109 
110 
111 // virtual
112 uno::Sequence< sal_Int8 > SAL_CALL
113 InteractionSupplyPassword::getImplementationId()
114 {
115  return css::uno::Sequence<sal_Int8>();
116 }
117 
118 
119 // virtual
120 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
121 {
122  static cppu::OTypeCollection s_aCollection(
125 
126  return s_aCollection.getTypes();
127 }
128 
129 
130 // XInteractionContinuation methods.
131 
132 
133 // virtual
134 void SAL_CALL InteractionSupplyPassword::select()
135 {
136  recordSelection();
137 }
138 
139 
140 // XInteractionPassword methods.
141 
142 
143 // virtual
144 void SAL_CALL
145 InteractionSupplyPassword::setPassword( const OUString& aPasswd )
146 {
147  osl::MutexGuard aGuard( m_aMutex );
148  m_aPassword = aPasswd;
149 }
150 
151 // virtual
152 OUString SAL_CALL InteractionSupplyPassword::getPassword()
153 {
154  osl::MutexGuard aGuard( m_aMutex );
155  return m_aPassword;
156 }
157 
158 
159 // DocumentPasswordRequest Implementation.
160 
161 
162 DocumentPasswordRequest::DocumentPasswordRequest(
163  task::PasswordRequestMode eMode,
164  const OUString & rDocumentName )
165 {
166  // Fill request...
167  task::DocumentPasswordRequest aRequest;
168 // aRequest.Message = // OUString
169 // aRequest.Context = // XInterface
170  aRequest.Classification = task::InteractionClassification_ERROR;
171  aRequest.Mode = eMode;
172  aRequest.Name = rDocumentName;
173 
174  setRequest( uno::makeAny( aRequest ) );
175 
176  // Fill continuations...
177  uno::Sequence<
178  uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
179  aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
180  aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
181  aContinuations[ 2 ] = new InteractionSupplyPassword( this );
182 
183  setContinuations( aContinuations );
184 }
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
::osl::Mutex m_aMutex
bool hasValue()
signed char sal_Int8
InteractionSupplyPassword(ucbhelper::InteractionRequest *pRequest)
Any makeAny(Color const &value)
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)