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