Branch data Line data Source code
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 : : #include <memory>
21 : :
22 : : #include "com/sun/star/document/ChangedByOthersRequest.hpp"
23 : : #include "com/sun/star/document/LockedDocumentRequest.hpp"
24 : : #include "com/sun/star/document/LockedOnSavingRequest.hpp"
25 : : #include "com/sun/star/document/LockFileIgnoreRequest.hpp"
26 : : #include "com/sun/star/document/OwnLockOnDocumentRequest.hpp"
27 : : #include "com/sun/star/task/XInteractionApprove.hpp"
28 : : #include "com/sun/star/task/XInteractionDisapprove.hpp"
29 : : #include "com/sun/star/task/XInteractionAbort.hpp"
30 : : #include "com/sun/star/task/XInteractionRequest.hpp"
31 : :
32 : : #include "osl/mutex.hxx"
33 : : #include "vcl/svapp.hxx"
34 : : #include "vcl/msgbox.hxx"
35 : :
36 : : #include "ids.hrc"
37 : : #include "getcontinuations.hxx"
38 : : #include "openlocked.hxx"
39 : : #include "trylater.hxx"
40 : : #include "alreadyopen.hxx"
41 : : #include "filechanged.hxx"
42 : : #include "lockfailed.hxx"
43 : :
44 : : #include "iahndl.hxx"
45 : :
46 : : #include <boost/scoped_ptr.hpp>
47 : :
48 : : #define UUI_DOC_LOAD_LOCK 0
49 : : #define UUI_DOC_OWN_LOAD_LOCK 1
50 : : #define UUI_DOC_SAVE_LOCK 2
51 : : #define UUI_DOC_OWN_SAVE_LOCK 3
52 : :
53 : : using namespace com::sun::star;
54 : :
55 : : namespace {
56 : :
57 : : void
58 : 0 : handleLockedDocumentRequest_(
59 : : Window * pParent,
60 : : const ::rtl::OUString& aDocumentURL,
61 : : const ::rtl::OUString& aInfo,
62 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
63 : : rContinuations,
64 : : sal_uInt16 nMode )
65 : : SAL_THROW((uno::RuntimeException))
66 : : {
67 : 0 : uno::Reference< task::XInteractionApprove > xApprove;
68 : 0 : uno::Reference< task::XInteractionDisapprove > xDisapprove;
69 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
70 [ # # ]: 0 : getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort);
71 : :
72 [ # # ][ # # ]: 0 : if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() )
[ # # ][ # # ]
73 : : return;
74 : :
75 : : try
76 : : {
77 [ # # ]: 0 : SolarMutexGuard aGuard;
78 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
79 [ # # ]: 0 : if (!xManager.get())
80 : : return;
81 : :
82 : 0 : ::rtl::OUString aMessage;
83 [ # # ]: 0 : std::vector< rtl::OUString > aArguments;
84 [ # # ]: 0 : aArguments.push_back( aDocumentURL );
85 : :
86 : 0 : sal_Int32 nResult = RET_CANCEL;
87 [ # # ]: 0 : if ( nMode == UUI_DOC_LOAD_LOCK )
88 : : {
89 : 0 : aArguments.push_back( !aInfo.isEmpty()
90 : : ? aInfo
91 : : : ResId( STR_UNKNOWNUSER,
92 [ # # ][ # # ]: 0 : *xManager.get() ).toString() );
[ # # ][ # # ]
[ # # ]
93 [ # # ]: 0 : aMessage = ResId(STR_OPENLOCKED_MSG, *xManager.get()).toString();
94 : : aMessage = UUIInteractionHelper::replaceMessageWithArguments(
95 [ # # ]: 0 : aMessage, aArguments );
96 : :
97 : : boost::scoped_ptr< OpenLockedQueryBox > xDialog(new OpenLockedQueryBox(
98 [ # # ][ # # ]: 0 : pParent, xManager.get(), aMessage ) );
[ # # ][ # # ]
99 [ # # ][ # # ]: 0 : nResult = xDialog->Execute();
100 : : }
101 [ # # ]: 0 : else if ( nMode == UUI_DOC_SAVE_LOCK )
102 : : {
103 : 0 : aArguments.push_back( !aInfo.isEmpty()
104 : : ? aInfo
105 : : : ResId( STR_UNKNOWNUSER,
106 [ # # ][ # # ]: 0 : *xManager.get() ).toString() );
[ # # ][ # # ]
[ # # ]
107 [ # # ]: 0 : aMessage = ResId(STR_TRYLATER_MSG, *xManager.get()).toString();
108 : : aMessage = UUIInteractionHelper::replaceMessageWithArguments(
109 [ # # ]: 0 : aMessage, aArguments );
110 : :
111 : : boost::scoped_ptr< TryLaterQueryBox > xDialog(
112 [ # # ][ # # ]: 0 : new TryLaterQueryBox( pParent, xManager.get(), aMessage ) );
[ # # ][ # # ]
113 [ # # ][ # # ]: 0 : nResult = xDialog->Execute();
114 : : }
115 [ # # ][ # # ]: 0 : else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
116 : : nMode == UUI_DOC_OWN_SAVE_LOCK )
117 : : {
118 [ # # ]: 0 : aArguments.push_back( aInfo );
119 : : aMessage = ResId(nMode == UUI_DOC_OWN_SAVE_LOCK
120 : : ? STR_ALREADYOPEN_SAVE_MSG
121 : : : STR_ALREADYOPEN_MSG,
122 [ # # ][ # # ]: 0 : *xManager.get() ).toString();
123 : : aMessage = UUIInteractionHelper::replaceMessageWithArguments(
124 [ # # ]: 0 : aMessage, aArguments );
125 : :
126 : : boost::scoped_ptr< AlreadyOpenQueryBox > xDialog(
127 : : new AlreadyOpenQueryBox( pParent,
128 : : xManager.get(),
129 : : aMessage,
130 [ # # ][ # # ]: 0 : nMode == UUI_DOC_OWN_SAVE_LOCK ) );
[ # # ][ # # ]
131 [ # # ][ # # ]: 0 : nResult = xDialog->Execute();
132 : : }
133 : :
134 [ # # ]: 0 : if ( nResult == RET_YES )
135 [ # # ][ # # ]: 0 : xApprove->select();
136 [ # # ]: 0 : else if ( nResult == RET_NO )
137 [ # # ][ # # ]: 0 : xDisapprove->select();
138 : : else
139 [ # # ][ # # ]: 0 : xAbort->select();
[ # # ][ # # ]
[ # # ][ # # ]
140 : : }
141 [ # # ]: 0 : catch (std::bad_alloc const &)
142 : : {
143 : : throw uno::RuntimeException(
144 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
145 [ # # # # ]: 0 : uno::Reference< uno::XInterface >());
146 [ # # ][ # # ]: 0 : }
[ # # ]
147 : : }
148 : :
149 : : void
150 : 0 : handleChangedByOthersRequest_(
151 : : Window * pParent,
152 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
153 : : rContinuations )
154 : : SAL_THROW((uno::RuntimeException))
155 : : {
156 : 0 : uno::Reference< task::XInteractionApprove > xApprove;
157 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
158 [ # # ]: 0 : getContinuations(rContinuations, &xApprove, &xAbort);
159 : :
160 [ # # ][ # # ]: 0 : if ( !xApprove.is() || !xAbort.is() )
[ # # ]
161 : : return;
162 : :
163 : : try
164 : : {
165 [ # # ]: 0 : SolarMutexGuard aGuard;
166 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
167 [ # # ]: 0 : if (!xManager.get())
168 : : return;
169 : :
170 : : boost::scoped_ptr< FileChangedQueryBox > xDialog(
171 [ # # ][ # # ]: 0 : new FileChangedQueryBox( pParent, xManager.get() ) );
172 [ # # ]: 0 : sal_Int32 nResult = xDialog->Execute();
173 : :
174 [ # # ]: 0 : if ( nResult == RET_YES )
175 [ # # ][ # # ]: 0 : xApprove->select();
176 : : else
177 [ # # ][ # # ]: 0 : xAbort->select();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
178 : : }
179 [ # # ]: 0 : catch (std::bad_alloc const &)
180 : : {
181 : : throw uno::RuntimeException(
182 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
183 [ # # # # ]: 0 : uno::Reference< uno::XInterface >());
184 [ # # ][ # # ]: 0 : }
185 : : }
186 : :
187 : : void
188 : 0 : handleLockFileIgnoreRequest_(
189 : : Window * pParent,
190 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
191 : : rContinuations )
192 : : SAL_THROW((uno::RuntimeException))
193 : : {
194 : 0 : uno::Reference< task::XInteractionApprove > xApprove;
195 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
196 [ # # ]: 0 : getContinuations(rContinuations, &xApprove, &xAbort);
197 : :
198 [ # # ][ # # ]: 0 : if ( !xApprove.is() || !xAbort.is() )
[ # # ]
199 : : return;
200 : :
201 : : try
202 : : {
203 [ # # ]: 0 : SolarMutexGuard aGuard;
204 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
205 [ # # ]: 0 : if (!xManager.get())
206 : : return;
207 : :
208 : : boost::scoped_ptr< LockFailedQueryBox > xDialog(
209 [ # # ][ # # ]: 0 : new LockFailedQueryBox( pParent, xManager.get() ) );
210 [ # # ]: 0 : sal_Int32 nResult = xDialog->Execute();
211 : :
212 [ # # ]: 0 : if ( nResult == RET_OK )
213 [ # # ][ # # ]: 0 : xApprove->select();
214 : : else
215 [ # # ][ # # ]: 0 : xAbort->select();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
216 : : }
217 [ # # ]: 0 : catch (std::bad_alloc const &)
218 : : {
219 : : throw uno::RuntimeException(
220 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
221 [ # # # # ]: 0 : uno::Reference< uno::XInterface >());
222 [ # # ][ # # ]: 0 : }
223 : : }
224 : :
225 : : } // namespace
226 : :
227 : : bool
228 : 0 : UUIInteractionHelper::handleLockedDocumentRequest(
229 : : uno::Reference< task::XInteractionRequest > const & rRequest)
230 : : SAL_THROW((::com::sun::star::uno::RuntimeException))
231 : : {
232 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
233 : :
234 [ # # ]: 0 : document::LockedDocumentRequest aLockedDocumentRequest;
235 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aLockedDocumentRequest )
236 : : {
237 : : handleLockedDocumentRequest_( getParentProperty(),
238 : : aLockedDocumentRequest.DocumentURL,
239 : : aLockedDocumentRequest.UserInfo,
240 [ # # ]: 0 : rRequest->getContinuations(),
241 [ # # ][ # # ]: 0 : UUI_DOC_LOAD_LOCK );
[ # # ][ # # ]
242 : 0 : return true;
243 : : }
244 : :
245 [ # # ]: 0 : document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
246 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aOwnLockOnDocumentRequest )
247 : : {
248 : : handleLockedDocumentRequest_( getParentProperty(),
249 : : aOwnLockOnDocumentRequest.DocumentURL,
250 : : aOwnLockOnDocumentRequest.TimeInfo,
251 [ # # ]: 0 : rRequest->getContinuations(),
252 : : aOwnLockOnDocumentRequest.IsStoring
253 : : ? UUI_DOC_OWN_SAVE_LOCK
254 [ # # ][ # # ]: 0 : : UUI_DOC_OWN_LOAD_LOCK );
[ # # ][ # # ]
[ # # ]
255 : 0 : return true;
256 : : }
257 : :
258 [ # # ]: 0 : document::LockedOnSavingRequest aLockedOnSavingRequest;
259 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aLockedOnSavingRequest )
260 : : {
261 : : handleLockedDocumentRequest_( getParentProperty(),
262 : : aLockedOnSavingRequest.DocumentURL,
263 : : aLockedOnSavingRequest.UserInfo,
264 [ # # ]: 0 : rRequest->getContinuations(),
265 [ # # ][ # # ]: 0 : UUI_DOC_SAVE_LOCK );
[ # # ][ # # ]
266 : 0 : return true;
267 : : }
268 [ # # ][ # # ]: 0 : return false;
[ # # ]
269 : : }
270 : :
271 : : bool
272 : 0 : UUIInteractionHelper::handleChangedByOthersRequest(
273 : : uno::Reference< task::XInteractionRequest > const & rRequest)
274 : : SAL_THROW((uno::RuntimeException))
275 : : {
276 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
277 : :
278 [ # # ]: 0 : document::ChangedByOthersRequest aChangedByOthersRequest;
279 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aChangedByOthersRequest )
280 : : {
281 : : handleChangedByOthersRequest_( getParentProperty(),
282 [ # # ][ # # ]: 0 : rRequest->getContinuations() );
[ # # ][ # # ]
[ # # ]
283 : 0 : return true;
284 : : }
285 [ # # ]: 0 : return false;
286 : : }
287 : :
288 : : bool
289 : 0 : UUIInteractionHelper::handleLockFileIgnoreRequest(
290 : : uno::Reference< task::XInteractionRequest > const & rRequest)
291 : : SAL_THROW((uno::RuntimeException))
292 : : {
293 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
294 : :
295 [ # # ]: 0 : document::LockFileIgnoreRequest aLockFileIgnoreRequest;
296 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aLockFileIgnoreRequest )
297 : : {
298 : : handleLockFileIgnoreRequest_( getParentProperty(),
299 [ # # ][ # # ]: 0 : rRequest->getContinuations() );
[ # # ][ # # ]
[ # # ]
300 : 0 : return true;
301 : : }
302 [ # # ]: 0 : return false;
303 : : }
304 : :
305 : :
306 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|